Browse Source

update Makefile

master
Olaf Rempel 3 years ago
parent
commit
5e460cb33f
2 changed files with 36 additions and 43 deletions
  1. +1
    -0
      .gitignore
  2. +35
    -43
      Makefile

+ 1
- 0
.gitignore View File

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

+ 35
- 43
Makefile View File

@@ -1,56 +1,48 @@
PRG = epromsim
OBJ = main.o
MCU_TARGET = attiny2313
OPTIMIZE = -Os
CC := avr-gcc
LD := avr-ld
OBJCOPY := avr-objcopy
OBJDUMP := avr-objdump
SIZE := avr-size

#AVRDUDE_PROG = -c avr910 -b 115200 -P /dev/ispprog
AVRDUDE_PROG = -c dragon_isp -P usb
AVRDUDE_MCU = attiny2313
TARGET = epromsim
SOURCE = $(wildcard *.c)

DEFS =
LIBS =
MCU=attiny2313
AVRDUDE_MCU=attiny2313

# Override is only needed by avr-lib build system.
override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS)
override LDFLAGS = -Wl,-Map,$(PRG).map
AVRDUDE_FUSES=lfuse:w:0xff:m hfuse:w:0xdb:m efuse:w:0xff:m
#AVRDUDE_PROG := -c avr910 -b 115200 -P /dev/ispprog
AVRDUDE_PROG := -c dragon_isp -P usb

CC = avr-gcc
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
CFLAGS += -fdata-sections -ffunction-sections
CFLAGS += -Wa,-adhlns=$(*F).lst
LDFLAGS = -Wl,-Map,$(@:.elf=.map),--cref
LDFLAGS += -Wl,--relax,--gc-sections

$(PRG).elf: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
# ---------------------------------------------------------------------------

%.o: %.c $(MAKEFILE_LIST)
$(CC) $(CFLAGS) -c $< -o $@

clean:
rm -rf *.o $(PRG).lst $(PRG).map $(PRG).elf $(PRG).hex $(PRG).bin

lst: $(PRG).lst
$(TARGET): $(TARGET).elf
@$(SIZE) -B -x --mcu=$(MCU) $<

%.lst: %.elf
$(OBJDUMP) -h -S $< > $@
$(TARGET).elf: $(SOURCE:.c=.o)
@echo " Linking file: $@"
@$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ 2> /dev/null
@$(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

hex: $(PRG).hex
bin: $(PRG).bin

%.hex: %.elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
%.o: %.c $(MAKEFILE_LIST)
@echo " Building file: $<"
@$(CC) $(CFLAGS) -o $@ -c $<

%.bin: %.elf
$(OBJCOPY) -j .text -j .data -O binary $< $@
clean:
rm -rf $(SOURCE:.c=.o) $(SOURCE:.c=.lst) $(addprefix $(TARGET), .elf .map .lss .hex .bin)

install: text
avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -V -U flash:w:$(PRG).hex
install: $(TARGET).elf
avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U flash:w:$(<:.elf=.hex)

fuses:
avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U efuse:w:0xff:m
avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U hfuse:w:0xdb:m
avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U lfuse:w:0xff:m
avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) $(patsubst %,-U %, $(AVRDUDE_FUSES))

Loading…
Cancel
Save