Add auto generated location id list.
[freeems-vanilla.git] / src / Makefile.windows
blob74a2d1045f0570cd3e20c7e4ce58f4667a02e8d1
1 #       FreeEMS - the open source engine management system
3 #       Copyright 2008, 2009 Fred Cooke
5 #       This Makefile is part of the FreeEMS project.
7 #       FreeEMS software is free software: you can redistribute it and/or modify
8 #       it under the terms of the GNU General Public License as published by
9 #       the Free Software Foundation, either version 3 of the License, or
10 #       (at your option) any later version.
12 #       FreeEMS software is distributed in the hope that it will be useful,
13 #       but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #       GNU General Public License for more details.
17 #       You should have received a copy of the GNU General Public License
18 #       along with any FreeEMS software.  If not, see http://www.gnu.org/licenses/
20 #       We ask that if you make any changes to this file you email them upstream to
21 #       us at admin(at)diyefi(dot)org or, even better, fork the code on github.com!
23 #       Thank you for choosing FreeEMS to run your engine!
26 #                                                                              #
27 #   This Makefile is designed to be run with GNU make! Accept no substitute!   #
28 #                                                                              #
29 #                                                                              #
30 #   Top level targets:                                                         #
31 #                                                                              #
32 #   make:                                                                      #
33 #       Builds all output files in the slow multi stage way with all debugging #
34 #   make fast:                                                                 #
35 #       Compiles from C straight to objects, links to elfs and copies to s19s  #
36 #   make clean:                                                                #
37 #       Permanently removes all build artifact files and directories           #
38 #   make release:                                                              #
39 #       Cleans the project, builds it from scratch, copies the s19 files up to #
40 #       the firmware directory, zips each s19 separately, zips all of the      #
41 #       documentation, cleans the project again and lastly zips the entire     #
42 #       project directory                                                      #
43 #                                                                              #
44 #                                                                              #
45 #   When doing a full build the following steps are taken:                     #
46 #                                                                              #
47 #    1) Pre-process all of the C files                                         #
48 #    2) Compile all preprocessed C files into assembly files                   #
49 #    3) Assemble all assembly files into object files                          #
50 #    4) Dump the contents of all object files                                  #
51 #    5) Link one decoder with garbage collection and reporting turned on       #
52 #    6) Link each decoder without garbage collection                           #
53 #    7) Dump the contents of each decoders elf                                 #
54 #    8) Produce a memory map for each elf                                      #
55 #    9) Produce a readelf dump for each elf                                    #
56 #   10) Produce an s19 loadable firmware file for each elf                     #
57 #                                                                              #
62 #                             All Fixed Variables                              #
65 # Constants
66 VERSION = 0.0.19
67 OUTPREFIX = freeems
69 # Directories here
70 RELEASEDIR = ../firmware
71 INCDIR = inc
72 BUGDIR = debug
73 OUTDIR = output
74 OBJDIR = objects
75 ASMDIR = assembly
76 S19DIR = firmware
77 PPCDIR = preprocessedc
79 # Set the windows/non debian path first and then overwrite
80 # with the debian one so we can grep the deb line out and
81 # end up with a working windows make file in an automated
82 # way. Additionally, please ensure you do not add any sets
83 # of three .. . in a row or the line will be missing from
84 # the windows version. Likewise sets of ### longer than 6
85 # or so are also at risk :-)
86 PREFIX = m6811-elf-
88 # All of the tools
89 CP = cp
90 RM = rm -rf
91 ZIP = zip
92 GCC = $(PREFIX)gcc
93 COPY = $(PREFIX)objcopy
94 DUMP = $(PREFIX)objdump
95 NM = $(PREFIX)nm
96 RE = $(PREFIX)readelf
97 SIZE = $(PREFIX)size
102 #                               All Source Files                               #
105 # Indirect dependencies - any header change means a full recompile. This can be improved upon and made more specific.
106 MAINH = main.h
107 INITH = init.h
108 UTILH = utils.h
109 MFILE = Makefile
110 ISRH = interrupts.h
111 CINCS = injectorISR.c
112 FLASHH = flashWrite.h
113 ASMH = 9S12XDP512asm.s
114 LOOKUPH = tableLookup.h
115 WMFILE = Makefile.windows
116 ISRSH = commsISRs.h injectionISRs.h
117 COMMSH = commsCore.h blockDetailsLookup.h
118 LINKER = memory.x regions.x hc9s12xdp512elfb.x
119 GLOBALH1 = freeEMS.h 9S12XDP512.h memory.h globalConstants.h structs.h
120 GLOBALH2 = globalDefines.h errorDefines.h TunableConfigs.h FixedConfigs.h
121 FUELH = fuelAndIgnitionCalcs.h derivedVarsGenerator.h coreVarsGenerator.h
122 RPMH = NipponDenso.h LT1-360-8.h Subaru-36-2-2-2.h MissingTeeth.h MiataNB.h
124 # Let's keep this to a bare minimum! If you write ASM code
125 # please provide an matching alternate C implementation too.
126 HANDASMS = flashBurn.s
127 #RPMHANDASMS = 
129 # .c files from inc/ should be included here as deps for the parts they are relied on by!!
130 ALLHEADERS = $(GLOBALH1) $(GLOBALH2) $(COMMSH) $(ISRSH) $(UTILH) $(FUELH) $(MAINH) $(INITH) $(ISRH) $(FLASHH) $(LOOKUPH) $(RPMH)
131 ALLH = $(patsubst %.h,$(INCDIR)/%.h,$(ALLHEADERS)) $(LINKER) $(MFILE) $(patsubst %.c,$(INCDIR)/%.c,$(CINCS)) $(INCDIR)/$(ASMH)
133 # Warning : do not include .c files from inc/ as they are included into the other C files and automatically compiled.
135 # Flash data files
136 FIXEDCLASSES = FixedConfig1.c FixedConfig2.c
137 LOOKUPCLASSES1 = IATTransferTable.c CHTTransferTable.c
138 LOOKUPCLASSES2 = MAFTransferTable.c TestTransferTable.c
139 FUELCLASSES = FuelTables.c FuelTables2.c
140 TIMECLASSES = TimingTables.c TimingTables2.c
141 TUNECLASSES = TunableConfig.c TunableConfig2.c
143 # Source code files
144 UTILCLASSES = tableLookup.c init.c utils.c globalConstants.c
145 MATHCLASSES = coreVarsGenerator.c derivedVarsGenerator.c fuelAndIgnitionCalcs.c
146 COMCLASSES = flashWrite.c commsCore.c blockDetailsLookup.c
147 ISRCLASSES = interrupts.c injectionISRs.c ignitionISRs.c commsISRs.c realtimeISRs.c miscISRs.c
149 # All but the engine position/RPM combined here
150 SOURCE = freeEMS.c staticInit.c main.c $(UTILCLASSES) $(MATHCLASSES) $(COMCLASSES) $(ISRCLASSES)
151 DATA = $(FIXEDCLASSES) $(LOOKUPCLASSES1) $(LOOKUPCLASSES2) $(FUELCLASSES) $(TIMECLASSES) $(TUNECLASSES)
152 CLASSES = $(SOURCE) $(DATA)
154 # Engine position/RPM here
155 RPMCLASSES = NipponDenso.c LT1-360-8.c Subaru-36-2-2-2.c MissingTeeth.c MiataNB.c
158 # Convert extensions
159 PREPROCESSED = $(patsubst %.c,$(PPCDIR)/%.pp.c,$(CLASSES))
160 ASSEMBLIES = $(patsubst %.c,$(ASMDIR)/%.s,$(CLASSES))
161 OBJECTS = $(patsubst %.c,$(OBJDIR)/%.o,$(CLASSES)) $(patsubst %.s,$(OBJDIR)/%.o,$(HANDASMS))
162 DUMPS = $(patsubst %.c,$(BUGDIR)/%.dmp,$(CLASSES)) $(patsubst %.s,$(BUGDIR)/%.dmp,$(HANDASMS))
164 # Convert RPM extensions
165 PREPROCESSEDRPM = $(patsubst %.c,$(PPCDIR)/%.pp.c,$(RPMCLASSES))
166 ASSEMBLIESRPM = $(patsubst %.c,$(ASMDIR)/%.s,$(RPMCLASSES))
167 OBJECTSRPM = $(patsubst %.c,$(OBJDIR)/%.o,$(RPMCLASSES)) #$(patsubst %.s,$(OBJDIR)/%.o,$(RPMHANDASMS))
168 DUMPSRPM = $(patsubst %.c,$(BUGDIR)/%.dmp,$(RPMCLASSES)) #$(patsubst %.s,$(BUGDIR)/%.dmp,$(RPMHANDASMS))
170 # Convert to output files
171 ALLELFS = $(patsubst %.c,$(OUTDIR)/$(OUTPREFIX)-$(VERSION)-%.elf,$(RPMCLASSES)) #$(patsubst %.s,$(OUTDIR)/$(OUTPREFIX)-$(VERSION)-%.elf,$(RPMHANDASMS))
172 ALLDMPS = $(patsubst %.c,$(BUGDIR)/$(OUTPREFIX)-$(VERSION)-%.dmp,$(RPMCLASSES)) #$(patsubst %.s,$(BUGDIR)/$(OUTPREFIX)-$(VERSION)-%.dmp,$(RPMHANDASMS))
173 ALLMAPS = $(patsubst %.c,$(BUGDIR)/$(OUTPREFIX)-$(VERSION)-%.map,$(RPMCLASSES)) #$(patsubst %.s,$(BUGDIR)/$(OUTPREFIX)-$(VERSION)-%.map,$(RPMHANDASMS))
174 ALLREAD = $(patsubst %.c,$(BUGDIR)/$(OUTPREFIX)-$(VERSION)-%.ree,$(RPMCLASSES)) #$(patsubst %.s,$(BUGDIR)/$(OUTPREFIX)-$(VERSION)-%.ree,$(RPMHANDASMS))
175 ALLS19S = $(patsubst %.c,$(S19DIR)/$(OUTPREFIX)-$(VERSION)-%.s19,$(RPMCLASSES)) #$(patsubst %.s,$(S19DIR)/$(OUTPREFIX)-$(VERSION)-%.s19,$(RPMHANDASMS))
177 # Convert to output files for GC variants
178 GCDELFS = $(patsubst %.c,$(OUTDIR)/$(OUTPREFIX)-$(VERSION)-%.gc.elf,$(RPMCLASSES)) #$(patsubst %.s,$(OUTDIR)/$(OUTPREFIX)-$(VERSION)-%.gc.elf,$(RPMHANDASMS))
179 GCDS19S = $(patsubst %.c,$(S19DIR)/$(OUTPREFIX)-$(VERSION)-%.gc.s19,$(RPMCLASSES)) #$(patsubst %.s,$(S19DIR)/$(OUTPREFIX)-$(VERSION)-%.gc.s19,$(RPMHANDASMS))
184 #                           All Command Line Options                           #
187 # M68hc1x GCC Options we may want : -minmax  -mlong-calls
189 # http://www.gnu.org/software/m68hc11/m68hc11_gcc.html shows code size with different options used
190 # include debug info, optimise , 16 bit ints, hcs12 platform
191 GCCOPTS = -g -Wall -Werror -Winline -O -m68hcs12 -mshort -ffunction-sections -fomit-frame-pointer -msoft-reg-count=8 -mauto-incdec -fsigned-char
192 # -ffunction-sections option splits out the functions such that the garbage collection can get
193 # them on a per section basis. I'm not sure, but this could be harmful to paged code so may
194 # have to review this at a later date perhaps splitting paged functions from nonpaged ones.
196 # pass to linker, link for hc12
197 # The vectors address in the linker options is the VMA address and must be short form 0xF710, not a paged address.
198 LINKOPTS = -Wl,-defsym,vectors_addr=0xF710,-m,m68hc12elfb,-T,hc9s12xdp512elfb.x
199 LINKOPTSGC = -Wl,--gc-sections,--print-gc-sections,-defsym,vectors_addr=0xF710,-m,m68hc12elfb,-T,hc9s12xdp512elfb.x
200 # Use this to get a map dump when the linker fails in a confusing way :
201 #LINKOPTSGC = -Wl,--print-map,--gc-sections,--print-gc-sections,-defsym,vectors_addr=0xF710,-m,m68hc12elfb,-T,hc9s12xdp512elfb.x
203 # If using the below option for paged flash, the ADDRESS_TYPE field in the freeEMSloader script should be updated to match.
204 # --change-section-lma .ppagePP=0xPP8000 \ (where PP = the ppage value for that page of flash) OR if using linear address per formula
205 COPYOPTS =  --output-target=srec \
206                 --change-section-lma .fixedconf1+0xFD4000 \
207                 --change-section-lma .fixedconf2+0xFD4000 \
208                      --change-section-lma .text1+0xFD4000 \
209                       --change-section-lma .text+0xFEC000 \
210                       --change-section-lma .data+0xFEC000 \
211                    --change-section-lma .vectors+0xFEC000 \
212                     --change-section-lma .rodata+0xFEC000 \
213                 --only-section=.fixedconf1 \
214                 --only-section=.fixedconf2 \
215                 --only-section=.text \
216                 --only-section=.text1 \
217                 --only-section=.data \
218                 --only-section=.vectors \
219                 --only-section=.rodata \
220                 --change-section-lma .ppageF8=0xF88000 \
221                 --change-section-lma .fpageF9=0xF98000 \
222                 --change-section-lma .dpageF9=0xF9A000 \
223                 --change-section-lma .ppageFE=0xFE8000 \
224                 --only-section=.ppageF8 \
225                 --only-section=.fpageF9 \
226                 --only-section=.dpageF9 \
227                 --only-section=.ppageFE \
228                 --change-section-lma .fpageFA=0xFA8000 \
229                 --change-section-lma .dpageFA=0xFAA000 \
230                 --change-section-lma .fpageFB=0xFB8000 \
231                 --change-section-lma .dpageFB1=0xFBA000 \
232                 --change-section-lma .dpageFB2=0xFBA400 \
233                 --change-section-lma .dpageFB3=0xFBA800 \
234                 --change-section-lma .dpageFB4=0xFBAC00 \
235                 --change-section-lma .dpageFB5=0xFBB000 \
236                 --change-section-lma .dpageFB6=0xFBB400 \
237                 --change-section-lma .dpageFB7=0xFBB800 \
238                 --change-section-lma .dpageFB8=0xFBBC00 \
239                 --change-section-lma .fpageFC=0xFC8000 \
240                 --change-section-lma .dpageFC=0xFCA000 \
241                 --only-section=.dpageFA \
242                 --only-section=.fpageFA \
243                 --only-section=.dpageFB1 \
244                 --only-section=.dpageFB2 \
245                 --only-section=.dpageFB3 \
246                 --only-section=.dpageFB4 \
247                 --only-section=.dpageFB5 \
248                 --only-section=.dpageFB6 \
249                 --only-section=.dpageFB7 \
250                 --only-section=.dpageFB8 \
251                 --only-section=.fpageFB \
252                 --only-section=.dpageFC \
253                 --only-section=.fpageFC
254 #               --change-section-lma .ppageFD=0xFD8000 \
255 #               --change-section-lma .ppageFF=0xFF8000 \
256 #               --only-section=.ppageFD \       This is left here for clarity only (equivalent to text1 but paged)
257 #               --only-section=.ppageFF         This is left here for clarity only (equivalent to text but paged)
258 # Changes to the above options should be reflected in memory.x and memory.h also!
260 # The following flash areas can only be used once Sean has written his loader app :
261 #               --only-section=.ppageE0 \
262 #               --only-section=.ppageE1 \
263 #               --only-section=.ppageE2 \
264 #               --only-section=.ppageE3 \
265 #               --only-section=.ppageE4 \
266 #               --only-section=.ppageE5 \
267 #               --only-section=.ppageE6 \
268 #               --only-section=.ppageE7 \
269 #               --only-section=.ppageE8 \
270 #               --only-section=.ppageE9 \
271 #               --only-section=.ppageEA \
272 #               --only-section=.ppageEB \
273 #               --only-section=.ppageEC \
274 #               --only-section=.ppageED \
275 #               --only-section=.ppageEE \
276 #               --only-section=.ppageEF \
277 #               --only-section=.ppageF0 \
278 #               --only-section=.ppageF1 \
279 #               --only-section=.ppageF2 \
280 #               --only-section=.ppageF3 \
281 #               --only-section=.ppageF4 \
282 #               --only-section=.ppageF5 \
283 #               --only-section=.ppageF6 \
284 #               --only-section=.ppageF7 \
285 #               --change-section-lma .ppageE0=0xE08000 \
286 #               --change-section-lma .ppageE1=0xE18000 \
287 #               --change-section-lma .ppageE2=0xE28000 \
288 #               --change-section-lma .ppageE3=0xE38000 \
289 #               --change-section-lma .ppageE4=0xE48000 \
290 #               --change-section-lma .ppageE5=0xE58000 \
291 #               --change-section-lma .ppageE6=0xE68000 \
292 #               --change-section-lma .ppageE7=0xE78000 \
293 #               --change-section-lma .ppageE8=0xE88000 \
294 #               --change-section-lma .ppageE9=0xE98000 \
295 #               --change-section-lma .ppageEA=0xEA8000 \
296 #               --change-section-lma .ppageEB=0xEB8000 \
297 #               --change-section-lma .ppageEC=0xEC8000 \
298 #               --change-section-lma .ppageED=0xED8000 \
299 #               --change-section-lma .ppageEE=0xEE8000 \
300 #               --change-section-lma .ppageEF=0xEF8000 \
301 #               --change-section-lma .ppageF0=0xF08000 \
302 #               --change-section-lma .ppageF1=0xF18000 \
303 #               --change-section-lma .ppageF2=0xF28000 \
304 #               --change-section-lma .ppageF3=0xF38000 \
305 #               --change-section-lma .ppageF4=0xF48000 \
306 #               --change-section-lma .ppageF5=0xF58000 \
307 #               --change-section-lma .ppageF6=0xF68000 \
308 #               --change-section-lma .ppageF7=0xF78000 \
313 #                        Dependency And Target Summary                         #
314 #                                                                              #
315 #   Top level targets:                                                         #
316 #                                                                              #
317 #       1) all                                                                 #
318 #       2) fast                                                                #
319 #       3) install                                                             #
320 #       4) release                                                             #
321 #       5) clean                                                               #
322 #                                                                              #
323 #   Second level targets:                                                      #
324 #                                                                              #
325 #       1) nonrpm:                                                             #
326 #                                                                              #
327 #           1) preprocess [list] Generate preprocessed C from sources          #
328 #           2) assemble   [list] Generate assembly from preprocessed C         #
329 #           3) compile    [list] Generate object files from assembly           #
330 #                                                                              #
331 #       2) rpm:                                                                #
332 #                                                                              #
333 #           1) preprocessrpm [list] Generate preprocessed C from sources       #
334 #           2) assemblerpm   [list] Generate assembly from preprocessed C      #
335 #           3) compilerpm    [list] Generate object files from assembly        #
336 #                                                                              #
337 #       3) final:                                                              #
338 #                                                                              #
339 #           1) link [list] Generate ELFs objects                               #
340 #           2) copy [list] s19s from elfs                                      #
341 #                                                                              #
342 #       4) debug:                                                              #
343 #                                                                              #
344 #           1) link      [list] Generate ELFs objects                          #
345 #           2) dump      [list] dumpslarge from elfs                           #
346 #           3) map       [list] mapslarge from elfs                            #
347 #           4) read      [list] relarge from elfs                              #
348 #           5) dumpsmall [list] dumpsall from obj + rpmobj                     #
349 #                                                                              #
350 #        release : md5sum, export, zip, copy, docs, etc                                                                      #
351 #                                                                              #
356 #                           All Target Dependencies                            #
359 # Build everything the long way (default)
360 all: s19
362 # Build minimally and quickly
363 fast: lessthings here
365 # Load the s19 of your choice
366 install: clean fast loader
368 # Perform a release
369 release: clean cleanrelease fast someMoreStuffHere
371 clean: cleanasm cleanobj cleanout cleanppc cleans19 cleandebug
373 final: link copy 
375 debug: dump map read dumpsmall
380 #                       Link and Copy Target Definitions                       #
384 link: assemble $(OUTDIR) $(ALLELFS)
386 # link the object files into an elf executable
387 $(ALLELFS): $(OUTDIR)/$(OUTPREFIX)-$(VERSION)-%.elf: $(OBJDIR)/%.o $(OBJECTS)
388         $(GCC) $(GCCOPTS) $(LINKOPTS) -o $@ $< $(OBJECTS)
396 s19: link $(S19DIR) $(ALLS19S)
397 # the gc dependency is temporary until i figure out if the .tramp removal is an issue or not.
399 # Generate the loadable s19 firmware files
400 $(ALLS19S): $(S19DIR)/%.s19: $(OUTDIR)/%.elf
401         $(COPY) $(COPYOPTS) $< $@
409 size: # TODO this should be run for each s19 target with only the one rpm .o file
410         $(SIZE) -t $(OBJECTS)
416 #              Preprocess, Compile and Assemble Target Definitions             #
420 preprocess: $(PPCDIR) $(PREPROCESSED) $(PREPROCESSEDRPM)
422 # Generate preprocessed source files to examine
423 $(PREPROCESSED) $(PREPROCESSEDRPM): $(PPCDIR)/%.pp.c: %.c $(ALLH)
424         $(GCC) $(GCCOPTS) -E $< > $@
428 compile: preprocess $(ASSEMBLIES) $(ASSEMBLIESRPM)
430 # Generate assembly files to examine
431 $(ASSEMBLIES) $(ASSEMBLIESRPM): $(ASMDIR)/%.s: $(PPCDIR)/%.pp.c
432         $(GCC) $(GCCOPTS) -x cpp-output -S -o $@ $<
436 assemble: compile $(OBJDIR) $(OBJECTS) $(OBJECTSRPM)
438 # Generate object files to link
439 $(OBJECTS) $(OBJECTSRPM): $(OBJDIR)/%.o: $(ASMDIR)/%.s
440         $(GCC) $(GCCOPTS) -c -o $@ $<
445 #                     Release Procedure Target Definitions                     #
447 ### clean all
449 #check git status for changes, fail build if not fully commited
451 ### build all
453 #copy s19s up
455 #md5sum s19s above
457 ### clean all
459 #git commit s19s
461 #zip each s19 to parent
463 #zip docs to parent
465 #zip without docs to parent
467 #zip entire directory to parent
472 #                     Create Directory Target Definitions                      #
474 # Assembly, release and inc directories don't get removed.
476 $(BUGDIR):
477         mkdir -p $(BUGDIR)
479 $(S19DIR):
480         mkdir -p $(S19DIR)
482 $(PPCDIR):
483         mkdir -p $(PPCDIR)
485 $(OUTDIR):
486         mkdir -p $(OUTDIR)
488 $(OBJDIR):
489         mkdir -p $(OBJDIR)
494 #                            Clean Target Definitions                          #
496 cleanasm:
497         $(RM) $(ASSEMBLIES) $(ASSEMBLIESRPM)
499 cleanppc:
500         $(RM) $(PPCDIR)
502 cleanobj:
503         $(RM) $(OBJDIR)
505 cleanout:
506         $(RM) $(OUTDIR)
508 cleans19:
509         $(RM) $(S19DIR)
511 cleandebug:
512         $(RM) $(DEBUGDIR)
514 cleanrelease:
515         $(RM) $(RELEASEDIR)/*
520 #                   Declare targets that aren't real files                     #
523 # Top level
524 .PHONY: all fast release clean
525 # Second level
526 .PHONY: rpm nonrpm final debug
527 ## Third level
528 .PHONY: preprocess assemble compile
529 # Comments
530 .PHONY: etc etc etc
531 # Clean targets
532 .PHONY: cleanasm cleandebug cleanobj cleanout cleanppc cleanrelease cleans19