1@c Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
2@c 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
3@c This is part of the GCC manual.
4@c For copying conditions, see the file gcc.texi.
5
6@node Fragments
7@chapter Makefile Fragments
8@cindex makefile fragment
9
10When you configure GCC using the @file{configure} script, it will
11construct the file @file{Makefile} from the template file
12@file{Makefile.in}.  When it does this, it can incorporate makefile
13fragments from the @file{config} directory.  These are used to set
14Makefile parameters that are not amenable to being calculated by
15autoconf.  The list of fragments to incorporate is set by
16@file{config.gcc} (and occasionally @file{config.build}
17and @file{config.host}); @xref{System Config}.
18
19Fragments are named either @file{t-@var{target}} or @file{x-@var{host}},
20depending on whether they are relevant to configuring GCC to produce
21code for a particular target, or to configuring GCC to run on a
22particular host.  Here @var{target} and @var{host} are mnemonics
23which usually have some relationship to the canonical system name, but
24no formal connection.
25
26If these files do not exist, it means nothing needs to be added for a
27given target or host.  Most targets need a few @file{t-@var{target}}
28fragments, but needing @file{x-@var{host}} fragments is rare.
29
30@menu
31* Target Fragment:: Writing @file{t-@var{target}} files.
32* Host Fragment::   Writing @file{x-@var{host}} files.
33@end menu
34
35@node Target Fragment
36@section Target Makefile Fragments
37@cindex target makefile fragment
38@cindex @file{t-@var{target}}
39
40Target makefile fragments can set these Makefile variables.
41
42@table @code
43@findex LIBGCC2_CFLAGS
44@item LIBGCC2_CFLAGS
45Compiler flags to use when compiling @file{libgcc2.c}.
46
47@findex LIB2FUNCS_EXTRA
48@item LIB2FUNCS_EXTRA
49A list of source file names to be compiled or assembled and inserted
50into @file{libgcc.a}.
51
52@findex Floating Point Emulation
53@item Floating Point Emulation
54To have GCC include software floating point libraries in @file{libgcc.a}
55define @code{FPBIT} and @code{DPBIT} along with a few rules as follows:
56@smallexample
57# We want fine grained libraries, so use the new code
58# to build the floating point emulation libraries.
59FPBIT = fp-bit.c
60DPBIT = dp-bit.c
61
62
63fp-bit.c: $(srcdir)/config/fp-bit.c
64        echo '#define FLOAT' > fp-bit.c
65        cat $(srcdir)/config/fp-bit.c >> fp-bit.c
66
67dp-bit.c: $(srcdir)/config/fp-bit.c
68        cat $(srcdir)/config/fp-bit.c > dp-bit.c
69@end smallexample
70
71You may need to provide additional #defines at the beginning of @file{fp-bit.c}
72and @file{dp-bit.c} to control target endianness and other options.
73
74
75@findex CRTSTUFF_T_CFLAGS
76@item CRTSTUFF_T_CFLAGS
77Special flags used when compiling @file{crtstuff.c}.
78@xref{Initialization}.
79
80@findex CRTSTUFF_T_CFLAGS_S
81@item CRTSTUFF_T_CFLAGS_S
82Special flags used when compiling @file{crtstuff.c} for shared
83linking.  Used if you use @file{crtbeginS.o} and @file{crtendS.o}
84in @code{EXTRA-PARTS}.
85@xref{Initialization}.
86
87@findex MULTILIB_OPTIONS
88@item MULTILIB_OPTIONS
89For some targets, invoking GCC in different ways produces objects
90that can not be linked together.  For example, for some targets GCC
91produces both big and little endian code.  For these targets, you must
92arrange for multiple versions of @file{libgcc.a} to be compiled, one for
93each set of incompatible options.  When GCC invokes the linker, it
94arranges to link in the right version of @file{libgcc.a}, based on
95the command line options used.
96
97The @code{MULTILIB_OPTIONS} macro lists the set of options for which
98special versions of @file{libgcc.a} must be built.  Write options that
99are mutually incompatible side by side, separated by a slash.  Write
100options that may be used together separated by a space.  The build
101procedure will build all combinations of compatible options.
102
103For example, if you set @code{MULTILIB_OPTIONS} to @samp{m68000/m68020
104msoft-float}, @file{Makefile} will build special versions of
105@file{libgcc.a} using the following sets of options:  @option{-m68000},
106@option{-m68020}, @option{-msoft-float}, @samp{-m68000 -msoft-float}, and
107@samp{-m68020 -msoft-float}.
108
109@findex MULTILIB_DIRNAMES
110@item MULTILIB_DIRNAMES
111If @code{MULTILIB_OPTIONS} is used, this variable specifies the
112directory names that should be used to hold the various libraries.
113Write one element in @code{MULTILIB_DIRNAMES} for each element in
114@code{MULTILIB_OPTIONS}.  If @code{MULTILIB_DIRNAMES} is not used, the
115default value will be @code{MULTILIB_OPTIONS}, with all slashes treated
116as spaces.
117
118For example, if @code{MULTILIB_OPTIONS} is set to @samp{m68000/m68020
119msoft-float}, then the default value of @code{MULTILIB_DIRNAMES} is
120@samp{m68000 m68020 msoft-float}.  You may specify a different value if
121you desire a different set of directory names.
122
123@findex MULTILIB_MATCHES
124@item MULTILIB_MATCHES
125Sometimes the same option may be written in two different ways.  If an
126option is listed in @code{MULTILIB_OPTIONS}, GCC needs to know about
127any synonyms.  In that case, set @code{MULTILIB_MATCHES} to a list of
128items of the form @samp{option=option} to describe all relevant
129synonyms.  For example, @samp{m68000=mc68000 m68020=mc68020}.
130
131@findex MULTILIB_EXCEPTIONS
132@item MULTILIB_EXCEPTIONS
133Sometimes when there are multiple sets of @code{MULTILIB_OPTIONS} being
134specified, there are combinations that should not be built.  In that
135case, set @code{MULTILIB_EXCEPTIONS} to be all of the switch exceptions
136in shell case syntax that should not be built.
137
138For example the ARM processor cannot execute both hardware floating
139point instructions and the reduced size THUMB instructions at the same
140time, so there is no need to build libraries with both of these
141options enabled.  Therefore @code{MULTILIB_EXCEPTIONS} is set to:
142@smallexample
143*mthumb/*mhard-float*
144@end smallexample
145
146@findex MULTILIB_EXTRA_OPTS
147@item MULTILIB_EXTRA_OPTS
148Sometimes it is desirable that when building multiple versions of
149@file{libgcc.a} certain options should always be passed on to the
150compiler.  In that case, set @code{MULTILIB_EXTRA_OPTS} to be the list
151of options to be used for all builds.  If you set this, you should
152probably set @code{CRTSTUFF_T_CFLAGS} to a dash followed by it.
153
154@findex NATIVE_SYSTEM_HEADER_DIR
155@item NATIVE_SYSTEM_HEADER_DIR
156If the default location for system headers is not @file{/usr/include},
157you must set this to the directory containing the headers.  This value
158should match the value of the @code{SYSTEM_INCLUDE_DIR} macro.
159
160@findex SPECS
161@item SPECS
162Unfortunately, setting @code{MULTILIB_EXTRA_OPTS} is not enough, since
163it does not affect the build of target libraries, at least not the
164build of the default multilib.  One possible work-around is to use
165@code{DRIVER_SELF_SPECS} to bring options from the @file{specs} file
166as if they had been passed in the compiler driver command line.
167However, you don't want to be adding these options after the toolchain
168is installed, so you can instead tweak the @file{specs} file that will
169be used during the toolchain build, while you still install the
170original, built-in @file{specs}.  The trick is to set @code{SPECS} to
171some other filename (say @file{specs.install}), that will then be
172created out of the built-in specs, and introduce a @file{Makefile}
173rule to generate the @file{specs} file that's going to be used at
174build time out of your @file{specs.install}.
175@end table
176
177@node Host Fragment
178@section Host Makefile Fragments
179@cindex host makefile fragment
180@cindex @file{x-@var{host}}
181
182The use of @file{x-@var{host}} fragments is discouraged.  You should do
183so only if there is no other mechanism to get the behavior desired.
184Host fragments should never forcibly override variables set by the
185configure script, as they may have been adjusted by the user.
186
187Variables provided for host fragments to set include:
188
189@table @code
190
191@item X_CFLAGS
192@itemx X_CPPFLAGS
193These are extra flags to pass to the C compiler and preprocessor,
194respectively.  They are used both when building GCC, and when compiling
195things with the just-built GCC@.
196
197@item XCFLAGS
198These are extra flags to use when building the compiler.  They are not
199used when compiling @file{libgcc.a}.  However, they @emph{are} used when
200recompiling the compiler with itself in later stages of a bootstrap.
201
202@item BOOT_LDFLAGS
203Flags to be passed to the linker when recompiling the compiler with
204itself in later stages of a bootstrap.  You might need to use this if,
205for instance, one of the front ends needs more text space than the
206linker provides by default.
207
208@item EXTRA_PROGRAMS
209A list of additional programs required to use the compiler on this host,
210which should be compiled with GCC and installed alongside the front
211ends.  If you set this variable, you must also provide rules to build
212the extra programs.
213
214@end table
215