Makefile 19 KB

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