Skip to content

Commit

Permalink
Switch project from error prone manual dependency management to autom…
Browse files Browse the repository at this point in the history
…atic dependency generation and maintenance. 9 lines less and better in every way. Thanks to STC for the example and motivation to finally do this.
  • Loading branch information
fredcooke committed Sep 28, 2011
1 parent 5b7cb89 commit 7f707c9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 46 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -14,6 +14,7 @@ docs/latex/*.pdf
docs/latex/*.ps
docs/latex/*.toc

src/dependencies/
src/firmware/
src/output/
src/preprocessedc/
Expand Down
82 changes: 36 additions & 46 deletions src/Makefile
Expand Up @@ -80,6 +80,7 @@ DISTRIBUTIONDIR = ../../$(LABEL)
DOXYDOCDIR = ../docs/doxygen-html
MAINDIR = freeems-vanilla
INCDIR = inc
DEPDIR = dependencies
DECDIR = decoders
DATADIR = initialisers
BUGDIR = debug
Expand Down Expand Up @@ -119,59 +120,18 @@ XGAS = $(XGPREFIX)as
################################################################################


# Indirect dependencies - any header change means a full recompile. This can be
# improved upon and made more specific. GCC actually has a function to output a
# dependency set for a C source file, maybe we should use that?
MAINH = main.h
INITH = init.h xgateVectors.h
UTILH = utils.h BenchTest.h
# Indirect dependencies that can affect everything and cause a full rebuild
MFILE = Makefile
ISRH = interrupts.h
CINCS = injectorISR.c
FLASHH = flashWrite.h flashGlobals.h flashBurn.h
ASMH = 9S12XDP512asm.s
LOOKUPH = tableLookup.h
ISRSH = commsISRs.h
COMMSH = commsCore.h blockDetailsLookup.h pagedLocationBuffers.h decodePacketAndRespond.h packetTypes.h locationIDs.h
LINKER = memory.x regions.x hc9s12xdp512elfb.x
GLOBALH1 = freeEMS.h 9S12XDP512.h memory.h globalConstants.h structs.h decoderInterface.h
GLOBALH2 = globalDefines.h errorDefines.h TunableConfigs.h FixedConfigs.h
FUELH = fuelAndIgnitionCalcs.h derivedVarsGenerator.h coreVarsGenerator.h
RPMH = Simple.h LT1-360-8.h MissingTeeth.h MitsiCAS-4and1.h
RPMC = Generic4Cylinder-HallOrOptical.c
DATACONF = defaultUteConfig.h
DATATABLESAXIS = FredsTruck-Load.h FredsTruck-RPM.h mainTable-Load.h mainTable-RPM.h
DATATABLESIGN = FE-DOHC.h flat15degrees.h flat0degrees.h FredsTruckIgnitionTiming.h
DATATABLESLAMBDA = flatStoichiometric.h FredsTruckLambda.h originalCurve.h
DATATABLESVE = flat80Percent.h FredsTruckVE.h
DATATHERMISTORS = $(DATAOLDTHERMISTORS) $(DATAGMTHERMISTORS) $(DATADENSOTHERMISTORS) $(DATABOSCHTHERMISTORS)
DATAOLDTHERMISTORS = Bosch.h
DATAGMTHERMISTORS = GM-2k0Bias.h GM-2k2Bias.h GM-2k49Bias.h GM-2k4Bias.h GM-2k6Bias.h GM-2k7Bias.h
DATADENSOTHERMISTORS = Denso-2k0Bias.h Denso-2k2Bias.h Denso-2k49Bias.h Denso-2k4Bias.h Denso-2k6Bias.h Denso-2k7Bias.h
DATABOSCHTHERMISTORS = BoschM12H-2k0Bias.h BoschM12H-2k2Bias.h BoschM12H-2k49Bias.h BoschM12H-2k4Bias.h BoschM12H-2k6Bias.h BoschM12H-2k7Bias.h


# Let's keep this to a bare minimum! If you write ASM code
# please provide an matching alternate C implementation too.
HANDASMS = flashBurn.s
#RPMHANDASMS =

# .c files from inc/ should be included here as deps for the parts they are relied on by!!
ALLHEADERS1 = $(GLOBALH1) $(COMMSH) $(ISRSH) $(UTILH) $(RPMH) $(FLASHH)
ALLHEADERS2 = $(GLOBALH2) $(FUELH) $(MAINH) $(INITH) $(ISRH) $(LOOKUPH)
DATAH1 = $(patsubst %.h,data/configuration/%.h,$(DATACONF))
DATAH2 = $(patsubst %.h,data/tables/axis/%.h,$(DATATABLESAXIS))
DATAH3 = $(patsubst %.h,data/tables/ign/%.h,$(DATATABLESIGN))
DATAH4 = $(patsubst %.h,data/tables/lambda/%.h,$(DATATABLESLAMBDA))
DATAH5 = $(patsubst %.h,data/tables/ve/%.h,$(DATATABLESVE))
DATAH6 = $(patsubst %.h,data/thermistors/%.h,$(DATATHERMISTORS))
ALLH1 = $(patsubst %.h,$(INCDIR)/%.h,$(ALLHEADERS1))
ALLH2 = $(patsubst %.h,$(INCDIR)/%.h,$(ALLHEADERS2))
ALLH3 = $(patsubst %.c,$(INCDIR)/%.c,$(CINCS))
ALLH4 = $(LINKER) $(MFILE) $(INCDIR)/$(ASMH)
ALLH5 = $(DATAH1) $(DATAH2) $(DATAH3) $(DATAH4) $(DATAH5) $(DATAH6)
RPMINC = $(patsubst %.c,decoders/%.c,$(RPMC))
ALLH = $(ALLH1) $(ALLH2) $(ALLH3) $(ALLH4) $(ALLH5) $(RPMINC)
ALLH = $(LINKER) $(MFILE) $(INCDIR)/$(ASMH)

# Warning : do not include .c files from inc/ as they are
# included into the other C files and automatically compiled.
Expand Down Expand Up @@ -209,18 +169,25 @@ XGASMSRCS = xgate.s


# Convert extensions
DEPENDENCIES = $(patsubst %.c,$(DEPDIR)/%.d,$(CLASSES))
DDEPENDENCIES = $(patsubst %.c,$(DEPDIR)/%.dd,$(CLASSES))
PREPROCESSED = $(patsubst %.c,$(PPCDIR)/%.pp.c,$(CLASSES))
ASSEMBLIES = $(patsubst %.c,$(ASMDIR)/%.s,$(CLASSES))
OBJECTS = $(patsubst %.c,$(OBJDIR)/%.o,$(CLASSES)) $(patsubst %.s,$(OBJDIR)/%.o,$(HANDASMS))
DUMPS = $(patsubst %.c,$(BUGDIR)/%.dmp,$(CLASSES)) $(patsubst %.s,$(BUGDIR)/%.dmp,$(HANDASMS))
XGOBJECTS = $(patsubst %.s,$(XGOBJDIR)/%.o,$(XGASMSRCS))

# Convert RPM extensions
DEPENDENCIESRPM = $(patsubst %.c,$(DEPDIR)/%.d,$(RPMCLASSES))
DDEPENDENCIESRPM = $(patsubst %.c,$(DEPDIR)/%.dd,$(RPMCLASSES))
PREPROCESSEDRPM = $(patsubst %.c,$(PPCDIR)/%.pp.c,$(RPMCLASSES))
ASSEMBLIESRPM = $(patsubst %.c,$(ASMDIR)/%.s,$(RPMCLASSES))
OBJECTSRPM = $(patsubst %.c,$(OBJDIR)/%.o,$(RPMCLASSES)) #$(patsubst $(DECDIR???)%.s,$(OBJDIR)/%.o,$(RPMHANDASMS))
DUMPSRPM = $(patsubst %.c,$(BUGDIR)/%.dmp,$(RPMCLASSES)) #$(patsubst $(DECDIR???)%.s,$(BUGDIR)/%.dmp,$(RPMHANDASMS))

# Bring in all of the generated deps. Note, if these fail on the first pass of parsing, Make will generate them and reparse.
-include $(DEPENDENCIES) $(DEPENDENCIESRPM) $(DDEPENDENCIES) $(DDEPENDENCIESRPM)

# Convert to output files for source
ALLELFSC = $(patsubst $(DECDIR)/%.c,$(OUTDIR)/$(LABEL)-%.elf,$(RPMCLASSES))
ALLELFSASM = #$(patsubst %.s,$(OUTDIR)/$(LABEL)-%.elf,$(RPMHANDASMS))
Expand Down Expand Up @@ -513,7 +480,7 @@ slow: sizes size
# Multi stage compilation with garbage collection
slowgc: gcsizes size
# Clean all except release
clean: cleanasm cleanobj cleanout cleanppc cleans19 cleandebug
clean: cleandep cleanasm cleanobj cleanout cleanppc cleans19 cleandebug
# Generate all debug
alldebug: maps rees elfdmps objdmps
# Load the s19 of your choice
Expand Down Expand Up @@ -726,6 +693,21 @@ size: assemble # TODO this should be run for each s19 target with only the one r
################################################################################


dependenciesmsg:
@echo $(Q)################################################################################$(Q)
@echo $(Q)# Generating the dependencies... #$(Q)
@echo $(Q)################################################################################$(Q)

dependencies: dependenciesmsg $(DEPENDENCIES) $(DEPENDENCIESRPM) $(DDEPENDENCIES) $(DDEPENDENCIESRPM)

# Generate dependency files for recompilation on change semantics
$(DEPENDENCIES) $(DEPENDENCIESRPM): $(DEPDIR)/%.d: %.c $(ALLH)
$(GCC) $(CLIFLAGS) -MM -MF $@ -MT $(PPCDIR)/$*.pp.c $<;
# Generate dependency files for the dependency files...
$(DDEPENDENCIES) $(DDEPENDENCIESRPM): $(DEPDIR)/%.dd: %.c $(ALLH)
$(GCC) $(CLIFLAGS) -MM -MF $@ -MT $(DEPDIR)/$*.d $<


preprocessmsg:
@echo $(Q)################################################################################$(Q)
@echo $(Q)# Running the C Pre Processor... #$(Q)
Expand All @@ -734,7 +716,7 @@ preprocessmsg:
preprocess: $(PPCDIR) preprocessmsg $(PREPROCESSED) $(PREPROCESSEDRPM)

# Generate preprocessed source files to examine
$(PREPROCESSED) $(PREPROCESSEDRPM): $(PPCDIR)/%.pp.c: %.c $(ALLH)
$(PREPROCESSED) $(PREPROCESSEDRPM): $(PPCDIR)/%.pp.c: %.c $(ALLH)
$(GCC) $(GCCOPTS) -E $< > $@


Expand Down Expand Up @@ -987,6 +969,14 @@ cleanasm:
@echo $(Q)################################################################################$(Q)
$(RM) $(ASSEMBLIES) $(ASSEMBLIESRPM)

cleandep:
@echo $(Q)################################################################################$(Q)
@echo $(Q)# Removing pre-processed C output directory... #$(Q)
@echo $(Q)################################################################################$(Q)
$(RM) $(DEPDIR)$(PATHSEP)*.d $(DEPDIR)$(PATHSEP)*.dd
$(RM) $(DEPDIR)$(PATHSEP)$(DECDIR)$(PATHSEP)*.d $(DEPDIR)$(PATHSEP)$(DECDIR)$(PATHSEP)*.dd
$(RM) $(DEPDIR)$(PATHSEP)$(DATADIR)$(PATHSEP)*.d $(DEPDIR)$(PATHSEP)$(DATADIR)$(PATHSEP)*.dd

cleanppc:
@echo $(Q)################################################################################$(Q)
@echo $(Q)# Removing pre-processed C output directory... #$(Q)
Expand Down Expand Up @@ -1056,7 +1046,7 @@ cleandoxy:
.PHONY: md5sumsmsg sha1sumsmsg s19zipsmsg

# Clean targets
.PHONY: clean cleanasm cleanppc cleanobj cleanout cleans19 cleandebug cleanrelease cleandoxy
.PHONY: clean cleandep cleanasm cleanppc cleanobj cleanout cleans19 cleandebug cleanrelease cleandoxy

# Lonely documentation target :-(
.PHONY: gendoxy
Empty file.
Empty file.

0 comments on commit 7f707c9

Please sign in to comment.