# Arduino Makefile w. modifications by Tom Schouten # Original comment: #---------------------- # Arduino 1.0 Makefile # Based on Arduino 0018 Makefile # last updated 12/15/2011, Kerry Wong # # Arduino adaptation by mellis, eighthave, oli.keller # # Modified by Kerry Wong to support NetBeans # http://www.kerrywong.com # # # This makefile allows you to build sketches from the command line # without the Arduino environment (or Java). # # Detailed instructions for using the makefile: # # 1. Copy this file into the folder with your sketch. There should be a # file with the same name as the folder and with the extension .pde # (e.g. foo.pde in the foo/ folder). # # 2. Modify the line containg "INSTALL_DIR" to point to the directory that # contains the Arduino installation (for example, under Mac OS X, this # might be /Applications/arduino-0012). # # 3. Modify the line containing "PORT" to refer to the filename # representing the USB or serial connection to your Arduino board # (e.g. PORT = /dev/tty.USB0). If the exact name of this file # changes, you can use * as a wildcard (e.g. PORT = /dev/tty.usb*). # # 4. Set the line containing "MCU" to match your board's processor. # Older one's are atmega8 based, newer ones like Arduino Mini, Bluetooth # or Diecimila have the atmega168. If you're using a LilyPad Arduino, # change F_CPU to 8000000. # # 5. At the command line, change to the directory containing your # program's file and the makefile. # # 6. Type "make" and press enter to compile/verify your program. # # 7. Type "make upload", reset your Arduino board, and press enter to # upload your program to the Arduino board. # # $Id$ TARGET = $(notdir $(CURDIR)) # Change this to match your arduino installation directory INSTALL_DIR = $(HOME)/arduino/arduino-1.0.1 # INSTALL_DIR = /usr/share/arduino PORT = /dev/ttyACM0 UPLOAD_RATE = 115200 # AVRDUDE_PROGRAMMER = stk500v1 AVRDUDE_PROGRAMMER = arduino MCU = atmega328p F_CPU = 16000000 CORE=hardware/arduino/cores/arduino VARIANT=hardware/arduino/variants/standard VERSION=101 ARDUINO = $(INSTALL_DIR)/$(CORE) VARIANTS = $(INSTALL_DIR)/$(VARIANT) ARDUINO_LIB = $(INSTALL_DIR)/libraries AVR_TOOLS_PATH = /usr/bin AVRDUDE_PATH = $(INSTALL_DIR)/hardware/tools APPLET=applet FORMAT = ihex # Name of this Makefile (used for "make depend"). MAKEFILE = Makefile # Debugging format. # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2. # AVR (extended) COFF requires stabs, plus an avr-objcopy run. #DEBUG = stabs DEBUG = OPT = s # Place -D or -U options here CDEFS = -DF_CPU=$(F_CPU)L -DARDUINO=$(VERSION) CXXDEFS = -DF_CPU=$(F_CPU)L -DARDUINO=$(VERSION) # Place -I options here CINCS = -I$(ARDUINO) -I$(VARIANTS) -I$(ARDUINO_LIB) CXXINCS = -I$(ARDUINO) -I$(VARIANTS) -I$(ARDUINO_LIB) # Compiler flag to set the C Standard level. # c89 - "ANSI" C # gnu89 - c89 plus GCC extensions # c99 - ISO C99 standard (not yet fully implemented) # gnu99 - c99 plus GCC extensions #CSTANDARD = -std=gnu99 CDEBUG = -g$(DEBUG) #CWARN = -Wall -Wstrict-prototypes #CWARN = -Wall # show all warnings CWARN = -w #suppress all warnings ####CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums CTUNING = -ffunction-sections -fdata-sections CXXTUNING = -fno-exceptions -ffunction-sections -fdata-sections #CEXTRA = -Wa,-adhlns=$(<:.c=.lst) CFLAGS = $(CDEBUG) -O$(OPT) $(CWARN) $(CTUNING) $(CDEFS) $(CINCS) $(CSTANDARD) $(CEXTRA) CXXFLAGS = $(CDEBUG) -O$(OPT) $(CWARN) $(CXXTUNING) $(CDEFS) $(CINCS) #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs LDFLAGS = -O$(OPT) -lm -Wl,--gc-sections # Programming support using avrdude. Settings and variables. AVRDUDE_PORT = $(PORT) AVRDUDE_WRITE_FLASH = -U flash:w:$(APPLET)/main.hex AVRDUDE_FLAGS = -V -F -C $(INSTALL_DIR)/hardware/tools/avrdude.conf \ -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \ -b $(UPLOAD_RATE) -D # Program settings CC = $(AVR_TOOLS_PATH)/avr-gcc CXX = $(AVR_TOOLS_PATH)/avr-g++ LD = $(AVR_TOOLS_PATH)/avr-gcc OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy OBJDUMP = $(AVR_TOOLS_PATH)/avr-objdump AR = $(AVR_TOOLS_PATH)/avr-ar SIZE = $(AVR_TOOLS_PATH)/avr-size NM = $(AVR_TOOLS_PATH)/avr-nm # AVRDUDE = $(AVRDUDE_PATH)/avrdude AVRDUDE = avrdude REMOVE = rm -f MV = mv -f # Combine all necessary flags and optional flags. # Add target processor to flags. ALL_CFLAGS = $(CFLAGS) -mmcu=$(MCU) ALL_CXXFLAGS = $(CXXFLAGS) -mmcu=$(MCU) ALL_ASFLAGS = -x assembler-with-cpp $(ASFLAGS) -mmcu=$(MCU) ALL_LDFLAGS = $(LDFLAGS) -mmcu=$(MCU) # Compile all .c and .cpp under these directories MODULES_DIRS = $(CORE) libraries C_MODULES = $(shell cd $(INSTALL_DIR); find $(MODULES_DIRS) -name '*.c') CXX_MODULES = $(shell cd $(INSTALL_DIR); find $(MODULES_DIRS) -name '*.cpp') # Gather source files and make a list of all object files, placed in $(APPLET)/ OBJ_MODULES = $(patsubst %,$(APPLET)/%,$(C_MODULES:.c=.o) $(CXX_MODULES:.cpp=.o)) # Default target. all: $(APPLET) hex $(APPLET): mkdir -p $(APPLET) elf: $(APPLET)/main.elf hex: $(APPLET)/main.hex eep: $(APPLET)/main.eep lss: $(APPLET)/main.lss sym: $(APPLET)/main.sym # Display size of file. HEXSIZE = $(SIZE) --target=$(FORMAT) $(APPLET)/main.hex ELFSIZE = $(SIZE) $(APPLET)/main.elf sizebefore: @if [ -f $(APPLET)/main.elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi sizeafter: @if [ -f $(APPLET)/main.elf ]; then echo; echo $(MSG_SIZE_AFTER); $(HEXSIZE); echo; fi # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. COFFCONVERT=$(OBJCOPY) --debugging \ --change-section-address .data-0x800000 \ --change-section-address .bss-0x800000 \ --change-section-address .noinit-0x800000 \ --change-section-address .eeprom-0x810000 coff: $(APPLET)/main.elf $(COFFCONVERT) -O coff-avr $(APPLET)/main.elf main.cof extcoff: main.elf $(COFFCONVERT) -O coff-ext-avr $(APPLET)/main.elf main.cof .SUFFIXES: .elf .hex .eep .lss .sym .elf.hex: @echo [hex] $(notdir $@) @$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ .elf.eep: @echo [eep] $(notdir $@) @$(OBJCOPY) -O $(FORMAT) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ --no-change-warnings \ --change-section-lma .eeprom=0 $< $@ # Create extended listing file from ELF output file. .elf.lss: $(OBJDUMP) -h -S $< > $@ # Create a symbol table from ELF output file. .elf.sym: $(NM) -n $< > $@ LIBRARIES = $(INSTALL_DIR)/libraries LIB_INCLUDE = $(patsubst %,-I$(LIBRARIES)/%,$(shell cd $(LIBRARIES); ls)) # Link: create ELF output file from library. $(APPLET)/main.elf: $(APPLET)/$(TARGET).o $(APPLET)/core.a @echo [elf] $(notdir $@) @mkdir -p $(dir $@) @$(LD) $(ALL_LDFLAGS) -o $@ $(APPLET)/$(TARGET).o $(APPLET)/core.a $(APPLET)/core.a: $(OBJ_MODULES) @echo [a] $(notdir $@) @$(AR) rcl $@ $(OBJ_MODULES) $(APPLET)/$(TARGET).o: $(TARGET).ino @echo [o] $(notdir $@) @mkdir -p $(dir $@) @$(CXX) -x c++ -c $(ALL_CXXFLAGS) $< -o $@ # Compile C/C++ from arduino core and libraries $(APPLET)/%.o: $(INSTALL_DIR)/%.c @echo [o] $(notdir $@) @mkdir -p $(dir $@) @$(CC) $(ALL_CFLAGS) -I$(dir $<) -I$(dir $<)/utility $(LIB_INCLUDE) -c $< -o $@ $(APPLET)/%.o: $(INSTALL_DIR)/%.cpp @echo [o] $(notdir $@) @mkdir -p $(dir $@) @$(CXX) $(ALL_CXXFLAGS) -I$(dir $<) -I$(dir $<)/utility $(LIB_INCLUDE) -c $< -o $@ # Program the device. upload: $(APPLET)/main.hex $(AVRDUDE) -F -V -c $(AVRDUDE_PROGRAMMER) -p $(MCU) -P $(AVRDUDE_PORT) -b $(UPLOAD_RATE) -U flash:w:$< # Compile: create assembler files from C source files. .c.s: $(CC) -S $(ALL_CFLAGS) $< -o $@ # Assemble: create object files from assembler source files. .S.o: $(CC) -c $(ALL_ASFLAGS) $< -o $@ # Automatic dependencies %.d: %.c $(CC) -M $(ALL_CFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@ %.d: %.cpp $(CXX) -M $(ALL_CXXFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@ # Target: clean project. clean: $(REMOVE) -r $(APPLET) .PHONY: all build elf hex eep lss sym program coff extcoff clean sizebefore sizeafter #include $(SRC:.c=.d) #include $(CXXSRC:.cpp=.d)