Makefile improved to handle multiple file project

This commit is contained in:
King Kévin 2013-10-12 17:52:10 +02:00
parent b42c237f3d
commit 6fc181547c
2 changed files with 42 additions and 26 deletions

2
src/.gitignore vendored
View File

@ -2,3 +2,5 @@ led-controller
*.o
*.hex
*.lst
*.map
*.elf

View File

@ -1,7 +1,7 @@
# required packages
# sudo aptitude install avrdude gcc-avr avr-libc
# the program
PROG=led-controller
TARGET=led-controller
# to compile
CC=avr-gcc
OBJDUMP=avr-objdump
@ -18,13 +18,26 @@ PROGRAMMER=usbtiny
# to flash
#AVRDUDE=avrdude -p $(DEVICE) -P $(PORT) -c $(PROGRAMMER)
FLASHER=avrdude -p $(DEVICE) -c $(PROGRAMMER)
# source files to compile
SRC = main.c
# object files.
OBJ = $(SRC:.c=.o)
# listing files.
LST = $(SRC:.c=.lst)
all: prog
all: program $(TARGET).lst verify burn-fuse flash
prog: verify $(PROG).c
$(CC) $(CFLAGS) -I. -mmcu=$(DEVICE) -DF_CPU=$(F_CPU) -o $(PROG) $(PROG).c
$(OBJDUMP) -h -S $(PROG) > $(PROG).lst
$(OBJCOPY) -j .text -j .data -O ihex $(PROG) $(PROG).hex
verify:
$(FLASHER)
if [ $$? -eq 0 ]; then \
echo "flasher configured correctly"; \
else \
echo "flasher not configured correctly in Makefile"; \
exit 1; \
fi
read-fuse:
$(FLASHER) -U lfuse:r:lfuse.raw:r -U hfuse:r:hfuse.raw:r -U efuse:r:efuse.raw:r
# Fuse low byte:
# 0xff = 1 1 1 1 1 1 1 1
@ -52,28 +65,29 @@ prog: verify $(PROG).c
burn-fuse:
$(FLASHER) -U lfuse:w:0xff:m -U hfuse:w:0xdf:m -U efuse:w:0x04:m
read-fuse:
$(FLASHER) -U lfuse:r:lfuse.raw:r -U hfuse:r:hfuse.raw:r -U efuse:r:efuse.raw:r
flash:
$(FLASHER) -U flash:w:$(PROG).hex:i
read-flash:
$(FLASHER) -U flash:r:flash_dump.hex:i
flash: prog load
install : prog load
load:
$(FLASHER) -U flash:w:$(PROG).hex:i
flash:
$(FLASHER) -U flash:w:$(TARGET).hex:i
program: $(TARGET).hex
# compile
%.o: %.c
$(CC) $(CFLAGS) -I. -mmcu=$(DEVICE) -DF_CPU=$(F_CPU) -c -o $@ $<
# link
%.elf: $(OBJ)
$(CC) $(CFLAGS) -I. -mmcu=$(DEVICE) -DF_CPU=$(F_CPU) -Wl,-Map=$(TARGET).map,--cref -o $@ $(OBJ)
# extended listing
%.lst: %.elf
$(OBJDUMP) -h -S $< > $@
# output file
%.hex: %.elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
clean:
rm -f $(PROG) *.hex *.lst
verify:
$(FLASHER)
if [ $$? -eq 0 ]; then \
echo "flasher configured correctly"; \
else \
echo "flasher not configured correctly in Makefile"; \
exit 1; \
fi
rm -f $(TARGET) $(TARGET).hex $(TARGET).elf $(LST) $(TARGET).lst $(OBJ)