AC-Archive
Autoconf Macro Archive

ac-archive.sf.net: - Project CVS - Download
Macro Index
- AM Support
- C++ Support
- C Support
- Fortran Support
- Java Support
- Cross Compilation
- Installed Packages
- Miscellaneous
- LaTeX Support
- Uncategorized
- archive macros
- adl's macros
- bkorb's macros
- guidod's macros
- latex's macros
- other's macros
- rleigh's macros
- obsoleted macros
- released macros
- search index

Documentation
- Contribute!
- History
- acincludedir m4
- acinclude (tool)
- macro howto
- ax tricks
- maintainers
- License
- Topics

generated...
2007-08-05

(C) 2007 guidod
Download the M4 Source.

ac_config_libconfig_in

Back to the Main Page.

Synopsis
AC_CONFIG_LIBCONFIG_IN [(LIBRARY [, DESTINATION [, MODULES]])]
, 
Version

2005-01-23

Author

Roger Leigh <roger@whinlatter.uklinux.net>

License

AllPermissive
Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. Users of this software should generally follow the principles of the MIT License includings its disclaimer.

Category

cryp.to ac-archive's Obsoleted (obsoleted)

Documentation

  • obsoleted Deprecated with the advent of pkg-config.

Creates a custom LIBRARY-config script. The script supports --cflags, --libs and --version options, as well as all of the standard configure variables e.g. --libdir and --sysconfdir. --prefix and --exec-prefix may be specified to override the defaults. --help gives a complete list of available options. Modules allow multiple sets of --libs, --cflags and --version options to be used, and combined together.

This macro saves you all the typing for a library-config.in script; you don't even need to distribute one along. Place this macro in your configure.ac, et voila, you got one that you want to install.

The options:

$1 = LIBRARY       e.g. gtk, ncurses
$2 = DESTINATION   Directory path, e.g. src/scripts
$3 = MODULES       Additional library modules, not including the
                   default ($1).

It is suggested that the following CFLAGS and LIBS variables are used in your configure.in. library_libs is *essential*. library_cflags is important, but not always needed. If they do not exist, defaults will be taken from LIBRARY_CFLAGS, LIBRARY_LIBS (should be -llibrary *only*) and LIBRARY_LIBDEPS (-l options for libraries your library depends upon. LIBLIBRARY_LIBS is simply $LIBRARY_LIBS $LIBRARY_LIBDEPS. NB. LIBRARY and library are the name of your library, in upper and lower case repectively e.g. GTK, gtk.

LIBRARY_CFLAGS:    cflags for compiling libraries and example progs
LIBRARY_LIBS:      libraries for linking programs
LIBRARY_LIBDEPS*:  libraries for linking libraries against (needed
                   to link -static
library_cflags*:   cflags to store in library-config
library_libs*:     libs to store in library-config
LIBLIBRARY_LIBS:   libs to link programs IN THIS PACKAGE ONLY against
LIBRARY_VERSION*:  the version of your library (x.y.z recommended)
  *=required if you want sensible output, otherwise they will be
    *guessed* (DWIM)

Support for pkg-config is available by default. libs, cflags and version information will be obtained from the pkg-config metadata file library.pc if it exists in the pkgconfig data directory. The above information still needs to be specified, as it will still be used if pkg-config is not found on the host system at configure time.

-I and -L flags will be obtained from *both* pkgconfig and the script. AC_CONFIG_LIBCONFIG_IN_PKGCONFIG enables pkg-config support (default) AC_CONFIG_LIBCONFIG_IN_STATIC disables pkg-config support

There is also an AC_SUBST(LIBRARY_CONFIG) that will be set to the name of the file that we output in this macro. Use as:

install-exec-local: install-config
install-config:
   $(mkinstalldirs) $(DESTDIR)$(bindir)
   $(INSTALL_EXEC) @LIBRARY_CONFIG@ $(DESTDIR)$(bindir)

Or, if using automake:

bin_SCRIPTS = @LIBRARY_CONFIG@

Based upon AC_CREATE_GENERIC_CONFIG (ac_create_generic_config.m4) by Guido Draheim <guidod@gmx.de> and gtk-config by Owen Taylor.

M4 Source Code
# AC_CONFIG_LIBCONFIG_IN(LIBRARY, DESTINATION, MODULES)
# -----------------------------------------------------
# Generate a custom LIBRARY-config script.  Create the script in the
# DESTINATION directory, including support for MODULES.
AC_DEFUN([AC_CONFIG_LIBCONFIG_IN],
[# create a custom library-config file ($1-config)
m4_if(AC_CONFIG_LIBCONFIG_IN_USEPKGCONFIG, [true],
      [AC_PATH_PROG(PKG_CONFIG, pkg-config)])
pushdef([LIBCONFIG_DIR], [m4_if([$2], , , [$2/])])
LIBCONFIG_FILE="LIBCONFIG_DIR[]$1-config.in"
AC_SUBST(target)dnl
AC_SUBST(host)dnl
AC_SUBST(build)dnl
dnl create directory if it does not preexist
m4_if([$2], , , [AS_MKDIR_P([$2])])
AC_MSG_NOTICE([creating $LIBCONFIG_FILE])
echo '#! /bin/sh' &gt;$LIBCONFIG_FILE
echo "# $1-config library configuration script" &gt;&gt;$LIBCONFIG_FILE
echo '# generated by ac_config_libconfig_in.m4' &gt;&gt;$LIBCONFIG_FILE
echo ' ' &gt;&gt;$LIBCONFIG_FILE
echo 'template_version="1.0.0"' &gt;&gt;$LIBCONFIG_FILE
echo ' ' &gt;&gt;$LIBCONFIG_FILE
echo 'package="@PACKAGE@"' &gt;&gt;$LIBCONFIG_FILE
echo ' ' &gt;&gt;$LIBCONFIG_FILE
echo '# usage instructions if no options given' &gt;&gt;$LIBCONFIG_FILE
echo 'if test "'"\$""#"'" -eq 0; then' &gt;&gt;$LIBCONFIG_FILE
echo '   cat &lt;&lt;EOF' &gt;&gt;$LIBCONFIG_FILE
m4_if($3, ,
      [echo 'Usage: $1-config [[OPTIONS]]' &gt;&gt;$LIBCONFIG_FILE],
      [echo 'Usage: $1-config [[OPTIONS]] [[LIBRARIES]]' &gt;&gt;$LIBCONFIG_FILE])
echo 'Options:' &gt;&gt;$LIBCONFIG_FILE
echo '        [[--prefix[=DIR]]]' &gt;&gt;$LIBCONFIG_FILE
echo '        [[--exec-prefix[=DIR]]]' &gt;&gt;$LIBCONFIG_FILE
echo '        [[--package]]' &gt;&gt;$LIBCONFIG_FILE
echo '        [[--version]]' &gt;&gt;$LIBCONFIG_FILE
echo '        [[--cflags]]' &gt;&gt;$LIBCONFIG_FILE
echo '        [[--libs]]' &gt;&gt;$LIBCONFIG_FILE
echo '        [[--help]]' &gt;&gt;$LIBCONFIG_FILE
m4_if($3, , ,
      [echo 'Libraries:' &gt;&gt;$LIBCONFIG_FILE
       for module in $1 $3 ; do
         echo "        $module" &gt;&gt;$LIBCONFIG_FILE ;
       done])
echo 'EOF' &gt;&gt;$LIBCONFIG_FILE
echo 'fi' &gt;&gt;$LIBCONFIG_FILE
echo ' ' &gt;&gt;$LIBCONFIG_FILE
echo '# parse options' &gt;&gt;$LIBCONFIG_FILE
echo 'o=""' &gt;&gt;$LIBCONFIG_FILE
echo 'h=""' &gt;&gt;$LIBCONFIG_FILE
echo 'for i ; do' &gt;&gt;$LIBCONFIG_FILE
echo '  case $i in' &gt;&gt;$LIBCONFIG_FILE
options="prefix exec-prefix eprefix package version cflags libs bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir infodir mandir target host build pkgdatadir pkglibdir pkgincludedir template-version help"
echo '    --prefix=*) prefix=`echo $i | sed -e "s/--prefix=//"` ;;' &gt;&gt;$LIBCONFIG_FILE
echo '    --exec-prefix=*) exec_prefix=`echo $i | sed -e "s/--exec-prefix=//"` ;;' &gt;&gt;$LIBCONFIG_FILE
echo '    --eprefix=*) exec_prefix=`echo $i | sed -e "s/--eprefix=//"` ;;' &gt;&gt;$LIBCONFIG_FILE
for option in $options ; do
  case $option in
    exec-prefix)  echo "    --$option) echo_exec_prefix=\"yes\" ;;" &gt;&gt;$LIBCONFIG_FILE ;;
    template-version)  echo "    --$option) echo_template_version=\"yes\" ;;" &gt;&gt;$LIBCONFIG_FILE ;;
    *)  echo "    --$option) echo_$option=\"yes\" ;;" &gt;&gt;$LIBCONFIG_FILE ;;
  esac
done
m4_if($3, , ,
      [for module in $1 $3 ; do
         echo "  $module) echo_module_$module=\"yes\" ;" &gt;&gt;$LIBCONFIG_FILE ;
         echo '    echo_module="yes" ;;' &gt;&gt;$LIBCONFIG_FILE ;
       done])
echo '    //*|/*//*|./*//*)        echo_extra="yes" ;;' &gt;&gt;$LIBCONFIG_FILE
echo '    *) eval "echo Unknown option: $i" ; exit 1 ;;' &gt;&gt;$LIBCONFIG_FILE
echo '  esac' &gt;&gt;$LIBCONFIG_FILE
echo 'done' &gt;&gt;$LIBCONFIG_FILE
echo ' ' &gt;&gt;$LIBCONFIG_FILE
# in the order of occurence a standard automake Makefile
echo '# defaults from configure; set only if not set previously' &gt;&gt;$LIBCONFIG_FILE
vars="prefix exec_prefix bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir infodir mandir includedir target host build"
for var in $vars ; do
  echo "if test -z \"\$$var\" ; then" &gt;&gt;$LIBCONFIG_FILE
  echo "  $var=\"@$var@\"" &gt;&gt;$LIBCONFIG_FILE
  echo 'fi' &gt;&gt;$LIBCONFIG_FILE
done
echo ' ' &gt;&gt;$LIBCONFIG_FILE
echo '# generate output' &gt;&gt;$LIBCONFIG_FILE
echo 'if test x$echo_module != xyes ; then' &gt;&gt;$LIBCONFIG_FILE
echo '  echo_module_$1="yes"' &gt;&gt;$LIBCONFIG_FILE
echo 'fi' &gt;&gt;$LIBCONFIG_FILE
AC_CONFIG_LIBCONFIG_IN_MODULES(m4_if([$3], , [$1], [m4_translit([$1 $3], [ ], [,])]))dnl
for option in $options extra; do
  case $option in
    exec-prefix)  echo "if test x\$echo_exec_prefix = xyes ; then" &gt;&gt;$LIBCONFIG_FILE ;;
    template-version)  echo "if test x\$echo_template_version = xyes ; then" &gt;&gt;$LIBCONFIG_FILE ;;
    *)  echo "if test x\$echo_$option = xyes ; then" &gt;&gt;$LIBCONFIG_FILE ;;
  esac
  case $option in
    exec-prefix | eprefix)  echo '  o="$o $exec_prefix"' &gt;&gt;$LIBCONFIG_FILE ;;
    template-version)  echo '  o="$o $template_version"' &gt;&gt;$LIBCONFIG_FILE ;;
    cflags)
      echo '  i=`eval echo "$includedir"`' &gt;&gt;$LIBCONFIG_FILE ;
      echo '  i=`eval echo "$i"`' &gt;&gt;$LIBCONFIG_FILE ;
      echo '  if test "_$i" != "_/usr/include" ; then' &gt;&gt;$LIBCONFIG_FILE ;
      echo '    o="$o -I$includedir"' &gt;&gt;$LIBCONFIG_FILE ;
      echo '  fi' &gt;&gt;$LIBCONFIG_FILE ;
      echo '  o="$o $cflags"' &gt;&gt;$LIBCONFIG_FILE ;;
    libs)  echo '  o="$o -L$libdir $libs"' &gt;&gt;$LIBCONFIG_FILE ;;
    help)  echo '  h="1"' &gt;&gt;$LIBCONFIG_FILE ;;
    pkgdatadir)  echo "  o=\"$o \${datadir}/\${package}\"" &gt;&gt;$LIBCONFIG_FILE ;;
    pkglibdir)  echo "  o=\"$o \${libdir}/\${package}\"" &gt;&gt;$LIBCONFIG_FILE ;;
    pkgincludedir)  echo "  o=\"$o \${includedir}/\${package}\"" &gt;&gt;$LIBCONFIG_FILE ;;
    extra)
      echo '  v=`echo $i | sed -e s://:\$:g`' &gt;&gt;$LIBCONFIG_FILE ;
      echo '  v=`eval "echo $v"`' &gt;&gt;$LIBCONFIG_FILE ;
      echo '  o="$o $v"' &gt;&gt;$LIBCONFIG_FILE ;;
    *)  echo "  o=\"$o \$$option\"" &gt;&gt;$LIBCONFIG_FILE
  esac
  echo 'fi' &gt;&gt;$LIBCONFIG_FILE
done
echo ' ' &gt;&gt;$LIBCONFIG_FILE
echo '# output data' &gt;&gt;$LIBCONFIG_FILE
echo 'o=`eval "echo $o"`' &gt;&gt;$LIBCONFIG_FILE
echo 'o=`eval "echo $o"`' &gt;&gt;$LIBCONFIG_FILE
echo 'if test -n "$o" ; then ' &gt;&gt;$LIBCONFIG_FILE
echo '  eval "echo $o"' &gt;&gt;$LIBCONFIG_FILE
echo 'fi' &gt;&gt;$LIBCONFIG_FILE
echo ' ' &gt;&gt;$LIBCONFIG_FILE
echo '# help text' &gt;&gt;$LIBCONFIG_FILE
echo 'if test ! -z "$h" ; then ' &gt;&gt;$LIBCONFIG_FILE
echo '  cat &lt;&lt;EOF' &gt;&gt;$LIBCONFIG_FILE
echo 'All available options:' &gt;&gt;$LIBCONFIG_FILE
echo '  --prefix=DIR and   change \$prefix and \$exec-prefix' &gt;&gt;$LIBCONFIG_FILE
echo '  --exec-prefix=DIR  (affects all other options)' &gt;&gt;$LIBCONFIG_FILE
echo '  --prefix           \$prefix        $prefix' &gt;&gt;$LIBCONFIG_FILE
echo '  --exec_prefix  or... ' &gt;&gt;$LIBCONFIG_FILE
echo '  --eprefix          \$exec_prefix   $exec_prefix' &gt;&gt;$LIBCONFIG_FILE
echo '  --version          \$version       $version' &gt;&gt;$LIBCONFIG_FILE
echo '  --cflags           -I\$includedir  unless it is /usr/include' &gt;&gt;$LIBCONFIG_FILE
echo '  --libs             -L\$libdir \$LIBS $libs' &gt;&gt;$LIBCONFIG_FILE
echo '  --package          \$package       $package' &gt;&gt;$LIBCONFIG_FILE
echo '  --bindir           \$bindir        $bindir' &gt;&gt;$LIBCONFIG_FILE
echo '  --sbindir          \$sbindir       $sbindir' &gt;&gt;$LIBCONFIG_FILE
echo '  --libexecdir       \$libexecdir    $libexecdir' &gt;&gt;$LIBCONFIG_FILE
echo '  --datadir          \$datadir       $datadir' &gt;&gt;$LIBCONFIG_FILE
echo '  --sysconfdir       \$sysconfdir    $sysconfdir' &gt;&gt;$LIBCONFIG_FILE
echo '  --sharedstatedir   \$sharedstatedir$sharedstatedir' &gt;&gt;$LIBCONFIG_FILE
echo '  --localstatedir    \$localstatedir $localstatedir' &gt;&gt;$LIBCONFIG_FILE
echo '  --libdir           \$libdir        $libdir' &gt;&gt;$LIBCONFIG_FILE
echo '  --infodir          \$infodir       $infodir' &gt;&gt;$LIBCONFIG_FILE
echo '  --mandir           \$mandir        $mandir' &gt;&gt;$LIBCONFIG_FILE
echo '  --target           \$target        $target' &gt;&gt;$LIBCONFIG_FILE
echo '  --host             \$host          $host' &gt;&gt;$LIBCONFIG_FILE
echo '  --build            \$build         $build' &gt;&gt;$LIBCONFIG_FILE
echo '  --pkgdatadir       \$datadir/\$package    ${datadir}/${package}'    &gt;&gt;$LIBCONFIG_FILE
echo '  --pkglibdir        \$libdir/\$package     ${libdir}/${package}' &gt;&gt;$LIBCONFIG_FILE
echo '  --pkgincludedir    \$includedir/\$package ${includedir}/${package}' &gt;&gt;$LIBCONFIG_FILE
echo '  --template-version \$template_version     $template_version' &gt;&gt;$LIBCONFIG_FILE
echo '  --help' &gt;&gt;$LIBCONFIG_FILE
echo 'EOF' &gt;&gt;$LIBCONFIG_FILE
echo 'fi' &gt;&gt;$LIBCONFIG_FILE
m4_pushdef([LIBCONFIG_UP], [m4_translit([$1], [a-z], [A-Z])])dnl
LIBCONFIG_UP[]_CONFIG="LIBCONFIG_DIR[]$1-config"
AC_SUBST(LIBCONFIG_UP[]_CONFIG)
dnl AC_CONFIG_FILES(LIBCONFIG_DIR[]$1[-config], [chmod +x ]LIBCONFIG_DIR[]$1[-config])
m4_popdef([LIBCONFIG_DIR])
m4_popdef([LIBCONFIG_UP])
])


# AC_CONFIG_LIBCONFIG_IN_MODULES [(MODULE1 [, MODULE2 [, ...]])]
# --------------------------------------------------------------
#Output shell script using custom module variables.
AC_DEFUN([AC_CONFIG_LIBCONFIG_IN_MODULES],
[m4_if([$1], , ,
       [# create module definition for $1
dnl we're going to need uppercase, lowercase and user-friendly versions of the
dnl string `MODULE'
m4_pushdef([MODULE_UP], m4_translit([$1], [a-z], [A-Z]))dnl
m4_pushdef([MODULE_DOWN], m4_translit([$1], [A-Z], [a-z]))dnl
if test -z "$MODULE_DOWN[]_cflags" ; then
  if test -n "$MODULE_UP[]_CFLAGS" ; then
      MODULE_DOWN[]_cflags="$MODULE_UP[]_CFLAGS"
  else
dnl    AC_MSG_WARN([variable `MODULE_DOWN[]_cflags' undefined])
    MODULE_DOWN[]_cflags=''
  fi
fi
AC_SUBST(MODULE_DOWN[]_cflags)dnl
if test -z "$MODULE_DOWN[]_libs" ; then
  if test -n "$MODULE_UP[]_LIBS" ; then
    MODULE_DOWN[]_libs="$MODULE_UP[]_LIBS"
  else
    AC_MSG_WARN([variable `MODULE_DOWN[]_libs' and `MODULE_UP[]_LIBS' undefined])
    MODULE_DOWN[]_libs='-l$1'
  fi
  if test -n "$MODULE_UP[]_LIBDEPS" ; then
    MODULE_DOWN[]_libs="$MODULE_DOWN[]_libs $MODULE_UP[]_LIBDEPS"
  fi
fi
AC_SUBST(MODULE_DOWN[]_libs)dnl
if test -z "$MODULE_UP[]_VERSION" ; then
  AC_MSG_WARN([variable `MODULE_UP[]_VERSION' undefined])
  MODULE_UP[]_VERSION="$VERSION"
fi
AC_SUBST(MODULE_UP[]_VERSION)dnl
echo 'if test x$echo_module_$1 = xyes ; then' &gt;&gt;$LIBCONFIG_FILE
AC_CONFIG_LIBCONFIG_IN_MODULES_VARS([cflags], [MODULE_DOWN[]_cflags], [cflags])
AC_CONFIG_LIBCONFIG_IN_MODULES_VARS([libs], [MODULE_DOWN[]_libs], [libs])
AC_CONFIG_LIBCONFIG_IN_MODULES_VARS([version], [MODULE_UP[]_VERSION], [modversion])
echo 'fi' &gt;&gt;$LIBCONFIG_FILE
m4_popdef([MODULE_UP])dnl
m4_popdef([MODULE_DOWN])dnl
AC_CONFIG_LIBCONFIG_IN_MODULES(m4_shift($@))])dnl
])


# AC_CONFIG_LIBCONFIG_IN_MODULES_VARS [(VAR, SUBSTITUTION,
# PKGCONFIG_ARGS)]
# --------------------------------------------------------
# Output AC_CONFIG_LIBCONFIG_IN_MODULES variables.
#   VAR = variable to set
#   SUBSTITUTION = set if pkg-config is not available
#   PKGCONFIG_ARGS = args for pkg-config
AC_DEFUN([AC_CONFIG_LIBCONFIG_IN_MODULES_VARS],
[m4_if(AC_CONFIG_LIBCONFIG_IN_USEPKGCONFIG, [true],
[
echo 'if test -x "`which pkg-config`" ; then' &gt;&gt;$LIBCONFIG_FILE
echo '  if pkg-config --atleast-pkgconfig-version=0.7 --exists "MODULE_DOWN"; then' &gt;&gt;$LIBCONFIG_FILE
echo '    $1="@S|@$1 `pkg-config --$3 MODULE_DOWN`"' &gt;&gt;$LIBCONFIG_FILE
echo '  fi' &gt;&gt;$LIBCONFIG_FILE
echo 'else' &gt;&gt;$LIBCONFIG_FILE
echo '  $1="@S|@$1 @$2@"' &gt;&gt;$LIBCONFIG_FILE
echo 'fi' &gt;&gt;$LIBCONFIG_FILE
],
[echo '  $1="@S|@$1 @$2@"' &gt;&gt;$LIBCONFIG_FILE
])])


# AC_CONFIG_LIBCONFIG_IN_PKGCONFIG
# --------------------------------
# Enable pkgconfig support in libconfig script (default)
AC_DEFUN([AC_CONFIG_LIBCONFIG_IN_PKGCONFIG],
[m4_define([AC_CONFIG_LIBCONFIG_IN_USEPKGCONFIG], [true])
])dnl


# AC_CONFIG_LIBCONFIG_IN_STATIC
# -----------------------------
# Disable pkgconfig support in libconfig script
AC_DEFUN([AC_CONFIG_LIBCONFIG_IN_STATIC],
[m4_define([AC_CONFIG_LIBCONFIG_IN_USEPKGCONFIG], [false])
])dnl