xref: /openssl/doc/internal/man7/build.info.pod (revision da1c088f)
1=pod
2
3=head1 NAME
4
5build.info - Building information files
6
7=head1 SYNOPSIS
8
9B<IF[>0|1B<]>
10
11B<ELSIF[>0|1B<]>
12
13B<ELSE>
14
15B<ENDIF>
16
17B<SUBDIRS=> I<dir> ...
18
19B<PROGRAMS=> I<name> ...
20
21B<LIBS=> I<name> ...
22
23B<MODULES=> I<name> ...
24
25B<SCRIPTS=> I<name> ...
26
27B<DEPEND[>I<items>B<]=> I<otheritem> ...
28
29B<GENERATE[>I<item>B<]=> I<generator> I<generator-args> ...
30
31B<SOURCE[>I<item>B<]=> I<file> ...
32
33B<SHARED_SOURCE[>I<item>B<]=> I<file> ...
34
35B<DEFINE[>I<items>B<]=> I<name>[B<=>I<value>] ...
36
37B<INCLUDE[>I<items>B<]=> I<dir> ...
38
39B<$>I<VARIABLE>B<=>I<value>
40
41=head1 DESCRIPTION
42
43OpenSSL's build system revolves around three questions:
44
45=over 4
46
47=item What to build for?
48
49This is about choice of platform (combination of hardware, operating
50system, and toolchain).
51
52=item What to build?
53
54This is about having all the information on what needs to be built and
55from what.
56
57=item How to build it?
58
59This is about build file generation.
60
61=back
62
63This document is all about the second item, "What to build?", and most
64of all, how to specify that information.
65
66For some terms used in this document, please see the L</GLOSSARY> at
67the end.
68
69=head2 F<build.info> files
70
71F<build.info> files are meta data files for OpenSSL's built file
72generators, and are used to specify exactly what end product files
73(programs, libraries, modules or scripts) are to be produced, and from
74what sources.
75
76Intermediate files, such as object files, are seldom referred to at
77all.  They sometimes can be, if there's a need, but this should happen
78very rarely, and support for that sort of thing is added on as-needed
79basis.
80
81Any time a directory or file is expected in a statement value, Unix
82syntax must be used, which means that the slash C</> must be used as
83the directory separator.
84
85=head2 General syntax
86
87=head3 Comments
88
89Comments are any line that start with a hash sign (C<#>).  The hash
90sign may be preceded by any number of horizontal spaces.
91
92=head3 Filenames
93
94F<build.info> files are platform agnostic.  This means that there is
95some information in them that is representative rather than specific.
96
97This is particularly visible with end product names, they work more
98like a tag than as the actual filename that's going to be produced.
99This is because different platforms have different decorations on
100different types of files.
101
102For example, if we say that we want to produce a program C<foo>, it
103would look like this:
104
105    PROGRAM=foo
106
107However, the program filename may end up being just C<foo> (typical
108for Unix), or C<foo.exe> (typical for Windows), or even C<BLAH$FOO.EXE>
109(possible on VMS, depending on policy).
110
111These platform specific decorations are not the concern of
112F<build.info> files.  The build file generators are responsible for
113transforming these platform agnostic names to their platform specific
114counterparts.
115
116=head3 Statements
117
118With the exception of variables and conditions, the general statement
119syntax is one of:
120
121=over 4
122
123=item B<I<KEYWORD>> B<=> I<value> ...
124
125=item B<I<KEYWORD>[>I<items>B<]> B<=> I<value> ...
126
127=back
128
129Every B<I<KEYWORD>> represents some particular type of information.
130
131The first form (sometimes called "plain statement") is used to specify
132information on what end products need to be built, for example:
133
134    PROGRAMS=foo bar
135    LIBS=libpoly libcookie
136    MODULES=awesome-plugin
137    SCRIPTS=tool1 tool2
138    SUBDIRS=dir1 dir2
139
140This says that we want to build programs C<foo> and C<bar>, the
141libraries C<libpoly> and C<libcookie>, an awesome plugin module
142C<awesome-plugin>, a couple of scripts C<tool1> and C<tool2>, and
143finally that there are more F<build.info> files in subdirectories
144C<dir1> and C<dir2>.
145
146The second form (sometimes called "indexed statement") is used to
147specify further details for existing items, for example:
148
149    SOURCE[foo]=foo.c details.c
150    DEPEND[foo]=libcookie
151
152This says that the program C<foo> is built from the source files
153F<foo.c> and F<details.c>, and that it depends on the library
154C<libcookie> (in other words, the library will be included when
155linking that program together).
156
157Multiple space separated items are allowed too:
158
159    SOURCE[foo]=foo.c
160    SOURCE[details]=details.c
161    DEPEND[foo details]=libcookie
162
163For any indexed statement for which the items haven't been specified
164through any plain statement, or where the items exists but the indexed
165statement does not apply, the value is simply ignored by the build
166file generators.
167
168=head3 Statement attributes
169
170Some statements can have attributes added to them, to allow for
171variations on how they are treated.
172
173=over 4
174
175=item B<I<KEYWORD>{> I<attrib> | I<attrib>B<=>I<attrib-value> [,...]B<}>
176B<=> I<value> ...
177
178=item B<I<KEYWORD>[>I<items>B<]{> I<attrib> | I<attrib>B<=>I<attrib-value>
179[,...]B<}> B<=> I<value> ...
180
181=back
182
183Attributes are passed as they are to the build file generators, and
184the exact interpretation of those attributes is entirely up to them
185(see L</Known attributes> below for details).
186
187A current example:
188
189    LIBS{noinst,has_main}=libtestutil.a
190
191This says that the static library C<libtestutil.a> should not be
192installed (C<noinst>), and that it includes an object file that has
193the C<main> symbol (C<has_main>).  Most platforms don't need to know
194the latter, but there are some where the program linker will not look
195for C<main> in libraries unless it's explicitly told so, so this is
196way to tell the build file generator to emit the necessary command
197options to make that happen.
198
199Attributes are accumulated globally.  This means that a library could
200be given like this in different places:
201
202    # Location 1
203    LIBS=libwhatever
204
205    # Location 2
206    LIBS{noinst}=libwhatever
207
208    # Location 3
209    LIBS{has_main}=libwhatever
210
211The end result is that the library C<libwhatever> will have the
212attributes C<noinst> and C<has_main> attached to it.
213
214=head3 Quoting and tokens
215
216Statement values are normally split into a list of tokens, separated
217by spaces.
218
219To avoid having a value split up into several tokens, they may be
220quoted with double (C<">) or single (C<'>) quotes.
221
222For example:
223
224    PROGRAMS=foo "space cadet" bar
225
226This says that we sant to build three programs, C<foo>, C<space cadet>
227and C<bar>.
228
229=head3 Conditionals
230
231F<build.info> files include a very simple condition system, involving
232the following keywords:
233
234=over 4
235
236=item B<IF[>0|1B<]>
237
238=item B<ELSIF[>0|1B<]>
239
240=item B<ELSE>
241
242=item B<ENDIF>
243
244=back
245
246This works like any condition system with similar syntax, and the
247condition value in B<IF> and B<ELSIF> can really be any literal value
248that perl can interpret as true or false.
249
250Conditional statements are nesting.
251
252In itself, this is not very powerful, but together with L</Perl nuggets>,
253it can be.
254
255=head3 Variables
256
257F<build.info> handles simple variables.  They are defined by
258assignment:
259
260=over 4
261
262=item B<$>I<NAME> B<=> I<value>
263
264=back
265
266These variables can then be used as part of any statement value or
267indexed statement item.  This should be used with some care, as
268I<variables are expanded into their values before the value they are
269part of is tokenized>.
270
271I<Variable assignment values are not tokenized.>
272
273Variable references can be one of:
274
275=over 4
276
277=item B<$>I<NAME> or B<${>I<NAME>B<}>
278
279Simple reference; the variable reference is replaced with its value,
280verbatim.
281
282=item B<${>I<NAME>B</>I<str>B</>I<subst>B<}>
283
284Substitution reference; the variable reference is replaced with its
285value, modified by replacing all occurrences of I<str> with I<subst>.
286
287=back
288
289=head2 Scope
290
291Most of the statement values are accumulated globally from all the
292F<build.info> files that are digested.  There are two exceptions,
293F<build.info> variables and B<SUBDIRS> statement, for which the scope
294is the F<build.info> file they are in.
295
296=head2 Perl nuggets
297
298Whenever a F<build.info> file is read, it is passed through the Perl
299template processor L<OpenSSL::Template>, which is a small extension of
300L<Text::Template>.
301
302Perl nuggets are anything between C<{-> and C<-}>, and whatever the
303result from such a nugget is, that value will replace the nugget in
304text form.  This is useful to get dynamically generated F<build.info>
305statements, and is most often seen used together with the B<IF> and
306B<ELSIF> conditional statements.
307
308For example:
309
310    IF[{- $disabled{something} -}]
311      # do whatever's needed when "something" is disabled
312    ELSIF[{- $somethingelse eq 'blah' -}]
313      # do whatever's needed to satisfy this condition
314    ELSE
315      # fallback
316    ENDIF
317
318Normal Perl scope applies, so it's possible to have an initial perl
319nugget that sets diverse global variables that are used in later
320nuggets.  Each nugget is a Perl block of its own, so B<my> definitions
321are only in scope within the same nugget, while B<our> definitions are
322in scope within the whole F<build.info> file.
323
324=head1 REFERENCE
325
326=head2 Conditionals
327
328=over 4
329
330=item B<IF[>0|1B<]>
331
332If the condition is true (represented as C<1> here), everything
333between this B<IF> and the next corresponding B<ELSIF> or B<ELSE>
334applies, and the rest until the corresponding B<ENDIF> is skipped
335over.
336
337If the condition is false (represented as C<0> here), everything
338from this B<IF> is skipped over until the next corresponding B<ELSIF>
339or B<ELSE>, at which point processing continues.
340
341=item B<ELSE>
342
343If F<build.info> statements have been skipped over to this point since
344the corresponding B<IF> or B<ELSIF>, F<build.info> processing starts
345again following this line.
346
347=item B<ELSIF[>0|1B<]>
348
349This is B<ELSE> and B<IF> combined.
350
351=item B<ENDIF>
352
353Marks the end of a conditional.
354
355=back
356
357=head2 Plain statements
358
359=over 4
360
361=item B<SUBDIRS=> I<dir> ...
362
363This instructs the F<build.info> reader to also read the F<build.info>
364file in every specified directory.  All directories should be given
365relative to the location of the current F<build.info> file.
366
367=item B<PROGRAMS=> I<name> ...
368
369Collects names of programs that should be built.
370
371B<PROGRAMS> statements may have attributes, which apply to all the
372programs given in such a statement.  For example:
373
374    PROGRAMS=foo
375    PROGRAMS{noinst}=bar
376
377With those two lines, the program C<foo> will not have the attribute
378C<noinst>, while the program C<bar> will.
379
380=item B<LIBS=> I<name> ...
381
382Collects names of libraries that should be built.
383
384The normal case is that libraries are built in both static and shared
385form.  However, if a name ends with C<.a>, only the static form will
386be produced.
387
388Similarly, libraries may be referred in indexed statements as just the
389plain name, or the name including the ending C<.a>.  If given without
390the ending C<.a>, any form available will be used, but if given with
391the ending C<.a>, the static library form is used unconditionally.
392
393B<LIBS> statements may have attributes, which apply to all the
394libraries given in such a statement.  For example:
395
396    LIBS=libfoo
397    LIBS{noinst}=libbar
398
399With those two lines, the library C<libfoo> will not have the
400attribute C<noinst>, while the library C<libbar> will.
401
402=item B<MODULES=> I<name>
403
404Collects names of dynamically loadable modules that should be built.
405
406B<MODULES> statements may have attributes, which apply to all the
407modules given in such a statement.  For example:
408
409    MODULES=foo
410    MODULES{noinst}=bar
411
412With those two lines, the module C<foo> will not have the attribute
413C<noinst>, while the module C<bar> will.
414
415=item B<SCRIPTS=> I<name>
416
417Collects names of scripts that should be built, or that just exist.
418That is how they differ from programs, as programs are always expected
419to be compiled from multiple sources.
420
421B<SCRIPTS> statements may have attributes, which apply to all the
422scripts given in such a statement.  For example:
423
424    SCRIPTS=foo
425    SCRIPTS{noinst}=bar
426
427With those two lines, the script C<foo> will not have the attribute
428C<noinst>, while the script C<bar> will.
429
430=back
431
432=head2 Indexed statements
433
434=over 4
435
436=item B<DEPEND[>I<items>B<]> B<=> I<file> ...
437
438Collects dependencies, where I<items> depend on the given I<file>s.
439
440As a special case, the I<items> may be empty, for which the build file
441generators should make the whole build depend on the given I<file>s,
442rather than the specific I<items>.
443
444The I<items> may be any program, library, module, script, or any
445filename used as a value anywhere.
446
447The I<items> may also be literal build file targets.  Those are
448recognised by being surrounded be vertical bars (also known as the
449"pipe" character), C<|>.  For example:
450
451    DEPEND[|tests|]=fipsmodule.cnf
452
453B<DEPEND> statements may have attributes, which apply to each
454individual dependency in such a statement.  For example:
455
456    DEPEND[libfoo.a]=libmandatory.a
457    DEPEND[libfoo.a]{weak}=libbar.a libcookie.a
458
459With those statements, the dependency between C<libfoo.a> and
460C<libmandatory.a> is strong, while the dependency between C<libfoo.a>
461and C<libbar.a> and C<libcookie.a> is weak.  See the description of
462B<weak> in L</Known attributes> for more information.
463
464B<DEPEND> is a bit more involving when used with I<item>s that are
465generated with B<GENERATE>.  This is described more in depth below.
466
467=item B<GENERATE[>I<item>B<]> B<=> I<generator> I<generator-arg> ...
468
469This specifies that the I<item> is generated using the I<generator>
470with the I<generator-arg>s as arguments, plus the name of the output
471file as last argument.
472
473The build file generators must be able to recognise the I<generator>.
474Currently, they at least recognise files ending in C<.pl>, and will
475execute them to generate the I<item>, and files ending in C<.in>,
476which will be used as input for L<OpenSSL::Template> to generate
477I<item> (in other words, we use the exact same style of
478L</Perl nuggets> mechanism that is used to read F<build.info> files).
479
480For I<generator>s where this is applicable, any B<INCLUDE> statement
481for the same I<item> will be given to the I<generator> as its
482inclusion directories.
483
484Likewise, For I<generator>s where this is applicable, any B<DEPEND>
485statement for the same I<item> will be given to the I<generator> as an
486extra file or module to load, where this is applicable.
487
488=over 4
489
490=item The B<DEPEND> statement may be problematic:
491
492Depending on what generator is used, a B<DEPEND> statement also acts
493as an B<INCLUDE> statement for the directory where the I<file> is
494located.  In some cases, that's not quite feasible, because a module
495isn't meant to be loaded by filename only and may require a nondefault
496separation between the implied inclusion directory and the intended module
497name.
498
499=item ... but there is a solution:
500
501To enable that sort of separation, B<DEPEND> can use a slightly
502different I<file> syntax, that looks like this:
503
504B<DEPEND[>I<items>B<]> B<=> I<dir>|I<module>
505
506The I<module> must be specified in a way that makes sense for the generator.
507For example, when the generator implies perl (ends with C<.in>) and depends
508on the module F<OpenSSL::foo> - a.k.a. F<OpenSSL/foo.pm> - which lives in
509F<util/perl>, it feasible to have something like this:
510
511    GENERATE[something.c]=something.c.in
512    DEPEND[something.c]=util/perl|OpenSSL/foo.pm
513
514=back
515
516=item B<SOURCE[>I<item>B<]> B<=> I<file> ...
517
518Collects filenames that will be used as source files for I<item>.
519
520The I<item> must be a singular item, and may be any program, library,
521module or script given with B<PROGRAMS>, B<LIBS>, B<MODULES> and
522B<SCRIPTS>.
523
524Static libraries may be sources.  In that case, its object files are
525used directly when building I<item> instead of relying on library
526dependency and symbol resolution (through B<DEPEND> statements).
527
528B<SOURCE> statements may have attributes, which apply to each
529individual dependency in such a statement.  For example:
530
531    SOURCE[prog]=prog_a.c
532    SOURCE[prog]{check}=prog_b.c prog_c.c
533
534With those statements, the association between C<prog> and C<prog_a.c>
535comes with no extra attributes, while the association between C<prog>
536and C<prog_b.c> as well as C<prog_c.c> comes with the extra attribute
537C<check>.
538
539=item B<SHARED_SOURCE[>I<item>B<]> B<=> I<file> ...
540
541Collects filenames that will be used as source files for I<item>.
542
543The I<item> must be a singular item, and may be any library or module
544given with B<LIBS> or B<MODULES>.  For libraries, the given filenames
545are only used for their shared form, so if the item is a library name
546ending with C<.a>, the filenames will be ignored.
547
548B<SHARED_SOURCE> statements may have attributes, just as B<SOURCE>
549statements.
550
551=item B<DEFINE[>I<items>B<]> B<=> I<name>[B<=>I<value>] ...
552
553Collects I<name> / I<value> pairs (or just I<name> with no defined
554value if no I<value> is given) associated with I<items>.
555
556The build file generators will decide what to do with them.  For
557example, these pairs should become C macro definitions whenever a
558C<.c> file is built into an object file.
559
560=item B<INCLUDE[>I<items>B<]> B<=> I<dir> ...
561
562Collects inclusion directories that will be used when building the
563I<items> components (object files and whatever else).  This is used at
564the discretion of the build file generators.
565
566=back
567
568=head2 Known attributes
569
570Note: this will never be a complete list of attributes.
571
572=over 4
573
574=item B<noinst>
575
576This is used to specify that the end products this is set for should
577not be installed, that they are only internal.  This is applicable on
578internal static libraries, or on test programs.
579
580=item B<misc>
581
582This is used with B<SCRIPTS>, to specify that some scripts should be
583installed in the "misc" directory rather than the normal program
584directory.
585
586=item B<engine>
587
588This is used with B<MODULES>, to specify what modules are engines and
589should be installed in the engines directory instead of the modules
590directory.
591
592=item B<weak>
593
594This is used with B<DEPEND> where libraries are involved, to specify
595that the dependency between two libraries is weak and is only there to
596infer order.
597
598Without this attribute, a dependency between two libraries, expressed
599like this, means that if C<libfoo.a> appears in a linking command
600line, so will C<libmandatory.a>:
601
602    DEPEND[libfoo.a]=libmandatory.a
603
604With this attribute, a dependency between two libraries, expressed
605like this, means that if I<both> C<libfoo.a> and C<libmandatory.a>
606appear in a linking command line (because of recursive dependencies
607through other libraries), they will be ordered in such a way that this
608dependency is maintained:
609
610    DEPEND[libfoo.a]{weak}=libfoo.a libcookie.a
611
612This is useful in complex dependency trees where two libraries can be
613used as alternatives for each other.  In this example, C<lib1.a> and
614C<lib2.a> have alternative implementations of the same thing, and
615C<libmandatory.a> has unresolved references to that same thing, and is
616therefore depending on either of them, but not both at the same time:
617
618    DEPEND[program1]=libmandatory.a lib1.a
619    DEPEND[program2]=libmandatory.a lib2.a
620    DEPEND[libmandatory]{weak}=lib1.a lib2.a
621
622=back
623
624=head1 GLOSSARY
625
626=over 4
627
628=item "build file"
629
630This is any platform specific file that describes the complete build,
631with platform specific commands.  On Unix, this is typically
632F<Makefile>; on VMS, this is typically F<descrip.mms>.
633
634=item "build file generator"
635
636Perl code that generates build files, given configuration data and
637data collected from F<build.info> files.
638
639=item "plain statement"
640
641Any F<build.info> statement of the form B<I<KEYWORD>>=I<values>, with
642the exception of conditional statements and variable assignments.
643
644=item "indexed statement"
645
646Any F<build.info> statement of the form B<I<KEYWORD>[>I<items>B<]=>I<values>,
647with the exception of conditional statements.
648
649=item "intermediate file"
650
651Any file that's an intermediate between a source file and an end
652product.
653
654=item "end product"
655
656Any file that is mentioned in the B<PROGRAMS>, B<LIBS>, B<MODULES> or
657B<SCRIPTS>.
658
659=back
660
661=head1 SEE ALSO
662
663For OpenSSL::Template documentation,
664C<perldoc -o man util/perl/OpenSSL/Template.pm>
665
666L<Text::Template|https://metacpan.org/pod/Text::Template>
667
668=head1 COPYRIGHT
669
670Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved.
671
672Licensed under the Apache License 2.0 (the "License").  You may not use this
673file except in compliance with the License.  You can obtain a copy in the file
674LICENSE in the source distribution or at
675L<https://www.openssl.org/source/license.html>.
676
677=cut
678