view Makefile @ 8:1969a435a7a2

Change to using 16c0:05e1 shared CDC USB ID Enumerate devices using "udevadm info" (lsusb does not show strings) Randomize serial numbers Add domain name to manufacturer string
author Frank Kingswood <frank@kingswood-consulting.co.uk>
date Mon, 21 Apr 2014 11:03:21 +0100
parents acbd0ddd002b
children 16a338171c99
line wrap: on
line source

2 # export PATH:=/usr/local/avr/bin:$(PATH)
3 # export LIBRARY_PATH:=/usr/local/avr/lib
5 CPU:=atmega32u4
7 CFLAGS:=-mmcu=$(CPU) -mtiny-stack -O3 -Os -DCPU=$(CPU) -DF_CPU=16 \
8 -Wall -Wno-uninitialized -Werror \
9 -foptimize-sibling-calls -fpeephole -fpeephole2 \
10 --param max-unrolled-insns=3 --param max-unroll-times=3 \
11 --param inline-unit-growth=1 -fno-tree-scev-cprop -fsplit-wide-types
13 # http://www.tty1.net/blog/2008/avr-gcc-optimisations_en.html
14 LDFLAGS:=$(CFLAGS) -Wl,--relax
16 ifneq "$(LIST)" ""
17 _LIST=-g -Wa,-ahlmns
18 endif
20 V:=0
21 ifeq "$(V)" "0"
22 .SILENT:
23 DASHQ:=-q
24 else
25 DASHV:=-v
26 endif
28 all: main.hex main.avr
30 # --------------------------------------------------------------------------
32 o:
33 mkdir -p o
35 o/%.o:%.S | o#
36 @echo gcc $^
37 avr-gcc -c $(CFLAGS) -o $@ $^ $(_LIST)
39 o/%.o:%.c | o
40 @echo gcc $^
41 avr-gcc -c $(CFLAGS) -std=c99 -o $@ $^ $(_LIST)
43 o/%.o:%.cc | o
44 @echo g++ $^
45 avr-g++ -c $(CFLAGS) -o $@ $^
47 #%.avr:%.o
48 # avr-gcc -L/usr/local/avr/lib $(CFLAGS) -o $@ $^ -v
49 # @chmod -x $@
51 # Convert to hex with objcopy. We can NOT use ld --oformat here.
52 %.hex:%.avr
53 @echo objcopy $@
54 avr-objcopy -j .text -j .data -O ihex $^ $@
55 chmod -x $@
57 # --------------------------------------------------------------------------
59 # need something to pick up latest tag
60 # echo '"'$$(hg tags | sort | awk '/^v[0-9\.]+/||1 { V=$$1 } END { if(V!="") print " " V}')'"'
62 version.h: $(wildcard *.c *.cc)
63 ID=$$(hg id -i) ; \
64 TAG=$$(hg tags | sort | awk '/^v[0-9\.]+/ { V=$$1 } END { if(V!="") print " " V}') ; \
65 REV=$$(hg id -r $${TAG:-0}) ; \
66 if [ "$$ID" != "$$REV" ] ; then \
67 [ -n "$$TAG" ] && echo '"'$$TAG' "' ; \
68 echo '"'$$ID'"' ; \
69 fi >$@
71 random.h: $(wildcard *.c *.cc)
72 echo "#define STR_SERIAL_NUMBER L\"$$(od -A n -t u -N 4 /dev/urandom | tr -d ' ')\"" >$@
74 o/usb_serial.o: usb_serial.c random.h | o
75 @echo gcc $^
76 avr-gcc -c $(CFLAGS) -o $@ $<
78 o/commands.o: commands.cc version.h | o
79 @echo g++ $^
80 avr-g++ -c $(CFLAGS) -o $@ $<
82 main.avr: o/main.o o/formatting.o o/commands.o o/gpib.o o/serial.o o/usb_serial.o o/timer.o
83 @echo ld $^
84 avr-g++ -L/usr/local/avr/lib $(LDFLAGS) -o $@ $^ $(DASHV)
85 chmod -x $@
86 avr-size $@
88 CLEAN+=main.avr version.h random.h
90 # --------------------------------------------------------------------------
92 .PHONY: disas fuses program term setspeed clean rebuild
93 disas: main.avr
94 avr-objdump -r -z -d $^ | avr-c++filt
96 LFUSE=0x62 # clkout=of sut=2 clksel=2 (rc)
97 LFUSE=0xb2 # clkout=on sut=3 clksel=2 (rc)
98 #HFUSE=0xc4 # extreset=off, debugwire=off, spi=off, wdt=on, eesave=on, bod=4=4.5V
99 # NEVER program HFUSE bit 7=0 or bit 5=1, because SPI can no longer be used
100 # HFUSE values should be 0b1X0XXXXX, or 0x8X, 0x9X, 0xCX, 0xDX
101 HFUSE=0xdf # extreset=off, debugwire=off, spi=off, wdt=off, eesave=on, bod=7
102 EFUSE=0xff # self-programming=on
104 fuses:
105 false Dangerous
106 avrdude -p t$(CPU) -u -U efuse:w:$$(($(EFUSE))):m -U hfuse:w:$$(($(HFUSE))):m -U lfuse:w:$$(($(LFUSE))):m
108 program: main.hex
109 ifeq "$(CPU)" "atmega32u4"
110 ./program $(DASHV) --program $(CPU) $^
111 else
112 if lsusb -d 03eb:2104 ; then \
113 avrdude -c avrispmkII -p m32u4 $(DASHQ) -U flash:w:$^ ; \
114 elif lsusb -d 16c0:05dc ; then \
115 avrdude -c usbasp-clone -p $(CPU) $(DASHQ) -U flash:w:$^ ;\
116 fi
117 endif
119 term:
120 avrdude -p t$(CPU) -v -E noreset -t
122 setspeed:
123 avrdude -p t$(CPU) -v -E noreset -B300
125 clean:
126 -rm -r o
127 -rm $(CLEAN)
129 rebuild:
130 $(MAKE) clean ; $(MAKE)
132 # ----- EOF Makefile -----