Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Misc/NEWS.d/next/Build/2021-11-19-15-42-27.bpo-45723.vwIJWI.rst
Original file line number Diff line number Diff line change
@@ -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.
26 changes: 15 additions & 11 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -11085,13 +11086,14 @@ 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
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sqlite3_open_v2 in -lsqlite3" >&5
$as_echo_n "checking for sqlite3_open_v2 in -lsqlite3... " >&6; }
if ${ac_cv_lib_sqlite3_sqlite3_open_v2+:} false; then :
$as_echo_n "(cached) " >&6
Expand Down Expand Up @@ -11129,15 +11131,15 @@ fi
$as_echo "$ac_cv_lib_sqlite3_sqlite3_open_v2" >&6; }
if test "x$ac_cv_lib_sqlite3_sqlite3_open_v2" = xyes; then :

have_sqlite3=yes
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
have_sqlite3=yes
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */


#include <sqlite3.h>
#if SQLITE_VERSION_NUMBER < 3007015
# error "SQLite 3.7.15 or higher required"
#endif
#include <sqlite3.h>
#if SQLITE_VERSION_NUMBER < 3007015
# error "SQLite 3.7.15 or higher required"
#endif

int
main ()
Expand All @@ -11159,7 +11161,7 @@ else
have_sqlite3=no
fi

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sqlite3_load_extension in -lsqlite3" >&5
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sqlite3_load_extension in -lsqlite3" >&5
$as_echo_n "checking for sqlite3_load_extension in -lsqlite3... " >&6; }
if ${ac_cv_lib_sqlite3_sqlite3_load_extension+:} false; then :
$as_echo_n "(cached) " >&6
Expand Down Expand Up @@ -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; }
Expand Down
78 changes: 48 additions & 30 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -3174,37 +3200,29 @@ 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"

AC_CHECK_HEADER([sqlite3.h], [
AC_CHECK_LIB([sqlite3], [sqlite3_open_v2], [
have_sqlite3=yes
AC_COMPILE_IFELSE([
AC_LANG_PROGRAM([
#include <sqlite3.h>
#if SQLITE_VERSION_NUMBER < 3007015
# error "SQLite 3.7.15 or higher required"
#endif
], [])
], [have_supported_sqlite3=yes], [have_supported_sqlite3=no])
], [have_sqlite3=no])
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])
dnl hence CPPFLAGS instead of CFLAGS.
CPPFLAGS="$LIBSQLITE3_CFLAGS $CFLAGS"
LDFLAGS="$LIBSQLITE3_LIBS $LDFLAGS"

AC_CHECK_HEADER([sqlite3.h], [
AC_CHECK_LIB([sqlite3], [sqlite3_open_v2], [
have_sqlite3=yes
AC_COMPILE_IFELSE([
AC_LANG_PROGRAM([
#include <sqlite3.h>
#if SQLITE_VERSION_NUMBER < 3007015
# error "SQLite 3.7.15 or higher required"
#endif
], [])
], [have_supported_sqlite3=yes], [have_supported_sqlite3=no])
], [have_sqlite3=no])
AC_CHECK_LIB([sqlite3], [sqlite3_load_extension],
[have_sqlite3_load_extension=yes],
[have_sqlite3_load_extension=no])
])
)

# Check for support for loadable sqlite extensions
AC_MSG_CHECKING(for --enable-loadable-sqlite-extensions)
Expand Down