OK, here is what I came up with.  I'm not that experienced with m4 yet,
so I wonder if the more experienced amongst you can conceive of any reason
why the following ATTRIBUTE-LIST approach is bad?  It has the advantage
of catching some problems at autoconf-time (instead of configure run-time)
and it makes it possible to update the help-string with the macro attributes
given in configure.in...

(I'm going to change from define/undefine to pushdef/popdef, but that's
about all I can think of right now...)

Typical usage from configure.in:

SIM_CHECK_SIMAGE([
  AC_DEFINE(HAVE_LIBSIMAGE)
  COIN_EXTRA_CPPFLAGS="$COIN_EXTRA_CPPFLAGS $sim_ac_simage_cppflags"
  COIN_EXTRA_LDFLAGS="$COIN_EXTRA_LDFLAGS $sim_ac_simage_ldflags"
  COIN_EXTRA_LIBS="$sim_ac_simage_libs $COIN_EXTRA_LIBS"
],[
  AC_MSG_WARN(simage development system not found)
],[
  searchprefix
])

Macro file (simage.m4):

dnl ************************************************************************
dnl Usage:
dnl   SIM_CHECK_SIMAGE( ACTION-IF-FOUND, ACTION-IF-NOT-FOUND, ATTRIBUTE-LIST )
dnl
dnl Description:
dnl   This macro locates the simage development system.  If it is found, the
dnl   set of variables listed below are set up as described and made available
dnl   to the configure script.
dnl
dnl ATTRIBUTE-LIST Options:
dnl   [no]default              whether --with-simage is default or not
dnl                            (default on)
dnl   [no]searchprefix         whether $exec_prefix is to be searched
dnl                            (default off)
dnl
dnl Autoconf Variables:
dnl   $sim_ac_simage_avail     yes | no
dnl   $sim_ac_simage_cppflags  (extra flags the compiler needs for simage)
dnl   $sim_ac_simage_ldflags   (extra flags the linker needs for simage)
dnl   $sim_ac_simage_libs      (link libraries the linker needs for simage)
dnl   $CPPFLAGS                $CPPFLAGS $sim_ac_simage_cppflags
dnl   $LDFLAGS                 $LDFLAGS $sim_ac_simage_ldflags
dnl   $LIBS                    $sim_ac_simage_libs $LIBS
dnl
dnl Automake Conditionals:
dnl   HAVE_SIMAGE              (code disabled)
dnl
dnl Config.h Defines:
dnl   HAVE_SIMAGE              (code disabled)
dnl   HAVE_SIMAGE_H            (code disabled)
dnl
dnl Authors:
dnl   Morten Eriksen, <[EMAIL PROTECTED]>
dnl   Lars J. Aas, <[EMAIL PROTECTED]>
dnl
dnl TODO:
dnl * [mortene:20000122] make sure this work on MSWin (with Cygwin)
dnl * [larsa:20000220] find a less strict AC_PREREQ setting
dnl

define([sim4_strcompact],[patsubst(patsubst(translit([$1],[
        ], [  ]), [\b +\b], [ ]), [^ \| $], [])])dnl

AC_DEFUN(SIM_CHECK_SIMAGE,[
dnl Autoconf is a developer tool, so don't bother to support older versions.
AC_PREREQ([2.14.1])

divert(-1)
# set up attribute variable default values
define([sim4_simage_with],yes)
define([sim4_simage_searchprefix],no)

# set up all the valid attributes to zero-expanding m4 defines
define([default],[define([sim4_simage_with],yes)])
define([nodefault],[define([sim4_simage_with],no)])
define([searchprefix],[define([sim4_simage_searchprefix],yes)])
define([nosearchprefix],[define([sim4_simage_searchprefix],no)])

# ensure that ATTRIBUTE-LIST expands to the empty string (when compacted) -
# otherwise there's a problem with SIM_CHECK_SIMAGE's given arguments
ifelse(sim4_strcompact($3), , ,
  [errprint([SIM_CHECK_SIMAGE ATTRIBUTE-LIST parse error: ]sim4_strcompact($3)[
])])

# clean up the attribute definitions
undefine([default])
undefine([nodefault])
undefine([searchprefix])
undefine([nosearchprefix])
divert

AC_ARG_WITH(simage, AC_HELP_STRING([--with-simage=DIR], changequote({,}){use simage 
for loading texture files [default=}sim4_simage_with{]}changequote([,])), , 
[with_simage=sim4_simage_with])

sim_ac_simage_avail=no

if test "x$with_simage" != "xno"; then
  sim_ac_path=$PATH
  if test "x$with_simage" != "xyes"; then
    sim_ac_path=${with_simage}/bin:$PATH
    ifelse(sim4_simage_searchprefix, yes,
    [if test "x$exec_prefix" != "xNONE"; then
      sim_ac_path=$sim_ac_path:$sim_ac_path/bin
    fi], :)
  fi

  AC_PATH_PROG(sim_ac_conf_cmd, simage-config, true, $sim_ac_path)
  if test "x$sim_ac_conf_cmd" = "xtrue"; then
    AC_MSG_WARN(could not find 'simage-config' in $sim_ac_path)
  fi

  sim_ac_simage_cppflags=`$sim_ac_conf_cmd --cppflags`
  sim_ac_simage_ldflags=`$sim_ac_conf_cmd --ldflags`
  sim_ac_simage_libs=`$sim_ac_conf_cmd --libs`

  AC_CACHE_CHECK([whether the simage library is available],
    sim_cv_lib_simage_avail, [
    sim_ac_save_cppflags=$CPPFLAGS
    sim_ac_save_ldflags=$LDFLAGS
    sim_ac_save_libs=$LIBS
    CPPFLAGS="$CPPFLAGS $sim_ac_simage_cppflags"
    LDFLAGS="$LDFLAGS $sim_ac_simage_ldflags"
    LIBS="$sim_ac_simage_libs $LIBS"
    AC_TRY_LINK([#include <simage.h>],
                 [(void)simage_read_image(0L, 0L, 0L, 0L);],
                 sim_cv_lib_simage_avail=yes,
                 sim_cv_lib_simage_avail=no)
    CPPFLAGS=$sim_ac_save_cppflags
    LDFLAGS=$sim_ac_save_ldflags
    LIBS=$sim_ac_save_libs
  ])

  if test x"$sim_cv_lib_simage_avail" = xyes; then
    sim_ac_simage_avail=yes
    CPPFLAGS="$CPPFLAGS $sim_ac_simage_cppflags"
    LDFLAGS="$LDFLAGS $sim_ac_simage_ldflags"
    LIBS="$sim_ac_simage_libs $LIBS"
dnl AM_CONDITIONAL(HAVE_SIMAGE, true)
dnl AC_DEFINE(HAVE_SIMAGE_H, 1,
dnl   [Define this if you have simage.h])
dnl AC_DEFINE(HAVE_SIMAGE, 1,
dnl   [Define this if you are going to use libsimage])
    ifelse($1, , :, $1)
  else
dnl AM_CONDITIONAL(HAVE_SIMAGE, false)
    ifelse($2, , :, $2)
  fi
else
  ifelse($2, , :, $2)
fi
])

  Lars J

Reply via email to