Skip to content

Commit 7b23ebf

Browse files
committed
autotools: use pkg-config and Homebrew when looking for libcrypto.
Grab the stuff from libpcap's configure script that looks for libssl (and libcrypto) and adapt it to look for libcrypto. his includes some macros to check using pkg-config (and other macros, such as macros to save and restore CFLAGS, LIBS, and LDFLAGS; any resemblance between their names and the cmake_push_check_state() and cmake_pop_check_state() commands is *entirely* coincidental :-)). Instead of checking for DES_cbc_encrypt(), which we don't use, to determine whether the libcrypto we found is usable, check for EVP_CIPHER_CTX_block_size(), which we *do* use. (We also check whether the openssl/evp.h header exists; if it doesn't, we might have found the libcrypto that Apple bundles with macOS, for which they do *NOT* provide the header in newer versions of Xcode.) See also #1174. This means that we don't need to check whether we have openssl/evp.h at compile time - now, if we don't, we don't even set HAVE_LIBCRYPTO, so there's no need to check HAVE_OPENSSL_EVP_H. (cherry picked from commit 749988b)
1 parent 7f382f4 commit 7b23ebf

File tree

4 files changed

+499
-57
lines changed

4 files changed

+499
-57
lines changed

aclocal.m4

+286-1
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,29 @@ AC_DEFUN(AC_LBL_C_INIT,
207207
fi
208208
])
209209

210+
dnl
211+
dnl Save the values of various variables that affect compilation and
212+
dnl linking, and that we don't ourselves modify persistently; done
213+
dnl before a test involving compiling or linking is done, so that we
214+
dnl can restore those variables after the test is done.
215+
dnl
216+
AC_DEFUN(AC_LBL_SAVE_CHECK_STATE,
217+
[
218+
save_CFLAGS="$CFLAGS"
219+
save_LIBS="$LIBS"
220+
save_LDFLAGS="$LDFLAGS"
221+
])
222+
223+
dnl
224+
dnl Restore the values of variables saved by AC_LBL_SAVE_CHECK_STATE.
225+
dnl
226+
AC_DEFUN(AC_LBL_RESTORE_CHECK_STATE,
227+
[
228+
CFLAGS="$save_CFLAGS"
229+
LIBS="$save_LIBS"
230+
LDFLAGS="$save_LDFLAGS"
231+
])
232+
210233
dnl
211234
dnl Check whether the compiler option specified as the second argument
212235
dnl is supported by the compiler and, if so, add it to the macro
@@ -517,7 +540,6 @@ AC_DEFUN(AC_LBL_LIBPCAP,
517540
# We didn't find a local libpcap.
518541
# Look for an installed pkg-config.
519542
#
520-
AC_PATH_TOOL(PKG_CONFIG, pkg-config)
521543
if test -n "$PKG_CONFIG" ; then
522544
#
523545
# We have it. Are there .pc files for libpcap?
@@ -1210,3 +1232,266 @@ AC_DEFUN(AC_LBL_SSLEAY,
12101232
incdir="-I$1/include"
12111233
fi
12121234
])
1235+
1236+
m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])])
1237+
dnl pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
1238+
dnl serial 11 (pkg-config-0.29)
1239+
dnl
1240+
dnl Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
1241+
dnl Copyright © 2012-2015 Dan Nicholson <dbn.lists@gmail.com>
1242+
dnl
1243+
dnl This program is free software; you can redistribute it and/or modify
1244+
dnl it under the terms of the GNU General Public License as published by
1245+
dnl the Free Software Foundation; either version 2 of the License, or
1246+
dnl (at your option) any later version.
1247+
dnl
1248+
dnl This program is distributed in the hope that it will be useful, but
1249+
dnl WITHOUT ANY WARRANTY; without even the implied warranty of
1250+
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1251+
dnl General Public License for more details.
1252+
dnl
1253+
dnl You should have received a copy of the GNU General Public License
1254+
dnl along with this program; if not, write to the Free Software
1255+
dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1256+
dnl 02111-1307, USA.
1257+
dnl
1258+
dnl As a special exception to the GNU General Public License, if you
1259+
dnl distribute this file as part of a program that contains a
1260+
dnl configuration script generated by Autoconf, you may include it under
1261+
dnl the same distribution terms that you use for the rest of that
1262+
dnl program.
1263+
1264+
dnl PKG_PREREQ(MIN-VERSION)
1265+
dnl -----------------------
1266+
dnl Since: 0.29
1267+
dnl
1268+
dnl Verify that the version of the pkg-config macros are at least
1269+
dnl MIN-VERSION. Unlike PKG_PROG_PKG_CONFIG, which checks the user's
1270+
dnl installed version of pkg-config, this checks the developer's version
1271+
dnl of pkg.m4 when generating configure.
1272+
dnl
1273+
dnl To ensure that this macro is defined, also add:
1274+
dnl m4_ifndef([PKG_PREREQ],
1275+
dnl [m4_fatal([must install pkg-config 0.29 or later before running autoconf/autogen])])
1276+
dnl
1277+
dnl See the "Since" comment for each macro you use to see what version
1278+
dnl of the macros you require.
1279+
m4_defun([PKG_PREREQ],
1280+
[m4_define([PKG_MACROS_VERSION], [0.29])
1281+
m4_if(m4_version_compare(PKG_MACROS_VERSION, [$1]), -1,
1282+
[m4_fatal([pkg.m4 version $1 or higher is required but ]PKG_MACROS_VERSION[ found])])
1283+
])dnl PKG_PREREQ
1284+
1285+
dnl PKG_PROG_PKG_CONFIG([MIN-VERSION])
1286+
dnl ----------------------------------
1287+
dnl Since: 0.16
1288+
dnl
1289+
dnl Search for the pkg-config tool and set the PKG_CONFIG variable to
1290+
dnl first found in the path. Checks that the version of pkg-config found
1291+
dnl is at least MIN-VERSION. If MIN-VERSION is not specified, 0.17.0 is
1292+
dnl used since that's the first version where --static was supported.
1293+
AC_DEFUN([PKG_PROG_PKG_CONFIG],
1294+
[m4_pattern_forbid([^_?PKG_[A-Z_]+$])
1295+
m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$])
1296+
m4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$])
1297+
AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
1298+
AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
1299+
AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
1300+
1301+
if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
1302+
AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
1303+
fi
1304+
if test -n "$PKG_CONFIG"; then
1305+
_pkg_min_version=m4_default([$1], [0.17.0])
1306+
AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
1307+
if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
1308+
AC_MSG_RESULT([yes])
1309+
else
1310+
AC_MSG_RESULT([no])
1311+
PKG_CONFIG=""
1312+
fi
1313+
fi[]dnl
1314+
])dnl PKG_PROG_PKG_CONFIG
1315+
1316+
dnl PKG_CHECK_EXISTS(MODULE, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
1317+
dnl -------------------------------------------------------------------
1318+
dnl Since: 0.18
1319+
dnl
1320+
dnl Check to see whether a particular module exists. Similar to
1321+
dnl PKG_CHECK_MODULE(), but does not set variables or print errors.
1322+
AC_DEFUN([PKG_CHECK_EXISTS],
1323+
[
1324+
if test -n "$PKG_CONFIG" && \
1325+
AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
1326+
m4_default([$2], [:])
1327+
m4_ifvaln([$3], [else
1328+
$3])dnl
1329+
fi])
1330+
1331+
dnl _PKG_CONFIG_WITH_FLAGS([VARIABLE], [FLAGS], [MODULE])
1332+
dnl ---------------------------------------------
1333+
dnl Internal wrapper calling pkg-config via PKG_CONFIG and, if
1334+
dnl pkg-config fails, reporting the error and quitting.
1335+
m4_define([_PKG_CONFIG_WITH_FLAGS],
1336+
[if test ! -n "$$1"; then
1337+
$1=`$PKG_CONFIG $2 "$3" 2>/dev/null`
1338+
if test "x$?" != "x0"; then
1339+
#
1340+
# That failed - report an error.
1341+
# Re-run the command, telling pkg-config to print an error
1342+
# message, capture the error message, and report it.
1343+
# This causes the configuration script to fail, as it means
1344+
# the script is almost certainly doing something wrong.
1345+
#
1346+
_PKG_SHORT_ERRORS_SUPPORTED
1347+
if test $_pkg_short_errors_supported = yes; then
1348+
_pkg_error_string=`$PKG_CONFIG --short-errors --print-errors $2 "$3" 2>&1`
1349+
else
1350+
_pkg_error_string=`$PKG_CONFIG --print-errors $2 "$3" 2>&1`
1351+
fi
1352+
AC_MSG_ERROR([$PKG_CONFIG $2 "$3" failed: $_pkg_error_string])
1353+
fi
1354+
fi[]dnl
1355+
])dnl _PKG_CONFIG_WITH_FLAGS
1356+
1357+
1358+
dnl _PKG_CONFIG([VARIABLE], [FLAGS], [MODULE])
1359+
dnl ---------------------------------------------
1360+
dnl Internal wrapper calling pkg-config via PKG_CONFIG and setting
1361+
dnl pkg_failed based on the result.
1362+
m4_define([_PKG_CONFIG],
1363+
[if test -n "$$1"; then
1364+
pkg_cv_[]$1="$$1"
1365+
elif test -n "$PKG_CONFIG"; then
1366+
PKG_CHECK_EXISTS([$3],
1367+
[pkg_cv_[]$1=`$PKG_CONFIG $2 "$3" 2>/dev/null`
1368+
test "x$?" != "x0" && pkg_failed=yes ],
1369+
[pkg_failed=yes])
1370+
else
1371+
pkg_failed=untried
1372+
fi[]dnl
1373+
])dnl _PKG_CONFIG
1374+
1375+
dnl _PKG_SHORT_ERRORS_SUPPORTED
1376+
dnl ---------------------------
1377+
dnl Internal check to see if pkg-config supports short errors.
1378+
AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
1379+
[
1380+
if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
1381+
_pkg_short_errors_supported=yes
1382+
else
1383+
_pkg_short_errors_supported=no
1384+
fi[]dnl
1385+
])dnl _PKG_SHORT_ERRORS_SUPPORTED
1386+
1387+
1388+
dnl PKG_CHECK_MODULE(VARIABLE-PREFIX, MODULE, [ACTION-IF-FOUND],
1389+
dnl [ACTION-IF-NOT-FOUND])
1390+
dnl --------------------------------------------------------------
1391+
dnl Since: 0.4.0
1392+
AC_DEFUN([PKG_CHECK_MODULE],
1393+
[
1394+
AC_MSG_CHECKING([for $2 with pkg-config])
1395+
if test -n "$PKG_CONFIG"; then
1396+
AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $2, overriding pkg-config])dnl
1397+
AC_ARG_VAR([$1][_LIBS], [linker flags for $2, overriding pkg-config])dnl
1398+
AC_ARG_VAR([$1][_LIBS_STATIC], [static-link linker flags for $2, overriding pkg-config])dnl
1399+
1400+
if AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$2"]); then
1401+
#
1402+
# The package was found, so try to get its C flags and
1403+
# libraries.
1404+
#
1405+
AC_MSG_RESULT([found])
1406+
_PKG_CONFIG_WITH_FLAGS([$1][_CFLAGS], [--cflags], [$2])
1407+
_PKG_CONFIG_WITH_FLAGS([$1][_LIBS], [--libs], [$2])
1408+
_PKG_CONFIG_WITH_FLAGS([$1][_LIBS_STATIC], [--libs --static], [$2])
1409+
m4_default([$3], [:])
1410+
else
1411+
AC_MSG_RESULT([not found])
1412+
m4_default([$4], [:])
1413+
fi
1414+
else
1415+
# No pkg-config, so obviously not found with pkg-config.
1416+
AC_MSG_RESULT([pkg-config not found])
1417+
m4_default([$4], [:])
1418+
fi
1419+
])dnl PKG_CHECK_MODULE
1420+
1421+
1422+
dnl PKG_CHECK_MODULE_STATIC(VARIABLE-PREFIX, MODULE, [ACTION-IF-FOUND],
1423+
dnl [ACTION-IF-NOT-FOUND])
1424+
dnl ---------------------------------------------------------------------
1425+
dnl Since: 0.29
1426+
dnl
1427+
dnl Checks for existence of MODULE and gathers its build flags with
1428+
dnl static libraries enabled. Sets VARIABLE-PREFIX_CFLAGS from --cflags
1429+
dnl and VARIABLE-PREFIX_LIBS from --libs.
1430+
AC_DEFUN([PKG_CHECK_MODULE_STATIC],
1431+
[
1432+
_save_PKG_CONFIG=$PKG_CONFIG
1433+
PKG_CONFIG="$PKG_CONFIG --static"
1434+
PKG_CHECK_MODULE($@)
1435+
PKG_CONFIG=$_save_PKG_CONFIG[]dnl
1436+
])dnl PKG_CHECK_MODULE_STATIC
1437+
1438+
1439+
dnl PKG_INSTALLDIR([DIRECTORY])
1440+
dnl -------------------------
1441+
dnl Since: 0.27
1442+
dnl
1443+
dnl Substitutes the variable pkgconfigdir as the location where a module
1444+
dnl should install pkg-config .pc files. By default the directory is
1445+
dnl $libdir/pkgconfig, but the default can be changed by passing
1446+
dnl DIRECTORY. The user can override through the --with-pkgconfigdir
1447+
dnl parameter.
1448+
AC_DEFUN([PKG_INSTALLDIR],
1449+
[m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])])
1450+
m4_pushdef([pkg_description],
1451+
[pkg-config installation directory @<:@]pkg_default[@:>@])
1452+
AC_ARG_WITH([pkgconfigdir],
1453+
[AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],,
1454+
[with_pkgconfigdir=]pkg_default)
1455+
AC_SUBST([pkgconfigdir], [$with_pkgconfigdir])
1456+
m4_popdef([pkg_default])
1457+
m4_popdef([pkg_description])
1458+
])dnl PKG_INSTALLDIR
1459+
1460+
1461+
dnl PKG_NOARCH_INSTALLDIR([DIRECTORY])
1462+
dnl --------------------------------
1463+
dnl Since: 0.27
1464+
dnl
1465+
dnl Substitutes the variable noarch_pkgconfigdir as the location where a
1466+
dnl module should install arch-independent pkg-config .pc files. By
1467+
dnl default the directory is $datadir/pkgconfig, but the default can be
1468+
dnl changed by passing DIRECTORY. The user can override through the
1469+
dnl --with-noarch-pkgconfigdir parameter.
1470+
AC_DEFUN([PKG_NOARCH_INSTALLDIR],
1471+
[m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])])
1472+
m4_pushdef([pkg_description],
1473+
[pkg-config arch-independent installation directory @<:@]pkg_default[@:>@])
1474+
AC_ARG_WITH([noarch-pkgconfigdir],
1475+
[AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],,
1476+
[with_noarch_pkgconfigdir=]pkg_default)
1477+
AC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir])
1478+
m4_popdef([pkg_default])
1479+
m4_popdef([pkg_description])
1480+
])dnl PKG_NOARCH_INSTALLDIR
1481+
1482+
1483+
dnl PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,
1484+
dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
1485+
dnl -------------------------------------------
1486+
dnl Since: 0.28
1487+
dnl
1488+
dnl Retrieves the value of the pkg-config variable for the given module.
1489+
AC_DEFUN([PKG_CHECK_VAR],
1490+
[
1491+
AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl
1492+
1493+
_PKG_CONFIG([$1], [--variable="][$3]["], [$2])
1494+
AS_VAR_COPY([$1], [pkg_cv_][$1])
1495+
1496+
AS_VAR_IF([$1], [""], [$5], [$4])dnl
1497+
])dnl PKG_CHECK_VAR

0 commit comments

Comments
 (0)