Google

Back to the Main Page.

ax_prefix_config_h

Download the M4 Source.

Synopsis

AX_PREFIX_CONFIG_H [(OUTPUT-HEADER [,PREFIX [,ORIG-HEADER]])]

Version

1.2 (2003/01/06)     guidod @ ac-archive-0.5.39

Author

Guiodo Draheim <guidod@gmx.de>

Description

* this is a new variant from ac_prefix_config_
this one will use a lowercase-prefix if the config-define was starting with a lowercase-char, e.g.
   #define const or #define restrict or #define off_t
(and this one can live in another directory, e.g. testpkg/config.h therefore I decided to move the output-header to be the first arg)

takes the usual config.h generated header file; looks for each of the generated "#define SOMEDEF" lines, and prefixes the defined name (ie. makes it "#define PREFIX_SOMEDEF". The result is written to the output config.header file. The PREFIX is converted to uppercase for the conversions.

- default OUTPUT-HEADER = $PACKAGE-config.h
- default PREFIX = $PACKAGE
- default ORIG-HEADER, from AM_CONFIG_HEADER(config.h)

Your configure.ac script should contain both macros in this order, and unlike the earlier variations of this prefix-macro it is okay to place the AX_PREFIX_CONFIG_H call before the AC_OUTPUT invokation.

example:
   AC_INIT(config.h.in)        # config.h.in as created by "autoheader"
   AM_INIT_AUTOMAKE(testpkg, 0.1.1)    # makes #undef VERSION and PACKAGE
   AM_CONFIG_HEADER(config.h)          # prep config.h from config.h.in
   AX_PREFIX_CONFIG_H(mylib/_config.h) # prep mylib/_config.h from it..
   AC_MEMORY_H                         # makes "#undef NEED_MEMORY_H"
   AC_C_CONST_H                        # makes "#undef const"
   AC_OUTPUT(Makefile)                 # creates the "config.h" now
                                       # and also mylib/_config.h

if the argument to AX_PREFIX_CONFIG_H would have been omitted then the default outputfile would have been called simply "testpkg-config.h", but even under the name "mylib/_config.h" it contains prefix-defines like
   #ifndef TESTPKG_VERSION 
   #define TESTPKG_VERSION "0.1.1"
   #endif
   #ifndef TESTPKG_NEED_MEMORY_H 
   #define TESTPKG_NEED_MEMORY_H 1
   #endif
   #ifndef _testpkg_const 
   #define _testpkg_const _const
   #endif

   and this "mylib/_config.h" can be installed along with other
   header-files, which is most convenient when creating a shared
   library (that has some headers) where some functionality is
   dependent on the OS-features detected at compile-time. No
   need to invent some "mylib-confdefs.h.in" manually. :-)

Note that some AC_DEFINEs that end up in the config.h file are actually self-referential - e.g. AC_C_INLINE, AC_C_CONST, and the AC_TYPE_OFF_T say that they "will define inline|const|off_t if the system does not do it by itself". You might want to clean up about these - consider an extra mylib/conf.h that reads something like:

    #include <mylib/_config.h>
    #ifndef _testpkg_const
    #define _testpkg_const const
    #endif

and then start using _testpkg_const in the header files. That is also a good thing to differentiate whether some library-user has starting to take up with a different compiler, so perhaps it could read something like this:

   #ifdef _MSC_VER
   #include <mylib/_msvc.h>
   #else
   #include <mylib/_config.h>
   #endif
   #ifndef _testpkg_const
   #define _testpkg_const const
   #endif

M4 Source Code

AC_DEFUN([AX_PREFIX_CONFIG_H],[AC_REQUIRE([AC_CONFIG_HEADER])
AC_CONFIG_COMMANDS([ifelse($1,,$PACKAGE-config.h,$1)],[dnl

ac_prefix_conf_OUT=`echo ifelse($1, , $PACKAGE-config.h, $1)`
ac_prefix_conf_DEF=`echo _$ac_prefix_conf_OUT | sed -e 'y:abcdefghijklmnopqrstuvwxyz./,-:ABCDEFGHIJKLMNOPQRSTUVWXYZ____:'`
ac_prefix_conf_PKG=`echo ifelse($2, , $PACKAGE, $2)`
ac_prefix_conf_LOW=`echo _$ac_prefix_conf_PKG | sed -e 'y:ABCDEFGHIJKLMNOPQRSTUVWXYZ-:abcdefghijklmnopqrstuvwxyz_:'`
ac_prefix_conf_UPP=`echo $ac_prefix_conf_PKG | sed -e 'y:abcdefghijklmnopqrstuvwxyz-:ABCDEFGHIJKLMNOPQRSTUVWXYZ_:'  -e '/^[0-9]/s/^/_/'`
ac_prefix_conf_INP=`echo ifelse($3, , _, $3)`
if test "$ac_prefix_conf_INP" = "_"; then
   for ac_file in : $CONFIG_HEADERS; do test "_$ac_file" = _: && continue
     test -f "$ac_prefix_conf_INP" && continue
     case $ac_file in
        *.h) test -f $ac_file && ac_prefix_conf_INP=$ac_file ;;
        *)
     esac
   done
fi
if test "$ac_prefix_conf_INP" = "_"; then
   case $ac_prefix_conf_OUT in
      */*) ac_prefix_conf_INP=`basename $ac_prefix_conf_OUT` 
      ;;
      *-*) ac_prefix_conf_INP=`echo $ac_prefix_conf_OUT | sed -e 's/[a-zA-Z0-9_]*-//'`
      ;;
      *) ac_prefix_conf_INP=config.h
      ;;
   esac
fi
if test -z "$ac_prefix_conf_PKG" ; then
   AC_MSG_ERROR([no prefix for _PREFIX_PKG_CONFIG_H])
else
  AC_MSG_NOTICE(creating $ac_prefix_conf_OUT - prefix $ac_prefix_conf_UPP for $ac_prefix_conf_INP defines)
  if test -f $ac_prefix_conf_INP ; then
    echo '#ifndef '$ac_prefix_conf_DEF      >$tmp/pconfig.h
    echo '#define '$ac_prefix_conf_DEF' 1' >>$tmp/pconfig.h
    echo ' ' >>$tmp/pconfig.h
    echo /'*' $ac_prefix_conf_OUT. Generated automatically at end of configure. '*'/ >>$tmp/pconfig.h

    echo 's/#undef  *\([A-Z_]\)/#undef '$ac_prefix_conf_UPP'_\1/' >conftest.prefix
    echo 's/#undef  *\([a-z]\)/#undef '$ac_prefix_conf_LOW'_\1/' >>conftest.prefix
    echo 's/#define  *\([A-Z_][A-Za-z0-9_]*\)\(.*\)/#ifndef '$ac_prefix_conf_UPP"_\\1 \\" >>conftest.prefix
    echo '#define '$ac_prefix_conf_UPP"_\\1 \\2 \\" >>conftest.prefix
    echo '#endif/' >>conftest.prefix
    echo 's/#define  *\([a-z][A-Za-z0-9_]*\)\(.*\)/#ifndef '$ac_prefix_conf_LOW"_\\1 \\" >>conftest.prefix
    echo '#define '$ac_prefix_conf_LOW"_\\1 \\2 \\" >>conftest.prefix
    echo '#endif/' >>conftest.prefix
    sed -f conftest.prefix $ac_prefix_conf_INP >>$tmp/pconfig.h
    echo ' ' >>$tmp/pconfig.h
    echo '/* once:' $ac_prefix_conf_DEF '*/' >>$tmp/pconfig.h
    echo '#endif' >>$tmp/pconfig.h
    if cmp -s $ac_prefix_conf_OUT $tmp/pconfig.h 2>/dev/null; then
      AC_MSG_NOTICE([$ac_prefix_conf_OUT is unchanged])
    else
      ac_dir=`AS_DIRNAME(["$ac_prefix_conf_OUT"])`
      AS_MKDIR_P(["$ac_dir"])
      rm -f $ac_prefix_conf_OUT
      mv $tmp/pconfig.h $ac_prefix_conf_OUT
    fi
  else
    AC_MSG_ERROR([input file $ac_prefix_conf_IN does not exist - dnl
    skip generating $ac_prefix_conf_OUT])
  fi
  rm -f conftest.* 
fi
],[PACKAGE="$PACKAGE"])])