build-sys: Give sensible errors if missing pkg-config
authorCraig Small <csmall@dropbear.xyz>
Wed, 25 May 2022 11:08:50 +0000 (21:08 +1000)
committerCraig Small <csmall@dropbear.xyz>
Wed, 25 May 2022 11:08:50 +0000 (21:08 +1000)
pkg-config is used to find various libraries used by procps.
Unfortunately it, or rather automake, give terrible misleading
error messages if pkg-config is not installed.

At ./configure time you get this:
configure: error: ncurses support missing/incomplete (for partial
build use --without-ncurses)

At automake time you get this:
configure.ac:33: error: possibly undefined macro: AC_MSG_ERROR
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.
configure.ac:48: error: possibly undefined macro: AS_IF
configure.ac:113: error: possibly undefined macro: AC_DEFINE

The internet is filled with such wonderful other examples.

This commit does two things:
 At autoconf time, check PKG_PREREQ macro is defined which is found in
pkg.m4 and tells us pkg-config has its macros available.
 At configure time, check the result of the pkg-config test and error
 if it didn't find it.

Now it actually says its missing pkg-config. To be fair, the autoconf
check is "documented" and recommended in pkg.m4 file.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
configure.ac

index 8c6c3380ebef8ea205a74299d4907429c38910db..28deb5306af75491f7405871cbac055a44e596d4 100644 (file)
@@ -40,7 +40,14 @@ AM_PROG_CC_C_O
 AC_PROG_CPP
 AC_PROG_INSTALL
 AC_PROG_LN_S
+
+dnl Check pkg-config is there for autoconf and at ./configure
+m4_ifndef([PKG_PREREQ],
+  [m4_fatal([must install pkg-config 0.29 or later before running autoconf/autogen])])
 PKG_PROG_PKG_CONFIG
+AS_IF([test -z "$PKG_CONFIG"],[
+  AC_MSG_ERROR([Could not find pkg-config])])
+
 AC_PROG_MAKE_SET
 
 AC_DEFUN([PROCPS_PROG_PO4A], [