source: git/m4/ax_prefix_config_h.m4 @ e4e36c

spielwiese
Last change on this file since e4e36c was 3af3ca, checked in by Oleksandr Motsak <motsak@…>, 13 years ago
FIX: public factory config.h should have ifndef/define/endif guards!
  • Property mode set to 100644
File size: 8.2 KB
Line 
1# ===========================================================================
2#    http://www.gnu.org/software/autoconf-archive/ax_prefix_config_h.html
3# ===========================================================================
4#
5# SYNOPSIS
6#
7#   AX_PREFIX_CONFIG_H (OUTPUT-HEADER, PREFIX [,ORIG-HEADER])
8#
9# DESCRIPTION
10#
11#   This is a new variant from ac_prefix_config_ this one will use a
12#   lowercase-prefix if the config-define was starting with a
13#   lowercase-char, e.g. "#define const", "#define restrict", or "#define
14#   off_t", (and this one can live in another directory, e.g.
15#   testpkg/config.h therefore I decided to move the output-header to be the
16#   first arg)
17#
18#   takes the usual config.h generated header file; looks for each of the
19#   generated "#define SOMEDEF" lines, and prefixes the defined name (ie.
20#   makes it "#define PREFIX_SOMEDEF". The result is written to the output
21#   config.header file. The PREFIX is converted to uppercase for the
22#   conversions.
23#
24#   Defaults:
25#
26#     ORIG-HEADER, from AM_CONFIG_HEADER(config.h)
27#
28#   Your configure.ac script should contain both macros in this order, and
29#   unlike the earlier variations of this prefix-macro it is okay to place
30#   the AX_PREFIX_CONFIG_H call before the AC_OUTPUT invokation.
31#
32#   Example:
33#
34#     AC_INIT(config.h.in)        # config.h.in as created by "autoheader"
35#     AM_INIT_AUTOMAKE(testpkg, 0.1.1)    # makes #undef VERSION and PACKAGE
36#     AM_CONFIG_HEADER(config.h)          # prep config.h from config.h.in
37#     AX_PREFIX_CONFIG_H(mylib/_config.h, TESTPKG_) # prep mylib/_config.h from it..
38#     AC_MEMORY_H                         # makes "#undef NEED_MEMORY_H"
39#     AC_C_CONST_H                        # makes "#undef const"
40#     AC_OUTPUT(Makefile)                 # creates the "config.h" now
41#                                         # and also mylib/_config.h
42#
43#   outputfile called "mylib/_config.h" contains prefix-defines like
44#
45#     #ifndef TESTPKG_VERSION
46#     #define TESTPKG_VERSION "0.1.1"
47#     #endif
48#     #ifndef TESTPKG_NEED_MEMORY_H
49#     #define TESTPKG_NEED_MEMORY_H 1
50#     #endif
51#     #ifndef testpkg_const
52#     #define testpkg_const _const
53#     #endif
54#
55#   and this "mylib/_config.h" can be installed along with other
56#   header-files, which is most convenient when creating a shared library
57#   (that has some headers) where some functionality is dependent on the
58#   OS-features detected at compile-time. No need to invent some
59#   "mylib-confdefs.h.in" manually. :-)
60#
61#   Note that some AC_DEFINEs that end up in the config.h file are actually
62#   self-referential - e.g. AC_C_INLINE, AC_C_CONST, and the AC_TYPE_OFF_T
63#   say that they "will define inline|const|off_t if the system does not do
64#   it by itself". You might want to clean up about these - consider an
65#   extra mylib/conf.h that reads something like:
66#
67#     #include <mylib/_config.h>
68#     #ifndef testpkg_const
69#     #define testpkg_const const
70#     #endif
71#
72#   and then start using testpkg_const in the header files. That is also a
73#   good thing to differentiate whether some library-user has starting to
74#   take up with a different compiler, so perhaps it could read something
75#   like this:
76#
77#     #ifdef _MSC_VER
78#     #include <mylib/_msvc.h>
79#     #else
80#     #include <mylib/_config.h>
81#     #endif
82#     #ifndef testpkg_const
83#     #define testpkg_const const
84#     #endif
85#
86# LICENSE
87#
88#   Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
89#   Copyright (c) 2008 Marten Svantesson
90#   Copyright (c) 2008 Gerald Point <Gerald.Point@labri.fr>
91#
92#   This program is free software; you can redistribute it and/or modify it
93#   under the terms of the GNU General Public License as published by the
94#   Free Software Foundation; either version 3 of the License, or (at your
95#   option) any later version.
96#
97#   This program is distributed in the hope that it will be useful, but
98#   WITHOUT ANY WARRANTY; without even the implied warranty of
99#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
100#   Public License for more details.
101#
102#   You should have received a copy of the GNU General Public License along
103#   with this program. If not, see <http://www.gnu.org/licenses/>.
104#
105#   As a special exception, the respective Autoconf Macro's copyright owner
106#   gives unlimited permission to copy, distribute and modify the configure
107#   scripts that are the output of Autoconf when processing the Macro. You
108#   need not follow the terms of the GNU General Public License when using
109#   or distributing such scripts, even though portions of the text of the
110#   Macro appear in them. The GNU General Public License (GPL) does govern
111#   all other use of the material that constitutes the Autoconf Macro.
112#
113#   This special exception to the GPL applies to versions of the Autoconf
114#   Macro released by the Autoconf Archive. When you make and distribute a
115#   modified version of the Autoconf Macro, you may extend this special
116#   exception to the GPL to apply to your modified version as well.
117
118#serial 11
119
120AC_DEFUN([AX_PREFIX_CONFIG_H],[dnl
121AC_PREREQ([2.62])
122AC_BEFORE([AC_CONFIG_HEADERS],[$0])dnl
123AC_CONFIG_COMMANDS([ifelse($1,,$PACKAGE-config.h,$1)],[dnl
124AS_VAR_PUSHDEF([_OUT],[ac_prefix_conf_OUT])dnl
125AS_VAR_PUSHDEF([_DEF],[ac_prefix_conf_DEF])dnl
126AS_VAR_PUSHDEF([_PKG],[ac_prefix_conf_PKG])dnl
127AS_VAR_PUSHDEF([_LOW],[ac_prefix_conf_LOW])dnl
128AS_VAR_PUSHDEF([_UPP],[ac_prefix_conf_UPP])dnl
129AS_VAR_PUSHDEF([_INP],[ac_prefix_conf_INP])dnl
130m4_pushdef([_script],[conftest.prefix])dnl
131m4_pushdef([_symbol],[m4_cr_Letters[]m4_cr_digits[]_])dnl
132
133_OUT=`echo ifelse($1, , $PACKAGE-config.h, $1)`
134_PKG=`echo $2`
135_LOW=`echo $_PKG | sed -e "y:m4_cr_LETTERS-:m4_cr_letters[]_:"`
136_UPP=`echo $_PKG | sed -e "y:m4_cr_letters-:m4_cr_LETTERS[]_:"  -e "/^@<:@m4_cr_digits@:>@/s/^/_/"`
137_INP=`echo "ifelse($3,,,$3)" | sed -e 's/ *//'`
138_DEF=`echo "$_UPP $PACKAGE $_OUT" | sed -e "y:m4_cr_letters:m4_cr_LETTERS[]:" -e "s/@<:@^m4_cr_Letters@:>@/_/g"`
139
140if test ".$_INP" = "."; then
141   for ac_file in : $CONFIG_HEADERS; do test "_$ac_file" = _: && continue
142     case "$ac_file" in
143        *.h) _INP=$ac_file ;;
144        *)
145     esac
146     test ".$_INP" != "." && break
147   done
148fi
149if test ".$_INP" = "."; then
150   case "$_OUT" in
151      */*) _INP=`basename "$_OUT"`
152      ;;
153      *-*) _INP=`echo "$_OUT" | sed -e "s/@<:@_symbol@:>@*-//"`
154      ;;
155      *) _INP=config.h
156      ;;
157   esac
158fi
159#if test -z "$_PKG" ; then
160#   AC_MSG_ERROR([no prefix for AX_PREFIX_PKG_CONFIG_H])
161#else
162  if test ! -f "$_INP" ; then if test -f "$srcdir/$_INP" ; then
163     _INP="$srcdir/$_INP"
164  fi fi
165  AC_MSG_NOTICE([creating '$_OUT' - prefix '$_UPP' for '$_INP' defines])
166  if test -f $_INP ; then
167    AS_ECHO(["s/^@%:@undef  *\\(@<:@m4_cr_LETTERS[]_@:>@\\)/@%:@undef $_UPP""\\1/"]) > _script
168    AS_ECHO(["s/^@%:@undef  *\\(@<:@m4_cr_letters@:>@\\)/@%:@undef $_LOW""\\1/"]) >> _script
169    AS_ECHO(["s/^@%:@def[]ine  *\\(@<:@m4_cr_LETTERS[]_@:>@@<:@_symbol@:>@*\\)\\(.*\\)/@%:@ifndef $_UPP""\\1\\"]) >> _script
170    AS_ECHO(["@%:@def[]ine $_UPP""\\1\\2\\"]) >> _script
171    AS_ECHO(["@%:@endif/"]) >> _script
172    AS_ECHO(["s/^@%:@def[]ine  *\\(@<:@m4_cr_letters@:>@@<:@_symbol@:>@*\\)\\(.*\\)/@%:@ifndef $_LOW""\\1\\"]) >> _script
173    AS_ECHO(["@%:@define $_LOW""\\1\\2\\"]) >> _script
174    AS_ECHO(["@%:@endif/"]) >> _script
175    # now executing _script on _DEF input to create _OUT output file
176    echo "@%:@ifndef $_DEF"      >$tmp/pconfig.h
177    echo "@%:@def[]ine $_DEF 1" >>$tmp/pconfig.h
178    echo ' ' >>$tmp/pconfig.h
179    echo /'*' $_OUT. Generated automatically at end of configure. '*'/ >>$tmp/pconfig.h
180
181    sed -f _script $_INP >>$tmp/pconfig.h
182    echo ' ' >>$tmp/pconfig.h
183    echo '/* once:' $_DEF '*/' >>$tmp/pconfig.h
184    echo "@%:@endif" >>$tmp/pconfig.h
185    if cmp -s $_OUT $tmp/pconfig.h 2>/dev/null; then
186      AC_MSG_NOTICE([$_OUT is unchanged])
187    else
188      ac_dir=`AS_DIRNAME(["$_OUT"])`
189      AS_MKDIR_P(["$ac_dir"])
190      rm -f "$_OUT"
191      mv $tmp/pconfig.h "$_OUT"
192    fi
193    cp _script _configs.sed
194    rm _configs.sed
195  else
196    AC_MSG_ERROR([input file $_INP does not exist - skip generating $_OUT])
197  fi
198  rm -f conftest.*
199#fi
200m4_popdef([_symbol])dnl
201m4_popdef([_script])dnl
202AS_VAR_POPDEF([_INP])dnl
203AS_VAR_POPDEF([_UPP])dnl
204AS_VAR_POPDEF([_LOW])dnl
205AS_VAR_POPDEF([_PKG])dnl
206AS_VAR_POPDEF([_DEF])dnl
207AS_VAR_POPDEF([_OUT])dnl
208],[PACKAGE="$PACKAGE"])])
Note: See TracBrowser for help on using the repository browser.