Makefile 18 KB

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