1 # FreeEMS - the open source engine management system
5 # Copyright 2008-2012 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
)
61 BUILD_DATE
:= "$(shell date)"
66 # Windows uses backslash
68 # Windows mkdir does not accept -p
70 # Windows echo repeats " symbols (Q stands for quote...)
84 # If using this on windows, we're in cygwin, same as Linux
89 DISTRIBUTIONDIR = ../tmp/$(LABEL)
90 FIRMWAREDISTRIBUTIONDIR = $(DISTRIBUTIONDIR)/$(LABEL)-firmware
91 DOXYDOCDIR = ../docs/doxygen-html
92 MAINDIR = freeems-vanilla
96 DATADIR = initialisers
102 PPCDIR = preprocessedc
103 XGASMDIR = $(ASMDIR)$(PATHSEP)xgate
104 XGOBJDIR = $(OBJDIR)$(PATHSEP)xgate
106 # Release tag message file
107 RELTAG = $(OUTDIR)/gitTagMessage.txt
108 TAGNAME = $(OUTDIR)/gitTagName.txt
110 # Program prefixes, for the main cpu and for the xgate coprocessor
119 COPY = $(PREFIX)objcopy
120 DUMP = $(PREFIX)objdump
122 RE = $(PREFIX)readelf
129 ################################################################################
131 ################################################################################
134 # Indirect dependencies that can affect everything and cause a full rebuild
136 ASMH = 9S12XDP512asm.s
137 LINKER = memory.x regions.x hc9s12xdp512elfb.x
140 # Let's keep this to a bare minimum! If you write ASM code
141 # please provide an matching alternate C implementation too.
142 HANDASMS = flashBurn.s
145 ALLH = $(LINKER) $(MFILE) $(INCDIR)/$(ASMH)
147 # Warning : do not include .c files from inc/ as they are
148 # included into the other C files and automatically compiled.
151 FIXEDCLASSES = FixedConfig1.c FixedConfig2.c
152 LOOKUPCLASSES1 = IATTransferTable.c CHTTransferTable.c
153 LOOKUPCLASSES2 = MAFTransferTable.c TestTransferTable.c
154 FUELCLASSES = FuelTables.c FuelTables2.c
155 TIMECLASSES = TimingTables.c TimingTables2.c
156 TUNECLASSES = TunableConfig.c TunableConfig2.c
157 # Combined data files
158 DATARAW = $(FIXEDCLASSES) $(LOOKUPCLASSES1) $(LOOKUPCLASSES2) $(FUELCLASSES) $(TIMECLASSES) $(TUNECLASSES)
159 DATA = $(patsubst %.c,$(DATADIR)/%.c,$(DATARAW))
162 UTILCLASSES = tableLookup.c init.c utils.c globalConstants.c StaticBenchTest.c
163 MATHCLASSES = coreVarsGenerator.c derivedVarsGenerator.c fuelAndIgnitionCalcs.c outputScheduler.c decoderInterface.c
164 COMCLASSES = flashWrite.c commsCore.c blockDetailsLookup.c
165 ISRCLASSES = interrupts.c injectionISRs.c commsISRs.c realtimeISRs.c miscISRs.c xgateVectors.c
166 # Combined source code files
167 SOURCE = freeEMS.c staticInit.c main.c $(UTILCLASSES) $(MATHCLASSES) $(COMCLASSES) $(ISRCLASSES)
169 # All but the engine position/RPM combined here
170 CLASSES = $(SOURCE) $(DATA)
172 # Engine position/RPM here
173 # Special decoders are not for use running an engine
174 RPMSPECIAL = Listener.c BenchTest.c
175 # TODO: Automate file naming for the following 4 lines
176 RPMEVENTEETH = EvenTeeth-Both-12and1.c EvenTeeth-Both-8and1.c EvenTeeth-Both-3and1.c
177 RPMMISSINGTEETH = MissingTeeth-TestFile.c MissingTeeth-Cam-24minus1.c MissingTeeth-Crank-8minus1.c MissingTeeth-Crank-12minus1.c MissingTeeth-Crank-36minus1.c MissingTeeth-Crank-60minus2.c MissingTeeth-Cam-6minus2.c MissingTeeth-Crank-30minus2.c
178 RPMHALLOROPTICAL = HallOrOptical-Distributor-4of64.c HallOrOptical-Distributor-4of69.c
180 # Specific purpose per engine stuff here
181 RPMSPECIFICENGINE1 = MitsiAndMazda-CAS-4and1.c GM-LT1-CAS-360and8.c
182 # Insert your file above and get coding!
183 RPMCLASSESRAW = $(RPMSPECIAL) $(RPMEVENTEETH) $(RPMMISSINGTEETH) $(RPMHALLOROPTICAL) $(RPMVRDISTRIBUTOR) $(RPMSPECIFICENGINE1)
184 RPMCLASSES = $(patsubst %.c,$(DECDIR)/%.c,$(RPMCLASSESRAW))
191 DEPENDENCIES = $(patsubst %.c,$(DEPDIR)/%.d,$(CLASSES))
192 DDEPENDENCIES = $(patsubst %.c,$(DEPDIR)/%.dd,$(CLASSES))
193 PREPROCESSED = $(patsubst %.c,$(PPCDIR)/%.pp.c,$(CLASSES))
194 ASSEMBLIES = $(patsubst %.c,$(ASMDIR)/%.s,$(CLASSES))
195 OBJECTS = $(patsubst %.c,$(OBJDIR)/%.o,$(CLASSES))
196 HANDOBJECTS = $(patsubst %.s,$(OBJDIR)/%.o,$(HANDASMS))
197 DUMPS = $(patsubst %.c,$(BUGDIR)/%.dmp,$(CLASSES)) $(patsubst %.s,$(BUGDIR)/%.dmp,$(HANDASMS))
198 XGOBJECTS = $(patsubst %.s,$(XGOBJDIR)/%.o,$(XGASMSRCS))
200 # Convert RPM extensions
201 DEPENDENCIESRPM = $(patsubst %.c,$(DEPDIR)/%.d,$(RPMCLASSES))
202 DDEPENDENCIESRPM = $(patsubst %.c,$(DEPDIR)/%.dd,$(RPMCLASSES))
203 PREPROCESSEDRPM = $(patsubst %.c,$(PPCDIR)/%.pp.c,$(RPMCLASSES))
204 ASSEMBLIESRPM = $(patsubst %.c,$(ASMDIR)/%.s,$(RPMCLASSES))
205 OBJECTSRPM = $(patsubst %.c,$(OBJDIR)/%.o,$(RPMCLASSES)) #$(patsubst $(DECDIR???)%.s,$(OBJDIR)/%.o,$(RPMHANDASMS))
206 DUMPSRPM = $(patsubst %.c,$(BUGDIR)/%.dmp,$(RPMCLASSES)) #$(patsubst $(DECDIR???)%.s,$(BUGDIR)/%.dmp,$(RPMHANDASMS))
208 # Bring in all of the generated deps. Note, if these fail on the first pass of parsing, Make will generate them and reparse.
209 -include $(DEPENDENCIES) $(DEPENDENCIESRPM) $(DDEPENDENCIES) $(DDEPENDENCIESRPM)
211 # Convert to output files for source
212 ALLELFSC = $(patsubst $(DECDIR)/%.c,$(OUTDIR)/$(LABEL)-%.elf,$(RPMCLASSES))
213 ALLELFSASM = #$(patsubst %.s,$(OUTDIR)/$(LABEL)-%.elf,$(RPMHANDASMS))
214 ALLDMPSC = $(patsubst $(DECDIR)/%.c,$(BUGDIR)/$(LABEL)-%.dmp,$(RPMCLASSES))
215 ALLDMPSASM = #$(patsubst %.s,$(BUGDIR)/$(LABEL)-%.dmp,$(RPMHANDASMS))
216 ALLMAPSC = $(patsubst $(DECDIR)/%.c,$(BUGDIR)/$(LABEL)-%.map,$(RPMCLASSES))
217 ALLMAPSASM = #$(patsubst %.s,$(BUGDIR)/$(LABEL)-%.map,$(RPMHANDASMS))
218 ALLREADC = $(patsubst $(DECDIR)/%.c,$(BUGDIR)/$(LABEL)-%.ree,$(RPMCLASSES))
219 ALLREADASM = #$(patsubst %.s,$(BUGDIR)/$(LABEL)-%.ree,$(RPMHANDASMS))
220 ALLS19SC = $(patsubst $(DECDIR)/%.c,$(S19DIR)/$(LABEL)-%.s19,$(RPMCLASSES))
221 ALLS19SASM = #$(patsubst %.s,$(S19DIR)/$(LABEL)-%.s19,$(RPMHANDASMS))
223 # Convert to output files for as-is variants
224 ALLELFS = $(ALLELFSC) $(ALLELFSASM)
225 ALLDMPS = $(ALLDMPSC) $(ALLDMPSASM)
226 ALLMAPS = $(ALLMAPSC) $(ALLMAPSASM)
227 ALLREAD = $(ALLREADC) $(ALLREADASM)
228 ALLS19S = $(ALLS19SC) $(ALLS19SASM)
229 ALLSIZES = $(patsubst $(S19DIR)/%,$(OUTDIR)/%.txt,$(ALLS19S))
230 ALLDUMMY = $(patsubst $(S19DIR)/%,$(OUTDIR)/%.txt.dummy,$(ALLS19S))
231 ALLMD5S = $(patsubst $(S19DIR)/%,$(FIRMWAREDISTRIBUTIONDIR)/%.md5,$(ALLS19S))
232 ALLSHA1S = $(patsubst $(S19DIR)/%,$(FIRMWAREDISTRIBUTIONDIR)/%.sha1,$(ALLS19S))
233 ALLS19ZIPS = $(patsubst $(S19DIR)/%,$(FIRMWAREDISTRIBUTIONDIR)/%.zip,$(ALLS19S))
236 # Convert to output files for GC variants
237 GCDELFSC = $(patsubst $(DECDIR)/%.c,$(OUTDIR)/$(LABEL)-%.gc.elf,$(RPMCLASSES))
238 GCDELFSASM = #$(patsubst %.s,$(OUTDIR)/$(LABEL)-%.gc.elf,$(RPMHANDASMS))
239 GCDS19SC = $(patsubst $(DECDIR)/%.c,$(S19DIR)/$(LABEL)-%.gc.s19,$(RPMCLASSES))
240 GCDS19SASM = #$(patsubst %.s,$(S19DIR)/$(LABEL)-%.gc.s19,$(RPMHANDASMS))
241 GCDELFS = $(GCDELFSC) $(GCDELFSASM)
242 GCDS19S = $(GCDS19SC) $(GCDELFSASM)
243 GCDSIZES = $(patsubst $(S19DIR)/%,$(OUTDIR)/%.txt,$(GCDS19S))
244 GCDDUMMY = $(patsubst $(S19DIR)/%,$(OUTDIR)/%.txt.dummy,$(GCDS19S))
249 ################################################################################
250 # All Command Line Options #
251 ################################################################################
254 # M68hc1x GCC Options we may want : -minmax -mlong-calls
256 # http://www.gnu.org/software/m68hc11/m68hc11_gcc.html shows code size with different options used
257 # include debug info, optimise , 16 bit ints, hcs12 platform
258 GCCOPTS1 = -Wall -Werror -Winline -O -m68hcs12 -mshort -ffunction-sections -idirafter custom -idirafter default
259 GCCOPTS2 = -fomit-frame-pointer -msoft-reg-count=8 -mauto-incdec -fsigned-char
260 GCCOPTS = $(GCCOPTS1) $(GCCOPTS2) $(CLIFLAGS) -D FIRMWARE_VERSION=\"$(FIRMWARE_VERSION)\" -D FIRMWARE_BUILD_DATE=\"$(BUILD_DATE)\" -D OPERATING_SYSTEM=\"$(OS)\"
261 # -ffunction-sections option splits out the functions such that the garbage collection can get
262 # them on a per section basis. I'm not sure, but this could be harmful to paged code so may
263 # have to review this at a later date perhaps splitting paged functions from nonpaged ones.
265 # pass to linker, link for hc12
266 # The vectors address in the linker options is the VMA address and must be short form 0xF710, not a paged address.
267 LINKOPTS = -no-warn-mismatch,-defsym,vectors_addr=0xF710,-m,m68hc12elfb,-T,hc9s12xdp512elfb.x
268 LINKOPTSGC = -no-warn-mismatch,--gc-sections,--print-gc-sections,-defsym,vectors_addr=0xF710,-m,m68hc12elfb,-T,hc9s12xdp512elfb.x
269 # Use this to get a map dump when the linker fails in a confusing way : --print-map
271 # If using the below option for paged flash, the ADDRESS_TYPE
272 # field in the freeEMSloader script should be updated to match.
273 COPYOPTS = --output-target=srec \
274 --change-section-lma .fixedconf1+0xFD4000 \
275 --change-section-lma .fixedconf2+0xFD4000 \
276 --change-section-lma .text1+0xFD4000 \
277 --change-section-lma .text+0xFEC000 \
278 --change-section-lma .data+0xFEC000 \
279 --change-section-lma .vectors+0xFEC000 \
280 --change-section-lma .rodata+0xFEC000 \
281 --only-section=.fixedconf1 \
282 --only-section=.fixedconf2 \
283 --only-section=.text \
284 --only-section=.text1 \
285 --only-section=.data \
286 --only-section=.vectors \
287 --only-section=.rodata \
288 --change-section-lma .ppageE0X=0xE08800 \
289 --change-section-lma .ppageE1=0xE18000 \
290 --only-section=.ppageE0X \
291 --only-section=.ppageE1 \
292 --set-section-flags .ppageE1=alloc,load \
293 --change-section-lma .ppageF8=0xF88000 \
294 --change-section-lma .fpageF9=0xF98000 \
295 --change-section-lma .dpageF9=0xF9A000 \
296 --change-section-lma .ppageFE=0xFE8000 \
297 --only-section=.ppageF8 \
298 --only-section=.fpageF9 \
299 --only-section=.dpageF9 \
300 --only-section=.ppageFE \
301 --change-section-lma .fpageFA=0xFA8000 \
302 --change-section-lma .dpageFA=0xFAA000 \
303 --change-section-lma .fpageFB=0xFB8000 \
304 --change-section-lma .dpageFB1=0xFBA000 \
305 --change-section-lma .dpageFB2=0xFBA400 \
306 --change-section-lma .dpageFB3=0xFBA800 \
307 --change-section-lma .dpageFB4=0xFBAC00 \
308 --change-section-lma .dpageFB5=0xFBB000 \
309 --change-section-lma .dpageFB6=0xFBB400 \
310 --change-section-lma .dpageFB7=0xFBB800 \
311 --change-section-lma .dpageFB8=0xFBBC00 \
312 --change-section-lma .fpageFC=0xFC8000 \
313 --change-section-lma .dpageFC=0xFCA000 \
314 --only-section=.dpageFA \
315 --only-section=.fpageFA \
316 --only-section=.dpageFB1 \
317 --only-section=.dpageFB2 \
318 --only-section=.dpageFB3 \
319 --only-section=.dpageFB4 \
320 --only-section=.dpageFB5 \
321 --only-section=.dpageFB6 \
322 --only-section=.dpageFB7 \
323 --only-section=.dpageFB8 \
324 --only-section=.fpageFB \
325 --only-section=.dpageFC \
326 --only-section=.fpageFC
327 # --change-section-lma .ppageFD=0xFD8000 \
328 # --change-section-lma .ppageFF=0xFF8000 \
329 # --only-section=.ppageFD \ This is left here for clarity only (equivalent to text1 but paged)
330 # --only-section=.ppageFF This is left here for clarity only (equivalent to text but paged)
331 # Changes to the above options should be reflected in memory.x and memory.h also!
333 # The following flash areas should only be included if they are used.
334 # --only-section=.ppageE0S \
335 # --only-section=.ppageE2 \
336 # --only-section=.ppageE3 \
337 # --only-section=.ppageE4 \
338 # --only-section=.ppageE5 \
339 # --only-section=.ppageE6 \
340 # --only-section=.ppageE7 \
341 # --only-section=.ppageE8 \
342 # --only-section=.ppageE9 \
343 # --only-section=.ppageEA \
344 # --only-section=.ppageEB \
345 # --only-section=.ppageEC \
346 # --only-section=.ppageED \
347 # --only-section=.ppageEE \
348 # --only-section=.ppageEF \
349 # --only-section=.ppageF0 \
350 # --only-section=.ppageF1 \
351 # --only-section=.ppageF2 \
352 # --only-section=.ppageF3 \
353 # --only-section=.ppageF4 \
354 # --only-section=.ppageF5 \
355 # --only-section=.ppageF6 \
356 # --only-section=.ppageF7 \
357 # --change-section-lma .ppageE0S=0xE08000 \
358 # --change-section-lma .ppageE2=0xE28000 \
359 # --change-section-lma .ppageE3=0xE38000 \
360 # --change-section-lma .ppageE4=0xE48000 \
361 # --change-section-lma .ppageE5=0xE58000 \
362 # --change-section-lma .ppageE6=0xE68000 \
363 # --change-section-lma .ppageE7=0xE78000 \
364 # --change-section-lma .ppageE8=0xE88000 \
365 # --change-section-lma .ppageE9=0xE98000 \
366 # --change-section-lma .ppageEA=0xEA8000 \
367 # --change-section-lma .ppageEB=0xEB8000 \
368 # --change-section-lma .ppageEC=0xEC8000 \
369 # --change-section-lma .ppageED=0xED8000 \
370 # --change-section-lma .ppageEE=0xEE8000 \
371 # --change-section-lma .ppageEF=0xEF8000 \
372 # --change-section-lma .ppageF0=0xF08000 \
373 # --change-section-lma .ppageF1=0xF18000 \
374 # --change-section-lma .ppageF2=0xF28000 \
375 # --change-section-lma .ppageF3=0xF38000 \
376 # --change-section-lma .ppageF4=0xF48000 \
377 # --change-section-lma .ppageF5=0xF58000 \
378 # --change-section-lma .ppageF6=0xF68000 \
379 # --change-section-lma .ppageF7=0xF78000 \
383 .DEFAULT_GOAL := help
385 @echo $(Q)################################################################################$(Q)
386 @echo $(Q)# Dependency And Target Summary #$(Q)
387 @echo $(Q)################################################################################$(Q)
389 @echo $(Q)# Common targets: #$(Q)
391 @echo $(Q)# 1) help - This comment block #$(Q)
392 @echo $(Q)# 2) all - Executes alldebug, slow, slowgc and size #$(Q)
393 @echo $(Q)# 3) dirs - Creates all of the directories required to build #$(Q)
394 @echo $(Q)# 5) slow - Three stage compilation with assembly retained #$(Q)
395 @echo $(Q)# 6) slowgc - As above, but with garbage collection during linking #$(Q)
396 @echo $(Q)# 7) alldebug - Generates all debug output files #$(Q)
397 @echo $(Q)# 8) install - Not yet implemented #$(Q)
398 @echo $(Q)# 9) release - Performs a full release build #$(Q)
399 @echo $(Q)# 10) clean - Removes all files and directories generated by building #$(Q)
401 @echo $(Q)# Second level targets: #$(Q)
403 @echo $(Q)# Stage one: #$(Q)
405 @echo $(Q)# 1) preprocess - run the C preprocessor over the raw C files #$(Q)
406 @echo $(Q)# 2) compile - compile the preprocessed C into assembly #$(Q)
407 @echo $(Q)# 3) assemble - assemble the assembly files into object files #$(Q)
409 @echo $(Q)# Stage two #$(Q)
411 @echo $(Q)# 1) link - Generate ELFs objects #$(Q)
412 @echo $(Q)# 2) gclink - As above, but with garbage collection #$(Q)
413 @echo $(Q)# 3) s19 - Create s19s from elfs #$(Q)
414 @echo $(Q)# 4) gcs19 - Create s19s from gc elfs #$(Q)
415 @echo $(Q)# 5) sizes - Calculate the approximate s19 sizes #$(Q)
416 @echo $(Q)# 6) gcsizes - Calculate the approximate gc s19 sizes #$(Q)
418 @echo $(Q)# Stage three: #$(Q)
420 @echo $(Q)# 1) maps - Memory map files #$(Q)
421 @echo $(Q)# 2) rees - Readelf dumps #$(Q)
422 @echo $(Q)# 3) elfdmps - Classic objdump output for final elfs #$(Q)
423 @echo $(Q)# 4) objdmps - Classic objdump output for each object file #$(Q)
425 @echo $(Q)# When doing a full build the following steps are taken: #$(Q)
427 @echo $(Q)# 1) Pre-process all of the C files #$(Q)
428 @echo $(Q)# 2) Compile all preprocessed C files into assembly files #$(Q)
429 @echo $(Q)# 3) Assemble all assembly files into object files #$(Q)
430 @echo $(Q)# 4) Link each decoder without garbage collection #$(Q)
431 @echo $(Q)# 5) Produce a memory map for each elf #$(Q)
432 @echo $(Q)# 6) Produce a readelf dump for each elf #$(Q)
433 @echo $(Q)# 7) Dump the contents of each decoders elf #$(Q)
434 @echo $(Q)# 8) Dump the contents of all object files #$(Q)
435 @echo $(Q)# 9) Link each decoder with garbage collection and reporting turned on #$(Q)
436 @echo $(Q)# 10) Produce an s19 loadable firmware file for each elf #$(Q)
437 @echo $(Q)# 11) Measure each binary image approximately #$(Q)
438 @echo $(Q)# 12) Measure each decoder object file #$(Q)
439 @echo $(Q)# 13) Measure each other object file and summarise #$(Q)
441 @echo $(Q)# The release target: #$(Q)
443 @echo $(Q)# This target is purely for use by lead developers to produce a file set #$(Q)
444 @echo $(Q)# that is suitable for release and distribution to users and interested #$(Q)
445 @echo $(Q)# parties. The steps performed are listed below: #$(Q)
447 @echo $(Q)# 1) Checks that the repository is consistent #$(Q)
448 @echo $(Q)# 2) Performs a full clean #$(Q)
449 @echo $(Q)# 4) Removes the doxygen files #$(Q)
450 @echo $(Q)# 5) Builds binaries for each decoder type #$(Q)
451 @echo $(Q)# 7) Generates a new doxygen site #$(Q)
452 @echo $(Q)# 8) Performs a full clean #$(Q)
453 @echo $(Q)# 9) Commits the release files #$(Q)
454 @echo $(Q)# 10) Asks for a tag name and tag message #$(Q)
455 @echo $(Q)# 11) Tags the release at the automatic commit point #$(Q)
456 @echo $(Q)# 12) Generates md5 and sha1 checksums into the distribution directory #$(Q)
457 @echo $(Q)# 13) Zips the binaries into the distribution directory #$(Q)
458 @echo $(Q)# 14) Zips the doxygen site into the distribution directory #$(Q)
459 @echo $(Q)# 15) Zips the documentation into the distribution directory #$(Q)
460 @echo $(Q)# 16) Zips the repository into the distribution directory #$(Q)
461 @echo $(Q)# 17) Zips the source code into the distribution directory #$(Q)
463 @echo $(Q)# At that point the developer in charge of release has only to upload #$(Q)
464 @echo $(Q)# the files found in the distribution directory to appropriate locations #$(Q)
465 @echo $(Q)# and publicise the fact that a new release has been performed! This #$(Q)
466 @echo $(Q)# automation removes most opportunity for mistakes and makes release #$(Q)
467 @echo $(Q)# quality consistent between each successive release cycle! #$(Q)
469 @echo $(Q)# Unlisted targets: #$(Q)
471 @echo $(Q)# Additionally any of the output files can be used as a target directly. #$(Q)
472 @echo $(Q)# This is perfect for building only what is required for a specific s19. #$(Q)
473 @echo $(Q)# It is also perfect for working with a single file as you don't have to #$(Q)
474 @echo $(Q)# wait for other unrelated things to build first nor do you have to wait #$(Q)
475 @echo $(Q)# for other files to continue building after yours is successful. Before #$(Q)
476 @echo $(Q)# using individual output files for targets, please run 'make dirs'. #$(Q)
478 @echo $(Q)# Common goals: #$(Q)
480 @echo $(Q)# You most likely just want to run "make s19
" or "make
clean", do that! #$(Q)
482 @echo $(Q)# To build with a specific compiled in configuration do this instead: #$(Q)
484 @echo $(Q)# CLIFLAGS="-D YOURBUILDNAME
=1" make clean s19 #$(Q)
486 @echo $(Q)################################################################################$(Q)
491 ################################################################################
492 # All Target Dependencies #
493 ################################################################################
496 # Build everything the long way
497 all: alldebug gcsizes sizes size
498 # Multi stage compilation
500 # Multi stage compilation with garbage collection
502 # Clean all except release
503 clean: cleandep cleanasm cleanobj cleanout cleanppc cleans19 cleandebug
505 alldebug: maps rees elfdmps objdmps
506 # Load the s19 of your choice
507 #install: clean slow loader
509 release: testgit relbuildfull tagrelease
510 package: relbuildfull relpack1 relpack2 zipsite
511 publish: package deploydoxy deploy
512 publishnodoxy: packagenodoxy deploy
513 packagenodoxy: relbuildfirmware relpack1 relpack2
514 relbuildfull: clean cleandoxy gendoxy s19
515 relbuildfirmware: clean s19
516 relpack1: md5sums sha1sums s19zips
517 relpack2: zipdocs zipmain zipsrc
522 ################################################################################
523 # Debug Target Definitions #
524 ################################################################################
528 @echo $(Q)################################################################################$(Q)
529 @echo $(Q)# Generating memory maps.... #$(Q)
530 @echo $(Q)################################################################################$(Q)
532 maps: link $(BUGDIR) mapsmsg $(ALLMAPS)
534 $(ALLMAPS): $(BUGDIR)/%.map: $(OUTDIR)/%.elf
539 @echo $(Q)################################################################################$(Q)
540 @echo $(Q)# Reading all elf files... #$(Q)
541 @echo $(Q)################################################################################$(Q)
543 rees: link $(BUGDIR) reesmsg $(ALLREAD)
545 $(ALLREAD): $(BUGDIR)/%.ree: $(OUTDIR)/%.elf
550 @echo $(Q)################################################################################$(Q)
551 @echo $(Q)# Dumping all elf files... #$(Q)
552 @echo $(Q)################################################################################$(Q)
554 elfdmps: link $(BUGDIR) elfdmpsmsg $(ALLDMPS)
556 $(ALLDMPS): $(BUGDIR)/%.dmp: $(OUTDIR)/%.elf
557 $(DUMP) -spSd $< > $@
561 @echo $(Q)################################################################################$(Q)
562 @echo $(Q)# Dumping all object files.... #$(Q)
563 @echo $(Q)################################################################################$(Q)
565 objdmps: assemble $(BUGDIR) objdmpmsg $(DUMPS) $(DUMPSRPM)
567 $(DUMPS) $(DUMPSRPM): $(BUGDIR)/%.dmp: $(OBJDIR)/%.o
568 $(DUMP) -spSd $< > $@
573 ################################################################################
574 # Link and Copy Target Definitions #
575 ################################################################################
579 @echo $(Q)################################################################################$(Q)
580 @echo $(Q)# Linking the Objects into an ELF... #$(Q)
581 @echo $(Q)################################################################################$(Q)
583 link: assemble $(OUTDIR) linkmsg $(ALLELFS)
585 # link the object files into an elf executable
586 $(ALLELFS): $(OUTDIR)/$(LABEL)-%.elf: $(OBJDIR)/$(DECDIR)/%.o $(OBJECTS) $(HANDOBJECTS) $(XGOBJECTS)
587 @echo $(Q)################################################################################$(Q)
588 @echo $(Q)# Linking $@ ...$(Q)
589 @echo $(Q)################################################################################$(Q)
590 $(GCC) $(GCCOPTS) -Wl,$(LINKOPTS) -o $@ $(OBJECTS) $(HANDOBJECTS) $(XGOBJECTS) $<
594 @echo $(Q)################################################################################$(Q)
595 @echo $(Q)# Linking the Objects into an ELF... #$(Q)
596 @echo $(Q)################################################################################$(Q)
598 gclink: assemble $(OUTDIR) linkmsg $(GCDELFS)
600 # link the object files into an elf executable with gc enabled
601 $(GCDELFS): $(OUTDIR)/$(LABEL)-%.gc.elf: $(OBJDIR)/$(DECDIR)/%.o $(OBJECTS) $(HANDOBJECTS) $(XGOBJECTS)
602 @echo $(Q)################################################################################$(Q)
603 @echo $(Q)# Linking $@ ...$(Q)
604 @echo $(Q)################################################################################$(Q)
605 $(GCC) $(GCCOPTS) -Wl,$(LINKOPTSGC) -o $@ $(OBJECTS) $(HANDOBJECTS) $(XGOBJECTS) $<
606 # The links with garbage collection are to ensure that there are no warnings
607 # TODO find out how to stop .tramp from being collected (or inserted)!
608 # This will be the only way once Sean's stuff is done and distributed, I can't wait to cut all this bullshit out!
612 @echo $(Q)################################################################################$(Q)
613 @echo $(Q)# Building The S19 Files.... #$(Q)
614 @echo $(Q)################################################################################$(Q)
616 s19: link $(S19DIR) s19msg $(ALLS19S)
617 # the gc dependency is temporary until i figure out if the .tramp removal is an issue or not.
619 # Generate the loadable s19 firmware files
620 $(ALLS19S): $(S19DIR)/%.s19: $(OUTDIR)/%.elf
621 @echo $(Q)################################################################################$(Q)
622 @echo $(Q)# Building $@ ...$(Q)
623 @echo $(Q)################################################################################$(Q)
624 $(COPY) $(COPYOPTS) $< $@
628 @echo $(Q)################################################################################$(Q)
629 @echo $(Q)# Measuring The S19 Files... #$(Q)
630 @echo $(Q)################################################################################$(Q)
632 sizes: s19 $(OUTDIR) sizesmsg $(ALLDUMMY)
634 # Roughly measure the s19 sizes
635 $(ALLSIZES): $(OUTDIR)/%.txt: $(S19DIR)/%
636 @echo $(shell cat $< | wc -l) $(Q)* 16$(Q) > $@
638 # Have to do this in two stages to allow $(shell exp) use and portability to windows
639 $(ALLDUMMY): $(OUTDIR)/%.dummy: $(OUTDIR)/%
640 @echo $(Q)Flash image size is$(Q) $(shell cat $< | bc -l) $(Q)bytes for $<$(Q)
644 @echo $(Q)################################################################################$(Q)
645 @echo $(Q)# Building The GC S19 Files.... #$(Q)
646 @echo $(Q)################################################################################$(Q)
648 gcs19: gclink $(S19DIR) gcs19msg $(GCDS19S)
650 # Generate the garbage collected s19 files temporarily
651 $(GCDS19S): $(S19DIR)/%.s19: $(OUTDIR)/%.elf
652 @echo $(Q)################################################################################$(Q)
653 @echo $(Q)# Building $@ ...$(Q)
654 @echo $(Q)################################################################################$(Q)
655 $(COPY) $(COPYOPTS) $< $@
658 @echo $(Q)################################################################################$(Q)
659 @echo $(Q)# Measuring The GC S19 Files... #$(Q)
660 @echo $(Q)################################################################################$(Q)
662 gcsizes: gcs19 $(OUTDIR) gcsizesmsg $(GCDDUMMY)
664 # Roughly measure the gc s19 sizes
665 $(GCDSIZES): $(OUTDIR)/%.txt: $(S19DIR)/%
666 @echo $(shell cat $< | wc -l) $(Q)* 16$(Q) > $@
668 # Have to do this in two stages to allow $(shell exp) use and portability to windows
669 $(GCDDUMMY): $(OUTDIR)/%.dummy: $(OUTDIR)/%
670 @echo $(Q)Flash image size is$(Q) $(shell cat $< | bc -l) $(Q)bytes for $<$(Q)
676 ################################################################################
677 # Size Measuring Target Definition #
678 ################################################################################
681 size: assemble # TODO this should be run for each s19 target with only the one rpm .o file
682 @echo $(Q)################################################################################$(Q)
683 @echo $(Q)# Measuring The Decoder Binaries... #$(Q)
684 @echo $(Q)################################################################################$(Q)
685 $(SIZE) $(OBJECTSRPM)
686 @echo $(Q)################################################################################$(Q)
687 @echo $(Q)# Measuring All Other Binaries... #$(Q)
688 @echo $(Q)################################################################################$(Q)
689 $(SIZE) -t $(OBJECTS)
690 @echo $(Q)################################################################################$(Q)
691 @echo $(Q)# Add one decoder to the total above and #$(Q)
692 @echo $(Q)# subtract the size reported for freeEMS.o #$(Q)
693 @echo $(Q)# this will give you the actual image size #$(Q)
694 @echo $(Q)################################################################################$(Q)
696 @echo $(Q)# Thank you for building FreeEMS firmware!!! #$(Q)
698 @echo $(Q)################################################################################$(Q)
703 ################################################################################
704 # Preprocess, Compile and Assemble Target Definitions #
705 ################################################################################
709 @echo $(Q)################################################################################$(Q)
710 @echo $(Q)# Generating the dependencies... #$(Q)
711 @echo $(Q)################################################################################$(Q)
713 dependencies: dependenciesmsg $(DEPENDENCIES) $(DEPENDENCIESRPM) $(DDEPENDENCIES) $(DDEPENDENCIESRPM)
715 # Generate dependency files for recompilation on change semantics
716 $(DEPENDENCIES) $(DEPENDENCIESRPM): $(DEPDIR)/%.d: %.c $(ALLH)
717 $(GCC) $(CLIFLAGS) -MM -MF $@ -MT $(PPCDIR)/$*.pp.c $<
718 # Generate dependency files for the dependency files...
719 $(DDEPENDENCIES) $(DDEPENDENCIESRPM): $(DEPDIR)/%.dd: %.c $(ALLH)
720 $(GCC) $(CLIFLAGS) -MM -MF $@ -MT $(DEPDIR)/$*.d $<
724 @echo $(Q)################################################################################$(Q)
725 @echo $(Q)# Running the C Pre Processor... #$(Q)
726 @echo $(Q)################################################################################$(Q)
728 preprocess: $(PPCDIR) preprocessmsg $(PREPROCESSED) $(PREPROCESSEDRPM)
730 # Generate preprocessed source files to examine
731 $(PREPROCESSED): $(PPCDIR)/%.pp.c: %.c $(ALLH)
732 $(GCC) $(GCCOPTS) -D BASE_FILE_NAME=\"$*\" -E $< > $@
733 $(PREPROCESSEDRPM): $(PPCDIR)/decoders/%.pp.c: decoders/%.c $(ALLH)
734 $(GCC) $(GCCOPTS) -D BASE_FILE_NAME=\"$*\" -E $< > $@
738 @echo $(Q)################################################################################$(Q)
739 @echo $(Q)# Compiling PPC to Assembly... #$(Q)
740 @echo $(Q)################################################################################$(Q)
742 compile: preprocess compilemsg $(ASSEMBLIES) $(ASSEMBLIESRPM)
744 # Generate assembly files to examine
745 $(ASSEMBLIES) $(ASSEMBLIESRPM): $(ASMDIR)/%.s: $(PPCDIR)/%.pp.c
746 $(GCC) -g $(GCCOPTS) -x cpp-output -S -o $@ $<
750 @echo $(Q)################################################################################$(Q)
751 @echo $(Q)# Assembling Object Files... #$(Q)
752 @echo $(Q)################################################################################$(Q)
754 assemble: compile $(OBJDIR) $(XGOBJDIR) assemblemsg $(OBJECTS) $(HANDOBJECTS) $(OBJECTSRPM) $(XGOBJECTS)
756 # Generate object files to link
757 $(OBJECTS) $(OBJECTSRPM): $(OBJDIR)/%.o: $(ASMDIR)/%.s
758 $(GCC) $(GCCOPTS) -c -o $@ $<
760 $(HANDOBJECTS): $(OBJDIR)/%.o: $(ASMDIR)/%.s
761 $(GCC) -g $(GCCOPTS) -c -o $@ $<
763 $(XGOBJECTS): $(XGOBJDIR)/%.o: $(XGASMDIR)/%.s
768 ################################################################################
769 # Release Procedure Target Definitions #
770 ################################################################################
775 @echo "################################################################################"
776 @echo
"# Checking git status... #"
777 @echo
"################################################################################"
778 @echo
"Are we on master?"
779 test `git symbolic-ref HEAD` = refs
/heads
/master
780 @echo
"Is everything checked in?"
781 test `git status -s | wc -l` -eq
0
782 @echo
"Fetching from origin..."
784 @echo
"Are we behind?"
785 test `git rev-list \`git show-ref
--hash refs
/heads
/master\
`..\`git show-ref
--hash refs
/remotes
/origin/master\
` | wc -l` -eq
0
786 @echo
"Are we ahead?"
787 test `git rev-list \`git show-ref
--hash refs
/remotes
/origin/master\
`..\`git show-ref
--hash refs
/heads
/master\
` | wc -l` -eq
0
791 @echo
$(Q
)################################################################################$(Q)
792 @echo
$(Q
)# Generating MD5 Sums... #$(Q)
793 @echo
$(Q
)################################################################################$(Q)
795 md5sums
: s19 distributiondir md5sumsmsg
$(ALLMD5S
)
797 $(ALLMD5S
): $(FIRMWAREDISTRIBUTIONDIR
)/%.s19.md5
: $(S19DIR
)/%.s19
802 @echo
$(Q
)################################################################################$(Q)
803 @echo
$(Q
)# Generating SHA1 Sums... #$(Q)
804 @echo
$(Q
)################################################################################$(Q)
806 sha1sums
: s19 distributiondir sha1sumsmsg
$(ALLSHA1S
)
808 $(ALLSHA1S
): $(FIRMWAREDISTRIBUTIONDIR
)/%.s19.sha1
: $(S19DIR
)/%.s19
815 @echo
$(Q
)################################################################################$(Q)
816 @echo
$(Q
)# Zipping S19s... #$(Q)
817 @echo
$(Q
)################################################################################$(Q)
819 s19zips
: s19 distributiondir s19zipsmsg
$(ALLS19ZIPS
)
821 $(ALLS19ZIPS
): $(FIRMWAREDISTRIBUTIONDIR
)/%.s19.zip
: $(S19DIR
)/%.s19
832 tagrelease
: tagname tagmessage
833 git tag
-F
$(RELTAG
) `cat $(TAGNAME)` HEAD
836 zipmain
: distributiondir
837 cd ..
/ ; git archive
--format
=zip
--prefix=$(LABEL
)/ HEAD
> .
/tmp
/$(DISTRIBUTIONDIR
)/$(LABEL
)-full.zip
;cd
-
839 zipdocs
: distributiondir
840 cd ..
/ ; git archive
--format
=zip
--prefix=$(LABEL
)- HEAD docs
/ > .
/tmp
/$(DISTRIBUTIONDIR
)/$(LABEL
)-docs.zip
;cd
-
843 cd ..
/ ; ( cat docs
/Doxyfile
; echo
"PROJECT_NUMBER=$(FIRMWARE_VERSION)" ) | doxygen
- | grep Warning
> src
/doxygen.output
;cd
-
845 zipsite
: distributiondir gendoxy
846 cd ..
/docs
/ ; zip
-r
$(DISTRIBUTIONDIR
)/$(LABEL
)-doxygen-html.zip doxygen-html
/;cd
-
848 zipsrc
: distributiondir
849 cd ..
/ ; git archive
--format
=zip
--prefix=$(LABEL
)- HEAD src
/ > .
/tmp
/$(DISTRIBUTIONDIR
)/$(LABEL
)-src.zip
;cd
-
851 deploy
: distributiondir
852 scp
-r
$(DISTRIBUTIONDIR
) raptor
:/home
/firmware
/releases
/
855 scp
-r
$(DISTRIBUTIONDIR
)/$(LABEL
)-doxygen-html.zip raptor
:/home
/docs
/releases
/
856 ssh raptor unzip
/home
/docs
/releases
/$(LABEL
)-doxygen-html.zip
-d
/home
/docs
/releases
/
857 ssh raptor mv
/home
/docs
/releases
/doxygen-html
/ /home
/docs
/releases
/$(FIRMWARE_VERSION
)
862 ################################################################################
863 # Create Directory Target Definitions #
864 ################################################################################
866 # Assembly, release and inc directories don't get removed.
868 dirs
: $(BUGDIR
) $(S19DIR
) $(PPCDIR
) $(OUTDIR
) $(OBJDIR
) $(XGOBJDIR
)
871 @echo
$(Q
)################################################################################$(Q)
872 @echo
$(Q
)# Creating the debug directory.... #$(Q)
873 @echo
$(Q
)################################################################################$(Q)
874 $(MKDIR
) $(BUGDIR
)$(PATHSEP
)$(DECDIR
)$(PATHSEP
)hack
875 rmdir
$(BUGDIR
)$(PATHSEP
)$(DECDIR
)$(PATHSEP
)hack
876 $(MKDIR
) $(BUGDIR
)$(PATHSEP
)$(DATADIR
)$(PATHSEP
)hack
877 rmdir
$(BUGDIR
)$(PATHSEP
)$(DATADIR
)$(PATHSEP
)hack
880 @echo
$(Q
)################################################################################$(Q)
881 @echo
$(Q
)# Creating the firmware directory... #$(Q)
882 @echo
$(Q
)################################################################################$(Q)
883 $(MKDIR
) $(S19DIR
)$(PATHSEP
)hack
884 rmdir
$(S19DIR
)$(PATHSEP
)hack
887 @echo
$(Q
)################################################################################$(Q)
888 @echo
$(Q
)# Creating the preprocessedc directory.... #$(Q)
889 @echo
$(Q
)################################################################################$(Q)
890 $(MKDIR
) $(PPCDIR
)$(PATHSEP
)$(DECDIR
)$(PATHSEP
)hack
891 rmdir
$(PPCDIR
)$(PATHSEP
)$(DECDIR
)$(PATHSEP
)hack
892 $(MKDIR
) $(PPCDIR
)$(PATHSEP
)$(DATADIR
)$(PATHSEP
)hack
893 rmdir
$(PPCDIR
)$(PATHSEP
)$(DATADIR
)$(PATHSEP
)hack
896 @echo
$(Q
)################################################################################$(Q)
897 @echo
$(Q
)# Creating the output directory... #$(Q)
898 @echo
$(Q
)################################################################################$(Q)
899 $(MKDIR
) $(OUTDIR
)$(PATHSEP
)hack
900 rmdir
$(OUTDIR
)$(PATHSEP
)hack
903 @echo
$(Q
)################################################################################$(Q)
904 @echo
$(Q
)# Creating the object directory... #$(Q)
905 @echo
$(Q
)################################################################################$(Q)
906 $(MKDIR
) $(OBJDIR
)$(PATHSEP
)$(DECDIR
)$(PATHSEP
)hack
907 rmdir
$(OBJDIR
)$(PATHSEP
)$(DECDIR
)$(PATHSEP
)hack
908 $(MKDIR
) $(OBJDIR
)$(PATHSEP
)$(DATADIR
)$(PATHSEP
)hack
909 rmdir
$(OBJDIR
)$(PATHSEP
)$(DATADIR
)$(PATHSEP
)hack
912 @echo
$(Q
)################################################################################$(Q)
913 @echo
$(Q
)# Creating the xgate object directory... #$(Q)
914 @echo
$(Q
)################################################################################$(Q)
915 $(MKDIR
) $(XGOBJDIR
)$(PATHSEP
)hack
916 rmdir
$(XGOBJDIR
)$(PATHSEP
)hack
919 @echo
$(Q
)################################################################################$(Q)
920 @echo
$(Q
)# Creating the distribution directory... #$(Q)
921 @echo
$(Q
)################################################################################$(Q)
922 $(MKDIR
) $(FIRMWAREDISTRIBUTIONDIR
)$(PATHSEP
)hack
923 rmdir
$(FIRMWAREDISTRIBUTIONDIR
)$(PATHSEP
)hack
928 ################################################################################
929 # Clean Target Definitions #
930 ################################################################################
933 @echo
$(Q
)################################################################################$(Q)
934 @echo
$(Q
)# Removing generated assembly files.... #$(Q)
935 @echo
$(Q
)################################################################################$(Q)
936 $(RM
) $(ASSEMBLIES
) $(ASSEMBLIESRPM
)
939 @echo
$(Q
)################################################################################$(Q)
940 @echo
$(Q
)# Removing pre-processed C output directory... #$(Q)
941 @echo
$(Q
)################################################################################$(Q)
942 $(RM
) $(DEPDIR
)$(PATHSEP
)*.d
$(DEPDIR
)$(PATHSEP
)*.dd
943 $(RM
) $(DEPDIR
)$(PATHSEP
)$(DECDIR
)$(PATHSEP
)*.d
$(DEPDIR
)$(PATHSEP
)$(DECDIR
)$(PATHSEP
)*.dd
944 $(RM
) $(DEPDIR
)$(PATHSEP
)$(DATADIR
)$(PATHSEP
)*.d
$(DEPDIR
)$(PATHSEP
)$(DATADIR
)$(PATHSEP
)*.dd
947 @echo
$(Q
)################################################################################$(Q)
948 @echo
$(Q
)# Removing pre-processed C output directory... #$(Q)
949 @echo
$(Q
)################################################################################$(Q)
953 @echo
$(Q
)################################################################################$(Q)
954 @echo
$(Q
)# Removing object directory... #$(Q)
955 @echo
$(Q
)################################################################################$(Q)
959 @echo
$(Q
)################################################################################$(Q)
960 @echo
$(Q
)# Removing link output directory... #$(Q)
961 @echo
$(Q
)################################################################################$(Q)
965 @echo
$(Q
)################################################################################$(Q)
966 @echo
$(Q
)# Removing s19 directory... #$(Q)
967 @echo
$(Q
)################################################################################$(Q)
971 @echo
$(Q
)################################################################################$(Q)
972 @echo
$(Q
)# Removing debug directory... #$(Q)
973 @echo
$(Q
)################################################################################$(Q)
977 @echo
$(Q
)################################################################################$(Q)
978 @echo
$(Q
)# Removing Doxygen HTML... #$(Q)
979 @echo
$(Q
)################################################################################$(Q)
980 $(RM
) ..
/docs
/doxygen-html
/
983 ################################################################################
984 # Declare targets that aren't real files #
985 ################################################################################
988 # Aggregators top level
989 .PHONY
: all slow slowgc single help dirs
991 # Aggregators middle level
992 .PHONY
: dependencies preprocess compile assemble link gclink s19 gcs19 sizes gcsizes
994 # Aggregators debug level
995 .PHONY
: alldebug maps rees objdmps elfdmps size
998 .PHONY
: release relpack1 relpack2 package packagenodoxy publish publishnodoxy
999 .PHONY
: rebuildfull rebuildnodoxy relbuildfirmware deploy deploydoxy
1000 .PHONY
: md5sums sha1sums s19zips sha1sumsgc s19zips s19zipsgc
1001 .PHONY
: testgit tagname tagmessage tagrelease
1002 .PHONY
: zipmain zipdocs zipsite zipsrc
1005 .PHONY
: mapsmsg reesmsg elfdmpsmsg objdmpmsg linkmsg gclinkmsg
1006 .PHONY
: s19msg gcs19msg preprocessmsg compilemsg assemblemsg
1007 .PHONY
: md5sumsmsg sha1sumsmsg s19zipsmsg
1010 .PHONY
: clean cleandep cleanasm cleanppc cleanobj cleanout cleans19 cleandebug cleandoxy
1012 # Lonely documentation target :-(