You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

734 line
31KB

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