From: Philipp Hachtmann Date: Mon, 6 Mar 2017 14:45:20 +0000 (+0100) Subject: trennfix/sw: Makefile: Move objects etc into build folder X-Git-Url: http://gitweb.hachti.de/?p=eisenbahn.git;a=commitdiff_plain;h=8ac2b48af3b494eef4e1d74d1d76e7e10334628d trennfix/sw: Makefile: Move objects etc into build folder Signed-off-by: Philipp Hachtmann --- diff --git a/trennfix/sw/Makefile b/trennfix/sw/Makefile index 0ad4b1b..248a0c7 100644 --- a/trennfix/sw/Makefile +++ b/trennfix/sw/Makefile @@ -2,10 +2,9 @@ ####################################### HW?=trennfix_0.4 -PROG?=smokefix - -####################################### +PROG?=trennfix +BUILD_DIR=build ####################################### # VERBOSITY CONTROL @@ -152,8 +151,9 @@ $(eval $(call SELECT_DEFAULT_template, $(PROG))) $(Q)$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) # Compile: create object files from C source files. -%.o : %.c Makefile +$(BUILD_DIR)/%.o : %.c Makefile $(wildcard mk/hw/*) @echo CC $@ + @mkdir -p $(@D) $(Q)$(CC) -c $(CFLAGS) $< -o $@ # Compile: create assembler files from C source files. @@ -164,13 +164,17 @@ $(eval $(call SELECT_DEFAULT_template, $(PROG))) # Assemble: create object files from assembler source files. %.o : %.S @echo ASM $@ + @mkdir -p $(@D) $(Q)$(CC) -c $(ASFLAGS) $< -o $@ ########################### The big template for each program ################## define PROGRAM_template= +$(1)_mupf: + @echo "$(1) Objects: " $$($(1)_OBJS) + # Determine program's object files -$(1)_OBJS=$$($(1)_SRC:.c=.o) +$(1)_OBJS=$$(foreach obj, $$($(1)_SRC:.c=.o), $(BUILD_DIR)/$$(obj)) $(1)_OBJS+=$$($(1)_ASRC:.S=.o) # Collect all listing files - for cleanup @@ -183,9 +187,6 @@ $(1)_program : $(1).hex $(1).eep @echo PROG $(1) $(Q)$(AVRDUDE) $(AVRDUDE_FLAGS) -U flash:w:$(1).hex -U eeprom:w:$(1).eep -$(1)_unfug: - @echo UNFUG $$@ - $(1)_fuses.bin: $(1).elf @echo OBJCOPY $$@ $(Q)$(OBJCOPY) -j .fuse $(1).elf -O binary $$@ @@ -216,7 +217,8 @@ $(1)_clean: $(Q)$(RM) $$($(1)_LST) $(Q)$(RM) $$($(1)_SRC:.c=.s) $(Q)$(RM) $$($(1)_SRC:.c=.d) - @$(Q)$(RM) $(1)_fuses.bin + $(Q)$(RM) $(1)_fuses.bin + $(Q) rm -rf $(BUILD_DIR)/ $(1)_build: $(1).hex $(1)_size