This commit was manufactured by cvs2svn to create branch
[official-gcc.git] / gcc / doc / sourcebuild.texi
blob75028aca6556cb79ba5b7b0c31a0dd18506c451f
1 @c Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
2 @c This is part of the GCC manual.
3 @c For copying conditions, see the file gcc.texi.
5 @node Source Tree
6 @chapter Source Tree Structure and Build System
8 This chapter describes the structure of the GCC source tree, and how
9 GCC is built.  The user documentation for building and installing GCC
10 is in a separate manual (@uref{http://gcc.gnu.org/install/}), with
11 which it is presumed that you are familiar.
13 @menu
14 * Configure Terms:: Configuration terminology and history.
15 * Top Level::       The top level source directory.
16 * gcc Directory::   The @file{gcc} subdirectory.
17 * Test Suites::     The GCC test suites.
18 @end menu
20 @include configterms.texi
22 @node Top Level
23 @section Top Level Source Directory
25 The top level source directory in a GCC distribution contains several
26 files and directories that are shared with other software
27 distributions such as that of GNU Binutils.  It also contains several
28 subdirectories that contain parts of GCC and its runtime libraries:
30 @table @file
31 @item boehm-gc
32 The Boehm conservative garbage collector, used as part of the Java
33 runtime library.
35 @item contrib
36 Contributed scripts that may be found useful in conjunction with GCC@.
37 One of these, @file{contrib/texi2pod.pl}, is used to generate man
38 pages from Texinfo manuals as part of the GCC build process.
40 @item fastjar
41 An implementation of the @command{jar} command, used with the Java
42 front end.
44 @item gcc
45 The main sources of GCC itself (except for runtime libraries),
46 including optimizers, support for different target architectures,
47 language front ends, and test suites.  @xref{gcc Directory, , The
48 @file{gcc} Subdirectory}, for details.
50 @item include
51 Headers for the @code{libiberty} library.
53 @item libf2c
54 The Fortran runtime library.
56 @item libffi
57 The @code{libffi} library, used as part of the Java runtime library.
59 @item libiberty
60 The @code{libiberty} library, used for portability and for some
61 generally useful data structures and algorithms.  @xref{Top, ,
62 Introduction, libiberty, @sc{gnu} libiberty}, for more information
63 about this library.
65 @item libjava
66 The Java runtime library.
68 @item libobjc
69 The Objective-C runtime library.
71 @item libstdc++-v3
72 The C++ runtime library.
74 @item maintainer-scripts
75 Scripts used by the @code{gccadmin} account on @code{gcc.gnu.org}.
77 @item zlib
78 The @code{zlib} compression library, used by the Java front end and as
79 part of the Java runtime library.
80 @end table
82 The build system in the top level directory, including how recursion
83 into subdirectories works and how building runtime libraries for
84 multilibs is handled, is documented in a separate manual, included
85 with GNU Binutils.  @xref{Top, , GNU configure and build system,
86 configure, The GNU configure and build system}, for details.
88 @node gcc Directory
89 @section The @file{gcc} Subdirectory
91 The @file{gcc} directory contains many files that are part of the C
92 sources of GCC, other files used as part of the configuration and
93 build process, and subdirectories including documentation and a
94 test suite.  The files that are sources of GCC are documented in a
95 separate chapter.  @xref{Passes, , Passes and Files of the Compiler}.
97 @menu
98 * Subdirectories:: Subdirectories of @file{gcc}.
99 * Configuration::  The configuration process, and the files it uses.
100 * Build::          The build system in the @file{gcc} directory.
101 * Makefile::       Targets in @file{gcc/Makefile}.
102 * Library Files::  Library source files and headers under @file{gcc/}.
103 * Headers::        Headers installed by GCC.
104 * Documentation::  Building documentation in GCC.
105 * Front End::      Anatomy of a language front end.
106 * Back End::       Anatomy of a target back end.
107 @end menu
109 @node Subdirectories
110 @subsection Subdirectories of @file{gcc}
112 The @file{gcc} directory contains the following subdirectories:
114 @table @file
115 @item @var{language}
116 Subdirectories for various languages.  Directories containing a file
117 @file{config-lang.in} are language subdirectories.  The contents of
118 the subdirectories @file{cp} (for C++) and @file{objc} (for
119 Objective-C) are documented in this manual (@pxref{Passes, , Passes
120 and Files of the Compiler}); those for other languages are not.
121 @xref{Front End, , Anatomy of a Language Front End}, for details of
122 the files in these directories.
124 @item config
125 Configuration files for supported architectures and operating
126 systems.  @xref{Back End, , Anatomy of a Target Back End}, for
127 details of the files in this directory.
129 @item doc
130 Texinfo documentation for GCC, together with automatically generated
131 man pages and support for converting the installation manual to
132 HTML@.  @xref{Documentation}.
134 @item fixinc
135 The support for fixing system headers to work with GCC@.  See
136 @file{fixinc/README} for more information.  The headers fixed by this
137 mechanism are installed in @file{@var{libsubdir}/include}.  Along with
138 those headers, @file{README-fixinc} is also installed, as
139 @file{@var{libsubdir}/include/README}.
141 @item ginclude
142 System headers installed by GCC, mainly those required by the C
143 standard of freestanding implementations.  @xref{Headers, , Headers
144 Installed by GCC}, for details of when these and other headers are
145 installed.
147 @item intl
148 GNU @code{libintl}, from GNU @code{gettext}, for systems which do not
149 include it in libc.  Properly, this directory should be at top level,
150 parallel to the @file{gcc} directory.
152 @item po
153 Message catalogs with translations of messages produced by GCC into
154 various languages, @file{@var{language}.po}.  This directory also
155 contains @file{gcc.pot}, the template for these message catalogues,
156 @file{exgettext}, a wrapper around @command{gettext} to extract the
157 messages from the GCC sources and create @file{gcc.pot}, which is run
158 by @samp{make gcc.pot}, and @file{EXCLUDES}, a list of files from
159 which messages should not be extracted.
161 @item testsuite
162 The GCC test suites (except for those for runtime libraries).
163 @xref{Test Suites}.
164 @end table
166 @node Configuration
167 @subsection Configuration in the @file{gcc} Directory
169 The @file{gcc} directory is configured with an Autoconf-generated
170 script @file{configure}.  The @file{configure} script is generated
171 from @file{configure.ac} and @file{aclocal.m4}.  From the files
172 @file{configure.ac} and @file{acconfig.h}, Autoheader generates the
173 file @file{config.in}.  The file @file{cstamp-h.in} is used as a
174 timestamp.
176 @menu
177 * Config Fragments::     Scripts used by @file{configure}.
178 * System Config::        The @file{config.build}, @file{config.host}, and
179                          @file{config.gcc} files.
180 * Configuration Files::  Files created by running @file{configure}.
181 @end menu
183 @node Config Fragments
184 @subsubsection Scripts Used by @file{configure}
186 @file{configure} uses some other scripts to help in its work:
188 @itemize @bullet
189 @item The standard GNU @file{config.sub} and @file{config.guess}
190 files, kept in the top level directory, are used.  FIXME: when is the
191 @file{config.guess} file in the @file{gcc} directory (that just calls
192 the top level one) used?
194 @item The file @file{config.gcc} is used to handle configuration
195 specific to the particular target machine.  The file
196 @file{config.build} is used to handle configuration specific to the
197 particular build machine.  The file @file{config.host} is used to handle
198 configuration specific to the particular host machine.  (In general,
199 these should only be used for features that cannot reasonably be tested in
200 Autoconf feature tests.)
201 @xref{System Config, , The @file{config.build}, @file{config.host},
202 and @file{config.gcc} Files}, for details of the contents of these files.
204 @item Each language subdirectory has a file
205 @file{@var{language}/config-lang.in} that is used for
206 front-end-specific configuration.  @xref{Front End Config, , The Front
207 End @file{config-lang.in} File}, for details of this file.
209 @item A helper script @file{configure.frag} is used as part of
210 creating the output of @file{configure}.
211 @end itemize
213 @node System Config
214 @subsubsection The @file{config.build}, @file{config.host}, and @file{config.gcc} Files
216 The @file{config.build} file contains specific rules for particular systems
217 which GCC is built on.  This should be used as rarely as possible, as the
218 behavior of the build system can always be detected by autoconf.
220 The @file{config.host} file contains specific rules for particular systems
221 which GCC will run on.  This is rarely needed.
223 The @file{config.gcc} file contains specific rules for particular systems
224 which GCC will generate code for.  This is usually needed.
226 Each file has a list of the shell variables it sets, with descriptions, at the
227 top of the file.
229 FIXME: document the contents of these files, and what variables should
230 be set to control build, host and target configuration.
232 @include configfiles.texi
234 @node Build
235 @subsection Build System in the @file{gcc} Directory
237 FIXME: describe the build system, including what is built in what
238 stages.  Also list the various source files that are used in the build
239 process but aren't source files of GCC itself and so aren't documented
240 below (@pxref{Passes}).
242 @include makefile.texi
244 @node Library Files
245 @subsection Library Source Files and Headers under the @file{gcc} Directory
247 FIXME: list here, with explanation, all the C source files and headers
248 under the @file{gcc} directory that aren't built into the GCC
249 executable but rather are part of runtime libraries and object files,
250 such as @file{crtstuff.c} and @file{unwind-dw2.c}.  @xref{Headers, ,
251 Headers Installed by GCC}, for more information about the
252 @file{ginclude} directory.
254 @node Headers
255 @subsection Headers Installed by GCC
257 In general, GCC expects the system C library to provide most of the
258 headers to be used with it.  However, GCC will fix those headers if
259 necessary to make them work with GCC, and will install some headers
260 required of freestanding implementations.  These headers are installed
261 in @file{@var{libsubdir}/include}.  Headers for non-C runtime
262 libraries are also installed by GCC; these are not documented here.
263 (FIXME: document them somewhere.)
265 Several of the headers GCC installs are in the @file{ginclude}
266 directory.  These headers, @file{iso646.h},
267 @file{stdarg.h}, @file{stdbool.h}, and @file{stddef.h},
268 are installed in @file{@var{libsubdir}/include},
269 unless the target Makefile fragment (@pxref{Target Fragment})
270 overrides this by setting @code{USER_H}.
272 In addition to these headers and those generated by fixing system
273 headers to work with GCC, some other headers may also be installed in
274 @file{@var{libsubdir}/include}.  @file{config.gcc} may set
275 @code{extra_headers}; this specifies additional headers under
276 @file{config} to be installed on some systems.
278 GCC installs its own version of @code{<float.h>}, from @file{ginclude/float.h}.
279 This is done to cope with command-line options that change the
280 representation of floating point numbers.
282 GCC also installs its own version of @code{<limits.h>}; this is generated
283 from @file{glimits.h}, together with @file{limitx.h} and
284 @file{limity.h} if the system also has its own version of
285 @code{<limits.h>}.  (GCC provides its own header because it is
286 required of ISO C freestanding implementations, but needs to include
287 the system header from its own header as well because other standards
288 such as POSIX specify additional values to be defined in
289 @code{<limits.h>}.)  The system's @code{<limits.h>} header is used via
290 @file{@var{libsubdir}/include/syslimits.h}, which is copied from
291 @file{gsyslimits.h} if it does not need fixing to work with GCC; if it
292 needs fixing, @file{syslimits.h} is the fixed copy.
294 @node Documentation
295 @subsection Building Documentation
297 The main GCC documentation is in the form of manuals in Texinfo
298 format.  These are installed in Info format, and DVI versions may be
299 generated by @samp{make dvi}.  In addition, some man pages are
300 generated from the Texinfo manuals, there are some other text files
301 with miscellaneous documentation, and runtime libraries have their own
302 documentation outside the @file{gcc} directory.  FIXME: document the
303 documentation for runtime libraries somewhere.
305 @menu
306 * Texinfo Manuals::      GCC manuals in Texinfo format.
307 * Man Page Generation::  Generating man pages from Texinfo manuals.
308 * Miscellaneous Docs::   Miscellaneous text files with documentation.
309 @end menu
311 @node Texinfo Manuals
312 @subsubsection Texinfo Manuals
314 The manuals for GCC as a whole, and the C and C++ front ends, are in
315 files @file{doc/*.texi}.  Other front ends have their own manuals in
316 files @file{@var{language}/*.texi}.  Common files
317 @file{doc/include/*.texi} are provided which may be included in
318 multiple manuals; the following files are in @file{doc/include}:
320 @table @file
321 @item fdl.texi
322 The GNU Free Documentation License.
323 @item funding.texi
324 The section ``Funding Free Software''.
325 @item gcc-common.texi
326 Common definitions for manuals.
327 @item gpl.texi
328 The GNU General Public License.
329 @item texinfo.tex
330 A copy of @file{texinfo.tex} known to work with the GCC manuals.
331 @end table
333 DVI formatted manuals are generated by @samp{make dvi}, which uses
334 @command{texi2dvi} (via the Makefile macro @code{$(TEXI2DVI)}).  Info
335 manuals are generated by @samp{make info} (which is run as part of
336 a bootstrap); this generates the manuals in the source directory,
337 using @command{makeinfo} via the Makefile macro @code{$(MAKEINFO)},
338 and they are included in release distributions.
340 Manuals are also provided on the GCC web site, in both HTML and
341 PostScript forms.  This is done via the script
342 @file{maintainer-scripts/update_web_docs}.  Each manual to be
343 provided online must be listed in the definition of @code{MANUALS} in
344 that file; a file @file{@var{name}.texi} must only appear once in the
345 source tree, and the output manual must have the same name as the
346 source file.  (However, other Texinfo files, included in manuals but
347 not themselves the root files of manuals, may have names that appear
348 more than once in the source tree.)  The manual file
349 @file{@var{name}.texi} should only include other files in its own
350 directory or in @file{doc/include}.  HTML manuals will be generated by
351 @samp{makeinfo --html} and PostScript manuals by @command{texi2dvi}
352 and @command{dvips}.  All Texinfo files that are parts of manuals must
353 be checked into CVS, even if they are generated files, for the
354 generation of online manuals to work.
356 The installation manual, @file{doc/install.texi}, is also provided on
357 the GCC web site.  The HTML version is generated by the script
358 @file{doc/install.texi2html}.
360 @node Man Page Generation
361 @subsubsection Man Page Generation
363 Because of user demand, in addition to full Texinfo manuals, man pages
364 are provided which contain extracts from those manuals.  These man
365 pages are generated from the Texinfo manuals using
366 @file{contrib/texi2pod.pl} and @command{pod2man}.  (The man page for
367 @command{g++}, @file{cp/g++.1}, just contains a @samp{.so} reference
368 to @file{gcc.1}, but all the other man pages are generated from
369 Texinfo manuals.)
371 Because many systems may not have the necessary tools installed to
372 generate the man pages, they are only generated if the
373 @file{configure} script detects that recent enough tools are
374 installed, and the Makefiles allow generating man pages to fail
375 without aborting the build.  Man pages are also included in release
376 distributions.  They are generated in the source directory.
378 Magic comments in Texinfo files starting @samp{@@c man} control what
379 parts of a Texinfo file go into a man page.  Only a subset of Texinfo
380 is supported by @file{texi2pod.pl}, and it may be necessary to add
381 support for more Texinfo features to this script when generating new
382 man pages.  To improve the man page output, some special Texinfo
383 macros are provided in @file{doc/include/gcc-common.texi} which
384 @file{texi2pod.pl} understands:
386 @table @code
387 @item @@gcctabopt
388 Use in the form @samp{@@table @@gcctabopt} for tables of options,
389 where for printed output the effect of @samp{@@code} is better than
390 that of @samp{@@option} but for man page output a different effect is
391 wanted.
392 @item @@gccoptlist
393 Use for summary lists of options in manuals.
394 @item @@gol
395 Use at the end of each line inside @samp{@@gccoptlist}.  This is
396 necessary to avoid problems with differences in how the
397 @samp{@@gccoptlist} macro is handled by different Texinfo formatters.
398 @end table
400 FIXME: describe the @file{texi2pod.pl} input language and magic
401 comments in more detail.
403 @node Miscellaneous Docs
404 @subsubsection Miscellaneous Documentation
406 In addition to the formal documentation that is installed by GCC,
407 there are several other text files with miscellaneous documentation:
409 @table @file
410 @item ABOUT-GCC-NLS
411 Notes on GCC's Native Language Support.  FIXME: this should be part of
412 this manual rather than a separate file.
413 @item ABOUT-NLS
414 Notes on the Free Translation Project.
415 @item COPYING
416 The GNU General Public License.
417 @item COPYING.LIB
418 The GNU Lesser General Public License.
419 @item *ChangeLog*
420 @itemx */ChangeLog*
421 Change log files for various parts of GCC@.
422 @item LANGUAGES
423 Details of a few changes to the GCC front-end interface.  FIXME: the
424 information in this file should be part of general documentation of
425 the front-end interface in this manual.
426 @item ONEWS
427 Information about new features in old versions of GCC@.  (For recent
428 versions, the information is on the GCC web site.)
429 @item README.Portability
430 Information about portability issues when writing code in GCC@.  FIXME:
431 why isn't this part of this manual or of the GCC Coding Conventions?
432 @item SERVICE
433 A pointer to the GNU Service Directory.
434 @end table
436 FIXME: document such files in subdirectories, at least @file{config},
437 @file{cp}, @file{objc}, @file{testsuite}.
439 @node Front End
440 @subsection Anatomy of a Language Front End
442 A front end for a language in GCC has the following parts:
444 @itemize @bullet
445 @item
446 A directory @file{@var{language}} under @file{gcc} containing source
447 files for that front end.  @xref{Front End Directory, , The Front End
448 @file{@var{language}} Directory}, for details.
449 @item
450 A mention of the language in the list of supported languages in
451 @file{gcc/doc/install.texi}.
452 @item
453 Details of contributors to that front end in
454 @file{gcc/doc/contrib.texi}.  If the details are in that front end's
455 own manual then there should be a link to that manual's list in
456 @file{contrib.texi}.
457 @item
458 Information about support for that language in
459 @file{gcc/doc/frontends.texi}.
460 @item
461 Information about standards for that language, and the front end's
462 support for them, in @file{gcc/doc/standards.texi}.  This may be a
463 link to such information in the front end's own manual.
464 @item
465 Details of source file suffixes for that language and @option{-x
466 @var{lang}} options supported, in @file{gcc/doc/invoke.texi}.
467 @item
468 Entries in @code{default_compilers} in @file{gcc.c} for source file
469 suffixes for that language.
470 @item
471 Preferably test suites, which may be under @file{gcc/testsuite} or
472 runtime library directories.  FIXME: document somewhere how to write
473 test suite harnesses.
474 @item
475 Probably a runtime library for the language, outside the @file{gcc}
476 directory.  FIXME: document this further.
477 @item
478 Details of the directories of any runtime libraries in
479 @file{gcc/doc/sourcebuild.texi}.
480 @end itemize
482 If the front end is added to the official GCC CVS repository, the
483 following are also necessary:
485 @itemize @bullet
486 @item
487 At least one Bugzilla component for bugs in that front end and runtime
488 libraries.  This category needs to be mentioned in
489 @file{gcc/gccbug.in}, as well as being added to the Bugzilla database.
490 @item
491 Normally, one or more maintainers of that front end listed in
492 @file{MAINTAINERS}.
493 @item
494 Mentions on the GCC web site in @file{index.html} and
495 @file{frontends.html}, with any relevant links on
496 @file{readings.html}.  (Front ends that are not an official part of
497 GCC may also be listed on @file{frontends.html}, with relevant links.)
498 @item
499 A news item on @file{index.html}, and possibly an announcement on the
500 @email{gcc-announce@@gcc.gnu.org} mailing list.
501 @item
502 The front end's manuals should be mentioned in
503 @file{maintainer-scripts/update_web_docs} (@pxref{Texinfo Manuals})
504 and the online manuals should be linked to from
505 @file{onlinedocs/index.html}.
506 @item
507 Any old releases or CVS repositories of the front end, before its
508 inclusion in GCC, should be made available on the GCC FTP site
509 @uref{ftp://gcc.gnu.org/pub/gcc/old-releases/}.
510 @item
511 The release and snapshot script @file{maintainer-scripts/gcc_release}
512 should be updated to generate appropriate tarballs for this front end.
513 The associated @file{maintainer-scripts/snapshot-README} and
514 @file{maintainer-scripts/snapshot-index.html} files should be updated
515 to list the tarballs and diffs for this front end.
516 @item
517 If this front end includes its own version files that include the
518 current date, @file{maintainer-scripts/update_version} should be
519 updated accordingly.
520 @item
521 @file{CVSROOT/modules} in the GCC CVS repository should be updated.
522 @end itemize
524 @menu
525 * Front End Directory::  The front end @file{@var{language}} directory.
526 * Front End Config::     The front end @file{config-lang.in} file.
527 @end menu
529 @node Front End Directory
530 @subsubsection The Front End @file{@var{language}} Directory
532 A front end @file{@var{language}} directory contains the source files
533 of that front end (but not of any runtime libraries, which should be
534 outside the @file{gcc} directory).  This includes documentation, and
535 possibly some subsidiary programs build alongside the front end.
536 Certain files are special and other parts of the compiler depend on
537 their names:
539 @table @file
540 @item config-lang.in
541 This file is required in all language subdirectories.  @xref{Front End
542 Config, , The Front End @file{config-lang.in} File}, for details of
543 its contents
544 @item Make-lang.in
545 This file is required in all language subdirectories.  It contains
546 targets @code{@var{lang}.@var{hook}} (where @code{@var{lang}} is the
547 setting of @code{language} in @file{config-lang.in}) for the following
548 values of @code{@var{hook}}, and any other Makefile rules required to
549 build those targets (which may if necessary use other Makefiles
550 specified in @code{outputs} in @file{config-lang.in}, although this is
551 deprecated).  Some hooks are defined by using a double-colon rule for
552 @code{@var{hook}}, rather than by using a target of form
553 @code{@var{lang}.@var{hook}}.  These hooks are called ``double-colon
554 hooks'' below.  It also adds any testsuite targets that can use the
555 standard rule in @file{gcc/Makefile.in} to the variable
556 @code{lang_checks}.
558 @table @code
559 @item all.build
560 @itemx all.cross
561 @itemx start.encap
562 @itemx rest.encap
563 FIXME: exactly what goes in each of these targets?
564 @item tags
565 Build an @command{etags} @file{TAGS} file in the language subdirectory
566 in the source tree.
567 @item info
568 Build info documentation for the front end, in the build directory.
569 This target is only called by @samp{make bootstrap} if a suitable
570 version of @command{makeinfo} is available, so does not need to check
571 for this, and should fail if an error occurs.
572 @item dvi
573 Build DVI documentation for the front end, in the build directory.
574 This should be done using @code{$(TEXI2DVI)}, with appropriate
575 @option{-I} arguments pointing to directories of included files.
576 This hook is a double-colon hook.
577 @item man
578 Build generated man pages for the front end from Texinfo manuals
579 (@pxref{Man Page Generation}), in the build directory.  This target
580 is only called if the necessary tools are available, but should ignore
581 errors so as not to stop the build if errors occur; man pages are
582 optional and the tools involved may be installed in a broken way.
583 @item install-normal
584 FIXME: what is this target for?
585 @item install-common
586 Install everything that is part of the front end, apart from the
587 compiler executables listed in @code{compilers} in
588 @file{config-lang.in}.
589 @item install-info
590 Install info documentation for the front end, if it is present in the
591 source directory.  This target should have dependencies on info files
592 that should be installed.  This hook is a double-colon hook.
593 @item install-man
594 Install man pages for the front end.  This target should ignore
595 errors.
596 @item srcextra
597 Copies its dependencies into the source directory.  This generally should
598 be used for generated files such as @file{gcc/c-parse.c} which are not
599 present in CVS, but should be included in any release tarballs.  This
600 target will be executed during a bootstrap if
601 @samp{--enable-generated-files-in-srcdir} was specified as a
602 @file{configure} option.
603 @item srcinfo
604 @itemx srcman
605 Copies its dependencies into the source directory.  These targets will be
606 executed during a bootstrap if @samp{--enable-generated-files-in-srcdir}
607 was specified as a @file{configure} option.
608 @item uninstall
609 Uninstall files installed by installing the compiler.  This is
610 currently documented not to be supported, so the hook need not do
611 anything.
612 @item mostlyclean
613 @itemx clean
614 @itemx distclean
615 @itemx maintainer-clean
616 The language parts of the standard GNU
617 @samp{*clean} targets. @xref{Standard Targets, , Standard Targets for
618 Users, standards, GNU Coding Standards}, for details of the standard
619 targets.  For GCC, @code{maintainer-clean} should delete
620 all generated files in the source directory that are not checked into
621 CVS, but should not delete anything checked into CVS@.
622 @item stage1
623 @itemx stage2
624 @itemx stage3
625 @itemx stage4
626 @itemx stageprofile
627 @itemx stagefeedback
628 Move to the stage directory files not included in @code{stagestuff} in
629 @file{config-lang.in} or otherwise moved by the main @file{Makefile}.
630 @end table
632 @item lang.opt
633 This file registers the set of switches that the front end accepts on
634 the command line, and their --help text.  The file format is
635 documented in the file @file{c.opt}.  These files are processed by the
636 script @file{opts.sh}.
637 @item lang-specs.h
638 This file provides entries for @code{default_compilers} in
639 @file{gcc.c} which override the default of giving an error that a
640 compiler for that language is not installed.
641 @item @var{language}-tree.def
642 This file, which need not exist, defines any language-specific tree
643 codes.
644 @end table
646 @node Front End Config
647 @subsubsection The Front End @file{config-lang.in} File
649 Each language subdirectory contains a @file{config-lang.in} file.  In
650 addition the main directory contains @file{c-config-lang.in}, which
651 contains limited information for the C language.  This file is a shell
652 script that may define some variables describing the language:
654 @table @code
655 @item language
656 This definition must be present, and gives the name of the language
657 for some purposes such as arguments to @option{--enable-languages}.
658 @item lang_requires
659 If defined, this variable lists (space-separated) language front ends
660 other than C that this front end requires to be enabled (with the
661 names given being their @code{language} settings).  For example, the
662 Java front end depends on the C++ front end, so sets
663 @samp{lang_requires=c++}.
664 @item target_libs
665 If defined, this variable lists (space-separated) targets in the top
666 level @file{Makefile} to build the runtime libraries for this
667 language, such as @code{target-libobjc}.
668 @item lang_dirs
669 If defined, this variable lists (space-separated) top level
670 directories (parallel to @file{gcc}), apart from the runtime libraries,
671 that should not be configured if this front end is not built.
672 @item build_by_default
673 If defined to @samp{no}, this language front end is not built unless
674 enabled in a @option{--enable-languages} argument.  Otherwise, front
675 ends are built by default, subject to any special logic in
676 @file{configure.ac} (as is present to disable the Ada front end if the
677 Ada compiler is not already installed).
678 @item boot_language
679 If defined to @samp{yes}, this front end is built in stage 1 of the
680 bootstrap.  This is only relevant to front ends written in their own
681 languages.
682 @item compilers
683 If defined, a space-separated list of compiler executables that will
684 be run by the driver.  The names here will each end
685 with @samp{\$(exeext)}.
686 @item stagestuff
687 If defined, a space-separated list of files that should be moved to
688 the @file{stage@var{n}} directories in each stage of bootstrap.
689 @item outputs
690 If defined, a space-separated list of files that should be generated
691 by @file{configure} substituting values in them.  This mechanism can
692 be used to create a file @file{@var{language}/Makefile} from
693 @file{@var{language}/Makefile.in}, but this is deprecated, building
694 everything from the single @file{gcc/Makefile} is preferred.
695 @item gtfiles
696 If defined, a space-separated list of files that should be scanned by
697 gengtype.c to generate the garbage collection tables and routines for
698 this language.  This excludes the files that are common to all front
699 ends. @xref{Type Information}.
701 @end table
703 @node Back End
704 @subsection Anatomy of a Target Back End
706 A back end for a target architecture in GCC has the following parts:
708 @itemize @bullet
709 @item
710 A directory @file{@var{machine}} under @file{gcc/config}, containing a
711 machine description @file{@var{machine}.md} file (@pxref{Machine Desc,
712 , Machine Descriptions}), header files @file{@var{machine}.h} and
713 @file{@var{machine}-protos.h} and a source file @file{@var{machine}.c}
714 (@pxref{Target Macros, , Target Description Macros and Functions}),
715 possibly a target Makefile fragment @file{t-@var{machine}}
716 (@pxref{Target Fragment, , The Target Makefile Fragment}), and maybe
717 some other files.  The names of these files may be changed from the
718 defaults given by explicit specifications in @file{config.gcc}.
719 @item
720 If necessary, a file @file{@var{machine}-modes.def} in the
721 @file{@var{machine}} directory, containing additional machine modes to
722 represent condition codes.  @xref{Condition Code}, for further details.
723 @item
724 Entries in @file{config.gcc} (@pxref{System Config, , The
725 @file{config.gcc} File}) for the systems with this target
726 architecture.
727 @item
728 Documentation in @file{gcc/doc/invoke.texi} for any command-line
729 options supported by this target (@pxref{Run-time Target, , Run-time
730 Target Specification}).  This means both entries in the summary table
731 of options and details of the individual options.
732 @item
733 Documentation in @file{gcc/doc/extend.texi} for any target-specific
734 attributes supported (@pxref{Target Attributes, , Defining
735 target-specific uses of @code{__attribute__}}), including where the
736 same attribute is already supported on some targets, which are
737 enumerated in the manual.
738 @item
739 Documentation in @file{gcc/doc/extend.texi} for any target-specific
740 pragmas supported.
741 @item
742 Documentation in @file{gcc/doc/extend.texi} of any target-specific
743 built-in functions supported.
744 @item
745 Documentation in @file{gcc/doc/md.texi} of any target-specific
746 constraint letters (@pxref{Machine Constraints, , Constraints for
747 Particular Machines}).
748 @item
749 A note in @file{gcc/doc/contrib.texi} under the person or people who
750 contributed the target support.
751 @item
752 Entries in @file{gcc/doc/install.texi} for all target triplets
753 supported with this target architecture, giving details of any special
754 notes about installation for this target, or saying that there are no
755 special notes if there are none.
756 @item
757 Possibly other support outside the @file{gcc} directory for runtime
758 libraries.  FIXME: reference docs for this.  The libstdc++ porting
759 manual needs to be installed as info for this to work, or to be a
760 chapter of this manual.
761 @end itemize
763 If the back end is added to the official GCC CVS repository, the
764 following are also necessary:
766 @itemize @bullet
767 @item
768 An entry for the target architecture in @file{readings.html} on the
769 GCC web site, with any relevant links.
770 @item
771 Details of the properties of the back end and target architecture in
772 @file{backends.html} on the GCC web site.
773 @item
774 A news item about the contribution of support for that target
775 architecture, in @file{index.html} on the GCC web site.
776 @item
777 Normally, one or more maintainers of that target listed in
778 @file{MAINTAINERS}.  Some existing architectures may be unmaintained,
779 but it would be unusual to add support for a target that does not have
780 a maintainer when support is added.
781 @end itemize
783 @node Test Suites
784 @section Test Suites
786 GCC contains several test suites to help maintain compiler quality.
787 Most of the runtime libraries and language front ends in GCC have test
788 suites.  Currently only the C language test suites are documented
789 here; FIXME: document the others.
791 @menu
792 * Test Idioms::     Idioms used in test suite code.
793 * Ada Tests::       The Ada language test suites.
794 * C Tests::         The C language test suites.
795 * libgcj Tests::    The Java library test suites.
796 * gcov Testing::    Support for testing gcov.
797 * profopt Testing:: Support for testing profile-directed optimizations.
798 * compat Testing::  Support for testing binary compatibility.
799 @end menu
801 @node Test Idioms
802 @subsection Idioms Used in Test Suite Code
804 In general C testcases have a trailing @file{-@var{n}.c}, starting
805 with @file{-1.c}, in case other testcases with similar names are added
806 later.  If the test is a test of some well-defined feature, it should
807 have a name referring to that feature such as
808 @file{@var{feature}-1.c}.  If it does not test a well-defined feature
809 but just happens to exercise a bug somewhere in the compiler, and a
810 bug report has been filed for this bug in the GCC bug database,
811 @file{pr@var{bug-number}-1.c} is the appropriate form of name.
812 Otherwise (for miscellaneous bugs not filed in the GCC bug database),
813 and previously more generally, test cases are named after the date on
814 which they were added.  This allows people to tell at a glance whether
815 a test failure is because of a recently found bug that has not yet
816 been fixed, or whether it may be a regression, but does not give any
817 other information about the bug or where discussion of it may be
818 found.  Some other language testsuites follow similar conventions.
820 Test cases should use @code{abort ()} to indicate failure and
821 @code{exit (0)} for success; on some targets these may be redefined to
822 indicate failure and success in other ways.
824 In the @file{gcc.dg} test suite, it is often necessary to test that an
825 error is indeed a hard error and not just a warning---for example,
826 where it is a constraint violation in the C standard, which must
827 become an error with @option{-pedantic-errors}.  The following idiom,
828 where the first line shown is line @var{line} of the file and the line
829 that generates the error, is used for this:
831 @smallexample
832 /* @{ dg-bogus "warning" "warning in place of error" @} */
833 /* @{ dg-error "@var{regexp}" "@var{message}" @{ target *-*-* @} @var{line} @} */
834 @end smallexample
836 It may be necessary to check that an expression is an integer constant
837 expression and has a certain value.  To check that @code{@var{E}} has
838 value @code{@var{V}}, an idiom similar to the following is used:
840 @smallexample
841 char x[((E) == (V) ? 1 : -1)];
842 @end smallexample
844 In @file{gcc.dg} tests, @code{__typeof__} is sometimes used to make
845 assertions about the types of expressions.  See, for example,
846 @file{gcc.dg/c99-condexpr-1.c}.  The more subtle uses depend on the
847 exact rules for the types of conditional expressions in the C
848 standard; see, for example, @file{gcc.dg/c99-intconst-1.c}.
850 It is useful to be able to test that optimizations are being made
851 properly.  This cannot be done in all cases, but it can be done where
852 the optimization will lead to code being optimized away (for example,
853 where flow analysis or alias analysis should show that certain code
854 cannot be called) or to functions not being called because they have
855 been expanded as built-in functions.  Such tests go in
856 @file{gcc.c-torture/execute}.  Where code should be optimized away, a
857 call to a nonexistent function such as @code{link_failure ()} may be
858 inserted; a definition
860 @smallexample
861 #ifndef __OPTIMIZE__
862 void
863 link_failure (void)
865   abort ();
867 #endif
868 @end smallexample
870 @noindent
871 will also be needed so that linking still succeeds when the test is
872 run without optimization.  When all calls to a built-in function
873 should have been optimized and no calls to the non-built-in version of
874 the function should remain, that function may be defined as
875 @code{static} to call @code{abort ()} (although redeclaring a function
876 as static may not work on all targets).
878 All testcases must be portable.  Target-specific testcases must have
879 appropriate code to avoid causing failures on unsupported systems;
880 unfortunately, the mechanisms for this differ by directory.
882 FIXME: discuss non-C test suites here.
884 @node Ada Tests
885 @subsection Ada Language Test Suites
887 The Ada test suite includes executable tests from the ACATS 2.5 test
888 suite, publicly available at @uref{http://www.adaic.org/compilers/acats/2.5}
890 These tests are integrated in the GCC test suite in the
891 @file{gcc/testsuite/ada/acats} directory, and
892 enabled automatically when running @code{make check}, assuming
893 the Ada language has been enabled when configuring GCC.
895 You can also run the Ada test suite independently, using
896 @code{make check-ada}, or run a subset of the tests by specifying which
897 chapter to run, e.g:
899 @smallexample
900 $ make check-ada CHAPTERS="c3 c9"
901 @end smallexample
903 The tests are organized by directory, each directory corresponding to
904 a chapter of the Ada Reference Manual. So for example, c9 corresponds
905 to chapter 9, which deals with tasking features of the language.
907 There is also an extra chapter called @file{gcc} containing a template for
908 creating new executable tests.
910 The tests are run using two 'sh' scripts: run_acats and run_all.sh
911 To run the tests using a simulator or a cross target, see the small
912 customization section at the top of run_all.sh
914 These tests are run using the build tree: they can be run without doing
915 a @code{make install}.
917 @node C Tests
918 @subsection C Language Test Suites
920 GCC contains the following C language test suites, in the
921 @file{gcc/testsuite} directory:
923 @table @file
924 @item gcc.dg
925 This contains tests of particular features of the C compiler, using the
926 more modern @samp{dg} harness.  Correctness tests for various compiler
927 features should go here if possible.
929 Magic comments determine whether the file
930 is preprocessed, compiled, linked or run.  In these tests, error and warning
931 message texts are compared against expected texts or regular expressions
932 given in comments.  These tests are run with the options @samp{-ansi -pedantic}
933 unless other options are given in the test.  Except as noted below they
934 are not run with multiple optimization options.
935 @item gcc.dg/compat
936 This subdirectory contains tests for binary compatibility using
937 @file{compat.exp}, which in turn uses the language-independent support
938 (@pxref{compat Testing, , Support for testing binary compatibility}).
939 @item gcc.dg/cpp
940 This subdirectory contains tests of the preprocessor.
941 @item gcc.dg/debug
942 This subdirectory contains tests for debug formats.  Tests in this
943 subdirectory are run for each debug format that the compiler supports.
944 @item gcc.dg/format
945 This subdirectory contains tests of the @option{-Wformat} format
946 checking.  Tests in this directory are run with and without
947 @option{-DWIDE}.
948 @item gcc.dg/noncompile
949 This subdirectory contains tests of code that should not compile and
950 does not need any special compilation options.  They are run with
951 multiple optimization options, since sometimes invalid code crashes
952 the compiler with optimization.
953 @item gcc.dg/special
954 FIXME: describe this.
956 @item gcc.c-torture
957 This contains particular code fragments which have historically broken easily.
958 These tests are run with multiple optimization options, so tests for features
959 which only break at some optimization levels belong here.  This also contains
960 tests to check that certain optimizations occur.  It might be worthwhile to
961 separate the correctness tests cleanly from the code quality tests, but
962 it hasn't been done yet.
964 @item gcc.c-torture/compat
965 FIXME: describe this.
967 This directory should probably not be used for new tests.
968 @item gcc.c-torture/compile
969 This test suite contains test cases that should compile, but do not
970 need to link or run.  These test cases are compiled with several
971 different combinations of optimization options.  All warnings are
972 disabled for these test cases, so this directory is not suitable if
973 you wish to test for the presence or absence of compiler warnings.
974 While special options can be set, and tests disabled on specific
975 platforms, by the use of @file{.x} files, mostly these test cases
976 should not contain platform dependencies.  FIXME: discuss how defines
977 such as @code{NO_LABEL_VALUES} and @code{STACK_SIZE} are used.
978 @item gcc.c-torture/execute
979 This test suite contains test cases that should compile, link and run;
980 otherwise the same comments as for @file{gcc.c-torture/compile} apply.
981 @item gcc.c-torture/execute/ieee
982 This contains tests which are specific to IEEE floating point.
983 @item gcc.c-torture/unsorted
984 FIXME: describe this.
986 This directory should probably not be used for new tests.
987 @item gcc.c-torture/misc-tests
988 This directory contains C tests that require special handling.  Some
989 of these tests have individual expect files, and others share
990 special-purpose expect files:
992 @table @file
993 @item @code{bprob*.c}
994 Test @option{-fbranch-probabilities} using @file{bprob.exp}, which
995 in turn uses the generic, language-independent framework
996 (@pxref{profopt Testing, , Support for testing profile-directed
997 optimizations}).
999 @item @code{dg-*.c}
1000 Test the testsuite itself using @file{dg-test.exp}.
1002 @item @code{gcov*.c}
1003 Test @command{gcov} output using @file{gcov.exp}, which in turn uses the
1004 language-independent support (@pxref{gcov Testing, , Support for testing gcov}).
1006 @item @code{i386-pf-*.c}
1007 Test i386-specific support for data prefetch using @file{i386-prefetch.exp}.
1008 @end table
1010 @end table
1012 FIXME: merge in @file{testsuite/README.gcc} and discuss the format of
1013 test cases and magic comments more.
1015 @node libgcj Tests
1016 @subsection The Java library test suites.
1018 Runtime tests are executed via @samp{make check} in the
1019 @file{@var{target}/libjava/testsuite} directory in the build
1020 tree.  Additional runtime tests can be checked into this testsuite.
1022 Regression testing of the core packages in libgcj is also covered by the
1023 Mauve test suite.  The @uref{http://sources.redhat.com/mauve/,,Mauve Project}
1024 develops tests for the Java Class Libraries.  These tests are run as part
1025 of libgcj testing by placing the Mauve tree within the libjava testsuite
1026 sources at @file{libjava/testsuite/libjava.mauve/mauve}, or by specifying
1027 the location of that tree when invoking @samp{make}, as in
1028 @samp{make MAUVEDIR=~/mauve check}.
1030 To detect regressions, a mechanism in @file{mauve.exp} compares the
1031 failures for a test run against the list of expected failures in
1032 @file{libjava/testsuite/libjava.mauve/xfails} from the source hierarchy.
1033 Update this file when adding new failing tests to Mauve, or when fixing
1034 bugs in libgcj that had caused Mauve test failures.
1036 The @uref{http://oss.software.ibm.com/developerworks/opensource/jacks/,,
1037 Jacks} project provides a test suite for Java compilers that can be used
1038 to test changes that affect the GCJ front end.  This test suite is run as
1039 part of Java testing by placing the Jacks tree within the the libjava
1040 testsuite sources at @file{libjava/testsuite/libjava.jacks/jacks}.
1042 We encourage developers to contribute test cases to Mauve and Jacks.
1044 @node gcov Testing
1045 @subsection Support for testing @command{gcov}
1047 Language-independent support for testing @command{gcov}, and for checking
1048 that branch profiling produces expected values, is provided by the
1049 expect file @file{gcov.exp}.  @command{gcov} tests also rely on procedures
1050 in @file{gcc.dg.exp} to compile and run the test program.  A typical
1051 @command{gcov} test contains the following DejaGNU commands within comments:
1053 @smallexample
1054 @{ dg-options "-fprofile-arcs -ftest-coverage" @}
1055 @{ dg-do run @{ target native @} @}
1056 @{ dg-final @{ run-gcov sourcefile @} @}
1057 @end smallexample
1059 Checks of @command{gcov} output can include line counts, branch percentages,
1060 and call return percentages.  All of these checks are requested via
1061 commands that appear in comments in the test's source file.
1062 Commands to check line counts are processed by default.
1063 Commands to check branch percentages and call return percentages are
1064 processed if the @command{run-gcov} command has arguments @code{branches}
1065 or @code{calls}, respectively.  For example, the following specifies
1066 checking both, as well as passing @code{-b} to @command{gcov}:
1068 @smallexample
1069 @{ dg-final @{ run-gcov branches calls @{ -b sourcefile @} @} @}
1070 @end smallexample
1072 A line count command appears within a comment on the source line
1073 that is expected to get the specified count and has the form
1074 @code{count(@var{cnt})}.  A test should only check line counts for
1075 lines that will get the same count for any architecture.
1077 Commands to check branch percentages (@code{branch}) and call
1078 return percentages (@code{returns}) are very similar to each other.
1079 A beginning command appears on or before the first of a range of
1080 lines that will report the percentage, and the ending command
1081 follows that range of lines.  The beginning command can include a
1082 list of percentages, all of which are expected to be found within
1083 the range.  A range is terminated by the next command of the same
1084 kind.  A command @code{branch(end)} or @code{returns(end)} marks
1085 the end of a range without starting a new one.  For example:
1087 @smallexample
1088 if (i > 10 && j > i && j < 20)  /* branch(27 50 75) */
1089                                 /* branch(end) */
1090   foo (i, j);
1091 @end smallexample
1093 For a call return percentage, the value specified is the
1094 percentage of calls reported to return.  For a branch percentage,
1095 the value is either the expected percentage or 100 minus that
1096 value, since the direction of a branch can differ depending on the
1097 target or the optimization level.
1099 Not all branches and calls need to be checked.  A test should not
1100 check for branches that might be optimized away or replaced with
1101 predicated instructions.  Don't check for calls inserted by the
1102 compiler or ones that might be inlined or optimized away.
1104 A single test can check for combinations of line counts, branch
1105 percentages, and call return percentages.  The command to check a
1106 line count must appear on the line that will report that count, but
1107 commands to check branch percentages and call return percentages can
1108 bracket the lines that report them.
1110 @node profopt Testing
1111 @subsection Support for testing profile-directed optimizations
1113 The file @file{profopt.exp} provides language-independent support for
1114 checking correct execution of a test built with profile-directed
1115 optimization.  This testing requires that a test program be built and
1116 executed twice.  The first time it is compiled to generate profile
1117 data, and the second time it is compiled to use the data that was
1118 generated during the first execution.  The second execution is to
1119 verify that the test produces the expected results.
1121 To check that the optimization actually generated better code, a
1122 test can be built and run a third time with normal optimizations to
1123 verify that the performance is better with the profile-directed
1124 optimizations.  @file{profopt.exp} has the beginnings of this kind
1125 of support.
1127 @file{profopt.exp} provides generic support for profile-directed
1128 optimizations.  Each set of tests that uses it provides information
1129 about a specific optimization:
1131 @table @code
1132 @item tool
1133 tool being tested, e.g., @command{gcc}
1135 @item profile_option
1136 options used to generate profile data
1138 @item feedback_option
1139 options used to optimize using that profile data
1141 @item prof_ext
1142 suffix of profile data files
1144 @item PROFOPT_OPTIONS
1145 list of options with which to run each test, similar to the lists for
1146 torture tests
1147 @end table
1149 @node compat Testing
1150 @subsection Support for testing binary compatibility
1152 The file @file{compat.exp} provides language-independent support for
1153 binary compatibility testing.  It supports testing interoperability
1154 of two compilers that follow the same ABI, or of multiple sets of
1155 compiler options that should not affect binary compatibility.
1156 It is intended to be used for test suites that complement ABI test
1157 suites.
1159 A test supported by this framework has three parts, each in a
1160 separate source file: a main program and two pieces that interact
1161 with each other to split up the functionality being tested.
1163 @table @file
1164 @item @var{testname}_main.@var{suffix}
1165 Contains the main program, which calls a function in file
1166 @file{@var{testname}_x.@var{suffix}}.
1168 @item @var{testname}_x.@var{suffix}
1169 Contains at least one call to a function in
1170 @file{@var{testname}_y.@var{suffix}}.
1172 @item @var{testname}_y.@var{suffix}
1173 Shares data with, or gets arguments from,
1174 @file{@var{testname}_x.@var{suffix}}.
1175 @end table
1177 Within each test, the main program and one functional piece are
1178 compiled by the GCC under test.  The other piece can be compiled by
1179 an alternate compiler.  If no alternate compiler is specified,
1180 then all three source files are all compiled by the GCC under test.
1181 It's also possible to specify a pair of lists of compiler options,
1182 one list for each compiler, so that each test will be compiled with
1183 each pair of options.
1185 @file{compat.exp} defines default pairs of compiler options.
1186 These can be overridden by defining the environment variable
1187 @env{COMPAT_OPTIONS} as:
1189 @smallexample
1190 COMPAT_OPTIONS="[list [list @{@var{tst1}@} @{@var{alt1}@}]
1191   ...[list @{@var{tstn}@} @{@var{altn}@}]]"
1192 @end smallexample
1194 where @var{tsti} and @var{alti} are lists of options, with @var{tsti}
1195 used by the compiler under test and @var{alti} used by the alternate
1196 compiler.  For example, with
1197 @code{[list [list @{-g -O0@} @{-O3@}] [list @{-fpic@} @{-fPIC -O2@}]]},
1198 the test is first built with @code{-g -O0} by the compiler under
1199 test and with @code{-O3} by the alternate compiler.  The test is
1200 built a second time using @code{-fpic} by the compiler under test
1201 and @code{-fPIC -O2} by the alternate compiler.
1203 An alternate compiler is specified by defining an environment
1204 variable; for C++ define @env{ALT_CXX_UNDER_TEST} to be the full
1205 pathname of an installed compiler.  That will be written to the
1206 @file{site.exp} file used by DejaGNU.  The default is to build each
1207 test with the compiler under test using the first of each pair of
1208 compiler options from @env{COMPAT_OPTIONS}.  When
1209 @env{ALT_CXX_UNDER_TEST} is @code{same}, each test is built using
1210 the compiler under test but with combinations of the options from
1211 @env{COMPAT_OPTIONS}.
1213 To run only the C++ compatibility suite using the compiler under test
1214 and another version of GCC using specific compiler options, do the
1215 following from @file{@var{objdir}/gcc}:
1217 @smallexample
1218 rm site.exp
1219 make -k \
1220   ALT_CXX_UNDER_TEST=$@{alt_prefix@}/bin/g++ \
1221   COMPAT_OPTIONS="lists as shown above" \
1222   check-c++ \
1223   RUNTESTFLAGS="compat.exp"
1224 @end smallexample
1226 A test that fails when the source files are compiled with different
1227 compilers, but passes when the files are compiled with the same
1228 compiler, demonstrates incompatibility of the generated code or
1229 runtime support.  A test that fails for the alternate compiler but
1230 passes for the compiler under test probably tests for a bug that was
1231 fixed in the compiler under test but is present in the alternate
1232 compiler.