2
0

README.design 24 KB

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