19
19
# program name should not be changed...
20
20
PROGRAM = optiboot
21
21
22
+ # The default behavior is to build using tools that are in the users
23
+ # current path variables, but we can also build using an installed
24
+ # Arduino user IDE setup, or the Arduino source tree.
25
+ # Uncomment this next lines to build within the arduino environment,
26
+ # using the arduino-included avrgcc toolset (mac and pc)
27
+ # ENV ?= arduino
28
+ # ENV ?= arduinodev
29
+ # OS ?= macosx
30
+ # OS ?= windows
31
+
32
+
22
33
# enter the parameters for the avrdude isp tool
23
34
ISPTOOL = stk500v2
24
35
ISPPORT = usb
@@ -27,6 +38,50 @@ ISPSPEED = -b 115200
27
38
MCU_TARGET = atmega168
28
39
LDSECTION = --section-start=.text=0x3e00
29
40
41
+ # Build environments
42
+ # Start of some ugly makefile-isms to allow optiboot to be built
43
+ # in several different environments. See the README.TXT file for
44
+ # details.
45
+
46
+ # default
47
+ fixpath = $(1 )
48
+
49
+ ifeq ($(ENV ) , arduino)
50
+ # For Arduino, we assume that we're connected to the optiboot directory
51
+ # included with the arduino distribution, which means that the full set
52
+ # of avr-tools are "right up there" in standard places.
53
+ TOOLROOT = ../../../tools
54
+ GCCROOT = $(TOOLROOT ) /avr/bin/
55
+ AVRDUDE_CONF = -C$(TOOLROOT ) /avr/etc/avrdude.conf
56
+
57
+ ifeq ($(OS ) , windows)
58
+ # On windows, SOME of the tool paths will need to have backslashes instead
59
+ # of forward slashes (because they use windows cmd.exe for execution instead
60
+ # of a unix/mingw shell?)
61
+ fixpath = $(subst /,\,$1)
62
+ endif
63
+
64
+ else ifeq ($(ENV), arduinodev)
65
+ # Arduino IDE source code environment. Use the unpacked compilers created
66
+ # by the build (you'll need to do "ant build" first.)
67
+ ifeq ($(OS ) , macosx)
68
+ TOOLROOT = ../../../../build/macosx/work/Arduino.app/Contents/Resources/Java/hardware/tools
69
+ endif
70
+ ifeq ($(OS ) , windows)
71
+ TOOLROOT = ../../../../build/windows/work/hardware/tools
72
+ endif
73
+
74
+ GCCROOT = $(TOOLROOT ) /avr/bin/
75
+ AVRDUDE_CONF = -C$(TOOLROOT ) /avr/etc/avrdude.conf
76
+
77
+ else
78
+ GCCROOT =
79
+ AVRDUDE_CONF =
80
+ endif
81
+ #
82
+ # End of build environment code.
83
+
84
+
30
85
# the efuse should really be 0xf8; since, however, only the lower
31
86
# three bits of that byte are used on the atmega168, avrdude gets
32
87
# confused if you specify 1's for the higher bits, see:
@@ -37,10 +92,13 @@ LDSECTION = --section-start=.text=0x3e00
37
92
# lock it), but since the high two bits of the lock byte are
38
93
# unused, avrdude would get confused.
39
94
40
- ISPFUSES = avrdude -c $(ISPTOOL ) -p $(MCU_TARGET ) -P $(ISPPORT ) $(ISPSPEED ) \
41
- -e -u -U lock:w:0x3f:m -U efuse:w:0x$(EFUSE ) :m -U hfuse:w:0x$(HFUSE ) :m -U lfuse:w:0x$(LFUSE ) :m
42
- ISPFLASH = avrdude -c $(ISPTOOL ) -p $(MCU_TARGET ) -P $(ISPPORT ) $(ISPSPEED ) \
43
- -U flash:w:$(PROGRAM ) _$(TARGET ) .hex -U lock:w:0x0f:m
95
+ ISPFUSES = $(GCCROOT ) avrdude $(AVRDUDE_CONF ) -c $(ISPTOOL ) \
96
+ -p $(MCU_TARGET ) -P $(ISPPORT ) $(ISPSPEED ) \
97
+ -e -u -U lock:w:0x3f:m -U efuse:w:0x$(EFUSE ) :m \
98
+ -U hfuse:w:0x$(HFUSE ) :m -U lfuse:w:0x$(LFUSE ) :m
99
+ ISPFLASH = $(GCCROOT ) avrdude $(AVRDUDE_CONF ) -c $(ISPTOOL ) \
100
+ -p $(MCU_TARGET ) -P $(ISPPORT ) $(ISPSPEED ) \
101
+ -U flash:w:$(PROGRAM ) _$(TARGET ) .hex -U lock:w:0x0f:m
44
102
45
103
STK500 = "C:\Program Files\Atmel\AVR Tools\STK500\Stk500.exe"
46
104
STK500-1 = $(STK500 ) -e -d$(MCU_TARGET ) -pf -vf -if$(PROGRAM ) _$(TARGET ) .hex \
@@ -53,15 +111,17 @@ OPTIMIZE = -Os -fno-inline-small-functions -fno-split-wide-types -mshort-calls
53
111
DEFS =
54
112
LIBS =
55
113
56
- CC = avr-gcc
114
+ CC = $( GCCROOT ) avr-gcc
57
115
58
116
# Override is only needed by avr-lib build system.
59
117
60
118
override CFLAGS = -g -Wall $(OPTIMIZE ) -mmcu=$(MCU_TARGET ) -DF_CPU=$(AVR_FREQ ) $(DEFS )
61
- override LDFLAGS = -Wl,$(LDSECTION ) -Wl,--relax -nostartfiles
119
+ override LDFLAGS = -Wl,$(LDSECTION ) -Wl,--relax -Wl,--gc-sections -nostartfiles -nostdlib
120
+
121
+ OBJCOPY = $(GCCROOT ) avr-objcopy
122
+ OBJDUMP = $(call fixpath,$(GCCROOT ) avr-objdump)
62
123
63
- OBJCOPY = avr-objcopy
64
- OBJDUMP = avr-objdump
124
+ SIZE = $(GCCROOT ) avr-size
65
125
66
126
# 20MHz clocked platforms
67
127
#
@@ -222,6 +282,7 @@ isp-stk500: $(PROGRAM)_$(TARGET).hex
222
282
223
283
% .elf : $(OBJ )
224
284
$(CC ) $(CFLAGS ) $(LDFLAGS ) -o $@ $^ $(LIBS )
285
+ $(SIZE ) $@
225
286
226
287
clean :
227
288
rm -rf * .o * .elf * .lst * .map * .sym * .lss * .eep * .srec * .bin * .hex
0 commit comments