bpo-45723: Add helpers for save/restore env (GH-29637)

This commit is contained in:
Erlend Egeberg Aasland 2021-11-22 09:05:06 +01:00 committed by GitHub
parent d2b55b07d2
commit db2277a114
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 72 additions and 40 deletions

View File

@ -0,0 +1,10 @@
Add ``autoconf`` helpers for saving and restoring environment variables:
* ``SAVE_ENV``: Save ``$CFLAGS``, ``$LDFLAGS``, ``$LIBS``, and
``$CPPFLAGS``.
* ``RESTORE_ENV``: Restore ``$CFLAGS``, ``$LDFLAGS``, ``$LIBS``, and
``$CPPFLAGS``.
* ``WITH_SAVE_ENV([SCRIPT])``: Run ``SCRIPT`` wrapped with ``SAVE_ENV`` and
``RESTORE_ENV``.
Patch by Erlend E. Aasland.

10
configure vendored
View File

@ -2866,6 +2866,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
if test "$srcdir" != . -a "$srcdir" != "$(pwd)"; then
# If we're building out-of-tree, we need to make sure the following
# resources get picked up before their $srcdir counterparts.
@ -11085,10 +11086,11 @@ save_CFLAGS=$CFLAGS
save_CPPFLAGS=$CPPFLAGS
save_LDFLAGS=$LDFLAGS
save_LIBS=$LIBS
CPPFLAGS="$LIBSQLITE3_CFLAGS $CFLAGS"
LDFLAGS="$LIBSQLITE3_LIBS $LDFLAGS"
ac_fn_c_check_header_mongrel "$LINENO" "sqlite3.h" "ac_cv_header_sqlite3_h" "$ac_includes_default"
CPPFLAGS="$LIBSQLITE3_CFLAGS $CFLAGS"
LDFLAGS="$LIBSQLITE3_LIBS $LDFLAGS"
ac_fn_c_check_header_mongrel "$LINENO" "sqlite3.h" "ac_cv_header_sqlite3_h" "$ac_includes_default"
if test "x$ac_cv_header_sqlite3_h" = xyes; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sqlite3_open_v2 in -lsqlite3" >&5
@ -11211,6 +11213,8 @@ CPPFLAGS=$save_CPPFLAGS
LDFLAGS=$save_LDFLAGS
LIBS=$save_LIBS
# Check for support for loadable sqlite extensions
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --enable-loadable-sqlite-extensions" >&5
$as_echo_n "checking for --enable-loadable-sqlite-extensions... " >&6; }

View File

@ -23,6 +23,32 @@ m4_ifdef(
[AC_MSG_ERROR([Please install pkgconf's m4 macro package and re-run autoreconf])]
)dnl
dnl Helpers for saving and restoring environment variables:
dnl - _SAVE_VAR([VAR]) Helper for SAVE_ENV; stores VAR as save_VAR
dnl - _RESTORE_VAR([VAR]) Helper for RESTORE_ENV; restores VAR from save_VAR
dnl - SAVE_ENV Saves CFLAGS, LDFLAGS, LIBS, and CPPFLAGS
dnl - RESTORE_ENV Restores CFLAGS, LDFLAGS, LIBS, and CPPFLAGS
dnl - WITH_SAVE_ENV([SCRIPT]) Runs SCRIPT wrapped with SAVE_ENV/RESTORE_ENV
AC_DEFUN([_SAVE_VAR], [AS_VAR_COPY([save_][$1], [$1])])dnl
AC_DEFUN([_RESTORE_VAR], [AS_VAR_COPY([$1], [save_][$1])])dnl
AC_DEFUN([SAVE_ENV],
[_SAVE_VAR([CFLAGS])]
[_SAVE_VAR([CPPFLAGS])]
[_SAVE_VAR([LDFLAGS])]
[_SAVE_VAR([LIBS])]
)dnl
AC_DEFUN([RESTORE_ENV],
[_RESTORE_VAR([CFLAGS])]
[_RESTORE_VAR([CPPFLAGS])]
[_RESTORE_VAR([LDFLAGS])]
[_RESTORE_VAR([LIBS])]
)dnl
AC_DEFUN([WITH_SAVE_ENV],
[SAVE_ENV]
[$1]
[RESTORE_ENV]
)dnl
AC_SUBST(BASECPPFLAGS)
if test "$srcdir" != . -a "$srcdir" != "$(pwd)"; then
# If we're building out-of-tree, we need to make sure the following
@ -3174,17 +3200,13 @@ PKG_CHECK_MODULES(
)
AS_VAR_APPEND([LIBSQLITE3_CFLAGS], [' -I$(srcdir)/Modules/_sqlite'])
WITH_SAVE_ENV(
dnl bpo-45774/GH-29507: The CPP check in AC_CHECK_HEADER can fail on FreeBSD,
dnl hence CPPFLAGS instead of CFLAGS. We still need to save CFLAGS, because it
dnl is touched by AC_CHECK_HEADER.
AS_VAR_COPY([save_CFLAGS], [CFLAGS])
AS_VAR_COPY([save_CPPFLAGS], [CPPFLAGS])
AS_VAR_COPY([save_LDFLAGS], [LDFLAGS])
AS_VAR_COPY([save_LIBS], [LIBS])
CPPFLAGS="$LIBSQLITE3_CFLAGS $CFLAGS"
LDFLAGS="$LIBSQLITE3_LIBS $LDFLAGS"
dnl hence CPPFLAGS instead of CFLAGS.
CPPFLAGS="$LIBSQLITE3_CFLAGS $CFLAGS"
LDFLAGS="$LIBSQLITE3_LIBS $LDFLAGS"
AC_CHECK_HEADER([sqlite3.h], [
AC_CHECK_HEADER([sqlite3.h], [
AC_CHECK_LIB([sqlite3], [sqlite3_open_v2], [
have_sqlite3=yes
AC_COMPILE_IFELSE([
@ -3199,12 +3221,8 @@ AC_CHECK_HEADER([sqlite3.h], [
AC_CHECK_LIB([sqlite3], [sqlite3_load_extension],
[have_sqlite3_load_extension=yes],
[have_sqlite3_load_extension=no])
])
AS_VAR_COPY([CFLAGS], [save_CFLAGS])
AS_VAR_COPY([CPPFLAGS], [save_CPPFLAGS])
AS_VAR_COPY([LDFLAGS], [save_LDFLAGS])
AS_VAR_COPY([LIBS], [save_LIBS])
])
)
# Check for support for loadable sqlite extensions
AC_MSG_CHECKING(for --enable-loadable-sqlite-extensions)