README.design 24 KB

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