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

2.0.x
Michael Moon 13 years ago
parent ab01658fd2
commit 9c918a497b

@ -32,19 +32,24 @@
# #
# $Id$ # $Id$
TARGET = $(notdir $(CURDIR))
INSTALL_DIR = ../../arduino-0022/
UPLOAD_RATE = 115200
AVRDUDE_PROGRAMMER = arduino
# PORT = /dev/arduino_A900G2I3
PORT = /dev/arduino
MCU = atmega1280
#For "old" Arduino Mega #For "old" Arduino Mega
#MCU = atmega1280 MCU = atmega1280
#For Arduino Mega2560
#MCU = atmega2560
#For Sanguinololu #For Sanguinololu
#MCU = atmega644p #MCU = atmega644p
#Arduino install directory
INSTALL_DIR = ../../arduino-0022/
F_CPU = 16000000 F_CPU = 16000000
UPLOAD_RATE = 115200
AVRDUDE_PROGRAMMER = arduino
PORT = /dev/arduino
TARGET = $(notdir $(CURDIR))
############################################################################ ############################################################################
# Below here nothing should be changed... # Below here nothing should be changed...
@ -52,11 +57,11 @@ F_CPU = 16000000
ARDUINO = $(INSTALL_DIR)/hardware/arduino/cores/arduino ARDUINO = $(INSTALL_DIR)/hardware/arduino/cores/arduino
AVR_TOOLS_PATH = AVR_TOOLS_PATH =
SRC = $(ARDUINO)/pins_arduino.c $(ARDUINO)/wiring.c \ SRC = $(ARDUINO)/pins_arduino.c $(ARDUINO)/wiring.c \
$(ARDUINO)/wiring_analog.c $(ARDUINO)/wiring_digital.c \ $(ARDUINO)/wiring_analog.c $(ARDUINO)/wiring_digital.c \
$(ARDUINO)/wiring_pulse.c \ $(ARDUINO)/wiring_pulse.c \
$(ARDUINO)/wiring_shift.c $(ARDUINO)/WInterrupts.c $(ARDUINO)/wiring_shift.c $(ARDUINO)/WInterrupts.c
CXXSRC = $(ARDUINO)/WMath.cpp $(ARDUINO)/WString.cpp\ CXXSRC = $(ARDUINO)/WMath.cpp $(ARDUINO)/WString.cpp\
$(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 $(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
FORMAT = ihex FORMAT = ihex
@ -90,7 +95,7 @@ CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -w -f
#CEXTRA = -Wa,-adhlns=$(<:.c=.lst) #CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CEXTRA) $(CTUNING) CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CEXTRA) $(CTUNING)
CXXFLAGS = $(CDEFS) $(CINCS) -O$(OPT) -Wall $(CEXTRA) $(CTUNING) CXXFLAGS = $(CDEFS) $(CINCS) -O$(OPT) -Wall $(CEXTRA) $(CTUNING)
#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
LDFLAGS = -lm LDFLAGS = -lm
@ -99,8 +104,8 @@ LDFLAGS = -lm
AVRDUDE_PORT = $(PORT) AVRDUDE_PORT = $(PORT)
AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex:i AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex:i
AVRDUDE_FLAGS = -D -C $(INSTALL_DIR)/hardware/tools/avrdude.conf \ AVRDUDE_FLAGS = -D -C $(INSTALL_DIR)/hardware/tools/avrdude.conf \
-p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \ -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \
-b $(UPLOAD_RATE) -b $(UPLOAD_RATE)
# Program settings # Program settings
CC = $(AVR_TOOLS_PATH)avr-gcc CC = $(AVR_TOOLS_PATH)avr-gcc
@ -128,22 +133,23 @@ ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
# Default target. # Default target.
all: applet_files build sizeafter all: build sizeafter
build: elf hex build: elf hex
applet_files: $(TARGET).pde applet/$(TARGET).cpp: $(TARGET).pde $(MAKEFILE)
# Here is the "preprocessing". # Here is the "preprocessing".
# It creates a .cpp file based with the same name as the .pde file. # It creates a .cpp file based with the same name as the .pde file.
# On top of the new .cpp file comes the WProgram.h header. # On top of the new .cpp file comes the WProgram.h header.
# At the end there is a generic main() function attached. # At the end there is a generic main() function attached.
# Then the .cpp file will be compiled. Errors during compile will # Then the .cpp file will be compiled. Errors during compile will
# refer to this new, automatically generated, file. # refer to this new, automatically generated, file.
# Not the original .pde file you actually edit... # Not the original .pde file you actually edit...
test -d applet || mkdir applet @echo " WR applet/$(TARGET).cpp"
echo '#include "WProgram.h"' > applet/$(TARGET).cpp @test -d applet || mkdir applet
cat $(TARGET).pde >> applet/$(TARGET).cpp @echo '#include "WProgram.h"' > applet/$(TARGET).cpp
cat $(ARDUINO)/main.cpp >> applet/$(TARGET).cpp @cat $(TARGET).pde >> applet/$(TARGET).cpp
@cat $(ARDUINO)/main.cpp >> applet/$(TARGET).cpp
elf: applet/$(TARGET).elf elf: applet/$(TARGET).elf
hex: applet/$(TARGET).hex hex: applet/$(TARGET).hex
@ -165,15 +171,15 @@ sizebefore:
@if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi @if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi
sizeafter: sizeafter:
@if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(HEXSIZE); echo; fi @if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \ COFFCONVERT=$(OBJCOPY) --debugging \
--change-section-address .data-0x800000 \ --change-section-address .data-0x800000 \
--change-section-address .bss-0x800000 \ --change-section-address .bss-0x800000 \
--change-section-address .noinit-0x800000 \ --change-section-address .noinit-0x800000 \
--change-section-address .eeprom-0x810000 --change-section-address .eeprom-0x810000
coff: applet/$(TARGET).elf coff: applet/$(TARGET).elf
@ -185,13 +191,15 @@ extcoff: $(TARGET).elf
.SUFFIXES: .elf .hex .eep .lss .sym .SUFFIXES: .elf .hex .eep .lss .sym
.PRECIOUS: .o
.elf.hex: .elf.hex:
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ @echo " COPY $@"
@$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
.elf.eep: .elf.eep:
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@ --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
# Create extended listing file from ELF output file. # Create extended listing file from ELF output file.
.elf.lss: .elf.lss:
@ -202,39 +210,29 @@ extcoff: $(TARGET).elf
$(NM) -n $< > $@ $(NM) -n $< > $@
# Link: create ELF output file from library. # Link: create ELF output file from library.
applet/$(TARGET).elf: $(TARGET).pde applet/core.a applet/$(TARGET).elf: applet/$(TARGET).cpp applet/core.a Configuration.h
$(CC) $(ALL_CFLAGS) -Wl,--gc-sections -o $@ applet/$(TARGET).cpp -L. applet/core.a $(LDFLAGS) @echo " CXX $@"
@$(CC) $(ALL_CXXFLAGS) -Wl,--gc-sections -o $@ applet/$(TARGET).cpp -L. applet/core.a $(LDFLAGS)
applet/core.a: $(OBJ)
@for i in $(OBJ); do echo $(AR) rcs applet/core.a $$i; $(AR) rcs applet/core.a $$i; done
# Compile: create object files from C++ source files.
.cpp.o:
$(CXX) -c $(ALL_CXXFLAGS) $< -o $@
# Compile: create object files from C source files.
.c.o:
$(CC) -c $(ALL_CFLAGS) $< -o $@
# Compile: create assembler files from C source files.
.c.s:
$(CC) -S $(ALL_CFLAGS) $< -o $@
# Assemble: create object files from assembler source files. applet/core.a: $(OBJ) Configuration.h
.S.o: @for i in $(OBJ); do echo " AR $$i"; $(AR) rcs applet/core.a $$i; done
$(CC) -c $(ALL_ASFLAGS) $< -o $@
%.o: %.c Configuration.h $(MAKEFILE)
@echo " CC $@"
@$(CC) -c $(ALL_CFLAGS) $< -o $@
%.o: %.cpp Configuration.h $(MAKEFILE)
@echo " CXX $@"
@$(CXX) -c $(ALL_CXXFLAGS) $< -o $@
# Target: clean project. # Target: clean project.
clean: clean:
$(REMOVE) applet/$(TARGET).hex applet/$(TARGET).eep applet/$(TARGET).cof applet/$(TARGET).elf \ @echo " RM applet/*"
applet/$(TARGET).map applet/$(TARGET).sym applet/$(TARGET).lss applet/core.a \ @$(REMOVE) applet/$(TARGET).hex applet/$(TARGET).eep applet/$(TARGET).cof applet/$(TARGET).elf \
$(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d) applet/$(TARGET).map applet/$(TARGET).sym applet/$(TARGET).lss applet/$(TARGET).cpp applet/core.a \
$(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)
@echo " RMDIR applet/"
@rmdir applet
depend: depend:
if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \ if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \

Loading…
Cancel
Save