ispprog/Makefile

54 lines
1.4 KiB
Makefile
Raw Normal View History

2014-10-05 14:27:03 +02:00
CC := avr-gcc
LD := avr-ld
OBJCOPY := avr-objcopy
OBJDUMP := avr-objdump
SIZE := avr-size
2006-05-05 19:02:04 +02:00
2014-10-05 14:27:03 +02:00
TARGET = ispprog
SOURCE = $(wildcard *.c)
2006-05-05 19:02:04 +02:00
2014-10-05 14:27:03 +02:00
# select MCU
MCU = atmega16
2006-05-05 19:02:04 +02:00
2014-10-05 14:27:03 +02:00
AVRDUDE_PROG := -c butterfly -b 19200 -P /dev/ttyUSB0
#AVRDUDE_PROG := -c dragon_isp -P usb
2006-05-05 19:02:04 +02:00
2014-10-05 14:27:03 +02:00
# ---------------------------------------------------------------------------
2006-05-05 19:02:04 +02:00
2014-10-05 14:27:03 +02:00
ifeq ($(MCU), atmega16)
# (ext. crystal)
AVRDUDE_MCU=m16
AVRDUDE_FUSES=lfuse:w:0xff:m hfuse:w:0xda:m
endif
2006-05-05 19:02:04 +02:00
2014-10-05 14:27:03 +02:00
# ---------------------------------------------------------------------------
2006-05-05 19:02:04 +02:00
2014-10-05 14:27:03 +02:00
CFLAGS = -pipe -g -Os -mmcu=$(MCU) -Wall -fdata-sections -ffunction-sections
CFLAGS += -Wa,-adhlns=$(*F).lst
LDFLAGS = -Wl,-Map,$(@:.elf=.map),--cref,--relax,--gc-sections
2006-05-05 19:02:04 +02:00
2014-10-05 14:27:03 +02:00
# ---------------------------------------------------------------------------
2006-05-05 19:02:04 +02:00
2014-10-05 14:27:03 +02:00
$(TARGET): $(TARGET).elf
@$(SIZE) -B -x --mcu=$(MCU) $<
2006-05-05 19:02:04 +02:00
2014-10-05 14:27:03 +02:00
$(TARGET).elf: $(SOURCE:.c=.o)
@echo " Linking file: $@"
@$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
@$(OBJDUMP) -h -S $@ > $(@:.elf=.lss)
@$(OBJCOPY) -j .text -j .data -O ihex $@ $(@:.elf=.hex)
@$(OBJCOPY) -j .text -j .data -O binary $@ $(@:.elf=.bin)
2006-05-05 19:02:04 +02:00
2014-10-05 14:27:03 +02:00
%.o: %.c $(MAKEFILE_LIST)
@echo " Building file: $<"
@$(CC) $(CFLAGS) -o $@ -c $<
2006-05-05 19:02:04 +02:00
2014-10-05 14:27:03 +02:00
clean:
rm -rf $(SOURCE:.c=.o) $(SOURCE:.c=.lst) $(addprefix $(TARGET), .elf .map .lss .hex .bin)
2006-05-05 19:02:04 +02:00
2014-10-05 14:27:03 +02:00
install: $(TARGET).elf
avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U flash:w:$(<:.elf=.hex)
2006-05-05 19:02:04 +02:00
2014-10-05 14:27:03 +02:00
fuses:
avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) $(patsubst %,-U %, $(AVRDUDE_FUSES))