Debian Codegraph @

libs/zziplib/m4/ax_prefix_config_h.m4

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