/host/resource/osconfig/tcl/prj_vxWorks.tcl

https://bitbucket.org/frc-cpp11/windriver-headers-package-deb · TCL · 2734 lines · 1612 code · 524 blank · 598 comment · 320 complexity · 50fa1c991ecaa4a432694e71675bfaec MD5 · raw file

  1. # prj_vxWorks.tcl - vxWorks project library
  2. #
  3. #
  4. # Copyright (c) 1984-2006 Wind River Systems, Inc.
  5. #
  6. # The right to copy, distribute, modify or otherwise make use
  7. # of this software may be licensed only pursuant to the terms
  8. # of an applicable Wind River license agreement.
  9. #
  10. #
  11. # modification history
  12. # --------------------
  13. # 02m,21Mar06,pee SPR 119127. Fixed path returned by Wind::tgtDir
  14. # 02n,14Mar06,pee added switch for scaling down BSPs. SPR 119056
  15. # 02m,06Feb06,pee adding support for linker symbol definitions.
  16. # 05l,27jan06,pee fixing problem with MACRO_NEST.
  17. # 05k,09jan06,pee modified handling of config.h at creation to better
  18. # support scalable BSPs. Also support components that
  19. # witn name that don't start with INCLUDE*
  20. # creation now return project handle instead of closing.
  21. # 05j,30sep05,pee fixed last fix.
  22. # 05i,28sep05,pee added project path to resolve header file 112722 & 112947
  23. # 05h,27sep05,pee new variable for cpu variants
  24. # 05g,05sep05,pee added support for Bsp type for scalable BSPs
  25. # 05f,30aug05,pee improved CPU variant support for source build
  26. # 05e,15aug05,pee added depend target in Makefile. Cleaned clean rule.
  27. # 05d,08Aug05,pee Updated source build functionality.
  28. # 05d,17jul05,zhr Added interface to enable building from source
  29. # 05c,07jul05,pee fixed pattern matching for headerMacros
  30. # Added comObjs.lst to Makefile, MODULE support in source build
  31. # Fixed pattern matching issue introduced with Jun20 optimizations
  32. # 05b,22jun05,zhr Updated for a scalability build from the sources
  33. # 05a,24Jun05,pee added source file to custom build rule.
  34. # 04z,20Jun05,pee No more file dependencies in Makefile
  35. # some regsub optimization
  36. # inclusion of INCLUDE_BSP for Puma prototype
  37. # 04y,15apr05,yvp Added usrRtpAppInit.c to project (SPR 105759).
  38. # 04x,15apr05,pee fixed typo, SPR 108031
  39. # 04w,23dec04,c_c removed references to foundation.
  40. # 04v,14dec04,fle SPR#103719 : dump all dependencies in the Makefile. Do not
  41. # hide taget h files ones anymore
  42. # 04u,08sep04,fle SPR#88074 : Make it use prjMakefile
  43. # + history cleanup
  44. # 04t,31aug04,pch Ensure all CC_ARCH_SPEC settings are in CFLAGS and CFLAGS_AS
  45. # 04s,08aug04,dlk Added minimal option build support.
  46. # 04r,09aug04,fle SPR#100158 : usrRtpAppInit.c is not copied when copying a
  47. # project
  48. # 04q,28jul04,fle SPR#99081 : fixed LD_LINK_PATH parsing in Makefile
  49. # 04p,22jul04,fle SPR#92405 : added prj_vxWorks::buildDirGet
  50. # 04o,09jul04,c_c Removed romfs_image.h copy.
  51. # 04r,09aug04,fle SPR#100158 : usrRtpAppInit.c is not copied when copying a
  52. # project
  53. # 04q,28jul04,fle SPR#99081 : fixed LD_LINK_PATH parsing in Makefile
  54. # 04p,22jul04,fle SPR#92405 : added prj_vxWorks::buildDirGet
  55. # 04o,09jul04,c_c Removed romfs_image.h copy.
  56. # 04o,02jul04,fle Make the adrs macros retrived through a call to make
  57. # adrsMacros
  58. # 04n,18may04,fle Do not use file copy on read-only files on Linux
  59. # 04m,11may04,fle Added CPP, LD_PARTIAL and LD_PARTIAL_FLAGS to the list of
  60. # skipped macros in project creation
  61. # 04l,10may04,fle Remove romfs_image.h after dependencies are generated
  62. # 04k,26apr04,fle Do not use relPath on setting of TGT_DIR in the generated
  63. # Makefile
  64. # 04j,09apr04,fle SPR#94279 : made it possible to use macros/environment
  65. # variables with CONFIGLETTES declaration
  66. # 04i,07apr04,fle SPR#95255 : added vpath for .s files too
  67. # + do not use [file copy ...] for Linux hosts troubles
  68. # 04h,26mar04,yvp Added RTP startup facility support.
  69. # 04g,26feb04,fle SPR#94359 : introduce PROTOTYPE handling
  70. # SPR#92845 : made bspMakeParse understand += statements
  71. # 04f,17feb04,fle Use packages
  72. # 04e,30jan04,fle SPR#92678 : touch a romfs_image.h file in the project
  73. # directory if the INCLUDE_ROMFS component is defined
  74. # + final fix for SPR#93114
  75. # 04d,13jan04,c_c temporary fix for SPR 93114.
  76. # 04c,25nov03,fle Better use Wind::tgtDir that Wind::base/target
  77. # 04c,18nov03,rp added include for h/wrn/coreip
  78. # 04b,18nov03,fle SPR#66928 : prjFileAdd now takes care of romInit,s and
  79. # romStart.c settings
  80. # 04a,29sep03,dat TEMP fix to add -D_WRS_KERNEL to CFLAGS
  81. # 03z,25sep03,pes Fix MIPS builds by removing extra backslashes.
  82. # 03y,05sep03,fle SPR#84899 : do not use make -C, rather change directory
  83. # first
  84. # 03x,03sep03,fle SPR#90391 : Fixed romStart and romInit rules
  85. # 03w,02sep03,fle SPR#88279 : fixed BSP_STUB not retrieved correctly
  86. # 03v,28aug03,fle SPR#84803 : do not add INCLUDE_ARP_API in macrosToComponents
  87. # 03u,18aug03,fle SPR#72109 fix : do not blindly delete project directory
  88. # when project creation failed
  89. # 03t,01jul03,fle fixed generated componentLibs since it uses Wind::base
  90. # 03s,19jun03,fle Updated to new location
  91. # 03r,25feb03,fle fixed classes use
  92. # 03q,29may03,pch add CPU_VARIANT to CFLAGS and CFLAGS_AS
  93. # 03p,03feb03,rbl fix problems parsing headerMacros arising from last fix
  94. # 03o,28jan03,rbl Fis spr 34798: Project Facility incorrectly transfers
  95. # NETIF_USR_ENTRIES from config.h.
  96. # 01a,18mar98,ms written.
  97. #
  98. # DESCRIPTION
  99. # This library adds vxWorks project handling to the generic project
  100. # management library.
  101. # It adds the following things that are specific to vxWorks:
  102. # * Project make-macros like RAM_LOW_ADRS, etc. These macros
  103. # are stored in the project under the tag VXWORKS_MAKE_MACRO
  104. # * Component configurations. These are stored under the tag
  105. # VXWORKS_COMPONENTS_<name>.
  106. #
  107. package provide PrjLib
  108. package require PrjUtils
  109. package require Wind
  110. # Call to the boot application for bootroms
  111. proc bootAppGet {} {
  112. return {taskSpawn ("tBoot", BOOT_LOADER_PRIORITY, \
  113. BOOT_LOADER_OPTIONS, BOOT_LOADER_STACK, bootCmdLoop, \
  114. 0,0,0,0,0,0,0,0,0,0);}
  115. }
  116. # List of components that must be stripped for a bootrom
  117. proc stripCompsGet {} {
  118. set cmps {
  119. INCLUDE_DEBUG \
  120. INCLUDE_DOS_DISK \
  121. INCLUDE_ENV_VARS \
  122. INCLUDE_FLOATING_POINT \
  123. INCLUDE_FORMATTED_IO \
  124. INCLUDE_HW_FP \
  125. INCLUDE_LOADER \
  126. INCLUDE_LPT \
  127. INCLUDE_MMU_BASIC \
  128. INCLUDE_MMU_FULL \
  129. INCLUDE_NET_INIT \
  130. INCLUDE_NTPASSFS \
  131. INCLUDE_PASSFS \
  132. INCLUDE_POSIX_AIO \
  133. INCLUDE_POSIX_MQ \
  134. INCLUDE_POSIX_SEM \
  135. INCLUDE_POSIX_SIGNALS \
  136. INCLUDE_SELECT \
  137. INCLUDE_SHOW_ROUTINES \
  138. INCLUDE_SIGNALS \
  139. INCLUDE_SM_OBJ \
  140. INCLUDE_SPY \
  141. INCLUDE_SW_FP \
  142. INCLUDE_SYM_TBL \
  143. INCLUDE_STANDALONE_SYM_TBL \
  144. INCLUDE_NET_SYM_TBL \
  145. INCLUDE_STAT_SYM_TBL \
  146. INCLUDE_CTORS_DTORS \
  147. INCLUDE_CPLUS \
  148. INCLUDE_CPLUS_MIN \
  149. INCLUDE_HTTP \
  150. INCLUDE_RBUFF \
  151. INCLUDE_WINDVIEW \
  152. INCLUDE_SHELL \
  153. INCLUDE_SECURITY \
  154. INCLUDE_DEMO \
  155. INCLUDE_UGL \
  156. INCLUDE_JAVA \
  157. INCLUDE_HTML \
  158. INCLUDE_SYM_TBL_SYNC \
  159. INCLUDE_TIMEX \
  160. INCLUDE_WDB \
  161. INCLUDE_WINDMP \
  162. USER_B_CACHE_ENABLE \
  163. USER_D_CACHE_ENABLE \
  164. USER_I_CACHE_ENABLE ;# (for sparc and x86 only ???) \
  165. }
  166. return $cmps
  167. }
  168. # List of components that must in a bootrom
  169. proc addCompsGet {} {
  170. set comps {
  171. INCLUDE_CACHE_SUPPORT \
  172. INCLUDE_EXC_HANDLING \
  173. INCLUDE_IO_SYSTEM \
  174. INCLUDE_LOGGING \
  175. INCLUDE_MEM_MGR_FULL \
  176. INCLUDE_PIPES \
  177. INCLUDE_USER_APPL \
  178. }
  179. }
  180. ################################################################################
  181. #
  182. # cpuAndToolFromBspGet - get default CPU and TOOL from a bsp Makefile
  183. #
  184. # This function quickly parses the bsp Makefile. It does not use
  185. # make makeMacros, simply for speed reasons.
  186. #
  187. # PARAMETERS
  188. # bspDir: bsp directory
  189. #
  190. # RETURNS: {<CPU> <TOOL>}, e.g. {PPC603 gnu}
  191. #
  192. proc cpuAndToolFromBspGet {bspDir} {
  193. set makeFd [open [file join $bspDir Makefile] r]
  194. set cpu ""
  195. set tool ""
  196. while {[gets $makeFd line] >= 0} {
  197. if {![regexp {^ *include .*} $line] && \
  198. ![regexp {^ *#.*} $line] && \
  199. ![regexp {^ +$} $line] && \
  200. [string length $line] != 0 } {
  201. # look for lines of the form "macro = value"
  202. if {[regexp {([^=]*)=(.*)} $line dummy macro val] != 1} {
  203. continue
  204. }
  205. set macro [string trim $macro]
  206. set val [string trim $val]
  207. # make sure "macro" has no spaces (i.e., really a macro definition)
  208. if {[regexp {.*[ ]+.*} $macro] == 1} {
  209. continue
  210. }
  211. if {$macro == "CPU"} {
  212. set cpu $val
  213. }
  214. if {$macro == "TOOL"} {
  215. set tool $val
  216. }
  217. if {$cpu != "" && $tool != ""} {
  218. break
  219. }
  220. }
  221. }
  222. close $makeFd
  223. return [list $cpu $tool]
  224. }
  225. source [file join [Wind::base] host resource osconfig tcl wccLib.tcl]
  226. namespace eval ::prj_vxWorks_hidden {
  227. ############################################################################
  228. #
  229. # preciousComponents - return list of components that should not be removed
  230. #
  231. proc preciousComponents {} {
  232. return [list INCLUDE_SYSHW_INIT INCLUDE_SYS_START \
  233. INCLUDE_MEM_MGR_BASIC INCLUDE_SYSCLK_INIT INCLUDE_KERNEL]
  234. }
  235. ############################################################################
  236. #
  237. # basedOnSimulator - is this project based on a simulator bsp?
  238. #
  239. # RETURNS: 1 if based on simulator, 0 otherwise
  240. #
  241. # PARAMETERS
  242. # hProj: project handle
  243. #
  244. # ERRORS: N / A
  245. #
  246. proc basedOnSimulator {hProj} {
  247. set simulators [list hpux solaris simpc]
  248. set bsp [file tail [prjTagDataGet $hProj BSP_DIR]]
  249. if {[lsearch $simulators $bsp] == -1} {
  250. return 0
  251. } else {
  252. return 1
  253. }
  254. }
  255. ############################################################################
  256. #
  257. # autoscale - return info on how to scale vxWorks to the application
  258. #
  259. # RETURNS: a list of required INCLUDES
  260. #
  261. #
  262. # The verbose mode option helps track down why extra components
  263. # are required by the application modules.
  264. # Verbose mode returns a list of lists. The first list is
  265. # the required INCLUDES.
  266. # The subsequent lists are of the form:
  267. # {appModule libSymsExtra libModulesExtra componentsExtra}
  268. # Where appModule is an application object module.
  269. # libSymsExtra is a list of symbols it imports from the archive, which
  270. # would not otherwise be pulled in by the component configuration.
  271. # libModulesExtra is the set of modules in the archive that are linked
  272. # in, which would not otherwize be pulled in by the component configuration.
  273. # componentsExtra is the set of extra components being pulled in.
  274. #
  275. # set throwErrors <> "" to cause any build errors to throw an error
  276. #
  277. proc autoscale {hProj {verbose ""} {throwErrors ""}} {
  278. set prjDir [file dirname [prjInfoGet $hProj fileName]]
  279. set build [prjBuildCurrentGet $hProj]
  280. set wcc [wccCurrentGet $hProj]
  281. set tc [prjBuildTcGet $hProj $build]
  282. set libs [concat [wccMxrLibsGet $hProj] \
  283. [prjBuildMacroGet $hProj $build LIBS]]
  284. set libs [mxrLibsExpand $hProj $libs $tc]
  285. # build project objects and analyze them with the libraries
  286. prjStatusLog "compiling project objects..."
  287. if {[catch {prjBuild $hProj partialImage.o "" complain} errorMsg]} {
  288. if {$throwErrors != ""} {
  289. error $errorMsg
  290. }
  291. }
  292. foreach obj [lindex [objsGet $hProj] 0] {
  293. lappend objs [file join $prjDir $build $obj]
  294. }
  295. regsub -all {[^ ]*((prjConfig.o)|(linkSyms.o)|(partialImage.o))} \
  296. $objs {} objs
  297. set objs "$objs [prjBuildMacroGet $hProj $build EXTRA_MODULES]"
  298. prjStatusLog "analyzing module dependencies..."
  299. set modDataDoc [modAnalyze "$objs $libs" [${tc}::name]]
  300. # compute modules and components requires by project objects
  301. set mxrDoc [mxrDocCreate $hProj]
  302. set cxrDoc [cxrDocCreate $hProj]
  303. set cxrSet [$cxrDoc setCreate]
  304. $cxrSet = [set modSubtree [modSubtree $modDataDoc $objs]]
  305. $cxrSet = "[$cxrSet get _MODULES] [preciousComponents]"
  306. set includes [cxrSubtree $cxrSet $mxrDoc]
  307. # in verbose mode, tell why these components are included
  308. if {"$verbose" == "verbose"} {
  309. set mxrSet [$mxrDoc setCreate]
  310. $cxrSet = [wccComponentListGet $hProj $wcc]
  311. $mxrSet = [cSymsMangle \
  312. "[$cxrSet get LINK_SYMS] [$cxrSet get LINK_DATASYMS]" $tc]
  313. $mxrSet = [$mxrSet get exportedBy]
  314. $mxrSet = [$mxrSet + [$cxrSet get MODULES]]
  315. set componentModules [mxrSubtree $mxrSet]
  316. $mxrSet = $componentModules
  317. set librarySyms "[$mxrSet get exports] [$mxrSet get declares]"
  318. set includes [list $includes]
  319. foreach usrMod $objs {
  320. $mxrSet = [modInfo $modDataDoc $usrMod imports]
  321. $mxrSet = [$mxrSet - $librarySyms]
  322. set syms [lsort [$mxrSet instances Symbol]]
  323. if {"$syms" == ""} {
  324. continue
  325. }
  326. $mxrSet = [modCalls $modDataDoc $usrMod]
  327. set definingModules [$mxrSet - "$objs $componentModules"]
  328. if {"$definingModules" == ""} {
  329. continue
  330. }
  331. $mxrSet = [modSubtree $mxrDoc $definingModules]
  332. $mxrSet = [$mxrSet - $componentModules]
  333. set modules [lsort [$mxrSet instances Module]]
  334. $cxrSet = $modules
  335. $cxrSet = [$cxrSet get _MODULES]
  336. $cxrSet = [$cxrSet - [wccComponentListGet $hProj $wcc]]
  337. set components [lsort [$cxrSet instances Component]]
  338. lappend includes [list $usrMod $syms $modules $components]
  339. }
  340. $mxrSet delete
  341. $modDataDoc delete
  342. }
  343. $cxrSet delete
  344. return $includes
  345. }
  346. ############################################################################
  347. #
  348. # macrosToComponents - translate old INCLUDE_* macros to components
  349. #
  350. proc macrosToComponents {macros hProj} {
  351. set cmpLib [cxrDocCreate $hProj]
  352. set cmpSet [$cmpLib setCreate]
  353. # remove components with missing nested macros (e.g., INCLUDE_AOUT is
  354. # not included unless it's nested macro, INCLUDE_LOADER, is also defined
  355. # This is faster, but requires MACRO_NEST be an association
  356. # set cmpSet2 [$cmpLib setCreate]
  357. # $cmpSet = $macros
  358. # $cmpSet2 = [$cmpSet get _MACRO_NEST]
  359. # $cmpSet2 = [$cmpSet2 - $macros]
  360. # $cmpSet2 = [$cmpSet2 get MACRO_NEST]
  361. # puts "XXX - removing nested components [$cmpSet2 contents]"
  362. # set components [$cmpSet - $cmpSet2]
  363. # $cmpSet2 delete
  364. set components ""
  365. foreach macro $macros {
  366. # skip if nested
  367. $cmpSet = $macro
  368. set nestedMacros [$cmpSet get MACRO_NEST]
  369. if {"$nestedMacros" != ""} {
  370. set included true
  371. foreach nestedMacro $nestedMacros {
  372. if {[lsearch $macros $nestedMacro] == -1} {
  373. set included false
  374. break
  375. }
  376. }
  377. if {"$included" == "false"} {
  378. continue
  379. }
  380. }
  381. lappend components $macro
  382. }
  383. # add in new components as needed
  384. set components [concat $components [preciousComponents]]
  385. if {[lsearch $components INCLUDE_SHELL] != -1} {
  386. lappend components INCLUDE_SHELL_BANNER
  387. }
  388. if {[set ix [lsearch $components INCLUDE_ANSI_ALL]] != -1} {
  389. set components [lreplace $components $ix $ix]
  390. set components [concat $components \
  391. INCLUDE_ANSI_ASSERT \
  392. INCLUDE_ANSI_CTYPE \
  393. INCLUDE_ANSI_LOCALE \
  394. INCLUDE_ANSI_MATH \
  395. INCLUDE_ANSI_STDIO \
  396. INCLUDE_ANSI_STDLIB \
  397. INCLUDE_ANSI_STRING \
  398. INCLUDE_ANSI_TIME \
  399. INCLUDE_ANSI_STDIO_EXTRA]
  400. }
  401. if {[set ix [lsearch $components INCLUDE_POSIX_ALL]] != -1} {
  402. set components [lreplace $components $ix $ix]
  403. set components [concat $components \
  404. INCLUDE_POSIX_AIO \
  405. INCLUDE_POSIX_AIO_SYSDRV \
  406. INCLUDE_POSIX_FTRUNC \
  407. INCLUDE_POSIX_MEM \
  408. INCLUDE_POSIX_MQ \
  409. INCLUDE_POSIX_SCHED \
  410. INCLUDE_POSIX_SEM \
  411. INCLUDE_POSIX_SIGNALS \
  412. INCLUDE_POSIX_TIMERS \
  413. INCLUDE_POSIX_CLOCKS]
  414. }
  415. if {[set ix [lsearch $components INCLUDE_CONFIGURATION_5_2]] != -1} {
  416. set components [lreplace $components $ix $ix]
  417. set components [concat $components \
  418. INCLUDE_LOADER \
  419. INCLUDE_NET_SYM_TBL \
  420. INCLUDE_RLOGIN \
  421. INCLUDE_SHELL \
  422. INCLUDE_SHOW_ROUTINES \
  423. INCLUDE_SPY \
  424. INCLUDE_STARTUP_SCRIPT \
  425. INCLUDE_STAT_SYM_TBL \
  426. INCLUDE_SYM_TBL \
  427. INCLUDE_TELNET \
  428. INCLUDE_UNLOADER \
  429. INCLUDE_DEBUG]
  430. }
  431. if {([lsearch $macros INCLUDE_TTY_DEV] != -1) && \
  432. ([lsearch $macros INCLUDE_TYCODRV_5_2] == -1)} {
  433. lappend components INCLUDE_SIO
  434. }
  435. # remove obsolete INCLUDE_* macros
  436. set obsolete {(INCLUDE_RDB)|(INCLUDE_DELETE_5_0)|(INCLUDE_ANSI_5_0)|(INCLUDE_SEM_OLD)|(INCLUDE_CPLUS_BOOCH)|(INCLUDE_CPLUS_HEAP)|(INCLUDE_MC68881)|(INCLUDE_SPARC_FPU)|(INCLUDE_R3010)|(INCLUDE_PPC_FPU)|(INCLUDE_I80387)}
  437. regsub -all $obsolete $components "" components
  438. # warn user of any unknown INCLUDE_* macros still left
  439. $cmpSet = $components
  440. set unknowns [$cmpSet - [$cmpSet instances]]
  441. if {[llength $unknowns] > 0} {
  442. prjWarnLog "ignoring unknown components $unknowns"
  443. }
  444. if {[$cmpSet & INCLUDE_CACHE_SUPPORT] == "INCLUDE_CACHE_SUPPORT"} {
  445. lappend components INCLUDE_CACHE_ENABLE
  446. }
  447. set components [format "%s" [$cmpSet instances]]
  448. # XXX : fle : since we switched to Tcl 8.4.1, there seem to be a glitch
  449. # in the cxrDoc, and just using an intermediate variable for components
  450. # seems to fix it. I should dig in the cxrDoc instances to understand
  451. # why it it fails with : Tcl_ListObjAppendElement called with shared
  452. # object
  453. lappend components INCLUDE_BOOT_LINE_INIT
  454. # remove all networking subcomponents if INCLUDE_NETWORK is not defined.
  455. # add INCLUDE_IP (new) if INCLUDE_NETWORK is defined.
  456. set cmps [$cmpSet setCreate]
  457. if {[$cmpSet & INCLUDE_NETWORK] != "INCLUDE_NETWORK"} {
  458. $cmps = FOLDER_NETWORK
  459. $cmps = [cxrSubfolders $cmps]
  460. set components [$cmpSet - [$cmps instances Component]]
  461. } else {
  462. if {[$cmpSet & INCLUDE_WDB_COMM_NETWORK] == \
  463. "INCLUDE_WDB_COMM_NETWORK"} {
  464. $cmps = INCLUDE_WDB_SYS
  465. set mxrDoc [mxrDocCreate $hProj]
  466. $cmps = [cxrSupertree $cmps $mxrDoc $components]
  467. set components [$cmpSet - [$cmps instances Component]]
  468. }
  469. if {[$cmpSet & INCLUDE_END] != "INCLUDE_END"} {
  470. lappend components INCLUDE_BSD
  471. }
  472. set components [concat $components [list INCLUDE_IP \
  473. INCLUDE_LOOPBACK \
  474. INCLUDE_NET_HOST_SETUP]]
  475. }
  476. $cmps delete
  477. $cmpSet delete
  478. return $components
  479. }
  480. ############################################################################
  481. #
  482. # bspVxOsLibsGet - get macro VX_OS_LIBS from bsp
  483. #
  484. proc bspVxOsLibsGet {hProj bspDir {cpuType ""} {toolType ""}} {
  485. variable makeMacrosReferred
  486. set build [prjBuildCurrentGet $hProj]
  487. set opt [prjBuildMacroGet $hProj $build OPT]
  488. set index "$hProj,$cpuType,$toolType,$opt"
  489. # use cached information if possible
  490. if {[info exists makeMacrosReferred($index,VX_OS_LIBS)]} {
  491. return $makeMacrosReferred($index,VX_OS_LIBS)
  492. }
  493. # SPR#84899 : change directory first, and do not use 'make -C'
  494. set makeCmd "make makeMacrosReferred BSP2PRJ=TRUE"
  495. if {$opt != ""} {
  496. set makeCmd "$makeCmd OPT=$opt"
  497. }
  498. if {$cpuType != ""} {
  499. set makeCmd "$makeCmd CPU=$cpuType"
  500. }
  501. if {$toolType != ""} {
  502. set makeCmd "$makeCmd TOOL=$toolType"
  503. }
  504. # If any of the exec'd commands writes to standard error
  505. # (e.g. a compiler warning) and standard error isn't redirected,
  506. # then exec will return an error. To avoid this we use
  507. # "2>@ stderr", which redirects standard error to
  508. # standard error. This has no effect other than to prevent
  509. # exec from returning an error on e.g. a compiler warning
  510. # SPR#84899 : change directory first, and do not use 'make -C'
  511. set oldPath [pwd]
  512. cd $bspDir
  513. if {[catch {set lines "[eval exec $makeCmd 2>@ [prjStderr]]"} err]} {
  514. catch {eval exec $makeCmd} err
  515. cd $oldPath
  516. error "$err\n\"$makeCmd\" failed"
  517. }
  518. cd $oldPath
  519. foreach line [split $lines \n] {
  520. if {[regsub {[^=]*=} $line {} val] != 1} {
  521. continue
  522. }
  523. set macro [lindex $line 1]
  524. set val [string trim $val]
  525. ::filePathFix val
  526. set makeMacrosReferred($index,$macro) $val
  527. }
  528. if {![info exists makeMacrosReferred($index,VX_OS_LIBS)]} {
  529. set makeMacrosReferred($index,VX_OS_LIBS) ""
  530. }
  531. return $makeMacrosReferred($index,VX_OS_LIBS)
  532. }
  533. ############################################################################
  534. #
  535. # bspMakeParse - parse a BSP Makefile
  536. #
  537. proc bspMakeParse {bspDir {cpuType ""} {toolType ""} {opt ""} } {
  538. variable makeMacros
  539. if {[info exists makeMacros]} {
  540. unset makeMacros
  541. }
  542. # SPR#84899 : change directory first, and do not use 'make -C'
  543. set makeCmd "make makeMacros BSP2PRJ=TRUE"
  544. if {$cpuType != ""} {
  545. set makeCmd "$makeCmd CPU=$cpuType"
  546. }
  547. if {$toolType != ""} {
  548. set makeCmd "$makeCmd TOOL=$toolType"
  549. }
  550. if {$opt != ""} {
  551. set makeCmd "$makeCmd OPT=$opt"
  552. }
  553. # If any of the exec'd commands writes to standard error
  554. # (e.g. a compiler warning) and standard error isn't redirected,
  555. # then exec will return an error. To avoid this we use
  556. # "2>@ stderr", which redirects standard error to
  557. # standard error. This has no effect other than to prevent
  558. # exec from returning an error on e.g. a compiler warning
  559. # SPR#84899 : change directory first, and do not use 'make -C'
  560. set oldPath [pwd]
  561. cd $bspDir
  562. if {[catch {set lines "[eval exec $makeCmd 2>@ [prjStderr]]"} err]} {
  563. catch {eval exec $makeCmd} err
  564. cd $oldPath
  565. error "$err\n\"$makeCmd\" failed"
  566. }
  567. cd $oldPath
  568. foreach line [split $lines \n] {
  569. if {[regsub {[^=]*=} $line {} val] != 1} {
  570. continue
  571. }
  572. set macro [lindex $line 1]
  573. set val [string trim $val]
  574. if {$macro == "LIBS"} {
  575. # convert relative paths
  576. ::filePathFix val
  577. set libs ""
  578. foreach lib $val {
  579. if {[file exists [file join $bspDir $lib]]} {
  580. set lib [file join $bspDir $lib]
  581. }
  582. lappend libs $lib
  583. }
  584. set makeMacros(LIBS) $libs
  585. continue
  586. }
  587. if {$macro == "LD_LINK_PATH"} {
  588. # fix paths
  589. ::filePathFix val
  590. set makeMacros(LD_LINK_PATH) $val
  591. continue
  592. }
  593. set makeMacros($macro) $val
  594. }
  595. # Macro list that we do not want to add to project
  596. set macroToSkip [list CPU TOOL TOOL_FAMILY BOARD TGT_DIR SED RELEASE \
  597. TARGET_DIR VENDOR LD_LOW_FLAGS]
  598. set makeFd [open [file join $bspDir Makefile] r]
  599. set switchLowHigh ""
  600. while {[gets $makeFd line] >= 0} {
  601. if {(![regexp {^ *include .*} $line]) && \
  602. (![regexp {^ *#.*} $line]) && \
  603. (![regexp {^ +$} $line]) && \
  604. ([string length $line] != 0) } {
  605. # look for lines of the form "macro = value"
  606. set addedValue ""
  607. set addValue 0
  608. if {![regexp {([^\+]*)\+=(.*)} $line dummy macro addedValue]} {
  609. if {[regexp {([^=]*)=(.*)} $line dummy macro val] != 1} {
  610. continue
  611. }
  612. } else {
  613. set val $addedValue
  614. set addValue 1
  615. }
  616. set macro [string trim $macro]
  617. set val [string trim $val]
  618. # make sure "macro" has no spaces (i.e., really a macro
  619. # definition)
  620. if {[regexp {.*[ ]+.*} $macro] == 1} {
  621. continue
  622. }
  623. # concatanate lines ending in a backslash
  624. while {[lindex $val end] == "\\"} {
  625. set val [string trimright $val "\\"]
  626. gets $makeFd line
  627. append val " " [string trim $line]
  628. }
  629. # XXX : fle : I am afraid this does not work. I think we should
  630. # test on LD_RAM_FLAGS macro, not LD_LOW_FLAGS
  631. if {$macro == "LD_LOW_FLAGS"} {
  632. if {$val == "LD_HIGH_FLAGS"} {
  633. set switchLowHigh true
  634. continue
  635. }
  636. set makeMacros(LD_RAM_FLAGS) $val
  637. continue
  638. }
  639. if {$macro == "LIBS"} {
  640. # convert relative paths
  641. ::filePathFix val
  642. set libs ""
  643. foreach lib $val {
  644. if {! [regexp {([\/].)|(.:)} [string range $lib 0 1]]} {
  645. set lib [file join $bspDir $lib]
  646. }
  647. lappend libs $lib
  648. }
  649. set val $libs
  650. }
  651. if {$macro == "LD_LINK_PATH"} {
  652. # fix paths
  653. ::filePathFix val
  654. }
  655. # check if it is an "add" command through the += operator
  656. if {($addValue) && ([info exists makeMacros($macro)])} {
  657. set val [format "%s %s" $makeMacros($macro) $val]
  658. }
  659. if {[lsearch -exact $macroToSkip $macro] == -1} {
  660. set makeMacros($macro) $val
  661. }
  662. }
  663. if {$switchLowHigh != ""} {
  664. set switchLowHigh ""
  665. set low $makeMacros(RAM_LOW_ADRS)
  666. set makeMacros(RAM_LOW_ADRS) $makeMacros(RAM_HIGH_ADRS)
  667. set makeMacros(RAM_HIGH_ADRS) $low
  668. }
  669. }
  670. close $makeFd
  671. }
  672. ############################################################################
  673. #
  674. # bspMakeGet - get info on a BSP make-macro
  675. #
  676. proc bspMakeGet {{macro ""}} {
  677. variable makeMacros
  678. if {$macro == ""} {
  679. return [array names makeMacros]
  680. }
  681. if {![info exists makeMacros($macro)]} {
  682. return ""
  683. }
  684. return "$makeMacros($macro)"
  685. }
  686. ############################################################################
  687. #
  688. # bspFilesGet - get the set of files in a BSP
  689. #
  690. # RETURNS: a list of three elements, the first containing the BSP source
  691. # files, the second containing the BSP boot files, and the third containing
  692. # other BSP objects of unknown type
  693. #
  694. # INTERNAL
  695. # Care must be taken to put the first file in MACH_DEP (typically sysALib.o)
  696. # as the first project file.
  697. # The reason is that the project Make system needs to put that file
  698. # first on the final link line.
  699. #
  700. proc bspFilesGet bspDir {
  701. set files ""
  702. set bootFiles ""
  703. set otherObjs ""
  704. set otherBootObjs ""
  705. set bspFiles [glob [file join $bspDir *.c] [file join $bspDir *.s] \
  706. [file join $bspDir *.cpp] [file join $bspDir *.cxx]]
  707. set bspObjs [bspMakeGet MACH_DEP]
  708. set bootObjs [bspMakeGet BOOT_EXTRA]
  709. set firstObj [lindex $bspObjs 0]
  710. foreach file $bspFiles {
  711. set obj [file rootname [file tail $file]].o
  712. if {[lsearch $bspObjs $obj] != -1} {
  713. if {$obj == $firstObj} {
  714. set files [concat $file $files]
  715. } else {
  716. lappend files $file
  717. }
  718. regsub $obj $bspObjs "" bspObjs
  719. if {[lsearch $bootObjs $obj] != -1} {
  720. lappend otherBootObjs $obj
  721. regsub $obj $bootObjs "" bootObjs
  722. }
  723. continue
  724. }
  725. if {[lsearch $bootObjs $obj] != -1} {
  726. lappend bootFiles $file
  727. regsub $obj $bootObjs "" bootObjs
  728. continue
  729. }
  730. }
  731. set objs [string trim [concat $bspObjs]]
  732. foreach obj $objs {
  733. lappend otherObjs [file join $bspDir $obj]
  734. }
  735. set objs [string trim [concat $bootObjs]]
  736. foreach obj $objs {
  737. lappend otherBootObjs [file join $bspDir $obj]
  738. }
  739. return [list $files $bootFiles $otherObjs $otherBootObjs]
  740. }
  741. ############################################################################
  742. #
  743. # bspRulesParse - parse a BSP Makefile for user defined rules
  744. #
  745. proc bspRulesParse {bspDir} {
  746. variable usrRules ;# rules array
  747. if {[info exists usrRules]} {
  748. unset usrRules
  749. }
  750. set makefile [file join $bspDir Makefile] ;# Makefile to parse
  751. set targetList "" ;# rules found in Makefile
  752. set findRule 0 ;# indicating if we found a rule
  753. set incompleteLine 0 ;# indicating that current line
  754. # is not complete
  755. set ruleToSkip ".*bootrom.*" ;# ignores *bootrom* rules
  756. set addCurrentRule 1 ;# add current rule (1) or skip
  757. # it (0)
  758. # open file to parse
  759. set makeFd [open $makefile r]
  760. while {[gets $makeFd line] >= 0} {
  761. # Skip include lines, macros lines, comments lines and blank lines
  762. if {([regexp "^ *include .*" $line] || \
  763. [regexp "^.*=.*$" $line] || \
  764. [regexp "^ *#.*" $line] || \
  765. [regexp "(^ +$|^$)" $line]) && $findRule == 0 } {
  766. # nothing to do
  767. } elseif {[regexp "^\[^\t\].*:.*$" $line]} {
  768. # We find a new rule if line match "target : dependencies"
  769. set findRule 1
  770. set target [lindex [split $line \;] 0]
  771. set targetName [lindex [split $target \:] 0]
  772. regsub " *$" $targetName "" targetName
  773. if {[regexp $ruleToSkip $targetName]} {
  774. set addCurrentRule 1 ; # always add current rule
  775. } else {
  776. set addCurrentRule 1
  777. }
  778. if {$addCurrentRule} {
  779. lappend targetList $targetName
  780. lappend usrRules($targetName) $target
  781. }
  782. # check if current line complete is ended by "\"
  783. # which means "to be continued"
  784. if {[regexp {^.*\\ *$} $target]} {
  785. set incompleteLine 1
  786. } else {
  787. set incompleteLine 0
  788. }
  789. # the first commands may appear on the same line than
  790. # the dependencies, with a semicolon as separator:
  791. #
  792. # targets : dependencies ; command1 ; command2
  793. # command3
  794. # ...
  795. set firstCommands [split $line \;]
  796. set firstCommands [lrange $firstCommands 1 end]
  797. if {$firstCommands != ""} {
  798. foreach command $firstCommands {
  799. regsub "(^\t*|^ *)" $command "" command
  800. regsub -all {\$\(MAKE\)} $line \
  801. "\$(MAKE) -f \$(PRJ_DIR)/Makefile" line
  802. if {$addCurrentRule} {
  803. lappend usrRules($targetName) $command
  804. }
  805. }
  806. }
  807. } elseif {$incompleteLine} {
  808. regsub "(^\t*|^ *)" $line "" line
  809. regsub -all {\$\(MAKE\)} $line \
  810. "\$(MAKE) -f \$(PRJ_DIR)/Makefile" line
  811. if {$addCurrentRule} {
  812. lappend usrRules($targetName) $line
  813. }
  814. if {![regexp {^.*\\ *$} $line]} {
  815. set incompleteLine 0
  816. }
  817. } elseif {$findRule && $line != "" && [regexp "^\t+.*" $line]} {
  818. # if line is not null and start by a tabulation
  819. regsub "(^\t*|^ *)" $line "" line
  820. regsub -all {\$\(MAKE\)} $line \
  821. "\$(MAKE) -f \$(PRJ_DIR)/Makefile" line
  822. if {$addCurrentRule} {
  823. lappend usrRules($targetName) $line
  824. }
  825. }
  826. }
  827. close $makeFd
  828. # if rule references BSP source files, prepend $bspDir
  829. set bspSources [glob -nocomplain [file join $bspDir *.s] \
  830. [file join $bspDir *.c] [file join $bspDir *.cpp] \
  831. [file join $bspDir *.cxx] [file join $bspDir *.h]]
  832. foreach target $targetList {
  833. foreach source $bspSources {
  834. set source [file tail $source]
  835. regsub -all "\[ \t\]$source" $usrRules($target) \
  836. " [file join $bspDir $source]" usrRules($target)
  837. }
  838. }
  839. foreach target $targetList {
  840. foreach line $usrRules($target) {
  841. prjStatusLog $line
  842. }
  843. }
  844. return $targetList
  845. }
  846. ############################################################################
  847. #
  848. # bspRulesGet - parse a BSP Makefile for user defined rules
  849. #
  850. proc bspRulesGet {{rule ""}} {
  851. variable usrRules ;# rules array
  852. if {"$rule" == ""} {
  853. return [array names usrRules]
  854. }
  855. if {![info exists usrRules($rule)]} {
  856. error "no such rule $rule"
  857. }
  858. return "$usrRules($rule)"
  859. }
  860. ############################################################################
  861. #
  862. # bspDirValid - check if a BSP directory is valid
  863. #
  864. proc bspDirValid bspDir {
  865. if {(![file isdirectory $bspDir]) || \
  866. (![file readable [file join $bspDir sysLib.c]])} {
  867. return 0
  868. }
  869. return 1
  870. }
  871. ############################################################################
  872. #
  873. # ::prj_vxWorks_hidden::bspAdrsMacroListGet - get the list of addrs macros
  874. #
  875. # SYNOPSIS
  876. # \cs
  877. # ::prj_vxWorks_hidden::bspAdrsMacroListGet <bspDir>
  878. # \ce
  879. #
  880. # DESCRIPTION
  881. # Calls the adrsMacros rule on the Makefile located in the given <bspDir>
  882. #
  883. # PARAMETERS:
  884. # bspDir : BSP directory which should contain a Makefile to call
  885. # macrosAdrs rule for
  886. #
  887. # RETURNS: A list of address macros
  888. #
  889. proc bspAdrsMacroListGet {bspDir} {
  890. return [bspMakeRuleCall $bspDir adrsMacros]
  891. }
  892. ############################################################################
  893. #
  894. # ::prj_vxWorks_hidden::bspMakeRuleCall - call a make rule to return a list
  895. #
  896. # SYNOPSIS
  897. # \cs
  898. # ::prj_vxWorks_hidden::bspMakeRuleCall <bspDir> <rule>
  899. # \ce
  900. #
  901. # DESCRIPTION
  902. # This procedure calls the make rule <rule> using the Makefile located
  903. # in <bspDir>. It gives the make command arguments `BSP2PRJ=TRUE'.
  904. #
  905. # It assumes the returned value is a one line string.
  906. #
  907. # PARAMETERS:
  908. # bspDir : directory where the Makefile to use is
  909. # rule : the rule to call for the make command
  910. #
  911. # RETURNS: The rule output, stripped from the make specific lines
  912. #
  913. # ERRORS: N/A
  914. #
  915. # SEE ALSO: bspAdrsMacroListGet, bspOverridenAdrsMacroListGet
  916. #
  917. proc bspMakeRuleCall {bspDir rule} {
  918. # get the list of addresses macros
  919. set makeCmd [format "make %s BSP2PRJ=TRUE" $rule]
  920. # go to the BSP dir first. We need a valid Makefile, and we are
  921. # currently generating the project Makefile ... so use the BSP one.
  922. set oldPath [pwd]
  923. cd $bspDir
  924. if {[catch {eval exec $makeCmd 2>@ [prjStderr]} adrsList]} {
  925. puts [prjStderr] "Error executing \"$makeCmd\" : \"$adrsList\""
  926. set adrsList {}
  927. }
  928. cd $oldPath
  929. # Remove some of the string 'make' returned and which are useless to us
  930. set cleanList {}
  931. foreach line [split $adrsList "\n"] {
  932. if {! [regexp "make(.exe)?\\\[\[0-9]+\\]:" $line]} {
  933. if {[llength $cleanList] == 0} {
  934. set cleanList $line
  935. } else {
  936. set cleanList [concat $cleanList $line]
  937. }
  938. }
  939. }
  940. return $cleanList
  941. }
  942. ############################################################################
  943. #
  944. # vxProjCreate - create a vxWorks project from a BSP
  945. #
  946. proc vxProjCreate {prjFile bspDir {prjBootromFile ""} {description ""} \
  947. {cpuType ""} {toolType ""} {opt ""}} {
  948. global tcl_platform
  949. set ix [lsearch -exact $opt "-source"]
  950. if { $ix != -1 } {
  951. set prjSrcBuild 1
  952. set opt [lreplace $opt $ix $ix]
  953. } else {
  954. set prjSrcBuild 0
  955. }
  956. set ix [lsearch -exact $opt "-scale"]
  957. if { $ix != -1 } {
  958. set useBSPDefault 0
  959. set opt [lreplace $opt $ix $ix]
  960. } else {
  961. set useBSPDefault 1
  962. }
  963. if {![prjCreateable $prjFile ::prj_vxWorks]} {
  964. error "can't create project $prjFile"
  965. }
  966. set prjDir [file dirname $prjFile]
  967. if {$prjBootromFile != ""} {
  968. if {![prjCreateable $prjFile ::prj_vxWorks]} {
  969. error "can't create project $prjBootromFile"
  970. }
  971. }
  972. if {![bspDirValid $bspDir]} {
  973. error "not a BSP directory: $bspDir"
  974. }
  975. # parse the BSP's headers and Makefile
  976. prjStatusLog "parsing the BSP Makefile..."
  977. bspMakeParse $bspDir $cpuType $toolType $opt
  978. prjStatusLog "extract user defined rules from BSP Makefile..."
  979. bspRulesParse $bspDir
  980. set vxWorksRules [bspRulesGet ""]
  981. # extract all the key info from the BSP
  982. prjStatusLog "creating the project file..."
  983. set cpu [bspMakeGet CPU]
  984. set tool [bspMakeGet TOOL]
  985. set files [bspFilesGet $bspDir]
  986. set prjFiles [lindex $files 0]
  987. set prjBootFiles [lindex $files 1]
  988. set otherObjs [lindex $files 2]
  989. set otherBootObjs [lindex $files 3]
  990. # create an empty project
  991. set hProj [prjCoreCreate $prjFile ::prj_vxWorks]
  992. set cmpDir [file join [Wind::tgtDir] config comps]
  993. prjTagDataSet $hProj BSP_DIR $bspDir
  994. set prjDir [file dirname $prjFile]
  995. prjTagDataSet $hProj BUILD_SOURCE_ENABLE $prjSrcBuild
  996. # set the description
  997. ::prjTagDataSet $hProj userComments $description
  998. # create a default build spec
  999. prjStatusLog "creating a default build spec for $cpu $tool ..."
  1000. set tc [lindex [prjTcListGet $cpu $tool C++] 0]
  1001. if {$tc == ""} {
  1002. error "${cpu}$tool not defined.\nCheck\
  1003. [file join [Wind::base] host resource osconfig tcl\
  1004. tcInfo_*]"
  1005. }
  1006. set cc [PrjUtils::relPath [${tc}::toolFindByFile foo.c] $prjDir]
  1007. set as [PrjUtils::relPath [${tc}::toolFindByFile foo.s] $prjDir]
  1008. set build [prjBuildCreate $hProj default $tc]
  1009. set cflags [prjBuildFlagsGet $hProj $build $cc]
  1010. set asflags [prjBuildFlagsGet $hProj $build $as]
  1011. prjBuildFlagsSet $hProj $build $cc "$cflags [bspMakeGet EXTRA_CFLAGS]"
  1012. prjBuildFlagsSet $hProj $build $as "$asflags [bspMakeGet EXTRA_CFLAGS]"
  1013. # Macro list that must not appear in the Macro Editor GUI
  1014. set macroToSkip [list CC CFLAGS AS CFLAGS_AS CPP CXX C++FLAGS LD \
  1015. LDFLAGS LD_PARTIAL LD_PARTIAL_FLAGS EXTRA_CFLAGS \
  1016. NM SIZE AR CPU TOOL TOOL_FAMILY MACH_DEP \
  1017. MACH_EXTRA LIB_EXTRA EXTRA_DEFINE]
  1018. # Get whole macro list
  1019. set macroList [bspMakeGet]
  1020. foreach macro $macroList {
  1021. if {[lsearch -exact $macroToSkip $macro] == -1} {
  1022. set val [bspMakeGet $macro]
  1023. if {$val != ""} {
  1024. # remove the '{' and '}' around $(VX_OS_LIBS)
  1025. regsub -all {\{\$\(VX_OS_LIBS\)\}} $val "\$\(VX_OS_LIBS\)" \
  1026. val
  1027. prjBuildMacroSet $hProj $build $macro $val
  1028. if {$macro == "CPU_VARIANT"} {
  1029. set newCc [format "-DCPU_VARIANT=%s %s" $val \
  1030. [prjBuildFlagsGet $hProj $build $cc]]
  1031. set newAs [format "-DCPU_VARIANT=%s %s" $val \
  1032. [prjBuildFlagsGet $hProj $build $as]]
  1033. prjBuildFlagsSet $hProj $build $cc $newCc
  1034. prjBuildFlagsSet $hProj $build $as $newAs
  1035. }
  1036. }
  1037. }
  1038. }
  1039. if {$opt != ""} {
  1040. prjBuildMacroSet $hProj $build OPT $opt
  1041. }
  1042. set extraModulesDefinition [prjBuildMacroGet $hProj $build \
  1043. EXTRA_MODULES]
  1044. set extraModulesDefinition [concat $extraModulesDefinition $otherObjs]
  1045. prjBuildMacroSet $hProj $build EXTRA_MODULES $extraModulesDefinition
  1046. if {$otherObjs != ""} {
  1047. prjStatusLog "adding source-less BSP objects $otherObjs to\
  1048. EXTRA_MODULES."
  1049. }
  1050. prjBuildMacroSet $hProj $build BOOT_EXTRA $otherBootObjs
  1051. if {$otherObjs != ""} {
  1052. prjStatusLog "adding source-less BSP objects $otherBootObjs to\
  1053. BOOT_EXTRA."
  1054. }
  1055. foreach rule $vxWorksRules {
  1056. set val [bspRulesGet $rule]
  1057. if {$val != ""} {
  1058. prjBuildRuleSet $hProj $build $rule $val
  1059. }
  1060. }
  1061. # create a component configuration
  1062. # XXX - create a .cdf file for all unknown BSP INCLUDE_* macros
  1063. prjStatusLog "creating a component configuration..."
  1064. set archDir [PrjUtils::archDirFind $cpu]
  1065. set toolFamily [${tc}::family]
  1066. set cdfPath [list [file join $cmpDir vxWorks] \
  1067. [file join $cmpDir vxWorks arch $archDir] \
  1068. [file join $cmpDir vxWorks net] \
  1069. [file join $cmpDir vxWorks net apps] \
  1070. [file join $cmpDir vxWorks tool $toolFamily] \
  1071. $bspDir [file dirname $prjFile]]
  1072. set wcc [file tail $bspDir]
  1073. wccCreate $hProj $wcc
  1074. wccCdfPathSet $hProj $cdfPath
  1075. wccMxrLibsSet $hProj ""
  1076. set bspname [file tail $bspDir]
  1077. set d [cxrDocCreate $hProj]
  1078. set s [$d setCreate]
  1079. $s = $bspname
  1080. if {$bspname == [$s instances]} {
  1081. # switching on temprarily, temporary compromise behaviour for scalable BSPs.
  1082. set do_configh 1
  1083. } else {
  1084. set do_configh 1
  1085. }
  1086. if {$do_configh} {
  1087. # prjStatusLog "parsing the BSP's config.h..."
  1088. # set fd [open [file join $bspDir config.h] r]
  1089. # set buf [read $fd]
  1090. # close $fd
  1091. #
  1092. # if {[regexp {#[ ]*include[ ]*"prjParams.h.*} $buf] == 0} {
  1093. # set tail "#if defined(PRJ_BUILD)\n#include \"prjParams.h\"\n#endif"
  1094. # puts "Modifying [file join $bspDir config.h]. Appending\n$tail"
  1095. # set fd [open [file join $bspDir config.h] w+]
  1096. # puts $fd "$buf\n$tail"
  1097. # close $fd
  1098. # }
  1099. # SPR#84899 : change directory first, and do not use 'make -C'
  1100. set makeCmd "make headerMacros BSP2PRJ=TRUE"
  1101. if {$opt != ""} {
  1102. set makeCmd "$makeCmd OPT=$opt"
  1103. }
  1104. if {$cpuType != ""} {
  1105. set makeCmd "$makeCmd CPU=$cpuType"
  1106. }
  1107. if {$toolType != ""} {
  1108. set makeCmd "$makeCmd TOOL=$toolType"
  1109. }
  1110. # If any of the exec'd commands writes to standard error
  1111. # (e.g. a compiler warning) and standard error isn't redirected,
  1112. # then exec will return an error. To avoid this we use
  1113. # "2>@ stderr", which redirects standard error to
  1114. # standard error. This has no effect other than to prevent
  1115. # exec from returning an error on e.g. a compiler warning
  1116. # SPR#84899 : change directory first, and do not use 'make -C'
  1117. set oldPath [pwd]
  1118. cd $bspDir
  1119. if {[catch {set lines "[eval exec $makeCmd 2>@ [prjStderr]]"} err]} {
  1120. catch {eval exec $makeCmd} err
  1121. cd $oldPath
  1122. error "$err\n\"$makeCmd\" failed"
  1123. }
  1124. cd $oldPath
  1125. prjStatusLog "calculating included components..."
  1126. set tmpl [split $lines "\n"]
  1127. foreach l $tmpl {
  1128. # During FR-V arch port it was seen that, bsp parser will not
  1129. # parse the output of "make headerMacros" correctly if an extra
  1130. # space is not present at the end of line.
  1131. #
  1132. # Somehow previous pre-processors were adding an extra space at the
  1133. # end of the line before "\n". And a new one does not do it.
  1134. #
  1135. # Because of this, this code was added to put a space before "\n"
  1136. # if it is not present.
  1137. #
  1138. # Note !! This code affects all the architectures.
  1139. #
  1140. if {[string index $l [expr {[string length $l]} - 1]] != " "} {
  1141. append l " "
  1142. }
  1143. # read macros of form "#define macro defn" and
  1144. # "#define macro(arg1, arg2, arg3) defn" into macros array
  1145. # XXX : fle : we may try this string instead of the regexp between
  1146. # curlies :
  1147. #
  1148. # set macroRegexp \
  1149. # "(#define\[ \t]+)(\[^ \t\n\\\(]+(\\(\[^\\)]*\\))?)(\[^\n]*)"
  1150. #
  1151. # then do
  1152. #
  1153. # regsub -all $macroRegexp $l "\\2" macroName
  1154. # regsub -all $macroRegexp $l "\\4" macros($macroName)
  1155. regsub {(#define[ ]+)([^ \(]+(\([^\)]*\))?)[ ]*(.*)$} $l {\2} macroName
  1156. regsub {(#define[ ]+)([^ \(]+(\([^\)]*\))?)[ ]*(.*)$} $l {\4} macros($macroName)
  1157. }
  1158. # convert some macros to new component names
  1159. if {[array names macros WDB_MODE] == "WDB_MODE"} {
  1160. switch [string trim $macros(WDB_MODE)] {
  1161. WDB_MODE_TASK {set macros(INCLUDE_WDB_TASK) 1}
  1162. WDB_MODE_EXTERN {set macros(INCLUDE_WDB_SYS) 1}
  1163. WDB_MODE_DUAL {
  1164. set macros(INCLUDE_WDB_TASK) 1
  1165. set macros(INCLUDE_WDB_SYS) 1
  1166. }
  1167. }
  1168. }
  1169. if {[array names macros INCLUDE_[string trim $macros(WDB_COMM_TYPE)]] \
  1170. == "INCLUDE_[string trim $macros(WDB_COMM_TYPE)]"} {
  1171. set macros(INCLUDE_[string trim $macros(WDB_COMM_TYPE)]) 1
  1172. }
  1173. }
  1174. if {[lsearch $bspname [$d instances Bsp]] != -1} {
  1175. $s = $bspname
  1176. wccComponentAdd $hProj $wcc [$s get REQUIRES]
  1177. if {[$s get DEFAULTS] == {} } {
  1178. $s = [array names macros]
  1179. $s = [$s - [array names macros INCLUDE*]]
  1180. $s = [$s + [macrosToComponents [array name macros INCLUDE*] $hProj]]
  1181. $d importRaw "\nBsp\t$bspname \{\n\tDEFAULTS\t\t[$s instances Component]\n\}\n"
  1182. if {$useBSPDefault} {
  1183. set components [$s instances Component]
  1184. wccComponentAdd $hProj $wcc $components
  1185. }
  1186. }
  1187. } else {
  1188. $s = [array names macros]
  1189. $s = [$s - [array names macros INCLUDE*]]
  1190. $s = [$s + [macrosToComponents [array name macros INCLUDE*] $hProj]]
  1191. set components [$s instances Component]
  1192. wccComponentAdd $hProj $wcc $components
  1193. }
  1194. wccComponentAdd $hProj $wcc INCLUDE_USER_APPL
  1195. # wccComponentAdd $hProj $wcc [wccDependsGet $hProj $wcc]
  1196. cmpRecalculate $hProj
  1197. prjStatusLog "calculating parameter values..."
  1198. if {$do_configh} {
  1199. $s = [array names macros]
  1200. foreach param [$s instances Parameter] {
  1201. if {[wccParamTypeGet $hProj $param] == "exists"} {
  1202. set macros($param) TRUE
  1203. }
  1204. wccParamSet $hProj $wcc $param [string trim $macros($param)]
  1205. }
  1206. }
  1207. $s delete
  1208. # add files to project
  1209. prjStatusLog "adding files to project..."
  1210. foreach file $prjFiles {
  1211. prjFileAdd $hProj $file
  1212. bspFileFlagsSet $hProj $build $file
  1213. }
  1214. foreach file $prjBootFiles {
  1215. prjFileAdd $hProj $file
  1216. prjFileInfoSet $hProj $file BOOT_FILE TRUE
  1217. bspFileFlagsSet $hProj $build $file
  1218. }
  1219. if {[file exists [file join $bspDir romInit.s]]} {
  1220. prjFileAdd $hProj [file join $bspDir romInit.s]
  1221. prjFileAdd $hProj [file join $cmpDir src romStart.c]
  1222. }
  1223. # Copy stubAppInit.c into the project directory as usrAppInit.c
  1224. set srcPath [file join [Wind::tgtDir] config comps src \
  1225. stubAppInit.c]
  1226. set destPath [file join $prjDir usrAppInit.c]
  1227. # get the source path content
  1228. set fileId [open $srcPath r]
  1229. set fileContent [read $fileId]
  1230. close $fileId
  1231. # copy it to destination
  1232. set fileId [open $destPath w]
  1233. fconfigure $fileId -translation lf
  1234. puts $fileId $fileContent
  1235. close $fileId
  1236. prjFileAdd $hProj [file join $prjDir usrAppInit.c]
  1237. # Copy stubRtpInit.c into the project directory as usrRtpAppInit.c
  1238. set srcPath [file join [Wind::tgtDir] config comps src \
  1239. stubRtpInit.c]
  1240. set destPath [file join $prjDir usrRtpAppInit.c]
  1241. # get the source path content
  1242. set fileId [open $srcPath r]
  1243. set fileContent [read $fileId]
  1244. close $fileId
  1245. # copy it to destination
  1246. set fileId [open $destPath w]
  1247. fconfigure $fileId -translation lf
  1248. puts $fileId $fileContent
  1249. close $fileId
  1250. prjFileAdd $hProj [file join $prjDir usrRtpAppInit.c]
  1251. # generate configuration files
  1252. prjStatusLog "generating configuration files..."
  1253. ::prj_vxWorks_hidden::configGen $hProj
  1254. prjFileAdd $hProj [file join $prjDir prjConfig.c]
  1255. bspFileFlagsSet $hProj $build [file join $prjDir prjConfig.c]
  1256. prjFileAdd $hProj [file join $prjDir linkSyms.c]
  1257. bspFileFlagsSet $hProj $build [file join $prjDir linkSyms.c]
  1258. set allComponents [wccComponentListGet $hProj $wcc]
  1259. prjStatusLog "computing file dependencies..."
  1260. if {[catch {prjFileBuildInfoGen $hProj "" FALSE } status]} {
  1261. puts [prjStderr] "Error generating Build info : $status"
  1262. }
  1263. # Validate the component set and cache the status
  1264. prjStatusLog "Validating the configuration..."
  1265. ::wccValidate $hProj $wcc
  1266. prjStatusLog "done"
  1267. # add the other build specs: rom, romCompress, romResident
  1268. # don't add them for the simulators - they don't make sense
  1269. if {![basedOnSimulator $hProj]} {
  1270. prjBuildCopy $hProj default default_rom
  1271. prjBuildRuleCurrentSet $hProj default_rom vxWorks_rom
  1272. prjBuildCopy $hProj default default_romCompress
  1273. prjBuildRuleCurrentSet $hProj default_romCompress \
  1274. vxWorks_romCompress
  1275. prjBuildCopy $hProj default default_romResident
  1276. prjBuildRuleCurrentSet $hProj default_romResident \
  1277. vxWorks_romResident
  1278. # restore current build to default
  1279. prjBuildCurrentSet $hProj default
  1280. }
  1281. # close the project to save all the info
  1282. prjStatusLog "saving the project..."
  1283. prjSave $hProj
  1284. set retval $hProj
  1285. # If a bootrom project was also requested, create it now
  1286. if {$prjBootromFile != ""} {
  1287. prjStatusLog "creating boot rom project..."
  1288. # Copy the bootable project
  1289. set hProj [prjOpen $prjFile "r"]
  1290. ::prjCopy $hProj $prjBootromFile
  1291. prjClose $hProj
  1292. # Open the new copy for manipulation
  1293. set hProj [prjOpen $prjBootromFile "r"]
  1294. set hSpec [prjBuildCurrentGet $hProj]
  1295. # Set the extended project type
  1296. prjTagDataSet $hProj CORE_INFO_SUBTYPE bootrom
  1297. # Add a comment
  1298. set description "Boot Rom image for '$prjFile'"
  1299. ::prjTagDataSet $hProj userComments $description
  1300. # Remove the components we don't want
  1301. set wcc [wccCurrentGet $hProj]
  1302. wccComponentRemove $hProj $wcc [stripCompsGet]
  1303. # Add the components we require
  1304. wccComponentAdd $hProj $wcc [addCompsGet]
  1305. # Define the USR_APPL_INIT macro to start the boot app
  1306. prjBuildMacroSet $hProj $hSpec USR_APPL_INIT [bootAppGet]
  1307. # Done!
  1308. prjClose $hProj SAVE
  1309. }
  1310. prjStatusLog "done"
  1311. return $retval
  1312. }
  1313. ############################################################################
  1314. #
  1315. # bspFileFlagsSet - set up a custom rule to compile file with bsp flags
  1316. #
  1317. # Basically this is to add -fvolatile (gnu) or -Xmemory-is-volatile (diab)
  1318. # to bsp files, where they are necessary if there are poorly written
  1319. # drivers. They are not necessary and in fact bad for optimization in
  1320. # application code.
  1321. #
  1322. proc bspFileFlagsSet {hProj build file} {
  1323. set tc [prjBuildTcGet $hProj $build]
  1324. set objs [prjFileInfoGet $hProj $file objects]
  1325. set tool [${tc}::toolFindByFile $file]
  1326. set toolMacro [${tool}::toolMacro]
  1327. set flagsMacro [${tool}::flagsMacro]
  1328. prjFileInfoSet $hProj $file customRule $objs
  1329. set rule [list "$objs : $file" \
  1330. "\$($toolMacro) \$(OPTION_OBJECT_ONLY) \$($flagsMacro) \
  1331. \$(PROJECT_BSP_FLAGS_EXTRA) $file -o $@"]
  1332. prjBuildRuleSet $hProj $build $objs $rule
  1333. }
  1334. ############################################################################
  1335. #
  1336. # prj_vxWorks_hidden::makeGen - generate a Makefile for a vxWorks project
  1337. #
  1338. # NOMANUAL
  1339. #
  1340. proc makeGen {hProj Makefile} {
  1341. global env ;# environment variables
  1342. set prjFile [prjInfoGet $hProj fileName]
  1343. set prjDir [file dirname $prjFile]
  1344. set hSpec [prjBuildCurrentGet $hProj]
  1345. set builds [prjBuildListGet $hProj]
  1346. set cmpLib [cxrDocCreate $hProj]
  1347. set cmpSet [$cmpLib setCreate]
  1348. set cwd [pwd]
  1349. cd $prjDir
  1350. set prjFullDir [pwd]
  1351. cd $cwd
  1352. set fd [open $Makefile w+]
  1353. fconfigure $fd -translation lf
  1354. set prjFiles [prjFileListGet $hProj]
  1355. set objs [objsGet $hProj]
  1356. set prjObjs [lindex $objs 0]
  1357. set bootObjs [lindex $objs 1]
  1358. set bspDir [prjTagDataGet $hProj BSP_DIR]
  1359. set buildMode [cmpBuildModeGet $hProj ]
  1360. puts $fd "# Makefile generated by the project manager\n#\n"
  1361. puts $fd ""
  1362. puts $fd "# GENERATED: [clock format [clock seconds]]"
  1363. puts $fd "# DO NOT EDIT - file is regenerated whenever the project\
  1364. changes"
  1365. puts $fd ""
  1366. puts $fd "\n## core information\n"
  1367. puts $fd "ifeq (\$(wildcard [file tail $Makefile]),)"
  1368. puts $fd "PRJ_DIR = .."
  1369. puts $fd "else"
  1370. puts $fd "PRJ_DIR = ."
  1371. puts $fd "endif"
  1372. puts $fd "PRJ_FILE = [PrjUtils::relPath [file tail $prjFile] \
  1373. $prjDir]"
  1374. puts $fd "PRJ_FULL_PATH = [PrjUtils::relPath $prjFullDir]"
  1375. puts $fd "PRJ_TYPE = vxWorks"
  1376. puts $fd "PRJ_OBJS = $prjObjs"
  1377. puts $fd "PRJ_MAKEFILE = \$(PRJ_DIR)/[file tail $Makefile]"
  1378. puts $fd "BOOT_OBJS = $bootObjs \$(BOOT_EXTRA)"
  1379. puts $fd "BUILD_SPEC = $hSpec"
  1380. puts $fd "BSP_DIR = [PrjUtils::relPath $bspDir $prjDir]"
  1381. if { $buildMode == "source" } {
  1382. puts $fd "SRC_BUILD = TRUE"
  1383. }
  1384. # SPR#93114 : never use true value of TGT_DIR, rather use WIND_BASE
  1385. # collapsed one, or this would make the project not buildable on any
  1386. # other location
  1387. set tgtDir [file join [Wind::tgtDir]]
  1388. set reg "[EscapeRegexpCharacters [file join [Wind::base]]](/| |\t)"
  1389. if {[Wind::isWindows]} {
  1390. regsub -all -- {/} [string tolower $reg] {[\\\/]} reg
  1391. regsub -nocase -all -- $reg $tgtDir {$(WIND_BASE)\1} tgtDir
  1392. } else {
  1393. regsub -all -- $reg $tgtDir {$(WIND_BASE)\1} tgtDir
  1394. }
  1395. puts $fd "TGT_DIR = $tgtDir"
  1396. puts $fd "\n\n"
  1397. puts $fd "## set searching directories for dependencies\n"
  1398. puts $fd "vpath %.c \$(BSP_DIR)"
  1399. puts $fd "vpath %.cpp \$(BSP_DIR)"
  1400. puts $fd "vpath %.cxx \$(BSP_DIR)"
  1401. puts $fd "vpath %.s \$(BSP_DIR)\n"
  1402. puts $fd "\n## build-configuration info\n"
  1403. foreach build $builds {
  1404. set tc [prjBuildTcGet $hProj $build]
  1405. puts $fd "ifeq (\$(BUILD_SPEC),$build)"
  1406. puts $fd "CPU = [${tc}::cpu]"
  1407. puts $fd "TOOL = [${tc}::tool]"
  1408. puts $fd "TOOL_FAMILY = [${tc}::family]"
  1409. puts $fd "DEFAULT_RULE = [prjBuildRuleCurrentGet $hProj $build]"
  1410. puts $fd "OPT = [prjBuildMacroGet $hProj $build OPT]"
  1411. puts $fd "endif\n"
  1412. }
  1413. set wcc [wccCurrentGet $hProj]
  1414. set cpu [${tc}::cpu]
  1415. set tool [${tc}::tool]
  1416. set componentLibs ""
  1417. set libs [prjBuildMacroGet $hProj $build LIBS]
  1418. foreach lib [wccMxrLibsGet $hProj] {
  1419. if {[lsearch $libs $lib] == -1} {
  1420. lappend componentLibs $lib
  1421. }
  1422. }
  1423. regsub "[file join [Wind::tgtDir] lib lib${cpu}${tool}vx.a]" \
  1424. $componentLibs "" componentLibs
  1425. regsub -all {[\{\}]} $componentLibs "" componentLibs
  1426. # special variables
  1427. puts $fd "\n## Memory adresses variables\n"
  1428. set adrsList [bspAdrsMacroListGet $bspDir]
  1429. set missedAdrsList {}
  1430. set adrsDefine ""
  1431. set def [prjBuildMacroGet $hProj $hSpec OPTION_DEFINE_MACRO]
  1432. foreach param $adrsList {
  1433. set paramValue [wccParamGet $hProj $wcc $param]
  1434. # check if the value starts with 0x already
  1435. if {[string first "0x" $paramValue] == 0} {
  1436. # XXX : fle : some rules use -D=0x$(RAM_LOW_ADRS), so we have to
  1437. # remove the leading 0x to make those rules work okay
  1438. set paramValue [string range $paramValue 2 end]
  1439. }
  1440. if {$paramValue != ""} {
  1441. puts $fd [format "%s = %s" $param $paramValue]
  1442. # still have to check if it is a real value. If there are still
  1443. # some values set through the config.h file which look like
  1444. # (LOCAL_MEM_LOCAL_ADDRS + 0x100000), the build will fail :(
  1445. if {! [catch {expr "0x$paramValue" + 0x0}]} {
  1446. append adrsDefine [format "%s%s=0x\$(%s) " $def $param \
  1447. $param]
  1448. } else {
  1449. # will have to retrieve it from the makefile later on
  1450. lappend missedAdrsList $param
  1451. }
  1452. }
  1453. }
  1454. puts $fd "\n## component-configuration info\n"
  1455. puts $fd "COMPONENTS = [prjDataSplit [lsort [wccComponentListGet\
  1456. $hProj $wcc]]]\n"
  1457. set prjComponents [lsort [wccComponentListGet $hProj $wcc]]
  1458. # define libraries managed by CDF
  1459. $cmpSet = [$cmpLib instances Component]
  1460. puts $fd "MANAGED_LIBS = [join [lsort -uniq [join [$cmpSet get ARCHIVE]]]]"
  1461. $cmpSet = $prjComponents
  1462. set componentLibs [$cmpSet get ARCHIVE]
  1463. set componentLibs [join $componentLibs]
  1464. set componentLibs [lsort -uniq $componentLibs]
  1465. set componentLibs [join $componentLibs]
  1466. puts $fd "COMPONENT_LIBS = $componentLibs\n"
  1467. set linkerSyms [$cmpSet get LINK_PARAMS]
  1468. set allsyms {}
  1469. foreach sym $linkerSyms {
  1470. $cmpSet = $sym
  1471. puts $fd "LINK_SYM_$sym = $sym [wccParamGet $hProj $wcc $sym]"
  1472. lappend allsyms LINK_SYM_$sym
  1473. }
  1474. puts $fd "PROJECT_LINK_SYMDEFS = $allsyms"
  1475. puts $fd "\n\ninclude \$(TGT_DIR)/h/make/defs.project\n"
  1476. puts $fd "\n## build-configuration info\n"
  1477. foreach build $builds {
  1478. set tc [prjBuildTcGet $hProj $build]
  1479. puts $fd "ifeq (\$(BUILD_SPEC),$build)"
  1480. foreach macro [prjBuildMacroListGet $hProj $build "" 1] {
  1481. set initValue [prjBuildMacroGet $hProj $build $macro]
  1482. set value [PrjUtils::relPath $initValue $prjDir]
  1483. # do not add the macros from ADRS_DEFINE
  1484. if {([lsearch -exact $adrsList $macro] == -1) ||
  1485. ([lsearch -exact $missedAdrsList $macro] != -1)} {
  1486. puts $fd [format "%-16s = %s" $macro $value]
  1487. }
  1488. }
  1489. puts $fd "endif\n"
  1490. }
  1491. puts $fd "# override make definitions only below this line\n\n"
  1492. puts $fd "# override make definitions only above this line\n"
  1493. puts $fd "include \$(TGT_DIR)/h/make/rules.project\n"
  1494. puts $fd "\n## build-configuration info\n"
  1495. puts $fd "sysALib.o: \$(PRJ_DIR)/prjParams.h\n"
  1496. foreach build $builds {
  1497. puts $fd "ifeq (\$(BUILD_SPEC),$build)"
  1498. foreach file $prjFiles {
  1499. # skip files with custom rules - custom rules generated later
  1500. if {"[prjFileInfoGet $hProj $file customRule]" != ""} {
  1501. continue
  1502. }
  1503. foreach object [prjFileInfoGet $hProj $file objects] {
  1504. puts $fd "\n${object}:"
  1505. set commands [PrjUtils::relPath [prjBuildCmdsGet $hProj \
  1506. $build $file] $prjDir]
  1507. foreach cmd $commands {
  1508. puts $fd "\t$cmd"
  1509. }
  1510. }
  1511. }
  1512. puts $fd "endif\n"
  1513. }
  1514. # add user defined rules
  1515. set targetList [prjBuildRuleListGet $hProj $hSpec]
  1516. if {"$targetList" != ""} {
  1517. puts $fd "\n## user defined rules\n"
  1518. foreach target $targetList {
  1519. set i 1
  1520. set rule [prjBuildRuleGet $hProj $hSpec $target]
  1521. if {$rule == ""} {
  1522. continue
  1523. }
  1524. foreach line $rule {
  1525. if {$i} {
  1526. # print the target line (no tabulation)
  1527. puts $fd [PrjUtils::relPath $line $prjDir]
  1528. set i 0
  1529. } else {
  1530. # print the command lines (with tabulation)
  1531. puts $fd "\t[PrjUtils::relPath $line $prjDir]"
  1532. }
  1533. }
  1534. puts $fd ""
  1535. }
  1536. }
  1537. if { $buildMode == "source" } {
  1538. puts $fd "\n## Build project libraries from the source\n"
  1539. if {"$prjComponents" != ""} {
  1540. puts $fd "TGT_SRC_DIR = \$\(TGT_DIR\)/src "
  1541. # make commands for source build with specified components
  1542. foreach component $prjComponents {
  1543. $cmpSet = $component
  1544. set slist [$cmpSet get SOURCE]
  1545. if { $slist !="" } {
  1546. foreach pair $slist {
  1547. set srcPath [lindex $pair 0]
  1548. if {[llength $pair] == 1} {
  1549. set objf [$cmpSet get MODULES]
  1550. } else {
  1551. set objf [lindex $pair 1]
  1552. }
  1553. foreach obj $objf {
  1554. lappend PathObjs($srcPath) $obj
  1555. }
  1556. }
  1557. }
  1558. }
  1559. puts $fd "\nsrc_build :"
  1560. foreach path [array names PathObjs] {
  1561. puts $fd "\tcd $path; \\"
  1562. puts $fd "\t make CPU=\$(CPU) TOOL=$tool ONLY_CPU_VARIANT=\$(CPU_VARIANT) NO_RECURSE=TRUE LIB_ROOT=\$(PRJ_FULL_PATH)/lib ADDED_CFLAGS+=\"-DPRJ_BUILD=1 -I\$(PRJ_FULL_PATH)\" ALL_SUBDIRS= OBJS=\"$PathObjs($path)\""
  1563. }
  1564. puts $fd "\nsrc_depend :"
  1565. foreach path [array names PathObjs] {
  1566. puts $fd "\tcd $path; \\"
  1567. puts $fd "\t make CPU=\$(CPU) TOOL=$tool ONLY_CPU_VARIANT=\$(CPU_VARIANT) NO_RECURSE=TRUE LIB_ROOT=\$(PRJ_FULL_PATH)/lib ADDED_CFLAGS+=\"-DPRJ_BUILD=1 -I\$(PRJ_FULL_PATH)\" ALL_SUBDIRS= OBJS=\"$PathObjs($path)\" depend"
  1568. }
  1569. puts $fd "\n\$(PRJ_FULL_PATH)/compObjs.lst : \$(PRJ_MAKEFILE)"
  1570. puts $fd "\t@ \$(RM) \$@"
  1571. puts $fd "\t@ touch \$@"
  1572. foreach path [array names PathObjs] {
  1573. puts $fd "\t@ cd $path; \\"
  1574. puts $fd "\tmake -s CPU=\$(CPU) TOOL=$tool ONLY_CPU_VARIANT=\$(CPU_VARIANT) LIB_ROOT=\$(PRJ_FULL_PATH)/lib ALL_SUBDIRS= OBJS=\"$PathObjs($path)\" opath >> \$@"
  1575. }
  1576. # clean source build including objects and libraries
  1577. puts $fd "\nsrc_clean :"
  1578. puts $fd "\t\$(RMDIR) lib"
  1579. puts $fd "\t@ \$(RM) compObjs.lst"
  1580. }
  1581. }
  1582. close $fd
  1583. $cmpSet delete
  1584. }
  1585. ############################################################################
  1586. #
  1587. # objsGet - get the list of project objects and the list of boot objects
  1588. # RETURNS list: <project objects, boot objects>
  1589. #
  1590. proc objsGet {hProj} {
  1591. set prjFiles [prjFileListGet $hProj]
  1592. set prjObjs ""
  1593. set bootObjs ""
  1594. foreach file $prjFiles {
  1595. set objs [prjFileInfoGet $hProj $file objects]
  1596. if {[prjFileInfoGet $hProj $file BOOT_FILE] != ""} {
  1597. if {"$objs" == "romInit.o"} {
  1598. set bootObjs [concat $objs $bootObjs]
  1599. continue
  1600. }
  1601. set bootObjs [concat $bootObjs $objs]
  1602. continue
  1603. }
  1604. if {"$objs" == "sysALib.o"} {
  1605. set prjObjs [concat $objs $prjObjs]
  1606. continue
  1607. }
  1608. foreach obj $objs {
  1609. if {"[string range [file extension $obj] 0 1]" == ".o"} {
  1610. lappend prjObjs $obj
  1611. }
  1612. }
  1613. }
  1614. return [list $prjObjs $bootObjs]
  1615. }
  1616. ############################################################################
  1617. #
  1618. # configGen - generate configuration files for a project
  1619. #
  1620. # This routine generates prjConfig.c, prjComps.h, prjParams.h, and
  1621. # linkSyms.c for a vxWorks system or bootrom project.
  1622. #
  1623. proc configGen {hProj {components ""}} {
  1624. set projType [::[prjTypeGet $hProj]::name]
  1625. set prjDir [file dirname [prjInfoGet $hProj fileName]]
  1626. set cmpLib [cxrDocCreate $hProj]
  1627. set cmpSet [$cmpLib setCreate]
  1628. set wcc [wccCurrentGet $hProj]
  1629. set macros [wccParamListGet $hProj $wcc]
  1630. if {$components == ""} {
  1631. set components [wccComponentListGet $hProj $wcc]
  1632. } else {
  1633. $cmpSet = $components
  1634. $cmpSet = "$macros [$cmpSet get CFG_PARAMS]"
  1635. set macros [$cmpSet instances Parameter]
  1636. }
  1637. set startDir [pwd]
  1638. cd $prjDir
  1639. # compute the set of included components
  1640. $cmpSet = [$cmpLib instances Component]
  1641. set s [$cmpLib setCreate]
  1642. $s = $components
  1643. set includes [lsort [$s instances]]
  1644. $cmpSet = [$cmpLib instances Component]
  1645. set excludes [$cmpSet - $components]
  1646. # XXX - some BSPs won't compile if INCLUDE_SCSIX is not defined
  1647. if {[lsearch INCLUDE_SCSI $includes] == -1} {
  1648. regsub -all {(INCLUDE_SCSI1)|(INCLUDE_SCSI2)} $excludes {} excludes
  1649. }
  1650. ## write out prjComps.h
  1651. set fd [open prjComps.h w+]
  1652. fconfigure $fd -translation lf
  1653. puts $fd "/* prjComps.h - dynamically generated configuration header\
  1654. */\n"
  1655. puts $fd ""
  1656. puts $fd "/*"
  1657. puts $fd "GENERATED: [clock format [clock seconds]]"
  1658. puts $fd "DO NOT EDIT - file is regenerated whenever the project\
  1659. changes"
  1660. puts $fd "*/"
  1661. puts $fd ""
  1662. puts $fd "#ifndef INCprjCompsh"
  1663. puts $fd "#define INCprjCompsh"
  1664. puts $fd "#define _WRS_LAYER [cmpSysLayerGet $hProj $includes]"
  1665. puts $fd "\n/*** INCLUDED COMPONENTS ***/\n"
  1666. foreach component $includes {
  1667. puts $fd "#define $component"
  1668. }
  1669. puts $fd "\n#endif /* INCprjCompsh */"
  1670. close $fd
  1671. # get prototypes here
  1672. set prototypes {}
  1673. foreach included $includes {
  1674. $cmpSet = $included
  1675. if {[set proto [format "%s" [$cmpSet get PROTOTYPE]]] != ""} {
  1676. lappend prototypes $proto
  1677. }
  1678. }
  1679. # write out prjParams.h
  1680. set fd [open prjParams.h w+]
  1681. fconfigure $fd -translation lf
  1682. puts $fd "/* prjParams.h - dynamically generated configuration header\
  1683. */\n"
  1684. puts $fd ""
  1685. puts $fd "/*"
  1686. puts $fd "GENERATED: [clock format [clock seconds]]"
  1687. puts $fd "DO NOT EDIT - file is regenerated whenever the project\
  1688. changes"
  1689. puts $fd "*/"
  1690. puts $fd ""
  1691. puts $fd "#ifndef INCprjParamsh"
  1692. puts $fd "#define INCprjParamsh"
  1693. puts $fd "\n\n/*** INCLUDED COMPONENTS ***/\n"
  1694. foreach component $includes {
  1695. puts $fd "#define $component"
  1696. }
  1697. foreach component $excludes {
  1698. puts $fd "#undef $component"
  1699. }
  1700. puts $fd "\n\n/*** PARAMETERS ***/\n"
  1701. foreach macro $macros {
  1702. puts $fd "#undef $macro"
  1703. if { ![wccParamHasValue $hProj $wcc $macro] } {
  1704. continue
  1705. }
  1706. set type [wccParamTypeGet $hProj $macro]
  1707. set val [wccParamGet $hProj $wcc $macro]
  1708. if {$type == "exists"} {
  1709. if {$val == "TRUE"} {
  1710. puts $fd "#define $macro"
  1711. }
  1712. continue
  1713. }
  1714. puts $fd "#define $macro [wccParamGet $hProj $wcc $macro]"
  1715. }
  1716. puts $fd "\n#endif /* INCprjParamsh */"
  1717. close $fd
  1718. ## write out linkSyms.c
  1719. $s = $includes
  1720. $cmpSet = [join [$s get LINK_SYMS]]
  1721. set syms [lsort [$cmpSet instances]]
  1722. $cmpSet = [join [$s get LINK_DATASYMS]]
  1723. set dataSyms [lsort [$cmpSet instances]]
  1724. set fd [open linkSyms.c w+]
  1725. fconfigure $fd -translation lf
  1726. puts $fd "/* linkSyms.c - dynamically generated configuration file */\n"
  1727. puts $fd ""
  1728. puts $fd "/*"
  1729. puts $fd "GENERATED: [clock format [clock seconds]]"
  1730. puts $fd "DO NOT EDIT - file is regenerated whenever the project\
  1731. changes"
  1732. puts $fd "*/"
  1733. puts $fd ""
  1734. puts $fd "typedef int (*FUNC) ();"
  1735. foreach sym $syms {
  1736. puts $fd "extern int $sym ();"
  1737. }
  1738. foreach sym $dataSyms {
  1739. puts $fd "extern int $sym;"
  1740. }
  1741. puts $fd "\nFUNC linkSyms \[\] = \{"
  1742. foreach sym $syms {
  1743. puts $fd " $sym,"
  1744. }
  1745. puts $fd " 0"
  1746. puts $fd "\};\n"
  1747. puts $fd "\nint * linkDataSyms \[\] = \{"
  1748. foreach sym $dataSyms {
  1749. puts $fd " &$sym,"
  1750. }
  1751. puts $fd " 0"
  1752. puts $fd "\};\n"
  1753. close $fd
  1754. ## write out prjConfig.c
  1755. if {$projType == "bootrom"} {
  1756. # XXX - hack for now
  1757. set srcFile [file join [Wind::tgtDir] config all bootConfig.c]
  1758. set dstFile prjConfig.c
  1759. # XXX : fle : file copy does not really work on Linux, use
  1760. # FileLib::copy
  1761. FileLib::copy $srcFile $dstFile
  1762. cd $startDir
  1763. return
  1764. }
  1765. set fd [open prjConfig.c w+]
  1766. fconfigure $fd -translation lf
  1767. puts $fd "/* prjConfig.c - dynamicaly generated configuration file */\n"
  1768. puts $fd ""
  1769. puts $fd "/*"
  1770. puts $fd "GENERATED: [clock format [clock seconds]]"
  1771. puts $fd "DO NOT EDIT - file is regenerated whenever the project\
  1772. changes."
  1773. puts $fd "This file contains the non-BSP system initialization code"
  1774. puts $fd "for $projType."
  1775. puts $fd "*/"
  1776. puts $fd "\n\n/* includes */\n"
  1777. $cmpSet = [join [$s get HDR_FILES]]
  1778. puts $fd "#include \"vxWorks.h\""
  1779. puts $fd "#include \"config.h\""
  1780. foreach header [lsort [$cmpSet contents]] {
  1781. puts $fd "#include \"$header\""
  1782. }
  1783. puts $fd "\n\n/* imports */\n"
  1784. puts $fd "IMPORT char etext \[\]; /* defined by\
  1785. loader */"
  1786. puts $fd "IMPORT char end \[\]; /* defined by\
  1787. loader */"
  1788. puts $fd "IMPORT char edata \[\]; /* defined by\
  1789. loader */"
  1790. # add CDF defined prototypes
  1791. if {[llength $prototypes] > 0} {
  1792. # add prototypes to the prjConfig.c file
  1793. puts $fd "\n/* forward declarations */\n"
  1794. foreach prototype $prototypes {
  1795. # if prototype does not use the "extern" or "IMPORT" keyword,
  1796. # add it
  1797. if {([string first "extern" [string trim $prototype]] == 0) ||
  1798. ([string first "IMPORT" [string trim $prototype]] == 0)} {
  1799. puts $fd $prototype
  1800. } else {
  1801. puts $fd [format "IMPORT %s" $prototype]
  1802. }
  1803. }
  1804. }
  1805. set bspDir [prjTagDataGet $hProj BSP_DIR]
  1806. puts $fd "\n\n/* BSP_STUBS */\n"
  1807. $cmpSet = [join [$s get BSP_STUBS]]
  1808. foreach bspStub [lsort [$cmpSet contents]] {
  1809. puts $fd "#include \"$bspStub\""
  1810. # SPR#88279 : first change directory to the BSP dir
  1811. cd $startDir
  1812. if {[file exists [file join ${bspDir} $bspStub]] == 0} {
  1813. puts "Missing BSP_STUB $bspStub, copying template into $bspDir"
  1814. set srcStub [file join [Wind::tgtDir] config comps src $bspStub]
  1815. set dstStub [file join ${bspDir} $bspStub]
  1816. # XXX : fle : file copy does not really work on Linux, use
  1817. # FileLib::copy
  1818. FileLib::copy $srcStub $dstStub
  1819. }
  1820. cd $prjDir
  1821. }
  1822. puts $fd "\n\n/* configlettes */\n"
  1823. $cmpSet = [join [$s get CONFIGLETTES]]
  1824. puts $fd "#include \"sysComms.c\""
  1825. # SPR#94279 : configlettes path may contain environment variable or
  1826. # macro
  1827. set cfglettes [prjConfigletteExpand $hProj [lsort [$cmpSet contents]]]
  1828. foreach configlette $cfglettes {
  1829. puts $fd "#include \"[file join $configlette]\""
  1830. }
  1831. # start with the root InitGroups
  1832. $s = [$cmpLib instances InitGroup] ;# all InitGroups
  1833. set initOrder [join [$s get INIT_ORDER]]
  1834. $s = [$s - $initOrder] ;# root InitGroups
  1835. foreach initGroup [$s contents] {
  1836. doInitGroup $initGroup $fd $cmpLib $includes
  1837. }
  1838. close $fd
  1839. cd $startDir
  1840. }
  1841. ############################################################################
  1842. #
  1843. # doInitGroup - process an InitGroup for output
  1844. #
  1845. # This procedure is recurvie, doing depth-first processing of the init
  1846. # groups.
  1847. # If none all the "child" initGroups are empty, and this initGroup
  1848. # has no included components, then we don't bother to output this initGroup.
  1849. #
  1850. proc doInitGroup {initGroup fd cmpLib includes} {
  1851. set s [$cmpLib setCreate]
  1852. $s = $initGroup
  1853. set synopsis [$s get SYNOPSIS]
  1854. set prototype [$s get PROTOTYPE]
  1855. if {"$prototype" == ""} {
  1856. set prototype "void [lindex [$s get INIT_RTN] 0] (void)"
  1857. }
  1858. set proc [lindex $prototype 1]
  1859. set initOrder [join [$s get INIT_ORDER]]
  1860. # adjust initOrder to respect INIT_BEFORE requests
  1861. set tmp [$cmpLib setCreate]
  1862. foreach item $initOrder {
  1863. $tmp = $item
  1864. if {[set initBefore [$tmp get INIT_BEFORE]] == ""} {
  1865. continue
  1866. }
  1867. set oldIx [lsearch $initOrder $item]
  1868. set newIx $oldIx
  1869. foreach cmp $initBefore {
  1870. set cmpIx [lsearch $initOrder $cmp]
  1871. if {$cmpIx < $newIx} {
  1872. set newIx $cmpIx
  1873. }
  1874. }
  1875. if {$newIx == $oldIx} {
  1876. continue
  1877. }
  1878. set initOrder [lreplace $initOrder $oldIx $oldIx]
  1879. set initOrder [linsert $initOrder $newIx $item]
  1880. }
  1881. $tmp delete
  1882. # compute included subgroups and components
  1883. set includedSubgroups ""
  1884. $s = $initOrder
  1885. foreach group [$s instances InitGroup] {
  1886. if {[doInitGroup $group $fd $cmpLib $includes] != 0} {
  1887. lappend includedSubgroups $group
  1888. }
  1889. }
  1890. $s = [$s & [concat $includes $includedSubgroups]]
  1891. set includedItems [$s & [concat $includes $includedSubgroups]]
  1892. if {[llength $includedItems] == 0} {
  1893. $s delete
  1894. return 0
  1895. }
  1896. puts $fd "\n\n/******************************************************************************\n*\n* $proc - $synopsis\n*/\n"
  1897. puts $fd "$prototype"
  1898. puts $fd " \{"
  1899. # XXX - it would be much faster if we could just do $s contents,
  1900. # but that only works if $s contents is ordered in the initOrder.
  1901. # unfortunalty in the current engine $s contents is a random order.
  1902. # That's OK for now since performance is fast enough.
  1903. foreach item $initOrder {
  1904. if {[lsearch $includedItems $item] == -1} {
  1905. continue
  1906. }
  1907. $s = $item
  1908. set desc [$s get SYNOPSIS]
  1909. if {"$desc" == ""} {
  1910. set desc [$s get NAME]
  1911. }
  1912. puts $fd [format " %-35s %s" [$s get INIT_RTN] "/* $desc */"]
  1913. }
  1914. puts $fd " \}\n"
  1915. $s delete
  1916. }
  1917. }
  1918. namespace eval ::prj_vxWorks {
  1919. ############################################################################
  1920. #
  1921. # prj_vxWorks::create - create a vxWorks project
  1922. #
  1923. proc create {prjFile bspDir {bootromFile ""} {description ""} {cpu ""} \
  1924. {tool ""} {opt ""}} {
  1925. set prjDir [file dirname $prjFile]
  1926. set originalFileList [FileLib::listGet $prjDir 1]
  1927. if {[catch {::prj_vxWorks_hidden::vxProjCreate $prjFile $bspDir \
  1928. "$bootromFile" \
  1929. "$description" "$cpu" \
  1930. "$tool" \
  1931. "$opt"} retval]} {
  1932. FileLib::listDelete $prjDir $originalFileList
  1933. error $retval
  1934. }
  1935. return $retval
  1936. }
  1937. ############################################################################
  1938. #
  1939. # prj_vxWorks::name - return the name of this project type
  1940. #
  1941. proc name {} {
  1942. return "Create a bootable VxWorks image (custom configured)"
  1943. }
  1944. ############################################################################
  1945. #
  1946. # prj_vxWorks::toolChainListGet - get list of compatible toolchains
  1947. #
  1948. proc toolChainListGet {} {
  1949. return [prjTcListGet {} {} C++]
  1950. }
  1951. ############################################################################
  1952. #
  1953. # prj_vxWorks::coreFilesGet - get the list of core files
  1954. #
  1955. # SYNOPSIS
  1956. # \cs
  1957. # prj_vxWorks::coreFilesGet
  1958. # \ce
  1959. #
  1960. # DESCRIPTION
  1961. # Returns list of files (apart from the project file itself) that define the
  1962. # <core> of the project. In a <save as>, these are the files that get
  1963. # copied.
  1964. #
  1965. proc coreFilesGet {} {
  1966. return [list linkSyms.c prjComps.h prjConfig.c prjParams.h \
  1967. usrAppInit.c usrRtpAppInit.c]
  1968. }
  1969. ############################################################################
  1970. #
  1971. # prj_vxWorks::close - hook to call on project close
  1972. #
  1973. proc close {hProj} {
  1974. cxrDocDelete $hProj
  1975. mxrDocDelete $hProj
  1976. }
  1977. ############################################################################
  1978. #
  1979. # prj_vxWorks::buildRuleListGet - return the list of build rules for vxWorks
  1980. #
  1981. proc buildRuleListGet {hProj} {
  1982. set retval vxWorks
  1983. if {![::prj_vxWorks_hidden::basedOnSimulator $hProj]} {
  1984. set retval [concat $retval \
  1985. vxWorks_rom \
  1986. vxWorks_rom.bin \
  1987. vxWorks_rom.hex \
  1988. vxWorks_romCompress \
  1989. vxWorks_romCompress.bin \
  1990. vxWorks_romCompress.hex \
  1991. vxWorks_romResident \
  1992. vxWorks_romResident.bin \
  1993. vxWorks_romResident.hex ]
  1994. }
  1995. return $retval
  1996. }
  1997. ############################################################################
  1998. #
  1999. # prj_vxWorks::buildRuleDefault - return the default build rule
  2000. #
  2001. proc buildRuleDefault {hProj} {
  2002. if {[string match [prjTagDataGet $hProj CORE_INFO_SUBTYPE] bootrom]} {
  2003. return vxWorks ;# This will need to be fixed!
  2004. } else {
  2005. return vxWorks
  2006. }
  2007. }
  2008. ############################################################################
  2009. #
  2010. # prj_vxWorks::buildCustomRuleListGet - get the list of custom build rules
  2011. #
  2012. proc buildCustomRuleListGet {} {
  2013. return [::prj_vxWorks_hidden::bspRulesGet]
  2014. }
  2015. ############################################################################
  2016. #
  2017. # prj_vxWorks::buildModify - modify a build spec for vxWorks projects
  2018. #
  2019. # After a buildSpec is created from toolchain defaults, this
  2020. # routine is called to make whatever modifications are needed
  2021. # for vxWorks projects.
  2022. # This routine:
  2023. # * adds appropriate -IXX flags for the vxWorks headers
  2024. # * adds -DCPU=$(CPU) -DTOOL=$(TOOL) -DTOOL_FAMILY=$(TOOL_FAMILY)
  2025. # * If another build-spec exists, it copies the BSP-specific build-macros
  2026. # from that spec:
  2027. # RAM_HIGH_ADRS. RAM_LOW_ADRS, ROM_SIZE, ROM_TEXT_ADRS,
  2028. # *IMI* flags (for I960).
  2029. # It also copies any defines and includes from that spec.
  2030. # that were not defaults. That way if the user adds custom -D and -I
  2031. # options to a build, those will be preserved when a new spec is
  2032. # created.
  2033. #
  2034. proc buildModify {hProj build} {
  2035. set tc [prjBuildTcGet $hProj $build]
  2036. set cc [${tc}::toolFindByFile foo.c]
  2037. set as [${tc}::toolFindByFile foo.s]
  2038. set tool [${tc}::tool]
  2039. set prjDir [file dirname [prjInfoGet $hProj fileName]]
  2040. set tgtDir [file join [Wind::tgtDir]]
  2041. set bspDir [prjTagDataGet $hProj BSP_DIR]
  2042. set inc [prjBuildMacroGet $hProj $build OPTION_INCLUDE_DIR]
  2043. set def [prjBuildMacroGet $hProj $build OPTION_DEFINE_MACRO]
  2044. set extraCppFlags "${inc}$prjDir ${inc}$bspDir ${inc}${tgtDir}/h \
  2045. ${inc}${tgtDir}/config/comps/src \
  2046. ${inc}${tgtDir}/h/wrn/coreip \
  2047. ${inc}${tgtDir}/src/drv ${def}CPU=[${tc}::cpu] \
  2048. ${def}TOOL_FAMILY=[${tc}::family] \
  2049. ${def}TOOL=${tool} ${def}PRJ_BUILD ${def}_WRS_KERNEL"
  2050. set cflags [prjBuildFlagsGet $hProj $build $cc]
  2051. set asflags [prjBuildFlagsGet $hProj $build $as]
  2052. # cflags and asflags are currently the toolchain's defaults.
  2053. # The CC_ARCH_SPEC may contain additional settings which should
  2054. # be used when building this project, e.g. if the BSP specifies
  2055. # a CPU_VARIANT.
  2056. foreach flag [::prj_vxWorks_hidden::bspMakeGet CC_ARCH_SPEC] {
  2057. if {[lsearch $cflags $flag] == -1} {
  2058. set cflags "$cflags $flag"
  2059. }
  2060. if {[lsearch $asflags $flag] == -1} {
  2061. set asflags "$asflags $flag"
  2062. }
  2063. }
  2064. prjBuildFlagsSet $hProj $build $cc "$cflags $extraCppFlags"
  2065. prjBuildFlagsSet $hProj $build $as "$asflags $extraCppFlags"
  2066. prjDepPathAdd $hProj $build [prjDepPathDefaults]
  2067. # try to copy BSP-specific build macros from an existing buildSpec
  2068. set buildList [prjBuildListGet $hProj]
  2069. if {[llength $buildList] > 1} {
  2070. set oldBuild [lindex $buildList 0]
  2071. set oldTc [prjBuildTcGet $hProj $oldBuild]
  2072. # Copy macros from old build if they exist in the old spec,
  2073. # but not in the new. This will get things like RAM_HIGH_ADRS, etc,
  2074. # without changing the toolchain values
  2075. foreach macro [prjBuildMacroListGet $hProj $oldBuild "" 1] {
  2076. set oldVal [prjBuildMacroGet $hProj $oldBuild $macro]
  2077. set newVal [prjBuildMacroGet $hProj $build $macro]
  2078. if {($oldVal != "") && ($newVal == "")} {
  2079. prjBuildMacroSet $hProj $build $macro $oldVal
  2080. }
  2081. }
  2082. # Copy custom C-preprocessor flags
  2083. foreach buildFlag "CFLAGS CFLAGS_AS" {
  2084. set tcFlags [${oldTc}::macroDefaultValGet $buildFlag]
  2085. foreach flag [prjBuildMacroGet $hProj $oldBuild $buildFlag] {
  2086. set searchFlag $flag
  2087. # if old flag is e.g. -DTOOL=diab, match
  2088. # -DTOOL=* in new flag. If we match, skip this
  2089. # flag. Otherwise we end up with e.g.
  2090. # -DTOOL=diab -DTOOL=gnu
  2091. if {[string match -D* $searchFlag]} {
  2092. regsub {=[^=]*} $searchFlag {=} searchFlag
  2093. append searchFlag *
  2094. }
  2095. if {[lsearch $tcFlags $searchFlag] != -1} {
  2096. continue
  2097. }
  2098. if {[lsearch $extraCppFlags $searchFlag] != -1} {
  2099. continue
  2100. }
  2101. prjBuildMacroSet $hProj $build $buildFlag \
  2102. "[prjBuildMacroGet $hProj $build $buildFlag] $flag"
  2103. }
  2104. }
  2105. }
  2106. }
  2107. ############################################################################
  2108. #
  2109. # prj_vxWorks::buildCmdGet - get the command needed to build an image
  2110. #
  2111. # RETURNS: a pair "command directory", so that invoking
  2112. # command in directory will build the desired image
  2113. #
  2114. proc buildCmdGet {hProj {rule ""} {spec ""}} {
  2115. # mTime - return the time of last modification of a file
  2116. # regenerate the Makefile if it is older than the project file
  2117. proc mTime file {
  2118. if {![file exists $file]} {
  2119. return 0
  2120. }
  2121. file stat $file statInfo
  2122. return $statInfo(mtime)
  2123. }
  2124. set prjDir [file dir [prjInfoGet $hProj fileName]]
  2125. set makeModTime [mTime [file join $prjDir [prjMakefile $hProj]]]
  2126. set prjModTime [prjInfoGet $hProj changed]
  2127. if {$prjModTime == ""} {
  2128. set prjModTime [mTime [prjInfoGet $hProj fileName]]
  2129. }
  2130. if {$makeModTime < $prjModTime} {
  2131. ::prj_vxWorks_hidden::makeGen $hProj \
  2132. [file join $prjDir \
  2133. [prjMakefile $hProj]]
  2134. }
  2135. # return the info
  2136. if {$spec == ""} {
  2137. set spec [prjBuildCurrentGet $hProj]
  2138. }
  2139. catch {file mkdir [file join $prjDir $spec]}
  2140. if {$rule != ""} {
  2141. set rule "DEFAULT_RULE=[lindex $rule end] $rule"
  2142. }
  2143. return [list "make -f [file join .. [prjMakefile $hProj]]\
  2144. BUILD_SPEC=$spec $rule" [buildDirGet $hProj $spec]]
  2145. }
  2146. ############################################################################
  2147. #
  2148. # prj_vxWorks::buildDirGet - get the build directory for given build spec
  2149. #
  2150. # SYNOPSIS
  2151. # \cs
  2152. # prj_vxWorks::buildDirGet <hProj> [<hSpec>]
  2153. # \ce
  2154. #
  2155. # DESCRIPTION
  2156. # This procedure simply returns the build directory of the project specified
  2157. # by <hProj>, for the build specification <hSpec>.
  2158. #
  2159. # If no <hSpec> is given, the current build specification is used
  2160. #
  2161. # PARAMETERS:
  2162. # hProj : handle of the project to get build directory for
  2163. # hSpec : build specification to get build directory for
  2164. #
  2165. # RETURNS: The path to the directory where build occurs for build spec
  2166. # <hSpec>
  2167. #
  2168. # ERRORS: N/A
  2169. #
  2170. # SEE ALSO: prjBuildCurrentGet, prj_vxWorks::buildCmdGet
  2171. #
  2172. proc buildDirGet {hProj {hSpec ""}} {
  2173. set prjDir [file dir [prjInfoGet $hProj fileName]]
  2174. if {$hSpec == ""} {
  2175. set hSpec [prjBuildCurrentGet $hProj]
  2176. }
  2177. set buildDir [file join $prjDir $hSpec]
  2178. # create directory if needed
  2179. if {! [file exists $buildDir]} {
  2180. catch {file mkdir $buildDir}
  2181. }
  2182. return $buildDir
  2183. }
  2184. ############################################################################
  2185. #
  2186. # prj_vxWorks::derivedObjsGet - get the derived objects produced the project
  2187. #
  2188. proc derivedObjsGet {hProj image} {
  2189. set prjDir [file dirname [prjInfoGet $hProj fileName]]
  2190. set build [prjBuildCurrentGet $hProj]
  2191. set tc [prjBuildTcGet $hProj $build]
  2192. set buildObjs ""
  2193. foreach file [prjFileListGet $hProj] {
  2194. if {"[set tool [::${tc}::toolFindByFile $file]]" == ""} {
  2195. continue
  2196. }
  2197. foreach obj [::${tool}::outputFiles $file] {
  2198. lappend buildObjs [file join $prjDir $build $obj]
  2199. }
  2200. }
  2201. if {"$tc" == "::tc_SIMNTgnu"} {
  2202. set image vxWorks.exe
  2203. }
  2204. set buildObjs "$buildObjs [file join $prjDir $build $image]"
  2205. return $buildObjs
  2206. }
  2207. prjTypeAdd ::prj_vxWorks
  2208. }