Use build directory

This commit is contained in:
Olaf Rempel 2019-11-22 22:35:37 +01:00
parent 88cc3ad2dc
commit f26732ccfa
2 changed files with 13 additions and 14 deletions

8
.gitignore vendored
View File

@ -1,7 +1 @@
*.o build
*.elf
*.bin
*.hex
*.lst
*.lss
*.map

View File

@ -6,6 +6,7 @@ SIZE := avr-size
TARGET = ispprog TARGET = ispprog
SOURCE = $(wildcard *.c) SOURCE = $(wildcard *.c)
BUILD_DIR = build
#CONFIG = ispprog #CONFIG = ispprog
CONFIG = ispprog2 CONFIG = ispprog2
@ -34,29 +35,33 @@ endif
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
CFLAGS = -pipe -g -Os -mmcu=$(MCU) -Wall -fdata-sections -ffunction-sections CFLAGS = -pipe -g -Os -mmcu=$(MCU) -Wall -fdata-sections -ffunction-sections
CFLAGS += -Wa,-adhlns=$(*F).lst -DCONFIG_$(CONFIG)=1 CFLAGS += -Wa,-adhlns=$(BUILD_DIR)/$(*D)/$(*F).lst -MMD -MP -MF $(BUILD_DIR)/$(*D)/$(*F).d
CFLAGS += -DCONFIG_$(CONFIG)=1
LDFLAGS = -Wl,-Map,$(@:.elf=.map),--cref,--relax,--gc-sections LDFLAGS = -Wl,-Map,$(@:.elf=.map),--cref,--relax,--gc-sections
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
$(TARGET): $(TARGET).elf $(TARGET): $(BUILD_DIR)/$(TARGET).elf
@$(SIZE) -B -x --mcu=$(MCU) $< @$(SIZE) -B -x --mcu=$(MCU) $<
$(TARGET).elf: $(SOURCE:.c=.o) $(BUILD_DIR)/$(TARGET).elf: $(patsubst %,$(BUILD_DIR)/%,$(SOURCE:.c=.o))
@echo " Linking file: $@" @echo " Linking file: $@"
@$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
@$(OBJDUMP) -h -S $@ > $(@:.elf=.lss) @$(OBJDUMP) -h -S $@ > $(@:.elf=.lss)
@$(OBJCOPY) -j .text -j .data -O ihex $@ $(@:.elf=.hex) @$(OBJCOPY) -j .text -j .data -O ihex $@ $(@:.elf=.hex)
@$(OBJCOPY) -j .text -j .data -O binary $@ $(@:.elf=.bin) @$(OBJCOPY) -j .text -j .data -O binary $@ $(@:.elf=.bin)
%.o: %.c $(MAKEFILE_LIST) $(BUILD_DIR)/%.o: %.c $(MAKEFILE_LIST)
@echo " Building file: $<" @echo " Building file: $<"
@$(shell test -d $(BUILD_DIR)/$(*D) || mkdir -p $(BUILD_DIR)/$(*D))
@$(CC) $(CFLAGS) -o $@ -c $< @$(CC) $(CFLAGS) -o $@ -c $<
clean: include $(shell find $(BUILD_DIR) -name \*.d 2> /dev/null)
rm -rf $(SOURCE:.c=.o) $(SOURCE:.c=.lst) $(addprefix $(TARGET), .elf .map .lss .hex .bin)
install: $(TARGET).elf clean:
rm -rf $(BUILD_DIR)
install: $(BUILD_DIR)/$(TARGET).elf
avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U flash:w:$(<:.elf=.hex) avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U flash:w:$(<:.elf=.hex)
fuses: fuses: