I wrote:
> Peter Eisentraut <[email protected]> writes:
>> On 01/11/2018 22:17, Tom Lane wrote:
>>> The other idea that's occurred to me is to go back to the scheme of
>>> commit 68fc227dd, where we inject the sysroot path into just the -I
>>> switches used for PL/Perl and PL/Tcl. We could improve on that
>>> commit by injecting it symbolically similar to what I did here, ie
>>> what ends up in the configure output is
>> How does that work when building against a non-system Perl or Tcl?
> It does nothing, because configure will not find that it needs to
> inject any sysroot reference in order to find such a Perl or Tcl's
> headers.
Here's a lightly-tested patch for that approach.
regards, tom lane
diff --git a/configure b/configure
index 43ae8c8..db50751 100755
*** a/configure
--- b/configure
*************** CPP
*** 731,736 ****
--- 731,737 ----
BITCODE_CXXFLAGS
BITCODE_CFLAGS
CFLAGS_VECTOR
+ PG_SYSROOT
LLVM_BINPATH
LLVM_CXXFLAGS
LLVM_CFLAGS
*************** unset CXXFLAGS
*** 5261,5266 ****
--- 5262,5270 ----
#
. "$srcdir/src/template/$template" || exit
+ # Record PG_SYSROOT in Makefile.global, if set by user or template.
+
+
# C[XX]FLAGS are selected so:
# If the user specifies something in the environment, that is used.
# else: If the template file set something, that is used.
*************** PL/Perl." "$LINENO" 5
*** 9776,9786 ****
fi
# On most platforms, archlibexp is also where the Perl include files live ...
perl_includespec="-I$perl_archlibexp/CORE"
! # ... but on newer macOS versions, we must use -iwithsysroot to look
! # under $PG_SYSROOT
if test \! -f "$perl_archlibexp/CORE/perl.h" ; then
if test -f "$PG_SYSROOT$perl_archlibexp/CORE/perl.h" ; then
! perl_includespec="-iwithsysroot $perl_archlibexp/CORE"
fi
fi
--- 9780,9789 ----
fi
# On most platforms, archlibexp is also where the Perl include files live ...
perl_includespec="-I$perl_archlibexp/CORE"
! # ... but on newer macOS versions, we must look under $PG_SYSROOT instead
if test \! -f "$perl_archlibexp/CORE/perl.h" ; then
if test -f "$PG_SYSROOT$perl_archlibexp/CORE/perl.h" ; then
! perl_includespec="-I$PG_SYSROOT$perl_archlibexp/CORE"
fi
fi
*************** eval TCL_SHARED_BUILD=\"$TCL_SHARED_BUIL
*** 18115,18120 ****
--- 18118,18128 ----
as_fn_error $? "cannot build PL/Tcl because Tcl is not a shared library
Use --without-tcl to disable building PL/Tcl." "$LINENO" 5
fi
+ # 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"
*************** fi
*** 18127,18132 ****
--- 18135,18147 ----
CPPFLAGS=$ac_save_CPPFLAGS
+ # If we are inserting PG_SYSROOT into TCL_INCLUDE_SPEC, 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 TCL_INCLUDE_SPEC.
+ if test x"$PG_SYSROOT" != x; then
+ TCL_INCLUDE_SPEC=`echo "$TCL_INCLUDE_SPEC" | sed -e "s|-I$PG_SYSROOT/|-I\\\$(PG_SYSROOT)/|"`
+ fi
fi
# check for <perl.h>
*************** rm -f core conftest.err conftest.$ac_obj
*** 18176,18181 ****
--- 18191,18203 ----
conftest$ac_exeext conftest.$ac_ext
LIBS=$pgac_save_LIBS
CPPFLAGS=$ac_save_CPPFLAGS
+ # If we are inserting PG_SYSROOT into perl_includespec, 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 perl_includespec.
+ if test x"$PG_SYSROOT" != x; then
+ perl_includespec=`echo "$perl_includespec" | sed -e "s|-I$PG_SYSROOT/|-I\\\$(PG_SYSROOT)/|"`
+ fi
fi
# check for <Python.h>
diff --git a/configure.in b/configure.in
index 519ecd5..b895f7d 100644
*** a/configure.in
--- b/configure.in
*************** unset CXXFLAGS
*** 404,409 ****
--- 404,412 ----
#
. "$srcdir/src/template/$template" || exit
+ # Record PG_SYSROOT in Makefile.global, if set by user or template.
+ AC_SUBST(PG_SYSROOT)
+
# C[XX]FLAGS are selected so:
# If the user specifies something in the environment, that is used.
# else: If the template file set something, that is used.
*************** PL/Perl.])
*** 1046,1056 ****
fi
# On most platforms, archlibexp is also where the Perl include files live ...
perl_includespec="-I$perl_archlibexp/CORE"
! # ... but on newer macOS versions, we must use -iwithsysroot to look
! # under $PG_SYSROOT
if test \! -f "$perl_archlibexp/CORE/perl.h" ; then
if test -f "$PG_SYSROOT$perl_archlibexp/CORE/perl.h" ; then
! perl_includespec="-iwithsysroot $perl_archlibexp/CORE"
fi
fi
AC_SUBST(perl_includespec)dnl
--- 1049,1058 ----
fi
# On most platforms, archlibexp is also where the Perl include files live ...
perl_includespec="-I$perl_archlibexp/CORE"
! # ... but on newer macOS versions, we must look under $PG_SYSROOT instead
if test \! -f "$perl_archlibexp/CORE/perl.h" ; then
if test -f "$PG_SYSROOT$perl_archlibexp/CORE/perl.h" ; then
! perl_includespec="-I$PG_SYSROOT$perl_archlibexp/CORE"
fi
fi
AC_SUBST(perl_includespec)dnl
*************** if test "$with_tcl" = yes; then
*** 2212,2222 ****
--- 2214,2236 ----
AC_MSG_ERROR([cannot build PL/Tcl because Tcl is not a shared library
Use --without-tcl to disable building PL/Tcl.])
fi
+ # 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"
AC_CHECK_HEADER(tcl.h, [], [AC_MSG_ERROR([header file <tcl.h> is required for Tcl])])
CPPFLAGS=$ac_save_CPPFLAGS
+ # If we are inserting PG_SYSROOT into TCL_INCLUDE_SPEC, 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 TCL_INCLUDE_SPEC.
+ if test x"$PG_SYSROOT" != x; then
+ TCL_INCLUDE_SPEC=`echo "$TCL_INCLUDE_SPEC" | sed -e "s|-I$PG_SYSROOT/|-I\\\$(PG_SYSROOT)/|"`
+ fi
fi
# check for <perl.h>
*************** if test "$with_perl" = yes; then
*** 2241,2246 ****
--- 2255,2267 ----
AC_MSG_ERROR([libperl library is required for Perl])])
LIBS=$pgac_save_LIBS
CPPFLAGS=$ac_save_CPPFLAGS
+ # If we are inserting PG_SYSROOT into perl_includespec, 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 perl_includespec.
+ if test x"$PG_SYSROOT" != x; then
+ perl_includespec=`echo "$perl_includespec" | sed -e "s|-I$PG_SYSROOT/|-I\\\$(PG_SYSROOT)/|"`
+ fi
fi
# check for <Python.h>
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index bdf394b..2f8c869 100644
*** a/src/Makefile.global.in
--- b/src/Makefile.global.in
*************** host_tuple = @host@
*** 496,501 ****
--- 496,504 ----
host_os = @host_os@
host_cpu = @host_cpu@
+ # On macOS, we may need to find include files here
+ PG_SYSROOT = @PG_SYSROOT@
+
# Make HAVE_IPV6 available for initdb script creation
HAVE_IPV6= @HAVE_IPV6@
diff --git a/src/template/darwin b/src/template/darwin
index 159d8bb..7022733 100644
*** a/src/template/darwin
--- b/src/template/darwin
***************
*** 3,10 ****
# 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.
if test x"$PG_SYSROOT" = x"" ; then
PG_SYSROOT=`xcodebuild -version -sdk macosx Path 2>/dev/null`
fi
--- 3,11 ----
# 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 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