Yet further rethinking of build changes for macOS Mojave.
authorTom Lane
Fri, 2 Nov 2018 22:54:00 +0000 (18:54 -0400)
committerTom Lane
Fri, 2 Nov 2018 22:54:00 +0000 (18:54 -0400)
The solution arrived at in commit e74dd00f5 presumes that the compiler
has a suitable default -isysroot setting ... but further experience
shows that in many combinations of macOS version, XCode version, Xcode
command line tools version, and phase of the moon, Apple's compiler
will *not* supply a default -isysroot value.

We could potentially go back to the approach used in commit 68fc227dd,
but I don't have a lot of faith in the reliability or life expectancy of
that either.  Let's just revert to the approach already shipped in 11.0,
namely specifying an -isysroot switch globally.  As a partial response to
the concerns raised by Jakob Egger, adjust the contents of Makefile.global
to look like

CPPFLAGS = -isysroot $(PG_SYSROOT) ...
PG_SYSROOT = /path/to/sysroot

This allows overriding the sysroot path at build time in a relatively
painless way.

Add documentation to installation.sgml about how to use the PG_SYSROOT
option.  I also took the opportunity to document how to work around
macOS's "System Integrity Protection" feature.

As before, back-patch to all supported versions.

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

configure
configure.in
doc/src/sgml/installation.sgml
src/Makefile.global.in
src/template/darwin

index feee12b538261a5b9cbe65027a9144be02099e31..6c93ec144ee8dac5f898e91c1d0e6ef233ac96bc 100755 (executable)
--- a/configure
+++ b/configure
@@ -627,6 +627,7 @@ ac_includes_default="\
 
 ac_subst_vars='LTLIBOBJS
 vpath_build
+PG_SYSROOT
 PG_VERSION_NUM
 PROVE
 OSX
@@ -15321,6 +15322,15 @@ _ACEOF
 
 
 
+# If we are inserting PG_SYSROOT into CPPFLAGS, do so symbolically not
+# literally, so that it's possible to override it at build time using
+# a command like "make ... PG_SYSROOT=path".  This has to be done after
+# we've finished all configure checks that depend on CPPFLAGS.
+if test x"$PG_SYSROOT" != x; then
+  CPPFLAGS=`echo "$CPPFLAGS" | sed -e "s| $PG_SYSROOT | \\\$(PG_SYSROOT) |"`
+fi
+
+
 
 # Begin output steps
 
index 68486fd9fea6637bf1206d6677807731fbb10e07..681ca6c6d7397b3f49e8b6457bd0b70f7e329aca 100644 (file)
@@ -2072,6 +2072,15 @@ $AWK '{printf "%d%02d%02d", $1, $2, (NF >= 3) ? $3 : 0}'`"]
 AC_DEFINE_UNQUOTED(PG_VERSION_NUM, $PG_VERSION_NUM, [PostgreSQL version as a number])
 AC_SUBST(PG_VERSION_NUM)
 
+# If we are inserting PG_SYSROOT into CPPFLAGS, do so symbolically not
+# literally, so that it's possible to override it at build time using
+# a command like "make ... PG_SYSROOT=path".  This has to be done after
+# we've finished all configure checks that depend on CPPFLAGS.
+if test x"$PG_SYSROOT" != x; then
+  CPPFLAGS=`echo "$CPPFLAGS" | sed -e "s| $PG_SYSROOT | \\\$(PG_SYSROOT) |"`
+fi
+AC_SUBST(PG_SYSROOT)
+
 
 # Begin output steps
 
index 4014b7bae4527e55e8f076655d00d9a6aa7a1e7e..cbf059534fd76d7401a8d27c6b40884a991d4c9a 100644 (file)
@@ -2594,6 +2594,57 @@ PHSS_30849  s700_800 u2comp/be/plugin library Patch
    
   
 
+  
+   macOS
+
+   
+    macOS
+    installation on
+   
+
+   
+    On recent macOS releases, it's necessary to
+    embed the sysroot path in the include switches used to
+    find some system header files.  This results in the outputs of
+    the configure script varying depending on
+    which SDK version was used during configure.
+    That shouldn't pose any problem in simple scenarios, but if you are
+    trying to do something like building an extension on a different machine
+    than the server code was built on, you may need to force use of a
+    different sysroot path.  To do that, set PG_SYSROOT,
+    for example
+
+make PG_SYSROOT=/desired/path all
+
+    To find out the appropriate path on your machine, run
+
+xcodebuild -version -sdk macosx Path
+
+    Note that building an extension using a different sysroot version than
+    was used to build the core server is not really recommended; in the
+    worst case it could result in hard-to-debug ABI inconsistencies.
+   
+
+   
+    You can also select a non-default sysroot path when configuring, by
+    specifying PG_SYSROOT
+    to configure:
+
+./configure ... PG_SYSROOT=/desired/path
+
+   
+
+   
+    macOS's System Integrity
+    Protection (SIP) feature breaks make check,
+    because it prevents passing the needed setting
+    of DYLD_LIBRARY_PATH down to the executables being
+    tested.  You can work around that by doing make
+    install before make check.
+    Most Postgres developers just turn off SIP, though.
+   
+  
+
   
    MinGW/Native Windows
 
index 363b643f72272b9069494fa7336f23bee08122a7..be22885f400c4830d0e8f0e8207a92e8d1ac5a09 100644 (file)
@@ -226,6 +226,7 @@ PTHREAD_LIBS        = @PTHREAD_LIBS@
 
 CPP = @CPP@
 CPPFLAGS = @CPPFLAGS@
+PG_SYSROOT = @PG_SYSROOT@
 
 ifdef PGXS
 override CPPFLAGS := -I$(includedir_server) -I$(includedir_internal) $(CPPFLAGS)
index 159d8bb12750f698bd48e6f0ae0a53f958aca3b9..c05adca0bfbec7bba7a6551d4edf0ea0bf932d49 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.
 
-# Some configure tests require explicit knowledge of where the Xcode "sysroot"
-# is.  We try to avoid having this leak into configure's results, though.
+# Select where system include files should be sought.
 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
+  if test -d "$PG_SYSROOT" ; then
+    CPPFLAGS="-isysroot $PG_SYSROOT $CPPFLAGS"
+  else
     PG_SYSROOT=""
   fi
 fi