From 30c2e473eea6dbd0f0ebb2a4ffd94328b3493415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Tue, 27 Jun 2017 15:33:31 +0200 Subject: [PATCH] better handle libopencm3 dependency --- Makefile | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index 14d4e31..5348451 100644 --- a/Makefile +++ b/Makefile @@ -30,6 +30,14 @@ FIRMWARE = $(APPLICATION) $(BOOTLOADER) # supported are: SYSTEM_BOARD, MAPLE_MINI, BLUE_PILL, CORE_BOARD BOARD = SYSTEM_BOARD +# opencm3 libraries +OPENCM3_DIR := libopencm3 +OPENCM3_INC = $(OPENCM3_DIR)/include +OPENCM3_LIB = $(OPENCM3_DIR)/lib + +# library for the STM32F1 (provided by opencm3) +STM32F1_LIB = opencm3_stm32f1 + # source files (this will be populated using includes based DEPENDENCIES) CSRC = global.c # headers corresponding to source files @@ -56,13 +64,6 @@ GDB := $(ELLCC)bin/ecc-gdb # ecc-gdb (0.13.3) is buggy (crash on kill, can't load elf) GDB := arm-none-eabi-gdb -# opencm3 libraries -OPENCM3_DIR := libopencm3 -OPENCM3_INC = $(OPENCM3_DIR)/include -OPENCM3_LIB = $(OPENCM3_DIR)/lib -# library for the STM32F1 (provided by opencm3) -STM32F1_LIB = opencm3_stm32f1 - # device micro-controller and board DEFS += -DSTM32F1 -D$(BOARD) @@ -107,8 +108,6 @@ LDFLAGS += -nostdlib -nostdinc LDFLAGS += --library-path $(ELLCC)libecc/lib/cortex-m3-linux/ # opencm3 libraries LDFLAGS += --library-path $(OPENCM3_LIB) -# linker script with definitions for micro-controller -#LDFLAGS += --script $(LDSCRIPT) # used libraries (gcc provides the ARM ABI, not sure how to replace with compiler-rt) LDLIBS += --library $(STM32F1_LIB) --library c --library m --library gcc @@ -129,7 +128,7 @@ BMP_PORT ?= /dev/ttyACM0 endif # compile target rules -all: $(OPENCM3_LIB)/lib$(STM32F1_LIB).a elf hex bin +all: elf hex bin elf: $(patsubst %,%.elf,$(FIRMWARE)) bin: $(patsubst %,%.bin,$(FIRMWARE)) @@ -149,12 +148,12 @@ hex: $(patsubst %,%.hex,$(FIRMWARE)) $(Q)$(LD) $(LDFLAGS) --script $(*).ld $(<) $(OBJ) $(LDLIBS) -o $(@) $(Q)size $(@) -%.o: %.c $(CHDR) +%.o: %.c $(CHDR) $(OPENCM3_LIB)/lib$(STM32F1_LIB).a $(info compiling $(@)) $(Q)$(CC) $(CFLAGS) $(ARCH_FLAGS) -o $(@) -c $(<) -# generate dependencies -%.d: %.c +# generate dependencies (requires libopencm3 to be built to generate all libraries) +%.d: %.c $(OPENCM3_LIB)/lib$(STM32F1_LIB).a @# check which libraries are used $(Q)$(CC) $(CFLAGS) $(ARCH_FLAGS) -MM -MF $(@) -o /dev/null -c $(<) @@ -162,6 +161,17 @@ hex: $(patsubst %,%.hex,$(FIRMWARE)) %.inc: %.d $(Q)grep -o -e " lib\/[^ ]*\.h" $(<) | sed -e 's|\(.*\)\.h$$|CSRC +=\1.c\n-include\1.inc|g' -e 's|.*${*}.*||g' > $(@) +# get libopencm3 +$(OPENCM3_DIR)/Makefile: + $(info checking out libopencm3 submodule) + $(Q)git submodule init + $(Q)git submodule update + +# compile libopencm3 +$(OPENCM3_LIB)/lib$(STM32F1_LIB).a: $(OPENCM3_DIR)/Makefile + $(info compiling libopencm3 submodule) + $(Q)CFLAGS=-fno-short-enums $(MAKE) --directory $(OPENCM3_DIR) + # doxygen documentation doc: Doxyfile README.md $(patsubst %,%.c,$(FIRMWARE)) $(CSRC) $(CHDR) $(Q)doxygen $(<) @@ -169,13 +179,6 @@ doc: Doxyfile README.md $(patsubst %,%.c,$(FIRMWARE)) $(CSRC) $(CHDR) clean: $(Q)$(RM) $(BOOTLOADER).elf $(BOOTLOADER).bin $(BOOTLOADER).hex $(APPLICATION).elf $(APPLICATION).bin $(APPLICATION).hex $(OBJ) $(DEPENDENCIES) *.inc lib/*.inc -# make libopencm3 if library for STM32F1 is not yet existing -$(OPENCM3_LIB)/lib$(STM32F1_LIB).a: - $(info compiling libopencm3 library) - git submodule init - git submodule update - $(Q)$(MAKE) CFLAGS=-fno-short-enums -C $(OPENCM3_DIR) - # flash application using DFU flash: $(APPLICATION).bin $(Q)dfu-util -d c440:0d00 -D $(<)