fragments.texi 12 KB

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