Advertisement
Guest User

makefile

a guest
Apr 24th, 2013
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.50 KB | None | 0 0
  1. # Hey Emacs, this is a -*- makefile -*-
  2. #
  3. # WinARM template makefile
  4. # by Martin Thomas, Kaiserslautern, Germany
  5. # <eversmith(at)heizung-thomas(dot)de>
  6. #
  7. # Released to the Public Domain
  8. # Please read the make user manual!
  9. #
  10. # The user-configuration is based on the WinAVR makefile-template
  11. # written by Eric B. Weddington, Jörg Wunsch, et al. but the internal
  12. # handling used here is very different.
  13. # This makefile can also be used with the GNU tools included in
  14. # Yagarto, GNUARM or the Codesourcery packages. It should work
  15. # on Unix/Linux-Systems too. Just a rather up-to-date GNU make is
  16. # needed.
  17. #
  18. #
  19. # On command line:
  20. #
  21. # make all = Make software.
  22. #
  23. # make clean = Clean out built project files.
  24. #
  25. # make program = Upload load-image to the device
  26. #
  27. # make filename.s = Just compile filename.c into the assembler code only
  28. #
  29. # make filename.o = Create object filename.o from filename.c (using CFLAGS)
  30. #
  31. # To rebuild project do "make clean" then "make all".
  32. #
  33. # Changes:
  34. # - 17. Feb. 2005 - added thumb-interwork support (mth)
  35. # - 28. Apr. 2005 - added C++ support (mth)
  36. # - 29. Arp. 2005 - changed handling for lst-Filename (mth)
  37. # - 1. Nov. 2005 - exception-vector placement options (mth)
  38. # - 15. Nov. 2005 - added library-search-path (EXTRA_LIB...) (mth)
  39. # - 2. Dec. 2005 - fixed ihex and binary file extensions (mth)
  40. # - 22. Feb. 2006 - added AT91LIBNOWARN setting (mth)
  41. # - 19. Apr. 2006 - option FLASH_TOOL (mth)
  42. # - 23. Jun. 2006 - option USE_THUMB_MODE -> THUMB/THUMB_IW
  43. # - 3. Aug. 2006 - added -ffunction-sections -fdata-sections to CFLAGS
  44. # and --gc-sections to LDFLAGS. Only available for gcc >=4 (mth)
  45. # (needs appropriate linker-script, remove them when using a
  46. # "simple" linker-script)
  47. # - 4. Aug. 2006 - pass SUBMDL-define to frontend (mth)
  48. # - 11. Nov. 2006 - FLASH_TOOL-config, TCHAIN-config (mth)
  49. # - 28. Mar. 2007 - remove .dep-Directory with rm -r -f and force "no error" (mth)
  50. # - 24. Apr. 2007 - added "both" option for format (.bin and .hex) (mth)
  51. # - 20. Aug. 2007 - extraincdirs in asflags, passing a "board"-define (mth)
  52. # - 13. Sep. 2007 - create assembler from c-sources fixed (make foo.s for foo.c) (mth)
  53. # - IMGEXT no longer used and removed (mth)
  54. # - moved some entries (mth)
  55. # - 25. Oct. 2007 - reverted 20070328-change (b/o "race condition" with
  56. # make clean all or when called from Eclipse) (mth)
  57. # - removed "for flash" from objdump message-string (mth)
  58. # - added same remarks (mth)
  59. # - 30. Oct. 2007 - Support for an output-directory with all files
  60. # created during "make all". (mth)
  61. # - modified targets which creates assembler (lower-case s)
  62. # from C-source using make <.c-file w/o ext.>.s (mth)
  63. # - removed redundant/unused defines, overall cleanup (mth)
  64. # - 10. Nov. 2007 - renamed TCHAIN to TCHAIN_PREFIX, other minor cleanup (mth)
  65. # - 13. Mar. 2008 - renamed FORMAT to LOADFORMAT, edited some comments/messages (mth)
  66. # - 13. Apr. 2009 - OpenOCD options for batch-programming (make program) (mth)
  67. # - 1. May 2009 - replaced SUBMDL with CHIP (mth)
  68. # - 15. Jul. 2009 - ComSpec environment-variable to select host-OS, should
  69. # increase compatibility (mth)
  70. # - 1. Sep. 2009 - rename ROM_RUN->FLASH_RUN, VECT_TAB_ROM->VECT_TAB_FLASH (mth)
  71. # - 11. Sep. 2009 - new target to create output directories. attempt for better
  72. # "Win32 only" support (without "Unix"-shell and -tools) (mth)
  73. # This is much faster on Win32 then MSYS/MinGW or Cygwin. (mth)
  74. # - 5. Dec. 2009 - automatic selection of gcc or g++ for linking. g++ used when C++
  75. # source-files are listed. -nostartfiles not used for C++ (mth)
  76. # - 16. May. 2010 - on Win32 use set instead of env to get environment, removed
  77. # flashing with uVision, added BOARD to CDEFS and ADEFS, phony
  78. # targets listed in one line, removed setting for output-format
  79. # and always create both (.hex and .bin), added debug-format gdb,
  80. # rename AT91LIBNOWARN to DISABLESPECIALWARNINGS, removed target
  81. # finished, remark on rm/cs-rm, other minor clean-ups, tested
  82. # with GNU make version 3.81 from CS and Cygwin (mth)
  83. # - 13. Jun. 2010 - Trigger build when non-source files have changed
  84. # (see BUILDONCHANGE). (mth)
  85.  
  86.  
  87. # Toolchain prefix (arm-elf- -> arm-elf-gcc.exe)
  88. TCHAIN_PREFIX = arm-none-eabi-
  89. #TCHAIN_PREFIX = arm-eabi-
  90. #TCHAIN_PREFIX = arm-elf-
  91. # cs-rm is a standard GNU rm which gets installed with CS G++ lite.
  92. # Just the filename is different. Use REMOVE_CMD=rm in environments
  93. # with rm (Linux, BSD, msys, Cygwin etc.)
  94. #REMOVE_CMD=rm
  95. REMOVE_CMD=cs-rm
  96.  
  97. # YES enables -mthumb option to flags for source-files listed
  98. # in SRC and CPPSRC and -mthumb-interwork option for all source
  99. USE_THUMB_MODE = YES
  100. #USE_THUMB_MODE = NO
  101.  
  102. # MCU name, submodel and board
  103. # - MCU used for compiler-option (-mcpu)
  104. # - SUBMDL used for linker-script name (-T) and passed as define
  105. # - BOARD just passed as define (don't used '-' characters)
  106. MCU = cortex-m3
  107. CHIP = STM32F10x_128k_20k
  108. #BOARD = EK_STM32F
  109. #BOARD = MINI_STM32
  110. BOARD = STM32_P103
  111. F_XTAL = 8000000
  112. SYSCLOCK_CL = SYSCLK_FREQ_72MHz=72000000
  113.  
  114. # *** This example only supports "FLASH_RUN" ***
  115. # RUN_MODE is passed as define and used for the linker-script filename,
  116. # the user has to implement the necessary operations for
  117. # the used mode (i.e. no copy of .data, remapping...)
  118. # Create FLASH-Image
  119. RUN_MODE=FLASH_RUN
  120. # Create RAM-Image
  121. #RUN_MODE=RAM_RUN
  122.  
  123. # Exception-vectors placement option is just passed as define,
  124. # the user has to implement the necessary operations (i.e. remapping)
  125. # Exception vectors in FLASH:
  126. VECTOR_TABLE_LOCATION=VECT_TAB_FLASH
  127. # Exception vectors in RAM:
  128. #VECTOR_TABLE_LOCATION=VECT_TAB_RAM
  129.  
  130. # Directory for output files (lst, obj, dep, elf, sym, map, hex, bin etc.)
  131. OUTDIR = $(RUN_MODE)
  132.  
  133. # Target file name (without extension).
  134. TARGET = main
  135.  
  136. # Utility variables
  137. APPLIBDIR = ./Libraries
  138. STMLIBDIR = $(APPLIBDIR)
  139. STMSPDDIR = $(STMLIBDIR)/STM32F10x_StdPeriph_Driver
  140. STMSPDSRCDIR = $(STMSPDDIR)/src
  141. STMSPDINCDIR = $(STMSPDDIR)/inc
  142. CMSISCOREDIR = $(STMLIBDIR)/CMSIS/CM3/CoreSupport
  143. CMSISDEVDIR = $(STMLIBDIR)/CMSIS/CM3/DeviceSupport/ST/STM32F10x
  144. FATFSDIR = $(APPLIBDIR)/fat_sd
  145. FATFSDIR_DEV = $(APPLIBDIR)/fat_sd_dev
  146. MININIDIR = $(APPLIBDIR)/minIni
  147. STMEEEMULDIR = $(APPLIBDIR)/EEPROMEmulation_AN
  148. STMEEEMULSRCDIR = $(STMEEEMULDIR)/source
  149. STMEEEMULINCDIR = $(STMEEEMULDIR)/include
  150.  
  151. # List C source files here. (C dependencies are automatically generated.)
  152. # use file-extension c for "c-only"-files
  153. ## Demo-Application:
  154. SRC = main.c rtc.c comm.c term_io.c ff_test_term.c misc_test_term.c
  155. ## Chan's fat and my low-level drivers
  156. SRC += $(FATFSDIR)/ff.c $(FATFSDIR)/option/ccsbcs.c
  157. #SRC += $(FATFSDIR_DEV)/ff.c $(FATFSDIR_DEV)/option/ccsbcs.c
  158. SRC += $(FATFSDIR)/fattime.c $(FATFSDIR)/sd_spi_stm32.c
  159. ## compiler- and libc-specific sources
  160. SRC += startup_stm32f10x_md_mthomas.c
  161. SRC += syscalls.c
  162. SRC += dcc_stdio.c
  163. ## ITB CompuPhase's minIni
  164. SRC += $(MININIDIR)/minIni.c
  165. ## CMSIS for STM32
  166. SRC += $(CMSISCOREDIR)/core_cm3.c
  167. SRC += $(CMSISDEVDIR)/system_stm32f10x.c
  168. ## used parts of the STM-Library
  169. SRC += $(STMSPDSRCDIR)/stm32f10x_usart.c
  170. SRC += $(STMSPDSRCDIR)/stm32f10x_flash.c
  171. SRC += $(STMSPDSRCDIR)/stm32f10x_gpio.c
  172. SRC += $(STMSPDSRCDIR)/stm32f10x_rcc.c
  173. SRC += $(STMSPDSRCDIR)/stm32f10x_spi.c
  174. SRC += $(STMSPDSRCDIR)/stm32f10x_rtc.c
  175. SRC += $(STMSPDSRCDIR)/stm32f10x_bkp.c
  176. SRC += $(STMSPDSRCDIR)/stm32f10x_pwr.c
  177. SRC += $(STMSPDSRCDIR)/stm32f10x_dma.c
  178. SRC += $(STMSPDSRCDIR)/stm32f10x_tim.c
  179. SRC += $(STMSPDSRCDIR)/misc.c
  180. ## EEprom Emulation AppNote Code
  181. SRC += $(STMEEEMULSRCDIR)/eeprom.c
  182.  
  183.  
  184. # List C source files here which must be compiled in ARM-Mode (no -mthumb).
  185. # use file-extension c for "c-only"-files
  186. ## just for testing, timer.c could be compiled in thumb-mode too
  187. SRCARM =
  188.  
  189. # List C++ source files here.
  190. # use file-extension .cpp for C++-files (not .C)
  191. CPPSRC =
  192.  
  193. # List C++ source files here which must be compiled in ARM-Mode.
  194. # use file-extension .cpp for C++-files (not .C)
  195. #CPPSRCARM = $(TARGET).cpp
  196. CPPSRCARM =
  197.  
  198. # List Assembler source files here.
  199. # Make them always end in a capital .S. Files ending in a lowercase .s
  200. # will not be considered source files but generated files (assembler
  201. # output from the compiler), and will be deleted upon "make clean"!
  202. # Even though the DOS/Win* filesystem matches both .s and .S the same,
  203. # it will preserve the spelling of the filenames, and gcc itself does
  204. # care about how the name is spelled on its command-line.
  205. ASRC =
  206.  
  207. # List Assembler source files here which must be assembled in ARM-Mode.
  208. ASRCARM =
  209.  
  210. # Place project-specific -D (define) and/or -U options for C here.
  211. CDEFS = -DSTM32F10X_MD
  212. CDEFS += -DHSE_VALUE=$(F_XTAL)UL
  213. CDEFS += -D$(SYSCLOCK_CL)
  214. CDEFS += -DUSE_STDPERIPH_DRIVER
  215. CDEFS += -DUSE_$(BOARD)
  216. CDEFS += -DSTM32_SD_USE_DMA
  217. CDEFS += -DSTARTUP_DELAY
  218. # enable modifications in STM's libraries
  219. CDEFS += -DMOD_MTHOMAS_STMLIB
  220. # enables parameter-checking in STM's library
  221. CDEFS += -DUSE_FULL_ASSERT
  222.  
  223. # Place project-specific -D and/or -U options for
  224. # Assembler with preprocessor here.
  225. ADEFS =
  226.  
  227. # List any extra directories to look for include files here.
  228. # Each directory must be seperated by a space.
  229. EXTRAINCDIRS = $(STMSPDINCDIR) $(CMSISDEVDIR) $(CMSISCOREDIR)
  230. #EXTRAINCDIRS += $(FATFSDIR_DEV)
  231. EXTRAINCDIRS += $(FATFSDIR)
  232. EXTRAINCDIRS += $(MININIDIR) $(STMEEEMULINCDIR)
  233.  
  234. # Extra libraries
  235. # Each library-name must be seperated by a space.
  236. # i.e. to link with libxyz.a, libabc.a and libefsl.a:
  237. # EXTRA_LIBS = xyz abc efsl
  238. # for newlib-lpc (file: libnewlibc-lpc.a):
  239. # EXTRA_LIBS = newlib-lpc
  240. EXTRA_LIBS =
  241.  
  242. # List non-source files which should trigger build here
  243. # Typically the Makefile and selected header-files
  244. # Entries must be seperated by a space.
  245. BUILDONCHANGE = Makefile platform_config.h
  246.  
  247. # Path to linker-scripts (see -T option)
  248. LINKERSCRIPTPATH = .
  249.  
  250. # List any directories with files included from linker-scripts.
  251. # Each directory must be seperated by a space.
  252. LINKERSCRIPTINC = .
  253.  
  254. # List any extra directories to look for library files here.
  255. # Each directory must be seperated by a space.
  256. EXTRA_LIBDIRS =
  257.  
  258. # Optimization level, can be [0, 1, 2, 3, s].
  259. # 0 = Turn off optimization. Reduce compilation time and make debugging
  260. # produce the expected results.
  261. # 1 = The compiler tries to reduce code size and execution time, without
  262. # performing any optimizations that take a great deal of compilation time.
  263. # 2 = GCC performs nearly all supported optimizations that do not involve a
  264. # space-speed tradeoff. As compared to -O1, this option increases
  265. # both compilation time and the performance of the generated code.
  266. # 3 = Optimize yet more. Turns on -finline-functions and more.
  267. # s = -Os enables all -O2 optimizations that do not typically increase code
  268. # size.
  269. # (See gcc manual for further information)
  270. #OPT = s
  271. #OPT = 2
  272. #OPT = 3
  273. OPT = 0
  274.  
  275. # Debugging format.
  276. #DEBUG = stabs
  277. #DEBUG = dwarf-2
  278. DEBUG = gdb
  279.  
  280. # Compiler flag to set the C Standard level.
  281. # c89 - "ANSI" C
  282. # gnu89 - c89 plus GCC extensions
  283. # c99 - ISO C99 standard (not yet fully implemented)
  284. # gnu99 - c99 plus GCC extensions
  285. CSTANDARD = -std=gnu99
  286.  
  287. # Flash programming tool
  288. FLASH_TOOL = OPENOCD
  289. #FLASH_TOOL = LPC21ISP
  290.  
  291. # Some warnings can be disabled by this setting
  292. # (useful for the old single-file AT91-lib)
  293. # yes - disable some warnings
  294. # no - keep default settings
  295. #DISABLESPECIALWARNINGS = yes
  296. DISABLESPECIALWARNINGS = no
  297.  
  298.  
  299. # ---------------------------------------------------------------------------
  300. # Options for lpc21isp by Martin Maurer
  301. # lpc21isp only supports NXP LPC and Analog ADuC ARMs though the
  302. # integrated uart-bootloader (ISP)
  303. #
  304. # Settings and variables:
  305. LPC21ISP = lpc21isp
  306. LPC21ISP_FLASHFILE = $(OUTDIR)/$(TARGET).hex
  307. LPC21ISP_PORT = com1
  308. LPC21ISP_BAUD = 57600
  309. LPC21ISP_XTAL = 12000
  310. # other options:
  311. # -debug: verbose output
  312. # -control: enter bootloader via RS232 DTR/RTS (only if hardware
  313. # supports this feature - see NXP AppNote)
  314. LPC21ISP_OPTIONS = -control
  315. #LPC21ISP_OPTIONS += -debug
  316. # ---------------------------------------------------------------------------
  317.  
  318. # ---------------------------------------------------------------------------
  319. # Options for OpenOCD flash-programming
  320. # see openocd.pdf/openocd.texi for further information
  321. #
  322. OOCD_LOADFILE+=$(OUTDIR)/$(TARGET).elf
  323. # if OpenOCD is in the $PATH just set OPENOCDEXE=openocd
  324. OOCD_EXE=./OpenOCD/bin/openocd
  325. # debug level
  326. OOCD_CL=-d0
  327. #OOCD_CL=-d3
  328. # interface and board/target settings (using the OOCD target-library here)
  329. ##OOCD_CL+=-f interface/jtagkey.cfg
  330. OOCD_CL+=-f interface/jtagkey2.cfg
  331. OOCD_CL+=-f target/stm32.cfg
  332. # initialize
  333. OOCD_CL+=-c init
  334. # enable "fast mode" - can be disabled for tests
  335. OOCD_CL+=-c "fast enable"
  336. # show the targets
  337. OOCD_CL+=-c targets
  338. # commands to prepare flash-write
  339. OOCD_CL+= -c "reset halt"
  340. # increase JTAG frequency a little bit - can be disabled for tests
  341. OOCD_CL+= -c "jtag_khz 1200"
  342. # disable polling (optional)
  343. OOCD_CL+= -c "poll off"
  344. # flash-write and -verify
  345. OOCD_CL+=-c "flash write_image erase $(OOCD_LOADFILE)" -c "verify_image $(OOCD_LOADFILE)"
  346. # reset target
  347. OOCD_CL+=-c "reset run"
  348. # terminate OOCD after programming
  349. OOCD_CL+=-c shutdown
  350. # ---------------------------------------------------------------------------
  351.  
  352.  
  353. ifdef VECTOR_TABLE_LOCATION
  354. CDEFS += -D$(VECTOR_TABLE_LOCATION)
  355. ADEFS += -D$(VECTOR_TABLE_LOCATION)
  356. endif
  357.  
  358. CDEFS += -D$(RUN_MODE) -D$(CHIP) -D$(BOARD)
  359. ADEFS += -D$(RUN_MODE) -D$(CHIP) -D$(BOARD)
  360.  
  361.  
  362. # Compiler flags.
  363.  
  364. ifeq ($(USE_THUMB_MODE),YES)
  365. THUMB = -mthumb
  366. THUMB_IW = -mthumb-interwork
  367. else
  368. THUMB =
  369. THUMB_IW =
  370. endif
  371.  
  372. # -g*: generate debugging information
  373. # -O*: optimization level
  374. # -f...: tuning, see GCC manual
  375. # -Wall...: warning level
  376. # -Wa,...: tell GCC to pass this to the assembler.
  377. # -adhlns...: create assembler listing
  378. #
  379. # Flags for C and C++ (arm-elf-gcc/arm-elf-g++)
  380. CFLAGS = -g$(DEBUG)
  381. CFLAGS += -O$(OPT)
  382. CFLAGS += -mcpu=$(MCU) $(THUMB_IW)
  383. CFLAGS += $(CDEFS)
  384. CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) -I.
  385. # when using ".ramfunc"s without attribute longcall:
  386. #CFLAGS += -mlong-calls
  387. # -mapcs-frame is important if gcc's interrupt attributes are used
  388. # (at least from my eabi tests), not needed if assembler-wrappers are used
  389. #CFLAGS += -mapcs-frame
  390. #CFLAGS += -fomit-frame-pointer
  391. CFLAGS += -ffunction-sections -fdata-sections
  392. CFLAGS += -Wall -Wextra
  393. CFLAGS += -pedantic
  394. CFLAGS += -Wimplicit -Wcast-align -Wpointer-arith
  395. CFLAGS += -Wredundant-decls -Wshadow -Wcast-qual -Wcast-align
  396. CFLAGS += -Wa,-adhlns=$(addprefix $(OUTDIR)/, $(notdir $(addsuffix .lst, $(basename $<))))
  397. # Compiler flags to generate dependency files:
  398. #CFLAGS += -MD -MP -MF $(OUTDIR)/dep/$(@F).d
  399. CFLAGS += -MMD -MP -MF $(OUTDIR)/dep/$(@F).d
  400. ##testing##CFLAGS += -MF"$@" -MG -MM -MP -MT"$@" -MT"$(<:.c=.o)"
  401. #CFLAGS += -fno-dwarf2-cfi-asm
  402. #CFLAGS += -fno-strict-aliasing -Wno-nested-externs
  403.  
  404. # flags only for C
  405. CONLYFLAGS += -Wnested-externs
  406. CONLYFLAGS += $(CSTANDARD)
  407.  
  408. ifeq ($(DISABLESPECIALWARNINGS),yes)
  409. CFLAGS += -Wno-cast-qual
  410. CONLYFLAGS += -Wno-missing-prototypes
  411. CONLYFLAGS += -Wno-strict-prototypes
  412. CONLYFLAGS += -Wno-missing-declarations
  413. endif
  414.  
  415. # flags only for C++ (arm-*-g++)
  416. CPPFLAGS = -fno-rtti -fno-exceptions
  417.  
  418. # Assembler flags.
  419. # -Wa,...: tell GCC to pass this to the assembler.
  420. # -ahlns: create listing
  421. # -g$(DEBUG): have the assembler create line number information
  422. ASFLAGS = -mcpu=$(MCU) $(THUMB_IW) -I. -x assembler-with-cpp
  423. ASFLAGS += -D__ASSEMBLY__ $(ADEFS)
  424. ASFLAGS += -Wa,-adhlns=$(addprefix $(OUTDIR)/, $(notdir $(addsuffix .lst, $(basename $<))))
  425. ASFLAGS += -Wa,-g$(DEBUG)
  426. ASFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  427.  
  428. # Link with the GNU C++ stdlib.
  429. CPLUSPLUS_LIB = -lstdc++
  430. #CPLUSPLUS_LIB += -lsupc++
  431.  
  432. # Linker flags.
  433. # -Wl,...: tell GCC to pass this to linker.
  434. # -Map: create map file
  435. # --cref: add cross reference to map file
  436. LDFLAGS = -Wl,-Map=$(OUTDIR)/$(TARGET).map,--cref,--gc-sections
  437. LDFLAGS += -lc -lm -lc -lgcc
  438. LDFLAGS += $(CPLUSPLUS_LIB)
  439. LDFLAGS += $(patsubst %,-L%,$(EXTRA_LIBDIRS))
  440. LDFLAGS += $(patsubst %,-L%,$(LINKERSCRIPTINC))
  441. LDFLAGS += $(patsubst %,-l%,$(EXTRA_LIBS))
  442.  
  443. # Set linker-script name depending on selected run-mode and chip
  444. ifeq ($(RUN_MODE),RAM_RUN)
  445. LDFLAGS +=-T$(LINKERSCRIPTPATH)/$(CHIP)_ram.ld
  446. else
  447. LDFLAGS +=-T$(LINKERSCRIPTPATH)/$(CHIP)_flash.ld
  448. endif
  449.  
  450. # Autodetect environment
  451. SHELL = sh
  452. ifneq ($(or $(COMSPEC), $(ComSpec)),)
  453. $(info COMSPEC detected $(COMSPEC) $(ComSpec))
  454. ifeq ($(findstring cygdrive,$(shell set)),)
  455. SHELL:=$(or $(COMSPEC),$(ComSpec))
  456. SHELL_IS_WIN32=1
  457. else
  458. $(info cygwin detected)
  459. #override user-setting since cygwin has rm
  460. REMOVE_CMD:=rm
  461. endif
  462. else
  463. #most probaly a Unix/Linux/BSD system which should have rm
  464. REMOVE_CMD:=rm
  465. endif
  466. $(info SHELL is $(SHELL), REMOVE_CMD is $(REMOVE_CMD))
  467.  
  468. # Define programs and commands.
  469. CC = $(TCHAIN_PREFIX)gcc
  470. CPP = $(TCHAIN_PREFIX)g++
  471. AR = $(TCHAIN_PREFIX)ar
  472. OBJCOPY = $(TCHAIN_PREFIX)objcopy
  473. OBJDUMP = $(TCHAIN_PREFIX)objdump
  474. SIZE = $(TCHAIN_PREFIX)size
  475. NM = $(TCHAIN_PREFIX)nm
  476. REMOVE = $(REMOVE_CMD) -f
  477.  
  478. # Define Messages
  479. # English
  480. MSG_BEGIN = -------- begin, mode: $(RUN_MODE) --------
  481. MSG_END = -------- end --------
  482. MSG_SIZE_BEFORE = Size before:
  483. MSG_SIZE_AFTER = Size after build:
  484. MSG_LOAD_FILE = Creating load file:
  485. MSG_EXTENDED_LISTING = Creating Extended Listing/Disassembly:
  486. MSG_SYMBOL_TABLE = Creating Symbol Table:
  487. MSG_LINKING = ---- Linking:
  488. MSG_COMPILING = ---- Compiling C:
  489. MSG_COMPILING_ARM = ---- Compiling C ARM-only:
  490. MSG_COMPILINGCPP = ---- Compiling C++:
  491. MSG_COMPILINGCPP_ARM = ---- Compiling C++ ARM-only:
  492. MSG_ASSEMBLING = ---- Assembling:
  493. MSG_ASSEMBLING_ARM = ---- Assembling ARM-only:
  494. MSG_CLEANING = Cleaning project:
  495. MSG_LPC21_RESETREMINDER = You may have to bring the target in bootloader-mode now.
  496. MSG_ASMFROMC = "Creating asm-File from C-Source:"
  497. MSG_ASMFROMC_ARM = "Creating asm-File from C-Source (ARM-only):"
  498.  
  499. # List of all source files.
  500. ALLSRC = $(ASRCARM) $(ASRC) $(SRCARM) $(SRC) $(CPPSRCARM) $(CPPSRC)
  501. # List of all source files without directory and file-extension.
  502. ALLSRCBASE = $(notdir $(basename $(ALLSRC)))
  503.  
  504. # Define all object files.
  505. ALLOBJ = $(addprefix $(OUTDIR)/, $(addsuffix .o, $(ALLSRCBASE)))
  506.  
  507. # Define all listing files (used for make clean).
  508. LSTFILES = $(addprefix $(OUTDIR)/, $(addsuffix .lst, $(ALLSRCBASE)))
  509. # Define all depedency-files (used for make clean).
  510. DEPFILES = $(addprefix $(OUTDIR)/dep/, $(addsuffix .o.d, $(ALLSRCBASE)))
  511.  
  512. elf: $(OUTDIR)/$(TARGET).elf
  513. lss: $(OUTDIR)/$(TARGET).lss
  514. sym: $(OUTDIR)/$(TARGET).sym
  515. hex: $(OUTDIR)/$(TARGET).hex
  516. bin: $(OUTDIR)/$(TARGET).bin
  517.  
  518. # Default target.
  519. all: begin createdirs gccversion build sizeafter end
  520.  
  521. # Target for the build-sequence.
  522. build: elf lss sym hex bin
  523.  
  524. # Create output directories.
  525. ifdef SHELL_IS_WIN32
  526. createdirs:
  527. -@md $(OUTDIR) >NUL 2>&1 || echo "" >NUL
  528. -@md $(OUTDIR)\dep >NUL 2>&1 || echo "" >NUL
  529. else
  530. createdirs:
  531. -@mkdir $(OUTDIR) 2>/dev/null || echo "" >/dev/null
  532. -@mkdir $(OUTDIR)/dep 2>/dev/null || echo "" >/dev/null
  533. endif
  534.  
  535. # Eye candy.
  536. begin:
  537. @echo $(MSG_BEGIN)
  538.  
  539. end:
  540. @echo $(MSG_END)
  541.  
  542. # Display sizes of sections.
  543. ELFSIZE = $(SIZE) -A $(OUTDIR)/$(TARGET).elf
  544. sizebefore:
  545. # @if [ -f $(OUTDIR)/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
  546.  
  547. sizeafter:
  548. # @if [ -f $(OUTDIR)/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
  549. @echo $(MSG_SIZE_AFTER)
  550. $(ELFSIZE)
  551.  
  552. # Display compiler version information.
  553. gccversion :
  554. @$(CC) --version
  555.  
  556. # Program the device.
  557. ifeq ($(FLASH_TOOL),OPENOCD)
  558. # Program the device with Dominic Rath's OPENOCD in "batch-mode"
  559. program: $(OUTDIR)/$(TARGET).elf
  560. @echo "Programming with OPENOCD"
  561. ifdef SHELL_IS_WIN32
  562. $(subst /,\,$(OOCD_EXE)) $(OOCD_CL)
  563. else
  564. $(OOCD_EXE) $(OOCD_CL)
  565. endif
  566. else
  567. # Program the device using lpc21isp (for NXP2k and ADuC UART bootloader)
  568. program: $(OUTDIR)/$(TARGET).hex
  569. @echo $(MSG_LPC21_RESETREMINDER)
  570. -$(LPC21ISP) $(LPC21ISP_OPTIONS) $(LPC21ISP_FLASHFILE) $(LPC21ISP_PORT) $(LPC21ISP_BAUD) $(LPC21ISP_XTAL)
  571. endif
  572.  
  573. # Create final output file in ihex format from ELF output file (.hex).
  574. %.hex: %.elf
  575. @echo $(MSG_LOAD_FILE) $@
  576. $(OBJCOPY) -O ihex $< $@
  577.  
  578. # Create final output file in raw binary format from ELF output file (.bin)
  579. %.bin: %.elf
  580. @echo $(MSG_LOAD_FILE) $@
  581. $(OBJCOPY) -O binary $< $@
  582.  
  583. # Create extended listing file/disassambly from ELF output file.
  584. # using objdump (testing: option -C)
  585. %.lss: %.elf
  586. @echo $(MSG_EXTENDED_LISTING) $@
  587. $(OBJDUMP) -h -S -C -r $< > $@
  588.  
  589. # Create a symbol table from ELF output file.
  590. %.sym: %.elf
  591. @echo $(MSG_SYMBOL_TABLE) $@
  592. $(NM) -n $< > $@
  593.  
  594. # Link: create ELF output file from object files.
  595. .SECONDARY : $(TARGET).elf
  596. .PRECIOUS : $(ALLOBJ)
  597. %.elf: $(ALLOBJ) $(BUILDONCHANGE)
  598. @echo $(MSG_LINKING) $@
  599. # use $(CC) for C-only projects or $(CPP) for C++-projects:
  600. ifeq "$(strip $(CPPSRC)$(CPPARM))" ""
  601. $(CC) $(THUMB) $(CFLAGS) $(ALLOBJ) --output $@ -nostartfiles $(LDFLAGS)
  602. else
  603. $(CPP) $(THUMB) $(CFLAGS) $(ALLOBJ) --output $@ $(LDFLAGS)
  604. endif
  605.  
  606.  
  607. # Assemble: create object files from assembler source files.
  608. define ASSEMBLE_TEMPLATE
  609. $(OUTDIR)/$(notdir $(basename $(1))).o : $(1) $(BUILDONCHANGE)
  610. @echo "hallo"
  611. @echo $(MSG_ASSEMBLING) $$< to $$@
  612. $(CC) -c $(THUMB) $$(ASFLAGS) $$< -o $$@
  613. endef
  614. $(foreach src, $(ASRC), $(eval $(call ASSEMBLE_TEMPLATE, $(src))))
  615.  
  616. # Assemble: create object files from assembler source files. ARM-only
  617. define ASSEMBLE_ARM_TEMPLATE
  618. $(OUTDIR)/$(notdir $(basename $(1))).o : $(1) $(BUILDONCHANGE)
  619. @echo $(MSG_ASSEMBLING_ARM) $$< to $$@
  620. $(CC) -c $$(ASFLAGS) $$< -o $$@
  621. endef
  622. $(foreach src, $(ASRCARM), $(eval $(call ASSEMBLE_ARM_TEMPLATE, $(src))))
  623.  
  624.  
  625. # Compile: create object files from C source files.
  626. define COMPILE_C_TEMPLATE
  627. $(OUTDIR)/$(notdir $(basename $(1))).o : $(1) $(BUILDONCHANGE)
  628. @echo $(MSG_COMPILING) $$< to $$@
  629. $(CC) -c $(THUMB) $$(CFLAGS) $$(CONLYFLAGS) $$< -o $$@
  630. endef
  631. $(foreach src, $(SRC), $(eval $(call COMPILE_C_TEMPLATE, $(src))))
  632.  
  633. # Compile: create object files from C source files. ARM-only
  634. define COMPILE_C_ARM_TEMPLATE
  635. $(OUTDIR)/$(notdir $(basename $(1))).o : $(1) $(BUILDONCHANGE)
  636. @echo $(MSG_COMPILING_ARM) $$< to $$@
  637. $(CC) -c $$(CFLAGS) $$(CONLYFLAGS) $$< -o $$@
  638. endef
  639. $(foreach src, $(SRCARM), $(eval $(call COMPILE_C_ARM_TEMPLATE, $(src))))
  640.  
  641.  
  642. # Compile: create object files from C++ source files.
  643. define COMPILE_CPP_TEMPLATE
  644. $(OUTDIR)/$(notdir $(basename $(1))).o : $(1) $(BUILDONCHANGE)
  645. @echo $(MSG_COMPILINGCPP) $$< to $$@
  646. $(CC) -c $(THUMB) $$(CFLAGS) $$(CPPFLAGS) $$< -o $$@
  647. endef
  648. $(foreach src, $(CPPSRC), $(eval $(call COMPILE_CPP_TEMPLATE, $(src))))
  649.  
  650. # Compile: create object files from C++ source files. ARM-only
  651. define COMPILE_CPP_ARM_TEMPLATE
  652. $(OUTDIR)/$(notdir $(basename $(1))).o : $(1) $(BUILDONCHANGE)
  653. @echo $(MSG_COMPILINGCPP_ARM) $$< to $$@
  654. $(CC) -c $$(CFLAGS) $$(CPPFLAGS) $$< -o $$@
  655. endef
  656. $(foreach src, $(CPPSRCARM), $(eval $(call COMPILE_CPP_ARM_TEMPLATE, $(src))))
  657.  
  658.  
  659. # Compile: create assembler files from C source files. ARM/Thumb
  660. $(SRC:.c=.s) : %.s : %.c $(BUILDONCHANGE)
  661. @echo $(MSG_ASMFROMC) $< to $@
  662. $(CC) $(THUMB) -S $(CFLAGS) $(CONLYFLAGS) $< -o $@
  663.  
  664. # Compile: create assembler files from C source files. ARM only
  665. $(SRCARM:.c=.s) : %.s : %.c $(BUILDONCHANGE)
  666. @echo $(MSG_ASMFROMC_ARM) $< to $@
  667. $(CC) -S $(CFLAGS) $(CONLYFLAGS) $< -o $@
  668.  
  669. # Target: clean project.
  670. clean: begin clean_list end
  671.  
  672. clean_list :
  673. @echo $(MSG_CLEANING)
  674. $(REMOVE) $(OUTDIR)/$(TARGET).map
  675. $(REMOVE) $(OUTDIR)/$(TARGET).elf
  676. $(REMOVE) $(OUTDIR)/$(TARGET).hex
  677. $(REMOVE) $(OUTDIR)/$(TARGET).bin
  678. $(REMOVE) $(OUTDIR)/$(TARGET).sym
  679. $(REMOVE) $(OUTDIR)/$(TARGET).lss
  680. $(REMOVE) $(ALLOBJ)
  681. $(REMOVE) $(LSTFILES)
  682. $(REMOVE) $(DEPFILES)
  683. $(REMOVE) $(SRC:.c=.s)
  684. $(REMOVE) $(SRCARM:.c=.s)
  685. $(REMOVE) $(CPPSRC:.cpp=.s)
  686. $(REMOVE) $(CPPSRCARM:.cpp=.s)
  687.  
  688. # Include the dependency files.
  689. ##-include $(wildcard dep/*)
  690. -include $(wildcard *.d)
  691.  
  692. # Listing of phony targets.
  693. .PHONY : all begin end sizebefore sizeafter gccversion build elf hex bin lss sym clean clean_list program createdirs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement