Skip to content

Instantly share code, notes, and snippets.

@letoh
Created November 13, 2012 05:15
Show Gist options
  • Select an option

  • Save letoh/4064035 to your computer and use it in GitHub Desktop.

Select an option

Save letoh/4064035 to your computer and use it in GitHub Desktop.
makefile for avr project
MCU ?= attiny2313
PROJ = test
TARGET = $(PROJ).hex # $(PROJ).bin
INC =
LIBS =
include ../000_common/make.rules
INC += -I../000_common
CFLAGS = -I/usr/cross/avr/include -mmcu=$(MCU) -Os \
-fpack-struct -fshort-enums \
-funsigned-bitfields -funsigned-char \
-Wall -Wstrict-prototypes \
-Wa,-ahlms=$(firstword $(filter %.lst, $(<:.c=.lst)))
LDFLAGS = -Wl,-Map,$(PROJ).map,--cref -mmcu=$(MCU) -nostdlib $(LIBS) # -lm
#ASMFLAGS =-I. $(INC) -mmcu=$(MCU) \
# -x assembler-with-cpp \
# -Wa,-gstabs,-ahlms=$(firstword $(<:.S=.lst) $(<.asm=.lst))
ASMFLAGS +=-I. $(INC) -mmcu=$(MCU) \
-x assembler-with-cpp \
-Wa,-I../000_common,-ahlms=$(firstword $(<:.S=.lst) $(<.asm=.lst))
# avr-objdump -h -S -D --stabs --disassemble-zeroes xxx.elf > xxx.lst
CC = avr-gcc
AS = avr-as
LD = avr-ld
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
AVRDUDE = avrdude.delay
ISP = $(AVRDUDE) -c avrisp -p $(MCU) -b 19200 -P /dev/ttyUSB0 -e
.SUFFIXES:
.SUFFIXES: .c .o .elf .hex .bin .S .asm
.c.o:
@echo $^' -> '$@
@echo 'generate listing...'
@$(CC) -c $(CFLAGS) -o $@ $^
.S.o:
@echo $^' -> '$@
@$(CC) -c $(ASMFLAGS) -o $@ $^
.asm.S:
@echo $^' -> '$@
@cp $^ $@
# @$(CC) -c $(ASMFLAGS) -o $@ $^
.o.elf:
@echo $^' -> '$@
@echo 'generate map file...'
@$(CC) $(LDFLAGS) -o $@ $^
@$(OBJDUMP) -h -S -D --stabs --disassemble-zeroes $@ > $@.lst
@$(SIZE) $@
.elf.hex:
@echo $^' -> '$@
@$(OBJCOPY) -j .text -j .data -O ihex $^ $@
.elf.bin:
@echo $^' -> '$@
@$(OBJCOPY) -j .text -j .data -O binary $^ $@
.PHONY:
.PHONY: all clean isp
all: $(TARGET)
isp: $(PROJ).hex
$(ISP) -U flash:w:$^
clean:
@echo "clean..."
@rm -f *.o *.hex *.bin *.map *.elf *.lst
# vim: ft=make
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment