Back to the Main Page. Download the M4 Source.

ac_create_prefix_config_h_

Synopsis

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

Version

1.2 (2002/04/22)     guidod @ ac-archive-0.5.37

Author

Guido Draheim <guidod@gmx.de>

Description

_______ easy creation of an installable library config header _______

this is a new variant from ac_prefix_config_ / ac_create_prefix_config_h    this one will treat Defines special if starting with a lowercase char
   as it is common with #define const or #define off_t
   they'll get defined always (!!) and they start off with the non-modified
   PREFIX (which is by-default the PACKAGE-name being usually all-lowercase)

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, derived from OUTPUT-HEADER
           if OUTPUT-HEADER has a "/", use the basename
           if OUTPUT-HEADER has a "-", use the section after it.
           otherwise, just config.h

   In most cases, the configure.in will contain a line saying
         AC_CONFIG_HEADER(config.h) 
   somewhere *before* AC_OUTPUT and a simple line saying
        AC_PREFIX_CONFIG_HEADER
   somewhere *after* AC_OUTPUT.

example:    AC_INIT(config.h.in)        # config.h.in as created by "autoheader"
   AM_INIT_AUTOMAKE(testpkg, 0.1.1)   # "#undef VERSION" and "PACKAGE"
   AM_CONFIG_HEADER(config.h)         #                in config.h.in
   AC_MEMORY_H                        # "#undef NEED_MEMORY_H"
   AC_C_CONST_H                       # "#undef const"
   AC_OUTPUT(Makefile)                # creates the "config.h" now
   AC_CREATE_PREFIX_CONFIG_H          # creates "testpkg-config.h"
         and the resulting "testpkg-config.h" contains lines 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 "testpkg-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 "testpkg-confdefs.h.in" manually. :-)

M4 Source Code


AC_DEFUN([AC_CREATE_PREFIX_CONFIG_H_],
[changequote({, })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 '/^[^A-Za-z_]/s/^/_/'`
ac_prefix_conf_UPP=`echo $ac_prefix_conf_PKG | sed -e '/^[^A-Za-z_]/s/^/_/' -e 'y:abcdefghijklmnopqrstuvwxyz-:ABCDEFGHIJKLMNOPQRSTUVWXYZ_:'`
ac_prefix_conf_INP=`echo ifelse($3, , _, $3)`
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
changequote([, ])dnl
if test -z "$ac_prefix_conf_PKG" ; then
   AC_MSG_ERROR([no prefix for _PREFIX_PKG_CONFIG_H])
else
  AC_MSG_RESULT(creating $ac_prefix_conf_OUT - prefix $ac_prefix_conf_UPP for $ac_prefix_conf_INP defines)
  if test -f $ac_prefix_conf_INP ; then
    AC_ECHO_MKFILE([/* automatically generated */], $ac_prefix_conf_OUT)
changequote({, })dnl 
    echo '#ifndef '$ac_prefix_conf_DEF >>$ac_prefix_conf_OUT
    echo '#define '$ac_prefix_conf_DEF' 1' >>$ac_prefix_conf_OUT
    echo ' ' >>$ac_prefix_conf_OUT
    echo /'*' $ac_prefix_conf_OUT. Generated automatically at end of configure. '*'/ >>$ac_prefix_conf_OUT

    echo '# generated for temporary usage' >conftest.sed
    echo 's/#define  *\([A-Z_][A-Za-z0-9_]*\)\(.*\)/#ifndef '$ac_prefix_conf_UPP'_\1 \' >>conftest.sed
    echo '#define '$ac_prefix_conf_UPP'_\1 \2 \' >>conftest.sed
    echo '#endif/' >>conftest.sed
    echo 's/#define  *\([a-z][A-Za-z0-9_]*\)\(.*\)/#ifndef '$ac_prefix_conf_LOW'_\1 \' >>conftest.sed
    echo '#define '$ac_prefix_conf_LOW'_\1 \2 \' >>conftest.sed
    echo '#endif/' >>conftest.sed
    echo 's/^.[*] *#undef  *\([a-z][a-z_]*[a-z]\)  *[*]. *$/#ifndef '$ac_prefix_conf_LOW'_\1 \' >>conftest.sed
    echo '#define '$ac_prefix_conf_LOW'_\1 \1 \' >>conftest.sed
    echo '#endif/' >>conftest.sed
    echo 's/#undef  *\([a-z]\)/#undef '$ac_prefix_conf_LOW'_\1/' >>conftest.sed
    echo 's/#undef  *\([A-Z_]\)/#undef '$ac_prefix_conf_UPP'_\1/' >>conftest.sed
    sed -f conftest.sed $ac_prefix_conf_INP >>$ac_prefix_conf_OUT
    echo ' ' >>$ac_prefix_conf_OUT
    echo '/*' $ac_prefix_conf_DEF '*/' >>$ac_prefix_conf_OUT
    echo '#endif' >>$ac_prefix_conf_OUT
changequote([, ])dnl
  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])