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