Browse Source

Makefile: Redone

+ Removed most explicit pathnames, use the standard make "VPATH" to let
make find the files for itself.

+ Added a "hardware variant" variable that allows compiging Sanguino and
Gen7 as well as "generic" arduino.

+ Allows overriding the MOTHERBOARD define from the Makefile

+ Removed the 'preprocessor' bit that wasn't needed, now just "include" the
files that are needed, since it allows gcc to show the right file/line
when displaying error/warnings.

+ Uses gcc's own dependency generator to generate the .d files, and
and include these instead of self-patching the makefile

Signed-off-by: Michel Pollet <buserror@gmail.com>
Michel Pollet 13 years ago
parent
commit
aa6e6e914e
2 changed files with 91 additions and 49 deletions
  1. 3
    1
      Marlin/Configuration.h
  2. 88
    48
      Marlin/Makefile

+ 3
- 1
Marlin/Configuration.h View File

29
 // Ultimaker = 7
29
 // Ultimaker = 7
30
 // Teensylu = 8
30
 // Teensylu = 8
31
 // Gen3+ =9
31
 // Gen3+ =9
32
+#ifndef MOTHERBOARD
32
 #define MOTHERBOARD 7
33
 #define MOTHERBOARD 7
34
+#endif
33
 
35
 
34
 //===========================================================================
36
 //===========================================================================
35
 //=============================Thermal Settings  ============================
37
 //=============================Thermal Settings  ============================
193
 //#define ULTRA_LCD  //general lcd support, also 16x2
195
 //#define ULTRA_LCD  //general lcd support, also 16x2
194
 //#define SDSUPPORT // Enable SD Card Support in Hardware Console
196
 //#define SDSUPPORT // Enable SD Card Support in Hardware Console
195
 
197
 
196
-#define ULTIPANEL
198
+//#define ULTIPANEL
197
 #ifdef ULTIPANEL
199
 #ifdef ULTIPANEL
198
 //  #define NEWPANEL  //enable this if you have a click-encoder panel
200
 //  #define NEWPANEL  //enable this if you have a click-encoder panel
199
   #define SDSUPPORT
201
   #define SDSUPPORT

+ 88
- 48
Marlin/Makefile View File

35
 # $Id$
35
 # $Id$
36
 
36
 
37
 #For "old" Arduino Mega
37
 #For "old" Arduino Mega
38
-MCU = atmega1280
38
+#MCU = atmega1280
39
 #For Arduino Mega2560
39
 #For Arduino Mega2560
40
 #MCU = atmega2560
40
 #MCU = atmega2560
41
 #For Sanguinololu
41
 #For Sanguinololu
42
-#MCU = atmega644p 
42
+MCU = atmega644p 
43
 
43
 
44
-#Arduino install directory
45
-INSTALL_DIR = ../../arduino-0022/
44
+# Here you select "arduino", "Sanguino", "Gen7", ...
45
+HARDWARE_VARIANT 		= Sanguino
46
+# This defined the board you are compiling for
47
+HARDWARE_MOTHERBOARD	= 91
48
+
49
+# Arduino source install directory
50
+INSTALL_DIR = ../../arduino-0022
51
+
52
+# Arduino containd the main source code for the Arduino
53
+# Libraries, the "hardware variant" are for boards
54
+# that derives from that, and their source are present in
55
+# the main Marlin source directory
56
+ARDUINO = $(INSTALL_DIR)/hardware/arduino/cores/arduino
57
+
58
+ifeq (${HARDWARE_VARIANT}, arduino)
59
+HARDWARE_SRC= $(ARDUINO)
60
+else
61
+HARDWARE_SRC= $(HARDWARE_VARIANT)/cores/arduino
62
+endif
46
 
63
 
47
 # Be sure to regenerate speed_lookuptable.h with create_speed_lookuptable.py
64
 # Be sure to regenerate speed_lookuptable.h with create_speed_lookuptable.py
48
 # if you are setting this to something other than 16MHz
65
 # if you are setting this to something other than 16MHz
54
 
71
 
55
 TARGET = $(notdir $(CURDIR))
72
 TARGET = $(notdir $(CURDIR))
56
 
73
 
74
+# VPATH tells make to look into these directory for source files,
75
+# there is no need to specify explicit pathnames as long as the
76
+# directory is added here
77
+
78
+VPATH = .
79
+VPATH += applet
80
+VPATH += $(HARDWARE_SRC)
81
+VPATH += $(ARDUINO)
82
+VPATH += $(INSTALL_DIR)/libraries/LiquidCrystal
57
 
83
 
58
 ############################################################################
84
 ############################################################################
59
 # Below here nothing should be changed...
85
 # Below here nothing should be changed...
60
 
86
 
61
-ARDUINO = $(INSTALL_DIR)/hardware/arduino/cores/arduino
62
 AVR_TOOLS_PATH = 
87
 AVR_TOOLS_PATH = 
63
-SRC =  $(ARDUINO)/pins_arduino.c $(ARDUINO)/wiring.c \
64
-	$(ARDUINO)/wiring_analog.c $(ARDUINO)/wiring_digital.c \
65
-	$(ARDUINO)/wiring_pulse.c \
66
-	$(ARDUINO)/wiring_shift.c $(ARDUINO)/WInterrupts.c
67
-CXXSRC = $(ARDUINO)/WMath.cpp $(ARDUINO)/WString.cpp\
68
-	$(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
88
+SRC =  pins_arduino.c wiring.c \
89
+	wiring_analog.c wiring_digital.c \
90
+	wiring_pulse.c \
91
+	wiring_shift.c WInterrupts.c
92
+CXXSRC = WMath.cpp WString.cpp Print.cpp \
93
+	Marlin.cpp MarlinSerial.cpp Sd2Card.cpp SdBaseFile.cpp \
94
+	SdFatUtil.cpp SdFile.cpp SdVolume.cpp motion_control.cpp \
95
+	planner.cpp stepper.cpp temperature.cpp cardreader.cpp
96
+#CXXSRC += LiquidCrystal.cpp ultralcd.cpp
97
+#CXXSRC += ultralcd.cpp
69
 FORMAT = ihex
98
 FORMAT = ihex
70
 
99
 
71
-
72
 # Name of this Makefile (used for "make depend").
100
 # Name of this Makefile (used for "make depend").
73
 MAKEFILE = Makefile
101
 MAKEFILE = Makefile
74
 
102
 
83
 CDEFS = -DF_CPU=$(F_CPU)
111
 CDEFS = -DF_CPU=$(F_CPU)
84
 CXXDEFS = -DF_CPU=$(F_CPU)
112
 CXXDEFS = -DF_CPU=$(F_CPU)
85
 
113
 
86
-# Place -I options here
87
-CINCS = -I$(ARDUINO)
88
-CXXINCS = -I$(ARDUINO)
114
+# Add all the source directories as include directories too
115
+CINCS = ${patsubst %,-I%,${subst :, ,${VPATH}}}
116
+CXXINCS = ${patsubst %,-I%,${subst :, ,${VPATH}}}
89
 
117
 
90
 # Compiler flag to set the C Standard level.
118
 # Compiler flag to set the C Standard level.
91
 # c89   - "ANSI" C
119
 # c89   - "ANSI" C
95
 #CSTANDARD = -std=gnu99
123
 #CSTANDARD = -std=gnu99
96
 CDEBUG = -g$(DEBUG)
124
 CDEBUG = -g$(DEBUG)
97
 CWARN = -Wall -Wstrict-prototypes
125
 CWARN = -Wall -Wstrict-prototypes
98
-CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -w -ffunction-sections -fdata-sections -DARDUINO=22
126
+CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct \
127
+	-fshort-enums -w -ffunction-sections -fdata-sections \
128
+	-DARDUINO=22
129
+ifneq (${HARDWARE_MOTHERBOARD},)
130
+CTUNING += -DMOTHERBOARD=${HARDWARE_MOTHERBOARD}
131
+endif
99
 #CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
132
 #CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
100
 
133
 
101
 CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CEXTRA) $(CTUNING)
134
 CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CEXTRA) $(CTUNING)
124
 MV = mv -f
157
 MV = mv -f
125
 
158
 
126
 # Define all object files.
159
 # Define all object files.
127
-OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o) 
160
+OBJ = ${patsubst %.c, applet/%.o, ${SRC}}
161
+OBJ += ${patsubst %.cpp, applet/%.o, ${CXXSRC}}
162
+OBJ += ${patsubst %.S, applet/%.o, ${ASRC}}
128
 
163
 
129
 # Define all listing files.
164
 # Define all listing files.
130
 LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst)
165
 LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst)
132
 # Combine all necessary flags and optional flags.
167
 # Combine all necessary flags and optional flags.
133
 # Add target processor to flags.
168
 # Add target processor to flags.
134
 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
169
 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
135
-ALL_CXXFLAGS = -mmcu=$(MCU) -I. $(CXXFLAGS)
136
-ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
170
+ALL_CXXFLAGS = -mmcu=$(MCU) $(CXXFLAGS)
171
+ALL_ASFLAGS = -mmcu=$(MCU) -x assembler-with-cpp $(ASFLAGS)
137
 
172
 
138
 
173
 
139
 # Default target.
174
 # Default target.
140
-all: build sizeafter
175
+all: sizeafter
141
 
176
 
142
-build: elf hex 
177
+build: applet elf hex 
143
 
178
 
144
-applet/$(TARGET).cpp: $(TARGET).pde $(MAKEFILE)
179
+# Creates the object directory
180
+applet: 
181
+	@mkdir -p applet
182
+
183
+# the .cpp for Marlin depends on the .pde
184
+#applet/$(TARGET).cpp: $(TARGET).pde
185
+# ..and the .o depends from the .cpp
186
+#applet/%.o: applet/%.cpp
145
 
187
 
146
 applet/%.cpp: %.pde
188
 applet/%.cpp: %.pde
147
 # Here is the "preprocessing".
189
 # Here is the "preprocessing".
148
 # It creates a .cpp file based with the same name as the .pde file.
190
 # It creates a .cpp file based with the same name as the .pde file.
149
 # On top of the new .cpp file comes the WProgram.h header.
191
 # On top of the new .cpp file comes the WProgram.h header.
150
-# At the end there is a generic main() function attached.
151
-# Then the .cpp file will be compiled. Errors during compile will
152
-# refer to this new, automatically generated, file. 
153
-# Not the original .pde file you actually edit...
154
 	@echo "  WR    $@"
192
 	@echo "  WR    $@"
155
-	@test -d $(dir $@) || mkdir $(dir $@)
156
 	@echo '#include "WProgram.h"' > $@
193
 	@echo '#include "WProgram.h"' > $@
157
-	@cat $< >> $@
158
-	@cat $(ARDUINO)/main.cpp >> $@
194
+	@echo '#include "$<"' >>$@
195
+	@echo '#include "$(ARDUINO)/main.cpp"' >> $@
159
 
196
 
160
 elf: applet/$(TARGET).elf
197
 elf: applet/$(TARGET).elf
161
 hex: applet/$(TARGET).hex
198
 hex: applet/$(TARGET).hex
164
 sym: applet/$(TARGET).sym
201
 sym: applet/$(TARGET).sym
165
 
202
 
166
 # Program the device.  
203
 # Program the device.  
204
+# Do not try to reset an arduino if it's not one
167
 upload: applet/$(TARGET).hex
205
 upload: applet/$(TARGET).hex
206
+ifeq (${AVRDUDE_PROGRAMMER}, arduino)
168
 	stty hup < $(PORT); true
207
 	stty hup < $(PORT); true
208
+endif
169
 	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
209
 	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
210
+ifeq (${AVRDUDE_PROGRAMMER}, arduino)
170
 	stty -hup < $(PORT); true
211
 	stty -hup < $(PORT); true
171
-
212
+endif
172
 
213
 
173
 	# Display size of file.
214
 	# Display size of file.
174
 HEXSIZE = $(SIZE) --target=$(FORMAT) applet/$(TARGET).hex
215
 HEXSIZE = $(SIZE) --target=$(FORMAT) applet/$(TARGET).hex
176
 sizebefore:
217
 sizebefore:
177
 	@if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi
218
 	@if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi
178
 
219
 
179
-sizeafter:
220
+sizeafter: build
180
 	@if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
221
 	@if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
181
 
222
 
182
 
223
 
220
 	@echo "  CXX   $@"
261
 	@echo "  CXX   $@"
221
 	@$(CC) $(ALL_CXXFLAGS) -Wl,--gc-sections -o $@ applet/$(TARGET).cpp -L. applet/core.a $(LDFLAGS)
262
 	@$(CC) $(ALL_CXXFLAGS) -Wl,--gc-sections -o $@ applet/$(TARGET).cpp -L. applet/core.a $(LDFLAGS)
222
 
263
 
223
-applet/core.a: $(OBJ) Configuration.h
264
+applet/core.a: $(OBJ)
224
 	@for i in $(OBJ); do echo "  AR    $$i"; $(AR) rcs applet/core.a $$i; done
265
 	@for i in $(OBJ); do echo "  AR    $$i"; $(AR) rcs applet/core.a $$i; done
225
 
266
 
226
-%.o: %.c Configuration.h $(MAKEFILE)
267
+applet/%.o: %.c
227
 	@echo "  CC    $@"
268
 	@echo "  CC    $@"
228
-	@$(CC) -c $(ALL_CFLAGS) $< -o $@
269
+	@$(CC) -MMD -c $(ALL_CFLAGS) $< -o $@
270
+
271
+applet/%.o: %.cpp
272
+	@echo "  CXX   $@"
273
+	@$(CXX) -MMD -c $(ALL_CXXFLAGS) $< -o $@
229
 
274
 
230
-%.o: %.cpp Configuration.h $(MAKEFILE)
275
+# special rule for autogenerated files...
276
+applet/%.o: applet/%.cpp
231
 	@echo "  CXX   $@"
277
 	@echo "  CXX   $@"
232
-	@$(CXX) -c $(ALL_CXXFLAGS) $< -o $@
278
+	@$(CXX) -MMD -c $(ALL_CXXFLAGS) $< -o $@
279
+
233
 
280
 
234
 # Target: clean project.
281
 # Target: clean project.
235
 clean:
282
 clean:
238
 		applet/$(TARGET).map applet/$(TARGET).sym applet/$(TARGET).lss applet/$(TARGET).cpp applet/core.a \
285
 		applet/$(TARGET).map applet/$(TARGET).sym applet/$(TARGET).lss applet/$(TARGET).cpp applet/core.a \
239
 		$(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)
286
 		$(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)
240
 	@echo "  RMDIR applet/"
287
 	@echo "  RMDIR applet/"
241
-	@rmdir applet
242
-
243
-depend:
244
-	if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \
245
-	then \
246
-		sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \
247
-			$(MAKEFILE).$$$$ && \
248
-		$(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \
249
-	fi
250
-	echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \
251
-		>> $(MAKEFILE); \
252
-	$(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE)
288
+	@rm -rf applet
289
+
253
 
290
 
254
 .PHONY:	all build elf hex eep lss sym program coff extcoff clean depend applet_files sizebefore sizeafter
291
 .PHONY:	all build elf hex eep lss sym program coff extcoff clean depend applet_files sizebefore sizeafter
292
+
293
+# Automaticaly include the dependency files created by gcc
294
+-include ${wildcard applet/*.d}

Loading…
Cancel
Save