|
| 1 | +# Build environments(from https://github.com/Optiboot/optiboot/blob/master/optiboot/bootloaders/optiboot/Makefile) |
| 2 | +# Start of some ugly makefile-isms to allow avr_boot to be built |
| 3 | +# in several different environments. |
| 4 | + |
| 5 | +# default |
| 6 | +fixpath = $(1) |
| 7 | +SH := bash |
| 8 | + |
| 9 | +ifeq ($(ENV), arduino) |
| 10 | +# For Arduino, we assume that we're connected to the avr_boot directory |
| 11 | +# in Arduino/hardware/avr/bootloader, which means that the full set |
| 12 | +# of avr-tools are "right up there" in standard places. |
| 13 | +# (except that in 1.5.x, there's an additional level of "up") |
| 14 | +TESTDIR := $(firstword $(wildcard ../../../tools/*)) |
| 15 | +ifeq (,$(TESTDIR)) |
| 16 | +# Arduino 1.5.x tool location compared to optiboot dir |
| 17 | + TOOLROOT = ../../../../tools |
| 18 | +else |
| 19 | +# Arduino 1.0 (and earlier) tool location |
| 20 | + TOOLROOT = ../../../tools |
| 21 | +endif |
| 22 | +GCCROOT = $(TOOLROOT)/avr/bin/ |
| 23 | + |
| 24 | +ifeq ($(OS), windows) |
| 25 | +# On windows, SOME of the tool paths will need to have backslashes instead |
| 26 | +# of forward slashes (because they use windows cmd.exe for execution instead |
| 27 | +# of a unix/mingw shell?) We also have to ensure that a consistent shell |
| 28 | +# is used even if a unix shell is installed (ie as part of WINAVR) |
| 29 | +fixpath = $(subst /,\,$1) |
| 30 | +SHELL = cmd.exe |
| 31 | +SH = sh |
| 32 | +endif |
| 33 | + |
| 34 | +else ifeq ($(ENV), arduinodev) |
| 35 | +# Arduino IDE source code environment. Use the unpacked compilers created |
| 36 | +# by the build (you'll need to do "ant build" first.) |
| 37 | +ifeq ($(OS), macosx) |
| 38 | +TOOLROOT = ../../../../build/macosx/work/Arduino.app/Contents/Resources/Java/hardware/tools |
| 39 | +endif |
| 40 | +ifeq ($(OS), windows) |
| 41 | +TOOLROOT = ../../../../build/windows/work/hardware/tools |
| 42 | +endif |
| 43 | + |
| 44 | +GCCROOT = $(TOOLROOT)/avr/bin/ |
| 45 | + |
| 46 | +else |
| 47 | +GCCROOT = |
| 48 | +endif |
| 49 | + |
| 50 | +# End of build environment code. |
| 51 | + |
| 52 | + |
| 53 | +atmega328p_cs4: TARGET = atmega328p_cs4 |
| 54 | +atmega328p_cs4: MCU_TARGET = atmega328p |
| 55 | +atmega328p_cs4: BOOT_ADR = 0x7000 |
| 56 | +atmega328p_cs4: F_CPU = 20000000 |
| 57 | +atmega328p_cs4: USE_LED = 0 |
| 58 | +atmega328p_cs4: USE_UART = 0 |
| 59 | +atmega328p_cs4: CS_PIN = 4 |
| 60 | +atmega328p_cs4: VARIANT_1284P = 0 |
| 61 | +atmega328p_cs4: clean |
| 62 | +atmega328p_cs4: atmega328p_cs4.elf |
| 63 | +atmega328p_cs4: atmega328p_cs4.lst |
| 64 | +atmega328p_cs4: atmega328p_cs4.hex |
| 65 | + |
| 66 | +atmega328p_cs8: TARGET = atmega328p_cs8 |
| 67 | +atmega328p_cs8: MCU_TARGET = atmega328p |
| 68 | +atmega328p_cs8: BOOT_ADR = 0x7000 |
| 69 | +atmega328p_cs8: F_CPU = 20000000 |
| 70 | +atmega328p_cs8: USE_LED = 0 |
| 71 | +atmega328p_cs8: USE_UART = 0 |
| 72 | +atmega328p_cs8: CS_PIN = 8 |
| 73 | +atmega328p_cs8: VARIANT_1284P = 0 |
| 74 | +atmega328p_cs8: clean |
| 75 | +atmega328p_cs8: atmega328p_cs8.elf |
| 76 | +atmega328p_cs8: atmega328p_cs8.lst |
| 77 | +atmega328p_cs8: atmega328p_cs8.hex |
| 78 | + |
| 79 | +atmega328p_cs10: TARGET = atmega328p_cs10 |
| 80 | +atmega328p_cs10: MCU_TARGET = atmega328p |
| 81 | +atmega328p_cs10: BOOT_ADR = 0x7000 |
| 82 | +atmega328p_cs10: F_CPU = 20000000 |
| 83 | +atmega328p_cs10: USE_LED = 0 |
| 84 | +atmega328p_cs10: USE_UART = 0 |
| 85 | +atmega328p_cs10: CS_PIN = 10 |
| 86 | +atmega328p_cs10: VARIANT_1284P = 0 |
| 87 | +atmega328p_cs10: clean |
| 88 | +atmega328p_cs10: atmega328p_cs10.elf |
| 89 | +atmega328p_cs10: atmega328p_cs10.lst |
| 90 | +atmega328p_cs10: atmega328p_cs10.hex |
| 91 | + |
| 92 | +atmega32u4_cs4: TARGET = atmega32u4_cs4 |
| 93 | +atmega32u4_cs4: MCU_TARGET = atmega32u4 |
| 94 | +atmega32u4_cs4: BOOT_ADR = 0x7000 |
| 95 | +atmega32u4_cs4: F_CPU = 20000000 |
| 96 | +atmega32u4_cs4: USE_LED = 0 |
| 97 | +atmega32u4_cs4: USE_UART = 0 |
| 98 | +atmega32u4_cs4: CS_PIN = 4 |
| 99 | +atmega32u4_cs4: VARIANT_1284P = 0 |
| 100 | +atmega32u4_cs4: clean |
| 101 | +atmega32u4_cs4: atmega32u4_cs4.elf |
| 102 | +atmega32u4_cs4: atmega32u4_cs4.lst |
| 103 | +atmega32u4_cs4: atmega32u4_cs4.hex |
| 104 | + |
| 105 | +atmega32u4_cs8: TARGET = atmega32u4_cs8 |
| 106 | +atmega32u4_cs8: MCU_TARGET = atmega32u4 |
| 107 | +atmega32u4_cs8: BOOT_ADR = 0x7000 |
| 108 | +atmega32u4_cs8: F_CPU = 20000000 |
| 109 | +atmega32u4_cs8: USE_LED = 0 |
| 110 | +atmega32u4_cs8: USE_UART = 0 |
| 111 | +atmega32u4_cs8: CS_PIN = 8 |
| 112 | +atmega32u4_cs8: VARIANT_1284P = 0 |
| 113 | +atmega32u4_cs8: clean |
| 114 | +atmega32u4_cs8: atmega32u4_cs8.elf |
| 115 | +atmega32u4_cs8: atmega32u4_cs8.lst |
| 116 | +atmega32u4_cs8: atmega32u4_cs8.hex |
| 117 | + |
| 118 | +atmega32u4_cs10: TARGET = atmega32u4_cs10 |
| 119 | +atmega32u4_cs10: MCU_TARGET = atmega32u4 |
| 120 | +atmega32u4_cs10: BOOT_ADR = 0x7000 |
| 121 | +atmega32u4_cs10: F_CPU = 20000000 |
| 122 | +atmega32u4_cs10: USE_LED = 0 |
| 123 | +atmega32u4_cs10: USE_UART = 0 |
| 124 | +atmega32u4_cs10: CS_PIN = 10 |
| 125 | +atmega32u4_cs10: VARIANT_1284P = 0 |
| 126 | +atmega32u4_cs10: clean |
| 127 | +atmega32u4_cs10: atmega32u4_cs10.elf |
| 128 | +atmega32u4_cs10: atmega32u4_cs10.lst |
| 129 | +atmega32u4_cs10: atmega32u4_cs10.hex |
| 130 | + |
| 131 | +atmega1284p_avrdevelopersstandard_cs4: TARGET = atmega1284p_avrdevelopersstandard_cs4 |
| 132 | +atmega1284p_avrdevelopersstandard_cs4: MCU_TARGET = atmega1284p |
| 133 | +atmega1284p_avrdevelopersstandard_cs4: BOOT_ADR = 0x1F000 |
| 134 | +atmega1284p_avrdevelopersstandard_cs4: F_CPU = 20000000 |
| 135 | +atmega1284p_avrdevelopersstandard_cs4: USE_LED = 0 |
| 136 | +atmega1284p_avrdevelopersstandard_cs4: USE_UART = 0 |
| 137 | +atmega1284p_avrdevelopersstandard_cs4: CS_PIN = 4 |
| 138 | +atmega1284p_avrdevelopersstandard_cs4: VARIANT_1284P = 0 |
| 139 | +atmega1284p_avrdevelopersstandard_cs4: clean |
| 140 | +atmega1284p_avrdevelopersstandard_cs4: atmega1284p_avrdevelopersstandard_cs4.elf |
| 141 | +atmega1284p_avrdevelopersstandard_cs4: atmega1284p_avrdevelopersstandard_cs4.lst |
| 142 | +atmega1284p_avrdevelopersstandard_cs4: atmega1284p_avrdevelopersstandard_cs4.hex |
| 143 | + |
| 144 | +atmega1284p_bobuinosleepingbeauty_cs4: TARGET = atmega1284p_bobuinosleepingbeauty_cs4 |
| 145 | +atmega1284p_bobuinosleepingbeauty_cs4: MCU_TARGET = atmega1284p |
| 146 | +atmega1284p_bobuinosleepingbeauty_cs4: BOOT_ADR = 0x1F000 |
| 147 | +atmega1284p_bobuinosleepingbeauty_cs4: F_CPU = 20000000 |
| 148 | +atmega1284p_bobuinosleepingbeauty_cs4: USE_LED = 0 |
| 149 | +atmega1284p_bobuinosleepingbeauty_cs4: USE_UART = 0 |
| 150 | +atmega1284p_bobuinosleepingbeauty_cs4: CS_PIN = 4 |
| 151 | +atmega1284p_bobuinosleepingbeauty_cs4: VARIANT_1284P = 1 |
| 152 | +atmega1284p_bobuinosleepingbeauty_cs4: clean |
| 153 | +atmega1284p_bobuinosleepingbeauty_cs4: atmega1284p_bobuinosleepingbeauty_cs4.elf |
| 154 | +atmega1284p_bobuinosleepingbeauty_cs4: atmega1284p_bobuinosleepingbeauty_cs4.lst |
| 155 | +atmega1284p_bobuinosleepingbeauty_cs4: atmega1284p_bobuinosleepingbeauty_cs4.hex |
| 156 | + |
| 157 | +atmega1284p_avrdevelopersstandard_cs8: TARGET = atmega1284p_avrdevelopersstandard_cs8 |
| 158 | +atmega1284p_avrdevelopersstandard_cs8: MCU_TARGET = atmega1284p |
| 159 | +atmega1284p_avrdevelopersstandard_cs8: BOOT_ADR = 0x1F000 |
| 160 | +atmega1284p_avrdevelopersstandard_cs8: F_CPU = 20000000 |
| 161 | +atmega1284p_avrdevelopersstandard_cs8: USE_LED = 0 |
| 162 | +atmega1284p_avrdevelopersstandard_cs8: USE_UART = 0 |
| 163 | +atmega1284p_avrdevelopersstandard_cs8: CS_PIN = 8 |
| 164 | +atmega1284p_avrdevelopersstandard_cs8: VARIANT_1284P = 0 |
| 165 | +atmega1284p_avrdevelopersstandard_cs8: clean |
| 166 | +atmega1284p_avrdevelopersstandard_cs8: atmega1284p_avrdevelopersstandard_cs8.elf |
| 167 | +atmega1284p_avrdevelopersstandard_cs8: atmega1284p_avrdevelopersstandard_cs8.lst |
| 168 | +atmega1284p_avrdevelopersstandard_cs8: atmega1284p_avrdevelopersstandard_cs8.hex |
| 169 | + |
| 170 | +atmega1284p_bobuino_cs8: TARGET = atmega1284p_bobuino_cs8 |
| 171 | +atmega1284p_bobuino_cs8: MCU_TARGET = atmega1284p |
| 172 | +atmega1284p_bobuino_cs8: BOOT_ADR = 0x1F000 |
| 173 | +atmega1284p_bobuino_cs8: F_CPU = 20000000 |
| 174 | +atmega1284p_bobuino_cs8: USE_LED = 0 |
| 175 | +atmega1284p_bobuino_cs8: USE_UART = 0 |
| 176 | +atmega1284p_bobuino_cs8: CS_PIN = 8 |
| 177 | +atmega1284p_bobuino_cs8: VARIANT_1284P = 1 |
| 178 | +atmega1284p_bobuino_cs8: clean |
| 179 | +atmega1284p_bobuino_cs8: atmega1284p_bobuino_cs4.elf |
| 180 | +atmega1284p_bobuino_cs8: atmega1284p_bobuino_cs8.lst |
| 181 | +atmega1284p_bobuino_cs8: atmega1284p_bobuino_cs8.hex |
| 182 | + |
| 183 | +atmega1284p_sleepingbeauty_cs8: TARGET = atmega1284p_sleepingbeauty_cs8 |
| 184 | +atmega1284p_sleepingbeauty_cs8: MCU_TARGET = atmega1284p |
| 185 | +atmega1284p_sleepingbeauty_cs8: BOOT_ADR = 0x1F000 |
| 186 | +atmega1284p_sleepingbeauty_cs8: F_CPU = 20000000 |
| 187 | +atmega1284p_sleepingbeauty_cs8: USE_LED = 0 |
| 188 | +atmega1284p_sleepingbeauty_cs8: USE_UART = 0 |
| 189 | +atmega1284p_sleepingbeauty_cs8: CS_PIN = 8 |
| 190 | +atmega1284p_sleepingbeauty_cs8: VARIANT_1284P = 2 |
| 191 | +atmega1284p_sleepingbeauty_cs8: clean |
| 192 | +atmega1284p_sleepingbeauty_cs8: atmega1284p_sleepingbeauty_cs8.elf |
| 193 | +atmega1284p_sleepingbeauty_cs8: atmega1284p_sleepingbeauty_cs8.lst |
| 194 | +atmega1284p_sleepingbeauty_cs8: atmega1284p_sleepingbeauty_cs8.hex |
| 195 | + |
| 196 | +atmega1284p_avrdevelopersstandard_cs10: TARGET = atmega1284p_avrdevelopersstandard_cs10 |
| 197 | +atmega1284p_avrdevelopersstandard_cs10: MCU_TARGET = atmega1284p |
| 198 | +atmega1284p_avrdevelopersstandard_cs10: BOOT_ADR = 0x1F000 |
| 199 | +atmega1284p_avrdevelopersstandard_cs10: F_CPU = 20000000 |
| 200 | +atmega1284p_avrdevelopersstandard_cs10: USE_LED = 0 |
| 201 | +atmega1284p_avrdevelopersstandard_cs10: USE_UART = 0 |
| 202 | +atmega1284p_avrdevelopersstandard_cs10: CS_PIN = 10 |
| 203 | +atmega1284p_avrdevelopersstandard_cs10: VARIANT_1284P = 0 |
| 204 | +atmega1284p_avrdevelopersstandard_cs10: clean |
| 205 | +atmega1284p_avrdevelopersstandard_cs10: atmega1284p_avrdevelopersstandard_cs10.elf |
| 206 | +atmega1284p_avrdevelopersstandard_cs10: atmega1284p_avrdevelopersstandard_cs10.lst |
| 207 | +atmega1284p_avrdevelopersstandard_cs10: atmega1284p_avrdevelopersstandard_cs10.hex |
| 208 | + |
| 209 | +atmega1284p_bobuinosleepingbeauty_cs10: TARGET = atmega1284p_bobuinosleepingbeauty_cs10 |
| 210 | +atmega1284p_bobuinosleepingbeauty_cs10: MCU_TARGET = atmega1284p |
| 211 | +atmega1284p_bobuinosleepingbeauty_cs10: BOOT_ADR = 0x1F000 |
| 212 | +atmega1284p_bobuinosleepingbeauty_cs10: F_CPU = 20000000 |
| 213 | +atmega1284p_bobuinosleepingbeauty_cs10: USE_LED = 0 |
| 214 | +atmega1284p_bobuinosleepingbeauty_cs10: USE_UART = 0 |
| 215 | +atmega1284p_bobuinosleepingbeauty_cs10: CS_PIN = 10 |
| 216 | +atmega1284p_bobuinosleepingbeauty_cs10: VARIANT_1284P = 1 |
| 217 | +atmega1284p_bobuinosleepingbeauty_cs10: clean |
| 218 | +atmega1284p_bobuinosleepingbeauty_cs10: atmega1284p_bobuinosleepingbeauty_cs10.elf |
| 219 | +atmega1284p_bobuinosleepingbeauty_cs10: atmega1284p_bobuinosleepingbeauty_cs10.lst |
| 220 | +atmega1284p_bobuinosleepingbeauty_cs10: atmega1284p_bobuinosleepingbeauty_cs10.hex |
| 221 | + |
| 222 | +# atmega2560_cs4: TARGET = atmega2560_cs4 |
| 223 | +# atmega2560_cs4: MCU_TARGET = atmega2560 |
| 224 | +# atmega2560_cs4: BOOT_ADR = 0x3F000 |
| 225 | +# atmega2560_cs4: F_CPU = 20000000 |
| 226 | +# atmega2560_cs4: USE_LED = 0 |
| 227 | +# atmega2560_cs4: USE_UART = 0 |
| 228 | +# atmega2560_cs4: CS_PIN = 4 |
| 229 | +# atmega2560_cs4: VARIANT_1284P = 0 |
| 230 | +# atmega2560_cs4: clean |
| 231 | +# atmega2560_cs4: atmega2560_cs4.elf |
| 232 | +# atmega2560_cs4: atmega2560_cs4.lst |
| 233 | +# atmega2560_cs4: atmega2560_cs4.hex |
| 234 | + |
| 235 | +# atmega2560_cs8: TARGET = atmega2560_cs8 |
| 236 | +# atmega2560_cs8: MCU_TARGET = atmega2560 |
| 237 | +# atmega2560_cs8: BOOT_ADR = 0x3F000 |
| 238 | +# atmega2560_cs8: F_CPU = 20000000 |
| 239 | +# atmega2560_cs8: USE_LED = 0 |
| 240 | +# atmega2560_cs8: USE_UART = 0 |
| 241 | +# atmega2560_cs8: CS_PIN = 8 |
| 242 | +# atmega2560_cs8: VARIANT_1284P = 0 |
| 243 | +# atmega2560_cs8: clean |
| 244 | +# atmega2560_cs8: atmega2560_cs8.elf |
| 245 | +# atmega2560_cs8: atmega2560_cs8.lst |
| 246 | +# atmega2560_cs8: atmega2560_cs8.hex |
| 247 | + |
| 248 | +# atmega2560_cs10: TARGET = atmega2560_cs10 |
| 249 | +# atmega2560_cs10: MCU_TARGET = atmega2560 |
| 250 | +# atmega2560_cs10: BOOT_ADR = 0x3F000 |
| 251 | +# atmega2560_cs10: F_CPU = 20000000 |
| 252 | +# atmega2560_cs10: USE_LED = 0 |
| 253 | +# atmega2560_cs10: USE_UART = 0 |
| 254 | +# atmega2560_cs10: CS_PIN = 10 |
| 255 | +# atmega2560_cs10: VARIANT_1284P = 0 |
| 256 | +# atmega2560_cs10: clean |
| 257 | +# atmega2560_cs10: atmega2560_cs10.elf |
| 258 | +# atmega2560_cs10: atmega2560_cs10.lst |
| 259 | +# atmega2560_cs10: atmega2560_cs10.hex |
| 260 | + |
| 261 | +# atmega2560_cs53: TARGET = atmega2560_cs53 |
| 262 | +# atmega2560_cs53: MCU_TARGET = atmega2560 |
| 263 | +# atmega2560_cs53: BOOT_ADR = 0x3F000 |
| 264 | +# atmega2560_cs53: F_CPU = 20000000 |
| 265 | +# atmega2560_cs53: USE_LED = 0 |
| 266 | +# atmega2560_cs53: USE_UART = 0 |
| 267 | +# atmega2560_cs53: CS_PIN = 53 |
| 268 | +# atmega2560_cs53: VARIANT_1284P = 0 |
| 269 | +# atmega2560_cs53: clean |
| 270 | +# atmega2560_cs53: atmega2560_cs53.elf |
| 271 | +# atmega2560_cs53: atmega2560_cs53.lst |
| 272 | +# atmega2560_cs53: atmega2560_cs53.hex |
| 273 | + |
| 274 | + |
| 275 | +# Generic build instructions |
| 276 | + |
| 277 | +#ifeq ($(strip $(USE_UART)),0) |
| 278 | +CSRC = main.c pff/src/pff.c diskio.c |
| 279 | +#else |
| 280 | +#CSRC = main.c pff/src/pff.c diskio.c uart/uart.c |
| 281 | +#endif |
| 282 | + |
| 283 | +ASRC = asmfunc.S |
| 284 | +OPTIMIZE = -Os -mcall-prologues -ffunction-sections -fdata-sections |
| 285 | +DEFS = -DBOOT_ADR=$(BOOT_ADR) -DF_CPU=$(F_CPU) -DUSE_LED=$(USE_LED) -DUSE_UART=$(USE_UART) -DCS_PIN=$(CS_PIN) -DVARIANT_1284P=$(VARIANT_1284P) |
| 286 | +LIBS = |
| 287 | +DEBUG = dwarf-2 |
| 288 | + |
| 289 | +ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs $(DEFS) |
| 290 | +ALL_ASFLAGS = -mmcu=$(MCU_TARGET) -I. -x assembler-with-cpp $(ASFLAGS) |
| 291 | +CFLAGS = -g$(DEBUG) -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) -std=c99 $(DEFS) |
| 292 | +LDFLAGS = -Wl,-Map,$(TARGET).map -Wl,--gc-sections -Wl,--section-start,.text=$(BOOT_ADR) |
| 293 | +OBJ = $(CSRC:.c=.o) $(ASRC:.S=.o) |
| 294 | + |
| 295 | +CC = $(GCCROOT)avr-gcc |
| 296 | +OBJCOPY = $(GCCROOT)avr-objcopy |
| 297 | +OBJDUMP = $(call fixpath,$(GCCROOT)avr-objdump) |
| 298 | +SIZE = $(GCCROOT)avr-size |
| 299 | + |
| 300 | + |
| 301 | +%.elf: $(OBJ) |
| 302 | + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) |
| 303 | + |
| 304 | + |
| 305 | +clean: |
| 306 | + rm -rf *.o $(TARGET).elf *.eps *.bak *.a *.bin |
| 307 | + rm -rf *.lst *.map $(EXTRA_CLEAN_FILES) |
| 308 | + rm -rf $(TARGET).hex |
| 309 | + |
| 310 | +%.lst: %.elf |
| 311 | + $(OBJDUMP) -h -S $< > $@ |
| 312 | + |
| 313 | +%.o : %.S |
| 314 | + $(CC) -c $(ALL_ASFLAGS) $< -o $@ |
| 315 | + |
| 316 | +%.hex: %.elf |
| 317 | + $(OBJCOPY) -j .text -j .data -j .fuse -O ihex $< $@ |
| 318 | + |
| 319 | +print-% : ; @echo $* = $($*) #test any var with make print-XXX |
0 commit comments