Makefile

changeset 0
2c8ba1964db7
equal deleted inserted replaced
-1:000000000000 0:2c8ba1964db7
1 # Sprinter Arduino Project Makefile
2 #
3 # Makefile Based on:
4 # Arduino 0011 Makefile
5 # Arduino adaptation by mellis, eighthave, oli.keller
6 #
7 # This has been tested with Arduino 0022.
8 #
9 # This makefile allows you to build sketches from the command line
10 # without the Arduino environment (or Java).
11 #
12 # Detailed instructions for using the makefile:
13 #
14 # 1. Modify the line containg "INSTALL_DIR" to point to the directory that
15 # contains the Arduino installation (for example, under Mac OS X, this
16 # might be /Applications/arduino-0012).
17 #
18 # 2. Modify the line containing "PORT" to refer to the filename
19 # representing the USB or serial connection to your Arduino board
20 # (e.g. PORT = /dev/tty.USB0). If the exact name of this file
21 # changes, you can use * as a wildcard (e.g. PORT = /dev/tty.usb*).
22 #
23 # 3. Set the line containing "MCU" to match your board's processor.
24 # Older one's are atmega8 based, newer ones like Arduino Mini, Bluetooth
25 # or Diecimila have the atmega168. If you're using a LilyPad Arduino,
26 # change F_CPU to 8000000. If you are using Gen7 electronics, you
27 # probably need to use 20000000. Either way, you must regenerate
28 # the speed lookup table with create_speed_lookuptable.py.
29 #
30 # 4. Type "make" and press enter to compile/verify your program.
31 #
32 # 5. Type "make upload", reset your Arduino board, and press enter to
33 # upload your program to the Arduino board.
34 #
35 # $Id$
36
37 #For "old" Arduino Mega
38 #MCU = atmega1280
39 #For Arduino Mega2560
40 #MCU = atmega2560
41 #For Sanguinololu
42 #MCU = atmega644p
43 MCU = atmega1284p
44 #For Printrboard
45 #MCU = at90usb1286
46
47
48 #Arduino install directory
49 INSTALL_DIR = ../../arduino-0022/
50
51 # Be sure to regenerate speed_lookuptable.h with create_speed_lookuptable.py
52 # if you are setting this to something other than 16MHz
53 F_CPU = 16000000
54
55 UPLOAD_RATE = 115200
56 AVRDUDE_PROGRAMMER = arduino
57 PORT = /dev/arduino
58
59 TARGET = $(notdir $(CURDIR))
60
61
62 ############################################################################
63 # Below here nothing should be changed...
64
65 ARDUINO = $(INSTALL_DIR)/hardware/arduino/cores/arduino
66 AVR_TOOLS_PATH =
67 SRC = $(ARDUINO)/pins_arduino.c $(ARDUINO)/wiring.c \
68 $(ARDUINO)/wiring_analog.c $(ARDUINO)/wiring_digital.c \
69 $(ARDUINO)/wiring_pulse.c \
70 $(ARDUINO)/wiring_shift.c $(ARDUINO)/WInterrupts.c
71 CXXSRC = $(ARDUINO)/WMath.cpp $(ARDUINO)/WString.cpp\
72 $(ARDUINO)/Print.cpp applet/Marlin.cpp MarlinSerial.cpp Sd2Card.cpp SdBaseFile.cpp SdFatUtil.cpp SdFile.cpp SdVolume.cpp motion_control.cpp planner.cpp stepper.cpp temperature.cpp cardreader.cpp MatrixMath.cpp FPUTransform.cpp z_probe.cpp
73
74 FORMAT = ihex
75
76
77 # Name of this Makefile (used for "make depend").
78 MAKEFILE = Makefile
79
80 # Debugging format.
81 # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
82 # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
83 DEBUG = stabs
84
85 OPT = s
86
87 # Place -D or -U options here
88 CDEFS = -DF_CPU=$(F_CPU)
89 CXXDEFS = -DF_CPU=$(F_CPU)
90
91 # Place -I options here
92 CINCS = -I$(ARDUINO)
93 CXXINCS = -I$(ARDUINO)
94
95 # Compiler flag to set the C Standard level.
96 # c89 - "ANSI" C
97 # gnu89 - c89 plus GCC extensions
98 # c99 - ISO C99 standard (not yet fully implemented)
99 # gnu99 - c99 plus GCC extensions
100 #CSTANDARD = -std=gnu99
101 CDEBUG = -g$(DEBUG)
102 CWARN = -Wall -Wstrict-prototypes
103 CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -w -ffunction-sections -fdata-sections -DARDUINO=22
104 #CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
105
106 CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CEXTRA) $(CTUNING)
107 CXXFLAGS = $(CDEFS) $(CINCS) -O$(OPT) -Wall $(CEXTRA) $(CTUNING)
108 #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
109 LDFLAGS = -lm
110
111
112 # Programming support using avrdude. Settings and variables.
113 AVRDUDE_PORT = $(PORT)
114 AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex:i
115 AVRDUDE_FLAGS = -D -C $(INSTALL_DIR)/hardware/tools/avrdude.conf \
116 -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \
117 -b $(UPLOAD_RATE)
118
119 # Program settings
120 CC = $(AVR_TOOLS_PATH)avr-gcc
121 CXX = $(AVR_TOOLS_PATH)avr-g++
122 OBJCOPY = $(AVR_TOOLS_PATH)avr-objcopy
123 OBJDUMP = $(AVR_TOOLS_PATH)avr-objdump
124 AR = $(AVR_TOOLS_PATH)avr-ar
125 SIZE = $(AVR_TOOLS_PATH)avr-size
126 NM = $(AVR_TOOLS_PATH)avr-nm
127 AVRDUDE = avrdude
128 REMOVE = rm -f
129 MV = mv -f
130
131 # Define all object files.
132 OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o)
133
134 # Define all listing files.
135 LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst)
136
137 # Combine all necessary flags and optional flags.
138 # Add target processor to flags.
139 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
140 ALL_CXXFLAGS = -mmcu=$(MCU) -I. $(CXXFLAGS)
141 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
142
143
144 # Default target.
145 all: build sizeafter
146
147 build: elf hex
148
149 applet/$(TARGET).cpp: $(TARGET).pde $(MAKEFILE)
150
151 applet/%.cpp: %.pde
152 # Here is the "preprocessing".
153 # It creates a .cpp file based with the same name as the .pde file.
154 # On top of the new .cpp file comes the WProgram.h header.
155 # At the end there is a generic main() function attached.
156 # Then the .cpp file will be compiled. Errors during compile will
157 # refer to this new, automatically generated, file.
158 # Not the original .pde file you actually edit...
159 @echo " WR $@"
160 @test -d $(dir $@) || mkdir $(dir $@)
161 @echo '#include "WProgram.h"' > $@
162 @cat $< >> $@
163 @cat $(ARDUINO)/main.cpp >> $@
164
165 elf: applet/$(TARGET).elf
166 hex: applet/$(TARGET).hex
167 eep: applet/$(TARGET).eep
168 lss: applet/$(TARGET).lss
169 sym: applet/$(TARGET).sym
170
171 # Program the device.
172 upload: applet/$(TARGET).hex
173 stty hup < $(PORT); true
174 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
175 stty -hup < $(PORT); true
176
177
178 # Display size of file.
179 HEXSIZE = $(SIZE) --target=$(FORMAT) applet/$(TARGET).hex
180 ELFSIZE = $(SIZE) applet/$(TARGET).elf
181 sizebefore:
182 @if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi
183
184 sizeafter:
185 @if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
186
187
188 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
189 COFFCONVERT=$(OBJCOPY) --debugging \
190 --change-section-address .data-0x800000 \
191 --change-section-address .bss-0x800000 \
192 --change-section-address .noinit-0x800000 \
193 --change-section-address .eeprom-0x810000
194
195
196 coff: applet/$(TARGET).elf
197 $(COFFCONVERT) -O coff-avr applet/$(TARGET).elf $(TARGET).cof
198
199
200 extcoff: $(TARGET).elf
201 $(COFFCONVERT) -O coff-ext-avr applet/$(TARGET).elf $(TARGET).cof
202
203
204 .SUFFIXES: .elf .hex .eep .lss .sym
205 .PRECIOUS: .o
206
207 .elf.hex:
208 @echo " COPY $@"
209 @$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
210
211 .elf.eep:
212 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
213 --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
214
215 # Create extended listing file from ELF output file.
216 .elf.lss:
217 $(OBJDUMP) -h -S $< > $@
218
219 # Create a symbol table from ELF output file.
220 .elf.sym:
221 $(NM) -n $< > $@
222
223 # Link: create ELF output file from library.
224 applet/$(TARGET).elf: applet/$(TARGET).cpp applet/core.a Configuration.h
225 @echo " CXX $@"
226 @$(CC) $(ALL_CXXFLAGS) -Wl,--gc-sections -o $@ applet/$(TARGET).cpp -L. applet/core.a $(LDFLAGS)
227
228 applet/core.a: $(OBJ) Configuration.h
229 @for i in $(OBJ); do echo " AR $$i"; $(AR) rcs applet/core.a $$i; done
230
231 %.o: %.c Configuration.h $(MAKEFILE)
232 @echo " CC $@"
233 @$(CC) -c $(ALL_CFLAGS) $< -o $@
234
235 %.o: %.cpp Configuration.h $(MAKEFILE)
236 @echo " CXX $@"
237 @$(CXX) -c $(ALL_CXXFLAGS) $< -o $@
238
239 # Target: clean project.
240 clean:
241 @echo " RM applet/*"
242 @$(REMOVE) applet/$(TARGET).hex applet/$(TARGET).eep applet/$(TARGET).cof applet/$(TARGET).elf \
243 applet/$(TARGET).map applet/$(TARGET).sym applet/$(TARGET).lss applet/$(TARGET).cpp applet/core.a \
244 $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)
245 @echo " RMDIR applet/"
246 @rmdir applet
247
248 depend:
249 if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \
250 then \
251 sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \
252 $(MAKEFILE).$$$$ && \
253 $(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \
254 fi
255 echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \
256 >> $(MAKEFILE); \
257 $(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE)
258
259 .PHONY: all build elf hex eep lss sym program coff extcoff clean depend applet_files sizebefore sizeafter

mercurial