README.design 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. Design document for the unified scheme data
  2. ===========================================
  3. How are things connected?
  4. -------------------------
  5. The unified scheme takes all its data from the build.info files seen
  6. throughout the source tree. These files hold the minimum information
  7. needed to build end product files from diverse sources. See the
  8. section on build.info files below.
  9. From the information in build.info files, Configure builds up an
  10. information database as a hash table called %unified_info, which is
  11. stored in configdata.pm, found at the top of the build tree (which may
  12. or may not be the same as the source tree).
  13. Configurations/common.tmpl uses the data from %unified_info to
  14. generate the rules for building end product files as well as
  15. intermediary files with the help of a few functions found in the
  16. build-file templates. See the section on build-file templates further
  17. down for more information.
  18. build.info files
  19. ----------------
  20. As mentioned earlier, build.info files are meant to hold the minimum
  21. information needed to build output files, and therefore only (with a
  22. few possible exceptions [1]) have information about end products (such
  23. as scripts, library files and programs) and source files (such as C
  24. files, C header files, assembler files, etc). Intermediate files such
  25. as object files are rarely directly referred to in build.info files (and
  26. when they are, it's always with the file name extension .o), they are
  27. inferred by Configure. By the same rule of minimalism, end product
  28. file name extensions (such as .so, .a, .exe, etc) are never mentioned
  29. in build.info. Their file name extensions will be inferred by the
  30. build-file templates, adapted for the platform they are meant for (see
  31. sections on %unified_info and build-file templates further down).
  32. The variables PROGRAMS, LIBS, ENGINES and SCRIPTS are used to declare
  33. end products. There are variants for them with '_NO_INST' as suffix
  34. (PROGRAM_NO_INST etc) to specify end products that shouldn't get
  35. installed.
  36. The variables SOURCE, DEPEND, INCLUDE and ORDINALS are indexed by a
  37. produced file, and their values are the source used to produce that
  38. particular produced file, extra dependencies, include directories
  39. needed, and ordinal files (explained further below.
  40. All their values in all the build.info throughout the source tree are
  41. collected together and form a set of programs, libraries, engines and
  42. scripts to be produced, source files, dependencies, etc etc etc.
  43. Let's have a pretend example, a very limited contraption of OpenSSL,
  44. composed of the program 'apps/openssl', the libraries 'libssl' and
  45. 'libcrypto', an engine 'engines/ossltest' and their sources and
  46. dependencies.
  47. # build.info
  48. LIBS=libcrypto libssl
  49. ORDINALS[libcrypto]=crypto
  50. ORDINALS[libssl]=ssl
  51. INCLUDE[libcrypto]=include
  52. INCLUDE[libssl]=include
  53. DEPEND[libssl]=libcrypto
  54. This is the top directory build.info file, and it tells us that two
  55. libraries are to be built, there are some ordinals to be used to
  56. declare what symbols in those libraries are seen as public, the
  57. include directory 'include/' shall be used throughout when building
  58. anything that will end up in each library, and that the library
  59. 'libssl' depend on the library 'libcrypto' to function properly.
  60. # apps/build.info
  61. PROGRAMS=openssl
  62. SOURCE[openssl]=openssl.c
  63. INCLUDE[openssl]=.. ../include
  64. DEPEND[openssl]=../libssl
  65. This is the build.info file in 'apps/', one may notice that all file
  66. paths mentioned are relative to the directory the build.info file is
  67. located in. This one tells us that there's a program to be built
  68. called 'apps/openssl' (the file name extension will depend on the
  69. platform and is therefore not mentioned in the build.info file). It's
  70. built from one source file, 'apps/openssl.c', and building it requires
  71. the use of '.' and 'include' include directories (both are declared
  72. from the point of view of the 'apps/' directory), and that the program
  73. depends on the library 'libssl' to function properly.
  74. # crypto/build.info
  75. LIBS=../libcrypto
  76. SOURCE[../libcrypto]=aes.c evp.c cversion.c
  77. DEPEND[cversion.o]=buildinf.h
  78. GENERATE[buildinf.h]=../util/mkbuildinf.pl "$(CC) $(CFLAGS)" "$(PLATFORM)"
  79. DEPEND[buildinf.h]=../Makefile
  80. DEPEND[../util/mkbuildinf.pl]=../util/Foo.pm
  81. This is the build.info file in 'crypto', and it tells us a little more
  82. about what's needed to produce 'libcrypto'. LIBS is used again to
  83. declare that 'libcrypto' is to be produced. This declaration is
  84. really unnecessary as it's already mentioned in the top build.info
  85. file, but can make the info file easier to understand. This is to
  86. show that duplicate information isn't an issue.
  87. This build.info file informs us that 'libcrypto' is built from a few
  88. source files, 'crypto/aes.c', 'crypto/evp.c' and 'crypto/cversion.c'.
  89. It also shows us that building the object file inferred from
  90. 'crypto/cversion.c' depends on 'crypto/buildinf.h'. Finally, it
  91. also shows the possibility to declare how some files are generated
  92. using some script, in this case a perl script, and how such scripts
  93. can be declared to depend on other files, in this case a perl module.
  94. Two things are worth an extra note:
  95. 'DEPEND[cversion.o]' mentions an object file. DEPEND indexes is the
  96. only location where it's valid to mention them
  97. Lines in 'BEGINRAW'..'ENDRAW' sections must always mention files as
  98. seen from the top directory, no exception.
  99. # ssl/build.info
  100. LIBS=../libssl
  101. SOURCE[../libssl]=tls.c
  102. This is the build.info file in 'ssl/', and it tells us that the
  103. library 'libssl' is built from the source file 'ssl/tls.c'.
  104. # engines/build.info
  105. ENGINES=dasync
  106. SOURCE[dasync]=e_dasync.c
  107. DEPEND[dasync]=../libcrypto
  108. INCLUDE[dasync]=../include
  109. ENGINES_NO_INST=ossltest
  110. SOURCE[ossltest]=e_ossltest.c
  111. DEPEND[ossltest]=../libcrypto
  112. INCLUDE[ossltest]=../include
  113. This is the build.info file in 'engines/', telling us that two engines
  114. called 'engines/dasync' and 'engines/ossltest' shall be built, that
  115. dasync's source is 'engines/e_dasync.c' and ossltest's source is
  116. 'engines/e_ossltest.c' and that the include directory 'include/' may
  117. be used when building anything that will be part of these engines.
  118. Also, both engines depend on the library 'libcrypto' to function
  119. properly. Finally, only dasync is being installed, as ossltest is
  120. only for internal testing.
  121. When Configure digests these build.info files, the accumulated
  122. information comes down to this:
  123. LIBS=libcrypto libssl
  124. ORDINALS[libcrypto]=crypto
  125. SOURCE[libcrypto]=crypto/aes.c crypto/evp.c crypto/cversion.c
  126. DEPEND[crypto/cversion.o]=crypto/buildinf.h
  127. INCLUDE[libcrypto]=include
  128. ORDINALS[libssl]=ssl
  129. SOURCE[libssl]=ssl/tls.c
  130. INCLUDE[libssl]=include
  131. DEPEND[libssl]=libcrypto
  132. PROGRAMS=apps/openssl
  133. SOURCE[apps/openssl]=apps/openssl.c
  134. INCLUDE[apps/openssl]=. include
  135. DEPEND[apps/openssl]=libssl
  136. ENGINES=engines/dasync
  137. SOURCE[engines/dasync]=engines/e_dasync.c
  138. DEPEND[engines/dasync]=libcrypto
  139. INCLUDE[engines/dasync]=include
  140. ENGINES_NO_INST=engines/ossltest
  141. SOURCE[engines/ossltest]=engines/e_ossltest.c
  142. DEPEND[engines/ossltest]=libcrypto
  143. INCLUDE[engines/ossltest]=include
  144. GENERATE[crypto/buildinf.h]=util/mkbuildinf.pl "$(CC) $(CFLAGS)" "$(PLATFORM)"
  145. DEPEND[crypto/buildinf.h]=Makefile
  146. DEPEND[util/mkbuildinf.pl]=util/Foo.pm
  147. A few notes worth mentioning:
  148. LIBS may be used to declare routine libraries only.
  149. PROGRAMS may be used to declare programs only.
  150. ENGINES may be used to declare engines only.
  151. The indexes for SOURCE and ORDINALS must only be end product files,
  152. such as libraries, programs or engines. The values of SOURCE
  153. variables must only be source files (possibly generated)
  154. INCLUDE and DEPEND shows a relationship between different files
  155. (usually produced files) or between files and directories, such as a
  156. program depending on a library, or between an object file and some
  157. extra source file.
  158. When Configure processes the build.info files, it will take it as
  159. truth without question, and will therefore perform very few checks.
  160. If the build tree is separate from the source tree, it will assume
  161. that all built files and up in the build directory and that all source
  162. files are to be found in the source tree, if they can be found there.
  163. Configure will assume that source files that can't be found in the
  164. source tree (such as 'crypto/bildinf.h' in the example above) are
  165. generated and will be found in the build tree.
  166. The %unified_info database
  167. --------------------------
  168. The information in all the build.info get digested by Configure and
  169. collected into the %unified_info database, divided into the following
  170. indexes:
  171. depends => a hash table containing 'file' => [ 'dependency' ... ]
  172. pairs. These are directly inferred from the DEPEND
  173. variables in build.info files.
  174. engines => a list of engines. These are directly inferred from
  175. the ENGINES variable in build.info files.
  176. generate => a hash table containing 'file' => [ 'generator' ... ]
  177. pairs. These are directly inferred from the GENERATE
  178. variables in build.info files.
  179. includes => a hash table containing 'file' => [ 'include' ... ]
  180. pairs. These are directly inferred from the INCLUDE
  181. variables in build.info files.
  182. install => a hash table containing 'type' => [ 'file' ... ] pairs.
  183. The types are 'programs', 'libraries', 'engines' and
  184. 'scripts', and the array of files list the files of
  185. that type that should be installed.
  186. libraries => a list of libraries. These are directly inferred from
  187. the LIBS variable in build.info files.
  188. ordinals => a hash table containing 'file' => [ 'word', 'ordfile' ]
  189. pairs. 'file' and 'word' are directly inferred from
  190. the ORDINALS variables in build.info files, while the
  191. file 'ofile' comes from internal knowledge in
  192. Configure.
  193. programs => a list of programs. These are directly inferred from
  194. the PROGRAMS variable in build.info files.
  195. rawlines => a list of build-file lines. These are a direct copy of
  196. the BEGINRAW..ENDRAW lines in build.info files. Note:
  197. only the BEGINRAW..ENDRAW section for the current
  198. platform are copied, the rest are ignored.
  199. scripts => a list of scripts. There are directly inferred from
  200. the SCRIPTS variable in build.info files.
  201. sources => a hash table containing 'file' => [ 'sourcefile' ... ]
  202. pairs. These are indirectly inferred from the SOURCE
  203. variables in build.info files. Object files are
  204. mentioned in this hash table, with source files from
  205. SOURCE variables, and AS source files for programs and
  206. libraries.
  207. shared_sources =>
  208. a hash table just like 'sources', but only as source
  209. files (object files) for building shared libraries.
  210. As an example, here is how the build.info files example from the
  211. section above would be digested into a %unified_info table:
  212. our %unified_info = (
  213. "depends" =>
  214. {
  215. "apps/openssl" =>
  216. [
  217. "libssl",
  218. ],
  219. "crypto/buildinf.h" =>
  220. [
  221. "Makefile",
  222. ],
  223. "crypto/cversion.o" =>
  224. [
  225. "crypto/buildinf.h",
  226. ],
  227. "engines/ossltest" =>
  228. [
  229. "libcrypto",
  230. ],
  231. "libssl" =>
  232. [
  233. "libcrypto",
  234. ],
  235. "util/mkbuildinf.pl" =>
  236. [
  237. "util/Foo.pm",
  238. ],
  239. },
  240. "engines" =>
  241. [
  242. "engines/dasync",
  243. "engines/ossltest",
  244. ],
  245. "generate" =>
  246. {
  247. "crypto/buildinf.h" =>
  248. [
  249. "util/mkbuildinf.pl",
  250. "\"\$(CC)",
  251. "\$(CFLAGS)\"",
  252. "\"$(PLATFORM)\"",
  253. ],
  254. },
  255. "includes" =>
  256. {
  257. "apps/openssl" =>
  258. [
  259. ".",
  260. "include",
  261. ],
  262. "engines/ossltest" =>
  263. [
  264. "include"
  265. ],
  266. "libcrypto" =>
  267. [
  268. "include",
  269. ],
  270. "libssl" =>
  271. [
  272. "include",
  273. ],
  274. "util/mkbuildinf.pl" =>
  275. [
  276. "util",
  277. ],
  278. }
  279. "install" =>
  280. {
  281. "engines" =>
  282. [
  283. "engines/dasync",
  284. ],
  285. "libraries" =>
  286. [
  287. "libcrypto",
  288. "libssl",
  289. ],
  290. "programs" =>
  291. [
  292. "apps/openssl",
  293. ],
  294. },
  295. "libraries" =>
  296. [
  297. "libcrypto",
  298. "libssl",
  299. ],
  300. "ordinals" =>
  301. {
  302. "libcrypto" =>
  303. [
  304. "crypto",
  305. "util/libcrypto.num",
  306. ],
  307. "libssl" =>
  308. [
  309. "ssl",
  310. "util/libssl.num",
  311. ],
  312. },
  313. "programs" =>
  314. [
  315. "apps/openssl",
  316. ],
  317. "rawlines" =>
  318. [
  319. ],
  320. "sources" =>
  321. {
  322. "apps/openssl" =>
  323. [
  324. "apps/openssl.o",
  325. ],
  326. "apps/openssl.o" =>
  327. [
  328. "apps/openssl.c",
  329. ],
  330. "crypto/aes.o" =>
  331. [
  332. "crypto/aes.c",
  333. ],
  334. "crypto/cversion.o" =>
  335. [
  336. "crypto/cversion.c",
  337. ],
  338. "crypto/evp.o" =>
  339. [
  340. "crypto/evp.c",
  341. ],
  342. "engines/e_ossltest.o" =>
  343. [
  344. "engines/e_ossltest.c",
  345. ],
  346. "engines/ossltest" =>
  347. [
  348. "engines/e_ossltest.o",
  349. ],
  350. "libcrypto" =>
  351. [
  352. "crypto/aes.c",
  353. "crypto/cversion.c",
  354. "crypto/evp.c",
  355. ],
  356. "libssl" =>
  357. [
  358. "ssl/tls.c",
  359. ],
  360. "ssl/tls.o" =>
  361. [
  362. "ssl/tls.c",
  363. ],
  364. },
  365. );
  366. As can be seen, everything in %unified_info is fairly simple suggest
  367. of information. Still, it tells us that to build all programs, we
  368. must build 'apps/openssl', and to build the latter, we will need to
  369. build all its sources ('apps/openssl.o' in this case) and all the
  370. other things it depends on (such as 'libssl'). All those dependencies
  371. need to be built as well, using the same logic, so to build 'libssl',
  372. we need to build 'ssl/tls.o' as well as 'libcrypto', and to build the
  373. latter...
  374. Build-file templates
  375. --------------------
  376. Build-file templates are essentially build-files (such as Makefile on
  377. Unix) with perl code fragments mixed in. Those perl code fragment
  378. will generate all the configuration dependent data, including all the
  379. rules needed to build end product files and intermediary files alike.
  380. At a minimum, there must be a perl code fragment that defines a set of
  381. functions that are used to generates specific build-file rules, to
  382. build static libraries from object files, to build shared libraries
  383. from static libraries, to programs from object files and libraries,
  384. etc.
  385. generatesrc - function that produces build file lines to generate
  386. a source file from some input.
  387. It's called like this:
  388. generatesrc(src => "PATH/TO/tobegenerated",
  389. generator => [ "generatingfile", ... ]
  390. generator_incs => [ "INCL/PATH", ... ]
  391. generator_deps => [ "dep1", ... ]
  392. incs => [ "INCL/PATH", ... ],
  393. deps => [ "dep1", ... ],
  394. intent => one of "libs", "dso", "bin" );
  395. 'src' has the name of the file to be generated.
  396. 'generator' is the command or part of command to
  397. generate the file, of which the first item is
  398. expected to be the file to generate from.
  399. generatesrc() is expected to analyse and figure out
  400. exactly how to apply that file and how to capture
  401. the result. 'generator_incs' and 'generator_deps'
  402. are include directories and files that the generator
  403. file itself depends on. 'incs' and 'deps' are
  404. include directories and files that are used if $(CC)
  405. is used as an intermediary step when generating the
  406. end product (the file indicated by 'src'). 'intent'
  407. indicates what the generated file is going to be
  408. used for.
  409. src2obj - function that produces build file lines to build an
  410. object file from source files and associated data.
  411. It's called like this:
  412. src2obj(obj => "PATH/TO/objectfile",
  413. srcs => [ "PATH/TO/sourcefile", ... ],
  414. deps => [ "dep1", ... ],
  415. incs => [ "INCL/PATH", ... ]
  416. intent => one of "lib", "dso", "bin" );
  417. 'obj' has the intended object file *without*
  418. extension, src2obj() is expected to add that.
  419. 'srcs' has the list of source files to build the
  420. object file, with the first item being the source
  421. file that directly corresponds to the object file.
  422. 'deps' is a list of explicit dependencies. 'incs'
  423. is a list of include file directories. Finally,
  424. 'intent' indicates what this object file is going
  425. to be used for.
  426. obj2lib - function that produces build file lines to build a
  427. static library file ("libfoo.a" in Unix terms) from
  428. object files.
  429. called like this:
  430. obj2lib(lib => "PATH/TO/libfile",
  431. objs => [ "PATH/TO/objectfile", ... ]);
  432. 'lib' has the intended library file name *without*
  433. extension, obj2lib is expected to add that. 'objs'
  434. has the list of object files (also *without*
  435. extension) to build this library.
  436. libobj2shlib - function that produces build file lines to build a
  437. shareable object library file ("libfoo.so" in Unix
  438. terms) from the corresponding static library file
  439. or object files.
  440. called like this:
  441. libobj2shlib(shlib => "PATH/TO/shlibfile",
  442. lib => "PATH/TO/libfile",
  443. objs => [ "PATH/TO/objectfile", ... ],
  444. deps => [ "PATH/TO/otherlibfile", ... ],
  445. ordinals => [ "word", "/PATH/TO/ordfile" ]);
  446. 'lib' has the intended library file name *without*
  447. extension, libobj2shlib is expected to add that.
  448. 'shlib' has the corresponding shared library name
  449. *without* extension. 'deps' has the list of other
  450. libraries (also *without* extension) this library
  451. needs to be linked with. 'objs' has the list of
  452. object files (also *without* extension) to build
  453. this library. 'ordinals' MAY be present, and when
  454. it is, its value is an array where the word is
  455. "crypto" or "ssl" and the file is one of the ordinal
  456. files util/libcrypto.num or util/libssl.num in the
  457. source directory.
  458. This function has a choice; it can use the
  459. corresponding static library as input to make the
  460. shared library, or the list of object files.
  461. obj2dynlib - function that produces build file lines to build a
  462. dynamically loadable library file ("libfoo.so" on
  463. Unix) from object files.
  464. called like this:
  465. obj2dynlib(lib => "PATH/TO/libfile",
  466. objs => [ "PATH/TO/objectfile", ... ],
  467. deps => [ "PATH/TO/otherlibfile",
  468. ... ]);
  469. This is almost the same as libobj2shlib, but the
  470. intent is to build a shareable library that can be
  471. loaded in runtime (a "plugin"...). The differences
  472. are subtle, one of the most visible ones is that the
  473. resulting shareable library is produced from object
  474. files only.
  475. obj2bin - function that produces build file lines to build an
  476. executable file from object files.
  477. called like this:
  478. obj2bin(bin => "PATH/TO/binfile",
  479. objs => [ "PATH/TO/objectfile", ... ],
  480. deps => [ "PATH/TO/libfile", ... ]);
  481. 'bin' has the intended executable file name
  482. *without* extension, obj2bin is expected to add
  483. that. 'objs' has the list of object files (also
  484. *without* extension) to build this library. 'deps'
  485. has the list of library files (also *without*
  486. extension) that the programs needs to be linked
  487. with.
  488. in2script - function that produces build file lines to build a
  489. script file from some input.
  490. called like this:
  491. in2script(script => "PATH/TO/scriptfile",
  492. sources => [ "PATH/TO/infile", ... ]);
  493. 'script' has the intended script file name.
  494. 'sources' has the list of source files to build the
  495. resulting script from.
  496. Along with the build-file templates is the driving engine
  497. Configurations/common.tmpl, which looks through all the information in
  498. %unified_info and generates all the rulesets to build libraries,
  499. programs and all intermediate files, using the rule generating
  500. functions defined in the build-file template.
  501. As an example with the smaller build.info set we've seen as an
  502. example, producing the rules to build 'libcrypto' would result in the
  503. following calls:
  504. # Note: libobj2shlib will only be called if shared libraries are
  505. # to be produced.
  506. # Note 2: libobj2shlib gets both the name of the static library
  507. # and the names of all the object files that go into it. It's up
  508. # to the implementation to decide which to use as input.
  509. # Note 3: common.tmpl peals off the ".o" extension from all object
  510. # files, as the platform at hand may have a different one.
  511. libobj2shlib(shlib => "libcrypto",
  512. lib => "libcrypto",
  513. objs => [ "crypto/aes", "crypto/evp", "crypto/cversion" ],
  514. deps => [ ]
  515. ordinals => [ "crypto", "util/libcrypto.num" ]);
  516. obj2lib(lib => "libcrypto"
  517. objs => [ "crypto/aes", "crypto/evp", "crypto/cversion" ]);
  518. src2obj(obj => "crypto/aes"
  519. srcs => [ "crypto/aes.c" ],
  520. deps => [ ],
  521. incs => [ "include" ],
  522. intent => "lib");
  523. src2obj(obj => "crypto/evp"
  524. srcs => [ "crypto/evp.c" ],
  525. deps => [ ],
  526. incs => [ "include" ],
  527. intent => "lib");
  528. src2obj(obj => "crypto/cversion"
  529. srcs => [ "crypto/cversion.c" ],
  530. deps => [ "crypto/buildinf.h" ],
  531. incs => [ "include" ],
  532. intent => "lib");
  533. generatesrc(src => "crypto/buildinf.h",
  534. generator => [ "util/mkbuildinf.pl", "\"$(CC)",
  535. "$(CFLAGS)\"", "\"$(PLATFORM)\"" ],
  536. generator_incs => [ "util" ],
  537. generator_deps => [ "util/Foo.pm" ],
  538. incs => [ ],
  539. deps => [ ],
  540. intent => "lib");
  541. The returned strings from all those calls are then concatenated
  542. together and written to the resulting build-file.