From 2c043efb66416f3d5cd85f0939054766082354de Mon Sep 17 00:00:00 2001 From: Perry Hung Date: Thu, 24 Jun 2010 11:16:26 -0400 Subject: make: Modularize makefiles, add dependency tracking, build-type tracking Major build system rewrite. New and exciting: 1. Proper dependency tracking. All source files including header files should be properly tracked and recompiled as necessary when they are changed. 2. Build-type tracking. If the target changes from 'ram' to 'flash,' for example, the build system will force a rebuild rather than incorrectly link modules to a different address. 3. New targets: The old 'ram,' 'flash,' and 'jtag' targets have been replaced with the environment variable MAPLE_TARGET, which controls the link address. Users can either export it to their environment, or pass MAPLE_TARGET on the command-line. Once this is set, sketches can be compiled with 'make sketch,' or simply 'make.' Note: the default is MAPLE_TARGET='flash.' The target 'install' now automagically uploads the sketch to the board using the appropriate method. The 'run' target has been renamed to 'debug.' It starts an openocd gdb server. 4. Odds and ends: -Verbose and 'quiet' modes. Set V=1 for verbose compilation, the default is quiet. -Object file sizes and disassembly information is generated and placed in build/$(BOARD).sizes and build/$(BOARD).disas, respectively. -Parallel make with -j should speed things up if you have multiple cores. --- support/make/build-rules.mk | 40 ++++++++++++++++++++++++++++++++++++++++ support/make/build-targets.mk | 31 +++++++++++++++++++++++++++++++ support/make/build-templates.mk | 5 +++++ 3 files changed, 76 insertions(+) create mode 100644 support/make/build-rules.mk create mode 100644 support/make/build-targets.mk create mode 100644 support/make/build-templates.mk (limited to 'support/make') diff --git a/support/make/build-rules.mk b/support/make/build-rules.mk new file mode 100644 index 0000000..52ede32 --- /dev/null +++ b/support/make/build-rules.mk @@ -0,0 +1,40 @@ +# Useful tools +CC := arm-none-eabi-gcc +CXX := arm-none-eabi-g++ +LD := arm-none-eabi-ld -v +AR := arm-none-eabi-ar +AS := arm-none-eabi-as +OBJCOPY := arm-none-eabi-objcopy +DISAS := arm-none-eabi-objdump +OBJDUMP := arm-none-eabi-objdump +SIZE := arm-none-eabi-size +DFU := dfu-util +OPENOCD := openocd + +# Suppress annoying output unless V is set +ifndef V + SILENT_CC = @echo ' [CC] ' $(@:$(BUILD_PATH)/%.o=%.c); + SILENT_CXX = @echo ' [CXX] ' $(@:$(BUILD_PATH)/%.o=%.cpp); + SILENT_LD = @echo ' [LD] ' $(@F); + SILENT_AR = @echo ' [AR] ' + SILENT_AS = @echo ' [AS] ' + SILENT_OBJCOPY = @echo ' [OBJCOPY] ' $(@F); + SILENT_DISAS = @echo ' [DISAS] ' $(@:$(BUILD_PATH)/%.bin=%).disas; + SILENT_OBJDUMP = @echo ' [OBJDUMP] ' $(OBJDUMP); + DFU := dfu-util + OPENOCD := openocd +endif + +BUILDDIRS := +TGT_BIN := + +CFLAGS = $(GLOBAL_CFLAGS) $(TGT_CFLAGS) +CXXFLAGS = $(GLOBAL_CXXFLAGS) $(TGT_CXXFLAGS) + +# General directory independent build rules, generate dependency information +$(BUILD_PATH)/%.o: %.c + $(SILENT_CC) $(CC) $(CFLAGS) -MMD -MP -MF $(@:%.o=%.d) -MT $@ -o $@ -c $< + +$(BUILD_PATH)/%.o: %.cpp + $(SILENT_CXX) $(CXX) $(CFLAGS) $(CXXFLAGS) -MMD -MP -MF $(@:%.o=%.d) -MT $@ -o $@ -c $< + diff --git a/support/make/build-targets.mk b/support/make/build-targets.mk new file mode 100644 index 0000000..a7f2446 --- /dev/null +++ b/support/make/build-targets.mk @@ -0,0 +1,31 @@ +# main project target +$(BUILD_PATH)/main.o: main.cpp + $(SILENT_CXX) $(CXX) $(CFLAGS) $(CXXFLAGS) $(LIBMAPLE_INCLUDES) $(WIRISH_INCLUDES) -o $@ -c $< + +$(BUILD_PATH)/$(BOARD).elf: $(BUILDDIRS) $(TGT_BIN) $(BUILD_PATH)/main.o + $(SILENT_LD) $(CXX) $(LDFLAGS) -o $@ $(TGT_BIN) $(BUILD_PATH)/main.o + +$(BUILD_PATH)/$(BOARD).bin: $(BUILD_PATH)/$(BOARD).elf + $(SILENT_OBJCOPY) $(OBJCOPY) -v -Obinary $(BUILD_PATH)/$(BOARD).elf $@ 1>/dev/null + $(SILENT_DISAS) $(DISAS) -d $(BUILD_PATH)/$(BOARD).elf > $(BUILD_PATH)/$(BOARD).disas + @echo + @find $(BUILD_PATH) -iname *.o | xargs $(SIZE) -t > $(BUILD_PATH)/$(BOARD).sizes + @echo "Final Size:" + $(SIZE) $< + @echo $(MAPLE_TARGET) > $(BUILD_PATH)/build-type + +$(BUILDDIRS): + @mkdir -p $@ + +MSG_INFO: + @echo "================================================================================" + @echo "" + @echo " Build info:" + @echo " BOARD:" $(BOARD) + @echo " MAPLE_TARGET:" $(MAPLE_TARGET) + @echo "" + @echo " See 'make help' for all possible targets" + @echo "" + @echo "================================================================================" + @echo + diff --git a/support/make/build-templates.mk b/support/make/build-templates.mk new file mode 100644 index 0000000..4371f13 --- /dev/null +++ b/support/make/build-templates.mk @@ -0,0 +1,5 @@ +define LIBMAPLE_MODULE_template +dir := $(1) +include $$(dir)/rules.mk +endef + -- cgit v1.2.3