Makefile 34 KB

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