1 # FreeEMS - the open source engine management system
5 # Copyright 2008-2011 Fred Cooke
7 # This Makefile is part of the FreeEMS project.
9 # FreeEMS software is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # FreeEMS software is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with any FreeEMS software. If not, see http://www.gnu.org/licenses/
22 # We ask that if you make any changes to this file you email them upstream to
23 # us at admin(at)diyefi(dot)org or, even better, fork the code on github.com!
25 # Thank you for choosing FreeEMS to run your engine!
30 ################################################################################
32 # About This Makefile #
34 # This makefile incorporates many non-standard features. In particular, it #
35 # is inspired by Maven 2 and it's highly disciplined release mechanism. By #
36 # automating the release process as much as possible the chance of human #
37 # error is minimised. As much as possible, reuse is employed to keep bugs #
38 # from being introduced when changes are made. Rather than compiling from #
39 # C source files directly to object files, the build is, by default, done #
40 # in three stages, C to pre-processed C, pre-processed C to assembly, and #
41 # assembly to object files. Linking is also a little different with two #
42 # variants available, with and without garbage collection. Target device #
43 # memory usage statistics are available and generated by default when the #
44 # all target is called. Finally, extensive debug information can be #
45 # generated with a single make call. #
47 ################################################################################
52 ################################################################################
53 # All Fixed Variables #
54 ################################################################################
58 FIRMWARE_VERSION
= $(shell git describe
--dirty
=-DEV
)
60 LABEL
= $(OUTPREFIX
)-$(FIRMWARE_VERSION
)
65 # Windows uses backslash
67 # Windows mkdir does not accept -p
69 # Windows echo repeats " symbols (Q stands for quote...)
83 # If using this on windows, we're in cygwin, same as Linux
88 DISTRIBUTIONDIR = ../../$(LABEL)
89 DOXYDOCDIR = ../docs/doxygen-html
90 MAINDIR = freeems-vanilla
94 DATADIR = initialisers
100 PPCDIR = preprocessedc
101 XGASMDIR = $(ASMDIR)$(PATHSEP)xgate
102 XGOBJDIR = $(OBJDIR)$(PATHSEP)xgate
104 # Release tag message file
105 RELTAG = $(OUTDIR)/gitTagMessage.txt
106 TAGNAME = $(OUTDIR)/gitTagName.txt
108 # Program prefixes, for the main cpu and for the xgate coprocessor
117 COPY = $(PREFIX)objcopy
118 DUMP = $(PREFIX)objdump
120 RE = $(PREFIX)readelf
127 ################################################################################
129 ################################################################################
132 # Indirect dependencies that can affect everything and cause a full rebuild
134 ASMH = 9S12XDP512asm.s
135 LINKER = memory.x regions.x hc9s12xdp512elfb.x
138 # Let's keep this to a bare minimum! If you write ASM code
139 # please provide an matching alternate C implementation too.
140 HANDASMS = flashBurn.s
143 ALLH = $(LINKER) $(MFILE) $(INCDIR)/$(ASMH)
145 # Warning : do not include .c files from inc/ as they are
146 # included into the other C files and automatically compiled.
149 FIXEDCLASSES = FixedConfig1.c FixedConfig2.c
150 LOOKUPCLASSES1 = IATTransferTable.c CHTTransferTable.c
151 LOOKUPCLASSES2 = MAFTransferTable.c TestTransferTable.c
152 FUELCLASSES = FuelTables.c FuelTables2.c
153 TIMECLASSES = TimingTables.c TimingTables2.c
154 TUNECLASSES = TunableConfig.c TunableConfig2.c
155 # Combined data files
156 DATARAW = $(FIXEDCLASSES) $(LOOKUPCLASSES1) $(LOOKUPCLASSES2) $(FUELCLASSES) $(TIMECLASSES) $(TUNECLASSES)
157 DATA = $(patsubst %.c,$(DATADIR)/%.c,$(DATARAW))
160 UTILCLASSES = tableLookup.c init.c utils.c globalConstants.c StaticBenchTest.c
161 MATHCLASSES = coreVarsGenerator.c derivedVarsGenerator.c fuelAndIgnitionCalcs.c decoderInterface.c
162 COMCLASSES = flashWrite.c commsCore.c blockDetailsLookup.c
163 ISRCLASSES = interrupts.c injectionISRs.c commsISRs.c realtimeISRs.c miscISRs.c xgateVectors.c
164 # Combined source code files
165 SOURCE = freeEMS.c staticInit.c main.c $(UTILCLASSES) $(MATHCLASSES) $(COMCLASSES) $(ISRCLASSES)
167 # All but the engine position/RPM combined here
168 CLASSES = $(SOURCE) $(DATA)
170 # Engine position/RPM here
171 # Special decoders are not for use running an engine
172 RPMSPECIAL = Listener.c BenchTest.c
173 # TODO: Automate file naming for the following 4 lines
174 RPMEVENTEETH = EvenTeeth-Both-12and1.c EvenTeeth-Both-8and1.c
175 RPMMISSINGTEETH = MissingTeeth-TestFile.c MissingTeeth-Crank-12minus1.c MissingTeeth-Crank-36minus1.c MissingTeeth-Crank-60minus2.c
176 RPMHALLOROPTICAL = HallOrOptical-Distributor-4of64.c HallOrOptical-Distributor-4of69.c
178 # Specific purpose per engine stuff here
179 RPMSPECIFICENGINE1 = MitsiAndMazda-CAS-4and1.c GM-LT1-CAS-360and8.c
180 # Insert your file above and get coding!
181 RPMCLASSESRAW = $(RPMSPECIAL) $(RPMEVENTEETH) $(RPMMISSINGTEETH) $(RPMHALLOROPTICAL) $(RPMVRDISTRIBUTOR) $(RPMSPECIFICENGINE1)
182 RPMCLASSES = $(patsubst %.c,$(DECDIR)/%.c,$(RPMCLASSESRAW))
189 DEPENDENCIES = $(patsubst %.c,$(DEPDIR)/%.d,$(CLASSES))
190 DDEPENDENCIES = $(patsubst %.c,$(DEPDIR)/%.dd,$(CLASSES))
191 PREPROCESSED = $(patsubst %.c,$(PPCDIR)/%.pp.c,$(CLASSES))
192 ASSEMBLIES = $(patsubst %.c,$(ASMDIR)/%.s,$(CLASSES))
193 OBJECTS = $(patsubst %.c,$(OBJDIR)/%.o,$(CLASSES)) $(patsubst %.s,$(OBJDIR)/%.o,$(HANDASMS))
194 DUMPS = $(patsubst %.c,$(BUGDIR)/%.dmp,$(CLASSES)) $(patsubst %.s,$(BUGDIR)/%.dmp,$(HANDASMS))
195 XGOBJECTS = $(patsubst %.s,$(XGOBJDIR)/%.o,$(XGASMSRCS))
197 # Convert RPM extensions
198 DEPENDENCIESRPM = $(patsubst %.c,$(DEPDIR)/%.d,$(RPMCLASSES))
199 DDEPENDENCIESRPM = $(patsubst %.c,$(DEPDIR)/%.dd,$(RPMCLASSES))
200 PREPROCESSEDRPM = $(patsubst %.c,$(PPCDIR)/%.pp.c,$(RPMCLASSES))
201 ASSEMBLIESRPM = $(patsubst %.c,$(ASMDIR)/%.s,$(RPMCLASSES))
202 OBJECTSRPM = $(patsubst %.c,$(OBJDIR)/%.o,$(RPMCLASSES)) #$(patsubst $(DECDIR???)%.s,$(OBJDIR)/%.o,$(RPMHANDASMS))
203 DUMPSRPM = $(patsubst %.c,$(BUGDIR)/%.dmp,$(RPMCLASSES)) #$(patsubst $(DECDIR???)%.s,$(BUGDIR)/%.dmp,$(RPMHANDASMS))
205 # Bring in all of the generated deps. Note, if these fail on the first pass of parsing, Make will generate them and reparse.
206 -include $(DEPENDENCIES) $(DEPENDENCIESRPM) $(DDEPENDENCIES) $(DDEPENDENCIESRPM)
208 # Convert to output files for source
209 ALLELFSC = $(patsubst $(DECDIR)/%.c,$(OUTDIR)/$(LABEL)-%.elf,$(RPMCLASSES))
210 ALLELFSASM = #$(patsubst %.s,$(OUTDIR)/$(LABEL)-%.elf,$(RPMHANDASMS))
211 ALLDMPSC = $(patsubst $(DECDIR)/%.c,$(BUGDIR)/$(LABEL)-%.dmp,$(RPMCLASSES))
212 ALLDMPSASM = #$(patsubst %.s,$(BUGDIR)/$(LABEL)-%.dmp,$(RPMHANDASMS))
213 ALLMAPSC = $(patsubst $(DECDIR)/%.c,$(BUGDIR)/$(LABEL)-%.map,$(RPMCLASSES))
214 ALLMAPSASM = #$(patsubst %.s,$(BUGDIR)/$(LABEL)-%.map,$(RPMHANDASMS))
215 ALLREADC = $(patsubst $(DECDIR)/%.c,$(BUGDIR)/$(LABEL)-%.ree,$(RPMCLASSES))
216 ALLREADASM = #$(patsubst %.s,$(BUGDIR)/$(LABEL)-%.ree,$(RPMHANDASMS))
217 ALLS19SC = $(patsubst $(DECDIR)/%.c,$(S19DIR)/$(LABEL)-%.s19,$(RPMCLASSES))
218 ALLS19SASM = #$(patsubst %.s,$(S19DIR)/$(LABEL)-%.s19,$(RPMHANDASMS))
220 # Convert to output files for as-is variants
221 ALLELFS = $(ALLELFSC) $(ALLELFSASM)
222 ALLDMPS = $(ALLDMPSC) $(ALLDMPSASM)
223 ALLMAPS = $(ALLMAPSC) $(ALLMAPSASM)
224 ALLREAD = $(ALLREADC) $(ALLREADASM)
225 ALLS19S = $(ALLS19SC) $(ALLS19SASM)
226 ALLSIZES = $(patsubst $(S19DIR)/%,$(OUTDIR)/%.txt,$(ALLS19S))
227 ALLDUMMY = $(patsubst $(S19DIR)/%,$(OUTDIR)/%.txt.dummy,$(ALLS19S))
228 ALLMD5S = $(patsubst $(S19DIR)/%,$(DISTRIBUTIONDIR)/%.md5,$(ALLS19S))
229 ALLSHA1S = $(patsubst $(S19DIR)/%,$(DISTRIBUTIONDIR)/%.sha1,$(ALLS19S))
230 ALLS19ZIPS = $(patsubst $(S19DIR)/%,$(DISTRIBUTIONDIR)/%.zip,$(ALLS19S))
233 # Convert to output files for GC variants
234 GCDELFSC = $(patsubst $(DECDIR)/%.c,$(OUTDIR)/$(LABEL)-%.gc.elf,$(RPMCLASSES))
235 GCDELFSASM = #$(patsubst %.s,$(OUTDIR)/$(LABEL)-%.gc.elf,$(RPMHANDASMS))
236 GCDS19SC = $(patsubst $(DECDIR)/%.c,$(S19DIR)/$(LABEL)-%.gc.s19,$(RPMCLASSES))
237 GCDS19SASM = #$(patsubst %.s,$(S19DIR)/$(LABEL)-%.gc.s19,$(RPMHANDASMS))
238 GCDELFS = $(GCDELFSC) $(GCDELFSASM)
239 GCDS19S = $(GCDS19SC) $(GCDELFSASM)
240 GCDSIZES = $(patsubst $(S19DIR)/%,$(OUTDIR)/%.txt,$(GCDS19S))
241 GCDDUMMY = $(patsubst $(S19DIR)/%,$(OUTDIR)/%.txt.dummy,$(GCDS19S))
246 ################################################################################
247 # All Command Line Options #
248 ################################################################################
251 # M68hc1x GCC Options we may want : -minmax -mlong-calls
253 # http://www.gnu.org/software/m68hc11/m68hc11_gcc.html shows code size with different options used
254 # include debug info, optimise , 16 bit ints, hcs12 platform
255 GCCOPTS1 = -g -Wall -Werror -Winline -O -m68hcs12 -mshort -ffunction-sections -idirafter custom -idirafter default
256 GCCOPTS2 = -fomit-frame-pointer -msoft-reg-count=8 -mauto-incdec -fsigned-char
257 GCCOPTS = $(GCCOPTS1) $(GCCOPTS2) $(CLIFLAGS) -D FIRMWARE_VERSION=\"$(FIRMWARE_VERSION)\" -D OPERATING_SYSTEM=\"$(OS)\"
258 # -ffunction-sections option splits out the functions such that the garbage collection can get
259 # them on a per section basis. I'm not sure, but this could be harmful to paged code so may
260 # have to review this at a later date perhaps splitting paged functions from nonpaged ones.
262 # pass to linker, link for hc12
263 # The vectors address in the linker options is the VMA address and must be short form 0xF710, not a paged address.
264 LINKOPTS = -no-warn-mismatch,-defsym,vectors_addr=0xF710,-m,m68hc12elfb,-T,hc9s12xdp512elfb.x
265 LINKOPTSGC = -no-warn-mismatch,--gc-sections,--print-gc-sections,-defsym,vectors_addr=0xF710,-m,m68hc12elfb,-T,hc9s12xdp512elfb.x
266 # Use this to get a map dump when the linker fails in a confusing way : --print-map
268 # If using the below option for paged flash, the ADDRESS_TYPE
269 # field in the freeEMSloader script should be updated to match.
270 COPYOPTS = --output-target=srec \
271 --change-section-lma .fixedconf1+0xFD4000 \
272 --change-section-lma .fixedconf2+0xFD4000 \
273 --change-section-lma .text1+0xFD4000 \
274 --change-section-lma .text+0xFEC000 \
275 --change-section-lma .data+0xFEC000 \
276 --change-section-lma .vectors+0xFEC000 \
277 --change-section-lma .rodata+0xFEC000 \
278 --only-section=.fixedconf1 \
279 --only-section=.fixedconf2 \
280 --only-section=.text \
281 --only-section=.text1 \
282 --only-section=.data \
283 --only-section=.vectors \
284 --only-section=.rodata \
285 --change-section-lma .ppageE0X=0xE08800 \
286 --change-section-lma .ppageE1=0xE18000 \
287 --only-section=.ppageE0X \
288 --only-section=.ppageE1 \
289 --set-section-flags .ppageE1=alloc,load \
290 --change-section-lma .ppageF8=0xF88000 \
291 --change-section-lma .fpageF9=0xF98000 \
292 --change-section-lma .dpageF9=0xF9A000 \
293 --change-section-lma .ppageFE=0xFE8000 \
294 --only-section=.ppageF8 \
295 --only-section=.fpageF9 \
296 --only-section=.dpageF9 \
297 --only-section=.ppageFE \
298 --change-section-lma .fpageFA=0xFA8000 \
299 --change-section-lma .dpageFA=0xFAA000 \
300 --change-section-lma .fpageFB=0xFB8000 \
301 --change-section-lma .dpageFB1=0xFBA000 \
302 --change-section-lma .dpageFB2=0xFBA400 \
303 --change-section-lma .dpageFB3=0xFBA800 \
304 --change-section-lma .dpageFB4=0xFBAC00 \
305 --change-section-lma .dpageFB5=0xFBB000 \
306 --change-section-lma .dpageFB6=0xFBB400 \
307 --change-section-lma .dpageFB7=0xFBB800 \
308 --change-section-lma .dpageFB8=0xFBBC00 \
309 --change-section-lma .fpageFC=0xFC8000 \
310 --change-section-lma .dpageFC=0xFCA000 \
311 --only-section=.dpageFA \
312 --only-section=.fpageFA \
313 --only-section=.dpageFB1 \
314 --only-section=.dpageFB2 \
315 --only-section=.dpageFB3 \
316 --only-section=.dpageFB4 \
317 --only-section=.dpageFB5 \
318 --only-section=.dpageFB6 \
319 --only-section=.dpageFB7 \
320 --only-section=.dpageFB8 \
321 --only-section=.fpageFB \
322 --only-section=.dpageFC \
323 --only-section=.fpageFC
324 # --change-section-lma .ppageFD=0xFD8000 \
325 # --change-section-lma .ppageFF=0xFF8000 \
326 # --only-section=.ppageFD \ This is left here for clarity only (equivalent to text1 but paged)
327 # --only-section=.ppageFF This is left here for clarity only (equivalent to text but paged)
328 # Changes to the above options should be reflected in memory.x and memory.h also!
330 # The following flash areas should only be included if they are used.
331 # --only-section=.ppageE0S \
332 # --only-section=.ppageE2 \
333 # --only-section=.ppageE3 \
334 # --only-section=.ppageE4 \
335 # --only-section=.ppageE5 \
336 # --only-section=.ppageE6 \
337 # --only-section=.ppageE7 \
338 # --only-section=.ppageE8 \
339 # --only-section=.ppageE9 \
340 # --only-section=.ppageEA \
341 # --only-section=.ppageEB \
342 # --only-section=.ppageEC \
343 # --only-section=.ppageED \
344 # --only-section=.ppageEE \
345 # --only-section=.ppageEF \
346 # --only-section=.ppageF0 \
347 # --only-section=.ppageF1 \
348 # --only-section=.ppageF2 \
349 # --only-section=.ppageF3 \
350 # --only-section=.ppageF4 \
351 # --only-section=.ppageF5 \
352 # --only-section=.ppageF6 \
353 # --only-section=.ppageF7 \
354 # --change-section-lma .ppageE0S=0xE08000 \
355 # --change-section-lma .ppageE2=0xE28000 \
356 # --change-section-lma .ppageE3=0xE38000 \
357 # --change-section-lma .ppageE4=0xE48000 \
358 # --change-section-lma .ppageE5=0xE58000 \
359 # --change-section-lma .ppageE6=0xE68000 \
360 # --change-section-lma .ppageE7=0xE78000 \
361 # --change-section-lma .ppageE8=0xE88000 \
362 # --change-section-lma .ppageE9=0xE98000 \
363 # --change-section-lma .ppageEA=0xEA8000 \
364 # --change-section-lma .ppageEB=0xEB8000 \
365 # --change-section-lma .ppageEC=0xEC8000 \
366 # --change-section-lma .ppageED=0xED8000 \
367 # --change-section-lma .ppageEE=0xEE8000 \
368 # --change-section-lma .ppageEF=0xEF8000 \
369 # --change-section-lma .ppageF0=0xF08000 \
370 # --change-section-lma .ppageF1=0xF18000 \
371 # --change-section-lma .ppageF2=0xF28000 \
372 # --change-section-lma .ppageF3=0xF38000 \
373 # --change-section-lma .ppageF4=0xF48000 \
374 # --change-section-lma .ppageF5=0xF58000 \
375 # --change-section-lma .ppageF6=0xF68000 \
376 # --change-section-lma .ppageF7=0xF78000 \
381 @echo $(Q)################################################################################$(Q)
382 @echo $(Q)# Dependency And Target Summary #$(Q)
383 @echo $(Q)################################################################################$(Q)
385 @echo $(Q)# Common targets: #$(Q)
387 @echo $(Q)# 1) help - This comment block #$(Q)
388 @echo $(Q)# 2) all - Executes alldebug, slow, slowgc and size #$(Q)
389 @echo $(Q)# 3) dirs - Creates all of the directories required to build #$(Q)
390 @echo $(Q)# 5) slow - Three stage compilation with assembly retained #$(Q)
391 @echo $(Q)# 6) slowgc - As above, but with garbage collection during linking #$(Q)
392 @echo $(Q)# 7) alldebug - Generates all debug output files #$(Q)
393 @echo $(Q)# 8) install - Not yet implemented #$(Q)
394 @echo $(Q)# 9) release - Performs a full release build #$(Q)
395 @echo $(Q)# 10) clean - Removes all files and directories generated by building #$(Q)
397 @echo $(Q)# Second level targets: #$(Q)
399 @echo $(Q)# Stage one: #$(Q)
401 @echo $(Q)# 1) preprocess - run the C preprocessor over the raw C files #$(Q)
402 @echo $(Q)# 2) compile - compile the preprocessed C into assembly #$(Q)
403 @echo $(Q)# 3) assemble - assemble the assembly files into object files #$(Q)
405 @echo $(Q)# Stage two #$(Q)
407 @echo $(Q)# 1) link - Generate ELFs objects #$(Q)
408 @echo $(Q)# 2) gclink - As above, but with garbage collection #$(Q)
409 @echo $(Q)# 3) s19 - Create s19s from elfs #$(Q)
410 @echo $(Q)# 4) gcs19 - Create s19s from gc elfs #$(Q)
411 @echo $(Q)# 5) sizes - Calculate the approximate s19 sizes #$(Q)
412 @echo $(Q)# 6) gcsizes - Calculate the approximate gc s19 sizes #$(Q)
414 @echo $(Q)# Stage three: #$(Q)
416 @echo $(Q)# 1) maps - Memory map files #$(Q)
417 @echo $(Q)# 2) rees - Readelf dumps #$(Q)
418 @echo $(Q)# 3) elfdmps - Classic objdump output for final elfs #$(Q)
419 @echo $(Q)# 4) objdmps - Classic objdump output for each object file #$(Q)
421 @echo $(Q)# When doing a full build the following steps are taken: #$(Q)
423 @echo $(Q)# 1) Pre-process all of the C files #$(Q)
424 @echo $(Q)# 2) Compile all preprocessed C files into assembly files #$(Q)
425 @echo $(Q)# 3) Assemble all assembly files into object files #$(Q)
426 @echo $(Q)# 4) Link each decoder without garbage collection #$(Q)
427 @echo $(Q)# 5) Produce a memory map for each elf #$(Q)
428 @echo $(Q)# 6) Produce a readelf dump for each elf #$(Q)
429 @echo $(Q)# 7) Dump the contents of each decoders elf #$(Q)
430 @echo $(Q)# 8) Dump the contents of all object files #$(Q)
431 @echo $(Q)# 9) Link each decoder with garbage collection and reporting turned on #$(Q)
432 @echo $(Q)# 10) Produce an s19 loadable firmware file for each elf #$(Q)
433 @echo $(Q)# 11) Measure each binary image approximately #$(Q)
434 @echo $(Q)# 12) Measure each decoder object file #$(Q)
435 @echo $(Q)# 13) Measure each other object file and summarise #$(Q)
437 @echo $(Q)# The release target: #$(Q)
439 @echo $(Q)# This target is purely for use by lead developers to produce a file set #$(Q)
440 @echo $(Q)# that is suitable for release and distribution to users and interested #$(Q)
441 @echo $(Q)# parties. The steps performed are listed below: #$(Q)
443 @echo $(Q)# 1) Checks that the repository is consistent #$(Q)
444 @echo $(Q)# 2) Performs a full clean #$(Q)
445 @echo $(Q)# 4) Removes the doxygen files #$(Q)
446 @echo $(Q)# 5) Builds binaries for each decoder type #$(Q)
447 @echo $(Q)# 7) Generates a new doxygen site #$(Q)
448 @echo $(Q)# 8) Performs a full clean #$(Q)
449 @echo $(Q)# 9) Commits the release files #$(Q)
450 @echo $(Q)# 10) Asks for a tag name and tag message #$(Q)
451 @echo $(Q)# 11) Tags the release at the automatic commit point #$(Q)
452 @echo $(Q)# 12) Generates md5 and sha1 checksums into the distribution directory #$(Q)
453 @echo $(Q)# 13) Zips the binaries into the distribution directory #$(Q)
454 @echo $(Q)# 14) Zips the doxygen site into the distribution directory #$(Q)
455 @echo $(Q)# 15) Zips the documentation into the distribution directory #$(Q)
456 @echo $(Q)# 16) Zips the repository into the distribution directory #$(Q)
457 @echo $(Q)# 17) Zips the source code into the distribution directory #$(Q)
459 @echo $(Q)# At that point the developer in charge of release has only to upload #$(Q)
460 @echo $(Q)# the files found in the distribution directory to appropriate locations #$(Q)
461 @echo $(Q)# and publicise the fact that a new release has been performed! This #$(Q)
462 @echo $(Q)# automation removes most opportunity for mistakes and makes release #$(Q)
463 @echo $(Q)# quality consistent between each successive release cycle! #$(Q)
465 @echo $(Q)# Unlisted targets: #$(Q)
467 @echo $(Q)# Additionally any of the output files can be used as a target directly. #$(Q)
468 @echo $(Q)# This is perfect for building only what is required for a specific s19. #$(Q)
469 @echo $(Q)# It is also perfect for working with a single file as you don't have to #$(Q)
470 @echo $(Q)# wait for other unrelated things to build first nor do you have to wait #$(Q)
471 @echo $(Q)# for other files to continue building after yours is successful. Before #$(Q)
472 @echo $(Q)# using individual output files for targets, please run 'make dirs'. #$(Q)
474 @echo $(Q)################################################################################$(Q)
479 ################################################################################
480 # All Target Dependencies #
481 ################################################################################
484 # Build everything the long way
485 all: alldebug gcsizes sizes size
486 # Multi stage compilation
488 # Multi stage compilation with garbage collection
490 # Clean all except release
491 clean: cleanasm cleanobj cleanout cleanppc cleans19 cleandebug
493 alldebug: maps rees elfdmps objdmps
494 # Load the s19 of your choice
495 #install: clean slow loader
497 release: testgit relbuild relperf
498 package: relbuildfull relpack1 relpack2 zipsite
499 packagenodoxy: relbuildfirmware relpack1 relpack2
500 relbuildfull: clean cleandoxy gendoxy s19
501 relbuildfirmware: clean s19
502 relperf: relcommit tagrelease
503 relpack1: md5sums sha1sums s19zips
504 relpack2: zipdocs zipmain zipsrc
509 ################################################################################
510 # Debug Target Definitions #
511 ################################################################################
515 @echo $(Q)################################################################################$(Q)
516 @echo $(Q)# Generating memory maps.... #$(Q)
517 @echo $(Q)################################################################################$(Q)
519 maps: link $(BUGDIR) mapsmsg $(ALLMAPS)
521 $(ALLMAPS): $(BUGDIR)/%.map: $(OUTDIR)/%.elf
526 @echo $(Q)################################################################################$(Q)
527 @echo $(Q)# Reading all elf files... #$(Q)
528 @echo $(Q)################################################################################$(Q)
530 rees: link $(BUGDIR) reesmsg $(ALLREAD)
532 $(ALLREAD): $(BUGDIR)/%.ree: $(OUTDIR)/%.elf
537 @echo $(Q)################################################################################$(Q)
538 @echo $(Q)# Dumping all elf files... #$(Q)
539 @echo $(Q)################################################################################$(Q)
541 elfdmps: link $(BUGDIR) elfdmpsmsg $(ALLDMPS)
543 $(ALLDMPS): $(BUGDIR)/%.dmp: $(OUTDIR)/%.elf
544 $(DUMP) -spSd $< > $@
548 @echo $(Q)################################################################################$(Q)
549 @echo $(Q)# Dumping all object files.... #$(Q)
550 @echo $(Q)################################################################################$(Q)
552 objdmps: assemble $(BUGDIR) objdmpmsg $(DUMPS) $(DUMPSRPM)
554 $(DUMPS) $(DUMPSRPM): $(BUGDIR)/%.dmp: $(OBJDIR)/%.o
555 $(DUMP) -spSd $< > $@
560 ################################################################################
561 # Link and Copy Target Definitions #
562 ################################################################################
566 @echo $(Q)################################################################################$(Q)
567 @echo $(Q)# Linking the Objects into an ELF... #$(Q)
568 @echo $(Q)################################################################################$(Q)
570 link: assemble $(OUTDIR) linkmsg $(ALLELFS)
572 # link the object files into an elf executable
573 $(ALLELFS): $(OUTDIR)/$(LABEL)-%.elf: $(OBJDIR)/$(DECDIR)/%.o $(OBJECTS) $(XGOBJECTS)
574 @echo $(Q)################################################################################$(Q)
575 @echo $(Q)# Linking $@ ...$(Q)
576 @echo $(Q)################################################################################$(Q)
577 $(GCC) $(GCCOPTS) -Wl,$(LINKOPTS) -o $@ $(OBJECTS) $(XGOBJECTS) $<
581 @echo $(Q)################################################################################$(Q)
582 @echo $(Q)# Linking the Objects into an ELF... #$(Q)
583 @echo $(Q)################################################################################$(Q)
585 gclink: assemble $(OUTDIR) linkmsg $(GCDELFS)
587 # link the object files into an elf executable with gc enabled
588 $(GCDELFS): $(OUTDIR)/$(LABEL)-%.gc.elf: $(OBJDIR)/$(DECDIR)/%.o $(OBJECTS) $(XGOBJECTS)
589 @echo $(Q)################################################################################$(Q)
590 @echo $(Q)# Linking $@ ...$(Q)
591 @echo $(Q)################################################################################$(Q)
592 $(GCC) $(GCCOPTS) -Wl,$(LINKOPTSGC) -o $@ $(OBJECTS) $(XGOBJECTS) $<
593 # The links with garbage collection are to ensure that there are no warnings
594 # TODO find out how to stop .tramp from being collected (or inserted)!
595 # This will be the only way once Sean's stuff is done and distributed, I can't wait to cut all this bullshit out!
599 @echo $(Q)################################################################################$(Q)
600 @echo $(Q)# Building The S19 Files.... #$(Q)
601 @echo $(Q)################################################################################$(Q)
603 s19: link $(S19DIR) s19msg $(ALLS19S)
604 # the gc dependency is temporary until i figure out if the .tramp removal is an issue or not.
606 # Generate the loadable s19 firmware files
607 $(ALLS19S): $(S19DIR)/%.s19: $(OUTDIR)/%.elf
608 @echo $(Q)################################################################################$(Q)
609 @echo $(Q)# Building $@ ...$(Q)
610 @echo $(Q)################################################################################$(Q)
611 $(COPY) $(COPYOPTS) $< $@
615 @echo $(Q)################################################################################$(Q)
616 @echo $(Q)# Measuring The S19 Files... #$(Q)
617 @echo $(Q)################################################################################$(Q)
619 sizes: s19 $(OUTDIR) sizesmsg $(ALLDUMMY)
621 # Roughly measure the s19 sizes
622 $(ALLSIZES): $(OUTDIR)/%.txt: $(S19DIR)/%
623 @echo $(shell cat $< | wc -l) $(Q)* 16$(Q) > $@
625 # Have to do this in two stages to allow $(shell exp) use and portability to windows
626 $(ALLDUMMY): $(OUTDIR)/%.dummy: $(OUTDIR)/%
627 @echo $(Q)Flash image size is$(Q) $(shell cat $< | bc -l) $(Q)bytes for $<$(Q)
631 @echo $(Q)################################################################################$(Q)
632 @echo $(Q)# Building The GC S19 Files.... #$(Q)
633 @echo $(Q)################################################################################$(Q)
635 gcs19: gclink $(S19DIR) gcs19msg $(GCDS19S)
637 # Generate the garbage collected s19 files temporarily
638 $(GCDS19S): $(S19DIR)/%.s19: $(OUTDIR)/%.elf
639 @echo $(Q)################################################################################$(Q)
640 @echo $(Q)# Building $@ ...$(Q)
641 @echo $(Q)################################################################################$(Q)
642 $(COPY) $(COPYOPTS) $< $@
645 @echo $(Q)################################################################################$(Q)
646 @echo $(Q)# Measuring The GC S19 Files... #$(Q)
647 @echo $(Q)################################################################################$(Q)
649 gcsizes: gcs19 $(OUTDIR) gcsizesmsg $(GCDDUMMY)
651 # Roughly measure the gc s19 sizes
652 $(GCDSIZES): $(OUTDIR)/%.txt: $(S19DIR)/%
653 @echo $(shell cat $< | wc -l) $(Q)* 16$(Q) > $@
655 # Have to do this in two stages to allow $(shell exp) use and portability to windows
656 $(GCDDUMMY): $(OUTDIR)/%.dummy: $(OUTDIR)/%
657 @echo $(Q)Flash image size is$(Q) $(shell cat $< | bc -l) $(Q)bytes for $<$(Q)
663 ################################################################################
664 # Size Measuring Target Definition #
665 ################################################################################
668 size: assemble # TODO this should be run for each s19 target with only the one rpm .o file
669 @echo $(Q)################################################################################$(Q)
670 @echo $(Q)# Measuring The Decoder Binaries... #$(Q)
671 @echo $(Q)################################################################################$(Q)
672 $(SIZE) $(OBJECTSRPM)
673 @echo $(Q)################################################################################$(Q)
674 @echo $(Q)# Measuring All Other Binaries... #$(Q)
675 @echo $(Q)################################################################################$(Q)
676 $(SIZE) -t $(OBJECTS)
677 @echo $(Q)################################################################################$(Q)
678 @echo $(Q)# Add one decoder to the total above and #$(Q)
679 @echo $(Q)# subtract the size reported for freeEMS.o #$(Q)
680 @echo $(Q)# this will give you the actual image size #$(Q)
681 @echo $(Q)################################################################################$(Q)
683 @echo $(Q)# Thank you for building FreeEMS firmware!!! #$(Q)
685 @echo $(Q)################################################################################$(Q)
690 ################################################################################
691 # Preprocess, Compile and Assemble Target Definitions #
692 ################################################################################
696 @echo $(Q)################################################################################$(Q)
697 @echo $(Q)# Generating the dependencies... #$(Q)
698 @echo $(Q)################################################################################$(Q)
700 dependencies: dependenciesmsg $(DEPENDENCIES) $(DEPENDENCIESRPM) $(DDEPENDENCIES) $(DDEPENDENCIESRPM)
702 # Generate dependency files for recompilation on change semantics
703 $(DEPENDENCIES) $(DEPENDENCIESRPM): $(DEPDIR)/%.d: %.c $(ALLH)
704 $(GCC) $(CLIFLAGS) -MM -MF $@ -MT $(PPCDIR)/$*.pp.c $<
705 # Generate dependency files for the dependency files...
706 $(DDEPENDENCIES) $(DDEPENDENCIESRPM): $(DEPDIR)/%.dd: %.c $(ALLH)
707 $(GCC) $(CLIFLAGS) -MM -MF $@ -MT $(DEPDIR)/$*.d $<
711 @echo $(Q)################################################################################$(Q)
712 @echo $(Q)# Running the C Pre Processor... #$(Q)
713 @echo $(Q)################################################################################$(Q)
715 preprocess: $(PPCDIR) preprocessmsg $(PREPROCESSED) $(PREPROCESSEDRPM)
717 # Generate preprocessed source files to examine
718 $(PREPROCESSED): $(PPCDIR)/%.pp.c: %.c $(ALLH)
719 $(GCC) $(GCCOPTS) -D BASE_FILE_NAME=\"$*\" -E $< > $@
720 $(PREPROCESSEDRPM): $(PPCDIR)/decoders/%.pp.c: decoders/%.c $(ALLH)
721 $(GCC) $(GCCOPTS) -D BASE_FILE_NAME=\"$*\" -E $< > $@
725 @echo $(Q)################################################################################$(Q)
726 @echo $(Q)# Compiling PPC to Assembly... #$(Q)
727 @echo $(Q)################################################################################$(Q)
729 compile: preprocess compilemsg $(ASSEMBLIES) $(ASSEMBLIESRPM)
731 # Generate assembly files to examine
732 $(ASSEMBLIES) $(ASSEMBLIESRPM): $(ASMDIR)/%.s: $(PPCDIR)/%.pp.c
733 $(GCC) $(GCCOPTS) -x cpp-output -S -o $@ $<
737 @echo $(Q)################################################################################$(Q)
738 @echo $(Q)# Assembling Object Files... #$(Q)
739 @echo $(Q)################################################################################$(Q)
741 assemble: compile $(OBJDIR) $(XGOBJDIR) assemblemsg $(OBJECTS) $(OBJECTSRPM) $(XGOBJECTS)
743 # Generate object files to link
744 $(OBJECTS) $(OBJECTSRPM): $(OBJDIR)/%.o: $(ASMDIR)/%.s
745 $(GCC) $(GCCOPTS) -c -o $@ $<
747 $(XGOBJECTS): $(XGOBJDIR)/%.o: $(XGASMDIR)/%.s
752 ################################################################################
753 # Release Procedure Target Definitions #
754 ################################################################################
759 @echo "################################################################################"
760 @echo
"# Checking git status... #"
761 @echo
"################################################################################"
762 @echo
"Are we on master?"
763 test `git symbolic-ref HEAD` = refs
/heads
/master
764 @echo
"Is everything checked in?"
765 test `git status -s | wc -l` -eq
0
766 @echo
"Fetching from origin..."
768 @echo
"Are we behind?"
769 test `git rev-list \`git show-ref
--hash refs
/heads
/master\
`..\`git show-ref
--hash refs
/remotes
/origin/master\
` | wc -l` -eq
0
770 @echo
"Are we ahead?"
771 test `git rev-list \`git show-ref
--hash refs
/remotes
/origin/master\
`..\`git show-ref
--hash refs
/heads
/master\
` | wc -l` -eq
0
775 @echo
$(Q
)################################################################################$(Q)
776 @echo
$(Q
)# Generating MD5 Sums... #$(Q)
777 @echo
$(Q
)################################################################################$(Q)
779 md5sums
: s19 distributiondir md5sumsmsg
$(ALLMD5S
)
781 $(ALLMD5S
): $(DISTRIBUTIONDIR
)/%.s19.md5
: $(S19DIR
)/%.s19
786 @echo
$(Q
)################################################################################$(Q)
787 @echo
$(Q
)# Generating SHA1 Sums... #$(Q)
788 @echo
$(Q
)################################################################################$(Q)
790 sha1sums
: s19 distributiondir sha1sumsmsg
$(ALLSHA1S
)
792 $(ALLSHA1S
): $(DISTRIBUTIONDIR
)/%.s19.sha1
: $(S19DIR
)/%.s19
799 @echo
$(Q
)################################################################################$(Q)
800 @echo
$(Q
)# Zipping S19s... #$(Q)
801 @echo
$(Q
)################################################################################$(Q)
803 s19zips
: s19 distributiondir s19zipsmsg
$(ALLS19ZIPS
)
805 $(ALLS19ZIPS
): $(DISTRIBUTIONDIR
)/%.s19.zip
: $(S19DIR
)/%.s19
816 tagrelease
: tagname tagmessage
817 git tag
-F
$(RELTAG
) `cat $(TAGNAME)` HEAD
820 zipmain
: distributiondir
821 cd ..
/ ; git archive
--format
=zip
--prefix=$(LABEL
)/ HEAD
> ..
/$(LABEL
)/$(LABEL
).zip
;cd
-
823 zipdocs
: distributiondir
824 cd ..
/ ; git archive
--format
=zip
--prefix=$(LABEL
)- HEAD docs
/ > ..
/$(LABEL
)/$(LABEL
)-docs.zip
;cd
-
827 cd ..
/ ; doxygen docs
/Doxyfile | grep Warning
> src
/doxygen.output
;cd
-
829 zipsite
: distributiondir gendoxy
830 cd ..
/docs
/ ; zip
-r
$(DISTRIBUTIONDIR
)/$(LABEL
)-doxygen-html.zip doxygen-html
/;cd
-
832 zipsrc
: distributiondir
833 cd ..
/ ; git archive
--format
=zip
--prefix=$(LABEL
)- HEAD src
/ > ..
/$(LABEL
)/$(LABEL
)-src.zip
;cd
-
838 ################################################################################
839 # Create Directory Target Definitions #
840 ################################################################################
842 # Assembly, release and inc directories don't get removed.
844 dirs
: $(BUGDIR
) $(S19DIR
) $(PPCDIR
) $(OUTDIR
) $(OBJDIR
) $(XGOBJDIR
)
847 @echo
$(Q
)################################################################################$(Q)
848 @echo
$(Q
)# Creating the debug directory.... #$(Q)
849 @echo
$(Q
)################################################################################$(Q)
850 $(MKDIR
) $(BUGDIR
)$(PATHSEP
)$(DECDIR
)$(PATHSEP
)hack
851 rmdir
$(BUGDIR
)$(PATHSEP
)$(DECDIR
)$(PATHSEP
)hack
852 $(MKDIR
) $(BUGDIR
)$(PATHSEP
)$(DATADIR
)$(PATHSEP
)hack
853 rmdir
$(BUGDIR
)$(PATHSEP
)$(DATADIR
)$(PATHSEP
)hack
856 @echo
$(Q
)################################################################################$(Q)
857 @echo
$(Q
)# Creating the firmware directory... #$(Q)
858 @echo
$(Q
)################################################################################$(Q)
859 $(MKDIR
) $(S19DIR
)$(PATHSEP
)hack
860 rmdir
$(S19DIR
)$(PATHSEP
)hack
863 @echo
$(Q
)################################################################################$(Q)
864 @echo
$(Q
)# Creating the preprocessedc directory.... #$(Q)
865 @echo
$(Q
)################################################################################$(Q)
866 $(MKDIR
) $(PPCDIR
)$(PATHSEP
)$(DECDIR
)$(PATHSEP
)hack
867 rmdir
$(PPCDIR
)$(PATHSEP
)$(DECDIR
)$(PATHSEP
)hack
868 $(MKDIR
) $(PPCDIR
)$(PATHSEP
)$(DATADIR
)$(PATHSEP
)hack
869 rmdir
$(PPCDIR
)$(PATHSEP
)$(DATADIR
)$(PATHSEP
)hack
872 @echo
$(Q
)################################################################################$(Q)
873 @echo
$(Q
)# Creating the output directory... #$(Q)
874 @echo
$(Q
)################################################################################$(Q)
875 $(MKDIR
) $(OUTDIR
)$(PATHSEP
)hack
876 rmdir
$(OUTDIR
)$(PATHSEP
)hack
879 @echo
$(Q
)################################################################################$(Q)
880 @echo
$(Q
)# Creating the object directory... #$(Q)
881 @echo
$(Q
)################################################################################$(Q)
882 $(MKDIR
) $(OBJDIR
)$(PATHSEP
)$(DECDIR
)$(PATHSEP
)hack
883 rmdir
$(OBJDIR
)$(PATHSEP
)$(DECDIR
)$(PATHSEP
)hack
884 $(MKDIR
) $(OBJDIR
)$(PATHSEP
)$(DATADIR
)$(PATHSEP
)hack
885 rmdir
$(OBJDIR
)$(PATHSEP
)$(DATADIR
)$(PATHSEP
)hack
888 @echo
$(Q
)################################################################################$(Q)
889 @echo
$(Q
)# Creating the xgate object directory... #$(Q)
890 @echo
$(Q
)################################################################################$(Q)
891 $(MKDIR
) $(XGOBJDIR
)$(PATHSEP
)hack
892 rmdir
$(XGOBJDIR
)$(PATHSEP
)hack
895 @echo
$(Q
)################################################################################$(Q)
896 @echo
$(Q
)# Creating the distribution directory... #$(Q)
897 @echo
$(Q
)################################################################################$(Q)
898 $(MKDIR
) $(DISTRIBUTIONDIR
)$(PATHSEP
)hack
899 rmdir
$(DISTRIBUTIONDIR
)$(PATHSEP
)hack
904 ################################################################################
905 # Clean Target Definitions #
906 ################################################################################
909 @echo
$(Q
)################################################################################$(Q)
910 @echo
$(Q
)# Removing generated assembly files.... #$(Q)
911 @echo
$(Q
)################################################################################$(Q)
912 $(RM
) $(ASSEMBLIES
) $(ASSEMBLIESRPM
)
915 @echo
$(Q
)################################################################################$(Q)
916 @echo
$(Q
)# Removing pre-processed C output directory... #$(Q)
917 @echo
$(Q
)################################################################################$(Q)
918 $(RM
) $(DEPDIR
)$(PATHSEP
)*.d
$(DEPDIR
)$(PATHSEP
)*.dd
919 $(RM
) $(DEPDIR
)$(PATHSEP
)$(DECDIR
)$(PATHSEP
)*.d
$(DEPDIR
)$(PATHSEP
)$(DECDIR
)$(PATHSEP
)*.dd
920 $(RM
) $(DEPDIR
)$(PATHSEP
)$(DATADIR
)$(PATHSEP
)*.d
$(DEPDIR
)$(PATHSEP
)$(DATADIR
)$(PATHSEP
)*.dd
923 @echo
$(Q
)################################################################################$(Q)
924 @echo
$(Q
)# Removing pre-processed C output directory... #$(Q)
925 @echo
$(Q
)################################################################################$(Q)
929 @echo
$(Q
)################################################################################$(Q)
930 @echo
$(Q
)# Removing object directory... #$(Q)
931 @echo
$(Q
)################################################################################$(Q)
935 @echo
$(Q
)################################################################################$(Q)
936 @echo
$(Q
)# Removing link output directory... #$(Q)
937 @echo
$(Q
)################################################################################$(Q)
941 @echo
$(Q
)################################################################################$(Q)
942 @echo
$(Q
)# Removing s19 directory... #$(Q)
943 @echo
$(Q
)################################################################################$(Q)
947 @echo
$(Q
)################################################################################$(Q)
948 @echo
$(Q
)# Removing debug directory... #$(Q)
949 @echo
$(Q
)################################################################################$(Q)
953 @echo
$(Q
)################################################################################$(Q)
954 @echo
$(Q
)# Removing Doxygen HTML... #$(Q)
955 @echo
$(Q
)################################################################################$(Q)
956 $(RM
) ..
/docs
/doxygen-html
/
959 ################################################################################
960 # Declare targets that aren't real files #
961 ################################################################################
964 # Aggregators top level
965 .PHONY
: all slow slowgc single help dirs
967 # Aggregators middle level
968 .PHONY
: dependencies preprocess compile assemble link gclink s19 gcs19 sizes gcsizes
970 # Aggregators debug level
971 .PHONY
: alldebug maps rees objdmps elfdmps size
974 .PHONY
: release relperf relbuild relpack
975 .PHONY
: md5sums sha1sums s19zips sha1sumsgc s19zips s19zipsgc
976 .PHONY
: testgit relcommit tagname tagmessage tagrelease
977 .PHONY
: zipmain zipdocs zipsite zipsource
980 .PHONY
: mapsmsg reesmsg elfdmpsmsg objdmpmsg linkmsg gclinkmsg
981 .PHONY
: s19msg gcs19msg preprocessmsg compilemsg assemblemsg
982 .PHONY
: md5sumsmsg sha1sumsmsg s19zipsmsg
985 .PHONY
: clean cleandep cleanasm cleanppc cleanobj cleanout cleans19 cleandebug cleandoxy
987 # Lonely documentation target :-(