view Makefile.avr @ 8:119688bb743f

Don't spin forever waiting for the TWI hardware to do something. I _think_ this will help the case where I find the micro is hanging but I haven't seen an error from it yet.
author darius@dons.net.au
date Fri, 01 May 2009 15:21:31 +0930
parents 43d3b2bef999
children 5f21a1c8ca06
line wrap: on
line source

#
# $Id$
#

.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}