1@c Copyright (C) 1988-2015 Free Software Foundation, Inc. 2@c This is part of the GCC manual. 3@c For copying conditions, see the file gcc.texi. 4 5@node Fragments 6@chapter Makefile Fragments 7@cindex makefile fragment 8 9When you configure GCC using the @file{configure} script, it will 10construct the file @file{Makefile} from the template file 11@file{Makefile.in}. When it does this, it can incorporate makefile 12fragments from the @file{config} directory. These are used to set 13Makefile parameters that are not amenable to being calculated by 14autoconf. The list of fragments to incorporate is set by 15@file{config.gcc} (and occasionally @file{config.build} 16and @file{config.host}); @xref{System Config}. 17 18Fragments are named either @file{t-@var{target}} or @file{x-@var{host}}, 19depending on whether they are relevant to configuring GCC to produce 20code for a particular target, or to configuring GCC to run on a 21particular host. Here @var{target} and @var{host} are mnemonics 22which usually have some relationship to the canonical system name, but 23no formal connection. 24 25If these files do not exist, it means nothing needs to be added for a 26given target or host. Most targets need a few @file{t-@var{target}} 27fragments, but needing @file{x-@var{host}} fragments is rare. 28 29@menu 30* Target Fragment:: Writing @file{t-@var{target}} files. 31* Host Fragment:: Writing @file{x-@var{host}} files. 32@end menu 33 34@node Target Fragment 35@section Target Makefile Fragments 36@cindex target makefile fragment 37@cindex @file{t-@var{target}} 38 39Target makefile fragments can set these Makefile variables. 40 41@table @code 42@findex LIBGCC2_CFLAGS 43@item LIBGCC2_CFLAGS 44Compiler flags to use when compiling @file{libgcc2.c}. 45 46@findex LIB2FUNCS_EXTRA 47@item LIB2FUNCS_EXTRA 48A list of source file names to be compiled or assembled and inserted 49into @file{libgcc.a}. 50 51@findex CRTSTUFF_T_CFLAGS 52@item CRTSTUFF_T_CFLAGS 53Special flags used when compiling @file{crtstuff.c}. 54@xref{Initialization}. 55 56@findex CRTSTUFF_T_CFLAGS_S 57@item CRTSTUFF_T_CFLAGS_S 58Special flags used when compiling @file{crtstuff.c} for shared 59linking. Used if you use @file{crtbeginS.o} and @file{crtendS.o} 60in @code{EXTRA-PARTS}. 61@xref{Initialization}. 62 63@findex MULTILIB_OPTIONS 64@item MULTILIB_OPTIONS 65For some targets, invoking GCC in different ways produces objects 66that can not be linked together. For example, for some targets GCC 67produces both big and little endian code. For these targets, you must 68arrange for multiple versions of @file{libgcc.a} to be compiled, one for 69each set of incompatible options. When GCC invokes the linker, it 70arranges to link in the right version of @file{libgcc.a}, based on 71the command line options used. 72 73The @code{MULTILIB_OPTIONS} macro lists the set of options for which 74special versions of @file{libgcc.a} must be built. Write options that 75are mutually incompatible side by side, separated by a slash. Write 76options that may be used together separated by a space. The build 77procedure will build all combinations of compatible options. 78 79For example, if you set @code{MULTILIB_OPTIONS} to @samp{m68000/m68020 80msoft-float}, @file{Makefile} will build special versions of 81@file{libgcc.a} using the following sets of options: @option{-m68000}, 82@option{-m68020}, @option{-msoft-float}, @samp{-m68000 -msoft-float}, and 83@samp{-m68020 -msoft-float}. 84 85@findex MULTILIB_DIRNAMES 86@item MULTILIB_DIRNAMES 87If @code{MULTILIB_OPTIONS} is used, this variable specifies the 88directory names that should be used to hold the various libraries. 89Write one element in @code{MULTILIB_DIRNAMES} for each element in 90@code{MULTILIB_OPTIONS}. If @code{MULTILIB_DIRNAMES} is not used, the 91default value will be @code{MULTILIB_OPTIONS}, with all slashes treated 92as spaces. 93 94@code{MULTILIB_DIRNAMES} describes the multilib directories using GCC 95conventions and is applied to directories that are part of the GCC 96installation. When multilib-enabled, the compiler will add a 97subdirectory of the form @var{prefix}/@var{multilib} before each 98directory in the search path for libraries and crt files. 99 100For example, if @code{MULTILIB_OPTIONS} is set to @samp{m68000/m68020 101msoft-float}, then the default value of @code{MULTILIB_DIRNAMES} is 102@samp{m68000 m68020 msoft-float}. You may specify a different value if 103you desire a different set of directory names. 104 105@findex MULTILIB_MATCHES 106@item MULTILIB_MATCHES 107Sometimes the same option may be written in two different ways. If an 108option is listed in @code{MULTILIB_OPTIONS}, GCC needs to know about 109any synonyms. In that case, set @code{MULTILIB_MATCHES} to a list of 110items of the form @samp{option=option} to describe all relevant 111synonyms. For example, @samp{m68000=mc68000 m68020=mc68020}. 112 113@findex MULTILIB_EXCEPTIONS 114@item MULTILIB_EXCEPTIONS 115Sometimes when there are multiple sets of @code{MULTILIB_OPTIONS} being 116specified, there are combinations that should not be built. In that 117case, set @code{MULTILIB_EXCEPTIONS} to be all of the switch exceptions 118in shell case syntax that should not be built. 119 120For example the ARM processor cannot execute both hardware floating 121point instructions and the reduced size THUMB instructions at the same 122time, so there is no need to build libraries with both of these 123options enabled. Therefore @code{MULTILIB_EXCEPTIONS} is set to: 124@smallexample 125*mthumb/*mhard-float* 126@end smallexample 127 128@findex MULTILIB_REQUIRED 129@item MULTILIB_REQUIRED 130Sometimes when there are only a few combinations are required, it would 131be a big effort to come up with a @code{MULTILIB_EXCEPTIONS} list to 132cover all undesired ones. In such a case, just listing all the required 133combinations in @code{MULTILIB_REQUIRED} would be more straightforward. 134 135The way to specify the entries in @code{MULTILIB_REQUIRED} is same with 136the way used for @code{MULTILIB_EXCEPTIONS}, only this time what are 137required will be specified. Suppose there are multiple sets of 138@code{MULTILIB_OPTIONS} and only two combinations are required, one 139for ARMv7-M and one for ARMv7-R with hard floating-point ABI and FPU, the 140@code{MULTILIB_REQUIRED} can be set to: 141@smallexample 142@code{MULTILIB_REQUIRED} = mthumb/march=armv7-m 143@code{MULTILIB_REQUIRED} += march=armv7-r/mfloat-abi=hard/mfpu=vfpv3-d16 144@end smallexample 145 146The @code{MULTILIB_REQUIRED} can be used together with 147@code{MULTILIB_EXCEPTIONS}. The option combinations generated from 148@code{MULTILIB_OPTIONS} will be filtered by @code{MULTILIB_EXCEPTIONS} 149and then by @code{MULTILIB_REQUIRED}. 150 151@findex MULTILIB_REUSE 152@item MULTILIB_REUSE 153Sometimes it is desirable to reuse one existing multilib for different 154sets of options. Such kind of reuse can minimize the number of multilib 155variants. And for some targets it is better to reuse an existing multilib 156than to fall back to default multilib when there is no corresponding multilib. 157This can be done by adding reuse rules to @code{MULTILIB_REUSE}. 158 159A reuse rule is comprised of two parts connected by equality sign. The left part 160is option set used to build multilib and the right part is option set that will 161reuse this multilib. The order of options in the left part matters and should be 162same with those specified in @code{MULTILIB_REQUIRED} or aligned with order in 163@code{MULTILIB_OPTIONS}. There is no such limitation for options in right part 164as we don't build multilib from them. But the equality sign in both parts should 165be replaced with period. 166 167The @code{MULTILIB_REUSE} is different from @code{MULTILIB_MATCHES} in that it 168sets up relations between two option sets rather than two options. Here is an 169example to demo how we reuse libraries built in Thumb mode for applications built 170in ARM mode: 171@smallexample 172@code{MULTILIB_REUSE} = mthumb/march.armv7-r=marm/march.armv7-r 173@end smallexample 174 175Before the advent of @code{MULTILIB_REUSE}, GCC select multilib by comparing command 176line options with options used to build multilib. The @code{MULTILIB_REUSE} is 177complementary to that way. Only when the original comparison matches nothing it will 178work to see if it is OK to reuse some existing multilib. 179 180@findex MULTILIB_EXTRA_OPTS 181@item MULTILIB_EXTRA_OPTS 182Sometimes it is desirable that when building multiple versions of 183@file{libgcc.a} certain options should always be passed on to the 184compiler. In that case, set @code{MULTILIB_EXTRA_OPTS} to be the list 185of options to be used for all builds. If you set this, you should 186probably set @code{CRTSTUFF_T_CFLAGS} to a dash followed by it. 187 188@findex MULTILIB_OSDIRNAMES 189@item MULTILIB_OSDIRNAMES 190If @code{MULTILIB_OPTIONS} is used, this variable specifies 191a list of subdirectory names, that are used to modify the search 192path depending on the chosen multilib. Unlike @code{MULTILIB_DIRNAMES}, 193@code{MULTILIB_OSDIRNAMES} describes the multilib directories using 194operating systems conventions, and is applied to the directories such as 195@code{lib} or those in the @env{LIBRARY_PATH} environment variable. 196The format is either the same as of 197@code{MULTILIB_DIRNAMES}, or a set of mappings. When it is the same 198as @code{MULTILIB_DIRNAMES}, it describes the multilib directories 199using operating system conventions, rather than GCC conventions. When it is a set 200of mappings of the form @var{gccdir}=@var{osdir}, the left side gives 201the GCC convention and the right gives the equivalent OS defined 202location. If the @var{osdir} part begins with a @samp{!}, 203GCC will not search in the non-multilib directory and use 204exclusively the multilib directory. Otherwise, the compiler will 205examine the search path for libraries and crt files twice; the first 206time it will add @var{multilib} to each directory in the search path, 207the second it will not. 208 209For configurations that support both multilib and multiarch, 210@code{MULTILIB_OSDIRNAMES} also encodes the multiarch name, thus 211subsuming @code{MULTIARCH_DIRNAME}. The multiarch name is appended to 212each directory name, separated by a colon (e.g. 213@samp{../lib32:i386-linux-gnu}). 214 215Each multiarch subdirectory will be searched before the corresponding OS 216multilib directory, for example @samp{/lib/i386-linux-gnu} before 217@samp{/lib/../lib32}. The multiarch name will also be used to modify the 218system header search path, as explained for @code{MULTIARCH_DIRNAME}. 219 220@findex MULTIARCH_DIRNAME 221@item MULTIARCH_DIRNAME 222This variable specifies the multiarch name for configurations that are 223multiarch-enabled but not multilibbed configurations. 224 225The multiarch name is used to augment the search path for libraries, crt 226files and system header files with additional locations. The compiler 227will add a multiarch subdirectory of the form 228@var{prefix}/@var{multiarch} before each directory in the library and 229crt search path. It will also add two directories 230@code{LOCAL_INCLUDE_DIR}/@var{multiarch} and 231@code{NATIVE_SYSTEM_HEADER_DIR}/@var{multiarch}) to the system header 232search path, respectively before @code{LOCAL_INCLUDE_DIR} and 233@code{NATIVE_SYSTEM_HEADER_DIR}. 234 235@code{MULTIARCH_DIRNAME} is not used for configurations that support 236both multilib and multiarch. In that case, multiarch names are encoded 237in @code{MULTILIB_OSDIRNAMES} instead. 238 239More documentation about multiarch can be found at 240@uref{http://wiki.debian.org/Multiarch}. 241 242@findex SPECS 243@item SPECS 244Unfortunately, setting @code{MULTILIB_EXTRA_OPTS} is not enough, since 245it does not affect the build of target libraries, at least not the 246build of the default multilib. One possible work-around is to use 247@code{DRIVER_SELF_SPECS} to bring options from the @file{specs} file 248as if they had been passed in the compiler driver command line. 249However, you don't want to be adding these options after the toolchain 250is installed, so you can instead tweak the @file{specs} file that will 251be used during the toolchain build, while you still install the 252original, built-in @file{specs}. The trick is to set @code{SPECS} to 253some other filename (say @file{specs.install}), that will then be 254created out of the built-in specs, and introduce a @file{Makefile} 255rule to generate the @file{specs} file that's going to be used at 256build time out of your @file{specs.install}. 257 258@item T_CFLAGS 259These are extra flags to pass to the C compiler. They are used both 260when building GCC, and when compiling things with the just-built GCC@. 261This variable is deprecated and should not be used. 262@end table 263 264@node Host Fragment 265@section Host Makefile Fragments 266@cindex host makefile fragment 267@cindex @file{x-@var{host}} 268 269The use of @file{x-@var{host}} fragments is discouraged. You should only 270use it for makefile dependencies. 271