/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

Large files are truncated click here to view the full 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…