]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/doc/xml/manual/build_hacking.xml
re PR libstdc++/28811 (--with-pic vs static libraries and libstdc++)
[thirdparty/gcc.git] / libstdc++-v3 / doc / xml / manual / build_hacking.xml
1 <section xmlns="http://docbook.org/ns/docbook" version="5.0"
2 xml:id="appendix.porting.build_hacking" xreflabel="Build Hacking">
3 <?dbhtml filename="build_hacking.html"?>
4
5 <info><title>Configure and Build Hacking</title>
6 <keywordset>
7 <keyword>
8 C++
9 </keyword>
10 <keyword>
11 build
12 </keyword>
13 <keyword>
14 configure
15 </keyword>
16 <keyword>
17 hacking
18 </keyword>
19 <keyword>
20 version
21 </keyword>
22 <keyword>
23 dynamic
24 </keyword>
25 <keyword>
26 shared
27 </keyword>
28 </keywordset>
29 </info>
30
31 <section xml:id="build_hacking.prereq"><info><title>Prerequisites</title></info>
32
33 <para>
34 As noted <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/install/prerequisites.html">previously</link>,
35 certain other tools are necessary for hacking on files that
36 control configure (<code>configure.ac</code>,
37 <code>acinclude.m4</code>) and make
38 (<code>Makefile.am</code>). These additional tools
39 (<code>automake</code>, and <code>autoconf</code>) are further
40 described in detail in their respective manuals. All the libraries
41 in GCC try to stay in sync with each other in terms of versions of
42 the auto-tools used, so please try to play nicely with the
43 neighbors.
44 </para>
45 </section>
46
47 <section xml:id="build_hacking.overview">
48 <info><title>Overview</title></info>
49
50 <section xml:id="build_hacking.overview.basic">
51 <info><title>General Process</title></info>
52
53 <para>
54 The configure process begins the act of building libstdc++, and is
55 started via:
56 </para>
57
58 <screen>
59 <computeroutput>
60 configure
61 </computeroutput>
62 </screen>
63
64 <para>
65 The <filename>configure</filename> file is a script generated (via
66 <command>autoconf</command>) from the file
67 <filename>configure.ac</filename>.
68 </para>
69
70
71 <para>
72 After the configure process is complete,
73 </para>
74
75 <screen>
76 <computeroutput>
77 make all
78 </computeroutput>
79 </screen>
80
81 <para>
82 in the build directory starts the build process. The <literal>all</literal> target comes from the <filename>Makefile</filename> file, which is generated via <command>configure</command> from the <filename>Makefile.in</filename> file, which is in turn generated (via
83 <command>automake</command>) from the file
84 <filename>Makefile.am</filename>.
85 </para>
86
87 </section>
88
89
90 <section xml:id="build_hacking.overview.map"><info><title>What Comes from Where</title></info>
91
92
93 <figure>
94 <title>Configure and Build File Dependencies</title>
95 <mediaobject>
96 <imageobject>
97 <imagedata align="center" format="PDF" scale="75" fileref="../images/confdeps.pdf"/>
98 </imageobject>
99 <imageobject>
100 <imagedata align="center" format="PNG" scale="100" fileref="../images/confdeps.png"/>
101 </imageobject>
102 <textobject>
103 <phrase>Dependency Graph for Configure and Build Files</phrase>
104 </textobject>
105 </mediaobject>
106 </figure>
107
108 <para>
109 Regenerate all generated files by using the command
110 <code>autoreconf</code> at the top level of the libstdc++ source
111 directory.
112 </para>
113 </section>
114
115 </section> <!-- overview -->
116
117
118 <section xml:id="build_hacking.configure">
119 <info><title>Configure</title></info>
120
121 <section xml:id="build_hacking.configure.scripts"><info><title>Storing Information in non-AC files (like configure.host)</title></info>
122
123
124 <para>
125 Until that glorious day when we can use AC_TRY_LINK with a
126 cross-compiler, we have to hardcode the results of what the tests
127 would have shown if they could be run. So we have an inflexible
128 mess like crossconfig.m4.
129 </para>
130
131 <para>
132 Wouldn't it be nice if we could store that information in files
133 like configure.host, which can be modified without needing to
134 regenerate anything, and can even be tweaked without really
135 knowing how the configury all works? Perhaps break the pieces of
136 crossconfig.m4 out and place them in their appropriate
137 config/{cpu,os} directory.
138 </para>
139
140 <para>
141 Alas, writing macros like
142 "<code>AC_DEFINE(HAVE_A_NICE_DAY)</code>" can only be done inside
143 files which are passed through autoconf. Files which are pure
144 shell script can be source'd at configure time. Files which
145 contain autoconf macros must be processed with autoconf. We could
146 still try breaking the pieces out into "config/*/cross.m4" bits,
147 for instance, but then we would need arguments to aclocal/autoconf
148 to properly find them all when generating configure. I would
149 discourage that.
150 </para>
151 </section>
152
153 <section xml:id="build_hacking.configure.conventions"><info><title>Coding and Commenting Conventions</title></info>
154
155
156 <para>
157 Most comments should use {octothorpes, shibboleths, hash marks,
158 pound signs, whatever} rather than "dnl". Nearly all comments in
159 configure.ac should. Comments inside macros written in ancilliary
160 .m4 files should. About the only comments which should
161 <emphasis>not</emphasis> use #, but use dnl instead, are comments
162 <emphasis>outside</emphasis> our own macros in the ancilliary
163 files. The difference is that # comments show up in
164 <code>configure</code> (which is most helpful for debugging),
165 while dnl'd lines just vanish. Since the macros in ancilliary
166 files generate code which appears in odd places, their "outside"
167 comments tend to not be useful while reading
168 <code>configure</code>.
169 </para>
170
171 <para>
172 Do not use any <code>$target*</code> variables, such as
173 <code>$target_alias</code>. The single exception is in
174 configure.ac, for automake+dejagnu's sake.
175 </para>
176 </section>
177
178 <section xml:id="build_hacking.configure.acinclude"><info><title>The acinclude.m4 layout</title></info>
179
180 <para>
181 The nice thing about acinclude.m4/aclocal.m4 is that macros aren't
182 actually performed/called/expanded/whatever here, just loaded. So
183 we can arrange the contents however we like. As of this writing,
184 acinclude.m4 is arranged as follows:
185 </para>
186 <programlisting>
187 GLIBCXX_CHECK_HOST
188 GLIBCXX_TOPREL_CONFIGURE
189 GLIBCXX_CONFIGURE
190 </programlisting>
191 <para>
192 All the major variable "discovery" is done here. CXX, multilibs,
193 etc.
194 </para>
195 <programlisting>
196 fragments included from elsewhere
197 </programlisting>
198 <para>
199 Right now, "fragments" == "the math/linkage bits".
200 </para>
201 <programlisting>
202 GLIBCXX_CHECK_COMPILER_FEATURES
203 GLIBCXX_CHECK_LINKER_FEATURES
204 GLIBCXX_CHECK_WCHAR_T_SUPPORT
205 </programlisting>
206 <para>
207 Next come extra compiler/linker feature tests. Wide character
208 support was placed here because I couldn't think of another place
209 for it. It will probably get broken apart like the math tests,
210 because we're still disabling wchars on systems which could actually
211 support them.
212 </para>
213 <programlisting>
214 GLIBCXX_CHECK_SETRLIMIT_ancilliary
215 GLIBCXX_CHECK_SETRLIMIT
216 GLIBCXX_CHECK_S_ISREG_OR_S_IFREG
217 GLIBCXX_CHECK_POLL
218 GLIBCXX_CHECK_WRITEV
219
220 GLIBCXX_CONFIGURE_TESTSUITE
221 </programlisting>
222 <para>
223 Feature tests which only get used in one place. Here, things used
224 only in the testsuite, plus a couple bits used in the guts of I/O.
225 </para>
226 <programlisting>
227 GLIBCXX_EXPORT_INCLUDES
228 GLIBCXX_EXPORT_FLAGS
229 GLIBCXX_EXPORT_INSTALL_INFO
230 </programlisting>
231 <para>
232 Installation variables, multilibs, working with the rest of the
233 compiler. Many of the critical variables used in the makefiles are
234 set here.
235 </para>
236 <programlisting>
237 GLIBGCC_ENABLE
238 GLIBCXX_ENABLE_C99
239 GLIBCXX_ENABLE_CHEADERS
240 GLIBCXX_ENABLE_CLOCALE
241 GLIBCXX_ENABLE_CONCEPT_CHECKS
242 GLIBCXX_ENABLE_CSTDIO
243 GLIBCXX_ENABLE_CXX_FLAGS
244 GLIBCXX_ENABLE_C_MBCHAR
245 GLIBCXX_ENABLE_DEBUG
246 GLIBCXX_ENABLE_DEBUG_FLAGS
247 GLIBCXX_ENABLE_LONG_LONG
248 GLIBCXX_ENABLE_PCH
249 GLIBCXX_ENABLE_SJLJ_EXCEPTIONS
250 GLIBCXX_ENABLE_SYMVERS
251 GLIBCXX_ENABLE_THREADS
252 </programlisting>
253 <para>
254 All the features which can be controlled with enable/disable
255 configure options. Note how they're alphabetized now? Keep them
256 like that. :-)
257 </para>
258 <programlisting>
259 AC_LC_MESSAGES
260 libtool bits
261 </programlisting>
262 <para>
263 Things which we don't seem to use directly, but just has to be
264 present otherwise stuff magically goes wonky.
265 </para>
266
267 </section>
268
269 <section xml:id="build_hacking.configure.enable"><info><title><constant>GLIBCXX_ENABLE</constant>, the <literal>--enable</literal> maker</title></info>
270
271
272 <para>
273 All the GLIBCXX_ENABLE_FOO macros use a common helper,
274 GLIBCXX_ENABLE. (You don't have to use it, but it's easy.) The
275 helper does two things for us:
276 </para>
277
278 <orderedlist>
279 <listitem>
280 <para>
281 Builds the call to the AC_ARG_ENABLE macro, with --help text
282 properly quoted and aligned. (Death to changequote!)
283 </para>
284 </listitem>
285 <listitem>
286 <para>
287 Checks the result against a list of allowed possibilities, and
288 signals a fatal error if there's no match. This means that the
289 rest of the GLIBCXX_ENABLE_FOO macro doesn't need to test for
290 strange arguments, nor do we need to protect against
291 empty/whitespace strings with the <code>"x$foo" = "xbar"</code>
292 idiom.
293 </para>
294 </listitem>
295 </orderedlist>
296
297 <para>Doing these things correctly takes some extra autoconf/autom4te code,
298 which made our macros nearly illegible. So all the ugliness is factored
299 out into this one helper macro.
300 </para>
301
302 <para>Many of the macros take an argument, passed from when they are expanded
303 in configure.ac. The argument controls the default value of the
304 enable/disable switch. Previously, the arguments themselves had defaults.
305 Now they don't, because that's extra complexity with zero gain for us.
306 </para>
307
308 <para>There are three "overloaded signatures". When reading the descriptions
309 below, keep in mind that the brackets are autoconf's quotation characters,
310 and that they will be stripped. Examples of just about everything occur
311 in acinclude.m4, if you want to look.
312 </para>
313
314 <programlisting>
315 GLIBCXX_ENABLE (FEATURE, DEFAULT, HELP-ARG, HELP-STRING)
316 GLIBCXX_ENABLE (FEATURE, DEFAULT, HELP-ARG, HELP-STRING, permit a|b|c)
317 GLIBCXX_ENABLE (FEATURE, DEFAULT, HELP-ARG, HELP-STRING, SHELL-CODE-HANDLER)
318 </programlisting>
319
320 <itemizedlist>
321 <listitem>
322 <para>
323 FEATURE is the string that follows --enable. The results of the
324 test (such as it is) will be in the variable $enable_FEATURE,
325 where FEATURE has been squashed. Example:
326 <code>[extra-foo]</code>, controlled by the --enable-extra-foo
327 option and stored in $enable_extra_foo.
328 </para>
329 </listitem>
330 <listitem>
331 <para>
332 DEFAULT is the value to store in $enable_FEATURE if the user does
333 not pass --enable/--disable. It should be one of the permitted
334 values passed later. Examples: <code>[yes]</code>, or
335 <code>[bar]</code>, or <code>[$1]</code> (which passes the
336 argument given to the GLIBCXX_ENABLE_FOO macro as the
337 default).
338 </para>
339 <para>
340 For cases where we need to probe for particular models of things,
341 it is useful to have an undocumented "auto" value here (see
342 GLIBCXX_ENABLE_CLOCALE for an example).
343 </para>
344 </listitem>
345 <listitem>
346 <para>
347 HELP-ARG is any text to append to the option string itself in the
348 --help output. Examples: <code>[]</code> (i.e., an empty string,
349 which appends nothing), <code>[=BAR]</code>, which produces
350 <code>--enable-extra-foo=BAR</code>, and
351 <code>[@&lt;:@=BAR@:&gt;@]</code>, which produces
352 <code>--enable-extra-foo[=BAR]</code>. See the difference? See
353 what it implies to the user?
354 </para>
355 <para>
356 If you're wondering what that line noise in the last example was,
357 that's how you embed autoconf special characters in output text.
358 They're called <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.gnu.org/software/autoconf/manual/autoconf.html#Quadrigraphs"><emphasis>quadrigraphs</emphasis></link>
359 and you should use them whenever necessary.
360 </para>
361 </listitem>
362 <listitem>
363 <para>HELP-STRING is what you think it is. Do not include the
364 "default" text like we used to do; it will be done for you by
365 GLIBCXX_ENABLE. By convention, these are not full English
366 sentences. Example: [turn on extra foo]
367 </para>
368 </listitem>
369 </itemizedlist>
370
371 <para>
372 With no other arguments, only the standard autoconf patterns are
373 allowed: "<code>--{enable,disable}-foo[={yes,no}]</code>" The
374 $enable_FEATURE variable is guaranteed to equal either "yes" or "no"
375 after the macro. If the user tries to pass something else, an
376 explanatory error message will be given, and configure will halt.
377 </para>
378
379 <para>
380 The second signature takes a fifth argument, "<code>[permit
381 a | b | c | ...]</code>"
382 This allows <emphasis>a</emphasis> or <emphasis>b</emphasis> or
383 ... after the equals sign in the option, and $enable_FEATURE is
384 guaranteed to equal one of them after the macro. Note that if you
385 want to allow plain --enable/--disable with no "=whatever", you must
386 include "yes" and "no" in the list of permitted values. Also note
387 that whatever you passed as DEFAULT must be in the list. If the
388 user tries to pass something not on the list, a semi-explanatory
389 error message will be given, and configure will halt. Example:
390 <code>[permit generic|gnu|ieee_1003.1-2001|yes|no|auto]</code>
391 </para>
392
393 <para>
394 The third signature takes a fifth argument. It is arbitrary shell
395 code to execute if the user actually passes the enable/disable
396 option. (If the user does not, the default is used. Duh.) No
397 argument checking at all is done in this signature. See
398 GLIBCXX_ENABLE_CXX_FLAGS for an example of handling, and an error
399 message.
400 </para>
401
402 </section>
403 </section> <!-- configure -->
404
405 <section xml:id="build_hacking.make"><info><title>Make</title></info>
406
407 <para>
408 The build process has to make all of object files needed for
409 static or shared libraries, but first it has to generate some
410 include files. The general order is as follows:
411 </para>
412
413 <orderedlist>
414 <listitem>
415 <para>
416 make include files, make pre-compiled headers
417 </para>
418 </listitem>
419 <listitem>
420 <para>
421 make libsupc++
422 </para>
423 <para>
424 Generates a libtool convenience library,
425 <filename>libsupc++convenience</filename> with language-support
426 routines. Also generates a freestanding static library,
427 <filename>libsupc++.a</filename>.
428 </para>
429 </listitem>
430 <listitem>
431 <para>
432 make src
433 </para>
434 <para>
435 Generates two convenience libraries, one for C++98 and one for
436 C++11, various compability files for shared and static
437 libraries, and then collects all the generated bits and creates
438 the final libstdc++ libraries.
439 </para>
440 <orderedlist>
441 <listitem>
442 <para>
443 make src/c++98
444 </para>
445 <para>
446 Generates a libtool convenience library,
447 <filename>libc++98convenience</filename> with language-support
448 routines. Uses the <literal>-std=gnu++98</literal> dialect.
449 </para>
450 </listitem>
451 <listitem>
452 <para>
453 make src/c++11
454 </para>
455 <para>
456 Generates a libtool convenience library,
457 <filename>libc++11convenience</filename> with language-support
458 routines. Uses the <literal>-std=gnu++11</literal> dialect.
459 </para>
460 </listitem>
461 <listitem>
462 <para>
463 make src
464 </para>
465 <para>
466 Generates needed compatibility objects for shared and static
467 libraries. Shared-only code is seggregated at compile-time via
468 the macro <literal>_GLIBCXX_SHARED</literal>.
469 </para>
470
471 <para>
472 Then, collects all the generated convenience libraries, adds in
473 any required compatibility objects, and creates the final shared
474 and static libraries: <filename>libstdc++.so</filename> and
475 <filename>libstdc++.a</filename>.
476 </para>
477
478 </listitem>
479 </orderedlist>
480 </listitem>
481 </orderedlist>
482
483 </section> <!-- make -->
484
485 </section>