Back off using -isysroot on Darwin.
authorTom Lane <[email protected]>
Tue, 16 Oct 2018 20:27:15 +0000 (16:27 -0400)
committerTom Lane <[email protected]>
Tue, 16 Oct 2018 20:27:15 +0000 (16:27 -0400)
Rethink the solution applied in commit 5e2217131 to get PL/Tcl to
build on macOS Mojave.  I feared that adding -isysroot globally might
have undesirable consequences, and sure enough Jakob Egger reported
one: it complicates building extensions with a different Xcode version
than was used for the core server.  (I find that a risky proposition
in general, but apparently it works most of the time, so we shouldn't
break it if we don't have to.)

We'd already adopted the solution for PL/Perl of inserting the sysroot
path directly into the -I switches used to find Perl's headers, and we
can do the same thing for PL/Tcl by changing the -iwithsysroot switch
that Apple's tclConfig.sh reports.  This restricts the risks to PL/Perl
and PL/Tcl themselves and directly-dependent extensions, which is a lot
more pleasing in general than a global -isysroot switch.

Along the way, tighten the test to see if we need to inject the sysroot
path into $perl_includedir, as I'd speculated about upthread but not
gotten round to doing.

As before, back-patch to all supported versions.

Discussion: https://postgr.es/m/20840.1537850987@sss.pgh.pa.us

configure
configure.in
src/template/darwin

index 5768f276a8316992b18359f43916c170284422e8..66bbcce299d3bad92faa2b030ba569670c09c4f3 100755 (executable)
--- a/configure
+++ b/configure
@@ -7796,7 +7796,7 @@ $as_echo "$perl_useshrplib" >&6; }
   perl_includedir="$perl_archlibexp"
   # ... but on some macOS versions, we must look under $PG_SYSROOT instead
   if test x"$PG_SYSROOT" != x"" ; then
-    if test -d "$PG_SYSROOT$perl_archlibexp" ; then
+    if test -f "$PG_SYSROOT$perl_archlibexp/CORE/perl.h" ; then
       perl_includedir="$PG_SYSROOT$perl_archlibexp"
     fi
   fi
@@ -30257,7 +30257,12 @@ eval TCL_LIBS=\"$TCL_LIBS\"
 eval TCL_LIB_SPEC=\"$TCL_LIB_SPEC\"
 eval TCL_SHARED_BUILD=\"$TCL_SHARED_BUILD\"
 
-        # now that we have TCL_INCLUDE_SPEC, we can check for <tcl.h>
+        # Some macOS versions report an include spec that uses -iwithsysroot.
+    # We don't really want to use -isysroot, so translate that if we can.
+    if test x"$PG_SYSROOT" != x"" ; then
+        TCL_INCLUDE_SPEC="`echo "$TCL_INCLUDE_SPEC" | sed "s|-iwithsysroot */|-I $PG_SYSROOT/|"`"
+    fi
+    # now that we have TCL_INCLUDE_SPEC, we can check for <tcl.h>
     ac_save_CPPFLAGS=$CPPFLAGS
     CPPFLAGS="$TCL_INCLUDE_SPEC $CPPFLAGS"
     if test "${ac_cv_header_tcl_h+set}" = set; then
index 1511108d4707c44bf7bb15cf7f1c8c5dc53fbcef..30f09a56c6c0937cb260020402cbb5ef47657ee0 100644 (file)
@@ -884,7 +884,7 @@ if test "$with_perl" = yes; then
   perl_includedir="$perl_archlibexp"
   # ... but on some macOS versions, we must look under $PG_SYSROOT instead
   if test x"$PG_SYSROOT" != x"" ; then
-    if test -d "$PG_SYSROOT$perl_archlibexp" ; then
+    if test -f "$PG_SYSROOT$perl_archlibexp/CORE/perl.h" ; then
       perl_includedir="$PG_SYSROOT$perl_archlibexp"
     fi
   fi
@@ -1891,6 +1891,11 @@ if test "$with_tcl" = yes; then
     PGAC_EVAL_TCLCONFIGSH([$TCL_CONFIG_SH],
                           [TCL_INCLUDE_SPEC,TCL_LIB_FILE,TCL_LIBS,TCL_LIB_SPEC,TCL_SHARED_BUILD])
     AC_SUBST(TCL_SHLIB_LD_LIBS)dnl don't want to double-evaluate that one
+    # Some macOS versions report an include spec that uses -iwithsysroot.
+    # We don't really want to use -isysroot, so translate that if we can.
+    if test x"$PG_SYSROOT" != x"" ; then
+        TCL_INCLUDE_SPEC="`echo "$TCL_INCLUDE_SPEC" | sed "s|-iwithsysroot */|-I $PG_SYSROOT/|"`"
+    fi
     # now that we have TCL_INCLUDE_SPEC, we can check for <tcl.h>
     ac_save_CPPFLAGS=$CPPFLAGS
     CPPFLAGS="$TCL_INCLUDE_SPEC $CPPFLAGS"
index cff258be26bf397d116ec22ae7c45e75553c2f46..702273356693bd9413ef6629e6b2485dc57b53c4 100644 (file)
@@ -3,14 +3,15 @@
 # Note: Darwin is the original code name for macOS, also known as OS X.
 # We still use "darwin" as the port name, partly because config.guess does.
 
-# Select where system include files should be sought.
+# Select where some include files should be sought.
+# We may eventually be forced to use "-isysroot" with this value,
+# but for now, it only affects Perl and Tcl include files.
 if test x"$PG_SYSROOT" = x"" ; then
   PG_SYSROOT=`xcodebuild -version -sdk macosx Path 2>/dev/null`
 fi
+# Old xcodebuild versions may produce garbage, so validate the result.
 if test x"$PG_SYSROOT" != x"" ; then
-  if test -d "$PG_SYSROOT" ; then
-    CPPFLAGS="$CPPFLAGS -isysroot $PG_SYSROOT"
-  else
+  if test \! -d "$PG_SYSROOT" ; then
     PG_SYSROOT=""
   fi
 fi