Blame m4/ax_prefix_config_h.m4

Packit 8c9aa0
# ===========================================================================
Packit 8c9aa0
#    http://www.gnu.org/software/autoconf-archive/ax_prefix_config_h.html
Packit 8c9aa0
# ===========================================================================
Packit 8c9aa0
#
Packit 8c9aa0
# SYNOPSIS
Packit 8c9aa0
#
Packit 8c9aa0
#   AX_PREFIX_CONFIG_H [(OUTPUT-HEADER [,PREFIX [,ORIG-HEADER]])]
Packit 8c9aa0
#
Packit 8c9aa0
# DESCRIPTION
Packit 8c9aa0
#
Packit 8c9aa0
#   This is a new variant from ac_prefix_config_ this one will use a
Packit 8c9aa0
#   lowercase-prefix if the config-define was starting with a
Packit 8c9aa0
#   lowercase-char, e.g. "#define const", "#define restrict", or "#define
Packit 8c9aa0
#   off_t", (and this one can live in another directory, e.g.
Packit 8c9aa0
#   testpkg/config.h therefore I decided to move the output-header to be the
Packit 8c9aa0
#   first arg)
Packit 8c9aa0
#
Packit 8c9aa0
#   takes the usual config.h generated header file; looks for each of the
Packit 8c9aa0
#   generated "#define SOMEDEF" lines, and prefixes the defined name (ie.
Packit 8c9aa0
#   makes it "#define PREFIX_SOMEDEF". The result is written to the output
Packit 8c9aa0
#   config.header file. The PREFIX is converted to uppercase for the
Packit 8c9aa0
#   conversions.
Packit 8c9aa0
#
Packit 8c9aa0
#   Defaults:
Packit 8c9aa0
#
Packit 8c9aa0
#     OUTPUT-HEADER = $PACKAGE-config.h
Packit 8c9aa0
#     PREFIX = $PACKAGE
Packit 8c9aa0
#     ORIG-HEADER, from AM_CONFIG_HEADER(config.h)
Packit 8c9aa0
#
Packit 8c9aa0
#   Your configure.ac script should contain both macros in this order, and
Packit 8c9aa0
#   unlike the earlier variations of this prefix-macro it is okay to place
Packit 8c9aa0
#   the AX_PREFIX_CONFIG_H call before the AC_OUTPUT invokation.
Packit 8c9aa0
#
Packit 8c9aa0
#   Example:
Packit 8c9aa0
#
Packit 8c9aa0
#     AC_INIT(config.h.in)        # config.h.in as created by "autoheader"
Packit 8c9aa0
#     AM_INIT_AUTOMAKE(testpkg, 0.1.1)    # makes #undef VERSION and PACKAGE
Packit 8c9aa0
#     AM_CONFIG_HEADER(config.h)          # prep config.h from config.h.in
Packit 8c9aa0
#     AX_PREFIX_CONFIG_H(mylib/_config.h) # prep mylib/_config.h from it..
Packit 8c9aa0
#     AC_MEMORY_H                         # makes "#undef NEED_MEMORY_H"
Packit 8c9aa0
#     AC_C_CONST_H                        # makes "#undef const"
Packit 8c9aa0
#     AC_OUTPUT(Makefile)                 # creates the "config.h" now
Packit 8c9aa0
#                                         # and also mylib/_config.h
Packit 8c9aa0
#
Packit 8c9aa0
#   if the argument to AX_PREFIX_CONFIG_H would have been omitted then the
Packit 8c9aa0
#   default outputfile would have been called simply "testpkg-config.h", but
Packit 8c9aa0
#   even under the name "mylib/_config.h" it contains prefix-defines like
Packit 8c9aa0
#
Packit 8c9aa0
#     #ifndef TESTPKG_VERSION
Packit 8c9aa0
#     #define TESTPKG_VERSION "0.1.1"
Packit 8c9aa0
#     #endif
Packit 8c9aa0
#     #ifndef TESTPKG_NEED_MEMORY_H
Packit 8c9aa0
#     #define TESTPKG_NEED_MEMORY_H 1
Packit 8c9aa0
#     #endif
Packit 8c9aa0
#     #ifndef _testpkg_const
Packit 8c9aa0
#     #define _testpkg_const _const
Packit 8c9aa0
#     #endif
Packit 8c9aa0
#
Packit 8c9aa0
#   and this "mylib/_config.h" can be installed along with other
Packit 8c9aa0
#   header-files, which is most convenient when creating a shared library
Packit 8c9aa0
#   (that has some headers) where some functionality is dependent on the
Packit 8c9aa0
#   OS-features detected at compile-time. No need to invent some
Packit 8c9aa0
#   "mylib-confdefs.h.in" manually. :-)
Packit 8c9aa0
#
Packit 8c9aa0
#   Note that some AC_DEFINEs that end up in the config.h file are actually
Packit 8c9aa0
#   self-referential - e.g. AC_C_INLINE, AC_C_CONST, and the AC_TYPE_OFF_T
Packit 8c9aa0
#   say that they "will define inline|const|off_t if the system does not do
Packit 8c9aa0
#   it by itself". You might want to clean up about these - consider an
Packit 8c9aa0
#   extra mylib/conf.h that reads something like:
Packit 8c9aa0
#
Packit 8c9aa0
#     #include <mylib/_config.h>
Packit 8c9aa0
#     #ifndef _testpkg_const
Packit 8c9aa0
#     #define _testpkg_const const
Packit 8c9aa0
#     #endif
Packit 8c9aa0
#
Packit 8c9aa0
#   and then start using _testpkg_const in the header files. That is also a
Packit 8c9aa0
#   good thing to differentiate whether some library-user has starting to
Packit 8c9aa0
#   take up with a different compiler, so perhaps it could read something
Packit 8c9aa0
#   like this:
Packit 8c9aa0
#
Packit 8c9aa0
#     #ifdef _MSC_VER
Packit 8c9aa0
#     #include <mylib/_msvc.h>
Packit 8c9aa0
#     #else
Packit 8c9aa0
#     #include <mylib/_config.h>
Packit 8c9aa0
#     #endif
Packit 8c9aa0
#     #ifndef _testpkg_const
Packit 8c9aa0
#     #define _testpkg_const const
Packit 8c9aa0
#     #endif
Packit 8c9aa0
#
Packit 8c9aa0
# LICENSE
Packit 8c9aa0
#
Packit 8c9aa0
#   Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
Packit 8c9aa0
#   Copyright (c) 2008 Marten Svantesson
Packit 8c9aa0
#   Copyright (c) 2008 Gerald Point <Gerald.Point@labri.fr>
Packit 8c9aa0
#
Packit 8c9aa0
#   This program is free software; you can redistribute it and/or modify it
Packit 8c9aa0
#   under the terms of the GNU General Public License as published by the
Packit 8c9aa0
#   Free Software Foundation; either version 3 of the License, or (at your
Packit 8c9aa0
#   option) any later version.
Packit 8c9aa0
#
Packit 8c9aa0
#   This program is distributed in the hope that it will be useful, but
Packit 8c9aa0
#   WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 8c9aa0
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Packit 8c9aa0
#   Public License for more details.
Packit 8c9aa0
#
Packit 8c9aa0
#   You should have received a copy of the GNU General Public License along
Packit 8c9aa0
#   with this program. If not, see <http://www.gnu.org/licenses/>.
Packit 8c9aa0
#
Packit 8c9aa0
#   As a special exception, the respective Autoconf Macro's copyright owner
Packit 8c9aa0
#   gives unlimited permission to copy, distribute and modify the configure
Packit 8c9aa0
#   scripts that are the output of Autoconf when processing the Macro. You
Packit 8c9aa0
#   need not follow the terms of the GNU General Public License when using
Packit 8c9aa0
#   or distributing such scripts, even though portions of the text of the
Packit 8c9aa0
#   Macro appear in them. The GNU General Public License (GPL) does govern
Packit 8c9aa0
#   all other use of the material that constitutes the Autoconf Macro.
Packit 8c9aa0
#
Packit 8c9aa0
#   This special exception to the GPL applies to versions of the Autoconf
Packit 8c9aa0
#   Macro released by the Autoconf Archive. When you make and distribute a
Packit 8c9aa0
#   modified version of the Autoconf Macro, you may extend this special
Packit 8c9aa0
#   exception to the GPL to apply to your modified version as well.
Packit 8c9aa0
Packit 8c9aa0
#serial 11
Packit 8c9aa0
Packit 8c9aa0
AC_DEFUN([AX_PREFIX_CONFIG_H],[dnl
Packit 8c9aa0
AC_PREREQ([2.62])
Packit 8c9aa0
AC_BEFORE([AC_CONFIG_HEADERS],[$0])dnl
Packit 8c9aa0
AC_CONFIG_COMMANDS([ifelse($1,,$PACKAGE-config.h,$1)],[dnl
Packit 8c9aa0
AS_VAR_PUSHDEF([_OUT],[ac_prefix_conf_OUT])dnl
Packit 8c9aa0
AS_VAR_PUSHDEF([_DEF],[ac_prefix_conf_DEF])dnl
Packit 8c9aa0
AS_VAR_PUSHDEF([_PKG],[ac_prefix_conf_PKG])dnl
Packit 8c9aa0
AS_VAR_PUSHDEF([_LOW],[ac_prefix_conf_LOW])dnl
Packit 8c9aa0
AS_VAR_PUSHDEF([_UPP],[ac_prefix_conf_UPP])dnl
Packit 8c9aa0
AS_VAR_PUSHDEF([_INP],[ac_prefix_conf_INP])dnl
Packit 8c9aa0
m4_pushdef([_script],[conftest.prefix])dnl
Packit 8c9aa0
m4_pushdef([_symbol],[m4_cr_Letters[]m4_cr_digits[]_])dnl
Packit 8c9aa0
_OUT=`echo ifelse($1, , $PACKAGE-config.h, $1)`
Packit 8c9aa0
_DEF=`echo _$_OUT | sed -e "y:m4_cr_letters:m4_cr_LETTERS[]:" -e "s/@<:@^m4_cr_Letters@:>@/_/g"`
Packit 8c9aa0
_PKG=`echo ifelse($2, , $PACKAGE, $2)`
Packit 8c9aa0
_LOW=`echo _$_PKG | sed -e "y:m4_cr_LETTERS-:m4_cr_letters[]_:"`
Packit 8c9aa0
_UPP=`echo $_PKG | sed -e "y:m4_cr_letters-:m4_cr_LETTERS[]_:"  -e "/^@<:@m4_cr_digits@:>@/s/^/_/"`
Packit 8c9aa0
_INP=`echo "ifelse($3,,,$3)" | sed -e 's/ *//'`
Packit 8c9aa0
if test ".$_INP" = "."; then
Packit 8c9aa0
   for ac_file in : $CONFIG_HEADERS; do test "_$ac_file" = _: && continue
Packit 8c9aa0
     case "$ac_file" in
Packit 8c9aa0
        *.h) _INP=$ac_file ;;
Packit 8c9aa0
        *)
Packit 8c9aa0
     esac
Packit 8c9aa0
     test ".$_INP" != "." && break
Packit 8c9aa0
   done
Packit 8c9aa0
fi
Packit 8c9aa0
if test ".$_INP" = "."; then
Packit 8c9aa0
   case "$_OUT" in
Packit 8c9aa0
      */*) _INP=`basename "$_OUT"`
Packit 8c9aa0
      ;;
Packit 8c9aa0
      *-*) _INP=`echo "$_OUT" | sed -e "s/@<:@_symbol@:>@*-//"`
Packit 8c9aa0
      ;;
Packit 8c9aa0
      *) _INP=config.h
Packit 8c9aa0
      ;;
Packit 8c9aa0
   esac
Packit 8c9aa0
fi
Packit 8c9aa0
if test -z "$_PKG" ; then
Packit 8c9aa0
   AC_MSG_ERROR([no prefix for _PREFIX_PKG_CONFIG_H])
Packit 8c9aa0
else
Packit 8c9aa0
  if test ! -f "$_INP" ; then if test -f "$srcdir/$_INP" ; then
Packit 8c9aa0
     _INP="$srcdir/$_INP"
Packit 8c9aa0
  fi fi
Packit 8c9aa0
  AC_MSG_NOTICE(creating $_OUT - prefix $_UPP for $_INP defines)
Packit 8c9aa0
  if test -f $_INP ; then
Packit 8c9aa0
    AS_ECHO(["s/^@%:@undef  *\\(@<:@m4_cr_LETTERS[]_@:>@\\)/@%:@undef $_UPP""_\\1/"]) > _script
Packit 8c9aa0
    AS_ECHO(["s/^@%:@undef  *\\(@<:@m4_cr_letters@:>@\\)/@%:@undef $_LOW""_\\1/"]) >> _script
Packit 8c9aa0
    AS_ECHO(["s/^@%:@def[]ine  *\\(@<:@m4_cr_LETTERS[]_@:>@@<:@_symbol@:>@*\\)\\(.*\\)/@%:@ifndef $_UPP""_\\1\\"]) >> _script
Packit 8c9aa0
    AS_ECHO(["@%:@def[]ine $_UPP""_\\1\\2\\"]) >> _script
Packit 8c9aa0
    AS_ECHO(["@%:@endif/"]) >> _script
Packit 8c9aa0
    AS_ECHO(["s/^@%:@def[]ine  *\\(@<:@m4_cr_letters@:>@@<:@_symbol@:>@*\\)\\(.*\\)/@%:@ifndef $_LOW""_\\1\\"]) >> _script
Packit 8c9aa0
    AS_ECHO(["@%:@define $_LOW""_\\1\\2\\"]) >> _script
Packit 8c9aa0
    AS_ECHO(["@%:@endif/"]) >> _script
Packit 8c9aa0
    # now executing _script on _DEF input to create _OUT output file
Packit 8c9aa0
    echo "@%:@ifndef $_DEF"      >$tmp/pconfig.h
Packit 8c9aa0
    echo "@%:@def[]ine $_DEF 1" >>$tmp/pconfig.h
Packit 8c9aa0
    echo ' ' >>$tmp/pconfig.h
Packit 8c9aa0
    echo /'*' $_OUT. Generated automatically at end of configure. '*'/ >>$tmp/pconfig.h
Packit 8c9aa0
Packit 8c9aa0
    sed -f _script $_INP >>$tmp/pconfig.h
Packit 8c9aa0
    echo ' ' >>$tmp/pconfig.h
Packit 8c9aa0
    echo '/* once:' $_DEF '*/' >>$tmp/pconfig.h
Packit 8c9aa0
    echo "@%:@endif" >>$tmp/pconfig.h
Packit 8c9aa0
    if cmp -s $_OUT $tmp/pconfig.h 2>/dev/null; then
Packit 8c9aa0
      AC_MSG_NOTICE([$_OUT is unchanged])
Packit 8c9aa0
    else
Packit 8c9aa0
      ac_dir=`AS_DIRNAME(["$_OUT"])`
Packit 8c9aa0
      AS_MKDIR_P(["$ac_dir"])
Packit 8c9aa0
      rm -f "$_OUT"
Packit 8c9aa0
      mv $tmp/pconfig.h "$_OUT"
Packit 8c9aa0
    fi
Packit 8c9aa0
    cp _script _configs.sed
Packit 8c9aa0
  else
Packit 8c9aa0
    AC_MSG_ERROR([input file $_INP does not exist - skip generating $_OUT])
Packit 8c9aa0
  fi
Packit 8c9aa0
  rm -f conftest.*
Packit 8c9aa0
fi
Packit 8c9aa0
m4_popdef([_symbol])dnl
Packit 8c9aa0
m4_popdef([_script])dnl
Packit 8c9aa0
AS_VAR_POPDEF([_INP])dnl
Packit 8c9aa0
AS_VAR_POPDEF([_UPP])dnl
Packit 8c9aa0
AS_VAR_POPDEF([_LOW])dnl
Packit 8c9aa0
AS_VAR_POPDEF([_PKG])dnl
Packit 8c9aa0
AS_VAR_POPDEF([_DEF])dnl
Packit 8c9aa0
AS_VAR_POPDEF([_OUT])dnl
Packit 8c9aa0
],[PACKAGE="$PACKAGE"])])