cosin-badge-tht/Makefile
2020-12-02 13:26:01 +01:00

98 lines
2.3 KiB
Makefile

PRG = badge
OBJ = main.o
OPTIMIZE = -Os -std=gnu99
PROGRAMMER = usbtiny
MCU_TARGET = attiny13
DEFS = -DF_CPU=1000000UL
INCLUDES = -I.
LIBS =
#LFUSE =
#HFUSE =
#EFUSE =
# You should not have to change anything below here.
CC = avr-gcc
DUDE = avrdude
HOST_CC = gcc
HOST_CFLAGS = -O0 -g
HOST_LDFLAGS =
# Override is only needed by avr-lib build system.
override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS) $(INCLUDES)
override LDFLAGS = -Wl,-Map,$(PRG).map
DUDEFLAGS = -c $(PROGRAMMER) -p $(MCU_TARGET)
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
all: $(PRG).elf lst text eeprom
$(PRG).elf: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
clean:
rm -rf $(OBJ) $(PRG).elf $(PRG).lst $(PRG).map $(PRG).bin $(PRG).hex $(PRG).srec $(PRG)_eeprom.bin $(PRG)_eeprom.hex $(PRG)_eeprom.srec $(EXTRA_CLEAN_FILES)
lst: $(PRG).lst
%.lst: %.elf
$(OBJDUMP) -h -S $< > $@
# Rules for flashing, EEPROM writing and fuse bit setting
flash: $(PRG).hex $(PRG)_eeprom.hex
$(DUDE) $(DUDEFLAGS) -U eeprom:w:$(PRG)_eeprom.hex:i -U flash:w:$(PRG).hex:i
flashprg: $(PRG).hex
$(DUDE) $(DUDEFLAGS) -U flash:w:$(PRG).hex:i
flasheep: $(PRG)_eeprom.hex
$(DUDE) $(DUDEFLAGS) -U eeprom:w:$(PRG)_eeprom.hex:i
fuse:
$(DUDE) $(DUDEFLAGS) -U hfuse:w:$(HFUSE):m -U lfuse:w:$(LFUSE):m -U efuse:w:$(EFUSE):m
# Rules for building the .text rom images
text: hex bin srec
hex: $(PRG).hex
bin: $(PRG).bin
srec: $(PRG).srec
%.hex: %.elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
%.srec: %.elf
$(OBJCOPY) -j .text -j .data -O srec $< $@
%.bin: %.elf
$(OBJCOPY) -j .text -j .data -O binary $< $@
# Rules for building the .eeprom rom images
eeprom: ehex ebin esrec
ehex: $(PRG)_eeprom.hex
ebin: $(PRG)_eeprom.bin
esrec: $(PRG)_eeprom.srec
%_eeprom.hex: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ \
|| { echo empty $@ not generated; exit 0; }
%_eeprom.srec: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O srec $< $@ \
|| { echo empty $@ not generated; exit 0; }
%_eeprom.bin: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $< $@ \
|| { echo empty $@ not generated; exit 0; }