view Makefile.avr @ 10:f0b4314b91ec

Fix for dual UART devices.
author Daniel O'Connor <darius@dons.net.au>
date Sat, 01 Jan 2011 19:43:34 +1030
parents 5f21a1c8ca06
children 4e10d1eef9a5
line wrap: on
line source

#
# Helper makefile to build AVR sources
#

.SUFFIXES: .hex .out .c .o .elf .dmp .s

# Otherwise we get -march=foo
NO_CPU_CFLAGS=
_CPUCFLAGS=

# Programs
AS=avr-as
CC=avr-gcc
OBJCOPY=avr-objcopy
OBJDUMP=avr-objdump

# Tell as to generate listings
CPPFLAGS+=-Wa,-adhlmsn=${<:T:S/.c/.lst/}

MCU?=notset
CFLAGS+=-mmcu=${MCU}

LDFLAGS+=-Wl,-Map=${PROG}.map,--cref
LDFLAGS+=${LDADD}

RM=rm -f

PROGRAMMER=avrdude
PROGTYPE?=alf
# Need the -B 1 or it is very slow. For slow clocks (eg factory fused) -B 10 works
PROGEXTRA?=-B 1

.if ${PROGTYPE} != "dragon_isp" && ${PROGTYPE} != "dragon_jtag"
PROGEXITS?=vcc,noreset
.endif

.if defined(PROGEXITS) && ${PROGEXITS} != ""
_PROGEXITS=-E ${PROGEXITS}
.endif
.if defined(PROGPORT) && ${PROGPORT} != ""
_PROGPORT=-P ${PROGPORT}
.endif

PROGOPTS?=-p ${PART} -c ${PROGTYPE} ${_PROGPORT} ${_PROGEXITS} -q ${PROGEXTRA}

.if !defined(SRCS)
SRCS=	${PROG}.c
.endif

OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}

all: ${PROG}.hex ${PROG}.dmp

.c.o:
	${CC} ${CFLAGS} ${CPPFLAGS} -c ${.IMPSRC} -o ${.PREFIX}.o

${PROG}.elf: ${OBJS}
	${CC} ${CFLAGS} ${LDFLAGS} -g ${OBJS} -o ${PROG}.elf ${LDADD}

.elf.hex:
	${OBJCOPY} -j .text -j .data -j .bss -j .noinit -O ihex $> $@

.elf.dmp:
	${OBJDUMP} -S ${.IMPSRC} > ${.PREFIX}.dmp

clean:
	${RM} ${PROG}.hex ${PROG}.out ${PROG}.elf ${PROG}.map ${OBJS} ${OBJS:S/.o/.lst/} ${PROG}.dmp

prog: all
	${PROGRAMMER} -U flash:w:${PROG}.hex ${PROGOPTS}