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