Search code examples
autotoolsautoconfautomakegladepkg-config

Query pkg-config variable through autotools


To install a catalog file, I'd like to get the directory for Glade (an UI designer) like so:

$ pkg-config --variable=catalogdir gladeui-2.0
/usr/share/glade/catalogs

but in a variable inside my Makefile.am. Is there a (portable) way to do this?


Solution

  • Get this value in configure.ac. I think the latest version of pkg-config is 0.28. Let's assume that 0.25 or above is good enough:


    configure.ac

    ...
    
    PKG_PROG_PKG_CONFIG([0.25]) # check and set $PKG_CONFIG
    
    PKG_CHECK_MODULES([GLADEUI],[gladeui-2.0],
      [ac_gladeui_catdir=`$PKG_CONFIG --variable=catalogdir gladeui-2.0`],
      [ac_gladeui_catdir=;])
    
    # there's nothing special about the choice of variable names:
    # GLADEUI or ac_gladeui_catdir - use whatever naming scheme you please.
    
    if test "x$ac_gladeui_catdir" = x ; then
      AC_MSG_ERROR([couldn't find Glade or catalog directory])
    fi
    
    # or if you prefer the AS_IF macro:
    # AS_IF([test "x$ac_gladeui_catdir" = x],
    #   [AC_MSG_ERROR([couldn't find Glade or catalog directory])])
    
    AC_SUBST(GLADEUI_CATDIR, $ac_gladeui_catdir)
    

    You can now access this value in the Makefile.am using: $(GLADEUI_CATDIR)