mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-01-12 08:04:29 +08:00
gcc.c (static_spec_functions): Add if-exists-else spec function.
* gcc.c (static_spec_functions): Add if-exists-else spec function. (if_exists_else_spec_function): New function. * doc/invoke.texi: Document the if-exists-else spec function. * config/netbsd-elf.h (NETBSD_STARTFILE_SPEC): For -static, use "%:if-exists-else(crtbeginT%O%s crtbegin%O%s)". From-SVN: r59480
This commit is contained in:
parent
a4967b8db1
commit
152a5a9c94
@ -53,7 +53,9 @@ Boston, MA 02111-1307, USA. */
|
|||||||
%{p:gcrt0%O%s} \
|
%{p:gcrt0%O%s} \
|
||||||
%{!p:crt0%O%s}}} \
|
%{!p:crt0%O%s}}} \
|
||||||
%:if-exists(crti%O%s) \
|
%:if-exists(crti%O%s) \
|
||||||
%{!shared:crtbegin%O%s} %{shared:crtbeginS%O%s}"
|
%{static:%:if-exists-else(crtbeginT%O%s crtbegin%O%s)} \
|
||||||
|
%{!static: \
|
||||||
|
%{!shared:crtbegin%O%s} %{shared:crtbeginS%O%s}}"
|
||||||
|
|
||||||
#undef STARTFILE_SPEC
|
#undef STARTFILE_SPEC
|
||||||
#define STARTFILE_SPEC NETBSD_STARTFILE_SPEC
|
#define STARTFILE_SPEC NETBSD_STARTFILE_SPEC
|
||||||
|
@ -4986,6 +4986,19 @@ pathname. Here is a small example of its usage:
|
|||||||
*startfile:
|
*startfile:
|
||||||
crt0%O%s %:if-exists(crti%O%s) crtbegin%O%s
|
crt0%O%s %:if-exists(crti%O%s) crtbegin%O%s
|
||||||
@end smallexample
|
@end smallexample
|
||||||
|
|
||||||
|
@item @code{if-exists-else}
|
||||||
|
The @code{if-exists-else} spec function is similar to the @code{if-exists}
|
||||||
|
spec function, except that it takes two arguments. The first argument is
|
||||||
|
an absolute pathname to a file. If the file exists, @code{if-exists-else}
|
||||||
|
returns the pathname. If it does not exist, it returns the second argument.
|
||||||
|
This way, @code{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:
|
||||||
|
|
||||||
|
@smallexample
|
||||||
|
*startfile:
|
||||||
|
crt0%O%s %:if-exists(crti%O%s) %:if-exists-else(crtbeginT%O%s crtbegin%O%s)
|
||||||
|
@end smallexample
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
@item %@{@code{S}@}
|
@item %@{@code{S}@}
|
||||||
|
22
gcc/gcc.c
22
gcc/gcc.c
@ -328,6 +328,7 @@ static const char *convert_filename PARAMS ((const char *, int, int));
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const char *if_exists_spec_function PARAMS ((int, const char **));
|
static const char *if_exists_spec_function PARAMS ((int, const char **));
|
||||||
|
static const char *if_exists_else_spec_function PARAMS ((int, const char **));
|
||||||
|
|
||||||
/* The Specs Language
|
/* The Specs Language
|
||||||
|
|
||||||
@ -1451,6 +1452,7 @@ static struct spec_list *specs = (struct spec_list *) 0;
|
|||||||
static const struct spec_function static_spec_functions[] =
|
static const struct spec_function static_spec_functions[] =
|
||||||
{
|
{
|
||||||
{ "if-exists", if_exists_spec_function },
|
{ "if-exists", if_exists_spec_function },
|
||||||
|
{ "if-exists-else", if_exists_else_spec_function },
|
||||||
{ 0, 0 }
|
{ 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -7264,3 +7266,23 @@ if_exists_spec_function (argc, argv)
|
|||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* if-exists-else built-in spec function.
|
||||||
|
|
||||||
|
This is like if-exists, but takes an additional argument which
|
||||||
|
is returned if the first argument does not exist. */
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
if_exists_else_spec_function (argc, argv)
|
||||||
|
int argc;
|
||||||
|
const char **argv;
|
||||||
|
{
|
||||||
|
/* Must have exactly two arguments. */
|
||||||
|
if (argc != 2)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (IS_ABSOLUTE_PATHNAME (argv[0]) && ! access (argv[0], R_OK))
|
||||||
|
return argv[0];
|
||||||
|
|
||||||
|
return argv[1];
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user