Makefile 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082
  1. #------------------------------------------------------------------------------
  2. # VARIABLES APPENDED TO BY INCLUDED MAKEFILE FRAGMENTS
  3. #------------------------------------------------------------------------------
  4. # List of include directories for -I compiler option (-I added when used).
  5. # Includes the BSP.
  6. ALT_INCLUDE_DIRS :=
  7. # List of library directories for -L linker option (-L added when used).
  8. # Includes the BSP.
  9. ALT_LIBRARY_DIRS :=
  10. # List of library names for -l linker option (-l added when used).
  11. # Includes the BSP.
  12. ALT_LIBRARY_NAMES :=
  13. # List of library names for -msys-lib linker option (-msys-lib added when used).
  14. # These are libraries that might be located in the BSP and depend on the BSP
  15. # library, or vice versa
  16. ALT_BSP_DEP_LIBRARY_NAMES :=
  17. # List of dependencies for the linker. This is usually the full pathname
  18. # of each library (*.a) file.
  19. # Includes the BSP.
  20. ALT_LDDEPS :=
  21. # List of root library directories that support running make to build them.
  22. # Includes the BSP and any ALT libraries.
  23. MAKEABLE_LIBRARY_ROOT_DIRS :=
  24. # Generic flags passed to the compiler for different types of input files.
  25. ALT_CFLAGS :=
  26. ALT_CXXFLAGS :=
  27. ALT_CPPFLAGS :=
  28. ALT_ASFLAGS :=
  29. ALT_LDFLAGS :=
  30. #------------------------------------------------------------------------------
  31. # The adjust-path macro
  32. #
  33. # If COMSPEC/ComSpec is defined, Make is launched from Windows through
  34. # Cygwin. The adjust-path macro converts absolute windows paths into
  35. # unix style paths (Example: c:/dir -> /c/dir). This will ensture
  36. # paths are readable by GNU Make.
  37. #
  38. # If COMSPEC/ComSpec is not defined, Make is launched from linux, and no
  39. # adjustment is necessary
  40. #
  41. #------------------------------------------------------------------------------
  42. ifndef COMSPEC
  43. ifdef ComSpec
  44. COMSPEC = $(ComSpec)
  45. endif # ComSpec
  46. endif # COMSPEC
  47. ifdef COMSPEC # if Windows OS
  48. ifeq ($(MAKE_VERSION),3.81)
  49. #
  50. # adjust-path/adjust-path-mixed for Mingw Gnu Make on Windows
  51. #
  52. # Example Usage:
  53. # $(call adjust-path,c:/aaa/bbb) => /c/aaa/bbb
  54. # $(call adjust-path-mixed,/c/aaa/bbb) => c:/aaa/bbb
  55. # $(call adjust-path-mixed,/cygdrive/c/aaa/bbb) => c:/aaa/bbb
  56. #
  57. #
  58. # adjust-path
  59. # - converts back slash characters into forward slashes
  60. # - if input arg ($1) is an empty string then return the empty string
  61. # - if input arg ($1) does not contain the string ":/", then return input arg
  62. # - using sed, convert mixed path [c:/...] into mingw path [/c/...]
  63. define adjust-path
  64. $(strip \
  65. $(if $1,\
  66. $(if $(findstring :/,$(subst \,/,$1)),\
  67. $(shell echo $(subst \,/,$1) | sed -e 's,^\([a-zA-Z]\):/,/\1/,'),\
  68. $(subst \,/,$1))))
  69. endef
  70. #
  71. # adjust-path-mixed
  72. # - converts back slash characters into forward slashes
  73. # - if input arg ($1) is an empty string then return the empty string
  74. # - if input arg ($1) does not begin with a forward slash '/' char, then
  75. # return input arg
  76. # - using sed, convert mingw path [/c/...] or cygwin path [/c/cygdrive/...]
  77. # into a mixed path [c:/...]
  78. define adjust-path-mixed
  79. $(strip \
  80. $(if $1,\
  81. $(if $(findstring $(subst \,/,$1),$(patsubst /%,%,$(subst \,/,$1))),\
  82. $(subst \,/,$1),\
  83. $(shell echo $(subst \,/,$1) | sed -e 's,^/cygdrive/\([a-zA-Z]\)/,\1:/,' -e 's,^/\([a-zA-Z]\)/,\1:/,'))))
  84. endef
  85. else # MAKE_VERSION != 3.81 (MAKE_VERSION == 3.80 or MAKE_VERSION == 3.79)
  86. #
  87. # adjust-path for Cygwin Gnu Make
  88. # $(call adjust-path,c:/aaa/bbb) = /cygdrive/c/aaa/bbb
  89. # $(call adjust-path-mixed,/cygdrive/c/aaa/bbb) = c:/aaa/bbb
  90. #
  91. adjust-path = $(if $1,$(shell cygpath -u "$1"),)
  92. adjust-path-mixed = $(if $1,$(shell cygpath -m "$1"),)
  93. endif
  94. else # !COMSPEC
  95. adjust-path = $1
  96. adjust-path-mixed = $1
  97. endif # COMSPEC
  98. #vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  99. # GENERATED SETTINGS START v
  100. #vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  101. #START GENERATED
  102. ACTIVE_BUILD_CONFIG := default
  103. BUILD_CONFIGS := default
  104. # The following TYPE comment allows tools to identify the 'type' of target this
  105. # makefile is associated with.
  106. # TYPE: APP_MAKEFILE
  107. # This following VERSION comment indicates the version of the tool used to
  108. # generate this makefile. A makefile variable is provided for VERSION as well.
  109. # ACDS_VERSION: 18.1
  110. ACDS_VERSION := 18.1
  111. # This following BUILD_NUMBER comment indicates the build number of the tool
  112. # used to generate this makefile.
  113. # BUILD_NUMBER: 646
  114. # Define path to the application ELF.
  115. # It may be used by the makefile fragments so is defined before including them.
  116. #
  117. ELF := hello_world.elf
  118. # Paths to C, C++, and assembly source files.
  119. C_SRCS := hello_world.c
  120. CXX_SRCS :=
  121. ASM_SRCS :=
  122. # Path to root of object file tree.
  123. OBJ_ROOT_DIR := obj
  124. # Options to control objdump.
  125. CREATE_OBJDUMP := 1
  126. OBJDUMP_INCLUDE_SOURCE := 1
  127. OBJDUMP_FULL_CONTENTS := 0
  128. # Options to enable/disable optional files.
  129. CREATE_ELF_DERIVED_FILES := 0
  130. CREATE_LINKER_MAP := 1
  131. # Common arguments for ALT_CFLAGSs
  132. APP_CFLAGS_DEFINED_SYMBOLS :=
  133. APP_CFLAGS_UNDEFINED_SYMBOLS :=
  134. APP_CFLAGS_OPTIMIZATION := -O0
  135. APP_CFLAGS_DEBUG_LEVEL := -g
  136. APP_CFLAGS_WARNINGS := -Wall
  137. APP_CFLAGS_USER_FLAGS :=
  138. APP_ASFLAGS_USER :=
  139. APP_LDFLAGS_USER :=
  140. # Linker options that have default values assigned later if not
  141. # assigned here.
  142. LINKER_SCRIPT :=
  143. CRT0 :=
  144. SYS_LIB :=
  145. # Define path to the root of the BSP.
  146. BSP_ROOT_DIR := ../hello_world_bsp/
  147. # List of application specific include directories, library directories and library names
  148. APP_INCLUDE_DIRS :=
  149. APP_LIBRARY_DIRS :=
  150. APP_LIBRARY_NAMES :=
  151. # Pre- and post- processor settings.
  152. BUILD_PRE_PROCESS :=
  153. BUILD_POST_PROCESS :=
  154. QUARTUS_PROJECT_DIR := ../../
  155. #END GENERATED
  156. #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  157. # GENERATED SETTINGS END ^
  158. #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  159. #------------------------------------------------------------------------------
  160. # DEFAULT TARGET
  161. #------------------------------------------------------------------------------
  162. # Define the variable used to echo output if not already defined.
  163. ifeq ($(ECHO),)
  164. ECHO := echo
  165. endif
  166. # Put "all" rule before included makefile fragments because they may
  167. # define rules and we don't want one of those to become the default rule.
  168. .PHONY : all
  169. all:
  170. @$(ECHO) [$(APP_NAME) build complete]
  171. all : build_pre_process libs app build_post_process
  172. #------------------------------------------------------------------------------
  173. # VARIABLES DEPENDENT ON GENERATED CONTENT
  174. #------------------------------------------------------------------------------
  175. # Define object file directory per build configuration
  176. CONFIG_OBJ_DIR := $(OBJ_ROOT_DIR)/$(ACTIVE_BUILD_CONFIG)
  177. ifeq ($(BSP_ROOT_DIR),)
  178. $(error Edit Makefile and provide a value for BSP_ROOT_DIR)
  179. endif
  180. ifeq ($(wildcard $(BSP_ROOT_DIR)),)
  181. $(error BSP directory does not exist: $(BSP_ROOT_DIR))
  182. endif
  183. # Define absolute path to the root of the BSP.
  184. ABS_BSP_ROOT_DIR := $(call adjust-path-mixed,$(shell cd "$(BSP_ROOT_DIR)"; pwd))
  185. # Include makefile fragments. Define variable ALT_LIBRARY_ROOT_DIR before
  186. # including each makefile fragment so that it knows the path to itself.
  187. BSP_INCLUDE_FILE := $(BSP_ROOT_DIR)/public.mk
  188. ALT_LIBRARY_ROOT_DIR := $(BSP_ROOT_DIR)
  189. include $(BSP_INCLUDE_FILE)
  190. # C2H will need this to touch the BSP public.mk and avoid the sopc file
  191. # out-of-date error during a BSP make
  192. ABS_BSP_INCLUDE_FILE := $(ABS_BSP_ROOT_DIR)/public.mk
  193. ifneq ($(WARNING.SMALL_STACK_SIZE),)
  194. # This WARNING is here to protect you from unknowingly using a very small stack
  195. # If the warning is set, increase your stack size or enable the BSP small stack
  196. # setting to eliminate the warning
  197. $(warning WARNING: $(WARNING.SMALL_STACK_SIZE))
  198. endif
  199. # If the BSP public.mk indicates that ALT_SIM_OPTIMIZE is set, rename the ELF
  200. # by prefixing it with RUN_ON_HDL_SIMULATOR_ONLY_.
  201. ifneq ($(filter -DALT_SIM_OPTIMIZE,$(ALT_CPPFLAGS)),)
  202. ELF := RUN_ON_HDL_SIMULATOR_ONLY_$(ELF)
  203. endif
  204. # If the BSP public.mk indicates that ALT_PROVIDE_GMON is set, add option to
  205. # download_elf target
  206. ifneq ($(filter -DALT_PROVIDE_GMON,$(ALT_CPPFLAGS)),)
  207. GMON_OUT_FILENAME := gmon.out
  208. WRITE_GMON_OPTION := --write-gmon $(GMON_OUT_FILENAME)
  209. endif
  210. # Name of ELF application.
  211. APP_NAME := $(basename $(ELF))
  212. # Set to defaults if variables not already defined in settings.
  213. ifeq ($(LINKER_SCRIPT),)
  214. LINKER_SCRIPT := $(BSP_LINKER_SCRIPT)
  215. endif
  216. ifeq ($(CRT0),)
  217. CRT0 := $(BSP_CRT0)
  218. endif
  219. ifeq ($(SYS_LIB),)
  220. SYS_LIB := $(BSP_SYS_LIB)
  221. endif
  222. OBJDUMP_NAME := $(APP_NAME).objdump
  223. OBJDUMP_FLAGS := --disassemble --syms --all-header
  224. ifeq ($(OBJDUMP_INCLUDE_SOURCE),1)
  225. OBJDUMP_FLAGS += --source
  226. endif
  227. ifeq ($(OBJDUMP_FULL_CONTENTS),1)
  228. OBJDUMP_FLAGS += --full-contents
  229. endif
  230. # Create list of linker dependencies (*.a files).
  231. APP_LDDEPS := $(ALT_LDDEPS) $(LDDEPS)
  232. # Take lists and add required prefixes.
  233. APP_INC_DIRS := $(addprefix -I, $(ALT_INCLUDE_DIRS) $(APP_INCLUDE_DIRS) $(INC_DIRS))
  234. ASM_INC_PREFIX := -Wa,-I
  235. APP_ASM_INC_DIRS := $(addprefix $(ASM_INC_PREFIX), $(ALT_INCLUDE_DIRS) $(APP_INCLUDE_DIRS) $(INC_DIRS))
  236. APP_LIB_DIRS := $(addprefix -L, $(ALT_LIBRARY_DIRS) $(APP_LIBRARY_DIRS) $(LIB_DIRS))
  237. APP_LIBS := $(addprefix -l, $(ALT_LIBRARY_NAMES) $(APP_LIBRARY_NAMES) $(LIBS))
  238. ifneq ($(AVOID_NIOS2_GCC3_OPTIONS),)
  239. #
  240. # Avoid Nios II GCC 3.X options.
  241. #
  242. # Detect if small newlib C library is requested.
  243. # If yes, remove the -msmallc option because it is
  244. # now handled by other means.
  245. ifneq ($(filter -msmallc,$(ALT_LDFLAGS)),)
  246. ALT_LDFLAGS := $(filter-out -msmallc,$(ALT_LDFLAGS))
  247. ALT_C_LIBRARY := smallc
  248. else
  249. ALT_C_LIBRARY := c
  250. endif
  251. # Put each BSP dependent library in a group to avoid circular dependencies.
  252. APP_BSP_DEP_LIBS := $(foreach l,$(ALT_BSP_DEP_LIBRARY_NAMES),-Wl,--start-group -l$(ALT_C_LIBRARY) -lgcc -lm -l$(l) -Wl,--end-group)
  253. else # !AVOID_NIOS2_GCC3_OPTIONS
  254. #
  255. # Use Nios II GCC 3.X options.
  256. #
  257. ALT_BSP_DEP_LIBRARY_NAMES += $(ALT_BSP_DEP_LIBRARY_NAMES) m
  258. APP_BSP_DEP_LIBS := $(addprefix -msys-lib=, $(ALT_BSP_DEP_LIBRARY_NAMES))
  259. endif # !AVOID_NIOS2_GCC3_OPTIONS
  260. # Arguments for the C preprocessor, C/C++ compiler, assembler, and linker.
  261. APP_CFLAGS := $(APP_CFLAGS_DEFINED_SYMBOLS) \
  262. $(APP_CFLAGS_UNDEFINED_SYMBOLS) \
  263. $(APP_CFLAGS_OPTIMIZATION) \
  264. $(APP_CFLAGS_DEBUG_LEVEL) \
  265. $(APP_CFLAGS_WARNINGS) \
  266. $(APP_CFLAGS_USER_FLAGS) \
  267. $(ALT_CFLAGS) \
  268. $(CFLAGS)
  269. # Arguments only for the C++ compiler.
  270. APP_CXXFLAGS := $(ALT_CXXFLAGS) $(CXXFLAGS)
  271. # Arguments only for the C preprocessor.
  272. # Prefix each include directory with -I.
  273. APP_CPPFLAGS := $(APP_INC_DIRS) \
  274. $(ALT_CPPFLAGS) \
  275. $(CPPFLAGS)
  276. # Arguments only for the assembler.
  277. APP_ASFLAGS := $(APP_ASM_INC_DIRS) \
  278. $(ALT_ASFLAGS) \
  279. $(APP_ASFLAGS_USER) \
  280. $(ASFLAGS)
  281. # Arguments only for the linker.
  282. APP_LDFLAGS := $(APP_LDFLAGS_USER)
  283. ifneq ($(LINKER_SCRIPT),)
  284. APP_LDFLAGS += -T'$(LINKER_SCRIPT)'
  285. endif
  286. ifneq ($(AVOID_NIOS2_GCC3_OPTIONS),)
  287. # Avoid Nios II GCC 3.x options.
  288. ifneq ($(CRT0),)
  289. APP_LDFLAGS += $(CRT0)
  290. endif
  291. # The equivalent of the -msys-lib option is provided
  292. # by the GROUP() command in the linker script.
  293. # Note this means the SYS_LIB variable is now ignored.
  294. else # !AVOID_NIOS2_GCC3_OPTIONS
  295. # Use Nios II GCC 3.x options.
  296. ifneq ($(CRT0),)
  297. APP_LDFLAGS += -msys-crt0='$(CRT0)'
  298. endif
  299. ifneq ($(SYS_LIB),)
  300. APP_LDFLAGS += -msys-lib=$(SYS_LIB)
  301. endif
  302. endif # !AVOID_NIOS2_GCC3_OPTIONS
  303. APP_LDFLAGS += \
  304. $(APP_LIB_DIRS) \
  305. $(ALT_LDFLAGS) \
  306. $(LDFLAGS)
  307. LINKER_MAP_NAME := $(APP_NAME).map
  308. ifeq ($(CREATE_LINKER_MAP), 1)
  309. APP_LDFLAGS += -Wl,-Map=$(LINKER_MAP_NAME)
  310. endif
  311. # QUARTUS_PROJECT_DIR and SOPC_NAME need to be defined if you want the
  312. # mem_init_install target of the mem_init.mk (located in the associated BSP)
  313. # to know how to copy memory initialization files (e.g. .dat, .hex) into
  314. # directories required for Quartus compilation or RTL simulation.
  315. # Defining QUARTUS_PROJECT_DIR causes mem_init_install to copy memory
  316. # initialization files into your Quartus project directory. This is required
  317. # to provide the initial memory contents of FPGA memories that can be
  318. # initialized by the programming file (.sof) or Hardcopy ROMs. It is also used
  319. # for VHDL simulation of on-chip memories.
  320. # Defining SOPC_NAME causes the mem_init_install target to copy memory
  321. # initialization files into your RTL simulation directory. This is required
  322. # to provide the initial memory contents of all memories that can be
  323. # initialized by RTL simulation. This variable should be set to the same name
  324. # as your SOPC Builder system name. For example, if you have a system called
  325. # "foo.sopc", this variable should be set to "foo".
  326. # If SOPC_NAME is not set and QUARTUS_PROJECT_DIR is set, then derive SOPC_NAME.
  327. ifeq ($(SOPC_NAME),)
  328. ifneq ($(QUARTUS_PROJECT_DIR),)
  329. SOPC_NAME := $(basename $(notdir $(wildcard $(QUARTUS_PROJECT_DIR)/*.sopcinfo)))
  330. endif
  331. endif
  332. # Defining JDI_FILE is required to specify the JTAG Debug Information File
  333. # path. This file is generated by Quartus, and is needed along with the
  334. # .sopcinfo file to resolve processor instance ID's from names in a multi-CPU
  335. # systems. For multi-CPU systems, the processor instance ID is used to select
  336. # from multiple CPU's during ELF download.
  337. # Both JDI_FILE and SOPCINFO_FILE are provided by the BSP if they found during
  338. # BSP creation. If JDI_FILE is not set and QUARTUS_PROJECT_DIR is set, then
  339. # derive JDI_FILE. We do not attempt to derive SOPCINFO_FILE since there may be
  340. # multiple .sopcinfo files in a Quartus project.
  341. ifeq ($(JDI_FILE),)
  342. ifneq ($(QUARTUS_PROJECT_DIR),)
  343. JDI_FILE := $(firstword $(wildcard $(QUARTUS_PROJECT_DIR)/output_files/*.jdi) $(wildcard $(QUARTUS_PROJECT_DIR)/*.jdi))
  344. endif
  345. endif
  346. # Path to root runtime directory used for hdl simulation
  347. RUNTIME_ROOT_DIR := $(CONFIG_OBJ_DIR)/runtime
  348. #------------------------------------------------------------------------------
  349. # MAKEFILE INCLUDES DEPENDENT ON GENERATED CONTENT
  350. #------------------------------------------------------------------------------
  351. # mem_init.mk is a generated makefile fragment. This file defines all targets
  352. # used to generate HDL initialization simulation files and pre-initialized
  353. # onchip memory files.
  354. MEM_INIT_FILE := $(BSP_ROOT_DIR)/mem_init.mk
  355. include $(MEM_INIT_FILE)
  356. # Create list of object files to be built using the list of source files.
  357. # The source file hierarchy is preserved in the object tree.
  358. # The supported file extensions are:
  359. #
  360. # .c - for C files
  361. # .cxx .cc .cpp - for C++ files
  362. # .S .s - for assembler files
  363. #
  364. # Handle source files specified by --src-dir & --src-rdir differently, to
  365. # save some processing time in calling the adjust-path macro.
  366. OBJ_LIST_C := $(patsubst %.c,%.o,$(filter %.c,$(C_SRCS)))
  367. OBJ_LIST_CPP := $(patsubst %.cpp,%.o,$(filter %.cpp,$(CXX_SRCS)))
  368. OBJ_LIST_CXX := $(patsubst %.cxx,%.o,$(filter %.cxx,$(CXX_SRCS)))
  369. OBJ_LIST_CC := $(patsubst %.cc,%.o,$(filter %.cc,$(CXX_SRCS)))
  370. OBJ_LIST_S := $(patsubst %.S,%.o,$(filter %.S,$(ASM_SRCS)))
  371. OBJ_LIST_SS := $(patsubst %.s,%.o,$(filter %.s,$(ASM_SRCS)))
  372. OBJ_LIST := $(sort $(OBJ_LIST_C) $(OBJ_LIST_CPP) $(OBJ_LIST_CXX) \
  373. $(OBJ_LIST_CC) $(OBJ_LIST_S) $(OBJ_LIST_SS))
  374. SDIR_OBJ_LIST_C := $(patsubst %.c,%.o,$(filter %.c,$(SDIR_C_SRCS)))
  375. SDIR_OBJ_LIST_CPP := $(patsubst %.cpp,%.o,$(filter %.cpp,$(SDIR_CXX_SRCS)))
  376. SDIR_OBJ_LIST_CXX := $(patsubst %.cxx,%.o,$(filter %.cxx,$(SDIR_CXX_SRCS)))
  377. SDIR_OBJ_LIST_CC := $(patsubst %.cc,%.o,$(filter %.cc,$(SDIR_CXX_SRCS)))
  378. SDIR_OBJ_LIST_S := $(patsubst %.S,%.o,$(filter %.S,$(SDIR_ASM_SRCS)))
  379. SDIR_OBJ_LIST_SS := $(patsubst %.s,%.o,$(filter %.s,$(SDIR_ASM_SRCS)))
  380. SDIR_OBJ_LIST := $(sort $(SDIR_OBJ_LIST_C) $(SDIR_OBJ_LIST_CPP) \
  381. $(SDIR_OBJ_LIST_CXX) $(SDIR_OBJ_LIST_CC) $(SDIR_OBJ_LIST_S) \
  382. $(SDIR_OBJ_LIST_SS))
  383. # Relative-pathed objects that being with "../" are handled differently.
  384. #
  385. # Regular objects are created as
  386. # $(CONFIG_OBJ_DIR)/<path>/<filename>.o
  387. # where the path structure is maintained under the obj directory. This
  388. # applies for both absolute and relative paths; in the absolute path
  389. # case this means the entire source path will be recreated under the obj
  390. # directory. This is done to allow two source files with the same name
  391. # to be included as part of the project.
  392. #
  393. # Note: On Cygwin, the path recreated under the obj directory will be
  394. # the cygpath -u output path.
  395. #
  396. # Relative-path objects that begin with "../" cause problems under this
  397. # scheme, as $(CONFIG_OBJ_DIR)/../<rest of path>/ can potentially put the object
  398. # files anywhere in the system, creating clutter and polluting the source tree.
  399. # As such, their paths are flattened - the object file created will be
  400. # $(CONFIG_OBJ_DIR)/<filename>.o. Due to this, two files specified with
  401. # "../" in the beginning cannot have the same name in the project. VPATH
  402. # will be set for these sources to allow make to relocate the source file
  403. # via %.o rules.
  404. #
  405. # The following lines separate the object list into the flatten and regular
  406. # lists, and then handles them as appropriate.
  407. FLATTEN_OBJ_LIST := $(filter ../%,$(OBJ_LIST))
  408. FLATTEN_APP_OBJS := $(addprefix $(CONFIG_OBJ_DIR)/,$(notdir $(FLATTEN_OBJ_LIST)))
  409. REGULAR_OBJ_LIST := $(filter-out $(FLATTEN_OBJ_LIST),$(OBJ_LIST))
  410. REGULAR_OBJ_LIST_C := $(filter $(OBJ_LIST_C),$(REGULAR_OBJ_LIST))
  411. REGULAR_OBJ_LIST_CPP := $(filter $(OBJ_LIST_CPP),$(REGULAR_OBJ_LIST))
  412. REGULAR_OBJ_LIST_CXX := $(filter $(OBJ_LIST_CXX),$(REGULAR_OBJ_LIST))
  413. REGULAR_OBJ_LIST_CC := $(filter $(OBJ_LIST_CC),$(REGULAR_OBJ_LIST))
  414. REGULAR_OBJ_LIST_S := $(filter $(OBJ_LIST_S),$(REGULAR_OBJ_LIST))
  415. REGULAR_OBJ_LIST_SS := $(filter $(OBJ_LIST_SS),$(REGULAR_OBJ_LIST))
  416. FLATTEN_SDIR_OBJ_LIST := $(filter ../%,$(SDIR_OBJ_LIST))
  417. FLATTEN_SDIR_APP_OBJS := $(addprefix $(CONFIG_OBJ_DIR)/,$(notdir $(FLATTEN_SDIR_OBJ_LIST)))
  418. REGULAR_SDIR_OBJ_LIST := $(filter-out $(FLATTEN_SDIR_OBJ_LIST),$(SDIR_OBJ_LIST))
  419. REGULAR_SDIR_OBJ_LIST_C := $(filter $(SDIR_OBJ_LIST_C),$(REGULAR_SDIR_OBJ_LIST))
  420. REGULAR_SDIR_OBJ_LIST_CPP := $(filter $(SDIR_OBJ_LIST_CPP),$(REGULAR_SDIR_OBJ_LIST))
  421. REGULAR_SDIR_OBJ_LIST_CXX := $(filter $(SDIR_OBJ_LIST_CXX),$(REGULAR_SDIR_OBJ_LIST))
  422. REGULAR_SDIR_OBJ_LIST_CC := $(filter $(SDIR_OBJ_LIST_CC),$(REGULAR_SDIR_OBJ_LIST))
  423. REGULAR_SDIR_OBJ_LIST_S := $(filter $(SDIR_OBJ_LIST_S),$(REGULAR_SDIR_OBJ_LIST))
  424. REGULAR_SDIR_OBJ_LIST_SS := $(filter $(SDIR_OBJ_LIST_SS),$(REGULAR_SDIR_OBJ_LIST))
  425. VPATH := $(sort $(dir $(FLATTEN_OBJ_LIST)) $(dir $(FLATTEN_SDIR_OBJ_LIST)))
  426. APP_OBJS_C := $(addprefix $(CONFIG_OBJ_DIR)/,\
  427. $(REGULAR_SDIR_OBJ_LIST_C) \
  428. $(foreach s,$(REGULAR_OBJ_LIST_C),$(call adjust-path,$s)))
  429. APP_OBJS_CPP := $(addprefix $(CONFIG_OBJ_DIR)/,\
  430. $(REGULAR_SDIR_OBJ_LIST_CPP) \
  431. $(foreach s,$(REGULAR_OBJ_LIST_CPP),$(call adjust-path,$s)))
  432. APP_OBJS_CXX := $(addprefix $(CONFIG_OBJ_DIR)/,\
  433. $(REGULAR_SDIR_OBJ_LIST_CXX) \
  434. $(foreach s,$(REGULAR_OBJ_LIST_CXX),$(call adjust-path,$s)))
  435. APP_OBJS_CC := $(addprefix $(CONFIG_OBJ_DIR)/,\
  436. $(REGULAR_SDIR_OBJ_LIST_CC) \
  437. $(foreach s,$(REGULAR_OBJ_LIST_CC),$(call adjust-path,$s)))
  438. APP_OBJS_S := $(addprefix $(CONFIG_OBJ_DIR)/,\
  439. $(REGULAR_SDIR_OBJ_LIST_S) \
  440. $(foreach s,$(REGULAR_OBJ_LIST_S),$(call adjust-path,$s)))
  441. APP_OBJS_SS := $(addprefix $(CONFIG_OBJ_DIR)/,\
  442. $(REGULAR_SDIR_OBJ_LIST_SS) \
  443. $(foreach s,$(REGULAR_OBJ_LIST_SS),$(call adjust-path,$s)))
  444. APP_OBJS := $(APP_OBJS_C) $(APP_OBJS_CPP) $(APP_OBJS_CXX) $(APP_OBJS_CC) \
  445. $(APP_OBJS_S) $(APP_OBJS_SS) \
  446. $(FLATTEN_APP_OBJS) $(FLATTEN_SDIR_APP_OBJS)
  447. # Add any extra user-provided object files.
  448. APP_OBJS += $(OBJS)
  449. # Create list of dependancy files for each object file.
  450. APP_DEPS := $(APP_OBJS:.o=.d)
  451. # Patch the Elf file with system specific information
  452. # Patch the Elf with the name of the sopc system
  453. ifneq ($(SOPC_NAME),)
  454. ELF_PATCH_FLAG += --sopc_system_name $(SOPC_NAME)
  455. endif
  456. # Patch the Elf with the absolute path to the Quartus Project Directory
  457. ifneq ($(QUARTUS_PROJECT_DIR),)
  458. ABS_QUARTUS_PROJECT_DIR := $(call adjust-path-mixed,$(shell cd "$(QUARTUS_PROJECT_DIR)"; pwd))
  459. ELF_PATCH_FLAG += --quartus_project_dir "$(ABS_QUARTUS_PROJECT_DIR)"
  460. endif
  461. # Patch the Elf and download args with the JDI_FILE if specified
  462. ifneq ($(wildcard $(JDI_FILE)),)
  463. ELF_PATCH_FLAG += --jdi $(JDI_FILE)
  464. DOWNLOAD_JDI_FLAG := --jdi $(JDI_FILE)
  465. endif
  466. # Patch the Elf with the SOPCINFO_FILE if specified
  467. ifneq ($(wildcard $(SOPCINFO_FILE)),)
  468. ELF_PATCH_FLAG += --sopcinfo $(SOPCINFO_FILE)
  469. endif
  470. # Use the DOWNLOAD_CABLE variable to specify which JTAG cable to use.
  471. # This is not needed if you only have one cable.
  472. ifneq ($(DOWNLOAD_CABLE),)
  473. DOWNLOAD_CABLE_FLAG := --cable '$(DOWNLOAD_CABLE)'
  474. endif
  475. #------------------------------------------------------------------------------
  476. # BUILD PRE/POST PROCESS
  477. #------------------------------------------------------------------------------
  478. build_pre_process :
  479. $(BUILD_PRE_PROCESS)
  480. build_post_process :
  481. $(BUILD_POST_PROCESS)
  482. .PHONY: build_pre_process build_post_process
  483. #------------------------------------------------------------------------------
  484. # TOOLS
  485. #------------------------------------------------------------------------------
  486. #
  487. # Set tool default variables if not already defined.
  488. # If these are defined, they would typically be defined in an
  489. # included makefile fragment.
  490. #
  491. ifeq ($(DEFAULT_CROSS_COMPILE),)
  492. DEFAULT_CROSS_COMPILE := nios2-elf-
  493. endif
  494. ifeq ($(DEFAULT_STACKREPORT),)
  495. DEFAULT_STACKREPORT := nios2-stackreport
  496. endif
  497. ifeq ($(DEFAULT_DOWNLOAD),)
  498. DEFAULT_DOWNLOAD := nios2-download
  499. endif
  500. ifeq ($(DEFAULT_FLASHPROG),)
  501. DEFAULT_FLASHPROG := nios2-flash-programmer
  502. endif
  503. ifeq ($(DEFAULT_ELFPATCH),)
  504. DEFAULT_ELFPATCH := nios2-elf-insert
  505. endif
  506. ifeq ($(DEFAULT_RM),)
  507. DEFAULT_RM := rm -f
  508. endif
  509. ifeq ($(DEFAULT_CP),)
  510. DEFAULT_CP := cp -f
  511. endif
  512. ifeq ($(DEFAULT_MKDIR),)
  513. DEFAULT_MKDIR := mkdir -p
  514. endif
  515. #
  516. # Set tool variables to defaults if not already defined.
  517. # If these are defined, they would typically be defined by a
  518. # setting in the generated portion of this makefile.
  519. #
  520. ifeq ($(CROSS_COMPILE),)
  521. CROSS_COMPILE := $(DEFAULT_CROSS_COMPILE)
  522. endif
  523. ifeq ($(origin CC),default)
  524. CC := $(CROSS_COMPILE)gcc -xc
  525. endif
  526. ifeq ($(origin CXX),default)
  527. CXX := $(CROSS_COMPILE)gcc -xc++
  528. endif
  529. ifeq ($(origin AS),default)
  530. AS := $(CROSS_COMPILE)gcc
  531. endif
  532. ifeq ($(origin AR),default)
  533. AR := $(CROSS_COMPILE)ar
  534. endif
  535. ifeq ($(origin LD),default)
  536. LD := $(CROSS_COMPILE)g++
  537. endif
  538. ifeq ($(origin RM),default)
  539. RM := $(DEFAULT_RM)
  540. endif
  541. ifeq ($(NM),)
  542. NM := $(CROSS_COMPILE)nm
  543. endif
  544. ifeq ($(CP),)
  545. CP := $(DEFAULT_CP)
  546. endif
  547. ifeq ($(OBJDUMP),)
  548. OBJDUMP := $(CROSS_COMPILE)objdump
  549. endif
  550. ifeq ($(OBJCOPY),)
  551. OBJCOPY := $(CROSS_COMPILE)objcopy
  552. endif
  553. ifeq ($(STACKREPORT),)
  554. STACKREPORT := $(DEFAULT_STACKREPORT) --prefix $(CROSS_COMPILE)
  555. else
  556. DISABLE_STACKREPORT := 1
  557. endif
  558. ifeq ($(DOWNLOAD),)
  559. DOWNLOAD := $(DEFAULT_DOWNLOAD)
  560. endif
  561. ifeq ($(FLASHPROG),)
  562. FLASHPROG := $(DEFAULT_FLASHPROG)
  563. endif
  564. ifeq ($(ELFPATCH),)
  565. ELFPATCH := $(DEFAULT_ELFPATCH)
  566. endif
  567. ifeq ($(MKDIR),)
  568. MKDIR := $(DEFAULT_MKDIR)
  569. endif
  570. #------------------------------------------------------------------------------
  571. # PATTERN RULES TO BUILD OBJECTS
  572. #------------------------------------------------------------------------------
  573. define compile.c
  574. @$(ECHO) Info: Compiling $< to $@
  575. @$(MKDIR) $(@D)
  576. $(CC) -MP -MMD -c $(APP_CPPFLAGS) $(APP_CFLAGS) -o $@ $<
  577. $(CC_POST_PROCESS)
  578. endef
  579. define compile.cpp
  580. @$(ECHO) Info: Compiling $< to $@
  581. @$(MKDIR) $(@D)
  582. $(CXX) -MP -MMD -c $(APP_CPPFLAGS) $(APP_CXXFLAGS) $(APP_CFLAGS) -o $@ $<
  583. $(CXX_POST_PROCESS)
  584. endef
  585. # If assembling with the compiler, ensure "-Wa," is prepended to all APP_ASFLAGS
  586. ifeq ($(AS),$(patsubst %as,%,$(AS)))
  587. COMMA := ,
  588. APP_ASFLAGS := $(filter-out $(APP_CFLAGS),$(addprefix -Wa$(COMMA),$(patsubst -Wa$(COMMA)%,%,$(APP_ASFLAGS))))
  589. endif
  590. define compile.s
  591. @$(ECHO) Info: Assembling $< to $@
  592. @$(MKDIR) $(@D)
  593. $(AS) -MP -MMD -c $(APP_CPPFLAGS) $(APP_CFLAGS) $(APP_ASFLAGS) -o $@ $<
  594. $(AS_POST_PROCESS)
  595. endef
  596. ifeq ($(MAKE_VERSION),3.81)
  597. .SECONDEXPANSION:
  598. $(APP_OBJS_C): $(CONFIG_OBJ_DIR)/%.o: $$(call adjust-path-mixed,%.c)
  599. $(compile.c)
  600. $(APP_OBJS_CPP): $(CONFIG_OBJ_DIR)/%.o: $$(call adjust-path-mixed,%.cpp)
  601. $(compile.cpp)
  602. $(APP_OBJS_CC): $(CONFIG_OBJ_DIR)/%.o: $$(call adjust-path-mixed,%.cc)
  603. $(compile.cpp)
  604. $(APP_OBJS_CXX): $(CONFIG_OBJ_DIR)/%.o: $$(call adjust-path-mixed,%.cxx)
  605. $(compile.cpp)
  606. $(APP_OBJS_S): $(CONFIG_OBJ_DIR)/%.o: $$(call adjust-path-mixed,%.S)
  607. $(compile.s)
  608. $(APP_OBJS_SS): $(CONFIG_OBJ_DIR)/%.o: $$(call adjust-path-mixed,%.s)
  609. $(compile.s)
  610. endif # MAKE_VERSION != 3.81
  611. $(CONFIG_OBJ_DIR)/%.o: %.c
  612. $(compile.c)
  613. $(CONFIG_OBJ_DIR)/%.o: %.cpp
  614. $(compile.cpp)
  615. $(CONFIG_OBJ_DIR)/%.o: %.cc
  616. $(compile.cpp)
  617. $(CONFIG_OBJ_DIR)/%.o: %.cxx
  618. $(compile.cpp)
  619. $(CONFIG_OBJ_DIR)/%.o: %.S
  620. $(compile.s)
  621. $(CONFIG_OBJ_DIR)/%.o: %.s
  622. $(compile.s)
  623. #------------------------------------------------------------------------------
  624. # PATTERN RULES TO INTERMEDIATE FILES
  625. #------------------------------------------------------------------------------
  626. $(CONFIG_OBJ_DIR)/%.s: %.c
  627. @$(ECHO) Info: Compiling $< to $@
  628. @$(MKDIR) $(@D)
  629. $(CC) -S $(APP_CPPFLAGS) $(APP_CFLAGS) -o $@ $<
  630. $(CONFIG_OBJ_DIR)/%.s: %.cpp
  631. @$(ECHO) Info: Compiling $< to $@
  632. @$(MKDIR) $(@D)
  633. $(CXX) -S $(APP_CPPFLAGS) $(APP_CXXFLAGS) $(APP_CFLAGS) -o $@ $<
  634. $(CONFIG_OBJ_DIR)/%.s: %.cc
  635. @$(ECHO) Info: Compiling $< to $@
  636. @$(MKDIR) $(@D)
  637. $(CXX) -S $(APP_CPPFLAGS) $(APP_CXXFLAGS) $(APP_CFLAGS) -o $@ $<
  638. $(CONFIG_OBJ_DIR)/%.s: %.cxx
  639. @$(ECHO) Info: Compiling $< to $@
  640. @$(MKDIR) $(@D)
  641. $(CXX) -S $(APP_CPPFLAGS) $(APP_CXXFLAGS) $(APP_CFLAGS) -o $@ $<
  642. $(CONFIG_OBJ_DIR)/%.i: %.c
  643. @$(ECHO) Info: Compiling $< to $@
  644. @$(MKDIR) $(@D)
  645. $(CC) -E $(APP_CPPFLAGS) $(APP_CFLAGS) -o $@ $<
  646. $(CONFIG_OBJ_DIR)/%.i: %.cpp
  647. @$(ECHO) Info: Compiling $< to $@
  648. @$(MKDIR) $(@D)
  649. $(CXX) -E $(APP_CPPFLAGS) $(APP_CXXFLAGS) $(APP_CFLAGS) -o $@ $<
  650. $(CONFIG_OBJ_DIR)/%.i: %.cc
  651. @$(ECHO) Info: Compiling $< to $@
  652. @$(MKDIR) $(@D)
  653. $(CXX) -E $(APP_CPPFLAGS) $(APP_CXXFLAGS) $(APP_CFLAGS) -o $@ $<
  654. $(CONFIG_OBJ_DIR)/%.i: %.cxx
  655. @$(ECHO) Info: Compiling $< to $@
  656. @$(MKDIR) $(@D)
  657. $(CXX) -E $(APP_CPPFLAGS) $(APP_CXXFLAGS) $(APP_CFLAGS) -o $@ $<
  658. #------------------------------------------------------------------------------
  659. # TARGET RULES
  660. #------------------------------------------------------------------------------
  661. .PHONY : help
  662. help :
  663. @$(ECHO) "Summary of Makefile targets"
  664. @$(ECHO) " Build targets:"
  665. @$(ECHO) " all (default) - Application and all libraries (including BSP)"
  666. @$(ECHO) " bsp - Just the BSP"
  667. @$(ECHO) " libs - All libraries (including BSP)"
  668. @$(ECHO) " flash - All flash files"
  669. @$(ECHO) " mem_init_generate - All memory initialization files"
  670. @$(ECHO)
  671. @$(ECHO) " Clean targets:"
  672. @$(ECHO) " clean_all - Application and all libraries (including BSP)"
  673. @$(ECHO) " clean - Just the application"
  674. @$(ECHO) " clean_bsp - Just the BSP"
  675. @$(ECHO) " clean_libs - All libraries (including BSP)"
  676. @$(ECHO)
  677. @$(ECHO) " Run targets:"
  678. @$(ECHO) " download-elf - Download and run your elf executable"
  679. @$(ECHO) " program-flash - Program flash contents to the board"
  680. # Handy rule to skip making libraries and just make application.
  681. .PHONY : app
  682. app : $(ELF)
  683. ifeq ($(CREATE_OBJDUMP), 1)
  684. app : $(OBJDUMP_NAME)
  685. endif
  686. ifeq ($(CREATE_ELF_DERIVED_FILES),1)
  687. app : elf_derived_files
  688. endif
  689. .PHONY: elf_derived_files
  690. elf_derived_files: default_mem_init
  691. # Handy rule for making just the BSP.
  692. .PHONY : bsp
  693. bsp :
  694. @$(ECHO) Info: Building $(BSP_ROOT_DIR)
  695. @$(MAKE) --no-print-directory -C $(BSP_ROOT_DIR)
  696. # Make sure all makeable libraries (including the BSP) are up-to-date.
  697. LIB_TARGETS := $(patsubst %,%-recurs-make-lib,$(MAKEABLE_LIBRARY_ROOT_DIRS))
  698. .PHONY : libs
  699. libs : $(LIB_TARGETS)
  700. ifneq ($(strip $(LIB_TARGETS)),)
  701. $(LIB_TARGETS): %-recurs-make-lib:
  702. @$(ECHO) Info: Building $*
  703. $(MAKE) --no-print-directory -C $*
  704. endif
  705. ifneq ($(strip $(APP_LDDEPS)),)
  706. $(APP_LDDEPS): libs
  707. @true
  708. endif
  709. # Rules to force your project to rebuild or relink
  710. # .force_relink file will cause any application that depends on this project to relink
  711. # .force_rebuild file will cause this project to rebuild object files
  712. # .force_rebuild_all file will cause this project and any project that depends on this project to rebuild object files
  713. FORCE_RELINK_DEP := .force_relink
  714. FORCE_REBUILD_DEP := .force_rebuild
  715. FORCE_REBUILD_ALL_DEP := .force_rebuild_all
  716. FORCE_REBUILD_DEP_LIST := $(CONFIG_OBJ_DIR)/$(FORCE_RELINK_DEP) $(CONFIG_OBJ_DIR)/$(FORCE_REBUILD_DEP) $(FORCE_REBUILD_ALL_DEP)
  717. $(FORCE_REBUILD_DEP_LIST):
  718. $(APP_OBJS): $(wildcard $(CONFIG_OBJ_DIR)/$(FORCE_REBUILD_DEP)) $(wildcard $(addsuffix /$(FORCE_REBUILD_ALL_DEP), . $(ALT_LIBRARY_DIRS)))
  719. $(ELF): $(wildcard $(addsuffix /$(FORCE_RELINK_DEP), $(CONFIG_OBJ_DIR) $(ALT_LIBRARY_DIRS)))
  720. # Clean just the application.
  721. .PHONY : clean
  722. ifeq ($(CREATE_ELF_DERIVED_FILES),1)
  723. clean : clean_elf_derived_files
  724. endif
  725. clean :
  726. @$(RM) -r $(ELF) $(OBJDUMP_NAME) $(LINKER_MAP_NAME) $(OBJ_ROOT_DIR) $(RUNTIME_ROOT_DIR) $(FORCE_REBUILD_DEP_LIST)
  727. @$(ECHO) [$(APP_NAME) clean complete]
  728. # Clean just the BSP.
  729. .PHONY : clean_bsp
  730. clean_bsp :
  731. @$(ECHO) Info: Cleaning $(BSP_ROOT_DIR)
  732. @$(MAKE) --no-print-directory -C $(BSP_ROOT_DIR) clean
  733. # Clean all makeable libraries including the BSP.
  734. LIB_CLEAN_TARGETS := $(patsubst %,%-recurs-make-clean-lib,$(MAKEABLE_LIBRARY_ROOT_DIRS))
  735. .PHONY : clean_libs
  736. clean_libs : $(LIB_CLEAN_TARGETS)
  737. ifneq ($(strip $(LIB_CLEAN_TARGETS)),)
  738. $(LIB_CLEAN_TARGETS): %-recurs-make-clean-lib:
  739. @$(ECHO) Info: Cleaning $*
  740. $(MAKE) --no-print-directory -C $* clean
  741. endif
  742. .PHONY: clean_elf_derived_files
  743. clean_elf_derived_files: mem_init_clean
  744. # Clean application and all makeable libraries including the BSP.
  745. .PHONY : clean_all
  746. clean_all : clean mem_init_clean clean_libs
  747. # Include the dependency files unless the make goal is performing a clean
  748. # of the application.
  749. ifneq ($(firstword $(MAKECMDGOALS)),clean)
  750. ifneq ($(firstword $(MAKECMDGOALS)),clean_all)
  751. -include $(APP_DEPS)
  752. endif
  753. endif
  754. .PHONY : download-elf
  755. download-elf : $(ELF)
  756. @if [ "$(DOWNLOAD)" = "none" ]; \
  757. then \
  758. $(ECHO) Downloading $(ELF) not supported; \
  759. else \
  760. $(ECHO) Info: Downloading $(ELF); \
  761. $(DOWNLOAD) --go --cpu_name=$(CPU_NAME) $(DOWNLOAD_CABLE_FLAG) $(SOPC_SYSID_FLAG) $(DOWNLOAD_JDI_FLAG) $(WRITE_GMON_OPTION) $(ELF); \
  762. fi
  763. # Delete the target of a rule if it has changed and its commands exit
  764. # with a nonzero exit status.
  765. .DELETE_ON_ERROR:
  766. # Rules for flash programming commands
  767. PROGRAM_FLASH_SUFFIX := -program
  768. PROGRAM_FLASH_TARGET := $(addsuffix $(PROGRAM_FLASH_SUFFIX), $(FLASH_FILES))
  769. .PHONY : program-flash
  770. program-flash : $(PROGRAM_FLASH_TARGET)
  771. .PHONY : $(PROGRAM_FLASH_TARGET)
  772. $(PROGRAM_FLASH_TARGET) : flash
  773. @if [ "$(FLASHPROG)" = "none" ]; \
  774. then \
  775. $(ECHO) Programming flash not supported; \
  776. else \
  777. $(ECHO) Info: Programming $(basename $@).flash; \
  778. if [ -z "$($(basename $@)_EPCS_FLAGS)" ]; \
  779. then \
  780. $(ECHO) $(FLASHPROG) $(SOPC_SYSID_FLAG) --base=$($(basename $@)_START) $(basename $@).flash; \
  781. $(FLASHPROG) $(DOWNLOAD_CABLE_FLAG) $(SOPC_SYSID_FLAG) --base=$($(basename $@)_START) $(basename $@).flash; \
  782. else \
  783. $(ECHO) $(FLASHPROG) $(SOPC_SYSID_FLAG) --epcs --base=$($(basename $@)_START) $(basename $@).flash; \
  784. $(FLASHPROG) $(DOWNLOAD_CABLE_FLAG) $(SOPC_SYSID_FLAG) --epcs --base=$($(basename $@)_START) $(basename $@).flash; \
  785. fi \
  786. fi
  787. # Rules for simulating with an HDL Simulator [QSYS only]
  788. ifeq ($(QSYS),1)
  789. #Create a top level modelsim script load_sim.tcl to source generate msim_setup.tcl and copy mem initialization files
  790. CREATE_TOP_SIM_SCRIPT := alt-create-top-sim-script
  791. ifeq ($(VSIM),)
  792. VSIM_EXE := "$(if $(VSIM_DIR),$(VSIM_DIR)/,)vsim"
  793. ifeq ($(ENABLE_VSIM_GUI),1)
  794. VSIM := $(VSIM_EXE) -gui
  795. else
  796. VSIM := $(VSIM_EXE) -c
  797. endif # ENABLE_VSIM_GUI == 1
  798. endif # VSIM not set
  799. ifeq ($(SPD),)
  800. ifneq ($(ABS_QUARTUS_PROJECT_DIR),)
  801. ifneq ($(SOPC_NAME),)
  802. SPD_LOCATION = $(ABS_QUARTUS_PROJECT_DIR)/$(SOPC_NAME)_tb/$(SOPC_NAME)_tb/$(SOPC_NAME)_tb.spd
  803. LEGACY_SPD_LOCATION = $(ABS_QUARTUS_PROJECT_DIR)/$(SOPC_NAME)_tb.spd
  804. SPD = $(if $(wildcard $(SPD_LOCATION)),$(SPD_LOCATION),$(LEGACY_SPD_LOCATION))
  805. endif # SOPC_NAME set
  806. endif # ABS_QUARTUS_PROJECT_DIR set
  807. endif # SPD == empty string
  808. ifeq ($(LOAD_SIM_SCRIPT),)
  809. SIM_SCRIPT_DIR := $(RUNTIME_ROOT_DIR)/sim
  810. LOAD_SIM_SCRIPT := $(SIM_SCRIPT_DIR)/mentor/load_sim.tcl
  811. endif # LOAD_SIM_SCRIPT == empty string
  812. ifeq ($(MAKE_VERSION),3.81)
  813. ABS_MEM_INIT_DESCRIPTOR_FILE := $(abspath $(MEM_INIT_DESCRIPTOR_FILE))
  814. else
  815. ABS_MEM_INIT_DESCRIPTOR_FILE := $(call adjust-path-mixed,$(shell pwd))/$(MEM_INIT_DESCRIPTOR_FILE)
  816. endif
  817. $(LOAD_SIM_SCRIPT): $(SPD) $(MEM_INIT_DESCRIPTOR_FILE)
  818. ifeq ($(SPD),)
  819. $(error No SPD file specified. Ensure QUARTUS_PROJECT_DIR variable is set)
  820. endif
  821. @$(MKDIR) $(SIM_SCRIPT_DIR)
  822. $(CREATE_TOP_SIM_SCRIPT) --spd=$(SPD) --mem-init-spd=$(abspath $(MEM_INIT_DESCRIPTOR_FILE)) --output-directory=$(SIM_SCRIPT_DIR)
  823. VSIM_COMMAND = \
  824. cd $(dir $(LOAD_SIM_SCRIPT)) && \
  825. $(VSIM) -do "do $(notdir $(LOAD_SIM_SCRIPT)); ld; $(if $(VSIM_RUN_TIME),run ${VSIM_RUN_TIME};quit;)"
  826. .PHONY: sim
  827. sim: $(LOAD_SIM_SCRIPT) mem_init_generate
  828. ifeq ($(LOAD_SIM_SCRIPT),)
  829. $(error LOAD_SIM_SCRIPT not set)
  830. endif
  831. $(VSIM_COMMAND)
  832. endif # QSYS == 1
  833. #------------------------------------------------------------------------------
  834. # ELF TARGET RULE
  835. #------------------------------------------------------------------------------
  836. # Rule for constructing the executable elf file.
  837. $(ELF) : $(APP_OBJS) $(LINKER_SCRIPT) $(APP_LDDEPS)
  838. @$(ECHO) Info: Linking $@
  839. $(LD) $(APP_LDFLAGS) $(APP_CFLAGS) -o $@ $(filter-out $(CRT0),$(APP_OBJS)) $(APP_LIBS) $(APP_BSP_DEP_LIBS)
  840. ifneq ($(DISABLE_ELFPATCH),1)
  841. $(ELFPATCH) $@ $(ELF_PATCH_FLAG)
  842. endif
  843. ifneq ($(DISABLE_STACKREPORT),1)
  844. @bash -c "$(STACKREPORT) $@"
  845. endif
  846. $(OBJDUMP_NAME) : $(ELF)
  847. @$(ECHO) Info: Creating $@
  848. $(OBJDUMP) $(OBJDUMP_FLAGS) $< >$@
  849. # Rule for printing the name of the elf file
  850. .PHONY: print-elf-name
  851. print-elf-name:
  852. @$(ECHO) $(ELF)