aboutsummaryrefslogtreecommitdiff
path: root/gcc/config/darwin-driver.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/config/darwin-driver.c')
-rw-r--r--gcc/config/darwin-driver.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/gcc/config/darwin-driver.c b/gcc/config/darwin-driver.c
index 3d85f29cb3d..b3577c416bc 100644
--- a/gcc/config/darwin-driver.c
+++ b/gcc/config/darwin-driver.c
@@ -210,6 +210,28 @@ darwin_default_min_version (void)
return new_flag;
}
+/* See if we can find the sysroot from the SDKROOT environment variable. */
+
+static const char *
+maybe_get_sysroot_from_sdkroot ()
+{
+ const char *maybe_sysroot = getenv ("SDKROOT");
+
+ /* We'll use the same rules as the clang driver, for compatibility.
+ 1) The path must be absolute
+ 2) Ignore "/", that is the default anyway and we do not want the
+ sysroot semantics to be applied to it.
+ 3) It must exist (actually, we'll check it's readable too). */
+
+ if (maybe_sysroot == NULL
+ || *maybe_sysroot != '/'
+ || strlen (maybe_sysroot) == 1
+ || access (maybe_sysroot, R_OK) == -1)
+ return NULL;
+
+ return xstrndup (maybe_sysroot, strlen (maybe_sysroot));
+}
+
/* Translate -filelist and -framework options in *DECODED_OPTIONS
(size *DECODED_OPTIONS_COUNT) to use -Xlinker so that they are
considered to be linker inputs in the case that no other inputs are
@@ -234,6 +256,7 @@ darwin_driver_init (unsigned int *decoded_options_count,
bool appendM64 = false;
const char *vers_string = NULL;
bool seen_version_min = false;
+ bool seen_sysroot_p = false;
for (i = 1; i < *decoded_options_count; i++)
{
@@ -314,6 +337,11 @@ darwin_driver_init (unsigned int *decoded_options_count,
--*decoded_options_count;
break;
+ case OPT__sysroot_:
+ case OPT_isysroot:
+ seen_sysroot_p = true;
+ break;
+
default:
break;
}
@@ -375,6 +403,22 @@ darwin_driver_init (unsigned int *decoded_options_count,
&(*decoded_options)[*decoded_options_count - 1]);
}
+ if (! seen_sysroot_p)
+ {
+ /* We will pick up an SDKROOT if we didn't specify a sysroot and treat
+ it as overriding any configure-time --with-sysroot. */
+ const char *sdkroot = maybe_get_sysroot_from_sdkroot ();
+ if (sdkroot)
+ {
+ ++*decoded_options_count;
+ *decoded_options = XRESIZEVEC (struct cl_decoded_option,
+ *decoded_options,
+ *decoded_options_count);
+ generate_option (OPT__sysroot_, sdkroot, 1, CL_DRIVER,
+ &(*decoded_options)[*decoded_options_count - 1]);
+ }
+ }
+
/* We will need to know the OS X version we're trying to build for here
so that we can figure out the mechanism and source for the sysroot to
be used. */