Use build directory
This commit is contained in:
parent
88cc3ad2dc
commit
f26732ccfa
8
.gitignore
vendored
8
.gitignore
vendored
@ -1,7 +1 @@
|
|||||||
*.o
|
build
|
||||||
*.elf
|
|
||||||
*.bin
|
|
||||||
*.hex
|
|
||||||
*.lst
|
|
||||||
*.lss
|
|
||||||
*.map
|
|
19
Makefile
19
Makefile
@ -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:
|
||||||
|
Loading…
Reference in New Issue
Block a user