view Makefile.avr @ 18:0876867347de

Remove CVS tags
author Daniel O'Connor <darius@dons.net.au>
date Sat, 31 Jan 2015 23:26:21 +1030
parents bbe75f183cf9
children b5e4591b6570
line wrap: on
line source

#
# Helper makefile to build AVR sources
#

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

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

# Programs
TPREFIX?=
AS=${TPREFIX}/avr-as
CC=${TPREFIX}/avr-gcc
OBJCOPY=${TPREFIX}/avr-objcopy
OBJDUMP=${TPREFIX}/avr-objdump
SED=sed
TAIL=tail

# 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
# For BP programming this is intolerably slow
#PROGOPTS+=-B 1

.if defined(WITH_FUSES)
FUSEFILE=${PROG}.fuse
PROGOPTS+=`cat ${PROG}.fuse`
.elf.fuse:
	${OBJDUMP} -s -j .fuse ${.IMPSRC} | ${TAIL} -1 | ${SED} -nEe 's, [^ ]+ (..)(..)(..).*,-Ulfuse:w:0x\1:m -Uhfuse:w:0x\2:m -Uefuse:w:0x\3:m,p' >${.TARGET}
.else
FUSEFILE=
.endif

.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

PROGPART?=${PART}

PROGOPTS+=-p ${PROGPART} -c ${PROGTYPE} ${_PROGPORT} ${_PROGEXITS} -U flash:w:${PROG}.hex ${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}.fuse

prog: ${PROG}.elf ${FUSEFILE}
	${PROGRAMMER} ${PROGOPTS}

#########################
#;;; Local Variables: ***
#;;; mode:makefile ***
#;;; End: ***