view Makefile @ 0:6dfcd8e5b8df

first release
author Frank Kingswood <frank@kingswood-consulting.co.uk>
date Tue, 25 Mar 2014 20:31:00 +0000
parents
children a70e0a8ac73e
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 -Werror -foptimize-sibling-calls -fpeephole -fpeephole2 \
9 --param max-unrolled-insns=3 --param max-unroll-times=3 \
10 --param inline-unit-growth=1 -fno-tree-scev-cprop -fsplit-wide-types
12 # http://www.tty1.net/blog/2008/avr-gcc-optimisations_en.html
13 LDFLAGS:=$(CFLAGS) -Wl,--relax
15 ifneq "$(LIST)" ""
16 _LIST=-g -Wa,-ahlmns
17 endif
19 V:=0
20 ifeq "$(V)" "0"
21 .SILENT:
22 DASHQ:=-q
23 else
24 DASHV:=-v
25 endif
27 all: main.hex main.avr
29 # --------------------------------------------------------------------------
31 o:
32 mkdir -p o
34 o/%.o:%.S | o#
35 @echo gcc $^
36 avr-gcc -c $(CFLAGS) -o $@ $^ $(_LIST)
38 o/%.o:%.c | o
39 @echo gcc $^
40 avr-gcc -c $(CFLAGS) -std=c99 -o $@ $^ $(_LIST)
42 o/%.o:%.cc | o
43 @echo g++ $^
44 avr-g++ -c $(CFLAGS) -o $@ $^
46 #%.avr:%.o
47 # avr-gcc -L/usr/local/avr/lib $(CFLAGS) -o $@ $^ -v
48 # @chmod -x $@
50 # Convert to hex with objcopy. We can NOT use ld --oformat here.
51 %.hex:%.avr
52 @echo objcopy $@
53 avr-objcopy -j .text -j .data -O ihex $^ $@
54 chmod -x $@
56 # --------------------------------------------------------------------------
58 # need something to pick up latest tag
59 # echo '"'$$(hg tags | sort | awk '/^v[0-9\.]+/||1 { V=$$1 } END { if(V!="") print " " V}')'"'
61 version.h: Makefile $(filter-out version.h,$(wildcard *.cc *.h))
62 ID=$$(hg id -i) ; \
63 TAG=$$(hg tags | sort | awk '/^v[0-9\.]+/ { V=$$1 } END { if(V!="") print " " V}') ; \
64 REV=$$(hg id -r $${TAG:-0}) ; \
65 if [ "$$ID" != "$$REV" ] ; then \
66 [ -n "$$TAG" ] && echo '"'$$TAG' "' ; \
67 echo '"'$$ID'"' ; \
68 fi >$@
70 o/commands.o: commands.cc version.h | o
71 @echo g++ $^
72 avr-g++ -c $(CFLAGS) -o $@ $<
74 main.avr: o/main.o o/commands.o o/gpib.o o/serial.o o/usb_serial.o
75 @echo ld $^
76 avr-g++ -L/usr/local/avr/lib $(LDFLAGS) -o $@ $^ $(DASHV)
77 chmod -x $@
78 avr-size $@
79 CLEAN+=main.avr version.h
81 # --------------------------------------------------------------------------
83 .PHONY: disas fuses program term setspeed clean rebuild
84 disas: main.avr
85 avr-objdump -z -d $^ | avr-c++filt
87 LFUSE=0x62 # clkout=of sut=2 clksel=2 (rc)
88 LFUSE=0xb2 # clkout=on sut=3 clksel=2 (rc)
89 #HFUSE=0xc4 # extreset=off, debugwire=off, spi=off, wdt=on, eesave=on, bod=4=4.5V
90 # NEVER program HFUSE bit 7=0 or bit 5=1, because SPI can no longer be used
91 # HFUSE values should be 0b1X0XXXXX, or 0x8X, 0x9X, 0xCX, 0xDX
92 HFUSE=0xdf # extreset=off, debugwire=off, spi=off, wdt=off, eesave=on, bod=7
93 EFUSE=0xff # self-programming=on
95 fuses:
96 false Dangerous
97 avrdude -p t$(CPU) -u -U efuse:w:$$(($(EFUSE))):m -U hfuse:w:$$(($(HFUSE))):m -U lfuse:w:$$(($(LFUSE))):m
99 program: main.hex
100 ifeq "$(CPU)" "atmega32u4"
101 ./program --program $(CPU) $^
102 else
103 if lsusb -d 03eb:2104 ; then \
104 avrdude -c avrispmkII -p m32u4 $(DASHQ) -U flash:w:$^ ; \
105 elif lsusb -d 16c0:05dc ; then \
106 avrdude -c usbasp-clone -p $(CPU) $(DASHQ) -U flash:w:$^ ;\
107 fi
108 endif
110 term:
111 avrdude -p t$(CPU) -v -E noreset -t
113 setspeed:
114 avrdude -p t$(CPU) -v -E noreset -B300
116 clean:
117 -rm -r o
118 -rm $(CLEAN)
120 rebuild:
121 $(MAKE) clean ; $(MAKE)
123 # ----- EOF Makefile -----