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