# Arduino Makefile modified and cleaned up by Jordan Perr # Original from Arduino.cc # # Tested with Arduino software 0013 for Mac # # To Use this Makefile: # -Copy this makefile into your project's directory # -set BUILD_TARGETS all of your project's files to BUILD_TARGETS # -set TARGET to your main target file's name. (eg. main for main.cpp) # -set INSTALL_DIR to the location of your arduino installation # -set LOAD_PORT to the serial port you wish to download to. Use * as a wildcard # -set READ_PORT to the serial port you wish to read from (cat port) # # # # make [build] # -builds into current directory, creating a TARGET.hex binary # # make upload # -uses avrdude to download TARGET.hex to PORT # # make clean # -removes all temp and binary files created during build # # make read # -reads serial port to console # # make cycle # - make build load read # # project specific settings TARGET = main BUILD_TARGETS = main.cpp INSTALL_DIR = /Applications/arduino-0013 LOAD_PORT = /dev/tty.usb* READ_PORT = /dev/cu.usb* # arduino model specific settings UPLOAD_RATE = 19200 AVRDUDE_PROGRAMMER = stk500 MCU = atmega168 ############################### ## don't go below this line ## ############################### # Arduino Distrobution Settings (v.0013) ARDUINO = $(INSTALL_DIR)/hardware/cores/arduino LIBRARY = $(INSTALL_DIR)/hardware/libraries AVR_TOOLS_PATH = $(INSTALL_DIR)/hardware/tools/avr/bin SRC = $(ARDUINO)/pins_arduino.c $(ARDUINO)/wiring.c \ $(ARDUINO)/wiring_analog.c $(ARDUINO)/wiring_digital.c \ $(ARDUINO)/wiring_pulse.c $(ARDUINO)/wiring_serial.c \ $(ARDUINO)/wiring_shift.c $(ARDUINO)/WInterrupts.c CXXSRC = $(BUILD_TARGETS) $(ARDUINO)/HardwareSerial.cpp $(ARDUINO)/WMath.cpp $(ARDUINO)/Print.cpp FORMAT = ihex # Environment settings CC = $(AVR_TOOLS_PATH)/avr-gcc CXX = $(AVR_TOOLS_PATH)/avr-gcc OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy OBJDUMP = $(AVR_TOOLS_PATH)/avr-objdump SIZE = $(AVR_TOOLS_PATH)/avr-size NM = $(AVR_TOOLS_PATH)/avr-nm AVRDUDE = $(AVR_TOOLS_PATH)/avrdude REMOVE = rm -f MV = mv -f ###### HELPFUL DEFINITIONS ===== # Compiler Flags ALL_CFLAGS = -c -g -Os -w -ffunction-sections -fdata-sections -mmcu=$(MCU) -DF_CPU=16000000L -I$(ARDUINO) -I$(LIBRARY) ALL_CXXFLAGS = -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -mmcu=$(MCU) -DF_CPU=16000000L -I$(ARDUINO) -I$(LIBRARY) # Assembler Flags ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp # Loader flags AVRDUDE_FLAGS = -C $(INSTALL_DIR)/hardware/tools/avr/etc/avrdude.conf -V -p $(MCU) -P $(LOAD_PORT) -c $(AVRDUDE_PROGRAMMER) -b $(UPLOAD_RATE) -D -U flash:w:$(TARGET).hex:i # Define all object files. OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o) ###### ROUTINES ####### # ALIASES all: build build: hex cycle: build load read # READ read: cat $(READ_PORT) # UPLAOD load: upload upload: $(TARGET).hex $(AVRDUDE) $(AVRDUDE_FLAGS) # CLEAN clean: $(REMOVE) $(TARGET).hex $(TARGET).eep $(TARGET).cof $(TARGET).elf \ $(TARGET).map $(TARGET).sym $(TARGET).lss \ $(OBJ) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d) # Transcode: create HEX file from ELF file. hex: elf $(OBJCOPY) -O $(FORMAT) -R .eeprom $(TARGET).elf $(TARGET).hex # Link: create ELF output file from object files. elf: $(OBJ) $(CC) -Os -Wl,--gc-sections -mmcu=atmega168 -o $(TARGET).elf $(OBJ) -lm # 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 $@