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