user1024718
user1024718

Reputation: 575

Autoconf without GLib breaks with syntax error on configure

If I don't have pkg-config installed nor glib my configure breaks with a syntax error when running ./configure. Is there a way to break with AC_MSG_ERROR?

./configure: line 4001: syntax error near unexpected token `GLIB2,'
./configure: line 4001: `  PKG_CHECK_MODULES(GLIB2, glib-2.0, , as_fn_error $? "glib needed" "$LINENO" 5)'

--

AC_ARG_ENABLE(GTK, [], [gtk="$enabled"], gtk=no)

if test "$gtk" = "yes"; then
    AC_CHECK_LIB([gtk-x11-2.0], [gtk_init], [], [AC_MSG_ERROR([gtk needed])])
else
    AC_CHECK_PROG(HAVE_PKG_CONFIG, pkg-config, yes)
    if test x"$HAVE_PKG_CONFIG" != x"yes" ; then
        AC_MSG_ERROR([pkg-config])
    fi
    PKG_CHECK_MODULES(GLIB2, glib-2.0, [], AC_MSG_ERROR([glib needed]))
    AC_SUBST(GLIB2_CFLAGS)
    AC_SUBST(GLIB2_LIBS)
    AC_CHECK_LIB([glib-2.0], [g_list_append], [], [AC_MSG_ERROR([glib needed])])
fi

AM_CONDITIONAL([GTK], [test "x$gtk" = "xyes"])

Upvotes: 2

Views: 3243

Answers (2)

DanielKO
DanielKO

Reputation: 4517

The configure script was generated incorrectly, in absence of pkg.m4. For all non-basic macros that don't start with AC_* it's a good idea to distribute them with the source code for this reason, so you can at least get a correct configure script.

That said, pkg-config is pretty ubiquitous nowadays, why are you generating a configure script from a system that doesn't have it? You could simply make dist from a "better" system, and build from the output tarball (that will contain a valid configure script).

Upvotes: 4

djcb
djcb

Reputation: 399

Adding a check for pkg-config should do the trick:

# require pkg-config
AC_PATH_PROG([PKG_CONFIG], [pkg-config], [no])
AS_IF([test "x$PKG_CONFIG" = "xno"],[
   AC_MSG_ERROR([
   *** The pkg-config script could not be found. Make sure it is
   *** in your path, or set the PKG_CONFIG environment variable
   *** to the full path to pkg-config.])
])

Upvotes: 0

Related Questions