https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79885

--- Comment #10 from Iain Sandoe <iains at gcc dot gnu.org> ---
Created attachment 45146
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45146&action=edit
Initial patch (incomplete)

rebased experimental patch on trunk at 266733.

I think that we need to be clear about what we're trying to achieve.

===

Here I'm operating on a system
 * without Xcode installed
 * without command line tools in the "usual place" (so mimicing a 'vanilla'
system).
 * a non-standard installation of the command line tools places the SDKs in a
known place.
 * GCC bootstrap compiler (so that I can build Ada) which, of course, is
capable of building code that will run on my build machine.
 * the build machine is Darwin16 / 10.16 and I target 10.10 typically for
x86_64 tests and cross-compilers for powerpc-darwin9, Linux and MinGW.

So, without a sysroot, my bootstraps will fail (there are no headers in
/usr/include,; it doesn't exist).

Normally, I use --with-sysroot=/path/to/SDK like this (here building on 10.12
for 10.10+):

MACOSX_DEPLOYMENT_TARGET=10.10 /src/gcc-trunk/configure
--prefix=/opt/iains/x86_64-apple-darwin16/gcc-trunk-unpatched
--target=x86_64-apple-darwin14 --host=x86_64-apple-darwin14
--build=x86_64-apple-darwin14 --with-iconv-prefix=/usr
--enable-checking=yes,rtl,tree --enable-lto --disable-nls
--with-sysroot=/opt/iains/x86_64-apple-darwin16/gcc-trunk-unpatched/SDKs/darwin14
--enable-version-specific-runtime-libs
--with-as=/opt/iains/x86_64-apple-darwin16/gcc-trunk-unpatched/bin/as
--with-ld=/opt/iains/x86_64-apple-darwin16/gcc-trunk-unpatched/bin/ld
--enable-languages=all,d >conf.txt

MACOSX_DEPLOYMENT_TARGET=10.10 make ... etc.

here, I have my own builds of cctools and ld64 - installed into the prefix.

So .. this will produce a self-contained compiler, 
this :/opt/iains/x86_64-apple-darwin16/gcc-trunk-unpatched/SDKs/darwin14 is a
symlink pointing to my command line install.

and that compiler will have a default sysroot of
/opt/iains/x86_64-apple-darwin16/gcc-trunk-unpatched/SDKs/darwin14, which can
be overidden by passing --sysroot= on the command line (just like clang).

======

Using --with-build-sysroot with the attached patch works (modulo things I need
to sort out with Ada)...

MACOSX_DEPLOYMENT_TARGET=10.10 /src/gcc-trunk/configure
--prefix=/opt/iains/x86_64-apple-darwin16/gcc-trunk-unpatched
--target=x86_64-apple-darwin14 --host=x86_64-apple-darwin14
--build=x86_64-apple-darwin14 --with-iconv-prefix=/usr
--enable-checking=yes,rtl,tree --enable-lto --disable-nls
--with-build-sysroot=/opt/iains/x86_64-apple-darwin16/gcc-trunk-unpatched/SDKs/darwin14
--enable-version-specific-runtime-libs
--with-as=/opt/iains/x86_64-apple-darwin16/gcc-trunk-unpatched/bin/as
--with-ld=/opt/iains/x86_64-apple-darwin16/gcc-trunk-unpatched/bin/ld
--enable-languages=c,c++,objc,obj-c++ >conf.txt

MACOSX_DEPLOYMENT_TARGET=10.10 make ... etc.

Now the difference here is that the resulting compiler has no default sysroot,
and therefore won't work *unless* 
a ) there are headers in the "usual place" (i.e. /usr/include) which I don't
think is what you want
b ) --sysroot= is specified on the command line (or isysroot IIRC, I think we
made that operate the same way as clang).

So -- I wonder if this is optimum, since the end user is now stuck with having
to add --sysroot= to every command line.
If you use --with-sysroot=/path/to/some/default/SDK then I suspect that works
tolerably for many cases.

=====

Ideally, we'd be able to make a "foreign" toolchain operate with the
DEVELOPER_TOOLDIR= (spelling?) option but I think that's more involved.

packaging for Darwin is a challenge since we allow are users to move stuff
where they like, and we are trying to avoid privileged installs, so no "well
known places".

As mentioned elsewhere (a more recent PR) one idea is to have a two-layer
approach, where we have a symlink to the SDK in some known place to GCC (e.g.
~/.gcc/version/darwinNN) and then take the runtime hit on updating that only
when it becomes stale.  I was experimenting with having a set of places to look
including (1) /usr/include (2) /A/Configure/Time/SDK/Path (3) xcrun --blah...

(I had a trial implementation a couple of years ago, needs dusting off).

For those of us who build for Darwin8+ it's essential to have some scheme that
allows switching SDKs since modern ones don't have support for the older
systems.

Reply via email to