add new function to pkg.m4 to help static linking
There is a continued interest in being able to do static linking of executables. When using pkg-config to determine linking requirements, the default behavior is to only specify libraries required for dynamic linking. In many cases, it suffices even for static linking to use pkg-config --libs package to obtain the linkage string required for ld. However, for libraries that have dependencies on non-standard libraries, this may not be the case. The cray PMI library is such a case. On a Cray CLE 5.X system, for example pkg-config --libs cray-pmi returns a string like -L/opt/cray/pmi/5.0.2-1.0000.9906.117.2.ari/lib64 -lpmi whereas pkgconfig --static --libs cray-pmi returns a string (modified for git commits) like -L/opt/cray/pmi/5.0.2-1.0000.9906.117.2.ari/lib64 -L/opt/cray/ugni/5.0-1.0000.8563.255.10.ari/lib64 -L/opt/cray/alps/6.0.0-2.0000.8544.102.21.ari/lib64 -L/opt/cray/wlm_detect/1.0-1.0000.48964.8.2.ari/lib64 -L/opt/cray/rca/1.0.0-2.0000.49383.133.60.ari/lib64 -lpmi -lpthread -lalpslli -lpthread -lwlm_detect -lugni -lpthread -lalpsutil -lpthread -lrca Unfortunately the pkg.m4 does not contain a function for adding the --static option to PKG_CHECK_MODULES. This commit defines a new function, PKG_CHECK_MODULES_STATIC, which in addition to defining the $1_CFLAGS and $1_LIBS variables defined by PKG_CHECK_MODULES, also defines a $1_STATIC_LIBS.
Этот коммит содержится в:
родитель
7a5b2e9b13
Коммит
9e382d634d
@ -212,3 +212,88 @@ AS_VAR_COPY([$1], [pkg_cv_][$1])
|
||||
|
||||
AS_VAR_IF([$1], [""], [$5], [$4])dnl
|
||||
])# PKG_CHECK_VAR
|
||||
|
||||
#
|
||||
# OpenMPI project extensions to pkg.m4
|
||||
#
|
||||
|
||||
# _PKG_CONFIG2([VARIABLE], [COMMAND1], [COMMAND2], [MODULES])
|
||||
# ---------------------------------------------
|
||||
m4_define([_PKG_CONFIG2],
|
||||
[if test -n "$$1"; then
|
||||
pkg_cv_[]$1="$$1"
|
||||
elif test -n "$PKG_CONFIG"; then
|
||||
PKG_CHECK_EXISTS([$4],
|
||||
[pkg_cv_[]$1=`$PKG_CONFIG --[]$2 --[]$3 "$4" 2>/dev/null`
|
||||
test "x$?" != "x0" && pkg_failed=yes ],
|
||||
[pkg_failed=yes])
|
||||
else
|
||||
pkg_failed=untried
|
||||
fi[]dnl
|
||||
])# _PKG_CONFIG2
|
||||
|
||||
# PKG_CHECK_MODULES_STATIC(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
|
||||
# [ACTION-IF-NOT-FOUND])
|
||||
#
|
||||
#
|
||||
# Variation of PGK_CHECK_MODULES which also defines $1_LIBS_STATIC
|
||||
# by using the pkg-config --libs --static pkg-config option.
|
||||
#
|
||||
# --------------------------------------------------------------
|
||||
AC_DEFUN([PKG_CHECK_MODULES_STATIC],
|
||||
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
|
||||
AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
|
||||
AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
|
||||
AC_ARG_VAR([$1][_STATIC_LIBS], [static linker flags for $1, overriding pkg-config])dnl
|
||||
|
||||
pkg_failed=no
|
||||
AC_MSG_CHECKING([for $1])
|
||||
|
||||
_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
|
||||
_PKG_CONFIG([$1][_LIBS], [libs], [$2])
|
||||
_PKG_CONFIG2([$1][_STATIC_LIBS], [libs], [static], [$2])
|
||||
|
||||
m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
|
||||
and $1[]_LIBS to avoid the need to call pkg-config.
|
||||
See the pkg-config man page for more details.])
|
||||
|
||||
if test $pkg_failed = yes; then
|
||||
AC_MSG_RESULT([no])
|
||||
_PKG_SHORT_ERRORS_SUPPORTED
|
||||
if test $_pkg_short_errors_supported = yes; then
|
||||
$1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1`
|
||||
else
|
||||
$1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1`
|
||||
fi
|
||||
# Put the nasty error message in config.log where it belongs
|
||||
echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
|
||||
|
||||
m4_default([$4], [AC_MSG_ERROR(
|
||||
[Package requirements ($2) were not met:
|
||||
|
||||
$$1_PKG_ERRORS
|
||||
|
||||
Consider adjusting the PKG_CONFIG_PATH environment variable if you
|
||||
installed software in a non-standard prefix.
|
||||
|
||||
_PKG_TEXT])[]dnl
|
||||
])
|
||||
elif test $pkg_failed = untried; then
|
||||
AC_MSG_RESULT([no])
|
||||
m4_default([$4], [AC_MSG_FAILURE(
|
||||
[The pkg-config script could not be found or is too old. Make sure it
|
||||
is in your PATH or set the PKG_CONFIG environment variable to the full
|
||||
path to pkg-config.
|
||||
|
||||
_PKG_TEXT
|
||||
|
||||
To get pkg-config, see <http://pkg-config.freedesktop.org/>.])[]dnl
|
||||
])
|
||||
else
|
||||
$1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
|
||||
$1[]_LIBS=$pkg_cv_[]$1[]_LIBS
|
||||
$1[]_STATIC_LIBS=$pkg_cv_[]$1[]_STATIC_LIBS
|
||||
AC_MSG_RESULT([yes])
|
||||
$3
|
||||
fi[]dnl
|
||||
])# PKG_CHECK_MODULES_STATIC
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user