I am developving a number of projects in Eclipse that share common files (such as peripheral drivers). Each project therefore pulls together source files from a number of folders.
Within my makefile I have concatenated together the names of all the source folders as can be summarised:
SOURCE = \ $(SOURCE_FOLDER)/Source/Application/Bus_Link/modbus.c \ $(SOURCE_FOLDER)/Source/Application/Bus_Link/Mitsubishi.c \ $(SOURCE_FOLDER)/Source/Application/Bus_Link/DF1.c \ COMMON_SOURCE = \ $(COMMON_FOLDER)/Source/IOcommon.c \ $(COMMON_FOLDER)/Source/DataLink/adc.c \ $(COMMON_FOLDER)/Source/DataLink/dac.c \ # Concatentate all sources together. SOURCE += $(COMMON_SOURCE)
I have then created the compile rule as follows:
define COMPILE_C_TEMPLATE $(OUTPUT_FOLDER)/$(notdir $(basename $(1))).o : $(1) $(COMPILE) -c $$(CFLAGS) $$< -o $$@ endef $(foreach src, $(SOURCE), $(eval $(call COMPILE_C_TEMPLATE, $(src))))
This works, but obviously doesn't include any dependency rules, so if I change a header file I have to re-compile the entire project.
I have added rules to make dependency files as follows:
define DEPEND_C_TEMPLATE $(OUTPUT_FOLDER)/$(notdir $(basename $(1))).d : $(1) $(OUTPUT_FOLDER)/$(notdir $(basename $(1))).d : $(1) $(COMPILE) -MM $$(CFLAGS) $$< -o $$@ endef $(foreach src, $(SOURCE), $(eval $(call DEPEND_C_TEMPLATE, $(src))))
This also works. and generates correctly-formatted dependency files into the designated output folder. However, I can't find a way of using them to compile the project.
I would appreciate any help