1 TARGET = $(notdir $(CURDIR)) 2 INSTALL_DIR = ../arduino-1.0.5 3 PORT = /dev/ttyUSB0 4 UPLOAD_RATE = 57600 # 19200 5 AVRDUDE_PROGRAMMER = stk500v1 6 MCU = atmega328p # atmega168 7 F_CPU = 16000000 8 9 EXTRA_SRC = 10 EXTRA_CXXSRC = 11 EXTRA_CINCS = 12 EXTRA_CXXINCS = 13 14 CIRCUIT = 74HC273 15 #CIRCUIT = 74HC595 16 17 ### Internal definitions. 18 19 CIRCUIT_DEFS = -DCIRCUIT_$(CIRCUIT) 20 21 ARDUINO = $(INSTALL_DIR)/hardware/arduino/cores/arduino 22 VARIANT = $(INSTALL_DIR)/hardware/arduino/variants/standard 23 SRC = $(ARDUINO)/wiring.c $(ARDUINO)/wiring_digital.c \ 24 $(EXTRA_SRC) 25 CXXSRC = $(ARDUINO)/HardwareSerial.cpp \ 26 $(ARDUINO)/Print.cpp $(ARDUINO)/WString.cpp \ 27 $(ARDUINO)/Stream.cpp $(EXTRA_CXXSRC) 28 FORMAT = ihex 29 30 # Name of this Makefile (used for "make depend"). 31 MAKEFILE = Makefile 32 33 # Debugging format. 34 # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2. 35 # AVR (extended) COFF requires stabs, plus an avr-objcopy run. 36 DEBUG = stabs 37 38 # Place -D or -U options here 39 CDEFS = -DF_CPU=$(F_CPU) $(CIRCUIT_DEFS) 40 CXXDEFS = -DF_CPU=$(F_CPU) $(CIRCUIT_DEFS) 41 42 # Place -I options here 43 CINCS = -I$(ARDUINO) -I$(VARIANT) $(EXTRA_CINCS) 44 CXXINCS = -I$(ARDUINO) -I$(VARIANT) $(EXTRA_CXXINCS) 45 46 # Compiler flag to set the C Standard level. 47 # c89 - "ANSI" C 48 # gnu89 - c89 plus GCC extensions 49 # c99 - ISO C99 standard (not yet fully implemented) 50 # gnu99 - c99 plus GCC extensions 51 CSTANDARD = -std=gnu99 52 CDEBUG = -g$(DEBUG) 53 CWARN = -Wall -Wstrict-prototypes 54 55 OPT = s 56 57 CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA) 58 CXXFLAGS = $(CXXDEFS) $(CXXINCS) -O$(OPT) -ffunction-sections -fdata-sections 59 LDFLAGS = -lm -Wl,--gc-sections 60 61 # Combine all necessary flags and optional flags. 62 # Add target processor to flags. 63 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) 64 ALL_CXXFLAGS = -mmcu=$(MCU) -I. $(CXXFLAGS) 65 66 # Programming support using avrdude. Settings and variables. 67 AVRDUDE_PORT = $(PORT) 68 AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex 69 AVRDUDE_FLAGS = -V -F -C /etc/avrdude.conf \ 70 -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \ 71 -b $(UPLOAD_RATE) 72 73 # Program settings 74 CC = avr-gcc 75 CXX = avr-g++ 76 LD = avr-ld 77 OBJCOPY = avr-objcopy 78 OBJDUMP = avr-objdump 79 AR = avr-ar 80 SIZE = avr-size 81 NM = avr-nm 82 AVRDUDE = avrdude 83 REMOVE = rm -f 84 MV = mv -f 85 86 # Define all object files. 87 OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) 88 89 # Default target. 90 all: applet_files build sizeafter 91 92 build: elf hex 93 94 applet_files: $(TARGET).cpp 95 test -d applet || mkdir applet 96 cat $(ARDUINO)/main.cpp > applet/$(TARGET).cpp 97 cat $(TARGET).cpp >> applet/$(TARGET).cpp 98 99 elf: applet/$(TARGET).elf 100 hex: applet/$(TARGET).hex 101 102 # Program the device. 103 upload: applet/$(TARGET).hex 104 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) 105 106 # Display size of file. 107 HEXSIZE = $(SIZE) --target=$(FORMAT) applet/$(TARGET).hex 108 ELFSIZE = $(SIZE) applet/$(TARGET).elf 109 110 sizebefore: 111 @if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi 112 113 sizeafter: 114 @if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(HEXSIZE); echo; fi 115 116 117 ### File-specific processing. 118 119 120 .SUFFIXES: .elf .hex .eep .lss .sym 121 122 .elf.hex: 123 $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ 124 125 applet/$(TARGET).elf: applet/$(TARGET).cpp applet/core.a 126 $(CXX) $(ALL_CXXFLAGS) -o $@ applet/$(TARGET).cpp -L. applet/core.a $(LDFLAGS) 127 128 applet/core.a: $(OBJ) 129 @for i in $(OBJ); do echo $(AR) rcs applet/core.a $$i; $(AR) rcs applet/core.a $$i; done 130 131 # Compile: create object files from C++ source files. 132 .cpp.o: 133 $(CXX) -c $(ALL_CXXFLAGS) $< -o $@ 134 135 # Compile: create object files from C source files. 136 .c.o: 137 $(CC) -c $(ALL_CFLAGS) $< -o $@ 138 139 # Target: clean project. 140 clean: 141 $(REMOVE) applet/$(TARGET).hex applet/$(TARGET).elf applet/$(TARGET).cpp \ 142 applet/$(TARGET).map applet/core.a $(OBJ) 143 144 .PHONY: all build elf hex eep lss sym program coff extcoff clean applet_files sizebefore sizeafter