Advertisement
Guest User

makefile_profile.mak

a guest
Apr 26th, 2011
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 17.51 KB | None | 0 0
  1. # ***********************************************************************************
  2. #
  3. # makefile_profile.mak     Version 1.0        Date: SEPT-29-2008
  4. #
  5. # Revisions:
  6. # - (v0.80) First "standard" GNU makefile for DaVinci Workshop
  7. #           used in workshop versions 1.30 (beta's 1 & 2)
  8. # - (v1.00) Used for DaVinci Workshop (production version 1.30)
  9. #
  10. # Use:
  11. # - Called by parent makefile named "makefile"
  12. # - Can be called directly using gMake's -f option; refer to the syntax used
  13. #   by the "parent" makefile to invoke this make file
  14. # - Currently builds for ARM9 target, however other targets can be supported.
  15. # - User can specify PROFILE (either debug
  16. #   or release or all) when invoking the parent makefile
  17. # - All dependencies (e.g. header files) are handled by the dependency rule
  18. # - Uses Configuro to consume packages delivered by TI
  19. # - All tools paths are specified in setpaths.mak located two levels above /app
  20. #
  21. # ***********************************************************************************
  22.  
  23.  
  24. # *****************************************************************************
  25. #
  26. #    (Early) Include files
  27. #
  28. # *****************************************************************************
  29.  
  30. # ---------------------------------------------------------------------
  31. # setpaths.mak includes all absolute paths for DaVinci tools
  32. #   and is located two levels above the /app directory.
  33. # ---------------------------------------------------------------------
  34. -include ../../setpaths.mak
  35.  
  36.  
  37. # *****************************************************************************
  38. #
  39. #    User-defined vars
  40. #
  41. # *****************************************************************************
  42.  
  43. # ---------------------------------------------------------------------
  44. # AT: - Used for debug, it hides commands for a prettier output
  45. #     - When debugging, you may want to set this variable to nothing by
  46. #       setting it to "" below, or on the command line
  47. # ---------------------------------------------------------------------
  48. AT :=  #@
  49.  
  50. # ---------------------------------------------------------------------
  51. # Location and build option flags for gcc build tools
  52. #   - MONTAVISTA_DEVKIT is defined in setpaths.mak
  53. #   - CC_ROOT is passed to configuro for building with gcc
  54. #   - CC is used to invoke gcc compiler
  55. #   - CFLAGS, LINKER_FLAGS are generic gcc build options
  56. #   - DEBUG/RELEASE FLAGS are profile specific options
  57. # ---------------------------------------------------------------------
  58. # For angstrom compiler
  59. #CC_ROOT :=  $(DEVKIT)/armv7a
  60. #CC      :=  $(CC_ROOT)/bin/arm-angstrom-linux-gnueabi-gcc
  61. #CFLAGS       := -Wall -fno-strict-aliasing -march=armv7-a -D_REENTRANT -I$(DEVKIT)/armv7a/lib/gcc/arm-angstrom-linux-gnueabi/4.3.1/include
  62.  
  63. # For CodeSourcery compiler
  64. CC_ROOT :=  $(DEVKIT)
  65. CC      :=  $(CC_ROOT)/bin/arm-none-linux-gnueabi-gcc
  66. CFLAGS       := -Wall -fno-strict-aliasing -march=armv7-a -D_REENTRANT -I$(DEVKIT)/lib/gcc/arm-none-linux-gnueabi/4.3.3/include
  67.  
  68. LINKER_FLAGS := -lpthread
  69.  
  70. DEBUG_CFLAGS   := -g -D_DEBUG_
  71. RELEASE_CFLAGS := -O2
  72.  
  73.  
  74.  
  75. # ---------------------------------------------------------------------
  76. # C_SRCS used to build two arrays:
  77. #   - C_OBJS is used as dependencies for executable build rule
  78. #   - C_DEPS is '-included' below; .d files are build in rule #3 below
  79. #
  80. # Three functions are used to create these arrays
  81. #   - Wildcard
  82. #   - Substitution
  83. #   - Add prefix
  84. # ---------------------------------------------------------------------
  85. C_SRCS := $(wildcard *.c)
  86.  
  87. OBJS   := $(subst .c,.o,$(C_SRCS))
  88. C_OBJS  = $(addprefix $(PROFILE)/,$(OBJS))
  89.  
  90. DEPS   := $(subst .c,.d,$(C_SRCS))
  91. C_DEPS  = $(addprefix $(PROFILE)/,$(DEPS))
  92.  
  93.  
  94. # ---------------------------------------------------------------------
  95. # Configuro related variables
  96. # ---------------------------
  97. #  - XDCROOT is defined in setpaths.mak
  98. #  - CONFIGURO is where the XDC configuration tool is located
  99. #  - Configuro searches for packages (i.e. smart libraries) along the
  100. #    path specified in XDCPATH; it is exported so that it's available
  101. #    when Configuro runs
  102. #  - Configuro requires that the TARGET and PLATFORM are specified
  103. #  - Here are some additional target/platform choices
  104. #      TARGET   := ti.targets.C64
  105. #      PLATFORM := ti.platforms.evmEM6446
  106. #      TARGET   := gnu.targets.Linux86
  107. #      PLATFORM := host.platforms.PC
  108. # ---------------------------------------------------------------------
  109. #XDCROOT := $(XDC_INSTALL_DIR)
  110. #CONFIGURO := $(XDCROOT)/xs xdc.tools.configuro
  111. #export XDCPATH:=/home/user/rtsc_primer/examples;$(XDCROOT)
  112. #TARGET   := gnu.targets.MVArm9
  113. #PLATFORM := ti.platforms.evmDM6446
  114.  
  115. # ---------------------------------------------------------------------
  116. # Project related variables
  117. # -------------------------
  118. #   PROGNAME defines the name of the program to be built
  119. #   CONFIG:  - defines the name of the configuration file
  120. #            - the actual config file name would be $(CONFIG).cfg
  121. #            - also defines the name of the folder Configuro outputs to
  122. #   PROFILE: - defines which set of build flags to use (debug or release)
  123. #            - output files are put into a $(PROFILE) subdirectory
  124. #            - set to "debug" by default; override via the command line
  125. # ---------------------------------------------------------------------
  126. PROGNAME := app
  127. #CONFIG   := app_cfg
  128. PROFILE  := DEBUG
  129.  
  130. # -------------------------------------------------
  131. # ----- always keep these intermediate files ------
  132. # -------------------------------------------------
  133. .PRECIOUS : $(C_OBJS)
  134. #.PRECIOUS : $(PROFILE)/$(CONFIG)/linker.cmd $(PROFILE)/$(CONFIG)/compiler.opt
  135.  
  136. # -------------------------------------------------
  137. # --- delete the implicit rules for object files --
  138. # -------------------------------------------------
  139. %.o : %.c
  140.  
  141.  
  142. # *****************************************************************************
  143. #
  144. #    Targets and Build Rules
  145. #
  146. # *****************************************************************************
  147.  
  148. # ---------------------------------------------------------------------
  149. # Default Rule
  150. # ------------
  151. #  - When called by the "parent" makefile, being the first rule in this
  152. #    file, this rule always runs
  153. #  - Depends upon ARM executable program
  154. #  - Echo's linefeed when complete; this target was added to
  155. #    prevent the parent makefile from generating an error if the
  156. #    ARM executable is already built and nothing needs to be done
  157. # ---------------------------------------------------------------------
  158. Default_Rule : $(PROGNAME)_$(PROFILE).Beagle
  159.     @echo
  160.  
  161.  
  162. # ---------------------------------------------------------------------
  163. # 1. Build Executable Rule  (.x)
  164. # ------------------------------
  165. #  - For reading convenience, we called this rule #1
  166. #  - The actual ARM executable to be built
  167. #  - Built using the object files compiled from all the C files in
  168. #    the current directory
  169. #  - linker.cmd is the other dependency, built by Configuro
  170. # ---------------------------------------------------------------------
  171. $(PROGNAME)_$(PROFILE).Beagle : $(C_OBJS)
  172.     @echo; echo "1.  ----- Need to generate executable file: $@ "
  173.     $(AT) $(CC) $(CFLAGS) $(LINKER_FLAGS) $^ -o $@
  174.     @echo "          Successfully created executable : $@ "
  175.  
  176.  
  177. # ---------------------------------------------------------------------
  178. # 2. Object File Rule (.o)
  179. # ------------------------
  180. #  - This was called rule #2
  181. #  - Pattern matching rule builds .o file from it's associated .c file
  182. #  - Since .o file is placed in $(PROFILE) directory, the rule includes
  183. #    a command to make the directory, just in case it doesn't exist
  184. #  - Unlike the TI DSP Compiler, gcc does not accept build options via
  185. #    a file; therefore, the options created by Configuro (in .opt file)
  186. #    must be included into the build command via the shell's 'cat' command
  187. # ---------------------------------------------------------------------
  188. $(PROFILE)/%.o : %.c
  189.     @echo "2.  ----- Need to generate:      $@ (due to: $(wordlist 1,1,$?) ...)"
  190.     $(AT) mkdir -p $(dir $@)
  191.     $(AT) $(CC) $(CFLAGS) $($(PROFILE)_CFLAGS) -c $< -o $@
  192.     @echo "          Successfully created:  $@ "
  193.  
  194.  
  195. # ---------------------------------------------------------------------
  196. # 3. Dependency Rule (.d)
  197. # -----------------------
  198. #  - Called rule #3 since it runs between rules 2 and 4
  199. #  - Created by the gcc compiler when using the -MM option
  200. #  - Lists all files that the .c file depends upon; most often, these
  201. #    are the header files #included into the .c file
  202. #  - Once again, we make the subdirectory it will be written to, just
  203. #    in case it doesn't already exist
  204. #  - For ease of use, the output of the -MM option is piped into the
  205. #    .d file, then formatted, and finally included (along with all
  206. #    the .d files) into this make script
  207. #  - We put the formatting commands into a make file macro, which is
  208. #    found towards the end of this file
  209. # ---------------------------------------------------------------------
  210. $(PROFILE)/%.d : %.c
  211.     @echo "3.  ----- Need to generate dep info for:        $< "
  212.     @echo "          Generating dependency file   :        $@ "
  213.     $(AT) mkdir -p $(PROFILE)
  214.     $(AT) $(CC) -MM $(CFLAGS) $($(PROFILE)_CFLAGS) $<   > $@
  215.  
  216.     @echo "          Formatting dependency file:           $@ "
  217.     $(AT) $(call format_d ,$@,$(PROFILE)/)
  218.     @echo "          Dependency file successfully created: $@ " ; echo
  219.  
  220.  
  221. # ---------------------------------------------------------------------
  222. # 4. Configuro Rule (.cfg)
  223. # ------------------------
  224. #  - The TI configuro tool can read (i.e. consume) RTSC packages
  225. #  - Many TI and 3rd Party libraries are packaged as Real Time Software
  226. #    Components (RTSC) - which includes metadata along with the library
  227. #  - To improve readability of this scripts feedback, the Configuro's
  228. #    feedback is piped into a a results log file
  229. #  - In the case where no .cfg file exists, this script makes an empty
  230. #    one using the shell's 'touch' command; in the case where this
  231. #    occurs, gMake will delete the file when the build is complete as
  232. #    is the case for all intermediate build files (note, we used the
  233. #    precious command earlier to keep certain intermediate files from
  234. #    being removed - this allows us to review them after the build)
  235. # ---------------------------------------------------------------------
  236. #$(PROFILE)/%/linker.cmd $(PROFILE)/%/compiler.opt : %.cfg
  237. #   @echo "4.  ----- Starting Configuro for $^  (note, this may take a minute)"
  238. #     ifdef DUMP
  239. #   $(AT) $(CONFIGURO) -c $(CC_ROOT) -t $(TARGET) -p $(PLATFORM) -r $(PROFILE) -o $(PROFILE)/$(CONFIG) $<
  240. #     else
  241. #   $(AT) mkdir -p $(PROFILE)/$(CONFIG)
  242. #   $(AT) $(CONFIGURO) -c $(CC_ROOT) -t $(TARGET) -p $(PLATFORM) -r $(PROFILE) -o $(PROFILE)/$(CONFIG) $< \
  243. #                > $(PROFILE)/$(CONFIG)_results.log
  244. #     endif
  245. #   @echo "          Configuro has completed; it's results are in $(CONFIG) " ; echo
  246.  
  247. # ---------------------------------------------------------------------
  248. # The "no" .cfg rule
  249. # ------------------
  250. #  - This additional rule creates an empty config file if one doesn't
  251. #    already exist
  252. #  - See the Configuro rule comments above for more details
  253. # ---------------------------------------------------------------------
  254. #%.cfg :
  255. #   $(AT) touch $(CONFIG).cfg
  256.  
  257.  
  258. # *****************************************************************************
  259. #
  260. #    "Phony" Rules
  261. #
  262. # *****************************************************************************
  263.  
  264. # ---------------------------------------------------------------------
  265. #  "all" Rule
  266. # -----------
  267. #   - Provided in case the a user calls the commonly found "all" target
  268. #  - Called a Phony rule since the target (i.e. "all") doesn't exist
  269. #    and shouldn't be searched for by gMake
  270. # ---------------------------------------------------------------------
  271. .PHONY  : all
  272. all : $(PROGNAME)_$(PROFILE).Beagle
  273.     @echo ; echo "The target ($<) has been built."
  274.     @echo
  275.  
  276.  
  277. # ---------------------------------------------------------------------
  278. #  "clean" Rule
  279. # -------------
  280. #  - Cleans all files associated with the $(PROFILE) specified above or
  281. #    via the command line
  282. #  - Cleans the associated files in the containing folder, as well as
  283. #    the ARM executable files copied by the "install" rule
  284. #  - EXEC_DIR is specified in the included 'setpaths.mak' file
  285. #  - Called a Phony rule since the target (i.e. "clean") doesn't exist
  286. #    and shouldn't be searched for by gMake
  287. # ---------------------------------------------------------------------
  288. .PHONY : clean
  289. clean  :
  290.     @echo ; echo "--------- Cleaning up files for $(PROFILE) -----"
  291.     rm -rf $(PROFILE)
  292.     rm -rf $(PROGNAME)_$(PROFILE).Beagle
  293. #   rm -rf $(EXEC_DIR)/$(PROGNAME)_$(PROFILE).Beagle
  294.     rm -rf $(C_DEPS)
  295.     rm -rf $(C_OBJS)
  296.     @echo
  297.  
  298.  
  299. # ---------------------------------------------------------------------
  300. #  "install" Rule
  301. # ---------------
  302. #  - The install target is a common name for the rule used to copy the
  303. #    executable file from the build directory, to the location it is
  304. #    to be executed from
  305. #  - Once again, a phony rule since we don't have an actual target file
  306. #    named 'install' -- so, we don't want gMake searching for one
  307. #  - This rule depends upon the ARM executable file (what we need to
  308. #    copy), therefore, it is the rule's dependency
  309. #  - We make the execute directory just in case it doesn't already
  310. #    exist (otherwise we might get an error)
  311. #  - EXEC_DIR is specified in the included 'setpaths.mak' file; in our
  312. #    target system (i.e. the DVEVM board), we will use /opt/workshop as
  313. #    the directory we'll run our programs from
  314. # ---------------------------------------------------------------------
  315. .PHONY  : install
  316. install : $(PROGNAME)_$(PROFILE).Beagle
  317.     @echo
  318.     @echo  "0.  ----- Installing $(PROGNAME)_$(PROFILE).Beagle to 'Execution Directory' -----"
  319.     @echo  "          Execution Directory:  $(EXEC_DIR)"
  320. #   $(AT) mkdir -p $(EXEC_DIR)
  321. #   $(AT) cp    $^ $(EXEC_DIR)
  322.     cp $^ ${HOME}/Desktop
  323.     @echo  "          Install (i.e. copy) has completed" ; echo
  324.  
  325. # *****************************************************************************
  326. #
  327. #    Macros
  328. #
  329. # *****************************************************************************
  330. # format_d
  331. # --------
  332. #  - This macro is called by the Dependency (.d) file rule (rule #3)
  333. #  - The macro copies the dependency information into a temp file,
  334. #    then reformats the data via SED commands
  335. #  - Two variations of the rule are provided
  336. #     (a) If DUMP was specified on the command line (and thus exists),
  337. #         then a warning command is embed into the top of the .d file;
  338. #         this warning just lets us know when/if this .d file is read
  339. #     (b) If DUMP doesn't exist, then we build the .d file without
  340. #         the extra make file debug information
  341. # ---------------------------------------------------------------------
  342. ifdef DUMP
  343.   define format_d
  344.    @# echo " Formatting dependency file: $@ "
  345.    @# echo " This macro has two parameters: "
  346.    @# echo "   Dependency File (.d): $1     "
  347.    @# echo "   Profile: $2                  "
  348.    @mv -f $1 $1.tmp
  349.    @echo '$$(warning --- Reading from included file: $1 ---)' > $1
  350.    @sed -e 's|.*:|$2$*.o:|' < $1.tmp >> $1
  351.    @rm -f $1.tmp
  352.   endef
  353. else
  354.   define format_d
  355.    @# echo " Formatting dependency file: $@ "
  356.    @# echo " This macro has two parameters: "
  357.    @# echo "   Dependency File (.d): $1     "
  358.    @# echo "   Profile: $2                  "
  359.    @mv -f $1 $1.tmp
  360.    @sed -e 's|.*:|$2$*.o:|' < $1.tmp > $1
  361.    @rm -f $1.tmp
  362.   endef
  363. endif
  364.  
  365.  
  366. # *****************************************************************************
  367. #
  368. #    (Late) Include files
  369. #
  370. # *****************************************************************************
  371. #  Include dependency files
  372. # -------------------------
  373. #  - Only include the dependency (.d) files if "clean" is not specified
  374. #    as a target -- this avoids an unnecessary warning from gMake
  375. #  - C_DEPS, which was created near the top of this script, includes a
  376. #    .d file for every .c file in the project folder
  377. #  - With C_DEPS being defined recursively via the "=" operator, this
  378. #    command iterates over the entire array of .d files
  379. # ---------------------------------------------------------------------
  380. ifneq ($(filter clean,$(MAKECMDGOALS)),clean)
  381.   -include $(C_DEPS)
  382. endif
  383.  
  384.  
  385. # *****************************************************************************
  386. #
  387. #    Additional Debug Information
  388. #
  389. # *****************************************************************************
  390. #  Prints out build & variable definitions
  391. # ----------------------------------------
  392. #  - While not exhaustive, these commands print out a number of
  393. #    variables created by gMake, or within this script
  394. #  - Can be useful information when debugging script errors
  395. #  - As described in the 2nd warning below, set DUMP=1 on the command
  396. #    line to have this debug info printed out for you
  397. #  - The $(warning ) gMake function is used for this rule; this allows
  398. #    almost anything to be printed out - in our case, variables
  399. # ---------------------------------------------------------------------
  400.  
  401. ifdef DUMP
  402.   $(warning To view build commands, invoke make with argument 'AT= ')
  403.   $(warning To view build variables, invoke make with 'DUMP=1')
  404.  
  405.   $(warning Source Files: $(C_SRCS))
  406.   $(warning Object Files: $(C_OBJS))
  407.   $(warning Depend Files: $(C_DEPS))
  408.  
  409.   $(warning Base program name : $(PROGNAME))
  410.   $(warning Configuration file: $(CONFIG))
  411.   $(warning Make Goals        : $(MAKECMDGOALS))
  412.  
  413.   $(warning Xdcpath :  $(XDCPATH))
  414.   $(warning Target  :  $(TARGET))
  415.   $(warning Platform:  $(PLATFORM))
  416. endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement