Skip to content

Commit 5b7c7cb

Browse files
authored
bpo-45763: Detect compression build deps in configure (GH-29483)
1 parent 1855336 commit 5b7c7cb

File tree

6 files changed

+230
-11
lines changed

6 files changed

+230
-11
lines changed

Doc/whatsnew/3.11.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,9 @@ Build Changes
524524
(Contributed by Brett Cannon and Christian Heimes in :issue:`45548`,
525525
:issue:`45570`, :issue:`45571`, and :issue:`43974`.)
526526

527+
* The build dependencies for :mod:`zlib`, :mod:`bz2`, and :mod:`lzma` are now
528+
detected by :program:`configure`.
529+
(Contributed by Christian Heimes in :issue:`45763`.)
527530

528531
C API Changes
529532
=============
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The build dependencies for :mod:`zlib`, :mod:`bz2`, and :mod:`lzma` are now
2+
detected by ``configure``.

configure

Lines changed: 184 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12884,8 +12884,62 @@ $as_echo "#define HAVE_LCHFLAGS 1" >>confdefs.h
1288412884

1288512885
fi
1288612886

12887-
# Check for compression libraries
12888-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for inflateCopy in -lz" >&5
12887+
for ac_header in zlib.h
12888+
do :
12889+
ac_fn_c_check_header_mongrel "$LINENO" "zlib.h" "ac_cv_header_zlib_h" "$ac_includes_default"
12890+
if test "x$ac_cv_header_zlib_h" = xyes; then :
12891+
cat >>confdefs.h <<_ACEOF
12892+
#define HAVE_ZLIB_H 1
12893+
_ACEOF
12894+
12895+
save_LIBS="$LIBS"
12896+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for gzread in -lz" >&5
12897+
$as_echo_n "checking for gzread in -lz... " >&6; }
12898+
if ${ac_cv_lib_z_gzread+:} false; then :
12899+
$as_echo_n "(cached) " >&6
12900+
else
12901+
ac_check_lib_save_LIBS=$LIBS
12902+
LIBS="-lz $LIBS"
12903+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
12904+
/* end confdefs.h. */
12905+
12906+
/* Override any GCC internal prototype to avoid an error.
12907+
Use char because int might match the return type of a GCC
12908+
builtin and then its argument prototype would still apply. */
12909+
#ifdef __cplusplus
12910+
extern "C"
12911+
#endif
12912+
char gzread ();
12913+
int
12914+
main ()
12915+
{
12916+
return gzread ();
12917+
;
12918+
return 0;
12919+
}
12920+
_ACEOF
12921+
if ac_fn_c_try_link "$LINENO"; then :
12922+
ac_cv_lib_z_gzread=yes
12923+
else
12924+
ac_cv_lib_z_gzread=no
12925+
fi
12926+
rm -f core conftest.err conftest.$ac_objext \
12927+
conftest$ac_exeext conftest.$ac_ext
12928+
LIBS=$ac_check_lib_save_LIBS
12929+
fi
12930+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_z_gzread" >&5
12931+
$as_echo "$ac_cv_lib_z_gzread" >&6; }
12932+
if test "x$ac_cv_lib_z_gzread" = xyes; then :
12933+
cat >>confdefs.h <<_ACEOF
12934+
#define HAVE_LIBZ 1
12935+
_ACEOF
12936+
12937+
LIBS="-lz $LIBS"
12938+
12939+
fi
12940+
12941+
LIBS="$save_LIBS"
12942+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for inflateCopy in -lz" >&5
1288912943
$as_echo_n "checking for inflateCopy in -lz... " >&6; }
1289012944
if ${ac_cv_lib_z_inflateCopy+:} false; then :
1289112945
$as_echo_n "(cached) " >&6
@@ -12927,6 +12981,134 @@ $as_echo "#define HAVE_ZLIB_COPY 1" >>confdefs.h
1292712981

1292812982
fi
1292912983

12984+
LIBS="$save_LIBS"
12985+
12986+
fi
12987+
12988+
done
12989+
12990+
12991+
for ac_header in bzlib.h
12992+
do :
12993+
ac_fn_c_check_header_mongrel "$LINENO" "bzlib.h" "ac_cv_header_bzlib_h" "$ac_includes_default"
12994+
if test "x$ac_cv_header_bzlib_h" = xyes; then :
12995+
cat >>confdefs.h <<_ACEOF
12996+
#define HAVE_BZLIB_H 1
12997+
_ACEOF
12998+
12999+
save_LIBS="$LIBS"
13000+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for BZ2_bzCompress in -lbz2" >&5
13001+
$as_echo_n "checking for BZ2_bzCompress in -lbz2... " >&6; }
13002+
if ${ac_cv_lib_bz2_BZ2_bzCompress+:} false; then :
13003+
$as_echo_n "(cached) " >&6
13004+
else
13005+
ac_check_lib_save_LIBS=$LIBS
13006+
LIBS="-lbz2 $LIBS"
13007+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
13008+
/* end confdefs.h. */
13009+
13010+
/* Override any GCC internal prototype to avoid an error.
13011+
Use char because int might match the return type of a GCC
13012+
builtin and then its argument prototype would still apply. */
13013+
#ifdef __cplusplus
13014+
extern "C"
13015+
#endif
13016+
char BZ2_bzCompress ();
13017+
int
13018+
main ()
13019+
{
13020+
return BZ2_bzCompress ();
13021+
;
13022+
return 0;
13023+
}
13024+
_ACEOF
13025+
if ac_fn_c_try_link "$LINENO"; then :
13026+
ac_cv_lib_bz2_BZ2_bzCompress=yes
13027+
else
13028+
ac_cv_lib_bz2_BZ2_bzCompress=no
13029+
fi
13030+
rm -f core conftest.err conftest.$ac_objext \
13031+
conftest$ac_exeext conftest.$ac_ext
13032+
LIBS=$ac_check_lib_save_LIBS
13033+
fi
13034+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_bz2_BZ2_bzCompress" >&5
13035+
$as_echo "$ac_cv_lib_bz2_BZ2_bzCompress" >&6; }
13036+
if test "x$ac_cv_lib_bz2_BZ2_bzCompress" = xyes; then :
13037+
cat >>confdefs.h <<_ACEOF
13038+
#define HAVE_LIBBZ2 1
13039+
_ACEOF
13040+
13041+
LIBS="-lbz2 $LIBS"
13042+
13043+
fi
13044+
13045+
LIBS="$save_LIBS"
13046+
13047+
fi
13048+
13049+
done
13050+
13051+
13052+
for ac_header in lzma.h
13053+
do :
13054+
ac_fn_c_check_header_mongrel "$LINENO" "lzma.h" "ac_cv_header_lzma_h" "$ac_includes_default"
13055+
if test "x$ac_cv_header_lzma_h" = xyes; then :
13056+
cat >>confdefs.h <<_ACEOF
13057+
#define HAVE_LZMA_H 1
13058+
_ACEOF
13059+
13060+
save_LIBS="$LIBS"
13061+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for lzma_easy_encoder in -llzma" >&5
13062+
$as_echo_n "checking for lzma_easy_encoder in -llzma... " >&6; }
13063+
if ${ac_cv_lib_lzma_lzma_easy_encoder+:} false; then :
13064+
$as_echo_n "(cached) " >&6
13065+
else
13066+
ac_check_lib_save_LIBS=$LIBS
13067+
LIBS="-llzma $LIBS"
13068+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
13069+
/* end confdefs.h. */
13070+
13071+
/* Override any GCC internal prototype to avoid an error.
13072+
Use char because int might match the return type of a GCC
13073+
builtin and then its argument prototype would still apply. */
13074+
#ifdef __cplusplus
13075+
extern "C"
13076+
#endif
13077+
char lzma_easy_encoder ();
13078+
int
13079+
main ()
13080+
{
13081+
return lzma_easy_encoder ();
13082+
;
13083+
return 0;
13084+
}
13085+
_ACEOF
13086+
if ac_fn_c_try_link "$LINENO"; then :
13087+
ac_cv_lib_lzma_lzma_easy_encoder=yes
13088+
else
13089+
ac_cv_lib_lzma_lzma_easy_encoder=no
13090+
fi
13091+
rm -f core conftest.err conftest.$ac_objext \
13092+
conftest$ac_exeext conftest.$ac_ext
13093+
LIBS=$ac_check_lib_save_LIBS
13094+
fi
13095+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_lzma_lzma_easy_encoder" >&5
13096+
$as_echo "$ac_cv_lib_lzma_lzma_easy_encoder" >&6; }
13097+
if test "x$ac_cv_lib_lzma_lzma_easy_encoder" = xyes; then :
13098+
cat >>confdefs.h <<_ACEOF
13099+
#define HAVE_LIBLZMA 1
13100+
_ACEOF
13101+
13102+
LIBS="-llzma $LIBS"
13103+
13104+
fi
13105+
13106+
LIBS="$save_LIBS"
13107+
13108+
fi
13109+
13110+
done
13111+
1293013112

1293113113

1293213114

configure.ac

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3830,9 +3830,26 @@ if test "$ac_cv_have_lchflags" = yes ; then
38303830
AC_DEFINE(HAVE_LCHFLAGS, 1, [Define to 1 if you have the 'lchflags' function.])
38313831
fi
38323832

3833-
# Check for compression libraries
3834-
dnl Check if system zlib has *Copy() functions
3835-
AC_CHECK_LIB(z, inflateCopy, AC_DEFINE(HAVE_ZLIB_COPY, 1, [Define if the zlib library has inflateCopy]))
3833+
dnl Check for compression libraries
3834+
AC_CHECK_HEADERS([zlib.h], [
3835+
save_LIBS="$LIBS"
3836+
AC_CHECK_LIB([z], [gzread])
3837+
LIBS="$save_LIBS"
3838+
AC_CHECK_LIB([z], [inflateCopy], [AC_DEFINE(HAVE_ZLIB_COPY, 1, [Define if the zlib library has inflateCopy])])
3839+
LIBS="$save_LIBS"
3840+
])
3841+
3842+
AC_CHECK_HEADERS([bzlib.h], [
3843+
save_LIBS="$LIBS"
3844+
AC_CHECK_LIB([bz2], [BZ2_bzCompress])
3845+
LIBS="$save_LIBS"
3846+
])
3847+
3848+
AC_CHECK_HEADERS([lzma.h], [
3849+
save_LIBS="$LIBS"
3850+
AC_CHECK_LIB([lzma], [lzma_easy_encoder])
3851+
LIBS="$save_LIBS"
3852+
])
38363853

38373854
PY_CHECK_FUNC([hstrerror], [#include <netdb.h>])
38383855

pyconfig.h.in

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@
124124
/* Has builtin __atomic_load_n() and __atomic_store_n() functions */
125125
#undef HAVE_BUILTIN_ATOMIC
126126

127+
/* Define to 1 if you have the <bzlib.h> header file. */
128+
#undef HAVE_BZLIB_H
129+
127130
/* Define to 1 if you have the 'chflags' function. */
128131
#undef HAVE_CHFLAGS
129132

@@ -580,6 +583,9 @@
580583
/* Define to 1 if you have the `lchown' function. */
581584
#undef HAVE_LCHOWN
582585

586+
/* Define to 1 if you have the `bz2' library (-lbz2). */
587+
#undef HAVE_LIBBZ2
588+
583589
/* Define to 1 if you have the `dl' library (-ldl). */
584590
#undef HAVE_LIBDL
585591

@@ -592,6 +598,9 @@
592598
/* Define to 1 if you have the <libintl.h> header file. */
593599
#undef HAVE_LIBINTL_H
594600

601+
/* Define to 1 if you have the `lzma' library (-llzma). */
602+
#undef HAVE_LIBLZMA
603+
595604
/* Define to build the readline module. */
596605
#undef HAVE_LIBREADLINE
597606

@@ -607,6 +616,9 @@
607616
/* Define to 1 if you have the `uuid' library (-luuid). */
608617
#undef HAVE_LIBUUID
609618

619+
/* Define to 1 if you have the `z' library (-lz). */
620+
#undef HAVE_LIBZ
621+
610622
/* Define if you have the 'link' function. */
611623
#undef HAVE_LINK
612624

@@ -670,6 +682,9 @@
670682
/* Define to 1 if you have the `lutimes' function. */
671683
#undef HAVE_LUTIMES
672684

685+
/* Define to 1 if you have the <lzma.h> header file. */
686+
#undef HAVE_LZMA_H
687+
673688
/* Define to 1 if you have the `madvise' function. */
674689
#undef HAVE_MADVISE
675690

@@ -1342,6 +1357,9 @@
13421357
/* Define if the zlib library has inflateCopy */
13431358
#undef HAVE_ZLIB_COPY
13441359

1360+
/* Define to 1 if you have the <zlib.h> header file. */
1361+
#undef HAVE_ZLIB_H
1362+
13451363
/* Define to 1 if you have the `_getpty' function. */
13461364
#undef HAVE__GETPTY
13471365

setup.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,10 +1634,7 @@ def detect_platform_specific_exts(self):
16341634

16351635
def detect_compress_exts(self):
16361636
# Andrew Kuchling's zlib module.
1637-
have_zlib = (
1638-
find_file('zlib.h', self.inc_dirs, []) is not None and
1639-
self.compiler.find_library_file(self.lib_dirs, 'z')
1640-
)
1637+
have_zlib = sysconfig.get_config_var("HAVE_LIBZ")
16411638
if have_zlib:
16421639
self.add(Extension('zlib', ['zlibmodule.c'],
16431640
libraries=['z']))
@@ -1657,14 +1654,14 @@ def detect_compress_exts(self):
16571654
libraries=libraries))
16581655

16591656
# Gustavo Niemeyer's bz2 module.
1660-
if (self.compiler.find_library_file(self.lib_dirs, 'bz2')):
1657+
if sysconfig.get_config_var("HAVE_LIBBZ2"):
16611658
self.add(Extension('_bz2', ['_bz2module.c'],
16621659
libraries=['bz2']))
16631660
else:
16641661
self.missing.append('_bz2')
16651662

16661663
# LZMA compression support.
1667-
if self.compiler.find_library_file(self.lib_dirs, 'lzma'):
1664+
if sysconfig.get_config_var("HAVE_LIBLZMA"):
16681665
self.add(Extension('_lzma', ['_lzmamodule.c'],
16691666
libraries=['lzma']))
16701667
else:

0 commit comments

Comments
 (0)