root/flukso/trunk/uc/Makefile
| Revision 122, 8.6 KB (checked in by icarus75, 2 years ago) | |
|---|---|
|
|
| Line | |
|---|---|
| 1 | # Arduino 0011 Makefile |
| 2 | # Arduino adaptation by mellis, eighthave, oli.keller |
| 3 | # |
| 4 | # This makefile allows you to build sketches from the command line |
| 5 | # without the Arduino environment (or Java). |
| 6 | # |
| 7 | # Detailed instructions for using the makefile: |
| 8 | # |
| 9 | # 1. Copy this file into the folder with your sketch. There should be a |
| 10 | # file with the extension .pde (e.g. foo.pde) |
| 11 | # |
| 12 | # 2. Below, modify the line containing "TARGET" to refer to the name of |
| 13 | # of your program's file without an extension (e.g. TARGET = foo). |
| 14 | # |
| 15 | # 3. Modify the line containg "INSTALL_DIR" to point to the directory that |
| 16 | # contains the Arduino installation (for example, under Mac OS X, this |
| 17 | # might be /Applications/arduino-0011). |
| 18 | # |
| 19 | # 4. Modify the line containing "PORT" to refer to the filename |
| 20 | # representing the USB or serial connection to your Arduino board |
| 21 | # (e.g. PORT = /dev/tty.USB0). If the exact name of this file |
| 22 | # changes, you can use * as a wildcard (e.g. PORT = /dev/tty.USB*). |
| 23 | # |
| 24 | # 5. Set the line containing "MCU" to match your board's processor. |
| 25 | # Older one's are atmega8 based, newer ones like Arduino Mini, Bluetooth |
| 26 | # or Diecimila have the atmega168. If you're using a LilyPad Arduino, |
| 27 | # change F_CPU to 8000000. |
| 28 | # |
| 29 | # 6. At the command line, change to the directory containing your |
| 30 | # program's file and the makefile. |
| 31 | # |
| 32 | # 7. Type "make" and press enter to compile/verify your program. |
| 33 | # |
| 34 | # 8. Type "make upload", reset your Arduino board, and press enter to |
| 35 | # upload your program to the Arduino board. |
| 36 | # |
| 37 | # $Id$ |
| 38 | |
| 39 | ############################################################################### |
| 40 | # |
| 41 | # project specific settings: |
| 42 | # |
| 43 | TARGET = main |
| 44 | # |
| 45 | # Predefine the TYPE and SENSORx C macros in main.h via this Makefile. |
| 46 | # Override the defaults on the command line by typing: |
| 47 | # make PHASE=x METERCONST=y SENSOR0=z ... |
| 48 | # |
| 49 | DBG = 0 |
| 50 | # |
| 51 | TYPE = 2300501 |
| 52 | PHASE = 1 |
| 53 | METERCONST= 5508 |
| 54 | # |
| 55 | SENSOR0 = 0123456789abcdef0123456789abcde0 |
| 56 | SENSOR1 = 0123456789abcdef0123456789abcde1 |
| 57 | SENSOR2 = 0123456789abcdef0123456789abcde2 |
| 58 | SENSOR3 = 0123456789abcdef0123456789abcde3 |
| 59 | # |
| 60 | CEXTRA = -D DBG=$(DBG) -D PHASE=$(PHASE) -D METERCONST=$(METERCONST) -D 'SENSOR0="$(SENSOR0)"' -D 'SENSOR1="$(SENSOR1)"' -D 'SENSOR2="$(SENSOR2)"' -D 'SENSOR3="$(SENSOR3)"' |
| 61 | ############################################################################### |
| 62 | |
| 63 | |
| 64 | ############################################################################### |
| 65 | # |
| 66 | # serial uploader settings |
| 67 | # |
| 68 | PORT = /dev/ttyUSB* |
| 69 | UPLOAD_RATE = 19200 |
| 70 | AVRDUDE_PROGRAMMER = usbtiny |
| 71 | # |
| 72 | # HINT: If you want to use the automatic reset feature which comes with Arduino |
| 73 | # Diecimila, put the follwoing in your avrdude.conf: |
| 74 | # (Use the systemwide $(INSTALL_DIR)/tools/avr/etc/avrdude.conf or create a |
| 75 | # local $HOME/.avrduderc file) |
| 76 | # |
| 77 | # programmer |
| 78 | # id = "arduino"; |
| 79 | # desc = "Arduino Serial Bootloader"; |
| 80 | # type = stk500; |
| 81 | # reset = 7; |
| 82 | # # since Arduino Diecimila the serial DTR line can be used to trigger a reset! |
| 83 | # ; |
| 84 | # |
| 85 | # After this you can specify AVRDUDE_PROGRAMMER = arduino, above. |
| 86 | # On older boards you can manually ad this reset feature. Wire a cable from the |
| 87 | # FTDI 232 Chip's DTR pin (the number differs from package to package, see datasheet) |
| 88 | # to the RESET line of the ATmega. Inbetween this connection must be a 100nF capacitor. |
| 89 | ##################################################################################### |
| 90 | |
| 91 | |
| 92 | ##################################################################################### |
| 93 | # |
| 94 | # hardware dependent settings |
| 95 | # |
| 96 | MCU = atmega48 |
| 97 | F_CPU = 1000000 |
| 98 | ##################################################################################### |
| 99 | |
| 100 | ##################################################################################### |
| 101 | # |
| 102 | # Below here nothing should be changed... |
| 103 | # |
| 104 | ##################################################################################### |
| 105 | |
| 106 | AVR_TOOLS_PATH = /usr/bin |
| 107 | SRC = wiring/serial.c |
| 108 | FORMAT = ihex |
| 109 | |
| 110 | # Name of this Makefile (used for "make depend"). |
| 111 | MAKEFILE = Makefile |
| 112 | |
| 113 | # Debugging format. |
| 114 | # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2. |
| 115 | # AVR (extended) COFF requires stabs, plus an avr-objcopy run. |
| 116 | DEBUG = stabs |
| 117 | |
| 118 | OPT = s |
| 119 | |
| 120 | # Place -D or -U options here |
| 121 | CDEFS = -DF_CPU=$(F_CPU) |
| 122 | CXXDEFS = -DF_CPU=$(F_CPU) |
| 123 | |
| 124 | # Compiler flag to set the C Standard level. |
| 125 | # c89 - "ANSI" C |
| 126 | # gnu89 - c89 plus GCC extensions |
| 127 | # c99 - ISO C99 standard (not yet fully implemented) |
| 128 | # gnu99 - c99 plus GCC extensions |
| 129 | CSTANDARD = -std=gnu99 |
| 130 | CDEBUG = -g$(DEBUG) |
| 131 | CWARN = -Wall -Wstrict-prototypes |
| 132 | CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums |
| 133 | #CEXTRA = -Wa,-adhlns=$(<:.c=.lst) |
| 134 | |
| 135 | CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA) |
| 136 | CXXFLAGS = $(CDEFS) $(CINCS) -O$(OPT) |
| 137 | #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs |
| 138 | LDFLAGS = -lm |
| 139 | |
| 140 | |
| 141 | # Programming support using avrdude. Settings and variables. |
| 142 | AVRDUDE_PORT = $(PORT) |
| 143 | AVRDUDE_WRITE_FUSES= -U lfuse:w:0x6E:m -U hfuse:w:0xD6:m -U efuse:w:0x1:m |
| 144 | AVRDUDE_WRITE_FLASH = -U flash:w:bin/$(TARGET).hex |
| 145 | AVRDUDE_WRITE_EEPROM = -U eeprom:w:bin/$(TARGET).eep |
| 146 | AVRDUDE_FLAGS = -p $(MCU) -c $(AVRDUDE_PROGRAMMER) -b $(UPLOAD_RATE) |
| 147 | |
| 148 | # Program settings |
| 149 | CC = $(AVR_TOOLS_PATH)/avr-gcc |
| 150 | CXX = $(AVR_TOOLS_PATH)/avr-g++ |
| 151 | OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy |
| 152 | OBJDUMP = $(AVR_TOOLS_PATH)/avr-objdump |
| 153 | AR = $(AVR_TOOLS_PATH)/avr-ar |
| 154 | SIZE = $(AVR_TOOLS_PATH)/avr-size |
| 155 | NM = $(AVR_TOOLS_PATH)/avr-nm |
| 156 | AVRDUDE = avrdude |
| 157 | REMOVE = rm -f |
| 158 | MV = mv -f |
| 159 | |
| 160 | # Define all object files. |
| 161 | OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o) |
| 162 | |
| 163 | # Define all listing files. |
| 164 | LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst) |
| 165 | |
| 166 | # Combine all necessary flags and optional flags. |
| 167 | # Add target processor to flags. |
| 168 | ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) |
| 169 | ALL_CXXFLAGS = -mmcu=$(MCU) -I. $(CXXFLAGS) |
| 170 | ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) |
| 171 | |
| 172 | |
| 173 | # Default target. |
| 174 | all: bin_files build sizeafter |
| 175 | |
| 176 | build: elf hex eep |
| 177 | |
| 178 | bin_files: $(TARGET).c |
| 179 | @test -d bin || mkdir bin |
| 180 | @cp $(TARGET).c bin/$(TARGET).c |
| 181 | |
| 182 | elf: bin/$(TARGET).elf |
| 183 | hex: bin/$(TARGET).hex |
| 184 | eep: bin/$(TARGET).eep |
| 185 | lss: bin/$(TARGET).lss |
| 186 | sym: bin/$(TARGET).sym |
| 187 | |
| 188 | # Program the device. |
| 189 | upload: bin/$(TARGET).hex |
| 190 | @$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FUSES) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) |
| 191 | |
| 192 | # Display size of file. |
| 193 | HEXSIZE = $(SIZE) --target=$(FORMAT) bin/$(TARGET).hex |
| 194 | ELFSIZE = $(SIZE) bin/$(TARGET).elf |
| 195 | sizebefore: |
| 196 | @if [ -f bin/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi |
| 197 | |
| 198 | sizeafter: |
| 199 | @if [ -f bin/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(HEXSIZE); echo; fi |
| 200 | |
| 201 | |
| 202 | # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. |
| 203 | COFFCONVERT=$(OBJCOPY) --debugging \ |
| 204 | --change-section-address .data-0x800000 \ |
| 205 | --change-section-address .bss-0x800000 \ |
| 206 | --change-section-address .noinit-0x800000 \ |
| 207 | --change-section-address .eeprom-0x810000 |
| 208 | |
| 209 | |
| 210 | coff: bin/$(TARGET).elf |
| 211 | $(COFFCONVERT) -O coff-avr bin/$(TARGET).elf $(TARGET).cof |
| 212 | |
| 213 | |
| 214 | extcoff: $(TARGET).elf |
| 215 | $(COFFCONVERT) -O coff-ext-avr bin/$(TARGET).elf $(TARGET).cof |
| 216 | |
| 217 | .SUFFIXES: .elf .hex .eep .lss .sym |
| 218 | |
| 219 | .elf.hex: |
| 220 | @$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ |
| 221 | |
| 222 | .elf.eep: |
| 223 | @$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ |
| 224 | --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ |
| 225 | |
| 226 | # Create extended listing file from ELF output file. |
| 227 | .elf.lss: |
| 228 | $(OBJDUMP) -h -S $< > $@ |
| 229 | |
| 230 | # Create a symbol table from ELF output file. |
| 231 | .elf.sym: |
| 232 | $(NM) -n $< > $@ |
| 233 | |
| 234 | # Link: create ELF output file from library. |
| 235 | bin/$(TARGET).elf: $(TARGET).c bin/core.a |
| 236 | @$(CC) $(ALL_CFLAGS) -o $@ bin/$(TARGET).c -L. bin/core.a $(LDFLAGS) |
| 237 | |
| 238 | bin/core.a: $(OBJ) |
| 239 | @for i in $(OBJ); do $(AR) rcs bin/core.a $$i; done |
| 240 | |
| 241 | # Compile: create object files from C++ source files. |
| 242 | .cpp.o: |
| 243 | @$(CXX) -c $(ALL_CXXFLAGS) $< -o $@ |
| 244 | |
| 245 | # Compile: create object files from C source files. |
| 246 | .c.o: |
| 247 | @$(CC) -c $(ALL_CFLAGS) $< -o $@ |
| 248 | |
| 249 | |
| 250 | # Compile: create assembler files from C source files. |
| 251 | .c.s: |
| 252 | $(CC) -S $(ALL_CFLAGS) $< -o $@ |
| 253 | |
| 254 | |
| 255 | # Assemble: create object files from assembler source files. |
| 256 | .S.o: |
| 257 | $(CC) -c $(ALL_ASFLAGS) $< -o $@ |
| 258 | |
| 259 | |
| 260 | |
| 261 | # Target: clean project. |
| 262 | clean: |
| 263 | @$(REMOVE) bin/$(TARGET).hex bin/$(TARGET).eep bin/$(TARGET).cof bin/$(TARGET).elf \ |
| 264 | bin/$(TARGET).map bin/$(TARGET).sym bin/$(TARGET).lss bin/$(TARGET).c bin/core.a \ |
| 265 | $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d) |
| 266 | |
| 267 | depend: |
| 268 | if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \ |
| 269 | then \ |
| 270 | sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \ |
| 271 | $(MAKEFILE).$$$$ && \ |
| 272 | $(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \ |
| 273 | fi |
| 274 | echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \ |
| 275 | >> $(MAKEFILE); \ |
| 276 | $(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE) |
| 277 | |
| 278 | .PHONY: all build elf hex eep lss sym program coff extcoff clean depend bin_files sizebefore sizeafter |
Note: See TracBrowser
for help on using the browser.
