- %%
Substitute one % into the program name or argument.
- %i
Substitute the name of the input file being processed.
- %b
Substitute the basename of the input file being processed.
This is the substring up to (and not including) the last period
and not including the directory.
- %B
This is the same as %b, but include the file suffix (text after
the last period).
- %d
Marks the argument containing or following the %d as a
temporary file name, so that that file will be deleted if GCC exits
successfully. Unlike %g, this contributes no text to the
argument.
- %gsuffix
Substitute a file name that has suffix suffix and is chosen
once per compilation, and mark the argument in the same way as
%d. To reduce exposure to denial-of-service attacks, the file
name is now chosen in a way that is hard to predict even when previously
chosen file names are known. For example, %g.s … %g.o … %g.s
might turn into ccUVUUAU.s ccXYAXZ12.o ccUVUUAU.s. suffix matches
the regexp [.A-Za-z]* or the special string %O, which is
treated exactly as if %O had been preprocessed. Previously, %g
was simply substituted with a file name chosen once per compilation,
without regard to any appended suffix (which was therefore treated
just like ordinary text), making such attacks more likely to succeed.
- %usuffix
Like %g, but generates a new temporary file name even if
%usuffix was already seen.
- %Usuffix
Substitutes the last file name generated with %usuffix, generating a
new one if there is no such last file name. In the absence of any
%usuffix, this is just like %gsuffix, except they don't share
the same suffix space, so %g.s … %U.s … %g.s … %U.s
would involve the generation of two distinct file names, one
for each %g.s and another for each %U.s. Previously, %U was
simply substituted with a file name chosen for the previous %u,
without regard to any appended suffix.
- %jsuffix
Substitutes the name of the HOST_BIT_BUCKET, if any, and if it is
writable, and if save-temps is off; otherwise, substitute the name
of a temporary file, just like %u. This temporary file is not
meant for communication between processes, but rather as a junk
disposal mechanism.
- %|suffix, %msuffix
Like %g, except if -pipe is in effect. In that case
%| substitutes a single dash and %m substitutes nothing at
all. These are the two most common ways to instruct a program that it
should read from standard input or write to standard output. If you
need something more elaborate you can use an %{pipe:X}
construct: see for example f/lang-specs.h.
- %.SUFFIX
Substitutes .SUFFIX for the suffixes of a matched switch's args
when it is subsequently output with %*. SUFFIX is
terminated by the next space or %.
- %w
Marks the argument containing or following the %w as the
designated output file of this compilation. This puts the argument
into the sequence of arguments that %o will substitute later.
- %o
Substitutes the names of all the output files, with spaces
automatically placed around them. You should write spaces
around the %o as well or the results are undefined.
%o is for use in the specs for running the linker.
Input files whose names have no recognized suffix are not compiled
at all, but they are included among the output files, so they will
be linked.
- %O
Substitutes the suffix for object files. Note that this is
handled specially when it immediately follows %g, %u, or %U,
because of the need for those to form complete file names. The
handling is such that %O is treated exactly as if it had already
been substituted, except that %g, %u, and %U do not currently
support additional suffix characters following %O as they would
following, for example, .o.
- %p
Substitutes the standard macro predefinitions for the
current target machine. Use this when running cpp.
- %P
Like %p, but puts __ before and after the name of each
predefined macro, except for macros that start with __ or with
_L, where L is an uppercase letter. This is for ISO
C.
- %I
Substitute any of -iprefix (made from GCC_EXEC_PREFIX),
-isysroot (made from TARGET_SYSTEM_ROOT), and
-isystem (made from COMPILER_PATH and -B options)
as necessary.
- %s
Current argument is the name of a library or startup file of some sort.
Search for that file in a standard list of directories and substitute
the full name found.
- %estr
Print str as an error message. str is terminated by a newline.
Use this when inconsistent options are detected.
- %(name)
Substitute the contents of spec string name at this point.
- %[name]
Like %(…) but put __ around -D arguments.
- %x{option}
Accumulate an option for %X.
- %X
Output the accumulated linker options specified by -Wl or a %x
spec string.
- %Y
Output the accumulated assembler options specified by -Wa.
- %Z
Output the accumulated preprocessor options specified by -Wp.
- %a
Process the asm spec. This is used to compute the
switches to be passed to the assembler.
- %A
Process the asm_final spec. This is a spec string for
passing switches to an assembler post-processor, if such a program is
needed.
- %l
Process the link spec. This is the spec for computing the
command line passed to the linker. Typically it will make use of the
%L %G %S %D and %E sequences.
- %D
Dump out a -L option for each directory that GCC believes might
contain startup files. If the target supports multilibs then the
current multilib directory will be prepended to each of these paths.
- %M
Output the multilib directory with directory separators replaced with
_. If multilib directories are not set, or the multilib directory is
. then this option emits nothing.
- %L
Process the lib spec. This is a spec string for deciding which
libraries should be included on the command line to the linker.
- %G
Process the libgcc spec. This is a spec string for deciding
which GCC support library should be included on the command line to the linker.
- %S
Process the startfile spec. This is a spec for deciding which
object files should be the first ones passed to the linker. Typically
this might be a file named crt0.o.
- %E
Process the endfile spec. This is a spec string that specifies
the last object files that will be passed to the linker.
- %C
Process the cpp spec. This is used to construct the arguments
to be passed to the C preprocessor.
- %c
Process the signed_char spec. This is intended to be used
to tell cpp whether a char is signed. It typically has the definition:
%{funsigned-char:-D__CHAR_UNSIGNED__} |
- %1
Process the cc1 spec. This is used to construct the options to be
passed to the actual C compiler (cc1).
- %2
Process the cc1plus spec. This is used to construct the options to be
passed to the actual C++ compiler (cc1plus).
- %*
Substitute the variable part of a matched option. See below.
Note that each comma in the substituted string is replaced by
a single space.
- %<S
Remove all occurrences of -S from the command line. Note--this
command is position dependent. % commands in the spec string
before this one will see -S, % commands in the spec string
after this one will not.
- %:function(args)
Call the named function function, passing it args.
args is first processed as a nested spec string, then split
into an argument vector in the usual fashion. The function returns
a string which is processed as if it had appeared literally as part
of the current spec.
The following built-in spec functions are provided:
- if-exists
The if-exists spec function takes one argument, an absolute
pathname to a file. If the file exists, if-exists returns the
pathname. Here is a small example of its usage:
*startfile:
crt0%O%s %:if-exists(crti%O%s) crtbegin%O%s |
- if-exists-else
The if-exists-else spec function is similar to the if-exists
spec function, except that it takes two arguments. The first argument is
an absolute pathname to a file. If the file exists, if-exists-else
returns the pathname. If it does not exist, it returns the second argument.
This way, if-exists-else can be used to select one file or another,
based on the existence of the first. Here is a small example of its usage:
*startfile:
crt0%O%s %:if-exists(crti%O%s) \
%:if-exists-else(crtbeginT%O%s crtbegin%O%s) |
- %{S}
Substitutes the -S switch, if that switch was given to GCC.
If that switch was not specified, this substitutes nothing. Note that
the leading dash is omitted when specifying this option, and it is
automatically inserted if the substitution is performed. Thus the spec
string %{foo} would match the command-line option -foo
and would output the command line option -foo.
- %W{S}
Like %{S} but mark last argument supplied within as a file to be
deleted on failure.
- %{S*}
Substitutes all the switches specified to GCC whose names start
with -S, but which also take an argument. This is used for
switches like -o, -D, -I, etc.
GCC considers -o foo as being
one switch whose names starts with o. %{o*} would substitute this
text, including the space. Thus two arguments would be generated.
- %{S*&T*}
Like %{S*}, but preserve order of S and T options
(the order of S and T in the spec is not significant).
There can be any number of ampersand-separated variables; for each the
wild card is optional. Useful for CPP as %{D*&U*&A*}.
- %{S:X}
Substitutes X, if the -S switch was given to GCC.
- %{!S:X}
Substitutes X, if the -S switch was not given to GCC.
- %{S*:X}
Substitutes X if one or more switches whose names start with
-S are specified to GCC. Normally X is substituted only
once, no matter how many such switches appeared. However, if %*
appears somewhere in X, then X will be substituted once
for each matching switch, with the %* replaced by the part of
that switch that matched the *.
- %{.S:X}
Substitutes X, if processing a file with suffix S.
- %{!.S:X}
Substitutes X, if not processing a file with suffix S.
- %{S|P:X}
Substitutes X if either -S or -P was given to GCC.
This may be combined with !, ., and * sequences as well,
although they have a stronger binding than the |. If %*
appears in X, all of the alternatives must be starred, and only
the first matching alternative is substituted.
For example, a spec string like this:
%{.c:-foo} %{!.c:-bar} %{.c|d:-baz} %{!.c|d:-boggle} |
will output the following command-line options from the following input
command-line options:
fred.c -foo -baz
jim.d -bar -boggle
-d fred.c -foo -baz -boggle
-d jim.d -bar -baz -boggle |
- %{S:X; T:Y; :D}
If S was given to GCC, substitutes X; else if T was
given to GCC, substitutes Y; else substitutes D. There can
be as many clauses as you need. This may be combined with .,
!, |, and * as needed.