Makefile: better support additional source libraries
This commit is contained in:
parent
f681026ec2
commit
60c337125e
37
Makefile
37
Makefile
|
@ -37,13 +37,14 @@ OPENCM3_LIB = $(OPENCM3_DIR)/lib
|
||||||
|
|
||||||
# library for the STM32F1 (provided by opencm3)
|
# library for the STM32F1 (provided by opencm3)
|
||||||
STM32F1_LIB = opencm3_stm32f1
|
STM32F1_LIB = opencm3_stm32f1
|
||||||
|
# libraries with source code used (also to be compiled)
|
||||||
|
SRCLIBS = . lib
|
||||||
# source files (this will be populated using includes based DEPENDENCIES)
|
# source files (this will be populated using includes based DEPENDENCIES)
|
||||||
CSRC = global.c
|
CSRC =
|
||||||
# headers corresponding to source files
|
# headers (unique, and if existing) corresponding to source files
|
||||||
CHDR = $(sort $(patsubst %.c,%.h,$(CSRC)))
|
CHDR = $(sort $(patsubst %.c,%.h,$(wildcard $(CSRC))))
|
||||||
# objects compiled from source files
|
# objects (unique, and if existing) compiled from source files
|
||||||
OBJ = $(sort $(patsubst %.c,%.o,$(CSRC)))
|
OBJ = $(sort $(patsubst %.c,%.o,$(wildcard $(CSRC))))
|
||||||
# figure out based on the main sources files which library files are used
|
# figure out based on the main sources files which library files are used
|
||||||
DEPENDENCIES = $(patsubst %,%.inc,$(FIRMWARE))
|
DEPENDENCIES = $(patsubst %,%.inc,$(FIRMWARE))
|
||||||
# populates CSRC based on the library files used
|
# populates CSRC based on the library files used
|
||||||
|
@ -89,7 +90,7 @@ CFLAGS += -nostdlib -nostdinc
|
||||||
# include ELLCC libraries
|
# include ELLCC libraries
|
||||||
CFLAGS += -I $(ELLCC)libecc/include/ -I $(ELLCC)libecc/include/arm/
|
CFLAGS += -I $(ELLCC)libecc/include/ -I $(ELLCC)libecc/include/arm/
|
||||||
# include own libraries
|
# include own libraries
|
||||||
CFLAGS += -I . -I lib
|
CFLAGS += $(foreach lib,$(SRCLIBS),-I $(lib))
|
||||||
# include opencm3 libraries
|
# include opencm3 libraries
|
||||||
CFLAGS += -I $(OPENCM3_INC)
|
CFLAGS += -I $(OPENCM3_INC)
|
||||||
# add defines for micro-controller and board
|
# add defines for micro-controller and board
|
||||||
|
@ -152,14 +153,20 @@ hex: $(patsubst %,%.hex,$(FIRMWARE))
|
||||||
$(info compiling $(@))
|
$(info compiling $(@))
|
||||||
$(Q)$(CC) $(CFLAGS) $(ARCH_FLAGS) -o $(@) -c $(<)
|
$(Q)$(CC) $(CFLAGS) $(ARCH_FLAGS) -o $(@) -c $(<)
|
||||||
|
|
||||||
# generate dependencies (requires libopencm3 to be built to generate all libraries)
|
# find out which library source files also need to be compiled and linked, based on its dependencies
|
||||||
%.d: %.c $(OPENCM3_LIB)/lib$(STM32F1_LIB).a
|
%.inc: %.c $(OPENCM3_LIB)/lib$(STM32F1_LIB).a
|
||||||
@# check which libraries are used
|
$(Q)echo "" > $(@)
|
||||||
$(Q)$(CC) $(CFLAGS) $(ARCH_FLAGS) -MM -MF $(@) -o /dev/null -c $(<)
|
$(Q)for dependency in $(shell $(CC) $(CFLAGS) $(ARCH_FLAGS) -MM -c $(<)); do \
|
||||||
|
if [ -f "$${dependency}" ]; then \
|
||||||
# figure out which library source files are used for later inclusion
|
for lib in $(SRCLIBS); do \
|
||||||
%.inc: %.d
|
if [ `dirname "$${dependency}"` = "$${lib}" ]; then \
|
||||||
$(Q)grep -o -e " lib\/[^ ]*\.h" $(<) | sed -e 's|\(.*\)\.h$$|CSRC +=\1.c\n-include\1.inc|g' -e 's|.*${*}.*||g' > $(@)
|
if [ -f `echo "$${dependency}" | sed -e 's|\(.*\)\.h$$|\1.c|'` ]; then \
|
||||||
|
echo "$${dependency}" | sed -e 's|\(.*\)\.h$$|CSRC += \1.c\n-include \1.inc|g' -e 's|.*${*}.*||g' >> $(@); \
|
||||||
|
fi; \
|
||||||
|
fi; \
|
||||||
|
done; \
|
||||||
|
fi; \
|
||||||
|
done
|
||||||
|
|
||||||
# get libopencm3
|
# get libopencm3
|
||||||
$(OPENCM3_DIR)/Makefile:
|
$(OPENCM3_DIR)/Makefile:
|
||||||
|
|
Loading…
Reference in New Issue