root/ImageMagick/trunk/m4/ax_prefix_config_h.m4

Revision 1, 8.9 KB (checked in by cristy, 3 months ago)


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