File: ac_prototype.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 (265 lines) | stat: -rw-r--r-- 7,500 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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
 <head>
  <title>
   Autoconf Macro: ac_prototype
  </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/ac_prototype.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>
   ac_prototype
  </h1>
  <h2>
   Synopsis
  </h2>
  <p class="indent" style="white-space:nowrap;">
   <code>AC_PROTOTYPE(function, includes, code, TAG1, values1 [, TAG2, values2
   [...]])</code>
  </p>
  <h2>
   Description
  </h2>
  <div class="indent">
   <p>
    Try all the combinations of &lt;TAG1&gt;, &lt;TAG2&gt;... to successfully
    compile &lt;code&gt;. &lt;TAG1&gt;, &lt;TAG2&gt;, ... are substituted in
    &lt;code&gt; and &lt;include&gt; with values found in &lt;values1&gt;,
    &lt;values2&gt;, ... respectively. &lt;values1&gt;, &lt;values2&gt;, ...
    contain a list of possible values for each corresponding tag and all
    combinations are tested. When AC_TRY_COMPILE(include, code) is successfull
    for a given substitution, the macro stops and defines the following macros:
    FUNCTION_TAG1, FUNCTION_TAG2, ... using AC_DEFINE() with values set to the
    current values of &lt;TAG1&gt;, &lt;TAG2&gt;, ... If no combination is
    successfull the configure script is aborted with a message.
   </p>
   <p>
    Intended purpose is to find which combination of argument types is
    acceptable for a given function &lt;function&gt;. It is recommended to list
    the most specific types first. For instance ARG1, [size_t, int] instead of
    ARG1, [int, size_t].
   </p>
   <p>
    Generic usage pattern:
   </p>
   <p>
    1) add a call in configure.in
   </p>
   <pre>
 AC_PROTOTYPE(...)
</pre>
   <p>
    2) call autoheader to see which symbols are not covered
   </p>
   <p>
    3) add the lines in acconfig.h
   </p>
   <pre>
 /* Type of Nth argument of function */
 #undef FUNCTION_ARGN
</pre>
   <p>
    4) Within the code use FUNCTION_ARGN instead of an hardwired type
   </p>
   <p>
    Complete example:
   </p>
   <p>
    1) configure.in
   </p>
   <pre>
 AC_PROTOTYPE(getpeername,
 [
  #include &lt;sys/types.h&gt;
  #include &lt;sys/socket.h&gt;
 ],
 [
  int a = 0;
  ARG2 * b = 0;
  ARG3 * c = 0;
  getpeername(a, b, c);
 ],
 ARG2, [struct sockaddr, void],
 ARG3, [socklen_t, size_t, int, unsigned int, long unsigned int])
</pre>
   <p>
    2) call autoheader
   </p>
   <pre>
 autoheader: Symbol `GETPEERNAME_ARG2' is not covered by ./acconfig.h
 autoheader: Symbol `GETPEERNAME_ARG3' is not covered by ./acconfig.h
</pre>
   <p>
    3) acconfig.h
   </p>
   <pre>
 /* Type of second argument of getpeername */
 #undef GETPEERNAME_ARG2

 /* Type of third argument of getpeername */
 #undef GETPEERNAME_ARG3
</pre>
   <p>
    4) in the code
   </p>
   <pre>
     ...
     GETPEERNAME_ARG2 name;
     GETPEERNAME_ARG3 namelen;
     ...
     ret = getpeername(socket, &amp;name, &amp;namelen);
     ...
</pre>
   <p>
    Implementation notes: generating all possible permutations of the arguments
    is not easily done with the usual mixture of shell and m4, that is why this
    macro is almost 100% m4 code. It generates long but simple to read code.
   </p>
  </div>
  <h2>
   Author
  </h2>
  <p class="indent">
   Loic Dachary &lt;loic@senga.org&gt;
  </p>
  <h2>
   Last Modified
  </h2>
  <p class="indent">
   2000-08-11
  </p>
  <h2>
   M4 Source Code
  </h2>
  <div class="indent">
   <pre class="m4source">
AC_DEFUN([AC_PROTOTYPE],[
dnl
dnl Upper case function name
dnl
 pushdef([function],translit([$1], [a-z], [A-Z]))
dnl
dnl Collect tags that will be substituted
dnl
 pushdef([tags],[AC_PROTOTYPE_TAGS(builtin([shift],builtin([shift],builtin([shift],$@))))])
dnl
dnl Wrap in a 1 time loop, when a combination is found break to stop the combinatory exploration
dnl
 for i in 1
 do
   AC_PROTOTYPE_LOOP(AC_PROTOTYPE_REVERSE($1, AC_PROTOTYPE_SUBST($2,tags),AC_PROTOTYPE_SUBST($3,tags),builtin([shift],builtin([shift],builtin([shift],$@)))))
   AC_MSG_ERROR($1 unable to find a working combination)
 done
 popdef([tags])
 popdef([function])
])

dnl
dnl AC_PROTOTYPE_REVERSE(list)
dnl
dnl Reverse the order of the &lt;list&gt;
dnl
AC_DEFUN([AC_PROTOTYPE_REVERSE],[ifelse($#,0,,$#,1,[[$1]],[AC_PROTOTYPE_REVERSE(builtin([shift],$@)),[$1]])])

dnl
dnl AC_PROTOTYPE_SUBST(string, tag)
dnl
dnl Substitute all occurence of &lt;tag&gt; in &lt;string&gt; with &lt;tag&gt;_VAL.
dnl Assumes that tag_VAL is a macro containing the value associated to tag.
dnl
AC_DEFUN([AC_PROTOTYPE_SUBST],[ifelse($2,,[$1],[AC_PROTOTYPE_SUBST(patsubst([$1],[$2],[$2[]_VAL]),builtin([shift],builtin([shift],$@)))])])

dnl
dnl AC_PROTOTYPE_TAGS([tag, values, [tag, values ...]])
dnl
dnl Generate a list of &lt;tag&gt; by skipping &lt;values&gt;.
dnl
AC_DEFUN([AC_PROTOTYPE_TAGS],[ifelse($1,,[],[$1, AC_PROTOTYPE_TAGS(builtin([shift],builtin([shift],$@)))])])

dnl
dnl AC_PROTOTYPE_DEFINES(tags)
dnl
dnl Generate a AC_DEFINE(function_tag, tag_VAL) for each tag in &lt;tags&gt; list
dnl Assumes that function is a macro containing the name of the function in upper case
dnl and that tag_VAL is a macro containing the value associated to tag.
dnl
AC_DEFUN([AC_PROTOTYPE_DEFINES],[ifelse($1,,[],[AC_DEFINE(function[]_$1, $1_VAL) AC_PROTOTYPE_DEFINES(builtin([shift],$@))])])

dnl
dnl AC_PROTOTYPE_STATUS(tags)
dnl
dnl Generates a message suitable for argument to AC_MSG_* macros. For each tag
dnl in the &lt;tags&gt; list the message tag =&gt; tag_VAL is generated.
dnl Assumes that tag_VAL is a macro containing the value associated to tag.
dnl
AC_DEFUN([AC_PROTOTYPE_STATUS],[ifelse($1,,[],[$1 =&gt; $1_VAL AC_PROTOTYPE_STATUS(builtin([shift],$@))])])

dnl
dnl AC_PROTOTYPE_EACH(tag, values)
dnl
dnl Call AC_PROTOTYPE_LOOP for each values and define the macro tag_VAL to
dnl the current value.
dnl
AC_DEFUN([AC_PROTOTYPE_EACH],[
  ifelse($2,, [
  ], [
    pushdef([$1_VAL], $2)
    AC_PROTOTYPE_LOOP(rest)
    popdef([$1_VAL])
    AC_PROTOTYPE_EACH($1, builtin([shift], builtin([shift], $@)))
  ])
])

dnl
dnl AC_PROTOTYPE_LOOP([tag, values, [tag, values ...]], code, include, function)
dnl
dnl If there is a tag/values pair, call AC_PROTOTYPE_EACH with it.
dnl If there is no tag/values pair left, tries to compile the code and include
dnl using AC_TRY_COMPILE. If it compiles, AC_DEFINE all the tags to their
dnl current value and exit with success.
dnl
AC_DEFUN([AC_PROTOTYPE_LOOP],[
 ifelse(builtin([eval], $# &gt; 3), 1,
   [
     pushdef([rest],[builtin([shift],builtin([shift],$@))])
     AC_PROTOTYPE_EACH($2,$1)
     popdef([rest])
   ], [
     AC_MSG_CHECKING($3 AC_PROTOTYPE_STATUS(tags))
dnl
dnl Activate fatal warnings if possible, gives better guess
dnl
     ac_save_CPPFLAGS="$CPPFLAGS"
     ifelse(AC_LANG,CPLUSPLUS,if test "$GXX" = "yes" ; then CPPFLAGS="$CPPFLAGS -Werror" ; fi)
     ifelse(AC_LANG,C,if test "$GCC" = "yes" ; then CPPFLAGS="$CPPFLAGS -Werror" ; fi)
     AC_TRY_COMPILE($2, $1, [
      CPPFLAGS="$ac_save_CPPFLAGS"
      AC_MSG_RESULT(ok)
      AC_PROTOTYPE_DEFINES(tags)
      break;
     ], [
      CPPFLAGS="$ac_save_CPPFLAGS"
      AC_MSG_RESULT(not ok)
     ])
   ]
 )
])
</pre>
  </div>
 </body>
</html>