Makefile improved to handle multiple file project
This commit is contained in:
parent
b42c237f3d
commit
6fc181547c
|
@ -2,3 +2,5 @@ led-controller
|
||||||
*.o
|
*.o
|
||||||
*.hex
|
*.hex
|
||||||
*.lst
|
*.lst
|
||||||
|
*.map
|
||||||
|
*.elf
|
||||||
|
|
66
src/Makefile
66
src/Makefile
|
@ -1,7 +1,7 @@
|
||||||
# required packages
|
# required packages
|
||||||
# sudo aptitude install avrdude gcc-avr avr-libc
|
# sudo aptitude install avrdude gcc-avr avr-libc
|
||||||
# the program
|
# the program
|
||||||
PROG=led-controller
|
TARGET=led-controller
|
||||||
# to compile
|
# to compile
|
||||||
CC=avr-gcc
|
CC=avr-gcc
|
||||||
OBJDUMP=avr-objdump
|
OBJDUMP=avr-objdump
|
||||||
|
@ -18,13 +18,26 @@ PROGRAMMER=usbtiny
|
||||||
# to flash
|
# to flash
|
||||||
#AVRDUDE=avrdude -p $(DEVICE) -P $(PORT) -c $(PROGRAMMER)
|
#AVRDUDE=avrdude -p $(DEVICE) -P $(PORT) -c $(PROGRAMMER)
|
||||||
FLASHER=avrdude -p $(DEVICE) -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
|
verify:
|
||||||
$(CC) $(CFLAGS) -I. -mmcu=$(DEVICE) -DF_CPU=$(F_CPU) -o $(PROG) $(PROG).c
|
$(FLASHER)
|
||||||
$(OBJDUMP) -h -S $(PROG) > $(PROG).lst
|
if [ $$? -eq 0 ]; then \
|
||||||
$(OBJCOPY) -j .text -j .data -O ihex $(PROG) $(PROG).hex
|
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:
|
# Fuse low byte:
|
||||||
# 0xff = 1 1 1 1 1 1 1 1
|
# 0xff = 1 1 1 1 1 1 1 1
|
||||||
|
@ -52,28 +65,29 @@ prog: verify $(PROG).c
|
||||||
burn-fuse:
|
burn-fuse:
|
||||||
$(FLASHER) -U lfuse:w:0xff:m -U hfuse:w:0xdf:m -U efuse:w:0x04:m
|
$(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:
|
read-flash:
|
||||||
$(FLASHER) -U flash:r:flash_dump.hex:i
|
$(FLASHER) -U flash:r:flash_dump.hex:i
|
||||||
|
|
||||||
flash: prog load
|
flash:
|
||||||
install : prog load
|
$(FLASHER) -U flash:w:$(TARGET).hex:i
|
||||||
load:
|
|
||||||
$(FLASHER) -U flash:w:$(PROG).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:
|
clean:
|
||||||
rm -f $(PROG) *.hex *.lst
|
rm -f $(TARGET) $(TARGET).hex $(TARGET).elf $(LST) $(TARGET).lst $(OBJ)
|
||||||
|
|
||||||
verify:
|
|
||||||
$(FLASHER)
|
|
||||||
if [ $$? -eq 0 ]; then \
|
|
||||||
echo "flasher configured correctly"; \
|
|
||||||
else \
|
|
||||||
echo "flasher not configured correctly in Makefile"; \
|
|
||||||
exit 1; \
|
|
||||||
fi
|
|
||||||
|
|
Loading…
Reference in New Issue