Blame m4/ax_prefix_config_h.m4

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