OSDN Git Service

2011-02-08 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.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_HACKING
12     </keyword>
13     <keyword>
14       version
15     </keyword>
16     <keyword>
17       dynamic
18     </keyword>
19     <keyword>
20       shared
21     </keyword>
22   </keywordset>
23 </info>
24
25 <section xml:id="build_hacking.prereq"><info><title>Prerequisites</title></info>
26
27   <para>
28     As noted <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/install/prerequisites.html">previously</link>,
29     certain other tools are necessary for hacking on files that
30     control configure (<code>configure.ac</code>,
31     <code>acinclude.m4</code>) and make
32     (<code>Makefile.am</code>). These additional tools
33     (<code>automake</code>, and <code>autoconf</code>) are further
34     described in detail in their respective manuals. All the libraries
35     in GCC try to stay in sync with each other in terms of versions of
36     the auto-tools used, so please try to play nicely with the
37     neighbors.
38   </para>
39 </section>
40
41 <section xml:id="build_hacking.map"><info><title>Overview: What Comes from Where</title></info>
42
43
44   <figure>
45     <title>Configure and Build File Dependencies</title>
46   <mediaobject>
47     <imageobject>
48       <imagedata align="center" format="PDF" fileref="/mnt/share/src/gcc.svn-trunk/libstdc++-v3/doc/xml/images/confdeps.pdf"/>
49     </imageobject>
50     <imageobject>
51       <imagedata align="center" format="PNG" fileref="/mnt/share/src/gcc.svn-trunk/libstdc++-v3/doc/xml/images/confdeps.png"/>
52     </imageobject>
53     <textobject>
54       <phrase>Dependency Graph for Configure and Build Files</phrase>
55     </textobject>
56   </mediaobject>
57   </figure>
58
59   <para>
60     Regenerate all generated files by using the command sequence
61     <code>"autoreconf"</code> at the top level of the libstdc++ source
62     directory. The following will also work, but is much more complex:
63     <code>"aclocal-1.11 &amp;&amp; autoconf-2.64 &amp;&amp;
64     autoheader-2.64 &amp;&amp; automake-1.11"</code> The version
65     numbers may be absent entirely or otherwise vary depending on
66     <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/install/prerequisites.html">the
67     current requirements</link> and your vendor's choice of
68     installation names.
69   </para>
70 </section>
71
72 <section xml:id="build_hacking.scripts"><info><title>Storing Information in non-AC files (like configure.host)</title></info>
73
74
75   <para>
76     Until that glorious day when we can use AC_TRY_LINK with a
77     cross-compiler, we have to hardcode the results of what the tests
78     would have shown if they could be run.  So we have an inflexible
79     mess like crossconfig.m4.
80   </para>
81
82   <para>
83     Wouldn't it be nice if we could store that information in files
84     like configure.host, which can be modified without needing to
85     regenerate anything, and can even be tweaked without really
86     knowing how the configury all works?  Perhaps break the pieces of
87     crossconfig.m4 out and place them in their appropriate
88     config/{cpu,os} directory.
89   </para>
90
91   <para>
92     Alas, writing macros like
93     "<code>AC_DEFINE(HAVE_A_NICE_DAY)</code>" can only be done inside
94     files which are passed through autoconf.  Files which are pure
95     shell script can be source'd at configure time.  Files which
96     contain autoconf macros must be processed with autoconf.  We could
97     still try breaking the pieces out into "config/*/cross.m4" bits,
98     for instance, but then we would need arguments to aclocal/autoconf
99     to properly find them all when generating configure.  I would
100     discourage that.
101 </para>
102 </section>
103
104 <section xml:id="build_hacking.conventions"><info><title>Coding and Commenting Conventions</title></info>
105
106
107   <para>
108     Most comments should use {octothorpes, shibboleths, hash marks,
109     pound signs, whatever} rather than "dnl".  Nearly all comments in
110     configure.ac should.  Comments inside macros written in ancilliary
111     .m4 files should.  About the only comments which should
112     <emphasis>not</emphasis> use #, but use dnl instead, are comments
113     <emphasis>outside</emphasis> our own macros in the ancilliary
114     files.  The difference is that # comments show up in
115     <code>configure</code> (which is most helpful for debugging),
116     while dnl'd lines just vanish.  Since the macros in ancilliary
117     files generate code which appears in odd places, their "outside"
118     comments tend to not be useful while reading
119     <code>configure</code>.
120   </para>
121
122   <para>
123     Do not use any <code>$target*</code> variables, such as
124     <code>$target_alias</code>.  The single exception is in
125     configure.ac, for automake+dejagnu's sake.
126   </para>
127 </section>
128
129 <section xml:id="build_hacking.acinclude"><info><title>The acinclude.m4 layout</title></info>
130
131   <para>
132     The nice thing about acinclude.m4/aclocal.m4 is that macros aren't
133     actually performed/called/expanded/whatever here, just loaded.  So
134     we can arrange the contents however we like.  As of this writing,
135     acinclude.m4 is arranged as follows:
136   </para>
137   <programlisting>
138     GLIBCXX_CHECK_HOST
139     GLIBCXX_TOPREL_CONFIGURE
140     GLIBCXX_CONFIGURE
141   </programlisting>
142   <para>
143     All the major variable "discovery" is done here.  CXX, multilibs,
144     etc.
145   </para>
146   <programlisting>
147     fragments included from elsewhere
148   </programlisting>
149   <para>
150     Right now, "fragments" == "the math/linkage bits".
151   </para>
152 <programlisting>
153     GLIBCXX_CHECK_COMPILER_FEATURES
154     GLIBCXX_CHECK_LINKER_FEATURES
155     GLIBCXX_CHECK_WCHAR_T_SUPPORT
156 </programlisting>
157 <para>
158   Next come extra compiler/linker feature tests.  Wide character
159   support was placed here because I couldn't think of another place
160   for it.  It will probably get broken apart like the math tests,
161   because we're still disabling wchars on systems which could actually
162   support them.
163 </para>
164 <programlisting>
165     GLIBCXX_CHECK_SETRLIMIT_ancilliary
166     GLIBCXX_CHECK_SETRLIMIT
167     GLIBCXX_CHECK_S_ISREG_OR_S_IFREG
168     GLIBCXX_CHECK_POLL
169     GLIBCXX_CHECK_WRITEV
170
171     GLIBCXX_CONFIGURE_TESTSUITE
172 </programlisting>
173 <para>
174   Feature tests which only get used in one place.  Here, things used
175   only in the testsuite, plus a couple bits used in the guts of I/O.
176 </para>
177 <programlisting>
178     GLIBCXX_EXPORT_INCLUDES
179     GLIBCXX_EXPORT_FLAGS
180     GLIBCXX_EXPORT_INSTALL_INFO
181 </programlisting>
182 <para>
183   Installation variables, multilibs, working with the rest of the
184   compiler.  Many of the critical variables used in the makefiles are
185   set here.
186 </para>
187 <programlisting>
188     GLIBGCC_ENABLE
189     GLIBCXX_ENABLE_C99
190     GLIBCXX_ENABLE_CHEADERS
191     GLIBCXX_ENABLE_CLOCALE
192     GLIBCXX_ENABLE_CONCEPT_CHECKS
193     GLIBCXX_ENABLE_CSTDIO
194     GLIBCXX_ENABLE_CXX_FLAGS
195     GLIBCXX_ENABLE_C_MBCHAR
196     GLIBCXX_ENABLE_DEBUG
197     GLIBCXX_ENABLE_DEBUG_FLAGS
198     GLIBCXX_ENABLE_LONG_LONG
199     GLIBCXX_ENABLE_PCH
200     GLIBCXX_ENABLE_SJLJ_EXCEPTIONS
201     GLIBCXX_ENABLE_SYMVERS
202     GLIBCXX_ENABLE_THREADS
203 </programlisting>
204 <para>
205   All the features which can be controlled with enable/disable
206   configure options.  Note how they're alphabetized now?  Keep them
207   like that.  :-)
208 </para>
209 <programlisting>
210     AC_LC_MESSAGES
211     libtool bits
212 </programlisting>
213 <para>
214   Things which we don't seem to use directly, but just has to be
215   present otherwise stuff magically goes wonky.
216 </para>
217
218 </section>
219
220 <section xml:id="build_hacking.enable"><info><title><constant>GLIBCXX_ENABLE</constant>, the <literal>--enable</literal> maker</title></info>
221
222
223   <para>
224     All the GLIBCXX_ENABLE_FOO macros use a common helper,
225     GLIBCXX_ENABLE.  (You don't have to use it, but it's easy.)  The
226     helper does two things for us:
227   </para>
228
229 <orderedlist>
230  <listitem>
231    <para>
232      Builds the call to the AC_ARG_ENABLE macro, with --help text
233      properly quoted and aligned.  (Death to changequote!)
234    </para>
235  </listitem>
236  <listitem>
237    <para>
238      Checks the result against a list of allowed possibilities, and
239      signals a fatal error if there's no match.  This means that the
240      rest of the GLIBCXX_ENABLE_FOO macro doesn't need to test for
241      strange arguments, nor do we need to protect against
242      empty/whitespace strings with the <code>"x$foo" = "xbar"</code>
243      idiom.
244    </para>
245  </listitem>
246 </orderedlist>
247
248 <para>Doing these things correctly takes some extra autoconf/autom4te code,
249    which made our macros nearly illegible.  So all the ugliness is factored
250    out into this one helper macro.
251 </para>
252
253 <para>Many of the macros take an argument, passed from when they are expanded
254    in configure.ac.  The argument controls the default value of the
255    enable/disable switch.  Previously, the arguments themselves had defaults.
256    Now they don't, because that's extra complexity with zero gain for us.
257 </para>
258
259 <para>There are three "overloaded signatures".  When reading the descriptions
260    below, keep in mind that the brackets are autoconf's quotation characters,
261    and that they will be stripped.  Examples of just about everything occur
262    in acinclude.m4, if you want to look.
263 </para>
264
265 <programlisting>
266     GLIBCXX_ENABLE (FEATURE, DEFAULT, HELP-ARG, HELP-STRING)
267     GLIBCXX_ENABLE (FEATURE, DEFAULT, HELP-ARG, HELP-STRING, permit a|b|c)
268     GLIBCXX_ENABLE (FEATURE, DEFAULT, HELP-ARG, HELP-STRING, SHELL-CODE-HANDLER)
269 </programlisting>
270
271 <itemizedlist>
272  <listitem>
273    <para>
274      FEATURE is the string that follows --enable.  The results of the
275      test (such as it is) will be in the variable $enable_FEATURE,
276      where FEATURE has been squashed.  Example:
277      <code>[extra-foo]</code>, controlled by the --enable-extra-foo
278      option and stored in $enable_extra_foo.
279    </para>
280  </listitem>
281  <listitem>
282    <para>
283      DEFAULT is the value to store in $enable_FEATURE if the user does
284      not pass --enable/--disable.  It should be one of the permitted
285      values passed later.  Examples: <code>[yes]</code>, or
286      <code>[bar]</code>, or <code>[$1]</code> (which passes the
287      argument given to the GLIBCXX_ENABLE_FOO macro as the
288      default).
289    </para>
290    <para>
291      For cases where we need to probe for particular models of things,
292      it is useful to have an undocumented "auto" value here (see
293      GLIBCXX_ENABLE_CLOCALE for an example).
294    </para>
295  </listitem>
296  <listitem>
297    <para>
298      HELP-ARG is any text to append to the option string itself in the
299      --help output.  Examples: <code>[]</code> (i.e., an empty string,
300      which appends nothing), <code>[=BAR]</code>, which produces
301      <code>--enable-extra-foo=BAR</code>, and
302      <code>[@&lt;:@=BAR@:&gt;@]</code>, which produces
303      <code>--enable-extra-foo[=BAR]</code>.  See the difference?  See
304      what it implies to the user?
305    </para>
306    <para>
307      If you're wondering what that line noise in the last example was,
308      that's how you embed autoconf special characters in output text.
309      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>
310      and you should use them whenever necessary.
311  </para>
312  </listitem>
313  <listitem>
314    <para>HELP-STRING is what you think it is.  Do not include the
315    "default" text like we used to do; it will be done for you by
316    GLIBCXX_ENABLE.  By convention, these are not full English
317    sentences.  Example: [turn on extra foo]
318    </para>
319  </listitem>
320 </itemizedlist>
321
322 <para>
323   With no other arguments, only the standard autoconf patterns are
324   allowed: "<code>--{enable,disable}-foo[={yes,no}]</code>" The
325   $enable_FEATURE variable is guaranteed to equal either "yes" or "no"
326   after the macro.  If the user tries to pass something else, an
327   explanatory error message will be given, and configure will halt.
328 </para>
329
330 <para>
331   The second signature takes a fifth argument, "<code>[permit
332   a | b | c | ...]</code>"
333   This allows <emphasis>a</emphasis> or <emphasis>b</emphasis> or
334   ... after the equals sign in the option, and $enable_FEATURE is
335   guaranteed to equal one of them after the macro.  Note that if you
336   want to allow plain --enable/--disable with no "=whatever", you must
337   include "yes" and "no" in the list of permitted values.  Also note
338   that whatever you passed as DEFAULT must be in the list.  If the
339   user tries to pass something not on the list, a semi-explanatory
340   error message will be given, and configure will halt.  Example:
341   <code>[permit generic|gnu|ieee_1003.1-2001|yes|no|auto]</code>
342 </para>
343
344 <para>
345   The third signature takes a fifth argument.  It is arbitrary shell
346   code to execute if the user actually passes the enable/disable
347   option.  (If the user does not, the default is used.  Duh.)  No
348   argument checking at all is done in this signature.  See
349   GLIBCXX_ENABLE_CXX_FLAGS for an example of handling, and an error
350   message.
351 </para>
352
353 </section>
354
355 </section>