Browse Source

update Makefile

master
Olaf Rempel 7 years ago
parent
commit
6afa5ccbd7
  1. 1
      .gitignore
  2. 76
      Makefile

1
.gitignore

@ -3,4 +3,5 @@
*.bin
*.hex
*.lst
*.lss
*.map

76
Makefile

@ -1,51 +1,53 @@
PRG = ispprog
OBJ = ispprog.o
MCU_TARGET = atmega16
OPTIMIZE = -Os
CC := avr-gcc
LD := avr-ld
OBJCOPY := avr-objcopy
OBJDUMP := avr-objdump
SIZE := avr-size
DEFS =
LIBS =
TARGET = ispprog
SOURCE = $(wildcard *.c)
# You should not have to change anything below here.
# select MCU
MCU = atmega16
CC = avr-gcc
AVRDUDE_PROG := -c butterfly -b 19200 -P /dev/ttyUSB0
#AVRDUDE_PROG := -c dragon_isp -P usb
# Override is only needed by avr-lib build system.
# ---------------------------------------------------------------------------
override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS)
override LDFLAGS = -Wl,-Map,$(PRG).map
ifeq ($(MCU), atmega16)
# (ext. crystal)
AVRDUDE_MCU=m16
AVRDUDE_FUSES=lfuse:w:0xff:m hfuse:w:0xda:m
endif
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
# ---------------------------------------------------------------------------
all: $(PRG).elf lst text
$(SIZE) -x -A $(PRG).elf
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
$(PRG).elf: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
# ---------------------------------------------------------------------------
clean:
rm -rf *.o $(PRG).lst $(PRG).map $(PRG).elf $(PRG).hex $(PRG).bin
lst: $(PRG).lst
%.lst: %.elf
$(OBJDUMP) -h -S $< > $@
$(TARGET): $(TARGET).elf
@$(SIZE) -B -x --mcu=$(MCU) $<
# Rules for building the .text rom images
$(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)
text: hex bin
%.o: %.c $(MAKEFILE_LIST)
@echo " Building file: $<"
@$(CC) $(CFLAGS) -o $@ -c $<
hex: $(PRG).hex
bin: $(PRG).bin
%.hex: %.elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
clean:
rm -rf $(SOURCE:.c=.o) $(SOURCE:.c=.lst) $(addprefix $(TARGET), .elf .map .lss .hex .bin)
%.bin: %.elf
$(OBJCOPY) -j .text -j .data -O binary $< $@
install: $(TARGET).elf
avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U flash:w:$(<:.elf=.hex)
install: text
# uisp -dprog=stk200 --erase --upload if=$(PRG).hex --verify
avrdude -p m16 -c butterfly -b 19200 -P /dev/ttyUSB0 -U flash:w:$(PRG).hex
fuses:
avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) $(patsubst %,-U %, $(AVRDUDE_FUSES))
Loading…
Cancel
Save