浏览代码

Update on makefile, should make it easier to compile for different boards without changing the makefile. (Still missing Arduino 1.x.x support).

daid303 12 年前
父节点
当前提交
789be03b4f
共有 1 个文件被更改,包括 171 次插入93 次删除
  1. 171
    93
      Marlin/Makefile

+ 171
- 93
Marlin/Makefile 查看文件

@@ -3,6 +3,7 @@
3 3
 # Makefile Based on:
4 4
 # Arduino 0011 Makefile
5 5
 # Arduino adaptation by mellis, eighthave, oli.keller
6
+# Marlin adaption by Daid
6 7
 #
7 8
 # This has been tested with Arduino 0022.
8 9
 # 
@@ -11,14 +12,14 @@
11 12
 #
12 13
 # Detailed instructions for using the makefile:
13 14
 #
14
-#  1. Modify the line containg "INSTALL_DIR" to point to the directory that
15
+#  1. Modify the line containg "ARDUINO_INSTALL_DIR" to point to the directory that
15 16
 #     contains the Arduino installation (for example, under Mac OS X, this
16 17
 #     might be /Applications/arduino-0012).
17 18
 #
18
-#  2. Modify the line containing "PORT" to refer to the filename
19
+#  2. Modify the line containing "UPLOAD_PORT" to refer to the filename
19 20
 #     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*).
21
+#     (e.g. UPLOAD_PORT = /dev/tty.USB0).  If the exact name of this file
22
+#     changes, you can use * as a wildcard (e.g. UPLOAD_PORT = /dev/tty.usb*).
22 23
 #
23 24
 #  3. Set the line containing "MCU" to match your board's processor. 
24 25
 #     Older one's are atmega8 based, newer ones like Arduino Mini, Bluetooth
@@ -32,43 +33,139 @@
32 33
 #  5. Type "make upload", reset your Arduino board, and press enter to
33 34
 #     upload your program to the Arduino board.
34 35
 #
35
-# $Id$
36
+# Note that all settings are set with ?=, this means you can override them
37
+# from the commandline with "make HARDWARE_MOTHERBOARD=71" for example
36 38
 
37
-#For "old" Arduino Mega
38
-#MCU = atmega1280
39
-#For Arduino Mega2560
40
-#MCU = atmega2560
41
-#For Sanguinololu
42
-MCU = atmega644p 
39
+# This defined the board you are compiling for (see Configuration.h for the options)
40
+HARDWARE_MOTHERBOARD ?= 11
43 41
 
44
-# Here you select "arduino", "Sanguino", "Gen7", ...
45
-HARDWARE_VARIANT 		= Sanguino
46
-# This defined the board you are compiling for
47
-HARDWARE_MOTHERBOARD	= 91
42
+# Arduino source install directory, and version number
43
+ARDUINO_INSTALL_DIR  ?= ../../arduino-0022
44
+ARDUINO_VERSION      ?= 22
48 45
 
49
-# Arduino source install directory
50
-INSTALL_DIR = ../../arduino-0022
46
+# You can optionally set a path to the avr-gcc tools. Requires a trailing slash. (ex: /usr/local/avr-gcc/bin)
47
+AVR_TOOLS_PATH ?= 
48
+
49
+#Programmer configuration
50
+UPLOAD_RATE        ?= 115200
51
+AVRDUDE_PROGRAMMER ?= arduino
52
+UPLOAD_PORT        ?= /dev/arduino
53
+
54
+#Directory used to build files in, contains all the build files, from object files to the final hex file.
55
+BUILD_DIR          ?= applet
56
+
57
+############################################################################
58
+# Below here nothing should be changed...
59
+
60
+# Here the Arduino variant is selected by the board type
61
+# HARDWARE_VARIANT = "arduino", "Sanguino", "Gen7", ...
62
+# MCU = "atmega1280", "Mega2560", "atmega2560", "atmega644p", ...
63
+
64
+#Gen7
65
+ifeq ($(HARDWARE_MOTHERBOARD),10)
66
+HARDWARE_VARIANT ?= Gen7
67
+MCU              ?= atmega644 
68
+F_CPU            ?= 20000000
69
+else ifeq  ($(HARDWARE_MOTHERBOARD),11)
70
+HARDWARE_VARIANT ?= Gen7
71
+MCU              ?= atmega644p
72
+F_CPU            ?= 20000000
73
+else ifeq  ($(HARDWARE_MOTHERBOARD),12)
74
+HARDWARE_VARIANT ?= Gen7
75
+MCU              ?= atmega644p
76
+F_CPU            ?= 20000000
77
+else ifeq  ($(HARDWARE_MOTHERBOARD),13)
78
+HARDWARE_VARIANT ?= Gen7
79
+MCU              ?= atmega1284p
80
+F_CPU            ?= 20000000
81
+
82
+#RAMPS
83
+else ifeq  ($(HARDWARE_MOTHERBOARD),3)
84
+HARDWARE_VARIANT ?= arduino
85
+MCU              ?= atmega2560
86
+else ifeq  ($(HARDWARE_MOTHERBOARD),33)
87
+HARDWARE_VARIANT ?= arduino
88
+MCU              ?= atmega2560
89
+else ifeq  ($(HARDWARE_MOTHERBOARD),34)
90
+HARDWARE_VARIANT ?= arduino
91
+MCU              ?= atmega2560
92
+
93
+#Duemilanove w/ ATMega328P pin assignment
94
+else ifeq  ($(HARDWARE_MOTHERBOARD),4)
95
+HARDWARE_VARIANT ?= arduino
96
+MCU              ?= atmega328p
97
+
98
+#Gen6
99
+else ifeq  ($(HARDWARE_MOTHERBOARD),5)
100
+HARDWARE_VARIANT ?= Gen6
101
+MCU              ?= atmega664p
102
+else ifeq  ($(HARDWARE_MOTHERBOARD),51)
103
+HARDWARE_VARIANT ?= Gen6
104
+MCU              ?= atmega664p
105
+
106
+#Sanguinololu
107
+else ifeq  ($(HARDWARE_MOTHERBOARD),6)
108
+HARDWARE_VARIANT ?= Sanguino
109
+MCU              ?= atmega1284p
110
+else ifeq  ($(HARDWARE_MOTHERBOARD),62)
111
+HARDWARE_VARIANT ?= Sanguino
112
+MCU              ?= atmega1284p
113
+else ifeq  ($(HARDWARE_MOTHERBOARD),63)
114
+HARDWARE_VARIANT ?= Sanguino
115
+MCU              ?= atmega1284p
116
+
117
+#Ultimaker
118
+else ifeq  ($(HARDWARE_MOTHERBOARD),7)
119
+HARDWARE_VARIANT ?= arduino
120
+MCU              ?= atmega2560
121
+else ifeq  ($(HARDWARE_MOTHERBOARD),71)
122
+HARDWARE_VARIANT ?= arduino
123
+MCU              ?= atmega1280
124
+
125
+#Teensylu
126
+else ifeq  ($(HARDWARE_MOTHERBOARD),8)
127
+HARDWARE_VARIANT ?= Teensyduino
128
+MCU              ?= at90usb1286
129
+
130
+#Gen3+
131
+else ifeq  ($(HARDWARE_MOTHERBOARD),9)
132
+HARDWARE_VARIANT ?= Sanguino
133
+MCU              ?= atmega644p
134
+
135
+#Megatronics
136
+else ifeq  ($(HARDWARE_MOTHERBOARD),70)
137
+HARDWARE_VARIANT ?= arduino
138
+MCU              ?= atmega2560
139
+
140
+#Alpha OMCA board
141
+else ifeq  ($(HARDWARE_MOTHERBOARD),90)
142
+HARDWARE_VARIANT ?= SanguinoA
143
+MCU              ?= atmega644
144
+
145
+#Final OMCA board
146
+else ifeq  ($(HARDWARE_MOTHERBOARD),91)
147
+HARDWARE_VARIANT ?= Sanguino
148
+MCU              ?= atmega644p
149
+
150
+endif
151
+
152
+# Be sure to regenerate speed_lookuptable.h with create_speed_lookuptable.py
153
+# if you are setting this to something other than 16MHz
154
+# Set to 16Mhz if not yet set.
155
+F_CPU ?= 16000000
51 156
 
52 157
 # Arduino containd the main source code for the Arduino
53 158
 # Libraries, the "hardware variant" are for boards
54 159
 # that derives from that, and their source are present in
55 160
 # the main Marlin source directory
56
-ARDUINO = $(INSTALL_DIR)/hardware/arduino/cores/arduino
161
+ARDUINO = $(ARDUINO_INSTALL_DIR)/hardware/arduino/cores/arduino
57 162
 
58 163
 ifeq (${HARDWARE_VARIANT}, arduino)
59
-HARDWARE_SRC= $(ARDUINO)
164
+HARDWARE_SRC = $(ARDUINO)
60 165
 else
61
-HARDWARE_SRC= $(HARDWARE_VARIANT)/cores/arduino
166
+HARDWARE_SRC = $(HARDWARE_VARIANT)/cores/arduino
62 167
 endif
63 168
 
64
-# Be sure to regenerate speed_lookuptable.h with create_speed_lookuptable.py
65
-# if you are setting this to something other than 16MHz
66
-F_CPU = 16000000
67
-
68
-UPLOAD_RATE = 115200
69
-AVRDUDE_PROGRAMMER = arduino
70
-PORT = /dev/arduino
71
-
72 169
 TARGET = $(notdir $(CURDIR))
73 170
 
74 171
 # VPATH tells make to look into these directory for source files,
@@ -76,20 +173,18 @@ TARGET = $(notdir $(CURDIR))
76 173
 # directory is added here
77 174
 
78 175
 VPATH = .
79
-VPATH += applet
176
+VPATH += $(BUILD_DIR)
80 177
 VPATH += $(HARDWARE_SRC)
81 178
 VPATH += $(ARDUINO)
82
-VPATH += $(INSTALL_DIR)/libraries/LiquidCrystal
179
+VPATH += $(ARDUINO_INSTALL_DIR)/libraries/LiquidCrystal
180
+#TODO: Add the path to the hardware variant when using Arduino >= 100, and adjust the files required for compilation.
181
+#VPATH += $(ARDUINO_INSTALL_DIR)/hardware/arduino/variants/mega
83 182
 
84
-############################################################################
85
-# Below here nothing should be changed...
86
-
87
-AVR_TOOLS_PATH = 
88
-SRC =  pins_arduino.c wiring.c \
183
+SRC = pins_arduino.c main.c wiring.c \
89 184
 	wiring_analog.c wiring_digital.c \
90 185
 	wiring_pulse.c \
91 186
 	wiring_shift.c WInterrupts.c
92
-CXXSRC = WMath.cpp WString.cpp Print.cpp Marlin.cpp Marlin_main.cpp	\
187
+CXXSRC = WMath.cpp WString.cpp Print.cpp Marlin_main.cpp	\
93 188
 	MarlinSerial.cpp Sd2Card.cpp SdBaseFile.cpp SdFatUtil.cpp	\
94 189
 	SdFile.cpp SdVolume.cpp motion_control.cpp planner.cpp		\
95 190
 	stepper.cpp temperature.cpp cardreader.cpp ConfigurationStore.cpp
@@ -125,8 +220,8 @@ CDEBUG = -g$(DEBUG)
125 220
 CWARN = -Wall -Wstrict-prototypes
126 221
 CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct \
127 222
 	-fshort-enums -w -ffunction-sections -fdata-sections \
128
-	-DARDUINO=22
129
-ifneq (${HARDWARE_MOTHERBOARD},)
223
+	-DARDUINO=$(ARDUINO_VERSION)
224
+ifneq ($(HARDWARE_MOTHERBOARD),)
130 225
 CTUNING += -DMOTHERBOARD=${HARDWARE_MOTHERBOARD}
131 226
 endif
132 227
 #CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
@@ -138,9 +233,9 @@ LDFLAGS = -lm
138 233
 
139 234
 
140 235
 # Programming support using avrdude. Settings and variables.
141
-AVRDUDE_PORT = $(PORT)
142
-AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex:i
143
-AVRDUDE_FLAGS = -D -C $(INSTALL_DIR)/hardware/tools/avrdude.conf \
236
+AVRDUDE_PORT = $(UPLOAD_PORT)
237
+AVRDUDE_WRITE_FLASH = -U flash:w:$(BUILD_DIR)/$(TARGET).hex:i
238
+AVRDUDE_FLAGS = -D -C $(ARDUINO_INSTALL_DIR)/hardware/tools/avrdude.conf \
144 239
 	-p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \
145 240
 	-b $(UPLOAD_RATE)
146 241
 
@@ -157,9 +252,9 @@ REMOVE = rm -f
157 252
 MV = mv -f
158 253
 
159 254
 # Define all object files.
160
-OBJ = ${patsubst %.c, applet/%.o, ${SRC}}
161
-OBJ += ${patsubst %.cpp, applet/%.o, ${CXXSRC}}
162
-OBJ += ${patsubst %.S, applet/%.o, ${ASRC}}
255
+OBJ = ${patsubst %.c, $(BUILD_DIR)/%.o, ${SRC}}
256
+OBJ += ${patsubst %.cpp, $(BUILD_DIR)/%.o, ${CXXSRC}}
257
+OBJ += ${patsubst %.S, $(BUILD_DIR)/%.o, ${ASRC}}
163 258
 
164 259
 # Define all listing files.
165 260
 LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst)
@@ -182,52 +277,38 @@ endif
182 277
 # Default target.
183 278
 all: sizeafter
184 279
 
185
-build: applet elf hex 
280
+build: $(BUILD_DIR) elf hex 
186 281
 
187 282
 # Creates the object directory
188
-applet: 
189
-	$P mkdir -p applet
190
-
191
-# the .cpp for Marlin depends on the .pde
192
-#applet/$(TARGET).cpp: $(TARGET).pde
193
-# ..and the .o depends from the .cpp
194
-#applet/%.o: applet/%.cpp
195
-
196
-applet/%.cpp: %.pde $(MAKEFILE)
197
-# Here is the "preprocessing".
198
-# It creates a .cpp file based with the same name as the .pde file.
199
-# On top of the new .cpp file comes the WProgram.h header.
200
-	$(Pecho) "  WR    $@"
201
-	$P echo '#include "WProgram.h"' > $@
202
-	$P echo '#include "$<"' >>$@
203
-	$P echo '#include "$(ARDUINO)/main.cpp"' >> $@
204
-
205
-elf: applet/$(TARGET).elf
206
-hex: applet/$(TARGET).hex
207
-eep: applet/$(TARGET).eep
208
-lss: applet/$(TARGET).lss 
209
-sym: applet/$(TARGET).sym
283
+$(BUILD_DIR): 
284
+	$P mkdir -p $(BUILD_DIR)
285
+
286
+elf: $(BUILD_DIR)/$(TARGET).elf
287
+hex: $(BUILD_DIR)/$(TARGET).hex
288
+eep: $(BUILD_DIR)/$(TARGET).eep
289
+lss: $(BUILD_DIR)/$(TARGET).lss 
290
+sym: $(BUILD_DIR)/$(TARGET).sym
210 291
 
211 292
 # Program the device.  
212 293
 # Do not try to reset an arduino if it's not one
213
-upload: applet/$(TARGET).hex
294
+upload: $(BUILD_DIR)/$(TARGET).hex
214 295
 ifeq (${AVRDUDE_PROGRAMMER}, arduino)
215
-	stty hup < $(PORT); true
296
+	stty hup < $(UPLOAD_PORT); true
216 297
 endif
217 298
 	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
218 299
 ifeq (${AVRDUDE_PROGRAMMER}, arduino)
219
-	stty -hup < $(PORT); true
300
+	stty -hup < $(UPLOAD_PORT); true
220 301
 endif
221 302
 
222 303
 	# Display size of file.
223
-HEXSIZE = $(SIZE) --target=$(FORMAT) applet/$(TARGET).hex
224
-ELFSIZE = $(SIZE) --mcu=$(MCU) -C applet/$(TARGET).elf; \
225
-          $(SIZE)  applet/$(TARGET).elf
304
+HEXSIZE = $(SIZE) --target=$(FORMAT) $(BUILD_DIR)/$(TARGET).hex
305
+ELFSIZE = $(SIZE) --mcu=$(MCU) -C $(BUILD_DIR)/$(TARGET).elf; \
306
+          $(SIZE)  $(BUILD_DIR)/$(TARGET).elf
226 307
 sizebefore:
227
-	$P if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi
308
+	$P if [ -f $(BUILD_DIR)/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi
228 309
 
229 310
 sizeafter: build
230
-	$P if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
311
+	$P if [ -f $(BUILD_DIR)/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
231 312
 
232 313
 
233 314
 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
@@ -238,12 +319,12 @@ COFFCONVERT=$(OBJCOPY) --debugging \
238 319
 	--change-section-address .eeprom-0x810000 
239 320
 
240 321
 
241
-coff: applet/$(TARGET).elf
242
-	$(COFFCONVERT) -O coff-avr applet/$(TARGET).elf $(TARGET).cof
322
+coff: $(BUILD_DIR)/$(TARGET).elf
323
+	$(COFFCONVERT) -O coff-avr $(BUILD_DIR)/$(TARGET).elf $(TARGET).cof
243 324
 
244 325
 
245 326
 extcoff: $(TARGET).elf
246
-	$(COFFCONVERT) -O coff-ext-avr applet/$(TARGET).elf $(TARGET).cof
327
+	$(COFFCONVERT) -O coff-ext-avr $(BUILD_DIR)/$(TARGET).elf $(TARGET).cof
247 328
 
248 329
 
249 330
 .SUFFIXES: .elf .hex .eep .lss .sym
@@ -266,37 +347,34 @@ extcoff: $(TARGET).elf
266 347
 	$(NM) -n $< > $@
267 348
 
268 349
 	# Link: create ELF output file from library.
269
-applet/$(TARGET).elf: applet/$(TARGET).cpp applet/core.a Configuration.h
350
+$(BUILD_DIR)/$(TARGET).elf: $(OBJ) Configuration.h
270 351
 	$(Pecho) "  CXX   $@"
271
-	$P $(CC) $(ALL_CXXFLAGS) -Wl,--gc-sections -o $@ applet/$(TARGET).cpp -L. applet/core.a $(LDFLAGS)
272
-
273
-applet/core.a: $(OBJ)
274
-	$P for i in $(OBJ); do echo "  AR    $$i"; $(AR) rcs applet/core.a $$i; done
352
+	$P $(CC) $(ALL_CXXFLAGS) -Wl,--gc-sections -o $@ -L. $(OBJ) $(LDFLAGS)
275 353
 
276
-applet/%.o: %.c Configuration.h Configuration_adv.h $(MAKEFILE)
354
+$(BUILD_DIR)/%.o: %.c Configuration.h Configuration_adv.h $(MAKEFILE)
277 355
 	$(Pecho) "  CC    $@"
278 356
 	$P $(CC) -MMD -c $(ALL_CFLAGS) $< -o $@
279 357
 
280
-applet/%.o: applet/%.cpp Configuration.h Configuration_adv.h $(MAKEFILE)
358
+$(BUILD_DIR)/%.o: $(BUILD_DIR)/%.cpp Configuration.h Configuration_adv.h $(MAKEFILE)
281 359
 	$(Pecho) "  CXX   $@"
282 360
 	$P $(CXX) -MMD -c $(ALL_CXXFLAGS) $< -o $@
283 361
 
284
-applet/%.o: %.cpp Configuration.h Configuration_adv.h $(MAKEFILE)
362
+$(BUILD_DIR)/%.o: %.cpp Configuration.h Configuration_adv.h $(MAKEFILE)
285 363
 	$(Pecho) "  CXX   $@"
286 364
 	$P $(CXX) -MMD -c $(ALL_CXXFLAGS) $< -o $@
287 365
 
288 366
 
289 367
 # Target: clean project.
290 368
 clean:
291
-	$(Pecho) "  RM    applet/*"
292
-	$P $(REMOVE) applet/$(TARGET).hex applet/$(TARGET).eep applet/$(TARGET).cof applet/$(TARGET).elf \
293
-		applet/$(TARGET).map applet/$(TARGET).sym applet/$(TARGET).lss applet/$(TARGET).cpp applet/core.a \
369
+	$(Pecho) "  RM    $(BUILD_DIR)/*"
370
+	$P $(REMOVE) $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep $(BUILD_DIR)/$(TARGET).cof $(BUILD_DIR)/$(TARGET).elf \
371
+		$(BUILD_DIR)/$(TARGET).map $(BUILD_DIR)/$(TARGET).sym $(BUILD_DIR)/$(TARGET).lss $(BUILD_DIR)/$(TARGET).cpp \
294 372
 		$(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)
295
-	$(Pecho) "  RMDIR applet/"
296
-	$P rm -rf applet
373
+	$(Pecho) "  RMDIR $(BUILD_DIR)/"
374
+	$P rm -rf $(BUILD_DIR)
297 375
 
298 376
 
299
-.PHONY:	all build elf hex eep lss sym program coff extcoff clean depend applet_files sizebefore sizeafter
377
+.PHONY:	all build elf hex eep lss sym program coff extcoff clean depend sizebefore sizeafter
300 378
 
301 379
 # Automaticaly include the dependency files created by gcc
302
--include ${wildcard applet/*.d}
380
+-include ${wildcard $(BUILD_DIR)/*.d}

正在加载...
取消
保存