1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/Makefile Sun Jan 18 19:48:44 2015 +0100
1.3 @@ -0,0 +1,143 @@
1.4 +TARGET = $(notdir $(CURDIR))
1.5 +INSTALL_DIR = ../arduino-1.0.5
1.6 +PORT = /dev/ttyUSB0
1.7 +UPLOAD_RATE = 57600 # 19200
1.8 +AVRDUDE_PROGRAMMER = stk500v1
1.9 +MCU = atmega328p # atmega168
1.10 +F_CPU = 16000000
1.11 +
1.12 +EXTRA_SRC =
1.13 +EXTRA_CXXSRC =
1.14 +EXTRA_CINCS =
1.15 +EXTRA_CXXINCS =
1.16 +
1.17 +
1.18 +### Internal definitions.
1.19 +
1.20 +
1.21 +ARDUINO = $(INSTALL_DIR)/hardware/arduino/cores/arduino
1.22 +VARIANT = $(INSTALL_DIR)/hardware/arduino/variants/standard
1.23 +SRC = $(ARDUINO)/wiring.c \
1.24 + $(ARDUINO)/wiring_analog.c $(ARDUINO)/wiring_digital.c \
1.25 + $(ARDUINO)/wiring_pulse.c $(ARDUINO)/wiring_shift.c \
1.26 + $(ARDUINO)/WInterrupts.c $(EXTRA_SRC)
1.27 +CXXSRC = $(ARDUINO)/HardwareSerial.cpp $(ARDUINO)/WMath.cpp \
1.28 + $(ARDUINO)/Print.cpp $(ARDUINO)/WString.cpp \
1.29 + $(ARDUINO)/Stream.cpp $(EXTRA_CXXSRC)
1.30 +FORMAT = ihex
1.31 +
1.32 +# Name of this Makefile (used for "make depend").
1.33 +MAKEFILE = Makefile
1.34 +
1.35 +# Debugging format.
1.36 +# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
1.37 +# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
1.38 +DEBUG = stabs
1.39 +
1.40 +# Place -D or -U options here
1.41 +CDEFS = -DF_CPU=$(F_CPU)
1.42 +CXXDEFS = -DF_CPU=$(F_CPU)
1.43 +
1.44 +# Place -I options here
1.45 +CINCS = -I$(ARDUINO) -I$(VARIANT) $(EXTRA_CINCS)
1.46 +CXXINCS = -I$(ARDUINO) -I$(VARIANT) $(EXTRA_CXXINCS)
1.47 +
1.48 +# Compiler flag to set the C Standard level.
1.49 +# c89 - "ANSI" C
1.50 +# gnu89 - c89 plus GCC extensions
1.51 +# c99 - ISO C99 standard (not yet fully implemented)
1.52 +# gnu99 - c99 plus GCC extensions
1.53 +CSTANDARD = -std=gnu99
1.54 +CDEBUG = -g$(DEBUG)
1.55 +CWARN = -Wall -Wstrict-prototypes
1.56 +
1.57 +OPT = s
1.58 +
1.59 +CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA)
1.60 +CXXFLAGS = $(CXXDEFS) $(CXXINCS) -O$(OPT)
1.61 +LDFLAGS = -lm
1.62 +
1.63 +# Combine all necessary flags and optional flags.
1.64 +# Add target processor to flags.
1.65 +ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
1.66 +ALL_CXXFLAGS = -mmcu=$(MCU) -I. $(CXXFLAGS)
1.67 +
1.68 +# Programming support using avrdude. Settings and variables.
1.69 +AVRDUDE_PORT = $(PORT)
1.70 +AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex
1.71 +AVRDUDE_FLAGS = -V -F -C /etc/avrdude.conf \
1.72 + -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \
1.73 + -b $(UPLOAD_RATE)
1.74 +
1.75 +# Program settings
1.76 +CC = avr-gcc
1.77 +CXX = avr-g++
1.78 +LD = avr-ld
1.79 +OBJCOPY = avr-objcopy
1.80 +OBJDUMP = avr-objdump
1.81 +AR = avr-ar
1.82 +SIZE = avr-size
1.83 +NM = avr-nm
1.84 +AVRDUDE = avrdude
1.85 +REMOVE = rm -f
1.86 +MV = mv -f
1.87 +
1.88 +# Define all object files.
1.89 +OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o)
1.90 +
1.91 +# Default target.
1.92 +all: applet_files build sizeafter
1.93 +
1.94 +build: elf hex
1.95 +
1.96 +applet_files: $(TARGET).cpp
1.97 + test -d applet || mkdir applet
1.98 + cat $(ARDUINO)/main.cpp > applet/$(TARGET).cpp
1.99 + cat $(TARGET).cpp >> applet/$(TARGET).cpp
1.100 +
1.101 +elf: applet/$(TARGET).elf
1.102 +hex: applet/$(TARGET).hex
1.103 +
1.104 +# Program the device.
1.105 +upload: applet/$(TARGET).hex
1.106 + $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
1.107 +
1.108 +# Display size of file.
1.109 +HEXSIZE = $(SIZE) --target=$(FORMAT) applet/$(TARGET).hex
1.110 +ELFSIZE = $(SIZE) applet/$(TARGET).elf
1.111 +
1.112 +sizebefore:
1.113 + @if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi
1.114 +
1.115 +sizeafter:
1.116 + @if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(HEXSIZE); echo; fi
1.117 +
1.118 +
1.119 +### File-specific processing.
1.120 +
1.121 +
1.122 +.SUFFIXES: .elf .hex .eep .lss .sym
1.123 +
1.124 +.elf.hex:
1.125 + $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
1.126 +
1.127 +applet/$(TARGET).elf: applet/$(TARGET).cpp applet/core.a
1.128 + $(CXX) $(ALL_CXXFLAGS) -o $@ applet/$(TARGET).cpp -L. applet/core.a $(LDFLAGS)
1.129 +
1.130 +applet/core.a: $(OBJ)
1.131 + @for i in $(OBJ); do echo $(AR) rcs applet/core.a $$i; $(AR) rcs applet/core.a $$i; done
1.132 +
1.133 +# Compile: create object files from C++ source files.
1.134 +.cpp.o:
1.135 + $(CXX) -c $(ALL_CXXFLAGS) $< -o $@
1.136 +
1.137 +# Compile: create object files from C source files.
1.138 +.c.o:
1.139 + $(CC) -c $(ALL_CFLAGS) $< -o $@
1.140 +
1.141 +# Target: clean project.
1.142 +clean:
1.143 + $(REMOVE) applet/$(TARGET).hex applet/$(TARGET).elf applet/$(TARGET).cpp \
1.144 + applet/$(TARGET).map applet/core.a $(OBJ)
1.145 +
1.146 +.PHONY: all build elf hex eep lss sym program coff extcoff clean applet_files sizebefore sizeafter