view Makefile.avr @ 6:3da232f97e81

Invert the bit mask, we only want to turn off this bit, not everything.
author darius@inchoate.localdomain
date Mon, 20 Apr 2009 13:52:06 +0800
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}