Browse Source

more work on Makefile - actually rebuilds if Makefile or Configuration.h are altered, also much cleaner output

Michael Moon 12 years ago
parent
commit
9c918a497b
1 changed files with 60 additions and 62 deletions
  1. 60
    62
      Marlin/Makefile

+ 60
- 62
Marlin/Makefile View File

32
 #
32
 #
33
 # $Id$
33
 # $Id$
34
 
34
 
35
-TARGET = $(notdir $(CURDIR))
36
-INSTALL_DIR = ../../arduino-0022/
37
-UPLOAD_RATE = 115200
38
-AVRDUDE_PROGRAMMER = arduino
39
-# PORT = /dev/arduino_A900G2I3
40
-PORT = /dev/arduino
41
-MCU = atmega1280
42
 #For "old" Arduino Mega
35
 #For "old" Arduino Mega
43
-#MCU = atmega1280
36
+MCU = atmega1280
37
+#For Arduino Mega2560
38
+#MCU = atmega2560
44
 #For Sanguinololu
39
 #For Sanguinololu
45
 #MCU = atmega644p 
40
 #MCU = atmega644p 
41
+
42
+#Arduino install directory
43
+INSTALL_DIR = ../../arduino-0022/
44
+
46
 F_CPU = 16000000
45
 F_CPU = 16000000
47
 
46
 
47
+UPLOAD_RATE = 115200
48
+AVRDUDE_PROGRAMMER = arduino
49
+PORT = /dev/arduino
50
+
51
+TARGET = $(notdir $(CURDIR))
52
+
48
 
53
 
49
 ############################################################################
54
 ############################################################################
50
 # Below here nothing should be changed...
55
 # Below here nothing should be changed...
52
 ARDUINO = $(INSTALL_DIR)/hardware/arduino/cores/arduino
57
 ARDUINO = $(INSTALL_DIR)/hardware/arduino/cores/arduino
53
 AVR_TOOLS_PATH = 
58
 AVR_TOOLS_PATH = 
54
 SRC =  $(ARDUINO)/pins_arduino.c $(ARDUINO)/wiring.c \
59
 SRC =  $(ARDUINO)/pins_arduino.c $(ARDUINO)/wiring.c \
55
-$(ARDUINO)/wiring_analog.c $(ARDUINO)/wiring_digital.c \
56
-$(ARDUINO)/wiring_pulse.c \
57
-$(ARDUINO)/wiring_shift.c $(ARDUINO)/WInterrupts.c
60
+	$(ARDUINO)/wiring_analog.c $(ARDUINO)/wiring_digital.c \
61
+	$(ARDUINO)/wiring_pulse.c \
62
+	$(ARDUINO)/wiring_shift.c $(ARDUINO)/WInterrupts.c
58
 CXXSRC = $(ARDUINO)/WMath.cpp $(ARDUINO)/WString.cpp\
63
 CXXSRC = $(ARDUINO)/WMath.cpp $(ARDUINO)/WString.cpp\
59
-$(ARDUINO)/Print.cpp 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
64
+	$(ARDUINO)/Print.cpp 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
60
 FORMAT = ihex
65
 FORMAT = ihex
61
 
66
 
62
 
67
 
90
 #CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
95
 #CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
91
 
96
 
92
 CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CEXTRA) $(CTUNING)
97
 CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CEXTRA) $(CTUNING)
93
-CXXFLAGS = $(CDEFS) $(CINCS) -O$(OPT) -Wall $(CEXTRA) $(CTUNING)
98
+CXXFLAGS =         $(CDEFS) $(CINCS) -O$(OPT) -Wall    $(CEXTRA) $(CTUNING)
94
 #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 
99
 #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 
95
 LDFLAGS = -lm
100
 LDFLAGS = -lm
96
 
101
 
99
 AVRDUDE_PORT = $(PORT)
104
 AVRDUDE_PORT = $(PORT)
100
 AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex:i
105
 AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex:i
101
 AVRDUDE_FLAGS = -D -C $(INSTALL_DIR)/hardware/tools/avrdude.conf \
106
 AVRDUDE_FLAGS = -D -C $(INSTALL_DIR)/hardware/tools/avrdude.conf \
102
--p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \
103
--b $(UPLOAD_RATE)
107
+	-p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \
108
+	-b $(UPLOAD_RATE)
104
 
109
 
105
 # Program settings
110
 # Program settings
106
 CC = $(AVR_TOOLS_PATH)avr-gcc
111
 CC = $(AVR_TOOLS_PATH)avr-gcc
128
 
133
 
129
 
134
 
130
 # Default target.
135
 # Default target.
131
-all: applet_files build sizeafter
136
+all: build sizeafter
132
 
137
 
133
 build: elf hex 
138
 build: elf hex 
134
 
139
 
135
-applet_files: $(TARGET).pde
136
-	# Here is the "preprocessing".
137
-	# It creates a .cpp file based with the same name as the .pde file.
138
-	# On top of the new .cpp file comes the WProgram.h header.
139
-	# At the end there is a generic main() function attached.
140
-	# Then the .cpp file will be compiled. Errors during compile will
141
-	# refer to this new, automatically generated, file. 
142
-	# Not the original .pde file you actually edit...
143
-	test -d applet || mkdir applet
144
-	echo '#include "WProgram.h"' > applet/$(TARGET).cpp
145
-	cat $(TARGET).pde >> applet/$(TARGET).cpp
146
-	cat $(ARDUINO)/main.cpp >> applet/$(TARGET).cpp
140
+applet/$(TARGET).cpp: $(TARGET).pde $(MAKEFILE)
141
+# Here is the "preprocessing".
142
+# It creates a .cpp file based with the same name as the .pde file.
143
+# On top of the new .cpp file comes the WProgram.h header.
144
+# At the end there is a generic main() function attached.
145
+# Then the .cpp file will be compiled. Errors during compile will
146
+# refer to this new, automatically generated, file. 
147
+# Not the original .pde file you actually edit...
148
+	@echo "  WR    applet/$(TARGET).cpp"
149
+	@test -d applet || mkdir applet
150
+	@echo '#include "WProgram.h"' > applet/$(TARGET).cpp
151
+	@cat $(TARGET).pde >> applet/$(TARGET).cpp
152
+	@cat $(ARDUINO)/main.cpp >> applet/$(TARGET).cpp
147
 
153
 
148
 elf: applet/$(TARGET).elf
154
 elf: applet/$(TARGET).elf
149
 hex: applet/$(TARGET).hex
155
 hex: applet/$(TARGET).hex
165
 	@if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi
171
 	@if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi
166
 
172
 
167
 sizeafter:
173
 sizeafter:
168
-	@if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(HEXSIZE); echo; fi
174
+	@if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
169
 
175
 
170
 
176
 
171
 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
177
 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
172
 COFFCONVERT=$(OBJCOPY) --debugging \
178
 COFFCONVERT=$(OBJCOPY) --debugging \
173
---change-section-address .data-0x800000 \
174
---change-section-address .bss-0x800000 \
175
---change-section-address .noinit-0x800000 \
176
---change-section-address .eeprom-0x810000 
179
+	--change-section-address .data-0x800000 \
180
+	--change-section-address .bss-0x800000 \
181
+	--change-section-address .noinit-0x800000 \
182
+	--change-section-address .eeprom-0x810000 
177
 
183
 
178
 
184
 
179
 coff: applet/$(TARGET).elf
185
 coff: applet/$(TARGET).elf
185
 
191
 
186
 
192
 
187
 .SUFFIXES: .elf .hex .eep .lss .sym
193
 .SUFFIXES: .elf .hex .eep .lss .sym
194
+.PRECIOUS: .o
188
 
195
 
189
 .elf.hex:
196
 .elf.hex:
190
-	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
197
+	@echo "  COPY  $@"
198
+	@$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
191
 
199
 
192
 .elf.eep:
200
 .elf.eep:
193
 	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
201
 	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
194
-	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
202
+		--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
195
 
203
 
196
 # Create extended listing file from ELF output file.
204
 # Create extended listing file from ELF output file.
197
 .elf.lss:
205
 .elf.lss:
202
 	$(NM) -n $< > $@
210
 	$(NM) -n $< > $@
203
 
211
 
204
 	# Link: create ELF output file from library.
212
 	# Link: create ELF output file from library.
205
-applet/$(TARGET).elf: $(TARGET).pde applet/core.a 
206
-	$(CC) $(ALL_CFLAGS) -Wl,--gc-sections -o $@ applet/$(TARGET).cpp -L. applet/core.a $(LDFLAGS)
207
-
208
-applet/core.a: $(OBJ)
209
-	@for i in $(OBJ); do echo $(AR) rcs applet/core.a $$i; $(AR) rcs applet/core.a $$i; done
210
-
211
-
212
-
213
-# Compile: create object files from C++ source files.
214
-.cpp.o:
215
-	$(CXX) -c $(ALL_CXXFLAGS) $< -o $@ 
216
-
217
-# Compile: create object files from C source files.
218
-.c.o:
219
-	$(CC) -c $(ALL_CFLAGS) $< -o $@ 
220
-
221
-
222
-# Compile: create assembler files from C source files.
223
-.c.s:
224
-	$(CC) -S $(ALL_CFLAGS) $< -o $@
225
-
213
+applet/$(TARGET).elf: applet/$(TARGET).cpp applet/core.a Configuration.h
214
+	@echo "  CXX   $@"
215
+	@$(CC) $(ALL_CXXFLAGS) -Wl,--gc-sections -o $@ applet/$(TARGET).cpp -L. applet/core.a $(LDFLAGS)
226
 
216
 
227
-# Assemble: create object files from assembler source files.
228
-.S.o:
229
-	$(CC) -c $(ALL_ASFLAGS) $< -o $@
217
+applet/core.a: $(OBJ) Configuration.h
218
+	@for i in $(OBJ); do echo "  AR    $$i"; $(AR) rcs applet/core.a $$i; done
230
 
219
 
220
+%.o: %.c Configuration.h $(MAKEFILE)
221
+	@echo "  CC    $@"
222
+	@$(CC) -c $(ALL_CFLAGS) $< -o $@
231
 
223
 
224
+%.o: %.cpp Configuration.h $(MAKEFILE)
225
+	@echo "  CXX   $@"
226
+	@$(CXX) -c $(ALL_CXXFLAGS) $< -o $@
232
 
227
 
233
 # Target: clean project.
228
 # Target: clean project.
234
 clean:
229
 clean:
235
-	$(REMOVE) applet/$(TARGET).hex applet/$(TARGET).eep applet/$(TARGET).cof applet/$(TARGET).elf \
236
-	applet/$(TARGET).map applet/$(TARGET).sym applet/$(TARGET).lss applet/core.a \
237
-	$(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)
230
+	@echo "  RM    applet/*"
231
+	@$(REMOVE) applet/$(TARGET).hex applet/$(TARGET).eep applet/$(TARGET).cof applet/$(TARGET).elf \
232
+		applet/$(TARGET).map applet/$(TARGET).sym applet/$(TARGET).lss applet/$(TARGET).cpp applet/core.a \
233
+		$(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)
234
+	@echo "  RMDIR applet/"
235
+	@rmdir applet
238
 
236
 
239
 depend:
237
 depend:
240
 	if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \
238
 	if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \

Loading…
Cancel
Save