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