From 6700a74782379da2135eac395efb76dd0ec88cda Mon Sep 17 00:00:00 2001 From: stac Date: Wed, 23 Feb 2011 04:18:53 +0000 Subject: [PATCH] makefile: refactor makefiles and clean up output This significantly reduces the amount of duplication across the various firmware makefiles. The new firmware-defs.mk file should contain only macros/declarations that will apply to all firmware makefiles. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2854 ebee16cc-31ac-478f-84a7-5cbb03baadba --- flight/AHRS/Makefile | 215 ++++++------------------------- flight/CopterControl/Makefile | 233 ++++++---------------------------- flight/OpenPilot/Makefile | 163 ++++-------------------- flight/PipXtreme/Makefile | 221 ++++++-------------------------- make/firmware-defs.mk | 145 +++++++++++++++++++++ 5 files changed, 284 insertions(+), 693 deletions(-) create mode 100644 make/firmware-defs.mk diff --git a/flight/AHRS/Makefile b/flight/AHRS/Makefile index a543dc7fb..b0de38d0a 100644 --- a/flight/AHRS/Makefile +++ b/flight/AHRS/Makefile @@ -22,6 +22,9 @@ # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ##### +WHEREAMI := $(dir $(lastword $(MAKEFILE_LIST))) +TOP := $(realpath $(WHEREAMI)/../../) +include $(TOP)/make/firmware-defs.mk # Set developer code and compile options # Set to YES for debugging @@ -31,9 +34,6 @@ USE_BOOTLOADER ?= NO # Set to YES when using Code Sourcery toolchain CODE_SOURCERY ?= YES -# Toolchain prefix (i.e arm-elf- -> arm-elf-gcc.exe) -TCHAIN_PREFIX = arm-none-eabi- - ifeq ($(CODE_SOURCERY), YES) REMOVE_CMD = cs-rm else @@ -42,10 +42,6 @@ endif FLASH_TOOL = OPENOCD -# YES enables -mthumb option to flags for source-files listed -# in SRC and CPPSRC -USE_THUMB_MODE = YES - # MCU name, submodel and board # - MCU used for compiler-option (-mcpu) # - MODEL used for linker-script name (-T) and passed as define @@ -59,8 +55,9 @@ BOOT_MODEL = $(MODEL)_BL else BOOT_MODEL = $(MODEL)_NB endif + # Directory for output files (lst, obj, dep, elf, sym, map, hex, bin etc.) -OUTDIR = ../../build/ahrs +OUTDIR = $(TOP)/build/ahrs # Target file name (without extension). TARGET = AHRS @@ -263,7 +260,7 @@ CFLAGS += -g$(DEBUGF) CFLAGS += -ffast-math -CFLAGS += -mcpu=$(MCU) -mthumb +CFLAGS += -mcpu=$(MCU) CFLAGS += $(CDEFS) CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) -I. @@ -286,7 +283,7 @@ CONLYFLAGS += $(CSTANDARD) # Assembler flags. # -Wa,...: tell GCC to pass this to the assembler. # -ahlns: create listing -ASFLAGS = -mcpu=$(MCU) -mthumb -I. -x assembler-with-cpp +ASFLAGS = -mcpu=$(MCU) -I. -x assembler-with-cpp ASFLAGS += $(ADEFS) ASFLAGS += -Wa,-adhlns=$(addprefix $(OUTDIR)/, $(notdir $(addsuffix .lst, $(basename $<)))) ASFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) @@ -341,42 +338,11 @@ OOCD_CL+=-c "reset run" OOCD_CL+=-c shutdown # --------------------------------------------------------------------------- - # Define programs and commands. -CC = $(TCHAIN_PREFIX)gcc -CPP = $(TCHAIN_PREFIX)g++ -AR = $(TCHAIN_PREFIX)ar -OBJCOPY = $(TCHAIN_PREFIX)objcopy -OBJDUMP = $(TCHAIN_PREFIX)objdump -SIZE = $(TCHAIN_PREFIX)size -NM = $(TCHAIN_PREFIX)nm REMOVE = $(REMOVE_CMD) -f ###SHELL = sh ###COPY = cp - -# Define Messages -# English -MSG_ERRORS_NONE = Errors: none -MSG_BEGIN = "-------- begin (mode: $(RUN_MODE)) --------" -MSG_END = -------- end -------- -MSG_SIZE_BEFORE = Size before: -MSG_SIZE_AFTER = Size after build: -MSG_LOAD_FILE = Creating load file: -MSG_EXTENDED_LISTING = Creating Extended Listing/Disassembly: -MSG_SYMBOL_TABLE = Creating Symbol Table: -MSG_LINKING = "**** Linking :" -MSG_COMPILING = "**** Compiling C :" -MSG_COMPILING_ARM = "**** Compiling C (ARM-only):" -MSG_COMPILINGCPP = "Compiling C++ :" -MSG_COMPILINGCPP_ARM = "Compiling C++ (ARM-only):" -MSG_ASSEMBLING = "**** Assembling:" -MSG_ASSEMBLING_ARM = "****Assembling (ARM-only):" -MSG_CLEANING = Cleaning project: -MSG_FORMATERROR = Can not handle output-format -MSG_ASMFROMC = "Creating asm-File from C-Source:" -MSG_ASMFROMC_ARM = "Creating asm-File from C-Source (ARM-only):" - # List of all source files. ALLSRC = $(ASRCARM) $(ASRC) $(SRCARM) $(SRC) $(CPPSRCARM) $(CPPSRC) # List of all source files without directory and file-extension. @@ -390,15 +356,8 @@ LSTFILES = $(addprefix $(OUTDIR)/, $(addsuffix .lst, $(ALLSRCBASE))) # Define all depedency-files (used for make clean). DEPFILES = $(addprefix $(OUTDIR)/dep/, $(addsuffix .o.d, $(ALLSRCBASE))) -elf: $(OUTDIR)/$(TARGET).elf -lss: $(OUTDIR)/$(TARGET).lss -sym: $(OUTDIR)/$(TARGET).sym -hex: $(OUTDIR)/$(TARGET).hex -bin: $(OUTDIR)/$(TARGET).bin - # Default target. -#all: begin gccversion sizebefore build sizeafter finished end -all: begin gccversion build sizeafter finished end +all: gccversion build ifeq ($(LOADFORMAT),ihex) build: elf hex lss sym @@ -414,35 +373,6 @@ endif endif endif - -# Eye candy. -begin: -## @echo - @echo $(MSG_BEGIN) - -finished: -## @echo $(MSG_ERRORS_NONE) - -end: - @echo $(MSG_END) -## @echo - -# Display sizes of sections. -ELFSIZE = $(SIZE) -A $(OUTDIR)/$(TARGET).elf -##ELFSIZE = $(SIZE) --format=Berkeley --common $(OUTDIR)/$(TARGET).elf -sizebefore: -# @if [ -f $(OUTDIR)/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi - -sizeafter: -# @if [ -f $(OUTDIR)/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi - @echo $(MSG_SIZE_AFTER) - $(ELFSIZE) - -# Display compiler version information. -gccversion : - @$(CC) --version -# @echo $(ALLOBJ) - # Program the device. ifeq ($(USE_BOOTLOADER), YES) # Program the device with OP Upload Tool". @@ -458,134 +388,67 @@ program: $(OUTDIR)/$(TARGET).elf endif endif -# Create final output file (.hex) from ELF output file. -%.hex: %.elf -## @echo - @echo $(MSG_LOAD_FILE) $@ - $(OBJCOPY) -O ihex $< $@ - -# Create final output file (.bin) from ELF output file. -%.bin: %.elf -## @echo - @echo $(MSG_LOAD_FILE) $@ - $(OBJCOPY) -O binary $< $@ - -# Create extended listing file/disassambly from ELF output file. -# using objdump testing: option -C -%.lss: %.elf -## @echo - @echo $(MSG_EXTENDED_LISTING) $@ - $(OBJDUMP) -h -S -C -r $< > $@ -# $(OBJDUMP) -x -S $< > $@ - -# Create a symbol table from ELF output file. -%.sym: %.elf -## @echo - @echo $(MSG_SYMBOL_TABLE) $@ - $(NM) -n $< > $@ - # Link: create ELF output file from object files. -.SECONDARY : $(TARGET).elf -.PRECIOUS : $(ALLOBJ) -%.elf: $(ALLOBJ) - @echo - @echo $(MSG_LINKING) $@ -# use $(CC) for C-only projects or $(CPP) for C++-projects: - $(CC) $(THUMB) $(CFLAGS) $(ALLOBJ) --output $@ $(LDFLAGS) -# $(CPP) $(THUMB) $(CFLAGS) $(ALLOBJ) --output $@ $(LDFLAGS) - +$(eval $(call LINK_TEMPLATE, $(OUTDIR)/$(TARGET).elf, $(ALLOBJ))) # Assemble: create object files from assembler source files. -define ASSEMBLE_TEMPLATE -$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) -## @echo - @echo $(MSG_ASSEMBLING) $$< "->" $$@ - $(CC) -c $(THUMB) $$(ASFLAGS) $$< -o $$@ -endef $(foreach src, $(ASRC), $(eval $(call ASSEMBLE_TEMPLATE, $(src)))) # Assemble: create object files from assembler source files. ARM-only -define ASSEMBLE_ARM_TEMPLATE -$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) -## @echo - @echo $(MSG_ASSEMBLING_ARM) $$< "->" $$@ - $(CC) -c $$(ASFLAGS) $$< -o $$@ -endef $(foreach src, $(ASRCARM), $(eval $(call ASSEMBLE_ARM_TEMPLATE, $(src)))) - # Compile: create object files from C source files. -define COMPILE_C_TEMPLATE -$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) -## @echo - @echo $(MSG_COMPILING) $$< "->" $$@ - $(CC) -c $(THUMB) $$(CFLAGS) $$(CONLYFLAGS) $$< -o $$@ -endef $(foreach src, $(SRC), $(eval $(call COMPILE_C_TEMPLATE, $(src)))) # Compile: create object files from C source files. ARM-only -define COMPILE_C_ARM_TEMPLATE -$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) -## @echo - @echo $(MSG_COMPILING_ARM) $$< "->" $$@ - $(CC) -c $$(CFLAGS) $$(CONLYFLAGS) $$< -o $$@ -endef $(foreach src, $(SRCARM), $(eval $(call COMPILE_C_ARM_TEMPLATE, $(src)))) - # Compile: create object files from C++ source files. -define COMPILE_CPP_TEMPLATE -$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) -## @echo - @echo $(MSG_COMPILINGCPP) $$< "->" $$@ - $(CC) -c $(THUMB) $$(CFLAGS) $$(CPPFLAGS) $$< -o $$@ -endef $(foreach src, $(CPPSRC), $(eval $(call COMPILE_CPP_TEMPLATE, $(src)))) # Compile: create object files from C++ source files. ARM-only -define COMPILE_CPP_ARM_TEMPLATE -$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) -## @echo - @echo $(MSG_COMPILINGCPP_ARM) $$< "->" $$@ - $(CC) -c $$(CFLAGS) $$(CPPFLAGS) $$< -o $$@ -endef $(foreach src, $(CPPSRCARM), $(eval $(call COMPILE_CPP_ARM_TEMPLATE, $(src)))) - # Compile: create assembler files from C source files. ARM/Thumb -$(SRC:.c=.s) : %.s : %.c - @echo $(MSG_ASMFROMC) $< to $@ - $(CC) $(THUMB) -S $(CFLAGS) $(CONLYFLAGS) $< -o $@ +$(eval $(call PARTIAL_COMPILE_TEMPLATE, SRC)) # Compile: create assembler files from C source files. ARM only -$(SRCARM:.c=.s) : %.s : %.c - @echo $(MSG_ASMFROMC_ARM) $< to $@ - $(CC) -S $(CFLAGS) $(CONLYFLAGS) $< -o $@ +$(eval $(call PARTIAL_COMPILE_ARM_TEMPLATE, SRCARM)) + +.PHONY: elf lss sym hex bin +elf: $(OUTDIR)/$(TARGET).elf +lss: $(OUTDIR)/$(TARGET).lss +sym: $(OUTDIR)/$(TARGET).sym +hex: $(OUTDIR)/$(TARGET).hex +bin: $(OUTDIR)/$(TARGET).bin + +# Display sizes of sections. +$(eval $(call SIZE_TEMPLATE, $(OUTDIR)/$(TARGET).elf)) +.PHONY: size +size: $(OUTDIR)/$(TARGET).elf_size # Generate Doxygen documents docs: doxygen $(DOXYGENDIR)/doxygen.cfg # Target: clean project. -clean: begin clean_list finished end +clean: clean_list clean_list : -## @echo @echo $(MSG_CLEANING) - $(REMOVE) $(OUTDIR)/$(TARGET).map - $(REMOVE) $(OUTDIR)/$(TARGET).elf - $(REMOVE) $(OUTDIR)/$(TARGET).hex - $(REMOVE) $(OUTDIR)/$(TARGET).bin - $(REMOVE) $(OUTDIR)/$(TARGET).sym - $(REMOVE) $(OUTDIR)/$(TARGET).lss - $(REMOVE) $(ALLOBJ) - $(REMOVE) $(LSTFILES) - $(REMOVE) $(DEPFILES) - $(REMOVE) $(SRC:.c=.s) - $(REMOVE) $(SRCARM:.c=.s) - $(REMOVE) $(CPPSRC:.cpp=.s) - $(REMOVE) $(CPPSRCARM:.cpp=.s) - + $(V1) $(REMOVE) $(OUTDIR)/$(TARGET).map + $(V1) $(REMOVE) $(OUTDIR)/$(TARGET).elf + $(V1) $(REMOVE) $(OUTDIR)/$(TARGET).hex + $(V1) $(REMOVE) $(OUTDIR)/$(TARGET).bin + $(V1) $(REMOVE) $(OUTDIR)/$(TARGET).sym + $(V1) $(REMOVE) $(OUTDIR)/$(TARGET).lss + $(V1) $(REMOVE) $(ALLOBJ) + $(V1) $(REMOVE) $(LSTFILES) + $(V1) $(REMOVE) $(DEPFILES) + $(V1) $(REMOVE) $(SRC:.c=.s) + $(V1) $(REMOVE) $(SRCARM:.c=.s) + $(V1) $(REMOVE) $(CPPSRC:.cpp=.s) + $(V1) $(REMOVE) $(CPPSRCARM:.cpp=.s) # Create output files directory # all known MS Windows OS define the ComSpec environment variable @@ -604,6 +467,4 @@ endif # Listing of phony targets. -.PHONY : all begin finish end sizebefore sizeafter gccversion \ -build elf hex bin lss sym clean clean_list program - +.PHONY : all build clean clean_list program diff --git a/flight/CopterControl/Makefile b/flight/CopterControl/Makefile index 8cdab2eef..58f1deb61 100644 --- a/flight/CopterControl/Makefile +++ b/flight/CopterControl/Makefile @@ -22,6 +22,9 @@ # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ##### +WHEREAMI := $(dir $(lastword $(MAKEFILE_LIST))) +TOP := $(realpath $(WHEREAMI)/../../) +include $(TOP)/make/firmware-defs.mk # Set developer code and compile options # Set to YES to compile for debugging @@ -42,9 +45,6 @@ USE_SPEKTRUM ?= NO # Set to YES when using Code Sourcery toolchain CODE_SOURCERY ?= YES -# Toolchain prefix (i.e arm-elf- -> arm-elf-gcc.exe) -TCHAIN_PREFIX ?= arm-none-eabi- - # Remove command is different for Code Sourcery on Windows ifeq ($(CODE_SOURCERY), YES) REMOVE_CMD = cs-rm @@ -54,10 +54,6 @@ endif FLASH_TOOL = OPENOCD -# YES enables -mthumb option to flags for source-files listed -# in SRC and CPPSRC -USE_THUMB_MODE = YES - # List of modules to include MODULES = Telemetry Attitude Stabilization Actuator ManualControl #FirmwareIAP @@ -77,7 +73,7 @@ BOOT_MODEL = $(MODEL)_NB endif # Directory for output files (lst, obj, dep, elf, sym, map, hex, bin etc.) -OUTDIR = ../../build/coptercontrol +OUTDIR = $(TOP)/build/coptercontrol # Target file name (without extension). TARGET = CopterControl @@ -427,7 +423,7 @@ CFLAGS = -g$(DEBUGF) -DDEBUG endif CFLAGS += -O$(OPT) -CFLAGS += -mcpu=$(MCU) -mthumb +CFLAGS += -mcpu=$(MCU) CFLAGS += $(CDEFS) CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) -I. @@ -455,7 +451,7 @@ CONLYFLAGS += $(CSTANDARD) # Assembler flags. # -Wa,...: tell GCC to pass this to the assembler. # -ahlns: create listing -ASFLAGS = -mcpu=$(MCU) -mthumb -I. -x assembler-with-cpp +ASFLAGS = -mcpu=$(MCU) -I. -x assembler-with-cpp ASFLAGS += $(ADEFS) ASFLAGS += -Wa,-adhlns=$(addprefix $(OUTDIR)/, $(notdir $(addsuffix .lst, $(basename $<)))) ASFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) @@ -510,47 +506,12 @@ OOCD_CL+=-c "reset run" OOCD_CL+=-c shutdown # --------------------------------------------------------------------------- - # Define programs and commands. -CC = $(TCHAIN_PREFIX)gcc -CPP = $(TCHAIN_PREFIX)g++ -AR = $(TCHAIN_PREFIX)ar -OBJCOPY = $(TCHAIN_PREFIX)objcopy -OBJDUMP = $(TCHAIN_PREFIX)objdump -SIZE = $(TCHAIN_PREFIX)size -NM = $(TCHAIN_PREFIX)nm REMOVE = $(REMOVE_CMD) -f PYTHON = python ###SHELL = sh ###COPY = cp - - -# Define Messages -# English -MSG_ERRORS_NONE = Errors: none -MSG_BEGIN = ${quote}-------- begin (mode: $(RUN_MODE)) --------${quote} -MSG_END = ${quote}-------- end --------${quote} -MSG_OBJINIT = ${quote}**** Generating ObjInit.c${quote} -MSG_MODINIT = ${quote}**** Generating ModInit.c${quote} -MSG_SIZE_BEFORE = ${quote}Size before:${quote} -MSG_SIZE_AFTER = ${quote}Size after build:${quote} -MSG_LOAD_FILE = ${quote}Creating load file:${quote} -MSG_EXTENDED_LISTING = ${quote}Creating Extended Listing/Disassembly:${quote} -MSG_SYMBOL_TABLE = ${quote}Creating Symbol Table:${quote} -MSG_LINKING = ${quote}**** Linking :${quote} -MSG_COMPILING = ${quote}**** Compiling C :${quote} -MSG_COMPILING_ARM = ${quote}**** Compiling C (ARM-only):${quote} -MSG_COMPILINGCPP = ${quote}Compiling C++ :${quote} -MSG_COMPILINGCPP_ARM = ${quote}Compiling C++ (ARM-only):${quote} -MSG_ASSEMBLING = ${quote}**** Assembling:${quote} -MSG_ASSEMBLING_ARM = ${quote}****Assembling (ARM-only):${quote} -MSG_CLEANING = ${quote}Cleaning project:${quote} -MSG_FORMATERROR = ${quote}Can not handle output-format${quote} -MSG_ASMFROMC = ${quote}Creating asm-File from C-Source:${quote} -MSG_ASMFROMC_ARM = ${quote}Creating asm-File from C-Source (ARM-only):${quote} -MSG_PYMITEINIT = ${quote}**** Generating PyMite intermediate code${quote} - # List of all source files. ALLSRC = $(ASRCARM) $(ASRC) $(SRCARM) $(SRC) $(CPPSRCARM) $(CPPSRC) # List of all source files without directory and file-extension. @@ -564,15 +525,8 @@ LSTFILES = $(addprefix $(OUTDIR)/, $(addsuffix .lst, $(ALLSRCBASE))) # Define all depedency-files (used for make clean). DEPFILES = $(addprefix $(OUTDIR)/dep/, $(addsuffix .o.d, $(ALLSRCBASE))) -elf: $(OUTDIR)/$(TARGET).elf -lss: $(OUTDIR)/$(TARGET).lss -sym: $(OUTDIR)/$(TARGET).sym -hex: $(OUTDIR)/$(TARGET).hex -bin: $(OUTDIR)/$(TARGET).bin - # Default target. -#all: begin gccversion sizebefore build sizeafter finished end -all: begin gencode gccversion build sizeafter finished end +all: gencode build ifeq ($(LOADFORMAT),ihex) build: elf hex lss sym @@ -588,21 +542,12 @@ endif endif endif -# Test if quotes are needed for the echo-command -result = ${shell echo "test"} -ifeq (${result}, test) - quote = ' -else - quote = -endif - - # Generate intermediate code for objects gencode: ${OUTDIR}/InitMods.c # Generate code for module initialization ${OUTDIR}/InitMods.c: Makefile - @echo ${MSG_MODINIT} + @echo $(MSG_MODINIT) $(call toprel, $@) @echo ${quote}// Autogenerated file${quote} > ${OUTDIR}/InitMods.c @echo ${quote}${foreach MOD, ${MODNAMES}, extern unsigned int ${MOD}Initialize(void);}${quote} >> ${OUTDIR}/InitMods.c @echo ${quote}void InitModules() {${quote} >> ${OUTDIR}/InitMods.c @@ -611,39 +556,11 @@ ${OUTDIR}/InitMods.c: Makefile # Generate code for PyMite #$(OUTDIR)/pmlib_img.c $(OUTDIR)/pmlib_nat.c $(OUTDIR)/pmlibusr_img.c $(OUTDIR)/pmlibusr_nat.c $(OUTDIR)/pmfeatures.h: $(wildcard $(PYMITELIB)/*.py) $(wildcard $(PYMITEPLAT)/*.py) $(wildcard $(FLIGHTPLANLIB)/*.py) $(wildcard $(FLIGHTPLANS)/*.py) -# @echo ${MSG_PYMITEINIT} +# @echo $(MSG_PYMITEINIT) $(call toprel, $@) # @$(PYTHON) $(PYMITETOOLS)/pmImgCreator.py -f $(PYMITEPLAT)/pmfeatures.py -c -s --memspace=flash -o $(OUTDIR)/pmlib_img.c --native-file=$(OUTDIR)/pmlib_nat.c $(PYMITELIB)/list.py $(PYMITELIB)/dict.py $(PYMITELIB)/__bi.py $(PYMITELIB)/sys.py $(PYMITELIB)/string.py $(wildcard $(FLIGHTPLANLIB)/*.py) # @$(PYTHON) $(PYMITETOOLS)/pmGenPmFeatures.py $(PYMITEPLAT)/pmfeatures.py > $(OUTDIR)/pmfeatures.h # @$(PYTHON) $(PYMITETOOLS)/pmImgCreator.py -f $(PYMITEPLAT)/pmfeatures.py -c -u -o $(OUTDIR)/pmlibusr_img.c --native-file=$(OUTDIR)/pmlibusr_nat.c $(FLIGHTPLANS)/test.py -# Eye candy. -begin: -## @echo - @echo $(MSG_BEGIN) - -finished: -## @echo $(MSG_ERRORS_NONE) - -end: - @echo $(MSG_END) -## @echo - -# Display sizes of sections. -ELFSIZE = $(SIZE) -A $(OUTDIR)/$(TARGET).elf -##ELFSIZE = $(SIZE) --format=Berkeley --common $(OUTDIR)/$(TARGET).elf -sizebefore: -# @if [ -f $(OUTDIR)/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi - -sizeafter: -# @if [ -f $(OUTDIR)/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi - @echo $(MSG_SIZE_AFTER) - $(ELFSIZE) - -# Display compiler version information. -gccversion : - @$(CC) --version -# @echo $(ALLOBJ) - # Program the device. ifeq ($(USE_BOOTLOADER), YES) # Program the device with OP Upload Tool". @@ -659,134 +576,69 @@ program: $(OUTDIR)/$(TARGET).elf endif endif -# Create final output file (.hex) from ELF output file. -%.hex: %.elf -## @echo - @echo $(MSG_LOAD_FILE) $@ - $(OBJCOPY) -O ihex $< $@ - -# Create final output file (.bin) from ELF output file. -%.bin: %.elf -## @echo - @echo $(MSG_LOAD_FILE) $@ - $(OBJCOPY) -O binary $< $@ - -# Create extended listing file/disassambly from ELF output file. -# using objdump testing: option -C -%.lss: %.elf -## @echo - @echo $(MSG_EXTENDED_LISTING) $@ - $(OBJDUMP) -h -S -C -r $< > $@ -# $(OBJDUMP) -x -S $< > $@ - -# Create a symbol table from ELF output file. -%.sym: %.elf -## @echo - @echo $(MSG_SYMBOL_TABLE) $@ - $(NM) -n $< > $@ - # Link: create ELF output file from object files. -.SECONDARY : $(TARGET).elf -.PRECIOUS : $(ALLOBJ) -%.elf: $(ALLOBJ) - @echo $(MSG_LINKING) $@ -# use $(CC) for C-only projects or $(CPP) for C++-projects: - $(CC) $(THUMB) $(CFLAGS) $(ALLOBJ) --output $@ $(LDFLAGS) -# $(CPP) $(THUMB) $(CFLAGS) $(ALLOBJ) --output $@ $(LDFLAGS) +$(eval $(call LINK_TEMPLATE, $(OUTDIR)/$(TARGET).elf, $(ALLOBJ))) - # Assemble: create object files from assembler source files. -define ASSEMBLE_TEMPLATE -$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) -## @echo - @echo $(MSG_ASSEMBLING) $$< to $$@ - $(CC) -c $(THUMB) $$(ASFLAGS) $$< -o $$@ -endef $(foreach src, $(ASRC), $(eval $(call ASSEMBLE_TEMPLATE, $(src)))) # Assemble: create object files from assembler source files. ARM-only -define ASSEMBLE_ARM_TEMPLATE -$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) -## @echo - @echo $(MSG_ASSEMBLING_ARM) $$< to $$@ - $(CC) -c $$(ASFLAGS) $$< -o $$@ -endef $(foreach src, $(ASRCARM), $(eval $(call ASSEMBLE_ARM_TEMPLATE, $(src)))) - # Compile: create object files from C source files. -define COMPILE_C_TEMPLATE -$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) -## @echo - @echo $(MSG_COMPILING) $$< to $$@ - $(CC) -c $(THUMB) $$(CFLAGS) $$(CONLYFLAGS) $$< -o $$@ -endef $(foreach src, $(SRC), $(eval $(call COMPILE_C_TEMPLATE, $(src)))) # Compile: create object files from C source files. ARM-only -define COMPILE_C_ARM_TEMPLATE -$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) -## @echo - @echo $(MSG_COMPILING_ARM) $$< to $$@ - $(CC) -c $$(CFLAGS) $$(CONLYFLAGS) $$< -o $$@ -endef $(foreach src, $(SRCARM), $(eval $(call COMPILE_C_ARM_TEMPLATE, $(src)))) - # Compile: create object files from C++ source files. -define COMPILE_CPP_TEMPLATE -$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) -## @echo - @echo $(MSG_COMPILINGCPP) $$< to $$@ - $(CC) -c $(THUMB) $$(CFLAGS) $$(CPPFLAGS) $$< -o $$@ -endef $(foreach src, $(CPPSRC), $(eval $(call COMPILE_CPP_TEMPLATE, $(src)))) # Compile: create object files from C++ source files. ARM-only -define COMPILE_CPP_ARM_TEMPLATE -$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) -## @echo - @echo $(MSG_COMPILINGCPP_ARM) $$< to $$@ - $(CC) -c $$(CFLAGS) $$(CPPFLAGS) $$< -o $$@ -endef $(foreach src, $(CPPSRCARM), $(eval $(call COMPILE_CPP_ARM_TEMPLATE, $(src)))) - # Compile: create assembler files from C source files. ARM/Thumb -$(SRC:.c=.s) : %.s : %.c - @echo $(MSG_ASMFROMC) $< to $@ - $(CC) $(THUMB) -S $(CFLAGS) $(CONLYFLAGS) $< -o $@ +$(eval $(call PARTIAL_COMPILE_TEMPLATE, SRC)) # Compile: create assembler files from C source files. ARM only -$(SRCARM:.c=.s) : %.s : %.c - @echo $(MSG_ASMFROMC_ARM) $< to $@ - $(CC) -S $(CFLAGS) $(CONLYFLAGS) $< -o $@ +$(eval $(call PARTIAL_COMPILE_ARM_TEMPLATE, SRCARM)) + +.PHONY: elf lss sym hex bin +elf: $(OUTDIR)/$(TARGET).elf +lss: $(OUTDIR)/$(TARGET).lss +sym: $(OUTDIR)/$(TARGET).sym +hex: $(OUTDIR)/$(TARGET).hex +bin: $(OUTDIR)/$(TARGET).bin + +# Display sizes of sections. +$(eval $(call SIZE_TEMPLATE, $(OUTDIR)/$(TARGET).elf)) +.PHONY: size +size: $(OUTDIR)/$(TARGET).elf_size # Generate Doxygen documents docs: doxygen $(DOXYGENDIR)/doxygen.cfg # Target: clean project. -clean: begin clean_list finished end +clean: clean_list clean_list : -## @echo @echo $(MSG_CLEANING) - $(REMOVE) $(OUTDIR)/$(TARGET).map - $(REMOVE) $(OUTDIR)/$(TARGET).elf - $(REMOVE) $(OUTDIR)/$(TARGET).hex - $(REMOVE) $(OUTDIR)/$(TARGET).bin - $(REMOVE) $(OUTDIR)/$(TARGET).sym - $(REMOVE) $(OUTDIR)/$(TARGET).lss - $(REMOVE) $(wildcard $(OUTDIR)/*.c) - $(REMOVE) $(wildcard $(OUTDIR)/*.h) - $(REMOVE) $(ALLOBJ) - $(REMOVE) $(LSTFILES) - $(REMOVE) $(DEPFILES) - $(REMOVE) $(SRC:.c=.s) - $(REMOVE) $(SRCARM:.c=.s) - $(REMOVE) $(CPPSRC:.cpp=.s) - $(REMOVE) $(CPPSRCARM:.cpp=.s) + $(V1) $(REMOVE) $(OUTDIR)/$(TARGET).map + $(V1) $(REMOVE) $(OUTDIR)/$(TARGET).elf + $(V1) $(REMOVE) $(OUTDIR)/$(TARGET).hex + $(V1) $(REMOVE) $(OUTDIR)/$(TARGET).bin + $(V1) $(REMOVE) $(OUTDIR)/$(TARGET).sym + $(V1) $(REMOVE) $(OUTDIR)/$(TARGET).lss + $(V1) $(REMOVE) $(wildcard $(OUTDIR)/*.c) + $(V1) $(REMOVE) $(wildcard $(OUTDIR)/*.h) + $(V1) $(REMOVE) $(ALLOBJ) + $(V1) $(REMOVE) $(LSTFILES) + $(V1) $(REMOVE) $(DEPFILES) + $(V1) $(REMOVE) $(SRC:.c=.s) + $(V1) $(REMOVE) $(SRCARM:.c=.s) + $(V1) $(REMOVE) $(CPPSRC:.cpp=.s) + $(V1) $(REMOVE) $(CPPSRCARM:.cpp=.s) # Create output files directory @@ -804,9 +656,6 @@ else -include $(shell mkdir -p $(OUTDIR) 2>/dev/null) $(shell mkdir $(OUTDIR)/dep 2>/dev/null) $(wildcard $(OUTDIR)/dep/*) endif - - # Listing of phony targets. -.PHONY : all begin finish end sizebefore sizeafter gccversion \ -build elf hex bin lss sym clean clean_list program gencode +.PHONY : all build clean clean_list program gencode diff --git a/flight/OpenPilot/Makefile b/flight/OpenPilot/Makefile index 9e002fd6a..8731067e2 100644 --- a/flight/OpenPilot/Makefile +++ b/flight/OpenPilot/Makefile @@ -22,6 +22,9 @@ # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ##### +WHEREAMI := $(dir $(lastword $(MAKEFILE_LIST))) +TOP := $(realpath $(WHEREAMI)/../../) +include $(TOP)/make/firmware-defs.mk # Set developer code and compile options # Set to YES to compile for debugging @@ -42,9 +45,6 @@ USE_SPEKTRUM ?= NO # Set to YES when using Code Sourcery toolchain CODE_SOURCERY ?= YES -# Toolchain prefix (i.e arm-elf- -> arm-elf-gcc.exe) -TCHAIN_PREFIX ?= arm-none-eabi- - # Remove command is different for Code Sourcery on Windows ifeq ($(CODE_SOURCERY), YES) REMOVE_CMD = cs-rm @@ -54,10 +54,6 @@ endif FLASH_TOOL = OPENOCD -# YES enables -mthumb option to flags for source-files listed -# in SRC and CPPSRC -USE_THUMB_MODE = YES - # List of modules to include MODULES = Actuator Telemetry GPS ManualControl Altitude AHRSComms Stabilization Guidance FirmwareIAP FlightPlan @@ -83,13 +79,12 @@ BOOT_MODEL = $(MODEL)_NB endif # Directory for output files (lst, obj, dep, elf, sym, map, hex, bin etc.) -OUTDIR = ../../build/openpilot +OUTDIR = $(TOP)/build/openpilot # Target file name (without extension). TARGET = OpenPilot # Paths -TOP := $(realpath $(PWD))/ OPSYSTEM = ./System OPSYSTEMINC = $(OPSYSTEM)/inc OPUAVTALK = ../UAVTalk @@ -419,7 +414,7 @@ CFLAGS = -g$(DEBUGF) -DDEBUG endif CFLAGS += -O$(OPT) -CFLAGS += -mcpu=$(MCU) -mthumb +CFLAGS += -mcpu=$(MCU) CFLAGS += $(CDEFS) CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) -I. @@ -497,49 +492,12 @@ OOCD_CL+=-c "reset run" OOCD_CL+=-c shutdown # --------------------------------------------------------------------------- -# Test if quotes are needed for the echo-command -result = ${shell echo "test"} -ifeq (${result}, test) - quote = ' -# This line is just to clear out the single quote above ' -else - quote = -endif - # Define programs and commands. -CC = $(TCHAIN_PREFIX)gcc -CPP = $(TCHAIN_PREFIX)g++ -AR = $(TCHAIN_PREFIX)ar -OBJCOPY = $(TCHAIN_PREFIX)objcopy -OBJDUMP = $(TCHAIN_PREFIX)objdump -SIZE = $(TCHAIN_PREFIX)size -NM = $(TCHAIN_PREFIX)nm REMOVE = $(REMOVE_CMD) -f PYTHON = python ###SHELL = sh ###COPY = cp -# Define Messages -# English -MSG_FORMATERROR := ${quote} Can not handle output-format${quote} -MSG_MODINIT := ${quote} MODINIT ${quote} -MSG_SIZE_BEFORE := ${quote} Size before:${quote} -MSG_SIZE_AFTER := ${quote} Size after build:${quote} -MSG_LOAD_FILE := ${quote} BIN/HEX ${quote} -MSG_EXTENDED_LISTING := ${quote} LIS ${quote} -MSG_SYMBOL_TABLE := ${quote} NM ${quote} -MSG_LINKING := ${quote} LD ${quote} -MSG_COMPILING := ${quote} CC ${quote} -MSG_COMPILING_ARM := ${quote} CC-ARM ${quote} -MSG_COMPILINGCPP := ${quote} CXX ${quote} -MSG_COMPILINGCPP_ARM := ${quote} CXX-ARM ${quote} -MSG_ASSEMBLING := ${quote} AS ${quote} -MSG_ASSEMBLING_ARM := ${quote} AS-ARM ${quote} -MSG_CLEANING := ${quote} CLEAN ${quote} -MSG_ASMFROMC := ${quote} AS(C) ${quote} -MSG_ASMFROMC_ARM := ${quote} AS(C)-ARM ${quote} -MSG_PYMITEINIT := ${quote} PY ${quote} - # List of all source files. ALLSRC = $(ASRCARM) $(ASRC) $(SRCARM) $(SRC) $(CPPSRCARM) $(CPPSRC) # List of all source files without directory and file-extension. @@ -553,14 +511,8 @@ LSTFILES = $(addprefix $(OUTDIR)/, $(addsuffix .lst, $(ALLSRCBASE))) # Define all depedency-files (used for make clean). DEPFILES = $(addprefix $(OUTDIR)/dep/, $(addsuffix .o.d, $(ALLSRCBASE))) -elf: $(OUTDIR)/$(TARGET).elf -lss: $(OUTDIR)/$(TARGET).lss -sym: $(OUTDIR)/$(TARGET).sym -hex: $(OUTDIR)/$(TARGET).hex -bin: $(OUTDIR)/$(TARGET).bin - # Default target. -all: gencode gccversion build sizeafter +all: gencode gccversion build ifeq ($(LOADFORMAT),ihex) build: elf hex lss sym @@ -576,8 +528,6 @@ endif endif endif -toprel = $(subst $(realpath $(TOP))/,,$(abspath $(1))) - # Generate intermediate code gencode: ${OUTDIR}/InitMods.c ${OUTDIR}/pmlib_img.c ${OUTDIR}/pmlib_nat.c ${OUTDIR}/pmlibusr_img.c ${OUTDIR}/pmlibusr_nat.c ${OUTDIR}/pmfeatures.h @@ -597,22 +547,6 @@ ${OUTDIR}/pmlib_img.c ${OUTDIR}/pmlib_nat.c ${OUTDIR}/pmlibusr_img.c ${OUTDIR}/p @$(PYTHON) $(PYMITETOOLS)/pmGenPmFeatures.py $(PYMITEPLAT)/pmfeatures.py > $(OUTDIR)/pmfeatures.h @$(PYTHON) $(PYMITETOOLS)/pmImgCreator.py -f $(PYMITEPLAT)/pmfeatures.py -c -u -o $(OUTDIR)/pmlibusr_img.c --native-file=$(OUTDIR)/pmlibusr_nat.c $(FLIGHTPLANS)/test.py -# Display sizes of sections. -ELFSIZE = $(SIZE) -A $(OUTDIR)/$(TARGET).elf -##ELFSIZE = $(SIZE) --format=Berkeley --common $(OUTDIR)/$(TARGET).elf -sizebefore: -# @if [ -f $(OUTDIR)/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi - -sizeafter: -# @if [ -f $(OUTDIR)/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi - @echo $(MSG_SIZE_AFTER) - $(ELFSIZE) - -# Display compiler version information. -gccversion : - @$(CC) --version -# @echo $(ALLOBJ) - # Program the device. ifeq ($(USE_BOOTLOADER), YES) # Program the device with OP Upload Tool". @@ -628,94 +562,44 @@ program: $(OUTDIR)/$(TARGET).elf endif endif -# Create final output file (.hex) from ELF output file. -%.hex: %.elf - @echo $(MSG_LOAD_FILE) $@ - $(V1) $(OBJCOPY) -O ihex $< $@ - -# Create final output file (.bin) from ELF output file. -%.bin: %.elf - @echo $(MSG_LOAD_FILE) $@ - $(V1) $(OBJCOPY) -O binary $< $@ - -# Create extended listing file/disassambly from ELF output file. -# using objdump testing: option -C -%.lss: %.elf - @echo $(MSG_EXTENDED_LISTING) $@ - $(V1) $(OBJDUMP) -h -S -C -r $< > $@ - -# Create a symbol table from ELF output file. -%.sym: %.elf - @echo $(MSG_SYMBOL_TABLE) $@ - $(V1) $(NM) -n $< > $@ - # Link: create ELF output file from object files. -.SECONDARY : $(TARGET).elf -.PRECIOUS : $(ALLOBJ) -%.elf: $(ALLOBJ) - @echo $(MSG_LINKING) $(call toprel, $@) - $(V1) $(CC) $(THUMB) $(CFLAGS) $(ALLOBJ) --output $@ $(LDFLAGS) +$(eval $(call LINK_TEMPLATE, $(OUTDIR)/$(TARGET).elf, $(ALLOBJ))) # Assemble: create object files from assembler source files. -define ASSEMBLE_TEMPLATE -$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) - @echo $(MSG_ASSEMBLING) $$(call toprel, $$<) - $(V1) $(CC) -c $(THUMB) $$(ASFLAGS) $$< -o $$@ -endef $(foreach src, $(ASRC), $(eval $(call ASSEMBLE_TEMPLATE, $(src)))) # Assemble: create object files from assembler source files. ARM-only -define ASSEMBLE_ARM_TEMPLATE -$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) - @echo $(MSG_ASSEMBLING_ARM) $$(call toprel, $$<) - $(V1) $(CC) -c $$(ASFLAGS) $$< -o $$@ -endef $(foreach src, $(ASRCARM), $(eval $(call ASSEMBLE_ARM_TEMPLATE, $(src)))) - # Compile: create object files from C source files. -define COMPILE_C_TEMPLATE -$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) - @echo $(MSG_COMPILING) $$(call toprel, $$<) - $(V1) $(CC) -c $(THUMB) $$(CFLAGS) $$(CONLYFLAGS) $$< -o $$@ -endef $(foreach src, $(SRC), $(eval $(call COMPILE_C_TEMPLATE, $(src)))) # Compile: create object files from C source files. ARM-only -define COMPILE_C_ARM_TEMPLATE -$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) - @echo $(MSG_COMPILING_ARM) $$(call toprel, $$<) - $(V1) $(CC) -c $$(CFLAGS) $$(CONLYFLAGS) $$< -o $$@ -endef $(foreach src, $(SRCARM), $(eval $(call COMPILE_C_ARM_TEMPLATE, $(src)))) - # Compile: create object files from C++ source files. -define COMPILE_CPP_TEMPLATE -$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) - @echo $(MSG_COMPILINGCPP) $$(call toprel, $$<) - $(V1) $(CC) -c $(THUMB) $$(CFLAGS) $$(CPPFLAGS) $$< -o $$@ -endef $(foreach src, $(CPPSRC), $(eval $(call COMPILE_CPP_TEMPLATE, $(src)))) # Compile: create object files from C++ source files. ARM-only -define COMPILE_CPP_ARM_TEMPLATE -$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) - @echo $(MSG_COMPILINGCPP_ARM) $$(call toprel, $$<) - $(V1) $(CC) -c $$(CFLAGS) $$(CPPFLAGS) $$< -o $$@ -endef $(foreach src, $(CPPSRCARM), $(eval $(call COMPILE_CPP_ARM_TEMPLATE, $(src)))) - # Compile: create assembler files from C source files. ARM/Thumb -$(SRC:.c=.s) : %.s : %.c - @echo $(MSG_ASMFROMC) ${quote}$(call toprel, $<)${quote} - $(V1) $(CC) $(THUMB) -S $(CFLAGS) $(CONLYFLAGS) $< -o $@ +$(eval $(call PARTIAL_COMPILE_TEMPLATE, SRC)) # Compile: create assembler files from C source files. ARM only -$(SRCARM:.c=.s) : %.s : %.c - @echo $(MSG_ASMFROMC_ARM) ${quote}$(call toprel, $<)${quote} - $(V1) $(CC) -S $(CFLAGS) $(CONLYFLAGS) $< -o $@ +$(eval $(call PARTIAL_COMPILE_ARM_TEMPLATE, SRCARM)) + +.PHONY: elf lss sym hex bin +elf: $(OUTDIR)/$(TARGET).elf +lss: $(OUTDIR)/$(TARGET).lss +sym: $(OUTDIR)/$(TARGET).sym +hex: $(OUTDIR)/$(TARGET).hex +bin: $(OUTDIR)/$(TARGET).bin + +# Display sizes of sections. +$(eval $(call SIZE_TEMPLATE, $(OUTDIR)/$(TARGET).elf)) +.PHONY: size +size: $(OUTDIR)/$(TARGET).elf_size # Generate Doxygen documents docs: @@ -758,9 +642,6 @@ else -include $(shell mkdir -p $(OUTDIR) 2>/dev/null) $(shell mkdir $(OUTDIR)/dep 2>/dev/null) $(wildcard $(OUTDIR)/dep/*) endif - - # Listing of phony targets. -.PHONY : all sizebefore sizeafter gccversion \ -build elf hex bin lss sym clean clean_list program gencode +.PHONY : all build clean clean_list program gencode diff --git a/flight/PipXtreme/Makefile b/flight/PipXtreme/Makefile index 9083bbbd9..94bcbd68e 100644 --- a/flight/PipXtreme/Makefile +++ b/flight/PipXtreme/Makefile @@ -22,6 +22,9 @@ # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ##### +WHEREAMI := $(dir $(lastword $(MAKEFILE_LIST))) +TOP := $(realpath $(WHEREAMI)/../../) +include $(TOP)/make/firmware-defs.mk # Debugging (YES/NO) ? DEBUG ?= NO @@ -32,29 +35,17 @@ USE_BOOTLOADER ?= NO # Use Code Sourcery toolchain (YES/NO) ? CODE_SOURCERY ?= YES -# Toolchain prefix (i.e arm-elf- -> arm-elf-gcc.exe) -TCHAIN_PREFIX = arm-none-eabi- - ifeq ($(CODE_SOURCERY), YES) REMOVE_CMD = cs-rm else REMOVE_CMD = rm endif - FLASH_TOOL = OPENOCD - -# YES enables -mthumb option to flags for source-files listed in SRC and CPPSRC -USE_THUMB_MODE = YES - - - # Include the USB files (YES/NO) ? USE_USB = YES - - # MCU name, submodel and board # - MCU used for compiler-option (-mcpu) # - MODEL used for linker-script name (-T) and passed as define @@ -72,7 +63,7 @@ BOOT_MODEL = $(MODEL)_NB endif # Directory for output files (lst, obj, dep, elf, sym, map, hex, bin etc.) -OUTDIR = ../../build/pipxtreme +OUTDIR = $(TOP)/build/pipxtreme # Target file name (without extension). TARGET = PipXtreme @@ -311,7 +302,7 @@ CFLAGS += -O$(OPT) ifeq ($(DEBUG),NO) CFLAGS += -fdata-sections -ffunction-sections endif -CFLAGS += -mcpu=$(MCU) -mthumb +CFLAGS += -mcpu=$(MCU) CFLAGS += $(CDEFS) CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) -I. @@ -334,7 +325,7 @@ CONLYFLAGS += $(CSTANDARD) # Assembler flags. # -Wa,...: tell GCC to pass this to the assembler. # -ahlns: create listing -ASFLAGS = -mcpu=$(MCU) -mthumb -I. -x assembler-with-cpp +ASFLAGS = -mcpu=$(MCU) -I. -x assembler-with-cpp ASFLAGS += $(ADEFS) ASFLAGS += -Wa,-adhlns=$(addprefix $(OUTDIR)/, $(notdir $(addsuffix .lst, $(basename $<)))) ASFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) @@ -394,40 +385,10 @@ OOCD_CL+=-c shutdown # Define programs and commands. -CC = $(TCHAIN_PREFIX)gcc -CPP = $(TCHAIN_PREFIX)g++ -AR = $(TCHAIN_PREFIX)ar -OBJCOPY = $(TCHAIN_PREFIX)objcopy -OBJDUMP = $(TCHAIN_PREFIX)objdump -SIZE = $(TCHAIN_PREFIX)size -NM = $(TCHAIN_PREFIX)nm REMOVE = $(REMOVE_CMD) -f ###SHELL = sh ###COPY = cp - -# Define Messages -# English -MSG_ERRORS_NONE = Errors: none -MSG_BEGIN = "-------- begin (mode: $(RUN_MODE)) --------" -MSG_END = -------- end -------- -MSG_SIZE_BEFORE = Size before: -MSG_SIZE_AFTER = Size after build: -MSG_LOAD_FILE = Creating load file: -MSG_EXTENDED_LISTING = Creating Extended Listing/Disassembly: -MSG_SYMBOL_TABLE = Creating Symbol Table: -MSG_LINKING = "**** Linking :" -MSG_COMPILING = "**** Compiling C :" -MSG_COMPILING_ARM = "**** Compiling C (ARM-only):" -MSG_COMPILINGCPP = "Compiling C++ :" -MSG_COMPILINGCPP_ARM = "Compiling C++ (ARM-only):" -MSG_ASSEMBLING = "**** Assembling:" -MSG_ASSEMBLING_ARM = "****Assembling (ARM-only):" -MSG_CLEANING = Cleaning project: -MSG_FORMATERROR = Can not handle output-format -MSG_ASMFROMC = "Creating asm-File from C-Source:" -MSG_ASMFROMC_ARM = "Creating asm-File from C-Source (ARM-only):" - # List of all source files. ALLSRC = $(ASRCARM) $(ASRC) $(SRCARM) $(SRC) $(CPPSRCARM) $(CPPSRC) # List of all source files without directory and file-extension. @@ -441,15 +402,8 @@ LSTFILES = $(addprefix $(OUTDIR)/, $(addsuffix .lst, $(ALLSRCBASE))) # Define all depedency-files (used for make clean). DEPFILES = $(addprefix $(OUTDIR)/dep/, $(addsuffix .o.d, $(ALLSRCBASE))) -elf: $(OUTDIR)/$(TARGET).elf -lss: $(OUTDIR)/$(TARGET).lss -sym: $(OUTDIR)/$(TARGET).sym -hex: $(OUTDIR)/$(TARGET).hex -bin: $(OUTDIR)/$(TARGET).bin - # Default target. -#all: begin gccversion sizebefore build sizeafter finished end -all: begin gccversion build sizeafter finished end +all: build ifeq ($(LOADFORMAT),ihex) build: elf hex lss sym @@ -465,35 +419,6 @@ endif endif endif - -# Eye candy. -begin: -## @echo - @echo $(MSG_BEGIN) - -finished: -## @echo $(MSG_ERRORS_NONE) - -end: - @echo $(MSG_END) -## @echo - -# Display sizes of sections. -ELFSIZE = $(SIZE) -A $(OUTDIR)/$(TARGET).elf -##ELFSIZE = $(SIZE) --format=Berkeley --common $(OUTDIR)/$(TARGET).elf -sizebefore: -# @if [ -f $(OUTDIR)/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi - -sizeafter: -# @if [ -f $(OUTDIR)/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi - @echo $(MSG_SIZE_AFTER) - $(ELFSIZE) - -# Display compiler version information. -gccversion : - @$(CC) --version -# @echo $(ALLOBJ) - # Program the device. ifeq ($(USE_BOOTLOADER), YES) # Program the device with OP Upload Tool". @@ -509,133 +434,67 @@ program: $(OUTDIR)/$(TARGET).elf endif endif -# Create final output file (.hex) from ELF output file. -%.hex: %.elf -## @echo - @echo $(MSG_LOAD_FILE) $@ - $(OBJCOPY) -O ihex $< $@ - -# Create final output file (.bin) from ELF output file. -%.bin: %.elf -## @echo - @echo $(MSG_LOAD_FILE) $@ - $(OBJCOPY) -O binary $< $@ - -# Create extended listing file/disassambly from ELF output file. -# using objdump testing: option -C -%.lss: %.elf -## @echo - @echo $(MSG_EXTENDED_LISTING) $@ - $(OBJDUMP) -h -S -C -r $< > $@ -# $(OBJDUMP) -x -S $< > $@ - -# Create a symbol table from ELF output file. -%.sym: %.elf -## @echo - @echo $(MSG_SYMBOL_TABLE) $@ - $(NM) -n $< > $@ - # Link: create ELF output file from object files. -.SECONDARY : $(TARGET).elf -.PRECIOUS : $(ALLOBJ) -%.elf: $(ALLOBJ) - @echo - @echo $(MSG_LINKING) $@ -# use $(CC) for C-only projects or $(CPP) for C++-projects: - $(CC) $(THUMB) $(CFLAGS) $(ALLOBJ) --output $@ $(LDFLAGS) -# $(CPP) $(THUMB) $(CFLAGS) $(ALLOBJ) --output $@ $(LDFLAGS) - +$(eval $(call LINK_TEMPLATE, $(OUTDIR)/$(TARGET).elf, $(ALLOBJ))) # Assemble: create object files from assembler source files. -define ASSEMBLE_TEMPLATE -$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) -## @echo - @echo $(MSG_ASSEMBLING) $$< "->" $$@ - $(CC) -c $(THUMB) $$(ASFLAGS) $$< -o $$@ -endef $(foreach src, $(ASRC), $(eval $(call ASSEMBLE_TEMPLATE, $(src)))) # Assemble: create object files from assembler source files. ARM-only -define ASSEMBLE_ARM_TEMPLATE -$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) -## @echo - @echo $(MSG_ASSEMBLING_ARM) $$< "->" $$@ - $(CC) -c $$(ASFLAGS) $$< -o $$@ -endef $(foreach src, $(ASRCARM), $(eval $(call ASSEMBLE_ARM_TEMPLATE, $(src)))) - # Compile: create object files from C source files. -define COMPILE_C_TEMPLATE -$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) -## @echo - @echo $(MSG_COMPILING) $$< "->" $$@ - $(CC) -c $(THUMB) $$(CFLAGS) $$(CONLYFLAGS) $$< -o $$@ -endef $(foreach src, $(SRC), $(eval $(call COMPILE_C_TEMPLATE, $(src)))) # Compile: create object files from C source files. ARM-only -define COMPILE_C_ARM_TEMPLATE -$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) -## @echo - @echo $(MSG_COMPILING_ARM) $$< "->" $$@ - $(CC) -c $$(CFLAGS) $$(CONLYFLAGS) $$< -o $$@ -endef $(foreach src, $(SRCARM), $(eval $(call COMPILE_C_ARM_TEMPLATE, $(src)))) - # Compile: create object files from C++ source files. -define COMPILE_CPP_TEMPLATE -$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) -## @echo - @echo $(MSG_COMPILINGCPP) $$< "->" $$@ - $(CC) -c $(THUMB) $$(CFLAGS) $$(CPPFLAGS) $$< -o $$@ -endef $(foreach src, $(CPPSRC), $(eval $(call COMPILE_CPP_TEMPLATE, $(src)))) # Compile: create object files from C++ source files. ARM-only -define COMPILE_CPP_ARM_TEMPLATE -$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) -## @echo - @echo $(MSG_COMPILINGCPP_ARM) $$< "->" $$@ - $(CC) -c $$(CFLAGS) $$(CPPFLAGS) $$< -o $$@ -endef $(foreach src, $(CPPSRCARM), $(eval $(call COMPILE_CPP_ARM_TEMPLATE, $(src)))) - # Compile: create assembler files from C source files. ARM/Thumb -$(SRC:.c=.s) : %.s : %.c - @echo $(MSG_ASMFROMC) $< to $@ - $(CC) $(THUMB) -S $(CFLAGS) $(CONLYFLAGS) $< -o $@ +$(eval $(call PARTIAL_COMPILE_TEMPLATE, SRC)) # Compile: create assembler files from C source files. ARM only -$(SRCARM:.c=.s) : %.s : %.c - @echo $(MSG_ASMFROMC_ARM) $< to $@ - $(CC) -S $(CFLAGS) $(CONLYFLAGS) $< -o $@ +$(eval $(call PARTIAL_COMPILE_ARM_TEMPLATE, SRCARM)) + +.PHONY: elf lss sym hex bin +elf: $(OUTDIR)/$(TARGET).elf +lss: $(OUTDIR)/$(TARGET).lss +sym: $(OUTDIR)/$(TARGET).sym +hex: $(OUTDIR)/$(TARGET).hex +bin: $(OUTDIR)/$(TARGET).bin + +# Display sizes of sections. +$(eval $(call SIZE_TEMPLATE, $(OUTDIR)/$(TARGET).elf)) +.PHONY: size +size: $(OUTDIR)/$(TARGET).elf_size # Generate Doxygen documents docs: doxygen $(DOXYGENDIR)/doxygen.cfg - + # Target: clean project. -clean: begin clean_list finished end +clean: clean_list clean_list : -## @echo @echo $(MSG_CLEANING) - $(REMOVE) $(OUTDIR)/$(TARGET).map - $(REMOVE) $(OUTDIR)/$(TARGET).elf - $(REMOVE) $(OUTDIR)/$(TARGET).hex - $(REMOVE) $(OUTDIR)/$(TARGET).bin - $(REMOVE) $(OUTDIR)/$(TARGET).sym - $(REMOVE) $(OUTDIR)/$(TARGET).lss - $(REMOVE) $(ALLOBJ) - $(REMOVE) $(LSTFILES) - $(REMOVE) $(DEPFILES) - $(REMOVE) $(SRC:.c=.s) - $(REMOVE) $(SRCARM:.c=.s) - $(REMOVE) $(CPPSRC:.cpp=.s) - $(REMOVE) $(CPPSRCARM:.cpp=.s) + $(V1) $(REMOVE) $(OUTDIR)/$(TARGET).map + $(V1) $(REMOVE) $(OUTDIR)/$(TARGET).elf + $(V1) $(REMOVE) $(OUTDIR)/$(TARGET).hex + $(V1) $(REMOVE) $(OUTDIR)/$(TARGET).bin + $(V1) $(REMOVE) $(OUTDIR)/$(TARGET).sym + $(V1) $(REMOVE) $(OUTDIR)/$(TARGET).lss + $(V1) $(REMOVE) $(ALLOBJ) + $(V1) $(REMOVE) $(LSTFILES) + $(V1) $(REMOVE) $(DEPFILES) + $(V1) $(REMOVE) $(SRC:.c=.s) + $(V1) $(REMOVE) $(SRCARM:.c=.s) + $(V1) $(REMOVE) $(CPPSRC:.cpp=.s) + $(V1) $(REMOVE) $(CPPSRCARM:.cpp=.s) # Create output files directory @@ -653,9 +512,5 @@ else -include $(shell mkdir -p $(OUTDIR) 2>/dev/null) $(shell mkdir $(OUTDIR)/dep 2>/dev/null) $(wildcard $(OUTDIR)/dep/*) endif - - # Listing of phony targets. -.PHONY : all begin finish end sizebefore sizeafter gccversion \ -build elf hex bin lss sym clean clean_list program - +.PHONY : all build clean clean_list program diff --git a/make/firmware-defs.mk b/make/firmware-defs.mk new file mode 100644 index 000000000..aff57a816 --- /dev/null +++ b/make/firmware-defs.mk @@ -0,0 +1,145 @@ +# Toolchain prefix (i.e arm-elf- -> arm-elf-gcc.exe) +TCHAIN_PREFIX ?= arm-none-eabi- + +# Define toolchain component names. +CC = $(TCHAIN_PREFIX)gcc +CPP = $(TCHAIN_PREFIX)g++ +AR = $(TCHAIN_PREFIX)ar +OBJCOPY = $(TCHAIN_PREFIX)objcopy +OBJDUMP = $(TCHAIN_PREFIX)objdump +SIZE = $(TCHAIN_PREFIX)size +NM = $(TCHAIN_PREFIX)nm + +THUMB = -mthumb + +# Test if quotes are needed for the echo-command +result = ${shell echo "test"} +ifeq (${result}, test) + quote = ' +# This line is just to clear out the single quote above ' +else + quote = +endif + +# Define Messages +# English +MSG_FORMATERROR := ${quote} Can not handle output-format${quote} +MSG_MODINIT := ${quote} MODINIT ${quote} +MSG_SIZE := ${quote} SIZE ${quote} +MSG_LOAD_FILE := ${quote} BIN/HEX ${quote} +MSG_EXTENDED_LISTING := ${quote} LIS ${quote} +MSG_SYMBOL_TABLE := ${quote} NM ${quote} +MSG_LINKING := ${quote} LD ${quote} +MSG_COMPILING := ${quote} CC ${quote} +MSG_COMPILING_ARM := ${quote} CC-ARM ${quote} +MSG_COMPILINGCPP := ${quote} CXX ${quote} +MSG_COMPILINGCPP_ARM := ${quote} CXX-ARM ${quote} +MSG_ASSEMBLING := ${quote} AS ${quote} +MSG_ASSEMBLING_ARM := ${quote} AS-ARM ${quote} +MSG_CLEANING := ${quote} CLEAN ${quote} +MSG_ASMFROMC := ${quote} AS(C) ${quote} +MSG_ASMFROMC_ARM := ${quote} AS(C)-ARM ${quote} +MSG_PYMITEINIT := ${quote} PY ${quote} + +toprel = $(subst $(realpath $(TOP))/,,$(abspath $(1))) + +# Display compiler version information. +.PHONY: gccversion +gccversion : + @$(CC) --version + +# Create final output file (.hex) from ELF output file. +%.hex: %.elf + @echo $(MSG_LOAD_FILE) $(call toprel, $@) + $(V1) $(OBJCOPY) -O ihex $< $@ + +# Create final output file (.bin) from ELF output file. +%.bin: %.elf + @echo $(MSG_LOAD_FILE) $(call toprel, $@) + $(V1) $(OBJCOPY) -O binary $< $@ + +# Create extended listing file/disassambly from ELF output file. +# using objdump testing: option -C +%.lss: %.elf + @echo $(MSG_EXTENDED_LISTING) $(call toprel, $@) + $(V1) $(OBJDUMP) -h -S -C -r $< > $@ + +# Create a symbol table from ELF output file. +%.sym: %.elf + @echo $(MSG_SYMBOL_TABLE) $(call toprel, $@) + $(V1) $(NM) -n $< > $@ + +define SIZE_TEMPLATE +.PHONY: $(1)_size +$(1)_size: $(1) + @echo $(MSG_SIZE) $$(call toprel, $$<) + $(V1) $(SIZE) -A $$< +endef + +# Assemble: create object files from assembler source files. +define ASSEMBLE_TEMPLATE +$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) + @echo $(MSG_ASSEMBLING) $$(call toprel, $$<) + $(V1) $(CC) -c -mthumb $$(ASFLAGS) $$< -o $$@ +endef + +# Assemble: create object files from assembler source files. ARM-only +define ASSEMBLE_ARM_TEMPLATE +$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) + @echo $(MSG_ASSEMBLING_ARM) $$(call toprel, $$<) + $(V1) $(CC) -c $$(ASFLAGS) $$< -o $$@ +endef + +# Compile: create object files from C source files. +define COMPILE_C_TEMPLATE +$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) + @echo $(MSG_COMPILING) $$(call toprel, $$<) + $(V1) $(CC) -c -mthumb $$(CFLAGS) $$(CONLYFLAGS) $$< -o $$@ +endef + +# Compile: create object files from C source files. ARM-only +define COMPILE_C_ARM_TEMPLATE +$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) + @echo $(MSG_COMPILING_ARM) $$(call toprel, $$<) + $(V1) $(CC) -c $$(CFLAGS) $$(CONLYFLAGS) $$< -o $$@ +endef + +# Compile: create object files from C++ source files. +define COMPILE_CPP_TEMPLATE +$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) + @echo $(MSG_COMPILINGCPP) $$(call toprel, $$<) + $(V1) $(CC) -c -mthumb $$(CFLAGS) $$(CPPFLAGS) $$< -o $$@ +endef + +# Compile: create object files from C++ source files. ARM-only +define COMPILE_CPP_ARM_TEMPLATE +$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) + @echo $(MSG_COMPILINGCPP_ARM) $$(call toprel, $$<) + $(V1) $(CC) -c $$(CFLAGS) $$(CPPFLAGS) $$< -o $$@ +endef + +# Link: create ELF output file from object files. +# $1 = elf file to produce +# $2 = list of object files that make up the elf file +define LINK_TEMPLATE +.SECONDARY : $(1) +.PRECIOUS : $(2) +$(1): $(2) + @echo $(MSG_LINKING) $$(call toprel, $$@) + $(V1) $(CC) -mthumb $$(CFLAGS) $(2) --output $$@ $$(LDFLAGS) +endef + +# Compile: create assembler files from C source files. ARM/Thumb +define PARTIAL_COMPILE_TEMPLATE +$($(1):.c=.s) : %.s : %.c + @echo $(MSG_ASMFROMC) $$(call toprel, $$<) + $(V1) $(CC) -mthumb -S $$(CFLAGS) $$(CONLYFLAGS) $$< -o $$@ +endef + +# Compile: create assembler files from C source files. ARM only +define PARTIAL_COMPILE_ARM_TEMPLATE +$($(1):.c=.s) : %.s : %.c + @echo $(MSG_ASMFROMC_ARM) $$(call toprel, $$<) + $(V1) $(CC) -S $$(CFLAGS) $$(CONLYFLAGS) $$< -o $$@ +endef +