If we copy this code, let's at least make sure we update
it every decade ;)
I also considered removing it. However, then autoconf
can't be run on systems without pkg-config installed
anymore. While that is very unusual, didn't see a good
reason to break that.
Change-Id: I34e96a225446693f401549d86d872c02427ef7d5
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Arne Schwabe <arne-openvpn@rfc2549.org>
Message-Id: <20240506160413.7189-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg28631.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
| ... | ... |
@@ -1,29 +1,60 @@ |
| 1 |
-# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*- |
|
| 2 |
-# serial 1 (pkg-config-0.24) |
|
| 3 |
-# |
|
| 4 |
-# Copyright © 2004 Scott James Remnant <scott@netsplit.com>. |
|
| 5 |
-# |
|
| 6 |
-# This program is free software; you can redistribute it and/or modify |
|
| 7 |
-# it under the terms of the GNU General Public License as published by |
|
| 8 |
-# the Free Software Foundation; either version 2 of the License, or |
|
| 9 |
-# (at your option) any later version. |
|
| 10 |
-# |
|
| 11 |
-# This program is distributed in the hope that it will be useful, but |
|
| 12 |
-# WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 13 |
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 14 |
-# General Public License for more details. |
|
| 15 |
-# |
|
| 16 |
-# You should have received a copy of the GNU General Public License along |
|
| 17 |
-# with this program; if not, write to the Free Software Foundation, Inc., |
|
| 18 |
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|
| 19 |
-# |
|
| 20 |
-# As a special exception to the GNU General Public License, if you |
|
| 21 |
-# distribute this file as part of a program that contains a |
|
| 22 |
-# configuration script generated by Autoconf, you may include it under |
|
| 23 |
-# the same distribution terms that you use for the rest of that program. |
|
| 24 |
- |
|
| 25 |
-# PKG_PROG_PKG_CONFIG([MIN-VERSION]) |
|
| 26 |
-# ---------------------------------- |
|
| 1 |
+# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*- |
|
| 2 |
+# serial 12 (pkg-config-0.29.2) |
|
| 3 |
+ |
|
| 4 |
+dnl Copyright © 2004 Scott James Remnant <scott@netsplit.com>. |
|
| 5 |
+dnl Copyright © 2012-2015 Dan Nicholson <dbn.lists@gmail.com> |
|
| 6 |
+dnl |
|
| 7 |
+dnl This program is free software; you can redistribute it and/or modify |
|
| 8 |
+dnl it under the terms of the GNU General Public License as published by |
|
| 9 |
+dnl the Free Software Foundation; either version 2 of the License, or |
|
| 10 |
+dnl (at your option) any later version. |
|
| 11 |
+dnl |
|
| 12 |
+dnl This program is distributed in the hope that it will be useful, but |
|
| 13 |
+dnl WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 14 |
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 15 |
+dnl General Public License for more details. |
|
| 16 |
+dnl |
|
| 17 |
+dnl You should have received a copy of the GNU General Public License |
|
| 18 |
+dnl along with this program; if not, write to the Free Software |
|
| 19 |
+dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
|
| 20 |
+dnl 02111-1307, USA. |
|
| 21 |
+dnl |
|
| 22 |
+dnl As a special exception to the GNU General Public License, if you |
|
| 23 |
+dnl distribute this file as part of a program that contains a |
|
| 24 |
+dnl configuration script generated by Autoconf, you may include it under |
|
| 25 |
+dnl the same distribution terms that you use for the rest of that |
|
| 26 |
+dnl program. |
|
| 27 |
+ |
|
| 28 |
+dnl PKG_PREREQ(MIN-VERSION) |
|
| 29 |
+dnl ----------------------- |
|
| 30 |
+dnl Since: 0.29 |
|
| 31 |
+dnl |
|
| 32 |
+dnl Verify that the version of the pkg-config macros are at least |
|
| 33 |
+dnl MIN-VERSION. Unlike PKG_PROG_PKG_CONFIG, which checks the user's |
|
| 34 |
+dnl installed version of pkg-config, this checks the developer's version |
|
| 35 |
+dnl of pkg.m4 when generating configure. |
|
| 36 |
+dnl |
|
| 37 |
+dnl To ensure that this macro is defined, also add: |
|
| 38 |
+dnl m4_ifndef([PKG_PREREQ], |
|
| 39 |
+dnl [m4_fatal([must install pkg-config 0.29 or later before running autoconf/autogen])]) |
|
| 40 |
+dnl |
|
| 41 |
+dnl See the "Since" comment for each macro you use to see what version |
|
| 42 |
+dnl of the macros you require. |
|
| 43 |
+m4_defun([PKG_PREREQ], |
|
| 44 |
+[m4_define([PKG_MACROS_VERSION], [0.29.2]) |
|
| 45 |
+m4_if(m4_version_compare(PKG_MACROS_VERSION, [$1]), -1, |
|
| 46 |
+ [m4_fatal([pkg.m4 version $1 or higher is required but ]PKG_MACROS_VERSION[ found])]) |
|
| 47 |
+])dnl PKG_PREREQ |
|
| 48 |
+ |
|
| 49 |
+dnl PKG_PROG_PKG_CONFIG([MIN-VERSION]) |
|
| 50 |
+dnl ---------------------------------- |
|
| 51 |
+dnl Since: 0.16 |
|
| 52 |
+dnl |
|
| 53 |
+dnl Search for the pkg-config tool and set the PKG_CONFIG variable to |
|
| 54 |
+dnl first found in the path. Checks that the version of pkg-config found |
|
| 55 |
+dnl is at least MIN-VERSION. If MIN-VERSION is not specified, 0.9.0 is |
|
| 56 |
+dnl used since that's the first version where most current features of |
|
| 57 |
+dnl pkg-config existed. |
|
| 27 | 58 |
AC_DEFUN([PKG_PROG_PKG_CONFIG], |
| 28 | 59 |
[m4_pattern_forbid([^_?PKG_[A-Z_]+$]) |
| 29 | 60 |
m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$]) |
| ... | ... |
@@ -45,18 +76,19 @@ if test -n "$PKG_CONFIG"; then |
| 45 | 45 |
PKG_CONFIG="" |
| 46 | 46 |
fi |
| 47 | 47 |
fi[]dnl |
| 48 |
-])# PKG_PROG_PKG_CONFIG |
|
| 49 |
- |
|
| 50 |
-# PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) |
|
| 51 |
-# |
|
| 52 |
-# Check to see whether a particular set of modules exists. Similar |
|
| 53 |
-# to PKG_CHECK_MODULES(), but does not set variables or print errors. |
|
| 54 |
-# |
|
| 55 |
-# Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG]) |
|
| 56 |
-# only at the first occurrence in configure.ac, so if the first place |
|
| 57 |
-# it's called might be skipped (such as if it is within an "if", you |
|
| 58 |
-# have to call PKG_CHECK_EXISTS manually |
|
| 59 |
-# -------------------------------------------------------------- |
|
| 48 |
+])dnl PKG_PROG_PKG_CONFIG |
|
| 49 |
+ |
|
| 50 |
+dnl PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) |
|
| 51 |
+dnl ------------------------------------------------------------------- |
|
| 52 |
+dnl Since: 0.18 |
|
| 53 |
+dnl |
|
| 54 |
+dnl Check to see whether a particular set of modules exists. Similar to |
|
| 55 |
+dnl PKG_CHECK_MODULES(), but does not set variables or print errors. |
|
| 56 |
+dnl |
|
| 57 |
+dnl Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG]) |
|
| 58 |
+dnl only at the first occurence in configure.ac, so if the first place |
|
| 59 |
+dnl it's called might be skipped (such as if it is within an "if", you |
|
| 60 |
+dnl have to call PKG_CHECK_EXISTS manually |
|
| 60 | 61 |
AC_DEFUN([PKG_CHECK_EXISTS], |
| 61 | 62 |
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl |
| 62 | 63 |
if test -n "$PKG_CONFIG" && \ |
| ... | ... |
@@ -66,8 +98,10 @@ m4_ifvaln([$3], [else |
| 66 | 66 |
$3])dnl |
| 67 | 67 |
fi]) |
| 68 | 68 |
|
| 69 |
-# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES]) |
|
| 70 |
-# --------------------------------------------- |
|
| 69 |
+dnl _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES]) |
|
| 70 |
+dnl --------------------------------------------- |
|
| 71 |
+dnl Internal wrapper calling pkg-config via PKG_CONFIG and setting |
|
| 72 |
+dnl pkg_failed based on the result. |
|
| 71 | 73 |
m4_define([_PKG_CONFIG], |
| 72 | 74 |
[if test -n "$$1"; then |
| 73 | 75 |
pkg_cv_[]$1="$$1" |
| ... | ... |
@@ -79,10 +113,11 @@ m4_define([_PKG_CONFIG], |
| 79 | 79 |
else |
| 80 | 80 |
pkg_failed=untried |
| 81 | 81 |
fi[]dnl |
| 82 |
-])# _PKG_CONFIG |
|
| 82 |
+])dnl _PKG_CONFIG |
|
| 83 | 83 |
|
| 84 |
-# _PKG_SHORT_ERRORS_SUPPORTED |
|
| 85 |
-# ----------------------------- |
|
| 84 |
+dnl _PKG_SHORT_ERRORS_SUPPORTED |
|
| 85 |
+dnl --------------------------- |
|
| 86 |
+dnl Internal check to see if pkg-config supports short errors. |
|
| 86 | 87 |
AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED], |
| 87 | 88 |
[AC_REQUIRE([PKG_PROG_PKG_CONFIG]) |
| 88 | 89 |
if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then |
| ... | ... |
@@ -90,26 +125,24 @@ if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then |
| 90 | 90 |
else |
| 91 | 91 |
_pkg_short_errors_supported=no |
| 92 | 92 |
fi[]dnl |
| 93 |
-])# _PKG_SHORT_ERRORS_SUPPORTED |
|
| 94 |
- |
|
| 95 |
- |
|
| 96 |
-# PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND], |
|
| 97 |
-# [ACTION-IF-NOT-FOUND]) |
|
| 98 |
-# |
|
| 99 |
-# |
|
| 100 |
-# Note that if there is a possibility the first call to |
|
| 101 |
-# PKG_CHECK_MODULES might not happen, you should be sure to include an |
|
| 102 |
-# explicit call to PKG_PROG_PKG_CONFIG in your configure.ac |
|
| 103 |
-# |
|
| 104 |
-# |
|
| 105 |
-# -------------------------------------------------------------- |
|
| 93 |
+])dnl _PKG_SHORT_ERRORS_SUPPORTED |
|
| 94 |
+ |
|
| 95 |
+ |
|
| 96 |
+dnl PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND], |
|
| 97 |
+dnl [ACTION-IF-NOT-FOUND]) |
|
| 98 |
+dnl -------------------------------------------------------------- |
|
| 99 |
+dnl Since: 0.4.0 |
|
| 100 |
+dnl |
|
| 101 |
+dnl Note that if there is a possibility the first call to |
|
| 102 |
+dnl PKG_CHECK_MODULES might not happen, you should be sure to include an |
|
| 103 |
+dnl explicit call to PKG_PROG_PKG_CONFIG in your configure.ac |
|
| 106 | 104 |
AC_DEFUN([PKG_CHECK_MODULES], |
| 107 | 105 |
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl |
| 108 | 106 |
AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl |
| 109 | 107 |
AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl |
| 110 | 108 |
|
| 111 | 109 |
pkg_failed=no |
| 112 |
-AC_MSG_CHECKING([for $1]) |
|
| 110 |
+AC_MSG_CHECKING([for $2]) |
|
| 113 | 111 |
|
| 114 | 112 |
_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2]) |
| 115 | 113 |
_PKG_CONFIG([$1][_LIBS], [libs], [$2]) |
| ... | ... |
@@ -119,11 +152,11 @@ and $1[]_LIBS to avoid the need to call pkg-config. |
| 119 | 119 |
See the pkg-config man page for more details.]) |
| 120 | 120 |
|
| 121 | 121 |
if test $pkg_failed = yes; then |
| 122 |
- AC_MSG_RESULT([no]) |
|
| 122 |
+ AC_MSG_RESULT([no]) |
|
| 123 | 123 |
_PKG_SHORT_ERRORS_SUPPORTED |
| 124 | 124 |
if test $_pkg_short_errors_supported = yes; then |
| 125 | 125 |
$1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1` |
| 126 |
- else |
|
| 126 |
+ else |
|
| 127 | 127 |
$1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1` |
| 128 | 128 |
fi |
| 129 | 129 |
# Put the nasty error message in config.log where it belongs |
| ... | ... |
@@ -140,7 +173,7 @@ installed software in a non-standard prefix. |
| 140 | 140 |
_PKG_TEXT])[]dnl |
| 141 | 141 |
]) |
| 142 | 142 |
elif test $pkg_failed = untried; then |
| 143 |
- AC_MSG_RESULT([no]) |
|
| 143 |
+ AC_MSG_RESULT([no]) |
|
| 144 | 144 |
m4_default([$4], [AC_MSG_FAILURE( |
| 145 | 145 |
[The pkg-config script could not be found or is too old. Make sure it |
| 146 | 146 |
is in your PATH or set the PKG_CONFIG environment variable to the full |
| ... | ... |
@@ -156,4 +189,87 @@ else |
| 156 | 156 |
AC_MSG_RESULT([yes]) |
| 157 | 157 |
$3 |
| 158 | 158 |
fi[]dnl |
| 159 |
-])# PKG_CHECK_MODULES |
|
| 159 |
+])dnl PKG_CHECK_MODULES |
|
| 160 |
+ |
|
| 161 |
+ |
|
| 162 |
+dnl PKG_CHECK_MODULES_STATIC(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND], |
|
| 163 |
+dnl [ACTION-IF-NOT-FOUND]) |
|
| 164 |
+dnl --------------------------------------------------------------------- |
|
| 165 |
+dnl Since: 0.29 |
|
| 166 |
+dnl |
|
| 167 |
+dnl Checks for existence of MODULES and gathers its build flags with |
|
| 168 |
+dnl static libraries enabled. Sets VARIABLE-PREFIX_CFLAGS from --cflags |
|
| 169 |
+dnl and VARIABLE-PREFIX_LIBS from --libs. |
|
| 170 |
+dnl |
|
| 171 |
+dnl Note that if there is a possibility the first call to |
|
| 172 |
+dnl PKG_CHECK_MODULES_STATIC might not happen, you should be sure to |
|
| 173 |
+dnl include an explicit call to PKG_PROG_PKG_CONFIG in your |
|
| 174 |
+dnl configure.ac. |
|
| 175 |
+AC_DEFUN([PKG_CHECK_MODULES_STATIC], |
|
| 176 |
+[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl |
|
| 177 |
+_save_PKG_CONFIG=$PKG_CONFIG |
|
| 178 |
+PKG_CONFIG="$PKG_CONFIG --static" |
|
| 179 |
+PKG_CHECK_MODULES($@) |
|
| 180 |
+PKG_CONFIG=$_save_PKG_CONFIG[]dnl |
|
| 181 |
+])dnl PKG_CHECK_MODULES_STATIC |
|
| 182 |
+ |
|
| 183 |
+ |
|
| 184 |
+dnl PKG_INSTALLDIR([DIRECTORY]) |
|
| 185 |
+dnl ------------------------- |
|
| 186 |
+dnl Since: 0.27 |
|
| 187 |
+dnl |
|
| 188 |
+dnl Substitutes the variable pkgconfigdir as the location where a module |
|
| 189 |
+dnl should install pkg-config .pc files. By default the directory is |
|
| 190 |
+dnl $libdir/pkgconfig, but the default can be changed by passing |
|
| 191 |
+dnl DIRECTORY. The user can override through the --with-pkgconfigdir |
|
| 192 |
+dnl parameter. |
|
| 193 |
+AC_DEFUN([PKG_INSTALLDIR], |
|
| 194 |
+[m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])])
|
|
| 195 |
+m4_pushdef([pkg_description], |
|
| 196 |
+ [pkg-config installation directory @<:@]pkg_default[@:>@]) |
|
| 197 |
+AC_ARG_WITH([pkgconfigdir], |
|
| 198 |
+ [AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],, |
|
| 199 |
+ [with_pkgconfigdir=]pkg_default) |
|
| 200 |
+AC_SUBST([pkgconfigdir], [$with_pkgconfigdir]) |
|
| 201 |
+m4_popdef([pkg_default]) |
|
| 202 |
+m4_popdef([pkg_description]) |
|
| 203 |
+])dnl PKG_INSTALLDIR |
|
| 204 |
+ |
|
| 205 |
+ |
|
| 206 |
+dnl PKG_NOARCH_INSTALLDIR([DIRECTORY]) |
|
| 207 |
+dnl -------------------------------- |
|
| 208 |
+dnl Since: 0.27 |
|
| 209 |
+dnl |
|
| 210 |
+dnl Substitutes the variable noarch_pkgconfigdir as the location where a |
|
| 211 |
+dnl module should install arch-independent pkg-config .pc files. By |
|
| 212 |
+dnl default the directory is $datadir/pkgconfig, but the default can be |
|
| 213 |
+dnl changed by passing DIRECTORY. The user can override through the |
|
| 214 |
+dnl --with-noarch-pkgconfigdir parameter. |
|
| 215 |
+AC_DEFUN([PKG_NOARCH_INSTALLDIR], |
|
| 216 |
+[m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])])
|
|
| 217 |
+m4_pushdef([pkg_description], |
|
| 218 |
+ [pkg-config arch-independent installation directory @<:@]pkg_default[@:>@]) |
|
| 219 |
+AC_ARG_WITH([noarch-pkgconfigdir], |
|
| 220 |
+ [AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],, |
|
| 221 |
+ [with_noarch_pkgconfigdir=]pkg_default) |
|
| 222 |
+AC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir]) |
|
| 223 |
+m4_popdef([pkg_default]) |
|
| 224 |
+m4_popdef([pkg_description]) |
|
| 225 |
+])dnl PKG_NOARCH_INSTALLDIR |
|
| 226 |
+ |
|
| 227 |
+ |
|
| 228 |
+dnl PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE, |
|
| 229 |
+dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) |
|
| 230 |
+dnl ------------------------------------------- |
|
| 231 |
+dnl Since: 0.28 |
|
| 232 |
+dnl |
|
| 233 |
+dnl Retrieves the value of the pkg-config variable for the given module. |
|
| 234 |
+AC_DEFUN([PKG_CHECK_VAR], |
|
| 235 |
+[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl |
|
| 236 |
+AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl |
|
| 237 |
+ |
|
| 238 |
+_PKG_CONFIG([$1], [variable="][$3]["], [$2]) |
|
| 239 |
+AS_VAR_COPY([$1], [pkg_cv_][$1]) |
|
| 240 |
+ |
|
| 241 |
+AS_VAR_IF([$1], [""], [$5], [$4])dnl |
|
| 242 |
+])dnl PKG_CHECK_VAR |