Home | History | Annotate | Line # | Download | only in doc
      1  1.12  mrg @c Copyright (C) 1988-2022 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.10  mrg that cannot 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.3  mrg @code{MULTILIB_DIRNAMES} describes the multilib directories using GCC
     95   1.3  mrg conventions and is applied to directories that are part of the GCC
     96   1.3  mrg installation.  When multilib-enabled, the compiler will add a
     97   1.3  mrg subdirectory of the form @var{prefix}/@var{multilib} before each
     98   1.3  mrg directory in the search path for libraries and crt files.
     99   1.3  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.3  mrg @findex MULTILIB_REQUIRED
    129   1.3  mrg @item MULTILIB_REQUIRED
    130   1.3  mrg Sometimes when there are only a few combinations are required, it would
    131   1.3  mrg be a big effort to come up with a @code{MULTILIB_EXCEPTIONS} list to
    132   1.3  mrg cover all undesired ones.  In such a case, just listing all the required
    133   1.3  mrg combinations in @code{MULTILIB_REQUIRED} would be more straightforward.
    134   1.3  mrg 
    135   1.3  mrg The way to specify the entries in @code{MULTILIB_REQUIRED} is same with
    136   1.3  mrg the way used for @code{MULTILIB_EXCEPTIONS}, only this time what are
    137   1.3  mrg required will be specified.  Suppose there are multiple sets of
    138   1.3  mrg @code{MULTILIB_OPTIONS} and only two combinations are required, one
    139   1.3  mrg for ARMv7-M and one for ARMv7-R with hard floating-point ABI and FPU, the
    140   1.3  mrg @code{MULTILIB_REQUIRED} can be set to:
    141   1.3  mrg @smallexample
    142   1.3  mrg @code{MULTILIB_REQUIRED} =  mthumb/march=armv7-m
    143   1.3  mrg @code{MULTILIB_REQUIRED} += march=armv7-r/mfloat-abi=hard/mfpu=vfpv3-d16
    144   1.3  mrg @end smallexample
    145   1.3  mrg 
    146   1.3  mrg The @code{MULTILIB_REQUIRED} can be used together with
    147   1.3  mrg @code{MULTILIB_EXCEPTIONS}.  The option combinations generated from
    148   1.3  mrg @code{MULTILIB_OPTIONS} will be filtered by @code{MULTILIB_EXCEPTIONS}
    149   1.3  mrg and then by @code{MULTILIB_REQUIRED}.
    150   1.3  mrg 
    151   1.3  mrg @findex MULTILIB_REUSE
    152   1.3  mrg @item MULTILIB_REUSE
    153   1.3  mrg Sometimes it is desirable to reuse one existing multilib for different
    154   1.3  mrg sets of options.  Such kind of reuse can minimize the number of multilib
    155   1.3  mrg variants.  And for some targets it is better to reuse an existing multilib
    156   1.3  mrg than to fall back to default multilib when there is no corresponding multilib.
    157   1.3  mrg This can be done by adding reuse rules to @code{MULTILIB_REUSE}.
    158   1.3  mrg 
    159   1.8  mrg A reuse rule is comprised of two parts connected by equality sign.  The left
    160   1.8  mrg part is the option set used to build multilib and the right part is the option
    161   1.8  mrg set that will reuse this multilib.  Both parts should only use options
    162   1.8  mrg specified in @code{MULTILIB_OPTIONS} and the equality signs found in options
    163   1.9  mrg name should be replaced with periods.  An explicit period in the rule can be
    164   1.9  mrg escaped by preceding it with a backslash.  The order of options in the left
    165   1.9  mrg part matters and should be same with those specified in
    166   1.9  mrg @code{MULTILIB_REQUIRED} or aligned with the order in @code{MULTILIB_OPTIONS}.
    167   1.9  mrg There is no such limitation for options in the right part as we don't build
    168   1.9  mrg multilib from them.
    169   1.3  mrg 
    170   1.8  mrg @code{MULTILIB_REUSE} is different from @code{MULTILIB_MATCHES} in that it
    171   1.3  mrg sets up relations between two option sets rather than two options.  Here is an
    172   1.3  mrg example to demo how we reuse libraries built in Thumb mode for applications built
    173   1.3  mrg in ARM mode:
    174   1.3  mrg @smallexample
    175   1.3  mrg @code{MULTILIB_REUSE} = mthumb/march.armv7-r=marm/march.armv7-r
    176   1.3  mrg @end smallexample
    177   1.3  mrg 
    178   1.3  mrg Before the advent of @code{MULTILIB_REUSE}, GCC select multilib by comparing command
    179   1.3  mrg line options with options used to build multilib.  The @code{MULTILIB_REUSE} is
    180   1.3  mrg complementary to that way.  Only when the original comparison matches nothing it will
    181   1.3  mrg work to see if it is OK to reuse some existing multilib.
    182   1.3  mrg 
    183   1.1  mrg @findex MULTILIB_EXTRA_OPTS
    184   1.1  mrg @item MULTILIB_EXTRA_OPTS
    185   1.1  mrg Sometimes it is desirable that when building multiple versions of
    186   1.1  mrg @file{libgcc.a} certain options should always be passed on to the
    187   1.1  mrg compiler.  In that case, set @code{MULTILIB_EXTRA_OPTS} to be the list
    188   1.1  mrg of options to be used for all builds.  If you set this, you should
    189   1.1  mrg probably set @code{CRTSTUFF_T_CFLAGS} to a dash followed by it.
    190   1.1  mrg 
    191   1.3  mrg @findex MULTILIB_OSDIRNAMES
    192   1.3  mrg @item MULTILIB_OSDIRNAMES
    193   1.3  mrg If @code{MULTILIB_OPTIONS} is used, this variable specifies 
    194   1.3  mrg a list of subdirectory names, that are used to modify the search
    195   1.3  mrg path depending on the chosen multilib.  Unlike @code{MULTILIB_DIRNAMES},
    196   1.3  mrg @code{MULTILIB_OSDIRNAMES} describes the multilib directories using
    197   1.3  mrg operating systems conventions, and is applied to the directories such as
    198   1.3  mrg @code{lib} or those in the @env{LIBRARY_PATH} environment variable.
    199   1.3  mrg The format is either the same as of
    200   1.3  mrg @code{MULTILIB_DIRNAMES}, or a set of mappings.  When it is the same
    201   1.3  mrg as @code{MULTILIB_DIRNAMES}, it describes the multilib directories
    202   1.3  mrg using operating system conventions, rather than GCC conventions.  When it is a set
    203   1.3  mrg of mappings of the form @var{gccdir}=@var{osdir}, the left side gives
    204   1.3  mrg the GCC convention and the right gives the equivalent OS defined
    205   1.3  mrg location.  If the @var{osdir} part begins with a @samp{!},
    206   1.3  mrg GCC will not search in the non-multilib directory and use
    207   1.3  mrg exclusively the multilib directory.  Otherwise, the compiler will
    208   1.3  mrg examine the search path for libraries and crt files twice; the first
    209   1.3  mrg time it will add @var{multilib} to each directory in the search path,
    210   1.3  mrg the second it will not.
    211   1.3  mrg 
    212   1.3  mrg For configurations that support both multilib and multiarch,
    213   1.3  mrg @code{MULTILIB_OSDIRNAMES} also encodes the multiarch name, thus
    214   1.3  mrg subsuming @code{MULTIARCH_DIRNAME}.  The multiarch name is appended to
    215  1.10  mrg each directory name, separated by a colon (e.g.@:
    216   1.3  mrg @samp{../lib32:i386-linux-gnu}).
    217   1.3  mrg 
    218   1.3  mrg Each multiarch subdirectory will be searched before the corresponding OS
    219   1.3  mrg multilib directory, for example @samp{/lib/i386-linux-gnu} before
    220   1.3  mrg @samp{/lib/../lib32}.  The multiarch name will also be used to modify the
    221   1.3  mrg system header search path, as explained for @code{MULTIARCH_DIRNAME}.
    222   1.3  mrg 
    223   1.3  mrg @findex MULTIARCH_DIRNAME
    224   1.3  mrg @item MULTIARCH_DIRNAME
    225   1.3  mrg This variable specifies the multiarch name for configurations that are
    226   1.3  mrg multiarch-enabled but not multilibbed configurations.
    227   1.3  mrg 
    228   1.3  mrg The multiarch name is used to augment the search path for libraries, crt
    229   1.3  mrg files and system header files with additional locations.  The compiler
    230   1.3  mrg will add a multiarch subdirectory of the form
    231   1.3  mrg @var{prefix}/@var{multiarch} before each directory in the library and
    232   1.3  mrg crt search path.  It will also add two directories
    233   1.3  mrg @code{LOCAL_INCLUDE_DIR}/@var{multiarch} and
    234   1.3  mrg @code{NATIVE_SYSTEM_HEADER_DIR}/@var{multiarch}) to the system header
    235   1.3  mrg search path, respectively before @code{LOCAL_INCLUDE_DIR} and
    236   1.3  mrg @code{NATIVE_SYSTEM_HEADER_DIR}.
    237   1.3  mrg 
    238   1.3  mrg @code{MULTIARCH_DIRNAME} is not used for configurations that support
    239   1.3  mrg both multilib and multiarch.  In that case, multiarch names are encoded
    240   1.3  mrg in @code{MULTILIB_OSDIRNAMES} instead.
    241   1.3  mrg 
    242   1.3  mrg More documentation about multiarch can be found at
    243   1.6  mrg @uref{https://wiki.debian.org/Multiarch}.
    244   1.1  mrg 
    245   1.1  mrg @findex SPECS
    246   1.1  mrg @item SPECS
    247   1.1  mrg Unfortunately, setting @code{MULTILIB_EXTRA_OPTS} is not enough, since
    248   1.1  mrg it does not affect the build of target libraries, at least not the
    249   1.1  mrg build of the default multilib.  One possible work-around is to use
    250   1.1  mrg @code{DRIVER_SELF_SPECS} to bring options from the @file{specs} file
    251   1.1  mrg as if they had been passed in the compiler driver command line.
    252   1.1  mrg However, you don't want to be adding these options after the toolchain
    253   1.1  mrg is installed, so you can instead tweak the @file{specs} file that will
    254   1.1  mrg be used during the toolchain build, while you still install the
    255   1.1  mrg original, built-in @file{specs}.  The trick is to set @code{SPECS} to
    256   1.1  mrg some other filename (say @file{specs.install}), that will then be
    257   1.1  mrg created out of the built-in specs, and introduce a @file{Makefile}
    258   1.1  mrg rule to generate the @file{specs} file that's going to be used at
    259   1.1  mrg build time out of your @file{specs.install}.
    260   1.1  mrg 
    261   1.1  mrg @item T_CFLAGS
    262   1.1  mrg These are extra flags to pass to the C compiler.  They are used both
    263   1.1  mrg when building GCC, and when compiling things with the just-built GCC@.
    264   1.1  mrg This variable is deprecated and should not be used.
    265   1.1  mrg @end table
    266   1.1  mrg 
    267   1.1  mrg @node Host Fragment
    268   1.1  mrg @section Host Makefile Fragments
    269   1.1  mrg @cindex host makefile fragment
    270   1.1  mrg @cindex @file{x-@var{host}}
    271   1.1  mrg 
    272   1.1  mrg The use of @file{x-@var{host}} fragments is discouraged.  You should only
    273   1.1  mrg use it for makefile dependencies.
    274