|
1 # Hey Emacs, this is a -*- makefile -*- |
|
2 #---------------------------------------------------------------------------- |
|
3 # WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al. |
|
4 # >> Modified for use with the LUFA project. << |
|
5 # |
|
6 # Released to the Public Domain |
|
7 # |
|
8 # Additional material for this makefile was written by: |
|
9 # Peter Fleury |
|
10 # Tim Henigan |
|
11 # Colin O'Flynn |
|
12 # Reiner Patommel |
|
13 # Markus Pfaff |
|
14 # Sander Pool |
|
15 # Frederik Rouleau |
|
16 # Carlos Lamas |
|
17 # Dean Camera |
|
18 # Opendous Inc. |
|
19 # Denver Gingerich |
|
20 # |
|
21 #---------------------------------------------------------------------------- |
|
22 # On command line: |
|
23 # |
|
24 # make all = Make software. |
|
25 # |
|
26 # make clean = Clean out built project files. |
|
27 # |
|
28 # make coff = Convert ELF to AVR COFF. |
|
29 # |
|
30 # make extcoff = Convert ELF to AVR Extended COFF. |
|
31 # |
|
32 # make program = Download the hex file to the device, using avrdude. |
|
33 # Please customize the avrdude settings below first! |
|
34 # |
|
35 # make dfu = Download the hex file to the device, using dfu-programmer (must |
|
36 # have dfu-programmer installed). |
|
37 # |
|
38 # make flip = Download the hex file to the device, using Atmel FLIP (must |
|
39 # have Atmel FLIP installed). |
|
40 # |
|
41 # make dfu-ee = Download the eeprom file to the device, using dfu-programmer |
|
42 # (must have dfu-programmer installed). |
|
43 # |
|
44 # make flip-ee = Download the eeprom file to the device, using Atmel FLIP |
|
45 # (must have Atmel FLIP installed). |
|
46 # |
|
47 # make doxygen = Generate DoxyGen documentation for the project (must have |
|
48 # DoxyGen installed) |
|
49 # |
|
50 # make debug = Start either simulavr or avarice as specified for debugging, |
|
51 # with avr-gdb or avr-insight as the front end for debugging. |
|
52 # |
|
53 # make filename.s = Just compile filename.c into the assembler code only. |
|
54 # |
|
55 # make filename.i = Create a preprocessed source file for use in submitting |
|
56 # bug reports to the GCC project. |
|
57 # |
|
58 # To rebuild project do "make clean" then "make all". |
|
59 #---------------------------------------------------------------------------- |
|
60 |
|
61 # MCU name(s) |
|
62 # Since the ATMEGA8U2 part is not directly supported by the current |
|
63 # versions of either avrdude or dfu-programmer, we specify a dummy |
|
64 # part; AT90USB82 which is close enough in memory size and organization |
|
65 MCU = atmega8u2 |
|
66 MCU_AVRDUDE = at90usb82 |
|
67 MCU_DFU = at90usb82 |
|
68 |
|
69 # Specify the Arduino model using the assigned PID. This is used by Descriptors.c |
|
70 # to set PID and product descriptor string |
|
71 # Uno PID: |
|
72 ARDUINO_MODEL_PID = 0x0001 |
|
73 # Mega 2560 PID: |
|
74 #ARDUINO_MODEL_PID = 0x0010 |
|
75 |
|
76 |
|
77 # Target board (see library "Board Types" documentation, NONE for projects not requiring |
|
78 # LUFA board drivers). If USER is selected, put custom board drivers in a directory called |
|
79 # "Board" inside the application directory. |
|
80 BOARD = USER |
|
81 |
|
82 |
|
83 # Processor frequency. |
|
84 # This will define a symbol, F_CPU, in all source code files equal to the |
|
85 # processor frequency in Hz. You can then use this symbol in your source code to |
|
86 # calculate timings. Do NOT tack on a 'UL' at the end, this will be done |
|
87 # automatically to create a 32-bit value in your source code. |
|
88 # |
|
89 # This will be an integer division of F_CLOCK below, as it is sourced by |
|
90 # F_CLOCK after it has run through any CPU prescalers. Note that this value |
|
91 # does not *change* the processor frequency - it should merely be updated to |
|
92 # reflect the processor speed set externally so that the code can use accurate |
|
93 # software delays. |
|
94 F_CPU = 16000000 |
|
95 |
|
96 |
|
97 # Input clock frequency. |
|
98 # This will define a symbol, F_CLOCK, in all source code files equal to the |
|
99 # input clock frequency (before any prescaling is performed) in Hz. This value may |
|
100 # differ from F_CPU if prescaling is used on the latter, and is required as the |
|
101 # raw input clock is fed directly to the PLL sections of the AVR for high speed |
|
102 # clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL' |
|
103 # at the end, this will be done automatically to create a 32-bit value in your |
|
104 # source code. |
|
105 # |
|
106 # If no clock division is performed on the input clock inside the AVR (via the |
|
107 # CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU. |
|
108 F_CLOCK = $(F_CPU) |
|
109 |
|
110 |
|
111 # Output format. (can be srec, ihex, binary) |
|
112 FORMAT = ihex |
|
113 |
|
114 |
|
115 # Target file name (without extension). |
|
116 TARGET = Arduino-usbserial |
|
117 |
|
118 |
|
119 # Object files directory |
|
120 # To put object files in current directory, use a dot (.), do NOT make |
|
121 # this an empty or blank macro! |
|
122 OBJDIR = . |
|
123 |
|
124 |
|
125 # Path to the LUFA library |
|
126 LUFA_PATH = ../.. |
|
127 |
|
128 |
|
129 # LUFA library compile-time options |
|
130 LUFA_OPTS = -D USB_DEVICE_ONLY |
|
131 LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=8 |
|
132 LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1 |
|
133 LUFA_OPTS += -D USE_FLASH_DESCRIPTORS |
|
134 LUFA_OPTS += -D INTERRUPT_CONTROL_ENDPOINT |
|
135 LUFA_OPTS += -D DEVICE_STATE_AS_GPIOR=0 |
|
136 LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" |
|
137 |
|
138 |
|
139 # Create the LUFA source path variables by including the LUFA root makefile |
|
140 include $(LUFA_PATH)/LUFA/makefile |
|
141 |
|
142 |
|
143 # List C source files here. (C dependencies are automatically generated.) |
|
144 SRC = $(TARGET).c \ |
|
145 Descriptors.c \ |
|
146 $(LUFA_SRC_USB) \ |
|
147 $(LUFA_SRC_USBCLASS) \ |
|
148 $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Device.c \ |
|
149 $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \ |
|
150 $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/HostStandardReq.c \ |
|
151 $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \ |
|
152 $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Pipe.c \ |
|
153 $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/USBController.c \ |
|
154 $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/Events.c \ |
|
155 $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/USBInterrupt.c \ |
|
156 $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c \ |
|
157 $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/DeviceStandardReq.c \ |
|
158 $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c \ |
|
159 $(LUFA_PATH)/LUFA/Drivers/USB/Class/Device/CDC.c \ |
|
160 $(LUFA_PATH)/LUFA/Drivers/USB/Class/Host/CDC.c |
|
161 |
|
162 |
|
163 # List C++ source files here. (C dependencies are automatically generated.) |
|
164 CPPSRC = |
|
165 |
|
166 |
|
167 # List Assembler source files here. |
|
168 # Make them always end in a capital .S. Files ending in a lowercase .s |
|
169 # will not be considered source files but generated files (assembler |
|
170 # output from the compiler), and will be deleted upon "make clean"! |
|
171 # Even though the DOS/Win* filesystem matches both .s and .S the same, |
|
172 # it will preserve the spelling of the filenames, and gcc itself does |
|
173 # care about how the name is spelled on its command-line. |
|
174 ASRC = |
|
175 |
|
176 |
|
177 # Optimization level, can be [0, 1, 2, 3, s]. |
|
178 # 0 = turn off optimization. s = optimize for size. |
|
179 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.) |
|
180 OPT = s |
|
181 |
|
182 |
|
183 # Debugging format. |
|
184 # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs. |
|
185 # AVR Studio 4.10 requires dwarf-2. |
|
186 # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run. |
|
187 DEBUG = dwarf-2 |
|
188 |
|
189 |
|
190 # List any extra directories to look for include files here. |
|
191 # Each directory must be seperated by a space. |
|
192 # Use forward slashes for directory separators. |
|
193 # For a directory that has spaces, enclose it in quotes. |
|
194 EXTRAINCDIRS = $(LUFA_PATH)/ |
|
195 |
|
196 |
|
197 # Compiler flag to set the C Standard level. |
|
198 # c89 = "ANSI" C |
|
199 # gnu89 = c89 plus GCC extensions |
|
200 # c99 = ISO C99 standard (not yet fully implemented) |
|
201 # gnu99 = c99 plus GCC extensions |
|
202 CSTANDARD = -std=gnu99 |
|
203 |
|
204 |
|
205 # Place -D or -U options here for C sources |
|
206 CDEFS = -DF_CPU=$(F_CPU)UL |
|
207 CDEFS += -DF_CLOCK=$(F_CLOCK)UL |
|
208 CDEFS += -DARDUINO_MODEL_PID=$(ARDUINO_MODEL_PID) |
|
209 CDEFS += -DBOARD=BOARD_$(BOARD) |
|
210 CDEFS += $(LUFA_OPTS) |
|
211 CDEFS += -DAVR_RESET_LINE_PORT="PORTD" |
|
212 CDEFS += -DAVR_RESET_LINE_DDR="DDRD" |
|
213 CDEFS += -DAVR_RESET_LINE_MASK="(1 << 7)" |
|
214 CDEFS += -DTX_RX_LED_PULSE_MS=3 |
|
215 CDEFS += -DPING_PONG_LED_PULSE_MS=100 |
|
216 |
|
217 # Place -D or -U options here for ASM sources |
|
218 ADEFS = -DF_CPU=$(F_CPU) |
|
219 ADEFS += -DF_CLOCK=$(F_CLOCK)UL |
|
220 ADEFS += -DBOARD=BOARD_$(BOARD) |
|
221 ADEFS += $(LUFA_OPTS) |
|
222 |
|
223 # Place -D or -U options here for C++ sources |
|
224 CPPDEFS = -DF_CPU=$(F_CPU)UL |
|
225 CPPDEFS += -DF_CLOCK=$(F_CLOCK)UL |
|
226 CPPDEFS += -DBOARD=BOARD_$(BOARD) |
|
227 CPPDEFS += $(LUFA_OPTS) |
|
228 #CPPDEFS += -D__STDC_LIMIT_MACROS |
|
229 #CPPDEFS += -D__STDC_CONSTANT_MACROS |
|
230 |
|
231 |
|
232 |
|
233 #---------------- Compiler Options C ---------------- |
|
234 # -g*: generate debugging information |
|
235 # -O*: optimization level |
|
236 # -f...: tuning, see GCC manual and avr-libc documentation |
|
237 # -Wall...: warning level |
|
238 # -Wa,...: tell GCC to pass this to the assembler. |
|
239 # -adhlns...: create assembler listing |
|
240 CFLAGS = -g$(DEBUG) |
|
241 CFLAGS += $(CDEFS) |
|
242 CFLAGS += -O$(OPT) |
|
243 CFLAGS += -funsigned-char |
|
244 CFLAGS += -funsigned-bitfields |
|
245 CFLAGS += -ffunction-sections |
|
246 CFLAGS += -fno-inline-small-functions |
|
247 CFLAGS += -fpack-struct |
|
248 CFLAGS += -fshort-enums |
|
249 CFLAGS += -fno-strict-aliasing |
|
250 CFLAGS += -Wall |
|
251 CFLAGS += -Wstrict-prototypes |
|
252 #CFLAGS += -mshort-calls |
|
253 #CFLAGS += -fno-unit-at-a-time |
|
254 #CFLAGS += -Wundef |
|
255 #CFLAGS += -Wunreachable-code |
|
256 #CFLAGS += -Wsign-compare |
|
257 CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst) |
|
258 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) |
|
259 CFLAGS += $(CSTANDARD) |
|
260 |
|
261 |
|
262 #---------------- Compiler Options C++ ---------------- |
|
263 # -g*: generate debugging information |
|
264 # -O*: optimization level |
|
265 # -f...: tuning, see GCC manual and avr-libc documentation |
|
266 # -Wall...: warning level |
|
267 # -Wa,...: tell GCC to pass this to the assembler. |
|
268 # -adhlns...: create assembler listing |
|
269 CPPFLAGS = -g$(DEBUG) |
|
270 CPPFLAGS += $(CPPDEFS) |
|
271 CPPFLAGS += -O$(OPT) |
|
272 CPPFLAGS += -funsigned-char |
|
273 CPPFLAGS += -funsigned-bitfields |
|
274 CPPFLAGS += -fpack-struct |
|
275 CPPFLAGS += -fshort-enums |
|
276 CPPFLAGS += -fno-exceptions |
|
277 CPPFLAGS += -Wall |
|
278 CPPFLAGS += -Wundef |
|
279 CFLAGS += -Wundef |
|
280 #CPPFLAGS += -mshort-calls |
|
281 #CPPFLAGS += -fno-unit-at-a-time |
|
282 #CPPFLAGS += -Wstrict-prototypes |
|
283 #CPPFLAGS += -Wunreachable-code |
|
284 #CPPFLAGS += -Wsign-compare |
|
285 CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst) |
|
286 CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) |
|
287 #CPPFLAGS += $(CSTANDARD) |
|
288 |
|
289 |
|
290 #---------------- Assembler Options ---------------- |
|
291 # -Wa,...: tell GCC to pass this to the assembler. |
|
292 # -adhlns: create listing |
|
293 # -gstabs: have the assembler create line number information; note that |
|
294 # for use in COFF files, additional information about filenames |
|
295 # and function names needs to be present in the assembler source |
|
296 # files -- see avr-libc docs [FIXME: not yet described there] |
|
297 # -listing-cont-lines: Sets the maximum number of continuation lines of hex |
|
298 # dump that will be displayed for a given single line of source input. |
|
299 ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100 |
|
300 |
|
301 |
|
302 #---------------- Library Options ---------------- |
|
303 # Minimalistic printf version |
|
304 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min |
|
305 |
|
306 # Floating point printf version (requires MATH_LIB = -lm below) |
|
307 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt |
|
308 |
|
309 # If this is left blank, then it will use the Standard printf version. |
|
310 PRINTF_LIB = |
|
311 #PRINTF_LIB = $(PRINTF_LIB_MIN) |
|
312 #PRINTF_LIB = $(PRINTF_LIB_FLOAT) |
|
313 |
|
314 |
|
315 # Minimalistic scanf version |
|
316 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min |
|
317 |
|
318 # Floating point + %[ scanf version (requires MATH_LIB = -lm below) |
|
319 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt |
|
320 |
|
321 # If this is left blank, then it will use the Standard scanf version. |
|
322 SCANF_LIB = |
|
323 #SCANF_LIB = $(SCANF_LIB_MIN) |
|
324 #SCANF_LIB = $(SCANF_LIB_FLOAT) |
|
325 |
|
326 |
|
327 MATH_LIB = -lm |
|
328 |
|
329 |
|
330 # List any extra directories to look for libraries here. |
|
331 # Each directory must be seperated by a space. |
|
332 # Use forward slashes for directory separators. |
|
333 # For a directory that has spaces, enclose it in quotes. |
|
334 EXTRALIBDIRS = |
|
335 |
|
336 |
|
337 |
|
338 #---------------- External Memory Options ---------------- |
|
339 |
|
340 # 64 KB of external RAM, starting after internal RAM (ATmega128!), |
|
341 # used for variables (.data/.bss) and heap (malloc()). |
|
342 #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff |
|
343 |
|
344 # 64 KB of external RAM, starting after internal RAM (ATmega128!), |
|
345 # only used for heap (malloc()). |
|
346 #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff |
|
347 |
|
348 EXTMEMOPTS = |
|
349 |
|
350 |
|
351 |
|
352 #---------------- Linker Options ---------------- |
|
353 # -Wl,...: tell GCC to pass this to linker. |
|
354 # -Map: create map file |
|
355 # --cref: add cross reference to map file |
|
356 LDFLAGS = -Wl,-Map=$(TARGET).map,--cref |
|
357 LDFLAGS += -Wl,--relax |
|
358 LDFLAGS += -Wl,--gc-sections |
|
359 LDFLAGS += $(EXTMEMOPTS) |
|
360 LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS)) |
|
361 LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) |
|
362 #LDFLAGS += -T linker_script.x |
|
363 |
|
364 |
|
365 |
|
366 #---------------- Programming Options (avrdude) ---------------- |
|
367 |
|
368 # Programming hardware |
|
369 # Type: avrdude -c ? |
|
370 # to get a full listing. |
|
371 # |
|
372 AVRDUDE_PROGRAMMER = avrispmkii |
|
373 |
|
374 # com1 = serial port. Use lpt1 to connect to parallel port. |
|
375 AVRDUDE_PORT = usb |
|
376 |
|
377 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex |
|
378 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep |
|
379 |
|
380 |
|
381 # Uncomment the following if you want avrdude's erase cycle counter. |
|
382 # Note that this counter needs to be initialized first using -Yn, |
|
383 # see avrdude manual. |
|
384 #AVRDUDE_ERASE_COUNTER = -y |
|
385 |
|
386 # Uncomment the following if you do /not/ wish a verification to be |
|
387 # performed after programming the device. |
|
388 #AVRDUDE_NO_VERIFY = -V |
|
389 |
|
390 # Increase verbosity level. Please use this when submitting bug |
|
391 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> |
|
392 # to submit bug reports. |
|
393 #AVRDUDE_VERBOSE = -v -v |
|
394 |
|
395 AVRDUDE_FORCE = -F |
|
396 |
|
397 AVRDUDE_FLAGS = -p $(MCU_AVRDUDE) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) |
|
398 AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY) |
|
399 AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE) |
|
400 AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER) |
|
401 AVRDUDE_FLAGS += $(AVRDUDE_FORCE) |
|
402 |
|
403 |
|
404 |
|
405 #---------------- Debugging Options ---------------- |
|
406 |
|
407 # For simulavr only - target MCU frequency. |
|
408 DEBUG_MFREQ = $(F_CPU) |
|
409 |
|
410 # Set the DEBUG_UI to either gdb or insight. |
|
411 # DEBUG_UI = gdb |
|
412 DEBUG_UI = insight |
|
413 |
|
414 # Set the debugging back-end to either avarice, simulavr. |
|
415 DEBUG_BACKEND = avarice |
|
416 #DEBUG_BACKEND = simulavr |
|
417 |
|
418 # GDB Init Filename. |
|
419 GDBINIT_FILE = __avr_gdbinit |
|
420 |
|
421 # When using avarice settings for the JTAG |
|
422 JTAG_DEV = /dev/com1 |
|
423 |
|
424 # Debugging port used to communicate between GDB / avarice / simulavr. |
|
425 DEBUG_PORT = 4242 |
|
426 |
|
427 # Debugging host used to communicate between GDB / avarice / simulavr, normally |
|
428 # just set to localhost unless doing some sort of crazy debugging when |
|
429 # avarice is running on a different computer. |
|
430 DEBUG_HOST = localhost |
|
431 |
|
432 |
|
433 |
|
434 #============================================================================ |
|
435 |
|
436 |
|
437 # Define programs and commands. |
|
438 SHELL = sh |
|
439 CC = avr-gcc |
|
440 OBJCOPY = avr-objcopy |
|
441 OBJDUMP = avr-objdump |
|
442 SIZE = avr-size |
|
443 AR = avr-ar rcs |
|
444 NM = avr-nm |
|
445 AVRDUDE = avrdude |
|
446 REMOVE = rm -f |
|
447 REMOVEDIR = rm -rf |
|
448 COPY = cp |
|
449 WINSHELL = cmd |
|
450 |
|
451 # Define Messages |
|
452 # English |
|
453 MSG_ERRORS_NONE = Errors: none |
|
454 MSG_BEGIN = -------- begin -------- |
|
455 MSG_END = -------- end -------- |
|
456 MSG_SIZE_BEFORE = Size before: |
|
457 MSG_SIZE_AFTER = Size after: |
|
458 MSG_COFF = Converting to AVR COFF: |
|
459 MSG_EXTENDED_COFF = Converting to AVR Extended COFF: |
|
460 MSG_FLASH = Creating load file for Flash: |
|
461 MSG_EEPROM = Creating load file for EEPROM: |
|
462 MSG_EXTENDED_LISTING = Creating Extended Listing: |
|
463 MSG_SYMBOL_TABLE = Creating Symbol Table: |
|
464 MSG_LINKING = Linking: |
|
465 MSG_COMPILING = Compiling C: |
|
466 MSG_COMPILING_CPP = Compiling C++: |
|
467 MSG_ASSEMBLING = Assembling: |
|
468 MSG_CLEANING = Cleaning project: |
|
469 MSG_CREATING_LIBRARY = Creating library: |
|
470 |
|
471 |
|
472 |
|
473 |
|
474 # Define all object files. |
|
475 OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o) |
|
476 |
|
477 # Define all listing files. |
|
478 LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst) |
|
479 |
|
480 |
|
481 # Compiler flags to generate dependency files. |
|
482 GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d |
|
483 |
|
484 |
|
485 # Combine all necessary flags and optional flags. |
|
486 # Add target processor to flags. |
|
487 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS) |
|
488 ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS) |
|
489 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) |
|
490 |
|
491 |
|
492 |
|
493 |
|
494 |
|
495 # Default target. |
|
496 #all: begin gccversion sizebefore build checkinvalidevents showliboptions showtarget sizeafter end |
|
497 all: begin gccversion sizebefore build showliboptions showtarget sizeafter end |
|
498 |
|
499 # Change the build target to build a HEX file or a library. |
|
500 build: elf hex eep lss sym asm |
|
501 #build: lib |
|
502 |
|
503 |
|
504 elf: $(TARGET).elf |
|
505 hex: $(TARGET).hex |
|
506 eep: $(TARGET).eep |
|
507 lss: $(TARGET).lss |
|
508 sym: $(TARGET).sym |
|
509 asm: $(TARGET).s |
|
510 LIBNAME=lib$(TARGET).a |
|
511 lib: $(LIBNAME) |
|
512 |
|
513 |
|
514 |
|
515 # Eye candy. |
|
516 # AVR Studio 3.x does not check make's exit code but relies on |
|
517 # the following magic strings to be generated by the compile job. |
|
518 begin: |
|
519 @echo |
|
520 @echo $(MSG_BEGIN) |
|
521 |
|
522 end: |
|
523 @echo $(MSG_END) |
|
524 @echo |
|
525 |
|
526 |
|
527 # Display size of file. |
|
528 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex |
|
529 ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf |
|
530 MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) ) |
|
531 FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr ) |
|
532 |
|
533 sizebefore: |
|
534 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \ |
|
535 2>/dev/null; echo; fi |
|
536 |
|
537 sizeafter: |
|
538 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \ |
|
539 2>/dev/null; echo; fi |
|
540 |
|
541 #$(LUFA_PATH)/LUFA/LUFA_Events.lst: |
|
542 # @make -C $(LUFA_PATH)/LUFA/ LUFA_Events.lst |
|
543 |
|
544 #checkinvalidevents: $(LUFA_PATH)/LUFA/LUFA_Events.lst |
|
545 # @echo |
|
546 # @echo Checking for invalid events... |
|
547 # @$(shell) avr-nm $(OBJ) | sed -n -e 's/^.*EVENT_/EVENT_/p' | \ |
|
548 # grep -F -v --file=$(LUFA_PATH)/LUFA/LUFA_Events.lst > InvalidEvents.tmp || true |
|
549 # @sed -n -e 's/^/ WARNING - INVALID EVENT NAME: /p' InvalidEvents.tmp |
|
550 # @if test -s InvalidEvents.tmp; then exit 1; fi |
|
551 |
|
552 showliboptions: |
|
553 @echo |
|
554 @echo ---- Compile Time Library Options ---- |
|
555 @for i in $(LUFA_OPTS:-D%=%); do \ |
|
556 echo $$i; \ |
|
557 done |
|
558 @echo -------------------------------------- |
|
559 |
|
560 showtarget: |
|
561 @echo |
|
562 @echo --------- Target Information --------- |
|
563 @echo AVR Model: $(MCU) |
|
564 @echo Board: $(BOARD) |
|
565 @echo Clock: $(F_CPU)Hz CPU, $(F_CLOCK)Hz Master |
|
566 @echo -------------------------------------- |
|
567 |
|
568 |
|
569 # Display compiler version information. |
|
570 gccversion : |
|
571 @$(CC) --version |
|
572 |
|
573 |
|
574 # Program the device. |
|
575 program: $(TARGET).hex $(TARGET).eep |
|
576 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) |
|
577 |
|
578 flip: $(TARGET).hex |
|
579 batchisp -hardware usb -device $(MCU_DFU) -operation erase f |
|
580 batchisp -hardware usb -device $(MCU_DFU) -operation loadbuffer $(TARGET).hex program |
|
581 batchisp -hardware usb -device $(MCU_DFU) -operation start reset 0 |
|
582 |
|
583 dfu: $(TARGET).hex |
|
584 dfu-programmer $(MCU_DFU) erase |
|
585 dfu-programmer $(MCU_DFU) flash --debug 1 $(TARGET).hex |
|
586 dfu-programmer $(MCU_DFU) reset |
|
587 |
|
588 |
|
589 flip-ee: $(TARGET).hex $(TARGET).eep |
|
590 $(COPY) $(TARGET).eep $(TARGET)eep.hex |
|
591 batchisp -hardware usb -device $(MCU_DFU) -operation memory EEPROM erase |
|
592 batchisp -hardware usb -device $(MCU_DFU) -operation memory EEPROM loadbuffer $(TARGET)eep.hex program |
|
593 batchisp -hardware usb -device $(MCU_DFU) -operation start reset 0 |
|
594 $(REMOVE) $(TARGET)eep.hex |
|
595 |
|
596 dfu-ee: $(TARGET).hex $(TARGET).eep |
|
597 dfu-programmer $(MCU_DFU) flash-eeprom --debug 1 --suppress-bootloader-mem $(TARGET).eep |
|
598 dfu-programmer $(MCU_DFU) reset |
|
599 |
|
600 |
|
601 # Generate avr-gdb config/init file which does the following: |
|
602 # define the reset signal, load the target file, connect to target, and set |
|
603 # a breakpoint at main(). |
|
604 gdb-config: |
|
605 @$(REMOVE) $(GDBINIT_FILE) |
|
606 @echo define reset >> $(GDBINIT_FILE) |
|
607 @echo SIGNAL SIGHUP >> $(GDBINIT_FILE) |
|
608 @echo end >> $(GDBINIT_FILE) |
|
609 @echo file $(TARGET).elf >> $(GDBINIT_FILE) |
|
610 @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE) |
|
611 ifeq ($(DEBUG_BACKEND),simulavr) |
|
612 @echo load >> $(GDBINIT_FILE) |
|
613 endif |
|
614 @echo break main >> $(GDBINIT_FILE) |
|
615 |
|
616 debug: gdb-config $(TARGET).elf |
|
617 ifeq ($(DEBUG_BACKEND), avarice) |
|
618 @echo Starting AVaRICE - Press enter when "waiting to connect" message displays. |
|
619 @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \ |
|
620 $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT) |
|
621 @$(WINSHELL) /c pause |
|
622 |
|
623 else |
|
624 @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \ |
|
625 $(DEBUG_MFREQ) --port $(DEBUG_PORT) |
|
626 endif |
|
627 @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE) |
|
628 |
|
629 |
|
630 |
|
631 |
|
632 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. |
|
633 COFFCONVERT = $(OBJCOPY) --debugging |
|
634 COFFCONVERT += --change-section-address .data-0x800000 |
|
635 COFFCONVERT += --change-section-address .bss-0x800000 |
|
636 COFFCONVERT += --change-section-address .noinit-0x800000 |
|
637 COFFCONVERT += --change-section-address .eeprom-0x810000 |
|
638 |
|
639 |
|
640 |
|
641 coff: $(TARGET).elf |
|
642 @echo |
|
643 @echo $(MSG_COFF) $(TARGET).cof |
|
644 $(COFFCONVERT) -O coff-avr $< $(TARGET).cof |
|
645 |
|
646 |
|
647 extcoff: $(TARGET).elf |
|
648 @echo |
|
649 @echo $(MSG_EXTENDED_COFF) $(TARGET).cof |
|
650 $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof |
|
651 |
|
652 |
|
653 |
|
654 # Create final output files (.hex, .eep) from ELF output file. |
|
655 %.hex: %.elf |
|
656 @echo |
|
657 @echo $(MSG_FLASH) $@ |
|
658 $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock $< $@ |
|
659 |
|
660 %.eep: %.elf |
|
661 @echo |
|
662 @echo $(MSG_EEPROM) $@ |
|
663 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ |
|
664 --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0 |
|
665 |
|
666 # Create extended listing file from ELF output file. |
|
667 %.lss: %.elf |
|
668 @echo |
|
669 @echo $(MSG_EXTENDED_LISTING) $@ |
|
670 $(OBJDUMP) -h -S -z $< > $@ |
|
671 |
|
672 # Create a symbol table from ELF output file. |
|
673 %.sym: %.elf |
|
674 @echo |
|
675 @echo $(MSG_SYMBOL_TABLE) $@ |
|
676 $(NM) -n $< > $@ |
|
677 |
|
678 |
|
679 |
|
680 # Create library from object files. |
|
681 .SECONDARY : $(TARGET).a |
|
682 .PRECIOUS : $(OBJ) |
|
683 %.a: $(OBJ) |
|
684 @echo |
|
685 @echo $(MSG_CREATING_LIBRARY) $@ |
|
686 $(AR) $@ $(OBJ) |
|
687 |
|
688 |
|
689 # Link: create ELF output file from object files. |
|
690 .SECONDARY : $(TARGET).elf |
|
691 .PRECIOUS : $(OBJ) |
|
692 %.elf: $(OBJ) |
|
693 @echo |
|
694 @echo $(MSG_LINKING) $@ |
|
695 $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS) |
|
696 |
|
697 |
|
698 # Compile: create object files from C source files. |
|
699 $(OBJDIR)/%.o : %.c |
|
700 @echo |
|
701 @echo $(MSG_COMPILING) $< |
|
702 $(CC) -c $(ALL_CFLAGS) $< -o $@ |
|
703 |
|
704 |
|
705 # Compile: create object files from C++ source files. |
|
706 $(OBJDIR)/%.o : %.cpp |
|
707 @echo |
|
708 @echo $(MSG_COMPILING_CPP) $< |
|
709 $(CC) -c $(ALL_CPPFLAGS) $< -o $@ |
|
710 |
|
711 |
|
712 # Compile: create assembler files from C source files. |
|
713 %.s : %.c |
|
714 $(CC) -S $(ALL_CFLAGS) $< -o $@ |
|
715 |
|
716 |
|
717 # Compile: create assembler files from C++ source files. |
|
718 %.s : %.cpp |
|
719 $(CC) -S $(ALL_CPPFLAGS) $< -o $@ |
|
720 |
|
721 |
|
722 # Assemble: create object files from assembler source files. |
|
723 $(OBJDIR)/%.o : %.S |
|
724 @echo |
|
725 @echo $(MSG_ASSEMBLING) $< |
|
726 $(CC) -c $(ALL_ASFLAGS) $< -o $@ |
|
727 |
|
728 |
|
729 # Create preprocessed source for use in sending a bug report. |
|
730 %.i : %.c |
|
731 $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@ |
|
732 |
|
733 |
|
734 # Target: clean project. |
|
735 clean: begin clean_list clean_binary end |
|
736 |
|
737 clean_binary: |
|
738 $(REMOVE) $(TARGET).hex |
|
739 |
|
740 clean_list: |
|
741 @echo $(MSG_CLEANING) |
|
742 $(REMOVE) $(TARGET).hex |
|
743 $(REMOVE) $(TARGET).eep |
|
744 $(REMOVE) $(TARGET).cof |
|
745 $(REMOVE) $(TARGET).elf |
|
746 $(REMOVE) $(TARGET).map |
|
747 $(REMOVE) $(TARGET).sym |
|
748 $(REMOVE) $(TARGET).lss |
|
749 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o) |
|
750 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst) |
|
751 $(REMOVE) $(SRC:.c=.s) |
|
752 $(REMOVE) $(SRC:.c=.d) |
|
753 $(REMOVE) $(SRC:.c=.i) |
|
754 $(REMOVEDIR) .dep |
|
755 |
|
756 doxygen: |
|
757 @echo Generating Project Documentation... |
|
758 @doxygen Doxygen.conf |
|
759 @echo Documentation Generation Complete. |
|
760 |
|
761 clean_doxygen: |
|
762 rm -rf Documentation |
|
763 |
|
764 # Create object files directory |
|
765 $(shell mkdir $(OBJDIR) 2>/dev/null) |
|
766 |
|
767 |
|
768 # Include the dependency files. |
|
769 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*) |
|
770 |
|
771 |
|
772 # Listing of phony targets. |
|
773 .PHONY : all begin finish end sizebefore sizeafter gccversion \ |
|
774 build elf hex eep lss sym coff extcoff doxygen clean \ |
|
775 clean_list clean_doxygen program dfu flip flip-ee dfu-ee \ |
|
776 debug gdb-config |