File: ax_prefix_config_h.html

package info (click to toggle)
autoconf-archive 20060312-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,180 kB
  • ctags: 13
  • sloc: sh: 455; makefile: 44
file content (234 lines) | stat: -rw-r--r-- 8,194 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
 <head>
  <title>
   Autoconf Macro: ax_prefix_config_h
  </title>
  <link rel="stylesheet" type="text/css" href="ac-archive.css">
 </head>
 <body>
  <table summary="web navigation" style="width:100%;">
   <tbody>
    <tr>
     <td style="width:50%;" align="center">
      <a href="http://autoconf-archive.cryp.to/ax_prefix_config_h.m4">Download
      M4 Source</a>
     </td>
     <td style="width:50%;" align="center">
      <a href="macros-by-category.html">Macro Index Page</a>
     </td>
    </tr>
   </tbody>
  </table>
  <hr>
  <h1>
   ax_prefix_config_h
  </h1>
  <h2>
   Synopsis
  </h2>
  <p class="indent" style="white-space:nowrap;">
   <code>AX_PREFIX_CONFIG_H [(OUTPUT-HEADER [,PREFIX [,ORIG-HEADER]])]</code>
  </p>
  <h2>
   Description
  </h2>
  <div class="indent">
   <p>
    This is a new variant from ac_prefix_config_ this one will use a
    lowercase-prefix if the config-define was starting with a lowercase-char,
    e.g. "#define const", "#define restrict", or "#define off_t", (and this one
    can live in another directory, e.g. testpkg/config.h therefore I decided to
    move the output-header to be the first arg)
   </p>
   <p>
    takes the usual config.h generated header file; looks for each of the
    generated "#define SOMEDEF" lines, and prefixes the defined name (ie. makes
    it "#define PREFIX_SOMEDEF". The result is written to the output
    config.header file. The PREFIX is converted to uppercase for the
    conversions.
   </p>
   <p>
    Defaults:
   </p>
   <pre>
  OUTPUT-HEADER = $PACKAGE-config.h
  PREFIX = $PACKAGE
  ORIG-HEADER, from AM_CONFIG_HEADER(config.h)
</pre>
   <p>
    Your configure.ac script should contain both macros in this order, and
    unlike the earlier variations of this prefix-macro it is okay to place the
    AX_PREFIX_CONFIG_H call before the AC_OUTPUT invokation.
   </p>
   <p>
    Example:
   </p>
   <pre>
  AC_INIT(config.h.in)        # config.h.in as created by "autoheader"
  AM_INIT_AUTOMAKE(testpkg, 0.1.1)    # makes #undef VERSION and PACKAGE
  AM_CONFIG_HEADER(config.h)          # prep config.h from config.h.in
  AX_PREFIX_CONFIG_H(mylib/_config.h) # prep mylib/_config.h from it..
  AC_MEMORY_H                         # makes "#undef NEED_MEMORY_H"
  AC_C_CONST_H                        # makes "#undef const"
  AC_OUTPUT(Makefile)                 # creates the "config.h" now
                                      # and also mylib/_config.h
</pre>
   <p>
    if the argument to AX_PREFIX_CONFIG_H would have been omitted then the
    default outputfile would have been called simply "testpkg-config.h", but
    even under the name "mylib/_config.h" it contains prefix-defines like
   </p>
   <pre>
  #ifndef TESTPKG_VERSION
  #define TESTPKG_VERSION "0.1.1"
  #endif
  #ifndef TESTPKG_NEED_MEMORY_H
  #define TESTPKG_NEED_MEMORY_H 1
  #endif
  #ifndef _testpkg_const
  #define _testpkg_const _const
  #endif
</pre>
   <p>
    and this "mylib/_config.h" can be installed along with other header-files,
    which is most convenient when creating a shared library (that has some
    headers) where some functionality is dependent on the OS-features detected
    at compile-time. No need to invent some "mylib-confdefs.h.in" manually. :-)
   </p>
   <p>
    Note that some AC_DEFINEs that end up in the config.h file are actually
    self-referential - e.g. AC_C_INLINE, AC_C_CONST, and the AC_TYPE_OFF_T say
    that they "will define inline|const|off_t if the system does not do it by
    itself". You might want to clean up about these - consider an extra
    mylib/conf.h that reads something like:
   </p>
   <pre>
   #include &lt;mylib/_config.h&gt;
   #ifndef _testpkg_const
   #define _testpkg_const const
   #endif
</pre>
   <p>
    and then start using _testpkg_const in the header files. That is also a
    good thing to differentiate whether some library-user has starting to take
    up with a different compiler, so perhaps it could read something like this:
   </p>
   <pre>
  #ifdef _MSC_VER
  #include &lt;mylib/_msvc.h&gt;
  #else
  #include &lt;mylib/_config.h&gt;
  #endif
  #ifndef _testpkg_const
  #define _testpkg_const const
  #endif
</pre>
  </div>
  <h2>
   Author
  </h2>
  <p class="indent">
   Guido Draheim &lt;guidod@gmx.de&gt;, M&aring;rten Svantesson
   &lt;msv@kth.se&gt;
  </p>
  <h2>
   Last Modified
  </h2>
  <p class="indent">
   2005-06-08
  </p>
  <h2>
   M4 Source Code
  </h2>
  <div class="indent">
   <pre class="m4source">
AC_DEFUN([AX_PREFIX_CONFIG_H],[AC_REQUIRE([AC_CONFIG_HEADER])
AC_CONFIG_COMMANDS([ifelse($1,,$PACKAGE-config.h,$1)],[dnl
AS_VAR_PUSHDEF([_OUT],[ac_prefix_conf_OUT])dnl
AS_VAR_PUSHDEF([_DEF],[ac_prefix_conf_DEF])dnl
AS_VAR_PUSHDEF([_PKG],[ac_prefix_conf_PKG])dnl
AS_VAR_PUSHDEF([_LOW],[ac_prefix_conf_LOW])dnl
AS_VAR_PUSHDEF([_UPP],[ac_prefix_conf_UPP])dnl
AS_VAR_PUSHDEF([_INP],[ac_prefix_conf_INP])dnl
m4_pushdef([_script],[conftest.prefix])dnl
m4_pushdef([_symbol],[m4_cr_Letters[]m4_cr_digits[]_])dnl
_OUT=`printf '%s\n' ifelse($1, , $PACKAGE-config.h, $1)`
_DEF=`printf '%s\n' _$_OUT | sed -e "y:m4_cr_letters:m4_cr_LETTERS[]:" -e "s/@&lt;:@^m4_cr_Letters@:&gt;@/_/g"`
_PKG=`printf '%s\n' ifelse($2, , $PACKAGE, $2)`
_LOW=`printf '%s\n' _$_PKG | sed -e "y:m4_cr_LETTERS-:m4_cr_letters[]_:"`
_UPP=`printf '%s\n' $_PKG | sed -e "y:m4_cr_letters-:m4_cr_LETTERS[]_:"  -e "/^@&lt;:@m4_cr_digits@:&gt;@/s/^/_/"`
_INP=`printf '%s\n' "ifelse($3,,,$3)" | sed -e 's/ *//'`
if test ".$_INP" = "."; then
   for ac_file in : $CONFIG_HEADERS; do test "_$ac_file" = _: &amp;&amp; continue
     case "$ac_file" in
        *.h) _INP=$ac_file ;;
        *)
     esac
     test ".$_INP" != "." &amp;&amp; break
   done
fi
if test ".$_INP" = "."; then
   case "$_OUT" in
      */*) _INP=`basename "$_OUT"`
      ;;
      *-*) _INP=`printf '%s\n' "$_OUT" | sed -e "s/@&lt;:@_symbol@:&gt;@*-//"`
      ;;
      *) _INP=config.h
      ;;
   esac
fi
if test -z "$_PKG" ; then
   AC_MSG_ERROR([no prefix for _PREFIX_PKG_CONFIG_H])
else
  if test ! -f "$_INP" ; then if test -f "$srcdir/$_INP" ; then
     _INP="$srcdir/$_INP"
  fi fi
  AC_MSG_NOTICE(creating $_OUT - prefix $_UPP for $_INP defines)
  if test -f $_INP ; then
    printf '%s\n' "s/@%:@undef  *\\(@&lt;:@m4_cr_LETTERS[]_@:&gt;@\\)/@%:@undef $_UPP""_\\1/" &gt; _script
    printf '%s\n' "s/@%:@undef  *\\(@&lt;:@m4_cr_letters@:&gt;@\\)/@%:@undef $_LOW""_\\1/" &gt;&gt; _script
    printf '%s\n' "s/@%:@def[]ine  *\\(@&lt;:@m4_cr_LETTERS[]_@:&gt;@@&lt;:@_symbol@:&gt;@*\\)\\(.*\\)/@%:@ifndef $_UPP""_\\1 \\" &gt;&gt; _script
    printf '%s\n' "@%:@def[]ine $_UPP""_\\1 \\2 \\" &gt;&gt; _script
    printf '%s\n' "@%:@endif/" &gt;&gt;_script
    printf '%s\n' "s/@%:@def[]ine  *\\(@&lt;:@m4_cr_letters@:&gt;@@&lt;:@_symbol@:&gt;@*\\)\\(.*\\)/@%:@ifndef $_LOW""_\\1 \\" &gt;&gt; _script
    printf '%s\n' "@%:@define $_LOW""_\\1 \\2 \\" &gt;&gt; _script
    printf '%s\n' "@%:@endif/" &gt;&gt; _script
    # now executing _script on _DEF input to create _OUT output file
    printf '%s\n' "@%:@ifndef $_DEF"      &gt;$tmp/pconfig.h
    printf '%s\n' "@%:@def[]ine $_DEF 1" &gt;&gt;$tmp/pconfig.h
    printf '%s\n' ' ' &gt;&gt;$tmp/pconfig.h
    printf '%s\n' /'*' $_OUT. Generated automatically at end of configure. '*'/ &gt;&gt;$tmp/pconfig.h

    sed -f _script $_INP &gt;&gt;$tmp/pconfig.h
    printf '%s\n' ' ' &gt;&gt;$tmp/pconfig.h
    printf '%s\n' '/* once:' $_DEF '*/' &gt;&gt;$tmp/pconfig.h
    printf '%s\n' "@%:@endif" &gt;&gt;$tmp/pconfig.h
    if cmp -s $_OUT $tmp/pconfig.h 2&gt;/dev/null; then
      AC_MSG_NOTICE([$_OUT is unchanged])
    else
      ac_dir=`AS_DIRNAME(["$_OUT"])`
      AS_MKDIR_P(["$ac_dir"])
      rm -f "$_OUT"
      mv $tmp/pconfig.h "$_OUT"
    fi
    cp _script _configs.sed
  else
    AC_MSG_ERROR([input file $_INP does not exist - skip generating $_OUT])
  fi
  rm -f conftest.*
fi
m4_popdef([_symbol])dnl
m4_popdef([_script])dnl
AS_VAR_POPDEF([_INP])dnl
AS_VAR_POPDEF([_UPP])dnl
AS_VAR_POPDEF([_LOW])dnl
AS_VAR_POPDEF([_PKG])dnl
AS_VAR_POPDEF([_DEF])dnl
AS_VAR_POPDEF([_OUT])dnl
],[PACKAGE="$PACKAGE"])])
</pre>
  </div>
 </body>
</html>