Spec-Files.html 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2017 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <title>Using the GNU Compiler Collection (GCC): Spec Files</title>
  20. <meta name="description" content="Using the GNU Compiler Collection (GCC): Spec Files">
  21. <meta name="keywords" content="Using the GNU Compiler Collection (GCC): Spec Files">
  22. <meta name="resource-type" content="document">
  23. <meta name="distribution" content="global">
  24. <meta name="Generator" content="makeinfo">
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="Invoking-GCC.html#Invoking-GCC" rel="up" title="Invoking GCC">
  30. <link href="Environment-Variables.html#Environment-Variables" rel="next" title="Environment Variables">
  31. <link href="zSeries-Options.html#zSeries-Options" rel="prev" title="zSeries Options">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.smallquotation {font-size: smaller}
  36. div.display {margin-left: 3.2em}
  37. div.example {margin-left: 3.2em}
  38. div.indentedblock {margin-left: 3.2em}
  39. div.lisp {margin-left: 3.2em}
  40. div.smalldisplay {margin-left: 3.2em}
  41. div.smallexample {margin-left: 3.2em}
  42. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style:oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nocodebreak {white-space:nowrap}
  54. span.nolinebreak {white-space:nowrap}
  55. span.roman {font-family:serif; font-weight:normal}
  56. span.sansserif {font-family:sans-serif; font-weight:normal}
  57. ul.no-bullet {list-style: none}
  58. -->
  59. </style>
  60. </head>
  61. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  62. <a name="Spec-Files"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Environment-Variables.html#Environment-Variables" accesskey="n" rel="next">Environment Variables</a>, Previous: <a href="Submodel-Options.html#Submodel-Options" accesskey="p" rel="prev">Submodel Options</a>, Up: <a href="Invoking-GCC.html#Invoking-GCC" accesskey="u" rel="up">Invoking GCC</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  66. </div>
  67. <hr>
  68. <a name="Specifying-Subprocesses-and-the-Switches-to-Pass-to-Them"></a>
  69. <h3 class="section">3.19 Specifying Subprocesses and the Switches to Pass to Them</h3>
  70. <a name="index-Spec-Files"></a>
  71. <p><code>gcc</code> is a driver program. It performs its job by invoking a
  72. sequence of other programs to do the work of compiling, assembling and
  73. linking. GCC interprets its command-line parameters and uses these to
  74. deduce which programs it should invoke, and which command-line options
  75. it ought to place on their command lines. This behavior is controlled
  76. by <em>spec strings</em>. In most cases there is one spec string for each
  77. program that GCC can invoke, but a few programs have multiple spec
  78. strings to control their behavior. The spec strings built into GCC can
  79. be overridden by using the <samp>-specs=</samp> command-line switch to specify
  80. a spec file.
  81. </p>
  82. <p><em>Spec files</em> are plain-text files that are used to construct spec
  83. strings. They consist of a sequence of directives separated by blank
  84. lines. The type of directive is determined by the first non-whitespace
  85. character on the line, which can be one of the following:
  86. </p>
  87. <dl compact="compact">
  88. <dt><code>%<var>command</var></code></dt>
  89. <dd><p>Issues a <var>command</var> to the spec file processor. The commands that can
  90. appear here are:
  91. </p>
  92. <dl compact="compact">
  93. <dt><code>%include &lt;<var>file</var>&gt;</code></dt>
  94. <dd><a name="index-_0025include"></a>
  95. <p>Search for <var>file</var> and insert its text at the current point in the
  96. specs file.
  97. </p>
  98. </dd>
  99. <dt><code>%include_noerr &lt;<var>file</var>&gt;</code></dt>
  100. <dd><a name="index-_0025include_005fnoerr"></a>
  101. <p>Just like &lsquo;<samp>%include</samp>&rsquo;, but do not generate an error message if the include
  102. file cannot be found.
  103. </p>
  104. </dd>
  105. <dt><code>%rename <var>old_name</var> <var>new_name</var></code></dt>
  106. <dd><a name="index-_0025rename"></a>
  107. <p>Rename the spec string <var>old_name</var> to <var>new_name</var>.
  108. </p>
  109. </dd>
  110. </dl>
  111. </dd>
  112. <dt><code>*[<var>spec_name</var>]:</code></dt>
  113. <dd><p>This tells the compiler to create, override or delete the named spec
  114. string. All lines after this directive up to the next directive or
  115. blank line are considered to be the text for the spec string. If this
  116. results in an empty string then the spec is deleted. (Or, if the
  117. spec did not exist, then nothing happens.) Otherwise, if the spec
  118. does not currently exist a new spec is created. If the spec does
  119. exist then its contents are overridden by the text of this
  120. directive, unless the first character of that text is the &lsquo;<samp>+</samp>&rsquo;
  121. character, in which case the text is appended to the spec.
  122. </p>
  123. </dd>
  124. <dt><code>[<var>suffix</var>]:</code></dt>
  125. <dd><p>Creates a new &lsquo;<samp>[<var>suffix</var>] spec</samp>&rsquo; pair. All lines after this directive
  126. and up to the next directive or blank line are considered to make up the
  127. spec string for the indicated suffix. When the compiler encounters an
  128. input file with the named suffix, it processes the spec string in
  129. order to work out how to compile that file. For example:
  130. </p>
  131. <div class="smallexample">
  132. <pre class="smallexample">.ZZ:
  133. z-compile -input %i
  134. </pre></div>
  135. <p>This says that any input file whose name ends in &lsquo;<samp>.ZZ</samp>&rsquo; should be
  136. passed to the program &lsquo;<samp>z-compile</samp>&rsquo;, which should be invoked with the
  137. command-line switch <samp>-input</samp> and with the result of performing the
  138. &lsquo;<samp>%i</samp>&rsquo; substitution. (See below.)
  139. </p>
  140. <p>As an alternative to providing a spec string, the text following a
  141. suffix directive can be one of the following:
  142. </p>
  143. <dl compact="compact">
  144. <dt><code>@<var>language</var></code></dt>
  145. <dd><p>This says that the suffix is an alias for a known <var>language</var>. This is
  146. similar to using the <samp>-x</samp> command-line switch to GCC to specify a
  147. language explicitly. For example:
  148. </p>
  149. <div class="smallexample">
  150. <pre class="smallexample">.ZZ:
  151. @c++
  152. </pre></div>
  153. <p>Says that .ZZ files are, in fact, C++ source files.
  154. </p>
  155. </dd>
  156. <dt><code>#<var>name</var></code></dt>
  157. <dd><p>This causes an error messages saying:
  158. </p>
  159. <div class="smallexample">
  160. <pre class="smallexample"><var>name</var> compiler not installed on this system.
  161. </pre></div>
  162. </dd>
  163. </dl>
  164. <p>GCC already has an extensive list of suffixes built into it.
  165. This directive adds an entry to the end of the list of suffixes, but
  166. since the list is searched from the end backwards, it is effectively
  167. possible to override earlier entries using this technique.
  168. </p>
  169. </dd>
  170. </dl>
  171. <p>GCC has the following spec strings built into it. Spec files can
  172. override these strings or create their own. Note that individual
  173. targets can also add their own spec strings to this list.
  174. </p>
  175. <div class="smallexample">
  176. <pre class="smallexample">asm Options to pass to the assembler
  177. asm_final Options to pass to the assembler post-processor
  178. cpp Options to pass to the C preprocessor
  179. cc1 Options to pass to the C compiler
  180. cc1plus Options to pass to the C++ compiler
  181. endfile Object files to include at the end of the link
  182. link Options to pass to the linker
  183. lib Libraries to include on the command line to the linker
  184. libgcc Decides which GCC support library to pass to the linker
  185. linker Sets the name of the linker
  186. predefines Defines to be passed to the C preprocessor
  187. signed_char Defines to pass to CPP to say whether <code>char</code> is signed
  188. by default
  189. startfile Object files to include at the start of the link
  190. </pre></div>
  191. <p>Here is a small example of a spec file:
  192. </p>
  193. <div class="smallexample">
  194. <pre class="smallexample">%rename lib old_lib
  195. *lib:
  196. --start-group -lgcc -lc -leval1 --end-group %(old_lib)
  197. </pre></div>
  198. <p>This example renames the spec called &lsquo;<samp>lib</samp>&rsquo; to &lsquo;<samp>old_lib</samp>&rsquo; and
  199. then overrides the previous definition of &lsquo;<samp>lib</samp>&rsquo; with a new one.
  200. The new definition adds in some extra command-line options before
  201. including the text of the old definition.
  202. </p>
  203. <p><em>Spec strings</em> are a list of command-line options to be passed to their
  204. corresponding program. In addition, the spec strings can contain
  205. &lsquo;<samp>%</samp>&rsquo;-prefixed sequences to substitute variable text or to
  206. conditionally insert text into the command line. Using these constructs
  207. it is possible to generate quite complex command lines.
  208. </p>
  209. <p>Here is a table of all defined &lsquo;<samp>%</samp>&rsquo;-sequences for spec
  210. strings. Note that spaces are not generated automatically around the
  211. results of expanding these sequences. Therefore you can concatenate them
  212. together or combine them with constant text in a single argument.
  213. </p>
  214. <dl compact="compact">
  215. <dt><code>%%</code></dt>
  216. <dd><p>Substitute one &lsquo;<samp>%</samp>&rsquo; into the program name or argument.
  217. </p>
  218. </dd>
  219. <dt><code>%i</code></dt>
  220. <dd><p>Substitute the name of the input file being processed.
  221. </p>
  222. </dd>
  223. <dt><code>%b</code></dt>
  224. <dd><p>Substitute the basename of the input file being processed.
  225. This is the substring up to (and not including) the last period
  226. and not including the directory.
  227. </p>
  228. </dd>
  229. <dt><code>%B</code></dt>
  230. <dd><p>This is the same as &lsquo;<samp>%b</samp>&rsquo;, but include the file suffix (text after
  231. the last period).
  232. </p>
  233. </dd>
  234. <dt><code>%d</code></dt>
  235. <dd><p>Marks the argument containing or following the &lsquo;<samp>%d</samp>&rsquo; as a
  236. temporary file name, so that that file is deleted if GCC exits
  237. successfully. Unlike &lsquo;<samp>%g</samp>&rsquo;, this contributes no text to the
  238. argument.
  239. </p>
  240. </dd>
  241. <dt><code>%g<var>suffix</var></code></dt>
  242. <dd><p>Substitute a file name that has suffix <var>suffix</var> and is chosen
  243. once per compilation, and mark the argument in the same way as
  244. &lsquo;<samp>%d</samp>&rsquo;. To reduce exposure to denial-of-service attacks, the file
  245. name is now chosen in a way that is hard to predict even when previously
  246. chosen file names are known. For example, &lsquo;<samp>%g.s &hellip; %g.o &hellip; %g.s</samp>&rsquo;
  247. might turn into &lsquo;<samp>ccUVUUAU.s ccXYAXZ12.o ccUVUUAU.s</samp>&rsquo;. <var>suffix</var> matches
  248. the regexp &lsquo;<samp>[.A-Za-z]*</samp>&rsquo; or the special string &lsquo;<samp>%O</samp>&rsquo;, which is
  249. treated exactly as if &lsquo;<samp>%O</samp>&rsquo; had been preprocessed. Previously, &lsquo;<samp>%g</samp>&rsquo;
  250. was simply substituted with a file name chosen once per compilation,
  251. without regard to any appended suffix (which was therefore treated
  252. just like ordinary text), making such attacks more likely to succeed.
  253. </p>
  254. </dd>
  255. <dt><code>%u<var>suffix</var></code></dt>
  256. <dd><p>Like &lsquo;<samp>%g</samp>&rsquo;, but generates a new temporary file name
  257. each time it appears instead of once per compilation.
  258. </p>
  259. </dd>
  260. <dt><code>%U<var>suffix</var></code></dt>
  261. <dd><p>Substitutes the last file name generated with &lsquo;<samp>%u<var>suffix</var></samp>&rsquo;, generating a
  262. new one if there is no such last file name. In the absence of any
  263. &lsquo;<samp>%u<var>suffix</var></samp>&rsquo;, this is just like &lsquo;<samp>%g<var>suffix</var></samp>&rsquo;, except they don&rsquo;t share
  264. the same suffix <em>space</em>, so &lsquo;<samp>%g.s &hellip; %U.s &hellip; %g.s &hellip; %U.s</samp>&rsquo;
  265. involves the generation of two distinct file names, one
  266. for each &lsquo;<samp>%g.s</samp>&rsquo; and another for each &lsquo;<samp>%U.s</samp>&rsquo;. Previously, &lsquo;<samp>%U</samp>&rsquo; was
  267. simply substituted with a file name chosen for the previous &lsquo;<samp>%u</samp>&rsquo;,
  268. without regard to any appended suffix.
  269. </p>
  270. </dd>
  271. <dt><code>%j<var>suffix</var></code></dt>
  272. <dd><p>Substitutes the name of the <code>HOST_BIT_BUCKET</code>, if any, and if it is
  273. writable, and if <samp>-save-temps</samp> is not used;
  274. otherwise, substitute the name
  275. of a temporary file, just like &lsquo;<samp>%u</samp>&rsquo;. This temporary file is not
  276. meant for communication between processes, but rather as a junk
  277. disposal mechanism.
  278. </p>
  279. </dd>
  280. <dt><code>%|<var>suffix</var></code></dt>
  281. <dt><code>%m<var>suffix</var></code></dt>
  282. <dd><p>Like &lsquo;<samp>%g</samp>&rsquo;, except if <samp>-pipe</samp> is in effect. In that case
  283. &lsquo;<samp>%|</samp>&rsquo; substitutes a single dash and &lsquo;<samp>%m</samp>&rsquo; substitutes nothing at
  284. all. These are the two most common ways to instruct a program that it
  285. should read from standard input or write to standard output. If you
  286. need something more elaborate you can use an &lsquo;<samp>%{pipe:<code>X</code>}</samp>&rsquo;
  287. construct: see for example <samp>f/lang-specs.h</samp>.
  288. </p>
  289. </dd>
  290. <dt><code>%.<var>SUFFIX</var></code></dt>
  291. <dd><p>Substitutes <var>.SUFFIX</var> for the suffixes of a matched switch&rsquo;s args
  292. when it is subsequently output with &lsquo;<samp>%*</samp>&rsquo;. <var>SUFFIX</var> is
  293. terminated by the next space or %.
  294. </p>
  295. </dd>
  296. <dt><code>%w</code></dt>
  297. <dd><p>Marks the argument containing or following the &lsquo;<samp>%w</samp>&rsquo; as the
  298. designated output file of this compilation. This puts the argument
  299. into the sequence of arguments that &lsquo;<samp>%o</samp>&rsquo; substitutes.
  300. </p>
  301. </dd>
  302. <dt><code>%o</code></dt>
  303. <dd><p>Substitutes the names of all the output files, with spaces
  304. automatically placed around them. You should write spaces
  305. around the &lsquo;<samp>%o</samp>&rsquo; as well or the results are undefined.
  306. &lsquo;<samp>%o</samp>&rsquo; is for use in the specs for running the linker.
  307. Input files whose names have no recognized suffix are not compiled
  308. at all, but they are included among the output files, so they are
  309. linked.
  310. </p>
  311. </dd>
  312. <dt><code>%O</code></dt>
  313. <dd><p>Substitutes the suffix for object files. Note that this is
  314. handled specially when it immediately follows &lsquo;<samp>%g, %u, or %U</samp>&rsquo;,
  315. because of the need for those to form complete file names. The
  316. handling is such that &lsquo;<samp>%O</samp>&rsquo; is treated exactly as if it had already
  317. been substituted, except that &lsquo;<samp>%g, %u, and %U</samp>&rsquo; do not currently
  318. support additional <var>suffix</var> characters following &lsquo;<samp>%O</samp>&rsquo; as they do
  319. following, for example, &lsquo;<samp>.o</samp>&rsquo;.
  320. </p>
  321. </dd>
  322. <dt><code>%p</code></dt>
  323. <dd><p>Substitutes the standard macro predefinitions for the
  324. current target machine. Use this when running <code>cpp</code>.
  325. </p>
  326. </dd>
  327. <dt><code>%P</code></dt>
  328. <dd><p>Like &lsquo;<samp>%p</samp>&rsquo;, but puts &lsquo;<samp>__</samp>&rsquo; before and after the name of each
  329. predefined macro, except for macros that start with &lsquo;<samp>__</samp>&rsquo; or with
  330. &lsquo;<samp>_<var>L</var></samp>&rsquo;, where <var>L</var> is an uppercase letter. This is for ISO
  331. C.
  332. </p>
  333. </dd>
  334. <dt><code>%I</code></dt>
  335. <dd><p>Substitute any of <samp>-iprefix</samp> (made from <code>GCC_EXEC_PREFIX</code>),
  336. <samp>-isysroot</samp> (made from <code>TARGET_SYSTEM_ROOT</code>),
  337. <samp>-isystem</samp> (made from <code>COMPILER_PATH</code> and <samp>-B</samp> options)
  338. and <samp>-imultilib</samp> as necessary.
  339. </p>
  340. </dd>
  341. <dt><code>%s</code></dt>
  342. <dd><p>Current argument is the name of a library or startup file of some sort.
  343. Search for that file in a standard list of directories and substitute
  344. the full name found. The current working directory is included in the
  345. list of directories scanned.
  346. </p>
  347. </dd>
  348. <dt><code>%T</code></dt>
  349. <dd><p>Current argument is the name of a linker script. Search for that file
  350. in the current list of directories to scan for libraries. If the file
  351. is located insert a <samp>--script</samp> option into the command line
  352. followed by the full path name found. If the file is not found then
  353. generate an error message. Note: the current working directory is not
  354. searched.
  355. </p>
  356. </dd>
  357. <dt><code>%e<var>str</var></code></dt>
  358. <dd><p>Print <var>str</var> as an error message. <var>str</var> is terminated by a newline.
  359. Use this when inconsistent options are detected.
  360. </p>
  361. </dd>
  362. <dt><code>%(<var>name</var>)</code></dt>
  363. <dd><p>Substitute the contents of spec string <var>name</var> at this point.
  364. </p>
  365. </dd>
  366. <dt><code>%x{<var>option</var>}</code></dt>
  367. <dd><p>Accumulate an option for &lsquo;<samp>%X</samp>&rsquo;.
  368. </p>
  369. </dd>
  370. <dt><code>%X</code></dt>
  371. <dd><p>Output the accumulated linker options specified by <samp>-Wl</samp> or a &lsquo;<samp>%x</samp>&rsquo;
  372. spec string.
  373. </p>
  374. </dd>
  375. <dt><code>%Y</code></dt>
  376. <dd><p>Output the accumulated assembler options specified by <samp>-Wa</samp>.
  377. </p>
  378. </dd>
  379. <dt><code>%Z</code></dt>
  380. <dd><p>Output the accumulated preprocessor options specified by <samp>-Wp</samp>.
  381. </p>
  382. </dd>
  383. <dt><code>%a</code></dt>
  384. <dd><p>Process the <code>asm</code> spec. This is used to compute the
  385. switches to be passed to the assembler.
  386. </p>
  387. </dd>
  388. <dt><code>%A</code></dt>
  389. <dd><p>Process the <code>asm_final</code> spec. This is a spec string for
  390. passing switches to an assembler post-processor, if such a program is
  391. needed.
  392. </p>
  393. </dd>
  394. <dt><code>%l</code></dt>
  395. <dd><p>Process the <code>link</code> spec. This is the spec for computing the
  396. command line passed to the linker. Typically it makes use of the
  397. &lsquo;<samp>%L %G %S %D and %E</samp>&rsquo; sequences.
  398. </p>
  399. </dd>
  400. <dt><code>%D</code></dt>
  401. <dd><p>Dump out a <samp>-L</samp> option for each directory that GCC believes might
  402. contain startup files. If the target supports multilibs then the
  403. current multilib directory is prepended to each of these paths.
  404. </p>
  405. </dd>
  406. <dt><code>%L</code></dt>
  407. <dd><p>Process the <code>lib</code> spec. This is a spec string for deciding which
  408. libraries are included on the command line to the linker.
  409. </p>
  410. </dd>
  411. <dt><code>%G</code></dt>
  412. <dd><p>Process the <code>libgcc</code> spec. This is a spec string for deciding
  413. which GCC support library is included on the command line to the linker.
  414. </p>
  415. </dd>
  416. <dt><code>%S</code></dt>
  417. <dd><p>Process the <code>startfile</code> spec. This is a spec for deciding which
  418. object files are the first ones passed to the linker. Typically
  419. this might be a file named <samp>crt0.o</samp>.
  420. </p>
  421. </dd>
  422. <dt><code>%E</code></dt>
  423. <dd><p>Process the <code>endfile</code> spec. This is a spec string that specifies
  424. the last object files that are passed to the linker.
  425. </p>
  426. </dd>
  427. <dt><code>%C</code></dt>
  428. <dd><p>Process the <code>cpp</code> spec. This is used to construct the arguments
  429. to be passed to the C preprocessor.
  430. </p>
  431. </dd>
  432. <dt><code>%1</code></dt>
  433. <dd><p>Process the <code>cc1</code> spec. This is used to construct the options to be
  434. passed to the actual C compiler (<code>cc1</code>).
  435. </p>
  436. </dd>
  437. <dt><code>%2</code></dt>
  438. <dd><p>Process the <code>cc1plus</code> spec. This is used to construct the options to be
  439. passed to the actual C++ compiler (<code>cc1plus</code>).
  440. </p>
  441. </dd>
  442. <dt><code>%*</code></dt>
  443. <dd><p>Substitute the variable part of a matched option. See below.
  444. Note that each comma in the substituted string is replaced by
  445. a single space.
  446. </p>
  447. </dd>
  448. <dt><code>%&lt;<code>S</code></code></dt>
  449. <dd><p>Remove all occurrences of <code>-S</code> from the command line. Note&mdash;this
  450. command is position dependent. &lsquo;<samp>%</samp>&rsquo; commands in the spec string
  451. before this one see <code>-S</code>, &lsquo;<samp>%</samp>&rsquo; commands in the spec string
  452. after this one do not.
  453. </p>
  454. </dd>
  455. <dt><code>%:<var>function</var>(<var>args</var>)</code></dt>
  456. <dd><p>Call the named function <var>function</var>, passing it <var>args</var>.
  457. <var>args</var> is first processed as a nested spec string, then split
  458. into an argument vector in the usual fashion. The function returns
  459. a string which is processed as if it had appeared literally as part
  460. of the current spec.
  461. </p>
  462. <p>The following built-in spec functions are provided:
  463. </p>
  464. <dl compact="compact">
  465. <dt><code><code>getenv</code></code></dt>
  466. <dd><p>The <code>getenv</code> spec function takes two arguments: an environment
  467. variable name and a string. If the environment variable is not
  468. defined, a fatal error is issued. Otherwise, the return value is the
  469. value of the environment variable concatenated with the string. For
  470. example, if <code>TOPDIR</code> is defined as <samp>/path/to/top</samp>, then:
  471. </p>
  472. <div class="smallexample">
  473. <pre class="smallexample">%:getenv(TOPDIR /include)
  474. </pre></div>
  475. <p>expands to <samp>/path/to/top/include</samp>.
  476. </p>
  477. </dd>
  478. <dt><code><code>if-exists</code></code></dt>
  479. <dd><p>The <code>if-exists</code> spec function takes one argument, an absolute
  480. pathname to a file. If the file exists, <code>if-exists</code> returns the
  481. pathname. Here is a small example of its usage:
  482. </p>
  483. <div class="smallexample">
  484. <pre class="smallexample">*startfile:
  485. crt0%O%s %:if-exists(crti%O%s) crtbegin%O%s
  486. </pre></div>
  487. </dd>
  488. <dt><code><code>if-exists-else</code></code></dt>
  489. <dd><p>The <code>if-exists-else</code> spec function is similar to the <code>if-exists</code>
  490. spec function, except that it takes two arguments. The first argument is
  491. an absolute pathname to a file. If the file exists, <code>if-exists-else</code>
  492. returns the pathname. If it does not exist, it returns the second argument.
  493. This way, <code>if-exists-else</code> can be used to select one file or another,
  494. based on the existence of the first. Here is a small example of its usage:
  495. </p>
  496. <div class="smallexample">
  497. <pre class="smallexample">*startfile:
  498. crt0%O%s %:if-exists(crti%O%s) \
  499. %:if-exists-else(crtbeginT%O%s crtbegin%O%s)
  500. </pre></div>
  501. </dd>
  502. <dt><code><code>replace-outfile</code></code></dt>
  503. <dd><p>The <code>replace-outfile</code> spec function takes two arguments. It looks for the
  504. first argument in the outfiles array and replaces it with the second argument. Here
  505. is a small example of its usage:
  506. </p>
  507. <div class="smallexample">
  508. <pre class="smallexample">%{fgnu-runtime:%:replace-outfile(-lobjc -lobjc-gnu)}
  509. </pre></div>
  510. </dd>
  511. <dt><code><code>remove-outfile</code></code></dt>
  512. <dd><p>The <code>remove-outfile</code> spec function takes one argument. It looks for the
  513. first argument in the outfiles array and removes it. Here is a small example
  514. its usage:
  515. </p>
  516. <div class="smallexample">
  517. <pre class="smallexample">%:remove-outfile(-lm)
  518. </pre></div>
  519. </dd>
  520. <dt><code><code>pass-through-libs</code></code></dt>
  521. <dd><p>The <code>pass-through-libs</code> spec function takes any number of arguments. It
  522. finds any <samp>-l</samp> options and any non-options ending in <samp>.a</samp> (which it
  523. assumes are the names of linker input library archive files) and returns a
  524. result containing all the found arguments each prepended by
  525. <samp>-plugin-opt=-pass-through=</samp> and joined by spaces. This list is
  526. intended to be passed to the LTO linker plugin.
  527. </p>
  528. <div class="smallexample">
  529. <pre class="smallexample">%:pass-through-libs(%G %L %G)
  530. </pre></div>
  531. </dd>
  532. <dt><code><code>print-asm-header</code></code></dt>
  533. <dd><p>The <code>print-asm-header</code> function takes no arguments and simply
  534. prints a banner like:
  535. </p>
  536. <div class="smallexample">
  537. <pre class="smallexample">Assembler options
  538. =================
  539. Use &quot;-Wa,OPTION&quot; to pass &quot;OPTION&quot; to the assembler.
  540. </pre></div>
  541. <p>It is used to separate compiler options from assembler options
  542. in the <samp>--target-help</samp> output.
  543. </p></dd>
  544. </dl>
  545. </dd>
  546. <dt><code>%{<code>S</code>}</code></dt>
  547. <dd><p>Substitutes the <code>-S</code> switch, if that switch is given to GCC.
  548. If that switch is not specified, this substitutes nothing. Note that
  549. the leading dash is omitted when specifying this option, and it is
  550. automatically inserted if the substitution is performed. Thus the spec
  551. string &lsquo;<samp>%{foo}</samp>&rsquo; matches the command-line option <samp>-foo</samp>
  552. and outputs the command-line option <samp>-foo</samp>.
  553. </p>
  554. </dd>
  555. <dt><code>%W{<code>S</code>}</code></dt>
  556. <dd><p>Like %{<code>S</code>} but mark last argument supplied within as a file to be
  557. deleted on failure.
  558. </p>
  559. </dd>
  560. <dt><code>%{<code>S</code>*}</code></dt>
  561. <dd><p>Substitutes all the switches specified to GCC whose names start
  562. with <code>-S</code>, but which also take an argument. This is used for
  563. switches like <samp>-o</samp>, <samp>-D</samp>, <samp>-I</samp>, etc.
  564. GCC considers <samp>-o foo</samp> as being
  565. one switch whose name starts with &lsquo;<samp>o</samp>&rsquo;. %{o*} substitutes this
  566. text, including the space. Thus two arguments are generated.
  567. </p>
  568. </dd>
  569. <dt><code>%{<code>S</code>*&amp;<code>T</code>*}</code></dt>
  570. <dd><p>Like %{<code>S</code>*}, but preserve order of <code>S</code> and <code>T</code> options
  571. (the order of <code>S</code> and <code>T</code> in the spec is not significant).
  572. There can be any number of ampersand-separated variables; for each the
  573. wild card is optional. Useful for CPP as &lsquo;<samp>%{D*&amp;U*&amp;A*}</samp>&rsquo;.
  574. </p>
  575. </dd>
  576. <dt><code>%{<code>S</code>:<code>X</code>}</code></dt>
  577. <dd><p>Substitutes <code>X</code>, if the <samp>-S</samp> switch is given to GCC.
  578. </p>
  579. </dd>
  580. <dt><code>%{!<code>S</code>:<code>X</code>}</code></dt>
  581. <dd><p>Substitutes <code>X</code>, if the <samp>-S</samp> switch is <em>not</em> given to GCC.
  582. </p>
  583. </dd>
  584. <dt><code>%{<code>S</code>*:<code>X</code>}</code></dt>
  585. <dd><p>Substitutes <code>X</code> if one or more switches whose names start with
  586. <code>-S</code> are specified to GCC. Normally <code>X</code> is substituted only
  587. once, no matter how many such switches appeared. However, if <code>%*</code>
  588. appears somewhere in <code>X</code>, then <code>X</code> is substituted once
  589. for each matching switch, with the <code>%*</code> replaced by the part of
  590. that switch matching the <code>*</code>.
  591. </p>
  592. <p>If <code>%*</code> appears as the last part of a spec sequence then a space
  593. is added after the end of the last substitution. If there is more
  594. text in the sequence, however, then a space is not generated. This
  595. allows the <code>%*</code> substitution to be used as part of a larger
  596. string. For example, a spec string like this:
  597. </p>
  598. <div class="smallexample">
  599. <pre class="smallexample">%{mcu=*:--script=%*/memory.ld}
  600. </pre></div>
  601. <p>when matching an option like <samp>-mcu=newchip</samp> produces:
  602. </p>
  603. <div class="smallexample">
  604. <pre class="smallexample">--script=newchip/memory.ld
  605. </pre></div>
  606. </dd>
  607. <dt><code>%{.<code>S</code>:<code>X</code>}</code></dt>
  608. <dd><p>Substitutes <code>X</code>, if processing a file with suffix <code>S</code>.
  609. </p>
  610. </dd>
  611. <dt><code>%{!.<code>S</code>:<code>X</code>}</code></dt>
  612. <dd><p>Substitutes <code>X</code>, if <em>not</em> processing a file with suffix <code>S</code>.
  613. </p>
  614. </dd>
  615. <dt><code>%{,<code>S</code>:<code>X</code>}</code></dt>
  616. <dd><p>Substitutes <code>X</code>, if processing a file for language <code>S</code>.
  617. </p>
  618. </dd>
  619. <dt><code>%{!,<code>S</code>:<code>X</code>}</code></dt>
  620. <dd><p>Substitutes <code>X</code>, if not processing a file for language <code>S</code>.
  621. </p>
  622. </dd>
  623. <dt><code>%{<code>S</code>|<code>P</code>:<code>X</code>}</code></dt>
  624. <dd><p>Substitutes <code>X</code> if either <code>-S</code> or <code>-P</code> is given to
  625. GCC. This may be combined with &lsquo;<samp>!</samp>&rsquo;, &lsquo;<samp>.</samp>&rsquo;, &lsquo;<samp>,</samp>&rsquo;, and
  626. <code>*</code> sequences as well, although they have a stronger binding than
  627. the &lsquo;<samp>|</samp>&rsquo;. If <code>%*</code> appears in <code>X</code>, all of the
  628. alternatives must be starred, and only the first matching alternative
  629. is substituted.
  630. </p>
  631. <p>For example, a spec string like this:
  632. </p>
  633. <div class="smallexample">
  634. <pre class="smallexample">%{.c:-foo} %{!.c:-bar} %{.c|d:-baz} %{!.c|d:-boggle}
  635. </pre></div>
  636. <p>outputs the following command-line options from the following input
  637. command-line options:
  638. </p>
  639. <div class="smallexample">
  640. <pre class="smallexample">fred.c -foo -baz
  641. jim.d -bar -boggle
  642. -d fred.c -foo -baz -boggle
  643. -d jim.d -bar -baz -boggle
  644. </pre></div>
  645. </dd>
  646. <dt><code>%{S:X; T:Y; :D}</code></dt>
  647. <dd>
  648. <p>If <code>S</code> is given to GCC, substitutes <code>X</code>; else if <code>T</code> is
  649. given to GCC, substitutes <code>Y</code>; else substitutes <code>D</code>. There can
  650. be as many clauses as you need. This may be combined with <code>.</code>,
  651. <code>,</code>, <code>!</code>, <code>|</code>, and <code>*</code> as needed.
  652. </p>
  653. </dd>
  654. </dl>
  655. <p>The conditional text <code>X</code> in a %{<code>S</code>:<code>X</code>} or similar
  656. construct may contain other nested &lsquo;<samp>%</samp>&rsquo; constructs or spaces, or
  657. even newlines. They are processed as usual, as described above.
  658. Trailing white space in <code>X</code> is ignored. White space may also
  659. appear anywhere on the left side of the colon in these constructs,
  660. except between <code>.</code> or <code>*</code> and the corresponding word.
  661. </p>
  662. <p>The <samp>-O</samp>, <samp>-f</samp>, <samp>-m</samp>, and <samp>-W</samp> switches are
  663. handled specifically in these constructs. If another value of
  664. <samp>-O</samp> or the negated form of a <samp>-f</samp>, <samp>-m</samp>, or
  665. <samp>-W</samp> switch is found later in the command line, the earlier
  666. switch value is ignored, except with {<code>S</code>*} where <code>S</code> is
  667. just one letter, which passes all matching options.
  668. </p>
  669. <p>The character &lsquo;<samp>|</samp>&rsquo; at the beginning of the predicate text is used to
  670. indicate that a command should be piped to the following command, but
  671. only if <samp>-pipe</samp> is specified.
  672. </p>
  673. <p>It is built into GCC which switches take arguments and which do not.
  674. (You might think it would be useful to generalize this to allow each
  675. compiler&rsquo;s spec to say which switches take arguments. But this cannot
  676. be done in a consistent fashion. GCC cannot even decide which input
  677. files have been specified without knowing which switches take arguments,
  678. and it must know which input files to compile in order to tell which
  679. compilers to run).
  680. </p>
  681. <p>GCC also knows implicitly that arguments starting in <samp>-l</samp> are to be
  682. treated as compiler output files, and passed to the linker in their
  683. proper position among the other output files.
  684. </p>
  685. <hr>
  686. <div class="header">
  687. <p>
  688. Next: <a href="Environment-Variables.html#Environment-Variables" accesskey="n" rel="next">Environment Variables</a>, Previous: <a href="Submodel-Options.html#Submodel-Options" accesskey="p" rel="prev">Submodel Options</a>, Up: <a href="Invoking-GCC.html#Invoking-GCC" accesskey="u" rel="up">Invoking GCC</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  689. </div>
  690. </body>
  691. </html>