menv.ck 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947
  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. "CPFLAGS": "-p",
  492. };
  493. if (config.verbose) {
  494. Core.print("Minoca Build Configuration:");
  495. for (key in mconfig) {
  496. Core.print("\t%s: %s" % [key, mconfig[key].__str()]);
  497. }
  498. }
  499. return getTools();
  500. }
  501. function
  502. addConfig (
  503. entry,
  504. name,
  505. value
  506. )
  507. /*++
  508. Routine Description:
  509. This routine adds a configure option to a list, ensuring that both the
  510. config dictionary and option already exist.
  511. Arguments:
  512. entry - Supplies the entry to add the configure option to.
  513. name - Supplies the name of the option to add.
  514. value - Supplies the new value to add to the list of options.
  515. Return Value:
  516. None.
  517. --*/
  518. {
  519. if (!entry.get("config")) {
  520. entry.config = {};
  521. }
  522. if (!entry.config.get(name)) {
  523. entry.config[name] = [];
  524. }
  525. entry.config[name] += [value];
  526. return;
  527. }
  528. function
  529. group (
  530. name,
  531. entries
  532. )
  533. /*++
  534. Routine Description:
  535. This routine creates a phony target that groups a bunch of different
  536. targets together under a common name.
  537. Arguments:
  538. name - Supplies the name of the new group target.
  539. entries - Supplies the list of entries.
  540. Return Value:
  541. Returns a list containing the entry for the group target.
  542. --*/
  543. {
  544. var entry = {
  545. "label": name,
  546. "type": "target",
  547. "tool": "phony",
  548. "inputs": entries,
  549. "config": {}
  550. };
  551. return [entry];
  552. }
  553. function
  554. touch (
  555. destination,
  556. destinationLabel,
  557. mode
  558. )
  559. /*++
  560. Routine Description:
  561. This routine creates an empty file target.
  562. Arguments:
  563. destination - Supplies the copy destination.
  564. destinationLabel - Supplies a label naming the target.
  565. mode - Supplies the chmod mode of the destination.
  566. Return Value:
  567. Returns a list containing the copy entry.
  568. --*/
  569. {
  570. var config = {};
  571. if (mode) {
  572. config["CHMOD_FLAGS"] = mode;
  573. }
  574. destinationLabel ?= destination;
  575. var entry = {
  576. "type": "target",
  577. "tool": "touch",
  578. "label": destinationLabel,
  579. "output": destination,
  580. "config": config
  581. };
  582. return [entry];
  583. }
  584. function
  585. makedir (
  586. destination,
  587. destinationLabel
  588. )
  589. /*++
  590. Routine Description:
  591. This routine creates an empty directory target.
  592. Arguments:
  593. destination - Supplies the copy destination.
  594. destinationLabel - Supplies a label naming the target.
  595. Return Value:
  596. Returns a list containing the copy entry.
  597. --*/
  598. {
  599. destinationLabel ?= destination;
  600. var entry = {
  601. "type": "target",
  602. "tool": "mkdir",
  603. "label": destinationLabel,
  604. "output": destination,
  605. };
  606. return [entry];
  607. }
  608. function
  609. copy (
  610. source,
  611. destination,
  612. destinationLabel,
  613. flags,
  614. mode
  615. )
  616. /*++
  617. Routine Description:
  618. This routine creates a target that copies a file from one place to another.
  619. Arguments:
  620. source - Supplies the source to copy.
  621. destination - Supplies the copy destination.
  622. destinationLabel - Supplies a label naming the copy target.
  623. flags - Supplies the flags to include in the copy.
  624. mode - Supplies the chmod mode of the destination.
  625. Return Value:
  626. Returns a list containing the copy entry.
  627. --*/
  628. {
  629. var config = {};
  630. if (flags) {
  631. config["CPFLAGS"] = flags;
  632. }
  633. if (mode) {
  634. config["CHMOD_FLAGS"] = mode;
  635. }
  636. var entry = {
  637. "type": "target",
  638. "tool": "copy",
  639. "label": destinationLabel,
  640. "inputs": [source],
  641. "output": destination,
  642. "config": config
  643. };
  644. if (!destinationLabel) {
  645. entry["label"] = destination;
  646. }
  647. return [entry];
  648. }
  649. function
  650. strip (
  651. params
  652. )
  653. /*++
  654. Routine Description:
  655. This routine converts an entry to a strip entry, where the target will be
  656. stripped.
  657. Arguments:
  658. params - Supplies the existing entry.
  659. Return Value:
  660. Returns a list containing the strip entry.
  661. --*/
  662. {
  663. params.type = "target";
  664. params.tool = "strip";
  665. if (params.get("build")) {
  666. params.tool = "build_strip";
  667. }
  668. return [params];
  669. }
  670. function
  671. binplace (
  672. params
  673. )
  674. /*++
  675. Routine Description:
  676. This routine replaces the current target with a copied version in the
  677. final bin directory. This will also create a stripped version in the
  678. stripped directory unless told not to.
  679. Arguments:
  680. params - Supplies the existing entry.
  681. Return Value:
  682. Returns a list containing the strip entry.
  683. --*/
  684. {
  685. var build = params.get("build");
  686. var copiedEntry;
  687. var cpflags = params.get("cpflags");;
  688. var destination;
  689. var destinationLabel;
  690. var destinationPath;
  691. var element;
  692. var entries = [];
  693. var extraCopy;
  694. var fileName;
  695. var label = params.get("label");
  696. var mode = params.get("mode");
  697. var newOriginalLabel;
  698. var originalTarget;
  699. var source = params.get("output");
  700. var strippedEntry;
  701. var strippedOutput;
  702. label ?= source;
  703. source ?= label;
  704. if ((!label) || (!source)) {
  705. Core.raise(ValueError("Label or output must be defined"));
  706. }
  707. //
  708. // Set the output since the label is going to be renamed and create the
  709. // copy target.
  710. //
  711. params.output = source;
  712. params.type = "target";
  713. fileName = basename(source);
  714. destination = params.get("binplace");
  715. newOriginalLabel = label + "_orig";
  716. originalTarget = ":" + newOriginalLabel;
  717. //
  718. // Create the first or only one with the genuine label.
  719. //
  720. element = destination;
  721. if (element is List) {
  722. element = element[0];
  723. }
  724. if (!element) {
  725. element = "bin";
  726. }
  727. destinationPath = mconfig.outroot + "/" + element + "/" + fileName;
  728. copiedEntry = copy(originalTarget,
  729. destinationPath,
  730. label,
  731. cpflags,
  732. mode)[0];
  733. entries.append(copiedEntry);
  734. //
  735. // Handle binplacing into several areas.
  736. //
  737. if (destination is List) {
  738. for (index in 1..destination.length()) {
  739. element = destination[index];
  740. if (!element) {
  741. element = "bin";
  742. }
  743. destinationPath = mconfig.outroot + "/" + element + "/" + fileName;
  744. destinationLabel = "%s_%d" % [label, index];
  745. extraCopy = copy(originalTarget,
  746. destinationPath,
  747. destinationLabel,
  748. cpflags,
  749. mode)[0];
  750. copiedEntry.implicit = [":" + destinationLabel];
  751. entries.append(extraCopy);
  752. }
  753. }
  754. //
  755. // The original label was given to the copied destination, so tack an _orig
  756. // on the source label.
  757. //
  758. params.label = newOriginalLabel;
  759. //
  760. // Unless asked not to, create a stripped entry as well.
  761. //
  762. if (!params.get("nostrip")) {
  763. if (build) {
  764. strippedOutput = mconfig.stripped + "/build/" + fileName;
  765. } else {
  766. strippedOutput = mconfig.stripped + "/" + fileName;
  767. }
  768. strippedEntry = {
  769. "label": label + "_stripped",
  770. "inputs": [originalTarget],
  771. "output": strippedOutput,
  772. "build": build,
  773. };
  774. //
  775. // Make the binplaced copy depend on the stripped version.
  776. //
  777. copiedEntry.implicit = [":" + strippedEntry["label"]];
  778. entries += strip(strippedEntry);
  779. }
  780. entries.append(params);
  781. return entries;
  782. }
  783. function
  784. compiledSources (
  785. params
  786. )
  787. /*++
  788. Routine Description:
  789. This routine compiles a group of object file targets from source files.
  790. Arguments:
  791. params - Supplies the entry with inputs filled out.
  792. Return Value:
  793. Returns the list containing a list of object names, and a list of object
  794. targets.
  795. --*/
  796. {
  797. var build = params.get("build");
  798. var entries = [];
  799. var ext;
  800. var includes = params.get("includes");
  801. var inputParts;
  802. var inputs = params.inputs;
  803. var objName;
  804. var obj;
  805. var objs = [];
  806. var sourcesConfig = params.get("sources_config");
  807. var prefix = params.get("prefix");
  808. var suffix;
  809. var tool;
  810. if (includes) {
  811. sourcesConfig ?= {};
  812. if (!sourcesConfig.get("CPPFLAGS")) {
  813. sourcesConfig.CPPFLAGS = [];
  814. }
  815. for (include in includes) {
  816. sourcesConfig["CPPFLAGS"] += ["-I" + include];
  817. }
  818. }
  819. if (inputs.length() == 0) {
  820. Core.raise(ValueError("Compilation must have inputs"));
  821. }
  822. for (input in inputs) {
  823. inputParts = input.rsplit(".", 1);
  824. try {
  825. ext = inputParts[1];
  826. } except IndexError {
  827. ext = "";
  828. }
  829. suffix = ".o";
  830. if (ext == "c") {
  831. tool = "cc";
  832. } else if (ext == "cc") {
  833. tool = "cxx";
  834. } else if (ext == "S") {
  835. tool = "as";
  836. } else if (ext == "rc") {
  837. tool = "rcc";
  838. suffix = ".rsc";
  839. } else {
  840. objs += [input];
  841. continue;
  842. }
  843. if (build) {
  844. tool = "build_" + tool;
  845. }
  846. objName = inputParts[0] + suffix;
  847. if (objName[0] == ":") {
  848. objName = objName[1...-1];
  849. }
  850. if (prefix) {
  851. objName = prefix + "/" + objName;
  852. }
  853. obj = {
  854. "type": "target",
  855. "label": objName,
  856. "output": objName,
  857. "inputs": [input],
  858. "tool": tool,
  859. "config": sourcesConfig,
  860. };
  861. entries += [obj];
  862. objs += [":" + objName];
  863. }
  864. if (prefix) {
  865. if (!params.get("output")) {
  866. params.output = params.label;
  867. }
  868. params.output = prefix + "/" + params.output;
  869. }
  870. return [objs, entries];
  871. }
  872. function
  873. executable (
  874. params
  875. )
  876. /*++
  877. Routine Description:
  878. This routine links a set of sources into some sort of executable or shared
  879. object.
  880. Arguments:
  881. params - Supplies the entry with inputs filled out.
  882. Return Value:
  883. Returns the list of the linked entry.
  884. --*/
  885. {
  886. var build = params.get("build");
  887. var entry = params.get("entry");
  888. var compilation = compiledSources(params);
  889. var linkerScript = params.get("linker_script");
  890. var objs = compilation[0];
  891. var entries = compilation[1];
  892. var textAddress = params.get("text_address");;
  893. params.type = "target";
  894. params.inputs = objs;
  895. params.tool = "ld";
  896. if (build) {
  897. params.tool = "build_ld";
  898. }
  899. //
  900. // Convert options for text_address, linker_script, and entry to actual
  901. // LDFLAGS.
  902. //
  903. if (textAddress) {
  904. addConfig(params, "LDFLAGS", "-Wl,-Ttext-segment=" + textAddress);
  905. addConfig(params,
  906. "LDFLAGS",
  907. "-Wl,--section-start,.init=" + textAddress);
  908. }
  909. if (linkerScript) {
  910. addConfig(params, "LDFLAGS", "-Wl,-T" + linkerScript);
  911. }
  912. if (entry != null) {
  913. addConfig(params, "LDFLAGS", "-Wl,-e" + entry);
  914. addConfig(params, "LDFLAGS", "-Wl,-u" + entry);
  915. }
  916. if (params.get("binplace")) {
  917. entries += binplace(params);
  918. } else {
  919. entries += [params];
  920. }
  921. return entries;
  922. }
  923. function
  924. application (
  925. params
  926. )
  927. /*++
  928. Routine Description:
  929. This routine creates a position independent application.
  930. Arguments:
  931. params - Supplies the entry with inputs filled out.
  932. Return Value:
  933. Returns the list of the application entry.
  934. --*/
  935. {
  936. var build = params.get("build");
  937. var exename = params.get("output");
  938. exename ?= params.get("label");
  939. if (!exename) {
  940. Core.raise(ValueError("Missing output or label"));
  941. }
  942. if (build && (mconfig.build_os == "Windows")) {
  943. params.output = exename + ".exe";
  944. }
  945. if (build && (mconfig.build_os == "Darwin")) {
  946. addConfig(params, "LDFLAGS", "-Wl,-pie");
  947. } else {
  948. addConfig(params, "LDFLAGS", "-pie");
  949. }
  950. if ((!build) && (params.get("binplace") == null)) {
  951. params.binplace = "bin";
  952. }
  953. return executable(params);
  954. }
  955. function
  956. staticApplication (
  957. params
  958. )
  959. /*++
  960. Routine Description:
  961. This routine creates a static application suitable for kernel or firmware
  962. environments.
  963. Arguments:
  964. params - Supplies the entry with inputs filled out.
  965. Return Value:
  966. Returns the list of the application entry.
  967. --*/
  968. {
  969. if (!(params.get("sources_config") is Dict)) {
  970. params.sources_config = {};
  971. }
  972. if (!(params.sources_config.get("CFLAGS") is List)) {
  973. params.sources_config.CFLAGS = [];
  974. }
  975. params.sources_config.CFLAGS += ["$KERNEL_CFLAGS"];
  976. addConfig(params, "LDFLAGS", "-static");
  977. addConfig(params, "LDFLAGS", "-nostdlib");
  978. return executable(params);
  979. }
  980. function
  981. sharedLibrary (
  982. params
  983. )
  984. /*++
  985. Routine Description:
  986. This routine creates a shared library or DLL.
  987. Arguments:
  988. params - Supplies the entry with inputs filled out.
  989. Return Value:
  990. Returns the list of the application entry.
  991. --*/
  992. {
  993. var build = params.get("build");
  994. var majorVersion = params.get("major_version");
  995. var minorVersion = params.get("minor_version");
  996. var soname = params.get("soname");
  997. soname ?= params.get("output");
  998. soname ?= params.get("label");
  999. if (!soname) {
  1000. Core.raise(ValueError(
  1001. "One of output, label, or soname must be defined."));
  1002. }
  1003. //
  1004. // Darwin shared libraries build with a whole different ballgame of options.
  1005. //
  1006. if (build && (mconfig.build_os == "Darwin")) {
  1007. majorVersion ?= "0";
  1008. minorVersion ?= "0";
  1009. soname += ".%s.dylib" % majorVersion;
  1010. addConfig(params,
  1011. "LDFLAGS",
  1012. "-undefined dynamic_lookup -dynamiclib");
  1013. addConfig(params,
  1014. "LDFLAGS",
  1015. "-current_version %s.%s" % [majorVersion, minorVersion]);
  1016. addConfig(params,
  1017. "LDFLAGS",
  1018. "-compatibility_version %s.%d" % [majorVersion, 0]);
  1019. } else {
  1020. addConfig(params, "LDFLAGS", "-shared");
  1021. if ((!build) || (mconfig.build_os != "Windows")) {
  1022. soname += ".so";
  1023. if (majorVersion != null) {
  1024. soname += "." + majorVersion;
  1025. }
  1026. addConfig(params, "LDFLAGS", "-Wl,-soname=" + soname);
  1027. } else {
  1028. soname += ".dll";
  1029. }
  1030. }
  1031. params.output = soname;
  1032. if ((!build) && (params.get("binplace") == null)) {
  1033. params.binplace = "bin";
  1034. }
  1035. return executable(params);
  1036. }
  1037. function
  1038. staticLibrary (
  1039. params
  1040. )
  1041. /*++
  1042. Routine Description:
  1043. This routine creates a static library.
  1044. Arguments:
  1045. params - Supplies the entry with inputs filled out.
  1046. Return Value:
  1047. Returns the list of the application entry.
  1048. --*/
  1049. {
  1050. var build = params.get("build");
  1051. var compilation = compiledSources(params);
  1052. var objs = compilation[0];
  1053. var output;
  1054. var entries = compilation[1];
  1055. params.type = "target";
  1056. output = params.get("output");
  1057. output ?= params.get("label");
  1058. if (!output) {
  1059. Core.raise(ValueError("output or label must be defined"));
  1060. }
  1061. params.output = output + ".a";
  1062. params.inputs = objs;
  1063. params.tool = "ar";
  1064. if (build) {
  1065. params.tool = "build_ar";
  1066. }
  1067. if (params.get("binplace")) {
  1068. entries += binplace(params);
  1069. } else {
  1070. entries += [params];
  1071. }
  1072. return entries;
  1073. }
  1074. function
  1075. kernelLibrary (
  1076. params
  1077. )
  1078. /*++
  1079. Routine Description:
  1080. This routine creates a static library compiled suitably for running within
  1081. the kernel.
  1082. Arguments:
  1083. params - Supplies the entry with inputs filled out.
  1084. Return Value:
  1085. Returns the list of the application entry.
  1086. --*/
  1087. {
  1088. if (!(params.get("sources_config") is Dict)) {
  1089. params.sources_config = {};
  1090. }
  1091. if (!(params.sources_config.get("CFLAGS") is List)) {
  1092. params.sources_config.CFLAGS = [];
  1093. }
  1094. params.sources_config.CFLAGS += ["$KERNEL_CFLAGS"];
  1095. return staticLibrary(params);
  1096. }
  1097. function
  1098. compiledAsl (
  1099. inputs
  1100. )
  1101. /*++
  1102. Routine Description:
  1103. This routine creates a list of compiled .aml files from a list of .asl
  1104. files.
  1105. Arguments:
  1106. params - Supplies the entry with inputs filled out.
  1107. Return Value:
  1108. Returns a list where the first element is a list of all the resulting
  1109. target names, and the second element is a list of the target entries.
  1110. --*/
  1111. {
  1112. var entries = [];
  1113. var ext;
  1114. var inputParts;
  1115. var objName;
  1116. var obj;
  1117. var objs = [];
  1118. if (inputs.length() == 0) {
  1119. Core.raise(ValueError("Compilation must have inputs"));
  1120. }
  1121. for (input in inputs) {
  1122. inputParts = input.rsplit(".", 1);
  1123. ext = inputParts[1];
  1124. objName = inputParts[0] + ".aml";
  1125. obj = {
  1126. "type": "target",
  1127. "label": objName,
  1128. "output": objName,
  1129. "inputs": [input],
  1130. "tool": "iasl"
  1131. };
  1132. entries += [obj];
  1133. objs += [":" + objName];
  1134. }
  1135. return [objs, entries];
  1136. }
  1137. function
  1138. objectifiedBinaries (
  1139. params
  1140. )
  1141. /*++
  1142. Routine Description:
  1143. This routine creates a group of object file targets from binary files.
  1144. Arguments:
  1145. params - Supplies the entry with inputs filled out.
  1146. Return Value:
  1147. Returns a list of object names in the first element and the object file
  1148. target entries in the second element.
  1149. --*/
  1150. {
  1151. var build = params.get("build");
  1152. var entries = [];
  1153. var inputs = params.inputs;
  1154. var obj;
  1155. var objcopyConfig = params.get("config");
  1156. var objName;
  1157. var objs = [];
  1158. var prefix = params.get("prefix");
  1159. var tool;
  1160. if (inputs.length() == 0) {
  1161. Core.raise(ValueError("Compilation must have inputs"));
  1162. }
  1163. for (input in inputs) {
  1164. tool = "objcopy";
  1165. if (build) {
  1166. tool = "build_objcopy";;
  1167. }
  1168. objName = input + ".o";
  1169. if (prefix) {
  1170. objName = prefix + "/" + objName;
  1171. }
  1172. obj = {
  1173. "type": "target",
  1174. "label": objName,
  1175. "output": objName,
  1176. "inputs": [input],
  1177. "tool": tool,
  1178. "config": objcopyConfig,
  1179. };
  1180. entries += [obj];
  1181. objs += [":" + objName];
  1182. }
  1183. if (prefix) {
  1184. params.output ?= params.label;
  1185. params.output = prefix + "/" + params.output;
  1186. }
  1187. return [objs, entries];
  1188. }
  1189. function
  1190. objectifiedBinary (
  1191. params
  1192. )
  1193. /*++
  1194. Routine Description:
  1195. This routine creates a single object file from a binary file.
  1196. Arguments:
  1197. params - Supplies the entry with inputs filled out.
  1198. Return Value:
  1199. Returns a list of the object file.
  1200. --*/
  1201. {
  1202. return objectifiedBinaries(params)[1];
  1203. }
  1204. function
  1205. objectifiedLibrary (
  1206. params
  1207. )
  1208. /*++
  1209. Routine Description:
  1210. This routine creates a library from a set of objectified files.
  1211. Arguments:
  1212. params - Supplies the entry with inputs filled out.
  1213. Return Value:
  1214. Returns a list of the object file.
  1215. --*/
  1216. {
  1217. var build = params.get("build");
  1218. var compilation = objectifiedBinaries(params);
  1219. var objs = compilation[0];
  1220. var entries = compilation[1];
  1221. var output = params.get("output");
  1222. params.type = "target";
  1223. output ?= params.label;
  1224. params.output = output + ".a";
  1225. params.inputs = objs;
  1226. params.tool = "ar";
  1227. if (build) {
  1228. params.tool = "build_ar";
  1229. }
  1230. entries += [params];
  1231. return entries;
  1232. }
  1233. //
  1234. // Create a flat binary from an executable image.
  1235. //
  1236. function
  1237. flattenedBinary (
  1238. params
  1239. )
  1240. /*++
  1241. Routine Description:
  1242. This routine creates a flat binary from an executable image.
  1243. Arguments:
  1244. params - Supplies the entry with inputs filled out.
  1245. Return Value:
  1246. Returns a list of the flat binary.
  1247. --*/
  1248. {
  1249. var entries;
  1250. params.type = "target";
  1251. params.tool = "objcopy";
  1252. addConfig(params, "OBJCOPY_FLAGS", "-O binary");
  1253. if (params.get("binplace")) {
  1254. params.nostrip = true;
  1255. entries = binplace(params);
  1256. } else {
  1257. entries = [params];
  1258. }
  1259. return entries;
  1260. }
  1261. function
  1262. driver (
  1263. params
  1264. )
  1265. /*++
  1266. Routine Description:
  1267. This routine creates a Minoca kernel driver.
  1268. Arguments:
  1269. params - Supplies the entry with inputs filled out.
  1270. Return Value:
  1271. Returns a list of the driver entry.
  1272. --*/
  1273. {
  1274. var soname = params.get("output");
  1275. if (!params.get("entry")) {
  1276. params.entry = "DriverEntry";
  1277. }
  1278. if (!(params.get("sources_config") is Dict)) {
  1279. params.sources_config = {};
  1280. }
  1281. if (!(params.sources_config.get("CFLAGS") is List)) {
  1282. params.sources_config.CFLAGS = [];
  1283. }
  1284. params.sources_config.CFLAGS += ["$KERNEL_CFLAGS"];
  1285. params.binplace = "bin";
  1286. soname ?= params.get("label");
  1287. if (soname != "kernel") {
  1288. soname += ".drv";
  1289. params.output = soname;
  1290. params.inputs += ["kernel:kernel"];
  1291. }
  1292. addConfig(params, "LDFLAGS", "-shared");
  1293. addConfig(params, "LDFLAGS", "-Wl,-soname=" + soname);
  1294. addConfig(params, "LDFLAGS", "-nostdlib");
  1295. return executable(params);
  1296. }
  1297. function
  1298. uefiRuntimeFfs (
  1299. name
  1300. )
  1301. /*++
  1302. Routine Description:
  1303. This routine creates a runtime driver .FFS file from an ELF file.
  1304. Arguments:
  1305. params - Supplies the entry with inputs filled out.
  1306. Return Value:
  1307. Returns a list of the .FFS entry.
  1308. --*/
  1309. {
  1310. var elfconvConfig;
  1311. var ffs;
  1312. var pe;
  1313. elfconvConfig = {
  1314. "ELFCONV_FLAGS": "-t efiruntimedriver"
  1315. };
  1316. pe = {
  1317. "type": "target",
  1318. "label": name,
  1319. "inputs": [":" + name + ".elf"],
  1320. "implicit": ["uefi/tools/elfconv:elfconv"],
  1321. "tool": "elfconv",
  1322. "config": elfconvConfig
  1323. };
  1324. ffs = {
  1325. "type": "target",
  1326. "label": name + ".ffs",
  1327. "inputs": [":" + name],
  1328. "implicit": ["uefi/tools/genffs:genffs"],
  1329. "tool": "genffs_runtime"
  1330. };
  1331. return [pe, ffs];
  1332. }
  1333. function
  1334. uefiFwvol (
  1335. path,
  1336. name,
  1337. ffs
  1338. )
  1339. /*++
  1340. Routine Description:
  1341. This routine creates a UEFI firmware volume object file based on a platform
  1342. name and a list of FFS inputs.
  1343. Arguments:
  1344. path - Supplies the path to the source. The object directory version of
  1345. this path will be added to the include path.
  1346. name - Supplies the name of the firmware volume.
  1347. ffs - Supplies the FFS inputs.
  1348. Return Value:
  1349. Returns a list of the firmware volume entry.
  1350. --*/
  1351. {
  1352. var fwv;
  1353. var fwvO;
  1354. var fwvName = name + "fwv";
  1355. var fwvS;
  1356. fwv = {
  1357. "type": "target",
  1358. "label": fwvName,
  1359. "inputs": ffs,
  1360. "implicit": ["uefi/tools/genfv:genfv"],
  1361. "tool": "genfv"
  1362. };
  1363. fwvS = {
  1364. "inputs": [fwvName + ".S"],
  1365. "includes": ["$O/" + path]
  1366. };
  1367. fwvO = compiledSources(fwvS);
  1368. fwvO = fwvO[1][0];
  1369. fwvO["implicit"] = [":" + fwvName];
  1370. return [fwv, fwvO];
  1371. }
  1372. //
  1373. // Define a function that creates a version.h file target.
  1374. //
  1375. function
  1376. createVersionHeader (
  1377. major,
  1378. minor,
  1379. revision
  1380. )
  1381. /*++
  1382. Routine Description:
  1383. This routine creates a version.h header that includes aspects of the
  1384. build environment.
  1385. Arguments:
  1386. major - Supplies the major number.
  1387. minor - Supplies the minor number.
  1388. revision - Supplies the revision.
  1389. Return Value:
  1390. Returns a list of the firmware volume entry.
  1391. --*/
  1392. {
  1393. var versionConfig;
  1394. var versionH;
  1395. versionConfig = {
  1396. "FORM": "header",
  1397. "MAJOR": major,
  1398. "MINOR": minor,
  1399. "REVISION": revision,
  1400. "RELEASE": mconfig.release_level
  1401. };
  1402. versionH = {
  1403. "type": "target",
  1404. "output": "version.h",
  1405. "inputs": ["$S/.git/HEAD"],
  1406. "tool": "gen_version",
  1407. "config": versionConfig
  1408. };
  1409. return [versionH];
  1410. }