menv.ck 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946
  1. /*++
  2. Copyright (c) 2017 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. env.ck
  9. Abstract:
  10. This build module contains the environment and functions used throughout
  11. the Minoca OS build.
  12. Author:
  13. Evan Green 1-Feb-2017
  14. Environment:
  15. Build
  16. --*/
  17. //
  18. // -------------------------------------------------------------------- Imports
  19. //
  20. from mingen import config;
  21. from os import getenv, basename;
  22. //
  23. // -------------------------------------------------------------------- Globals
  24. //
  25. var mconfig;
  26. //
  27. // ------------------------------------------------------------------ Functions
  28. //
  29. function
  30. initListFromEnvironment (
  31. name,
  32. default
  33. )
  34. /*++
  35. Routine Description:
  36. This routine gets an environment variable. It either returns that
  37. environment variable wrapped in a list, or the given default.
  38. Arguments:
  39. name - Supplies the name of the environment variable.
  40. default - Supplies the default value to return if not set.
  41. Return Value:
  42. Returns eithe the provided default or has the contents of the environment
  43. variable wrapped in a list.
  44. --*/
  45. {
  46. var value = getenv(name);
  47. if (value != null) {
  48. return [value];
  49. }
  50. return default;
  51. }
  52. function
  53. getTools (
  54. )
  55. /*++
  56. Routine Description:
  57. This routine is called as part of setupEnv, at the end. It returns the
  58. basic set of tools used by the environment.
  59. Arguments:
  60. None.
  61. Return Value:
  62. Returns a list of the basic tools used in the environment.
  63. --*/
  64. {
  65. var buildCflagsLine = "$BUILD_BASE_CPPFLAGS $CPPFLAGS " +
  66. "$BUILD_BASE_CFLAGS $CFLAGS -MMD -MF $OUT.d ";
  67. var buildAsflagsLine = buildCflagsLine +
  68. "$BUILD_BASE_ASFLAGS $ASFLAGS ";
  69. var buildLdflagsLine = "$BUILD_BASE_LDFLAGS $LDFLAGS ";
  70. var cflagsLine = "$BASE_CPPFLAGS $CPPFLAGS $BASE_CFLAGS $CFLAGS "
  71. "-MMD -MF $OUT.d ";
  72. var asflagsLine = cflagsLine + "$BASE_ASFLAGS $ASFLAGS ";
  73. var entries;
  74. var ldflagsLine = "-Wl,-Map=$OUT.map $BASE_LDFLAGS $LDFLAGS ";
  75. var symlinkCommand = "ln -sf $SYMLINK_IN $OUT";
  76. var buildLdLine = "$BUILD_CC " + buildLdflagsLine +
  77. "-o $OUT $IN -Bdynamic $DYNLIBS";
  78. var tools;
  79. if (mconfig.build_os == "Windows") {
  80. symlinkCommand = "cp $IN $OUT";
  81. }
  82. //
  83. // On Mac OS there shouldn't be a -Bdynamic flag to indicate the start of
  84. // the dynamic libraries section.
  85. //
  86. if (mconfig.build_os == "Darwin") {
  87. buildLdLine = "$BUILD_CC " + buildLdflagsLine +
  88. "-o $OUT $IN $DYNLIBS";
  89. //
  90. // Create a .map file (except on Mac, which doesn't support it).
  91. //
  92. } else {
  93. buildLdflagsLine = "-Wl,-Map=$OUT.map " + buildLdflagsLine;
  94. }
  95. //
  96. // Define the tools used.
  97. //
  98. tools = [
  99. //
  100. // C compiler for target binaries.
  101. //
  102. {
  103. "type": "tool",
  104. "name": "cc",
  105. "command": "$CC " + cflagsLine + "-c -o $OUT $IN",
  106. "description": "Compiling - $IN",
  107. "depsformat": "gcc",
  108. "depfile": "$OUT.d"
  109. },
  110. //
  111. // C++ compiler for target binaries.
  112. //
  113. {
  114. "type": "tool",
  115. "name": "cxx",
  116. "command": "$CXX " + cflagsLine + "-c -o $OUT $IN",
  117. "description": "Compiling - $IN",
  118. "depsformat": "gcc",
  119. "depfile": "$OUT.d"
  120. },
  121. //
  122. // Linker for target binaries.
  123. //
  124. {
  125. "type": "tool",
  126. "name": "ld",
  127. "command": "$CC " + ldflagsLine + "-o $OUT $IN -Bdynamic $DYNLIBS",
  128. "description": "Linking - $OUT",
  129. },
  130. //
  131. // Static archiver for target binaries.
  132. //
  133. {
  134. "type": "tool",
  135. "name": "ar",
  136. "command": "$AR rcs $OUT $IN",
  137. "description": "Building Library - $OUT",
  138. },
  139. //
  140. // Assembler for target binaries.
  141. //
  142. {
  143. "type": "tool",
  144. "name": "as",
  145. "command": "$CC " + asflagsLine + "-c -o $OUT $IN",
  146. "description": "Assembling - $IN",
  147. "depsformat": "gcc",
  148. "depfile": "$OUT.d"
  149. },
  150. //
  151. // Objcopy for target binaries.
  152. //
  153. {
  154. "type": "tool",
  155. "name": "objcopy",
  156. "command": "$SHELL -c \"cd `dirname $IN` && "
  157. "$OBJCOPY $OBJCOPY_FLAGS `basename $IN` $OUT\"",
  158. "description": "Objectifying - $IN"
  159. },
  160. //
  161. // Strip for target binaries.
  162. //
  163. {
  164. "type": "tool",
  165. "name": "strip",
  166. "command": "$STRIP $STRIP_FLAGS -o $OUT $IN",
  167. "description": "Stripping - $OUT",
  168. },
  169. //
  170. // C compiler for the build machine.
  171. //
  172. {
  173. "type": "tool",
  174. "name": "build_cc",
  175. "command": "$BUILD_CC " + buildCflagsLine + "-c -o $OUT $IN",
  176. "description": "Compiling - $IN",
  177. "depsformat": "gcc",
  178. "depfile": "$OUT.d"
  179. },
  180. //
  181. // C++ compiler for the build machine.
  182. //
  183. {
  184. "type": "tool",
  185. "name": "build_cxx",
  186. "command": "$BUILD_CXX " + buildCflagsLine + "-c -o $OUT $IN",
  187. "description": "Compiling - $IN",
  188. "depsformat": "gcc",
  189. "depfile": "$OUT.d"
  190. },
  191. //
  192. // Linker for the build machine.
  193. //
  194. {
  195. "type": "tool",
  196. "name": "build_ld",
  197. "command": "$BUILD_CC " + buildLdflagsLine +
  198. "-o $OUT $IN -Bdynamic $DYNLIBS",
  199. "description": "Linking - $OUT",
  200. },
  201. //
  202. // Static archiver for the build machine.
  203. //
  204. {
  205. "type": "tool",
  206. "name": "build_ar",
  207. "command": "$BUILD_AR rcs $OUT $IN",
  208. "description": "Building Library - $OUT",
  209. },
  210. //
  211. // Assembler for the build machine.
  212. //
  213. {
  214. "type": "tool",
  215. "name": "build_as",
  216. "command": "$BUILD_CC " + buildAsflagsLine + "-c -o $OUT $IN",
  217. "description": "Assembling - $IN",
  218. "depsformat": "gcc",
  219. "depfile": "$OUT.d"
  220. },
  221. //
  222. // Strip for the build machine.
  223. //
  224. {
  225. "type": "tool",
  226. "name": "build_strip",
  227. "command": "$BUILD_STRIP $STRIP_FLAGS -o $OUT $IN",
  228. "description": "Stripping - $OUT",
  229. },
  230. //
  231. // Windows resource compiler for the build machine.
  232. //
  233. {
  234. "type": "tool",
  235. "name": "build_rcc",
  236. "command": "$RCC -o $OUT $IN",
  237. "description": "Compiling Resource - $IN",
  238. },
  239. //
  240. // ACPI assembler used to build firmware images.
  241. //
  242. {
  243. "type": "tool",
  244. "name": "iasl",
  245. "command": "$SHELL -c \"$IASL $IASL_FLAGS -p $OUT $IN > $OUT.stdout\"",
  246. "description": "Compiling ASL - $IN"
  247. },
  248. //
  249. // Copy files from one location to another.
  250. //
  251. {
  252. "type": "tool",
  253. "name": "copy",
  254. "command": "$SHELL -c \"cp $CPFLAGS $IN $OUT && [ -z $CHMOD_FLAGS ] || "
  255. "chmod $CHMOD_FLAGS $OUT\"",
  256. "description": "Copying - $IN -> $OUT"
  257. },
  258. //
  259. // Create symbolic links (or just copy on Windows).
  260. //
  261. {
  262. "type": "tool",
  263. "name": "symlink",
  264. "command": symlinkCommand,
  265. "description": "Symlinking - $OUT"
  266. },
  267. //
  268. // Touch a file with the date.
  269. //
  270. {
  271. "type": "tool",
  272. "name": "stamp",
  273. "command": "$SHELL -c \"date > $OUT\"",
  274. "description": "Stamp - $OUT"
  275. },
  276. //
  277. // Touch to create a timestamped empty file.
  278. //
  279. {
  280. "type": "tool",
  281. "name": "touch",
  282. "command": "touch $OUT",
  283. "description": "Touch - $OUT"
  284. },
  285. //
  286. // Create a directory.
  287. //
  288. {
  289. "type": "tool",
  290. "name": "mkdir",
  291. "command": "mkdir -p $OUT",
  292. "description": "mkdir $OUT"
  293. },
  294. //
  295. // Generate a version.h.
  296. //
  297. {
  298. "type": "tool",
  299. "name": "gen_version",
  300. "command": "$SHELL $S/tasks/build/print_version.sh $OUT $FORM "
  301. "$MAJOR $MINOR $REVISION $RELEASE $SERIAL $BUILD_STRING",
  302. "description": "Versioning - $OUT"
  303. }];
  304. return tools;
  305. }
  306. function
  307. setupEnv (
  308. )
  309. /*++
  310. Routine Description:
  311. This routine is called once to set up the build environment.
  312. Arguments:
  313. None.
  314. Return Value:
  315. Returns the basic set of tools used by the environment.
  316. --*/
  317. {
  318. var archVariant;
  319. //
  320. // Prefer Ninja files.
  321. //
  322. config.format ?= "ninja";
  323. //
  324. // Set up the Minoca config dictionary.
  325. //
  326. mconfig = {};
  327. mconfig.build_os = config.build_os;
  328. mconfig.build_machine = config.build_machine;
  329. mconfig.build_variant = "";
  330. if (mconfig.build_machine == "i686") {
  331. mconfig.build_arch = "x86";
  332. } else if (mconfig.build_machine == "i586") {
  333. mconfig.build_arch = "x86";
  334. mconfig.build_variant = "q";
  335. } else if ((mconfig.build_machine == "armv7") ||
  336. (mconfig.build_machine == "armv6")) {
  337. mconfig.build_arch = mconfig.build_machine;
  338. } else if (mconfig.build_machine == "x86_64") {
  339. mconfig.build_arch = "x64";
  340. }
  341. mconfig.arch = getenv("ARCH");
  342. mconfig.arch ?= mconfig.build_arch;
  343. mconfig.arch ?= "x86";
  344. mconfig.debug = getenv("DEBUG");
  345. mconfig.debug ?= "dbg";
  346. mconfig.variant = getenv("VARIANT");
  347. mconfig.variant ?= mconfig.build_variant;
  348. mconfig.release_level = "SystemReleaseDevelopment";
  349. mconfig.cflags = initListFromEnvironment("CFLAGS",
  350. ["-O2", "-Wall", "-Werror"]);
  351. mconfig.kernelCflags = [];
  352. mconfig.cppflags = initListFromEnvironment("CPPFLAGS", []);
  353. mconfig.ldflags = initListFromEnvironment("LDFLAGS", []);
  354. mconfig.asflags = initListFromEnvironment("ASFLAGS", []);
  355. mconfig.stripflags = initListFromEnvironment("STRIP_FLAGS", []);
  356. mconfig.build_cc = getenv("BUILD_CC");
  357. mconfig.build_cc ?= "gcc";
  358. mconfig.build_ar = getenv("BUILD_AR");
  359. mconfig.build_ar ?= "ar";
  360. mconfig.build_strip = getenv("BUILD_STRIP");
  361. mconfig.build_strip ?= "strip";
  362. config.output ?= "$S/../" + mconfig.arch + mconfig.variant + mconfig.debug +
  363. "/obj/os";
  364. mconfig.outroot = "$O/../..";
  365. mconfig.binroot = mconfig.outroot + "/bin";
  366. mconfig.stripped = mconfig.binroot + "/stripped";
  367. mconfig.cc = getenv("CC");
  368. mconfig.ar = getenv("AR");
  369. mconfig.objcopy = getenv("OBJCOPY");
  370. mconfig.strip = getenv("STRIP");
  371. mconfig.rcc = getenv("RCC");
  372. mconfig.rcc ?= "windres";
  373. mconfig.iasl = getenv("IASL");
  374. mconfig.iasl ?= "iasl";
  375. mconfig.shell = getenv("SHELL");
  376. mconfig.shell ?= "sh";
  377. mconfig.target = null;
  378. //
  379. // Add in the command line variables, then define the derived variables.
  380. //
  381. for (key in config.cmdvars) {
  382. mconfig[key] = config.cmdvars[key];
  383. }
  384. archVariant = mconfig.arch + mconfig.variant;
  385. if (!mconfig.target) {
  386. if (archVariant == "x86") {
  387. mconfig.target = "i686-pc-minoca";
  388. } else if (archVariant == "x86q") {
  389. mconfig.target = "i586-pc-minoca";
  390. } else if ((mconfig.arch == "armv7") || (mconfig.arch == "armv6")) {
  391. mconfig.target = "arm-none-minoca";
  392. } else if (mconfig.arch == "x64") {
  393. mconfig.target = "x86_64-pc-minoca";
  394. } else {
  395. Core.raise(ValueError("Unknown architecture" + mconfig.arch));
  396. }
  397. }
  398. mconfig.native = false;
  399. if ((mconfig.build_os == "Minoca") &&
  400. (mconfig.arch == mconfig.build_arch)) {
  401. mconfig.native = true;
  402. }
  403. if (mconfig.native) {
  404. mconfig.cc ?= mconfig.build_cc;
  405. mconfig.ar ?= mconfig.build_ar;
  406. mconfig.strip ?= mconfig.build_strip;
  407. mconfig.objcopy ?= "objcopy";
  408. } else {
  409. mconfig.cc ?= mconfig.target + "-gcc";
  410. mconfig.ar ?= mconfig.target + "-ar";
  411. mconfig.strip ?= mconfig.target + "-strip";
  412. mconfig.objcopy ?= mconfig.target + "-objcopy";
  413. }
  414. if (mconfig.debug == "dbg") {
  415. mconfig.cflags += ["-DDEBUG=1"];
  416. } else {
  417. mconfig.cflags += ["-Wno-unused-but-set-variable", "-DNDEBUG"];
  418. }
  419. mconfig.cflags += ["-fno-builtin",
  420. "-g",
  421. "-save-temps=obj",
  422. "-ffunction-sections",
  423. "-fdata-sections",
  424. "-fvisibility=hidden"];
  425. mconfig.cppflags += ["-I$S/include"];
  426. mconfig.build_cflags = [] + mconfig.cflags;
  427. mconfig.build_cppflags = [] + mconfig.cppflags;
  428. mconfig.cflags += ["-fpic"];
  429. //
  430. // Windows cannot handle -fpic, but everyone else can.
  431. //
  432. if (mconfig.build_os == "Windows") {
  433. mconfig.build_cflags += ["-mno-ms-bitfields"];
  434. } else {
  435. mconfig.build_cflags += ["-fpic"];
  436. }
  437. if (mconfig.build_os == "Darwin") {
  438. mconfig.build_cflags += ["-Wno-tautological-compare",
  439. "-Wno-parentheses-equality"];
  440. }
  441. //
  442. // Add some architecture variant flags.
  443. //
  444. if (archVariant == "x86q") {
  445. mconfig.cppflags += ["-Wa,-momit-lock-prefix=yes", "-march=i586"];
  446. } else if (archVariant == "x64") {
  447. mconfig.kernelCflags = ["-mno-sse", "-mno-red-zone"];
  448. } else if (archVariant == "armv6") {
  449. mconfig.cflags += ["-march=armv6zk", "-marm", "-mfpu=vfp"];
  450. }
  451. mconfig.build_asflags = [];
  452. mconfig.asflags += ["-Wa,-g"];
  453. mconfig.build_ldflags = initListFromEnvironment("BUILD_LDFLAGS",
  454. [] + mconfig.ldflags);
  455. mconfig.ldflags += ["-Wl,--gc-sections"];
  456. //
  457. // Mac OS cannot handle --gc-sections or strip -p.
  458. //
  459. if (mconfig.build_os != "Darwin") {
  460. mconfig.build_ldflags += ["-Wl,--gc-sections"];
  461. mconfig.stripflags += ["-p"];
  462. }
  463. //
  464. // Define the set of variables that get passed all the way through to the
  465. // final Make/ninja file. Passing these on as variables rather than
  466. // substituting during the mingen build process allows for a smaller
  467. // build file, and easier manual tweaking by the user.
  468. //
  469. config.vars = {
  470. "BUILD_CC": mconfig.build_cc,
  471. "BUILD_AR": mconfig.build_ar,
  472. "BUILD_STRIP": mconfig.build_strip,
  473. "CC": mconfig.cc,
  474. "AR": mconfig.ar,
  475. "STRIP": mconfig.strip,
  476. "OBJCOPY": mconfig.objcopy,
  477. "RCC": mconfig.rcc,
  478. "IASL": mconfig.iasl,
  479. "SHELL": mconfig.shell,
  480. "BASE_CFLAGS": mconfig.cflags,
  481. "KERNEL_CFLAGS": mconfig.kernelCflags,
  482. "BASE_CPPFLAGS": mconfig.cppflags,
  483. "BASE_LDFLAGS": mconfig.ldflags,
  484. "BASE_ASFLAGS": mconfig.asflags,
  485. "BUILD_BASE_CFLAGS": mconfig.build_cflags,
  486. "BUILD_BASE_CPPFLAGS": mconfig.build_cppflags,
  487. "BUILD_BASE_LDFLAGS": mconfig.build_ldflags,
  488. "BUILD_BASE_ASFLAGS": mconfig.build_asflags,
  489. "STRIP_FLAGS": mconfig.stripflags,
  490. "IASL_FLAGS": ["-we"]
  491. };
  492. if (config.verbose) {
  493. Core.print("Minoca Build Configuration:");
  494. for (key in mconfig) {
  495. Core.print("\t%s: %s" % [key, mconfig[key].__str()]);
  496. }
  497. }
  498. return getTools();
  499. }
  500. function
  501. addConfig (
  502. entry,
  503. name,
  504. value
  505. )
  506. /*++
  507. Routine Description:
  508. This routine adds a configure option to a list, ensuring that both the
  509. config dictionary and option already exist.
  510. Arguments:
  511. entry - Supplies the entry to add the configure option to.
  512. name - Supplies the name of the option to add.
  513. value - Supplies the new value to add to the list of options.
  514. Return Value:
  515. None.
  516. --*/
  517. {
  518. if (!entry.get("config")) {
  519. entry.config = {};
  520. }
  521. if (!entry.config.get(name)) {
  522. entry.config[name] = [];
  523. }
  524. entry.config[name] += [value];
  525. return;
  526. }
  527. function
  528. group (
  529. name,
  530. entries
  531. )
  532. /*++
  533. Routine Description:
  534. This routine creates a phony target that groups a bunch of different
  535. targets together under a common name.
  536. Arguments:
  537. name - Supplies the name of the new group target.
  538. entries - Supplies the list of entries.
  539. Return Value:
  540. Returns a list containing the entry for the group target.
  541. --*/
  542. {
  543. var entry = {
  544. "label": name,
  545. "type": "target",
  546. "tool": "phony",
  547. "inputs": entries,
  548. "config": {}
  549. };
  550. return [entry];
  551. }
  552. function
  553. touch (
  554. destination,
  555. destinationLabel,
  556. mode
  557. )
  558. /*++
  559. Routine Description:
  560. This routine creates an empty file target.
  561. Arguments:
  562. destination - Supplies the copy destination.
  563. destinationLabel - Supplies a label naming the target.
  564. mode - Supplies the chmod mode of the destination.
  565. Return Value:
  566. Returns a list containing the copy entry.
  567. --*/
  568. {
  569. var config = {};
  570. if (mode) {
  571. config["CHMOD_FLAGS"] = mode;
  572. }
  573. destinationLabel ?= destination;
  574. var entry = {
  575. "type": "target",
  576. "tool": "touch",
  577. "label": destinationLabel,
  578. "output": destination,
  579. "config": config
  580. };
  581. return [entry];
  582. }
  583. function
  584. makedir (
  585. destination,
  586. destinationLabel
  587. )
  588. /*++
  589. Routine Description:
  590. This routine creates an empty directory target.
  591. Arguments:
  592. destination - Supplies the copy destination.
  593. destinationLabel - Supplies a label naming the target.
  594. Return Value:
  595. Returns a list containing the copy entry.
  596. --*/
  597. {
  598. destinationLabel ?= destination;
  599. var entry = {
  600. "type": "target",
  601. "tool": "mkdir",
  602. "label": destinationLabel,
  603. "output": destination,
  604. };
  605. return [entry];
  606. }
  607. function
  608. copy (
  609. source,
  610. destination,
  611. destinationLabel,
  612. flags,
  613. mode
  614. )
  615. /*++
  616. Routine Description:
  617. This routine creates a target that copies a file from one place to another.
  618. Arguments:
  619. source - Supplies the source to copy.
  620. destination - Supplies the copy destination.
  621. destinationLabel - Supplies a label naming the copy target.
  622. flags - Supplies the flags to include in the copy.
  623. mode - Supplies the chmod mode of the destination.
  624. Return Value:
  625. Returns a list containing the copy entry.
  626. --*/
  627. {
  628. var config = {};
  629. if (flags) {
  630. config["CPFLAGS"] = flags;
  631. }
  632. if (mode) {
  633. config["CHMOD_FLAGS"] = mode;
  634. }
  635. var entry = {
  636. "type": "target",
  637. "tool": "copy",
  638. "label": destinationLabel,
  639. "inputs": [source],
  640. "output": destination,
  641. "config": config
  642. };
  643. if (!destinationLabel) {
  644. entry["label"] = destination;
  645. }
  646. return [entry];
  647. }
  648. function
  649. strip (
  650. params
  651. )
  652. /*++
  653. Routine Description:
  654. This routine converts an entry to a strip entry, where the target will be
  655. stripped.
  656. Arguments:
  657. params - Supplies the existing entry.
  658. Return Value:
  659. Returns a list containing the strip entry.
  660. --*/
  661. {
  662. params.type = "target";
  663. params.tool = "strip";
  664. if (params.get("build")) {
  665. params.tool = "build_strip";
  666. }
  667. return [params];
  668. }
  669. function
  670. binplace (
  671. params
  672. )
  673. /*++
  674. Routine Description:
  675. This routine replaces the current target with a copied version in the
  676. final bin directory. This will also create a stripped version in the
  677. stripped directory unless told not to.
  678. Arguments:
  679. params - Supplies the existing entry.
  680. Return Value:
  681. Returns a list containing the strip entry.
  682. --*/
  683. {
  684. var build = params.get("build");
  685. var copiedEntry;
  686. var cpflags = params.get("cpflags");;
  687. var destination;
  688. var destinationLabel;
  689. var destinationPath;
  690. var element;
  691. var entries = [];
  692. var extraCopy;
  693. var fileName;
  694. var label = params.get("label");
  695. var mode = params.get("mode");
  696. var newOriginalLabel;
  697. var originalTarget;
  698. var source = params.get("output");
  699. var strippedEntry;
  700. var strippedOutput;
  701. label ?= source;
  702. source ?= label;
  703. if ((!label) || (!source)) {
  704. Core.raise(ValueError("Label or output must be defined"));
  705. }
  706. //
  707. // Set the output since the label is going to be renamed and create the
  708. // copy target.
  709. //
  710. params.output = source;
  711. params.type = "target";
  712. fileName = basename(source);
  713. destination = params.get("binplace");
  714. newOriginalLabel = label + "_orig";
  715. originalTarget = ":" + newOriginalLabel;
  716. //
  717. // Create the first or only one with the genuine label.
  718. //
  719. element = destination;
  720. if (element is List) {
  721. element = element[0];
  722. }
  723. if (!element) {
  724. element = "bin";
  725. }
  726. destinationPath = mconfig.outroot + "/" + element + "/" + fileName;
  727. copiedEntry = copy(originalTarget,
  728. destinationPath,
  729. label,
  730. cpflags,
  731. mode)[0];
  732. entries.append(copiedEntry);
  733. //
  734. // Handle binplacing into several areas.
  735. //
  736. if (destination is List) {
  737. for (index in 1..destination.length()) {
  738. element = destination[index];
  739. if (!element) {
  740. element = "bin";
  741. }
  742. destinationPath = mconfig.outroot + "/" + element + "/" + fileName;
  743. destinationLabel = "%s_%d" % [label, index];
  744. extraCopy = copy(originalTarget,
  745. destinationPath,
  746. destinationLabel,
  747. cpflags,
  748. mode)[0];
  749. copiedEntry.implicit = [":" + destinationLabel];
  750. entries.append(extraCopy);
  751. }
  752. }
  753. //
  754. // The original label was given to the copied destination, so tack an _orig
  755. // on the source label.
  756. //
  757. params.label = newOriginalLabel;
  758. //
  759. // Unless asked not to, create a stripped entry as well.
  760. //
  761. if (!params.get("nostrip")) {
  762. if (build) {
  763. strippedOutput = mconfig.stripped + "/build/" + fileName;
  764. } else {
  765. strippedOutput = mconfig.stripped + "/" + fileName;
  766. }
  767. strippedEntry = {
  768. "label": label + "_stripped",
  769. "inputs": [originalTarget],
  770. "output": strippedOutput,
  771. "build": build,
  772. };
  773. //
  774. // Make the binplaced copy depend on the stripped version.
  775. //
  776. copiedEntry.implicit = [":" + strippedEntry["label"]];
  777. entries += strip(strippedEntry);
  778. }
  779. entries.append(params);
  780. return entries;
  781. }
  782. function
  783. compiledSources (
  784. params
  785. )
  786. /*++
  787. Routine Description:
  788. This routine compiles a group of object file targets from source files.
  789. Arguments:
  790. params - Supplies the entry with inputs filled out.
  791. Return Value:
  792. Returns the list containing a list of object names, and a list of object
  793. targets.
  794. --*/
  795. {
  796. var build = params.get("build");
  797. var entries = [];
  798. var ext;
  799. var includes = params.get("includes");
  800. var inputParts;
  801. var inputs = params.inputs;
  802. var objName;
  803. var obj;
  804. var objs = [];
  805. var sourcesConfig = params.get("sources_config");
  806. var prefix = params.get("prefix");
  807. var suffix;
  808. var tool;
  809. if (includes) {
  810. sourcesConfig ?= {};
  811. if (!sourcesConfig.get("CPPFLAGS")) {
  812. sourcesConfig.CPPFLAGS = [];
  813. }
  814. for (include in includes) {
  815. sourcesConfig["CPPFLAGS"] += ["-I" + include];
  816. }
  817. }
  818. if (inputs.length() == 0) {
  819. Core.raise(ValueError("Compilation must have inputs"));
  820. }
  821. for (input in inputs) {
  822. inputParts = input.rsplit(".", 1);
  823. try {
  824. ext = inputParts[1];
  825. } except IndexError {
  826. ext = "";
  827. }
  828. suffix = ".o";
  829. if (ext == "c") {
  830. tool = "cc";
  831. } else if (ext == "cc") {
  832. tool = "cxx";
  833. } else if (ext == "S") {
  834. tool = "as";
  835. } else if (ext == "rc") {
  836. tool = "rcc";
  837. suffix = ".rsc";
  838. } else {
  839. objs += [input];
  840. continue;
  841. }
  842. if (build) {
  843. tool = "build_" + tool;
  844. }
  845. objName = inputParts[0] + suffix;
  846. if (objName[0] == ":") {
  847. objName = objName[1...-1];
  848. }
  849. if (prefix) {
  850. objName = prefix + "/" + objName;
  851. }
  852. obj = {
  853. "type": "target",
  854. "label": objName,
  855. "output": objName,
  856. "inputs": [input],
  857. "tool": tool,
  858. "config": sourcesConfig,
  859. };
  860. entries += [obj];
  861. objs += [":" + objName];
  862. }
  863. if (prefix) {
  864. if (!params.get("output")) {
  865. params.output = params.label;
  866. }
  867. params.output = prefix + "/" + params.output;
  868. }
  869. return [objs, entries];
  870. }
  871. function
  872. executable (
  873. params
  874. )
  875. /*++
  876. Routine Description:
  877. This routine links a set of sources into some sort of executable or shared
  878. object.
  879. Arguments:
  880. params - Supplies the entry with inputs filled out.
  881. Return Value:
  882. Returns the list of the linked entry.
  883. --*/
  884. {
  885. var build = params.get("build");
  886. var entry = params.get("entry");
  887. var compilation = compiledSources(params);
  888. var linkerScript = params.get("linker_script");
  889. var objs = compilation[0];
  890. var entries = compilation[1];
  891. var textAddress = params.get("text_address");;
  892. params.type = "target";
  893. params.inputs = objs;
  894. params.tool = "ld";
  895. if (build) {
  896. params.tool = "build_ld";
  897. }
  898. //
  899. // Convert options for text_address, linker_script, and entry to actual
  900. // LDFLAGS.
  901. //
  902. if (textAddress) {
  903. addConfig(params, "LDFLAGS", "-Wl,-Ttext-segment=" + textAddress);
  904. addConfig(params,
  905. "LDFLAGS",
  906. "-Wl,--section-start,.init=" + textAddress);
  907. }
  908. if (linkerScript) {
  909. addConfig(params, "LDFLAGS", "-Wl,-T" + linkerScript);
  910. }
  911. if (entry != null) {
  912. addConfig(params, "LDFLAGS", "-Wl,-e" + entry);
  913. addConfig(params, "LDFLAGS", "-Wl,-u" + entry);
  914. }
  915. if (params.get("binplace")) {
  916. entries += binplace(params);
  917. } else {
  918. entries += [params];
  919. }
  920. return entries;
  921. }
  922. function
  923. application (
  924. params
  925. )
  926. /*++
  927. Routine Description:
  928. This routine creates a position independent application.
  929. Arguments:
  930. params - Supplies the entry with inputs filled out.
  931. Return Value:
  932. Returns the list of the application entry.
  933. --*/
  934. {
  935. var build = params.get("build");
  936. var exename = params.get("output");
  937. exename ?= params.get("label");
  938. if (!exename) {
  939. Core.raise(ValueError("Missing output or label"));
  940. }
  941. if (build && (mconfig.build_os == "Windows")) {
  942. params.output = exename + ".exe";
  943. }
  944. if (build && (mconfig.build_os == "Darwin")) {
  945. addConfig(params, "LDFLAGS", "-Wl,-pie");
  946. } else {
  947. addConfig(params, "LDFLAGS", "-pie");
  948. }
  949. if ((!build) && (params.get("binplace") == null)) {
  950. params.binplace = "bin";
  951. }
  952. return executable(params);
  953. }
  954. function
  955. staticApplication (
  956. params
  957. )
  958. /*++
  959. Routine Description:
  960. This routine creates a static application suitable for kernel or firmware
  961. environments.
  962. Arguments:
  963. params - Supplies the entry with inputs filled out.
  964. Return Value:
  965. Returns the list of the application entry.
  966. --*/
  967. {
  968. if (!(params.get("sources_config") is Dict)) {
  969. params.sources_config = {};
  970. }
  971. if (!(params.sources_config.get("CFLAGS") is List)) {
  972. params.sources_config.CFLAGS = [];
  973. }
  974. params.sources_config.CFLAGS += ["$KERNEL_CFLAGS"];
  975. addConfig(params, "LDFLAGS", "-static");
  976. addConfig(params, "LDFLAGS", "-nostdlib");
  977. return executable(params);
  978. }
  979. function
  980. sharedLibrary (
  981. params
  982. )
  983. /*++
  984. Routine Description:
  985. This routine creates a shared library or DLL.
  986. Arguments:
  987. params - Supplies the entry with inputs filled out.
  988. Return Value:
  989. Returns the list of the application entry.
  990. --*/
  991. {
  992. var build = params.get("build");
  993. var majorVersion = params.get("major_version");
  994. var minorVersion = params.get("minor_version");
  995. var soname = params.get("soname");
  996. soname ?= params.get("output");
  997. soname ?= params.get("label");
  998. if (!soname) {
  999. Core.raise(ValueError(
  1000. "One of output, label, or soname must be defined."));
  1001. }
  1002. //
  1003. // Darwin shared libraries build with a whole different ballgame of options.
  1004. //
  1005. if (build && (mconfig.build_os == "Darwin")) {
  1006. majorVersion ?= "0";
  1007. minorVersion ?= "0";
  1008. soname += ".%s.dylib" % majorVersion;
  1009. addConfig(params,
  1010. "LDFLAGS",
  1011. "-undefined dynamic_lookup -dynamiclib");
  1012. addConfig(params,
  1013. "LDFLAGS",
  1014. "-current_version %s.%s" % [majorVersion, minorVersion]);
  1015. addConfig(params,
  1016. "LDFLAGS",
  1017. "-compatibility_version %s.%d" % [majorVersion, 0]);
  1018. } else {
  1019. addConfig(params, "LDFLAGS", "-shared");
  1020. if ((!build) || (mconfig.build_os != "Windows")) {
  1021. soname += ".so";
  1022. if (majorVersion != null) {
  1023. soname += "." + majorVersion;
  1024. }
  1025. addConfig(params, "LDFLAGS", "-Wl,-soname=" + soname);
  1026. } else {
  1027. soname += ".dll";
  1028. }
  1029. }
  1030. params.output = soname;
  1031. if ((!build) && (params.get("binplace") == null)) {
  1032. params.binplace = "bin";
  1033. }
  1034. return executable(params);
  1035. }
  1036. function
  1037. staticLibrary (
  1038. params
  1039. )
  1040. /*++
  1041. Routine Description:
  1042. This routine creates a static library.
  1043. Arguments:
  1044. params - Supplies the entry with inputs filled out.
  1045. Return Value:
  1046. Returns the list of the application entry.
  1047. --*/
  1048. {
  1049. var build = params.get("build");
  1050. var compilation = compiledSources(params);
  1051. var objs = compilation[0];
  1052. var output;
  1053. var entries = compilation[1];
  1054. params.type = "target";
  1055. output = params.get("output");
  1056. output ?= params.get("label");
  1057. if (!output) {
  1058. Core.raise(ValueError("output or label must be defined"));
  1059. }
  1060. params.output = output + ".a";
  1061. params.inputs = objs;
  1062. params.tool = "ar";
  1063. if (build) {
  1064. params.tool = "build_ar";
  1065. }
  1066. if (params.get("binplace")) {
  1067. entries += binplace(params);
  1068. } else {
  1069. entries += [params];
  1070. }
  1071. return entries;
  1072. }
  1073. function
  1074. kernelLibrary (
  1075. params
  1076. )
  1077. /*++
  1078. Routine Description:
  1079. This routine creates a static library compiled suitably for running within
  1080. the kernel.
  1081. Arguments:
  1082. params - Supplies the entry with inputs filled out.
  1083. Return Value:
  1084. Returns the list of the application entry.
  1085. --*/
  1086. {
  1087. if (!(params.get("sources_config") is Dict)) {
  1088. params.sources_config = {};
  1089. }
  1090. if (!(params.sources_config.get("CFLAGS") is List)) {
  1091. params.sources_config.CFLAGS = [];
  1092. }
  1093. params.sources_config.CFLAGS += ["$KERNEL_CFLAGS"];
  1094. return staticLibrary(params);
  1095. }
  1096. function
  1097. compiledAsl (
  1098. inputs
  1099. )
  1100. /*++
  1101. Routine Description:
  1102. This routine creates a list of compiled .aml files from a list of .asl
  1103. files.
  1104. Arguments:
  1105. params - Supplies the entry with inputs filled out.
  1106. Return Value:
  1107. Returns a list where the first element is a list of all the resulting
  1108. target names, and the second element is a list of the target entries.
  1109. --*/
  1110. {
  1111. var entries = [];
  1112. var ext;
  1113. var inputParts;
  1114. var objName;
  1115. var obj;
  1116. var objs = [];
  1117. if (inputs.length() == 0) {
  1118. Core.raise(ValueError("Compilation must have inputs"));
  1119. }
  1120. for (input in inputs) {
  1121. inputParts = input.rsplit(".", 1);
  1122. ext = inputParts[1];
  1123. objName = inputParts[0] + ".aml";
  1124. obj = {
  1125. "type": "target",
  1126. "label": objName,
  1127. "output": objName,
  1128. "inputs": [input],
  1129. "tool": "iasl"
  1130. };
  1131. entries += [obj];
  1132. objs += [":" + objName];
  1133. }
  1134. return [objs, entries];
  1135. }
  1136. function
  1137. objectifiedBinaries (
  1138. params
  1139. )
  1140. /*++
  1141. Routine Description:
  1142. This routine creates a group of object file targets from binary files.
  1143. Arguments:
  1144. params - Supplies the entry with inputs filled out.
  1145. Return Value:
  1146. Returns a list of object names in the first element and the object file
  1147. target entries in the second element.
  1148. --*/
  1149. {
  1150. var build = params.get("build");
  1151. var entries = [];
  1152. var inputs = params.inputs;
  1153. var obj;
  1154. var objcopyConfig = params.get("config");
  1155. var objName;
  1156. var objs = [];
  1157. var prefix = params.get("prefix");
  1158. var tool;
  1159. if (inputs.length() == 0) {
  1160. Core.raise(ValueError("Compilation must have inputs"));
  1161. }
  1162. for (input in inputs) {
  1163. tool = "objcopy";
  1164. if (build) {
  1165. tool = "build_objcopy";;
  1166. }
  1167. objName = input + ".o";
  1168. if (prefix) {
  1169. objName = prefix + "/" + objName;
  1170. }
  1171. obj = {
  1172. "type": "target",
  1173. "label": objName,
  1174. "output": objName,
  1175. "inputs": [input],
  1176. "tool": tool,
  1177. "config": objcopyConfig,
  1178. };
  1179. entries += [obj];
  1180. objs += [":" + objName];
  1181. }
  1182. if (prefix) {
  1183. params.output ?= params.label;
  1184. params.output = prefix + "/" + params.output;
  1185. }
  1186. return [objs, entries];
  1187. }
  1188. function
  1189. objectifiedBinary (
  1190. params
  1191. )
  1192. /*++
  1193. Routine Description:
  1194. This routine creates a single object file from a binary file.
  1195. Arguments:
  1196. params - Supplies the entry with inputs filled out.
  1197. Return Value:
  1198. Returns a list of the object file.
  1199. --*/
  1200. {
  1201. return objectifiedBinaries(params)[1];
  1202. }
  1203. function
  1204. objectifiedLibrary (
  1205. params
  1206. )
  1207. /*++
  1208. Routine Description:
  1209. This routine creates a library from a set of objectified files.
  1210. Arguments:
  1211. params - Supplies the entry with inputs filled out.
  1212. Return Value:
  1213. Returns a list of the object file.
  1214. --*/
  1215. {
  1216. var build = params.get("build");
  1217. var compilation = objectifiedBinaries(params);
  1218. var objs = compilation[0];
  1219. var entries = compilation[1];
  1220. var output = params.get("output");
  1221. params.type = "target";
  1222. output ?= params.label;
  1223. params.output = output + ".a";
  1224. params.inputs = objs;
  1225. params.tool = "ar";
  1226. if (build) {
  1227. params.tool = "build_ar";
  1228. }
  1229. entries += [params];
  1230. return entries;
  1231. }
  1232. //
  1233. // Create a flat binary from an executable image.
  1234. //
  1235. function
  1236. flattenedBinary (
  1237. params
  1238. )
  1239. /*++
  1240. Routine Description:
  1241. This routine creates a flat binary from an executable image.
  1242. Arguments:
  1243. params - Supplies the entry with inputs filled out.
  1244. Return Value:
  1245. Returns a list of the flat binary.
  1246. --*/
  1247. {
  1248. var entries;
  1249. params.type = "target";
  1250. params.tool = "objcopy";
  1251. addConfig(params, "OBJCOPY_FLAGS", "-O binary");
  1252. if (params.get("binplace")) {
  1253. params.nostrip = true;
  1254. entries = binplace(params);
  1255. } else {
  1256. entries = [params];
  1257. }
  1258. return entries;
  1259. }
  1260. function
  1261. driver (
  1262. params
  1263. )
  1264. /*++
  1265. Routine Description:
  1266. This routine creates a Minoca kernel driver.
  1267. Arguments:
  1268. params - Supplies the entry with inputs filled out.
  1269. Return Value:
  1270. Returns a list of the driver entry.
  1271. --*/
  1272. {
  1273. var soname = params.get("output");
  1274. if (!params.get("entry")) {
  1275. params.entry = "DriverEntry";
  1276. }
  1277. if (!(params.get("sources_config") is Dict)) {
  1278. params.sources_config = {};
  1279. }
  1280. if (!(params.sources_config.get("CFLAGS") is List)) {
  1281. params.sources_config.CFLAGS = [];
  1282. }
  1283. params.sources_config.CFLAGS += ["$KERNEL_CFLAGS"];
  1284. params.binplace = "bin";
  1285. soname ?= params.get("label");
  1286. if (soname != "kernel") {
  1287. soname += ".drv";
  1288. params.output = soname;
  1289. params.inputs += ["kernel:kernel"];
  1290. }
  1291. addConfig(params, "LDFLAGS", "-shared");
  1292. addConfig(params, "LDFLAGS", "-Wl,-soname=" + soname);
  1293. addConfig(params, "LDFLAGS", "-nostdlib");
  1294. return executable(params);
  1295. }
  1296. function
  1297. uefiRuntimeFfs (
  1298. name
  1299. )
  1300. /*++
  1301. Routine Description:
  1302. This routine creates a runtime driver .FFS file from an ELF file.
  1303. Arguments:
  1304. params - Supplies the entry with inputs filled out.
  1305. Return Value:
  1306. Returns a list of the .FFS entry.
  1307. --*/
  1308. {
  1309. var elfconvConfig;
  1310. var ffs;
  1311. var pe;
  1312. elfconvConfig = {
  1313. "ELFCONV_FLAGS": "-t efiruntimedriver"
  1314. };
  1315. pe = {
  1316. "type": "target",
  1317. "label": name,
  1318. "inputs": [":" + name + ".elf"],
  1319. "implicit": ["uefi/tools/elfconv:elfconv"],
  1320. "tool": "elfconv",
  1321. "config": elfconvConfig
  1322. };
  1323. ffs = {
  1324. "type": "target",
  1325. "label": name + ".ffs",
  1326. "inputs": [":" + name],
  1327. "implicit": ["uefi/tools/genffs:genffs"],
  1328. "tool": "genffs_runtime"
  1329. };
  1330. return [pe, ffs];
  1331. }
  1332. function
  1333. uefiFwvol (
  1334. path,
  1335. name,
  1336. ffs
  1337. )
  1338. /*++
  1339. Routine Description:
  1340. This routine creates a UEFI firmware volume object file based on a platform
  1341. name and a list of FFS inputs.
  1342. Arguments:
  1343. path - Supplies the path to the source. The object directory version of
  1344. this path will be added to the include path.
  1345. name - Supplies the name of the firmware volume.
  1346. ffs - Supplies the FFS inputs.
  1347. Return Value:
  1348. Returns a list of the firmware volume entry.
  1349. --*/
  1350. {
  1351. var fwv;
  1352. var fwvO;
  1353. var fwvName = name + "fwv";
  1354. var fwvS;
  1355. fwv = {
  1356. "type": "target",
  1357. "label": fwvName,
  1358. "inputs": ffs,
  1359. "implicit": ["uefi/tools/genfv:genfv"],
  1360. "tool": "genfv"
  1361. };
  1362. fwvS = {
  1363. "inputs": [fwvName + ".S"],
  1364. "includes": ["$O/" + path]
  1365. };
  1366. fwvO = compiledSources(fwvS);
  1367. fwvO = fwvO[1][0];
  1368. fwvO["implicit"] = [":" + fwvName];
  1369. return [fwv, fwvO];
  1370. }
  1371. //
  1372. // Define a function that creates a version.h file target.
  1373. //
  1374. function
  1375. createVersionHeader (
  1376. major,
  1377. minor,
  1378. revision
  1379. )
  1380. /*++
  1381. Routine Description:
  1382. This routine creates a version.h header that includes aspects of the
  1383. build environment.
  1384. Arguments:
  1385. major - Supplies the major number.
  1386. minor - Supplies the minor number.
  1387. revision - Supplies the revision.
  1388. Return Value:
  1389. Returns a list of the firmware volume entry.
  1390. --*/
  1391. {
  1392. var versionConfig;
  1393. var versionH;
  1394. versionConfig = {
  1395. "FORM": "header",
  1396. "MAJOR": major,
  1397. "MINOR": minor,
  1398. "REVISION": revision,
  1399. "RELEASE": mconfig.release_level
  1400. };
  1401. versionH = {
  1402. "type": "target",
  1403. "output": "version.h",
  1404. "inputs": ["$S/.git/HEAD"],
  1405. "tool": "gen_version",
  1406. "config": versionConfig
  1407. };
  1408. return [versionH];
  1409. }