beta-0.89.2
[luatex.git] / source / libs / zziplib / zziplib-0.13.62 / m4 / ax_prefix_config_h.m4
blob70dee8fb4eca963fc564ae1fd59d445d03daf97f
1 dnl @synopsis AX_PREFIX_CONFIG_H [(OUTPUT-HEADER [,PREFIX [,ORIG-HEADER]])]
2 dnl
3 dnl This is a new variant from ac_prefix_config_ this one will use a
4 dnl lowercase-prefix if the config-define was starting with a
5 dnl lowercase-char, e.g. "#define const", "#define restrict", or
6 dnl "#define off_t", (and this one can live in another directory, e.g.
7 dnl testpkg/config.h therefore I decided to move the output-header to
8 dnl be the first arg)
9 dnl
10 dnl takes the usual config.h generated header file; looks for each of
11 dnl the generated "#define SOMEDEF" lines, and prefixes the defined
12 dnl name (ie. makes it "#define PREFIX_SOMEDEF". The result is written
13 dnl to the output config.header file. The PREFIX is converted to
14 dnl uppercase for the conversions.
15 dnl
16 dnl Defaults:
17 dnl
18 dnl   OUTPUT-HEADER = $PACKAGE-config.h
19 dnl   PREFIX = $PACKAGE
20 dnl   ORIG-HEADER, from AM_CONFIG_HEADER(config.h)
21 dnl
22 dnl Your configure.ac script should contain both macros in this order,
23 dnl and unlike the earlier variations of this prefix-macro it is okay
24 dnl to place the AX_PREFIX_CONFIG_H call before the AC_OUTPUT
25 dnl invokation.
26 dnl
27 dnl Example:
28 dnl
29 dnl   AC_INIT(config.h.in)        # config.h.in as created by "autoheader"
30 dnl   AM_INIT_AUTOMAKE(testpkg, 0.1.1)    # makes #undef VERSION and PACKAGE
31 dnl   AM_CONFIG_HEADER(config.h)          # prep config.h from config.h.in
32 dnl   AX_PREFIX_CONFIG_H(mylib/_config.h) # prep mylib/_config.h from it..
33 dnl   AC_MEMORY_H                         # makes "#undef NEED_MEMORY_H"
34 dnl   AC_C_CONST_H                        # makes "#undef const"
35 dnl   AC_OUTPUT(Makefile)                 # creates the "config.h" now
36 dnl                                       # and also mylib/_config.h
37 dnl
38 dnl if the argument to AX_PREFIX_CONFIG_H would have been omitted then
39 dnl the default outputfile would have been called simply
40 dnl "testpkg-config.h", but even under the name "mylib/_config.h" it
41 dnl contains prefix-defines like
42 dnl
43 dnl   #ifndef TESTPKG_VERSION
44 dnl   #define TESTPKG_VERSION "0.1.1"
45 dnl   #endif
46 dnl   #ifndef TESTPKG_NEED_MEMORY_H
47 dnl   #define TESTPKG_NEED_MEMORY_H 1
48 dnl   #endif
49 dnl   #ifndef _testpkg_const
50 dnl   #define _testpkg_const _const
51 dnl   #endif
52 dnl
53 dnl and this "mylib/_config.h" can be installed along with other
54 dnl header-files, which is most convenient when creating a shared
55 dnl library (that has some headers) where some functionality is
56 dnl dependent on the OS-features detected at compile-time. No need to
57 dnl invent some "mylib-confdefs.h.in" manually. :-)
58 dnl
59 dnl Note that some AC_DEFINEs that end up in the config.h file are
60 dnl actually self-referential - e.g. AC_C_INLINE, AC_C_CONST, and the
61 dnl AC_TYPE_OFF_T say that they "will define inline|const|off_t if the
62 dnl system does not do it by itself". You might want to clean up about
63 dnl these - consider an extra mylib/conf.h that reads something like:
64 dnl
65 dnl    #include <mylib/_config.h>
66 dnl    #ifndef _testpkg_const
67 dnl    #define _testpkg_const const
68 dnl    #endif
69 dnl
70 dnl and then start using _testpkg_const in the header files. That is
71 dnl also a good thing to differentiate whether some library-user has
72 dnl starting to take up with a different compiler, so perhaps it could
73 dnl read something like this:
74 dnl
75 dnl   #ifdef _MSC_VER
76 dnl   #include <mylib/_msvc.h>
77 dnl   #else
78 dnl   #include <mylib/_config.h>
79 dnl   #endif
80 dnl   #ifndef _testpkg_const
81 dnl   #define _testpkg_const const
82 dnl   #endif
83 dnl
84 dnl @category Misc
85 dnl @author Guido U. Draheim <guidod@gmx.de>
86 dnl @version 2003-07-03
87 dnl @license GPLWithACException
88 AC_DEFUN([AX_PREFIX_CONFIG_H],[dnl
89 AC_PROVIDE_IFELSE([AC_CONFIG_HEADERS], dnl
90    ,[warning if no AC_CONFIG_HEADERS precedes $ ])dnl 
91 AC_CONFIG_COMMANDS([ifelse($1,,$PACKAGE-config.h,$1)],[dnl
92 AS_VAR_PUSHDEF([_OUT],[ac_prefix_conf_OUT])dnl
93 AS_VAR_PUSHDEF([_DEF],[ac_prefix_conf_DEF])dnl
94 AS_VAR_PUSHDEF([_PKG],[ac_prefix_conf_PKG])dnl
95 AS_VAR_PUSHDEF([_LOW],[ac_prefix_conf_LOW])dnl
96 AS_VAR_PUSHDEF([_UPP],[ac_prefix_conf_UPP])dnl
97 AS_VAR_PUSHDEF([_INP],[ac_prefix_conf_INP])dnl
98 m4_pushdef([_script],[conftest.prefix])dnl
99 m4_pushdef([_symbol],[m4_cr_Letters[]m4_cr_digits[]_])dnl
100 _OUT=`echo ifelse($1, , $PACKAGE-config.h, $1)`
101 _DEF=`echo _$_OUT | sed -e "y:m4_cr_letters:m4_cr_LETTERS[]:" -e "s/@<:@^m4_cr_Letters@:>@/_/g"`
102 _PKG=`echo ifelse($2, , $PACKAGE, $2)`
103 _LOW=`echo _$_PKG | sed -e "y:m4_cr_LETTERS-:m4_cr_letters[]_:"`
104 _UPP=`echo $_PKG | sed -e "y:m4_cr_letters-:m4_cr_LETTERS[]_:"  -e "/^@<:@m4_cr_digits@:>@/s/^/_/"`
105 _INP=`echo "ifelse($3,,,$3)" | sed -e 's/ *//'`
106 if test ".$_INP" = "."; then
107    for ac_file in : $CONFIG_HEADERS; do test "_$ac_file" = _: && continue
108      case "$ac_file" in
109         *.h) _INP=$ac_file ;;
110         *)
111      esac
112      test ".$_INP" != "." && break
113    done
115 if test ".$_INP" = "."; then
116    case "$_OUT" in
117       */*) _INP=`basename "$_OUT"`
118       ;;
119       *-*) _INP=`echo "$_OUT" | sed -e "s/@<:@_symbol@:>@*-//"`
120       ;;
121       *) _INP=config.h
122       ;;
123    esac
125 if test -z "$_PKG" ; then
126    AC_MSG_ERROR([no prefix for _PREFIX_PKG_CONFIG_H])
127 else
128   if test ! -f "$_INP" ; then if test -f "$srcdir/$_INP" ; then
129      _INP="$srcdir/$_INP"
130   fi fi
131   AC_MSG_NOTICE(creating $_OUT - prefix $_UPP for $_INP defines)
132   if test -f $_INP ; then
133     echo "s/^@%:@undef  *\\(@<:@m4_cr_LETTERS[]_@:>@\\)/@%:@undef $_UPP""_\\1/" > _script
134     echo "s/^@%:@undef  *\\(@<:@m4_cr_letters@:>@\\)/@%:@undef $_LOW""_\\1/" >> _script
135     echo "s/^@%:@def[]ine  *\\(@<:@m4_cr_LETTERS[]_@:>@@<:@_symbol@:>@*\\)\\(.*\\)/@%:@ifndef $_UPP""_\\1 \\" >> _script
136     echo "@%:@def[]ine $_UPP""_\\1 \\2 \\" >> _script
137     echo "@%:@endif/" >>_script
138     echo "s/^@%:@def[]ine  *\\(@<:@m4_cr_letters@:>@@<:@_symbol@:>@*\\)\\(.*\\)/@%:@ifndef $_LOW""_\\1 \\" >> _script
139     echo "@%:@define $_LOW""_\\1 \\2 \\" >> _script
140     echo "@%:@endif/" >> _script
141     # now executing _script on _DEF input to create _OUT output file
142     echo "@%:@ifndef $_DEF"      >$tmp/pconfig.h
143     echo "@%:@def[]ine $_DEF 1" >>$tmp/pconfig.h
144     echo ' ' >>$tmp/pconfig.h
145     echo /'*' $_OUT. Generated automatically at end of configure. '*'/ >>$tmp/pconfig.h
147     sed -f _script $_INP >>$tmp/pconfig.h
148     echo ' ' >>$tmp/pconfig.h
149     echo '/* once:' $_DEF '*/' >>$tmp/pconfig.h
150     echo "@%:@endif" >>$tmp/pconfig.h
151     if cmp -s $_OUT $tmp/pconfig.h 2>/dev/null; then
152       AC_MSG_NOTICE([$_OUT is unchanged])
153     else
154       ac_dir=`AS_DIRNAME(["$_OUT"])`
155       AS_MKDIR_P(["$ac_dir"])
156       rm -f "$_OUT"
157       mv $tmp/pconfig.h "$_OUT"
158     fi
159     cp _script _configs.sed
160   else
161     AC_MSG_ERROR([input file $_INP does not exist - skip generating $_OUT])
162   fi
163   rm -f conftest.*
165 m4_popdef([_symbol])dnl
166 m4_popdef([_script])dnl
167 AS_VAR_POPDEF([_INP])dnl
168 AS_VAR_POPDEF([_UPP])dnl
169 AS_VAR_POPDEF([_LOW])dnl
170 AS_VAR_POPDEF([_PKG])dnl
171 AS_VAR_POPDEF([_DEF])dnl
172 AS_VAR_POPDEF([_OUT])dnl
173 ],[PACKAGE="$PACKAGE"])])
175 dnl implementation note: a bug report (31.5.2005) from Marten Svantesson points 
176 dnl out a problem where `echo "\1"` results in a Control-A. The unix standard
177 dnl    http://www.opengroup.org/onlinepubs/000095399/utilities/echo.html
178 dnl defines all backslash-sequences to be inherently non-portable asking
179 dnl for replacement mit printf. Some old systems had problems with that
180 dnl one either. However, the latest libtool (!) release does export an $ECHO 
181 dnl (and $echo) that does the right thing - just one question is left: what 
182 dnl was the first version to have it? Is it greater 2.58 ?