annotate Makefile.avr @ 20:76a6bad110e2

Add routine to split string into argv/argc
author Daniel O'Connor <darius@dons.net.au>
date Sat, 31 Jan 2015 23:30:35 +1030
parents b5e4591b6570
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
1 #
9
5f21a1c8ca06 Remove $Id$ and add a brief comment.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
2 # Helper makefile to build AVR sources
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
3 #
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
4
12
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
5 .SUFFIXES: .hex .out .c .o .elf .dmp .s .fuse
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
6
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
7 # Otherwise we get -march=foo
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
8 NO_CPU_CFLAGS=
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
9 _CPUCFLAGS=
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
10
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
11 # Programs
17
bbe75f183cf9 Allow path to toolchain to be specified.
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
12 TPREFIX?=
19
b5e4591b6570 - Satisfy new compiler
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
13 AS=${TPREFIX}avr-as
b5e4591b6570 - Satisfy new compiler
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
14 CC=${TPREFIX}avr-gcc
b5e4591b6570 - Satisfy new compiler
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
15 OBJCOPY=${TPREFIX}avr-objcopy
b5e4591b6570 - Satisfy new compiler
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
16 OBJDUMP=${TPREFIX}avr-objdump
12
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
17 SED=sed
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
18 TAIL=tail
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
19
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
20 # Tell as to generate listings
1
f5022e20d550 Fixup so .lst files end up in the project directory not the library one.
darius@Inchoate
parents: 0
diff changeset
21 CPPFLAGS+=-Wa,-adhlmsn=${<:T:S/.c/.lst/}
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
22
2
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
23 MCU?=notset
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
24 CFLAGS+=-mmcu=${MCU}
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
25
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
26 LDFLAGS+=-Wl,-Map=${PROG}.map,--cref
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
27 LDFLAGS+=${LDADD}
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
28
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
29 RM=rm -f
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
30
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
31 PROGRAMMER=avrdude
2
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
32 PROGTYPE?=alf
12
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
33
2
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
34 # Need the -B 1 or it is very slow. For slow clocks (eg factory fused) -B 10 works
17
bbe75f183cf9 Allow path to toolchain to be specified.
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
35 # For BP programming this is intolerably slow
bbe75f183cf9 Allow path to toolchain to be specified.
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
36 #PROGOPTS+=-B 1
12
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
37
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
38 .if defined(WITH_FUSES)
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
39 FUSEFILE=${PROG}.fuse
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
40 PROGOPTS+=`cat ${PROG}.fuse`
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
41 .elf.fuse:
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
42 ${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}
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
43 .else
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
44 FUSEFILE=
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
45 .endif
2
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
46
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
47 .if ${PROGTYPE} != "dragon_isp" && ${PROGTYPE} != "dragon_jtag"
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
48 PROGEXITS?=vcc,noreset
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
49 .endif
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
50
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
51 .if defined(PROGEXITS) && ${PROGEXITS} != ""
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
52 _PROGEXITS=-E ${PROGEXITS}
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
53 .endif
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
54 .if defined(PROGPORT) && ${PROGPORT} != ""
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
55 _PROGPORT=-P ${PROGPORT}
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
56 .endif
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
57
17
bbe75f183cf9 Allow path to toolchain to be specified.
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
58 PROGPART?=${PART}
bbe75f183cf9 Allow path to toolchain to be specified.
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
59
bbe75f183cf9 Allow path to toolchain to be specified.
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
60 PROGOPTS+=-p ${PROGPART} -c ${PROGTYPE} ${_PROGPORT} ${_PROGEXITS} -U flash:w:${PROG}.hex ${PROGEXTRA}
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
61
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
62 .if !defined(SRCS)
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
63 SRCS= ${PROG}.c
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
64 .endif
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
65
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
66 OBJS+= ${SRCS:N*.h:R:S/$/.o/g}
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
67
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
68 all: ${PROG}.hex ${PROG}.dmp
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
69
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
70 .c.o:
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
71 ${CC} ${CFLAGS} ${CPPFLAGS} -c ${.IMPSRC} -o ${.PREFIX}.o
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
72
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
73 ${PROG}.elf: ${OBJS}
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
74 ${CC} ${CFLAGS} ${LDFLAGS} -g ${OBJS} -o ${PROG}.elf ${LDADD}
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
75
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
76 .elf.hex:
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
77 ${OBJCOPY} -j .text -j .data -j .bss -j .noinit -O ihex $> $@
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
78
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
79 .elf.dmp:
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
80 ${OBJDUMP} -S ${.IMPSRC} > ${.PREFIX}.dmp
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
81
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
82 clean:
12
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
83 ${RM} ${PROG}.hex ${PROG}.out ${PROG}.elf ${PROG}.map ${OBJS} ${OBJS:S/.o/.lst/} ${PROG}.dmp ${PROG}.fuse
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
84
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
85 prog: ${PROG}.elf ${FUSEFILE}
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
86 ${PROGRAMMER} ${PROGOPTS}
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
87
12
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
88 #########################
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
89 #;;; Local Variables: ***
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
90 #;;; mode:makefile ***
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
91 #;;; End: ***