Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Makefile.common 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. # Hey Emacs, this is a -*- makefile -*-
  2. #----------------------------------------------------------------------------
  3. # WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al.
  4. #
  5. # Released to the Public Domain
  6. #
  7. # Additional material for this makefile was written by:
  8. # Peter Fleury
  9. # Tim Henigan
  10. # Colin O'Flynn
  11. # Reiner Patommel
  12. # Markus Pfaff
  13. # Sander Pool
  14. # Frederik Rouleau
  15. # Carlos Lamas
  16. #
  17. #----------------------------------------------------------------------------
  18. # On command line:
  19. #
  20. # make all = Make software.
  21. #
  22. # make clean = Clean out built project files.
  23. #
  24. # make coff = Convert ELF to AVR COFF.
  25. #
  26. # make extcoff = Convert ELF to AVR Extended COFF.
  27. #
  28. # make program = Download the hex file to the device, using avrdude.
  29. # Please customize the avrdude settings below first!
  30. #
  31. # make debug = Start either simulavr or avarice as specified for debugging,
  32. # with avr-gdb or avr-insight as the front end for debugging.
  33. #
  34. # make filename.s = Just compile filename.c into the assembler code only.
  35. #
  36. # make filename.i = Create a preprocessed source file for use in submitting
  37. # bug reports to the GCC project.
  38. #
  39. # To rebuild project do "make clean" then "make all".
  40. #----------------------------------------------------------------------------
  41. # Following variables need to be set in <target>/Makefile:
  42. # TARGET
  43. # COMMON_DIR
  44. # TARGET_DIR
  45. # TARGET_SRC
  46. # MCU
  47. # F_CPU
  48. # List C source files here. (C dependencies are automatically generated.)
  49. SRC = tmk.c \
  50. layer.c \
  51. key_process.c \
  52. usb_keyboard.c \
  53. usb_debug.c \
  54. usb.c \
  55. jump_bootloader.c \
  56. print.c \
  57. timer.c \
  58. util.c
  59. SRC += $(TARGET_SRC)
  60. # Option modules
  61. ifdef $(or MOUSEKEY_ENABLE, PS2_MOUSE_ENABLE)
  62. SRC += usb_mouse.c
  63. endif
  64. ifdef MOUSEKEY_ENABLE
  65. SRC += mousekey.c
  66. endif
  67. ifdef PS2_MOUSE_ENABLE
  68. SRC += ps2.c \
  69. ps2_mouse.c
  70. endif
  71. ifdef USB_EXTRA_ENABLE
  72. SRC += usb_extra.c
  73. endif
  74. ALL_SRC = $(SRC)
  75. ALL_SRC += usb_mouse.c \
  76. mousekey.c \
  77. ps2.c \
  78. ps2_mouse.c \
  79. usb_extra.c
  80. # C source file search path
  81. VPATH = $(TARGET_DIR):$(COMMON_DIR)
  82. # Output format. (can be srec, ihex, binary)
  83. FORMAT = ihex
  84. # Object files directory
  85. # To put object files in current directory, use a dot (.), do NOT make
  86. # this an empty or blank macro!
  87. OBJDIR = .
  88. # List C++ source files here. (C dependencies are automatically generated.)
  89. CPPSRC =
  90. # List Assembler source files here.
  91. # Make them always end in a capital .S. Files ending in a lowercase .s
  92. # will not be considered source files but generated files (assembler
  93. # output from the compiler), and will be deleted upon "make clean"!
  94. # Even though the DOS/Win* filesystem matches both .s and .S the same,
  95. # it will preserve the spelling of the filenames, and gcc itself does
  96. # care about how the name is spelled on its command-line.
  97. ASRC =
  98. # Optimization level, can be [0, 1, 2, 3, s].
  99. # 0 = turn off optimization. s = optimize for size.
  100. # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
  101. OPT = s
  102. # Debugging format.
  103. # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
  104. # AVR Studio 4.10 requires dwarf-2.
  105. # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
  106. DEBUG = dwarf-2
  107. # List any extra directories to look for include files here.
  108. # Each directory must be seperated by a space.
  109. # Use forward slashes for directory separators.
  110. # For a directory that has spaces, enclose it in quotes.
  111. EXTRAINCDIRS = $(TARGET_DIR) $(COMMON_DIR)
  112. # Compiler flag to set the C Standard level.
  113. # c89 = "ANSI" C
  114. # gnu89 = c89 plus GCC extensions
  115. # c99 = ISO C99 standard (not yet fully implemented)
  116. # gnu99 = c99 plus GCC extensions
  117. CSTANDARD = -std=gnu99
  118. OPT_DEFS =
  119. ifdef MOUSEKEY_ENABLE
  120. OPT_DEFS += -DMOUSEKEY_ENABLE
  121. endif
  122. ifdef PS2_MOUSE_ENABLE
  123. OPT_DEFS += -DPS2_MOUSE_ENABLE
  124. endif
  125. ifdef USB_EXTRA_ENABLE
  126. OPT_DEFS += -DUSB_EXTRA_ENABLE
  127. endif
  128. ifdef USB_NKRO_ENABLE
  129. OPT_DEFS += -DUSB_NKRO_ENABLE
  130. endif
  131. ifdef $(or MOUSEKEY_ENABLE, PS2_MOUSE_ENABLE)
  132. OPT_DEFS += -DUSB_MOUSE_ENABLE
  133. endif
  134. # Place -D or -U options here for C sources
  135. CDEFS = -DF_CPU=$(F_CPU)UL
  136. CDEFS += $(OPT_DEFS)
  137. # Place -D or -U options here for ASM sources
  138. ADEFS = -DF_CPU=$(F_CPU)
  139. ADEFS += $(OPT_DEFS)
  140. # Place -D or -U options here for C++ sources
  141. CPPDEFS = -DF_CPU=$(F_CPU)UL
  142. #CPPDEFS += -D__STDC_LIMIT_MACROS
  143. #CPPDEFS += -D__STDC_CONSTANT_MACROS
  144. CPPDEFS += $(OPT_DEFS)
  145. #---------------- Compiler Options C ----------------
  146. # -g*: generate debugging information
  147. # -O*: optimization level
  148. # -f...: tuning, see GCC manual and avr-libc documentation
  149. # -Wall...: warning level
  150. # -Wa,...: tell GCC to pass this to the assembler.
  151. # -adhlns...: create assembler listing
  152. CFLAGS = -g$(DEBUG)
  153. CFLAGS += $(CDEFS)
  154. CFLAGS += -O$(OPT)
  155. CFLAGS += -funsigned-char
  156. CFLAGS += -funsigned-bitfields
  157. CFLAGS += -ffunction-sections
  158. CFLAGS += -fpack-struct
  159. CFLAGS += -fshort-enums
  160. CFLAGS += -Wall
  161. CFLAGS += -Wstrict-prototypes
  162. #CFLAGS += -mshort-calls
  163. #CFLAGS += -fno-unit-at-a-time
  164. #CFLAGS += -Wundef
  165. #CFLAGS += -Wunreachable-code
  166. #CFLAGS += -Wsign-compare
  167. CFLAGS += -Wa,-adhlns=$(@:%.o=$(OBJDIR)/%.lst)
  168. CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  169. CFLAGS += $(CSTANDARD)
  170. CFLAGS += -include config.h
  171. #---------------- Compiler Options C++ ----------------
  172. # -g*: generate debugging information
  173. # -O*: optimization level
  174. # -f...: tuning, see GCC manual and avr-libc documentation
  175. # -Wall...: warning level
  176. # -Wa,...: tell GCC to pass this to the assembler.
  177. # -adhlns...: create assembler listing
  178. CPPFLAGS = -g$(DEBUG)
  179. CPPFLAGS += $(CPPDEFS)
  180. CPPFLAGS += -O$(OPT)
  181. CPPFLAGS += -funsigned-char
  182. CPPFLAGS += -funsigned-bitfields
  183. CPPFLAGS += -fpack-struct
  184. CPPFLAGS += -fshort-enums
  185. CPPFLAGS += -fno-exceptions
  186. CPPFLAGS += -Wall
  187. CPPFLAGS += -Wundef
  188. #CPPFLAGS += -mshort-calls
  189. #CPPFLAGS += -fno-unit-at-a-time
  190. #CPPFLAGS += -Wstrict-prototypes
  191. #CPPFLAGS += -Wunreachable-code
  192. #CPPFLAGS += -Wsign-compare
  193. CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
  194. CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  195. #CPPFLAGS += $(CSTANDARD)
  196. CPPFLAGS += -include config.h
  197. #---------------- Assembler Options ----------------
  198. # -Wa,...: tell GCC to pass this to the assembler.
  199. # -adhlns: create listing
  200. # -gstabs: have the assembler create line number information; note that
  201. # for use in COFF files, additional information about filenames
  202. # and function names needs to be present in the assembler source
  203. # files -- see avr-libc docs [FIXME: not yet described there]
  204. # -listing-cont-lines: Sets the maximum number of continuation lines of hex
  205. # dump that will be displayed for a given single line of source input.
  206. ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
  207. ASFLAGS += -include config.h
  208. #---------------- Library Options ----------------
  209. # Minimalistic printf version
  210. PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
  211. # Floating point printf version (requires MATH_LIB = -lm below)
  212. PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
  213. # If this is left blank, then it will use the Standard printf version.
  214. PRINTF_LIB =
  215. #PRINTF_LIB = $(PRINTF_LIB_MIN)
  216. #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
  217. # Minimalistic scanf version
  218. SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
  219. # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
  220. SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
  221. # If this is left blank, then it will use the Standard scanf version.
  222. SCANF_LIB =
  223. #SCANF_LIB = $(SCANF_LIB_MIN)
  224. #SCANF_LIB = $(SCANF_LIB_FLOAT)
  225. MATH_LIB = -lm
  226. # List any extra directories to look for libraries here.
  227. # Each directory must be seperated by a space.
  228. # Use forward slashes for directory separators.
  229. # For a directory that has spaces, enclose it in quotes.
  230. EXTRALIBDIRS =
  231. #---------------- External Memory Options ----------------
  232. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  233. # used for variables (.data/.bss) and heap (malloc()).
  234. #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
  235. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  236. # only used for heap (malloc()).
  237. #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
  238. EXTMEMOPTS =
  239. #---------------- Linker Options ----------------
  240. # -Wl,...: tell GCC to pass this to linker.
  241. # -Map: create map file
  242. # --cref: add cross reference to map file
  243. #
  244. # Comennt out "--relax" option to avoid a error such:
  245. # (.vectors+0x30): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_12'
  246. #
  247. LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
  248. LDFLAGS += -Wl,--relax
  249. LDFLAGS += -Wl,--gc-sections
  250. LDFLAGS += $(EXTMEMOPTS)
  251. LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
  252. LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
  253. #LDFLAGS += -T linker_script.x
  254. #---------------- Programming Options (avrdude) ----------------
  255. # Programming hardware
  256. # Type: avrdude -c ?
  257. # to get a full listing.
  258. #
  259. AVRDUDE_PROGRAMMER = stk500v2
  260. # com1 = serial port. Use lpt1 to connect to parallel port.
  261. AVRDUDE_PORT = com1 # programmer connected to serial device
  262. AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
  263. #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
  264. # Uncomment the following if you want avrdude's erase cycle counter.
  265. # Note that this counter needs to be initialized first using -Yn,
  266. # see avrdude manual.
  267. #AVRDUDE_ERASE_COUNTER = -y
  268. # Uncomment the following if you do /not/ wish a verification to be
  269. # performed after programming the device.
  270. #AVRDUDE_NO_VERIFY = -V
  271. # Increase verbosity level. Please use this when submitting bug
  272. # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
  273. # to submit bug reports.
  274. #AVRDUDE_VERBOSE = -v -v
  275. AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
  276. AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
  277. AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
  278. AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
  279. #---------------- Debugging Options ----------------
  280. # For simulavr only - target MCU frequency.
  281. DEBUG_MFREQ = $(F_CPU)
  282. # Set the DEBUG_UI to either gdb or insight.
  283. # DEBUG_UI = gdb
  284. DEBUG_UI = insight
  285. # Set the debugging back-end to either avarice, simulavr.
  286. DEBUG_BACKEND = avarice
  287. #DEBUG_BACKEND = simulavr
  288. # GDB Init Filename.
  289. GDBINIT_FILE = __avr_gdbinit
  290. # When using avarice settings for the JTAG
  291. JTAG_DEV = /dev/com1
  292. # Debugging port used to communicate between GDB / avarice / simulavr.
  293. DEBUG_PORT = 4242
  294. # Debugging host used to communicate between GDB / avarice / simulavr, normally
  295. # just set to localhost unless doing some sort of crazy debugging when
  296. # avarice is running on a different computer.
  297. DEBUG_HOST = localhost
  298. #============================================================================
  299. # Define programs and commands.
  300. SHELL = sh
  301. CC = avr-gcc
  302. OBJCOPY = avr-objcopy
  303. OBJDUMP = avr-objdump
  304. SIZE = avr-size
  305. AR = avr-ar rcs
  306. NM = avr-nm
  307. AVRDUDE = avrdude
  308. REMOVE = rm -f
  309. REMOVEDIR = rm -rf
  310. COPY = cp
  311. WINSHELL = cmd
  312. # Define Messages
  313. # English
  314. MSG_ERRORS_NONE = Errors: none
  315. MSG_BEGIN = -------- begin --------
  316. MSG_END = -------- end --------
  317. MSG_SIZE_BEFORE = Size before:
  318. MSG_SIZE_AFTER = Size after:
  319. MSG_COFF = Converting to AVR COFF:
  320. MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
  321. MSG_FLASH = Creating load file for Flash:
  322. MSG_EEPROM = Creating load file for EEPROM:
  323. MSG_EXTENDED_LISTING = Creating Extended Listing:
  324. MSG_SYMBOL_TABLE = Creating Symbol Table:
  325. MSG_LINKING = Linking:
  326. MSG_COMPILING = Compiling C:
  327. MSG_COMPILING_CPP = Compiling C++:
  328. MSG_ASSEMBLING = Assembling:
  329. MSG_CLEANING = Cleaning project:
  330. MSG_CREATING_LIBRARY = Creating library:
  331. # Define all object files.
  332. OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
  333. # Define all listing files.
  334. LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
  335. # Compiler flags to generate dependency files.
  336. GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
  337. # Combine all necessary flags and optional flags.
  338. # Add target processor to flags.
  339. ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
  340. ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
  341. ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
  342. # Default target.
  343. all: begin gccversion sizebefore build sizeafter end
  344. depend: tmk.c
  345. @echo $<
  346. @echo $(<F)
  347. # $(CC) -E $(ALL_CFLAGS) $<
  348. # Change the build target to build a HEX file or a library.
  349. build: elf hex eep lss sym
  350. #build: lib
  351. elf: $(TARGET).elf
  352. hex: $(TARGET).hex
  353. eep: $(TARGET).eep
  354. lss: $(TARGET).lss
  355. sym: $(TARGET).sym
  356. LIBNAME=lib$(TARGET).a
  357. lib: $(LIBNAME)
  358. # Eye candy.
  359. # AVR Studio 3.x does not check make's exit code but relies on
  360. # the following magic strings to be generated by the compile job.
  361. begin:
  362. @echo
  363. @echo $(MSG_BEGIN)
  364. end:
  365. @echo $(MSG_END)
  366. @echo
  367. # Display size of file.
  368. HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
  369. #ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
  370. ELFSIZE = $(SIZE) $(TARGET).elf
  371. sizebefore:
  372. @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
  373. 2>/dev/null; echo; fi
  374. sizeafter:
  375. @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
  376. 2>/dev/null; echo; fi
  377. # Display compiler version information.
  378. gccversion :
  379. @$(CC) --version
  380. # Program the device.
  381. program: $(TARGET).hex $(TARGET).eep
  382. $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
  383. # Generate avr-gdb config/init file which does the following:
  384. # define the reset signal, load the target file, connect to target, and set
  385. # a breakpoint at main().
  386. gdb-config:
  387. @$(REMOVE) $(GDBINIT_FILE)
  388. @echo define reset >> $(GDBINIT_FILE)
  389. @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
  390. @echo end >> $(GDBINIT_FILE)
  391. @echo file $(TARGET).elf >> $(GDBINIT_FILE)
  392. @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
  393. ifeq ($(DEBUG_BACKEND),simulavr)
  394. @echo load >> $(GDBINIT_FILE)
  395. endif
  396. @echo break main >> $(GDBINIT_FILE)
  397. debug: gdb-config $(TARGET).elf
  398. ifeq ($(DEBUG_BACKEND), avarice)
  399. @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
  400. @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
  401. $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
  402. @$(WINSHELL) /c pause
  403. else
  404. @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
  405. $(DEBUG_MFREQ) --port $(DEBUG_PORT)
  406. endif
  407. @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
  408. # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
  409. COFFCONVERT = $(OBJCOPY) --debugging
  410. COFFCONVERT += --change-section-address .data-0x800000
  411. COFFCONVERT += --change-section-address .bss-0x800000
  412. COFFCONVERT += --change-section-address .noinit-0x800000
  413. COFFCONVERT += --change-section-address .eeprom-0x810000
  414. coff: $(TARGET).elf
  415. @echo
  416. @echo $(MSG_COFF) $(TARGET).cof
  417. $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
  418. extcoff: $(TARGET).elf
  419. @echo
  420. @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
  421. $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
  422. # Create final output files (.hex, .eep) from ELF output file.
  423. %.hex: %.elf
  424. @echo
  425. @echo $(MSG_FLASH) $@
  426. $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@
  427. %.eep: %.elf
  428. @echo
  429. @echo $(MSG_EEPROM) $@
  430. -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
  431. --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0
  432. # Create extended listing file from ELF output file.
  433. %.lss: %.elf
  434. @echo
  435. @echo $(MSG_EXTENDED_LISTING) $@
  436. $(OBJDUMP) -h -S -z $< > $@
  437. # Create a symbol table from ELF output file.
  438. %.sym: %.elf
  439. @echo
  440. @echo $(MSG_SYMBOL_TABLE) $@
  441. $(NM) -n $< > $@
  442. # Create library from object files.
  443. .SECONDARY : $(TARGET).a
  444. .PRECIOUS : $(OBJ)
  445. %.a: $(OBJ)
  446. @echo
  447. @echo $(MSG_CREATING_LIBRARY) $@
  448. $(AR) $@ $(OBJ)
  449. # Link: create ELF output file from object files.
  450. .SECONDARY : $(TARGET).elf
  451. .PRECIOUS : $(OBJ)
  452. %.elf: $(OBJ)
  453. @echo
  454. @echo $(MSG_LINKING) $@
  455. $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
  456. # Compile: create object files from C source files.
  457. $(OBJDIR)/%.o : %.c
  458. @echo
  459. @echo $(MSG_COMPILING) $<
  460. $(CC) -c $(ALL_CFLAGS) $< -o $@
  461. # Compile: create object files from C++ source files.
  462. $(OBJDIR)/%.o : %.cpp
  463. @echo
  464. @echo $(MSG_COMPILING_CPP) $<
  465. $(CC) -c $(ALL_CPPFLAGS) $< -o $@
  466. # Compile: create assembler files from C source files.
  467. %.s : %.c
  468. $(CC) -S $(ALL_CFLAGS) $< -o $@
  469. # Compile: create assembler files from C++ source files.
  470. %.s : %.cpp
  471. $(CC) -S $(ALL_CPPFLAGS) $< -o $@
  472. # Assemble: create object files from assembler source files.
  473. $(OBJDIR)/%.o : %.S
  474. @echo
  475. @echo $(MSG_ASSEMBLING) $<
  476. $(CC) -c $(ALL_ASFLAGS) $< -o $@
  477. # Create preprocessed source for use in sending a bug report.
  478. %.i : %.c
  479. $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
  480. # Target: clean project.
  481. clean: begin clean_list end
  482. clean_list :
  483. @echo
  484. @echo $(MSG_CLEANING)
  485. $(REMOVE) $(TARGET).hex
  486. $(REMOVE) $(TARGET).eep
  487. $(REMOVE) $(TARGET).cof
  488. $(REMOVE) $(TARGET).elf
  489. $(REMOVE) $(TARGET).map
  490. $(REMOVE) $(TARGET).sym
  491. $(REMOVE) $(TARGET).lss
  492. $(REMOVE) $(ALL_SRC:%.c=$(OBJDIR)/%.o)
  493. $(REMOVE) $(ALL_SRC:%.c=$(OBJDIR)/%.lst)
  494. $(REMOVE) $(ALL_SRC:.c=.s)
  495. $(REMOVE) $(ALL_SRC:.c=.d)
  496. $(REMOVE) $(ALL_SRC:.c=.i)
  497. $(REMOVEDIR) .dep
  498. # Create object files directory
  499. $(shell mkdir $(OBJDIR) 2>/dev/null)
  500. # Include the dependency files.
  501. -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
  502. # Listing of phony targets.
  503. .PHONY : all begin finish end sizebefore sizeafter gccversion \
  504. build elf hex eep lss sym coff extcoff \
  505. clean clean_list program debug gdb-config