]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
configure.ac: fix the check for static libcap
authorSerge Hallyn <shallyn@cisco.com>
Thu, 4 Jan 2018 03:02:53 +0000 (21:02 -0600)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 19 Jan 2018 13:30:31 +0000 (14:30 +0100)
The existing check doesn't work, because when you statically
link a program against libc, any functions not called are not
included.  So cap_init() which we check for is not there in
the built binary.

So instead just check whether a "gcc -lcap -static" works.
If libcap.a is not available it will fail, if it is it will
succeed.

Signed-off-by: Serge Hallyn <shallyn@cisco.com>
configure.ac

index 0a8eff1a003f3fbc38f5716c2de6f4d34e84d5b8..8b51dc38a9c16dedfb95796e36458b284c23f85e 100644 (file)
@@ -343,16 +343,32 @@ else
        AC_MSG_RESULT([no])
 fi
 
+AC_MSG_CHECKING(for static libcap)
 # Check for static libcap, make sure the function checked for differs from the
 # the one checked below so the cache doesn't give a wrong answer
 OLD_CFLAGS="$CFLAGS"
-CFLAGS="$CFLAGS -static"
-AC_CHECK_LIB([cap],[cap_init],[have_static_libcap=yes],[have_static_libcap=no])
+OLD_CPPFLAGS="$CPPFLAGS"
+OLD_LDFLAGS="$LDFLAGS"
+OLD_LIBS="$LIBS"
+CFLAGS=""
+CPPFLAGS=""
+LDFLAGS="-static"
+LIBS="-lcap"
+AC_LINK_IFELSE([
+  AC_LANG_SOURCE(
+    [[int main() { return 0; }]]
+  )],[have_static_libcap=yes],[have_static_libcap=no])
 AM_CONDITIONAL([HAVE_STATIC_LIBCAP], [test "x$have_static_libcap" = "xyes"])
 if test "x$have_static_libcap" = "xyes"; then
        AC_DEFINE([HAVE_STATIC_LIBCAP], 1, [Have static libcap])
+       AC_MSG_RESULT([yes])
+else
+       AC_MSG_RESULT([no])
 fi
+CPPFLAGS="$OLD_CPPFLAGS"
 CFLAGS="$OLD_CFLAGS"
+LDFLAGS="$OLD_LDFLAGS"
+LIBS="$OLD_LIBS"
 
 
 # Linux capabilities