summaryrefslogtreecommitdiffstats
path: root/tests/semantics.at
blob: 0ca46b4ea7f072b16e0b91c2c2f462cb300fb283 (plain)
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
#							-*- autoconf -*-

AT_BANNER([Semantics.])




## -------------------------------- ##
## Members of the AC_CHECK family.  ##
## -------------------------------- ##


# AC_CHECK_LIB
# ------------
# Well, I can't imagine a system where `cos' is neither in libc, nor
# in libm.  Nor can I imagine a lib more likely to exists than libm.
# But there are systems without libm, on which we don't want to have
# this test fail, so exit successfully if `cos' is in libc.
AT_CHECK_MACRO([AC_CHECK_LIB],
[AC_TRY_LINK_FUNC(cos,
                  [AC_MSG_ERROR([`cos' is in `libc'], 77)])

AC_CHECK_LIB(m, cos,,
             [AC_MSG_ERROR([cannot find `cos' in `libm'])])

# No kidding, using variables was broken in 2.50 :(
ac_sin=sin
AC_CHECK_LIB(m, $ac_sin,,
      [AC_MSG_ERROR([cannot find `\$ac_sin' (= `$ac_sin') in `libm'])])

ac_m=m
AC_CHECK_LIB($ac_m, acos,,
      [AC_MSG_ERROR([cannot find `acos' in `\$ac_m' (= `$ac_m')])])

ac_asin=asin
AC_CHECK_LIB($ac_m, $ac_asin,,
      [AC_MSG_ERROR([cannot find `\$ac_asin' (= `$ac_asin') in `\$ac_m' (= `$at_m')])])

# But if the bug is in the caching mechanism, then be sure we
# correctly detect failures.

AC_CHECK_LIB(m, cossack,
             [AC_MSG_ERROR([found `cossack' in `libm'])])

# No kidding, using variables was broken in 2.50 :(
ac_sinner=sinner
AC_CHECK_LIB(m, $ac_sinner,
      [AC_MSG_ERROR([found `\$ac_sinner' (= `$ac_sinner') in `libm'])])

ac_m=m
AC_CHECK_LIB($ac_m, acossack,
      [AC_MSG_ERROR([found `acossack' in `\$ac_m' (= `$ac_m')])])

ac_asinner=asinner
AC_CHECK_LIB($ac_m, $ac_asinner,
      [AC_MSG_ERROR([found `\$ac_asinner' (= `$ac_asinner') in `\$ac_m' (= `$at_m')])])

])


# AC_CHECK_DECLS
# --------------
# Check that it performs the correct actions:
# Must define NEED_NO_DECL, but not NEED_YES_DECL.
AT_CHECK_MACRO([AC_CHECK_DECLS],
[[AC_CHECK_DECLS([yes, no],,,
                 [int yes = 1;])]],
[AT_CHECK_DEFINES(
[#define HAVE_DECL_NO 0
#define HAVE_DECL_YES 1
])])


# AC_CHECK_FUNCS
# --------------
# Check that it performs the correct actions:
# Must define HAVE_PRINTF, but not HAVE_AUTOCONF_FTNIRP
AT_CHECK_MACRO([AC_CHECK_FUNCS],
[AC_CHECK_FUNCS(printf autoconf_ftnirp)],
[AT_CHECK_DEFINES(
[/* #undef HAVE_AUTOCONF_FTNIRP */
#define HAVE_PRINTF 1
])])


# AC_REPLACE_FUNCS
# ----------------
# Check that it performs the correct actions: autoconf_ftnirp.c must
# be compiled, and must define HAVE_PRINTF, but not HAVE_AUTOCONF_FTNIRP
# FIXME: Maybe check the traces?
AT_SETUP([AC_REPLACE_FUNCS])

AT_DATA([config.in],
[@LIBOBJS@
])

AT_CONFIGURE_AC(
[AC_CONFIG_FILES(config.libobjs:config.in)
AC_REPLACE_FUNCS(printf autoconf_ftnirp)])

AT_CHECK_AUTOCONF([-W obsolete])
AT_CHECK_AUTOHEADER
AT_CHECK_CONFIGURE
AT_CHECK_ENV
AT_CHECK_DEFINES(
[/* #undef HAVE_AUTOCONF_FTNIRP */
#define HAVE_PRINTF 1
])

AT_CHECK([sed 's/  */ /g;s/^ //;s/ $//' config.libobjs], [],
         [autoconf_ftnirp.o
])

AT_CLEANUP([config.libobjs])


# AC_CHECK_HEADERS
# ----------------
# Check that it performs the correct actions:
# Must define HAVE_STDIO_H, but not HAVE_AUTOCONF_IO_H.
AT_CHECK_MACRO([AC_CHECK_HEADERS],
[AC_CHECK_HEADERS(stdio.h autoconf_io.h)],
[AT_CHECK_DEFINES(
[/* #undef HAVE_AUTOCONF_IO_H */
#define HAVE_STDIO_H 1
])])


# AC_CHECK_MEMBERS
# ----------------
# Check that it performs the correct actions.
# Must define HAVE_STRUCT_YES_S_YES, but not HAVE_STRUCT_YES_S_NO.
AT_CHECK_MACRO([AC_CHECK_MEMBERS],
[[AC_CHECK_MEMBERS([struct yes_s.yes, struct yes_s.no],,,
                   [struct yes_s { int yes ;} ;])]],
[AT_CHECK_DEFINES(
[/* #undef HAVE_STRUCT_YES_S_NO */
#define HAVE_STRUCT_YES_S_YES 1
])])


# AC_CHECK_SIZEOF
# ---------------
AT_CHECK_MACRO([AC_CHECK_SIZEOF],
[[AC_CHECK_SIZEOF(char)
AC_CHECK_SIZEOF(charchar,,
[[#include <stdio.h>
typedef char charchar[2];]])
AC_CHECK_SIZEOF(charcharchar)

# Exercise the code used when cross-compiling
cross_compiling=yes
AC_CHECK_SIZEOF(unsigned char)
AC_CHECK_SIZEOF(ucharchar,,
[[#include <stdio.h>
typedef unsigned char ucharchar[2];]])
AC_CHECK_SIZEOF(ucharcharchar)]],
[AT_CHECK_DEFINES(
[#define SIZEOF_CHAR 1
#define SIZEOF_CHARCHAR 2
#define SIZEOF_CHARCHARCHAR 0
#define SIZEOF_UCHARCHAR 2
#define SIZEOF_UCHARCHARCHAR 0
#define SIZEOF_UNSIGNED_CHAR 1
])])


# AC_CHECK_TYPES
# --------------
# Check that it performs the correct actions.
# Must define HAVE_STRUCT_YES_S, HAVE_INT, but not HAVE_STRUCT_NO_S.
# `int' and `struct yes_s' are both checked to test both the compiler
# builtin types, and defined types.
AT_CHECK_MACRO([AC_CHECK_TYPES],
[[AC_CHECK_TYPES([int, struct yes_s, struct no_s],,,
                 [struct yes_s { int yes ;} ;])]],
[AT_CHECK_DEFINES(
[#define HAVE_INT 1
/* #undef HAVE_STRUCT_NO_S */
#define HAVE_STRUCT_YES_S 1
])])


# AC_CHECK_TYPES
# --------------
# Check that we properly dispatch properly to the old implementation
# or to the new one.
AT_SETUP([AC_CHECK_TYPES: backward compatibility])

AT_DATA(configure.ac,
[[AC_INIT
define([_AC_CHECK_TYPE_NEW], [NEW])
define([_AC_CHECK_TYPE_OLD], [OLD])
#(cut-from-here
AC_CHECK_TYPE(ptrdiff_t)
AC_CHECK_TYPE(ptrdiff_t, int)
AC_CHECK_TYPE(quad, long long)
AC_CHECK_TYPE(table_42, [int[42]])
# Nice machine!
AC_CHECK_TYPE(uint8_t, uint65536_t)
AC_CHECK_TYPE(a,b,c,d)
#to-here)
AC_OUTPUT
]])

AT_CHECK_AUTOCONF
AT_CHECK([[sed -e '/^#(cut-from-here/,/^#to-here)/!d' -e '/^#/d' configure]],
         0,
         [NEW
OLD
OLD
OLD
OLD
NEW
])

AT_CLEANUP


# AC_CHECK_FILES
# --------------
# FIXME: To really test HAVE_AC_EXISTS2 and HAVE_AC_MISSING2 we need to
# open AH_TEMPLATE to `configure.ac', which is not yet the case.
AT_CHECK_MACRO([AC_CHECK_FILES],
[touch at-exists1 at-exists2
ac_exists2=at-exists2
ac_missing2=at-missing2
AC_CHECK_FILES(at-exists1 at-missing1 $ac_exists2 $ac_missing2)
rm at-exists1 at-exists2],
[AT_CHECK_DEFINES(
[#define HAVE_AT_EXISTS1 1
/* #undef HAVE_AT_MISSING1 */
])])



## ------------------------------ ##
## AC_CHECK_PROG & AC_PATH_PROG.  ##
## ------------------------------ ##


# AT_CHECK_PROGS_PREPARE
# ----------------------
# Create a sub directory `path' with 6 subdirs which all 7 contain
# an executable `tool'. `6' contains a `better' tool.
m4_define([AT_CHECK_PROGS_PREPARE],
[mkdir path

cat >path/tool <<\EOF
#! /bin/sh
exit 0
EOF
chmod +x path/tool

for i in 1 2 3 4 5 6
do
  mkdir path/$i
  cp path/tool path/$i
done
cp path/tool path/6/better])


# -------------------------------- #
# AC_CHECK_PROG & AC_CHECK_PROGS.  #
# -------------------------------- #

AT_SETUP([AC_CHECK_PROG & AC_CHECK_PROGS])

AT_CHECK_PROGS_PREPARE

AT_DATA(configure.ac,
[[AC_INIT
pwd=`pwd`
p="1${ac_path_separator}2${ac_path_separator}3${ac_path_separator}4${ac_path_separator}5${ac_path_separator}6"
path=`echo $p | sed -e 's,\([[0-9]]\),'"$pwd"'/path/\1,g'`
fail=false

AC_CHECK_PROG(TOOL1, tool, found, not-found, $path)
test "$TOOL1" = found || fail=:

# Yes, the semantics of this macro is weird.
AC_CHECK_PROG(TOOL2, tool,, not-found, $path)
test "$TOOL2" = not-found || fail=:

AC_CHECK_PROG(TOOL3, tool, tool, not-found, $path, $pwd/path/1/tool)
test "$TOOL3" = $pwd/path/2/tool || fail=:

AC_CHECK_PROG(TOOL4, better, better, not-found, $path, $pwd/path/1/tool)
test "$TOOL4" = better || fail=:

# When a tool is not found, and no value is given for not-found,
# the variable is left empty.
AC_CHECK_PROGS(TOOL5, missing,, $path)
test -z "$TOOL5" || fail=:

AC_CHECK_PROGS(TOOL6, missing tool better,, $path)
test "$TOOL6" = tool || fail=:

# No AC-OUTPUT, we don't need config.status.
$fail &&
  AC_MSG_ERROR([[CHECK_PROG failed]])
AS_EXIT(0)
]])

AT_CHECK_AUTOCONF
AT_CHECK_CONFIGURE

AT_CLEANUP(path)


# ------------------------------ #
# AC_PATH_PROG & AC_PATH_PROGS.  #
# ------------------------------ #

AT_SETUP(AC_PATH_PROG & AC_PATH_PROGS)

AT_CHECK_PROGS_PREPARE

AT_DATA(configure.ac,
[[AC_INIT
pwd=`pwd`
p="1${ac_path_separator}2${ac_path_separator}3${ac_path_separator}4${ac_path_separator}5${ac_path_separator}6"
path=`echo $p | sed -e 's,\([[0-9]]\),'"$pwd"'/path/\1,g'`
fail=false

AC_PATH_PROG(TOOL1, tool, not-found, $path)
test "$TOOL1" = $pwd/path/1/tool || fail=:

AC_PATH_PROG(TOOL2, better, not-found, $path)
test "$TOOL2" = $pwd/path/6/better || fail=:

# When a tool is not found, and no value is given for not-found,
# the variable is left empty.
AC_PATH_PROGS(TOOL3, missing,, $path)
test -z "$TOOL3" || fail=:

AC_PATH_PROGS(TOOL4, missing tool better,, $path)
test "$TOOL4" = $pwd/path/1/tool || fail=:

# No AC-OUTPUT, we don't need config.status.
$fail &&
  AC_MSG_ERROR([[PATH_PROG failed]])
AS_EXIT(0)
]])

AT_CHECK_AUTOCONF
AT_CHECK_CONFIGURE

AT_CLEANUP(path)




## -------------- ##
## AC_PATH_XTRA.  ##
## -------------- ##


AT_SETUP([AC_PATH_XTRA])

_AT_CHECK_AC_MACRO([AC_PATH_XTRA])

# Check X_DISPLAY_MISSING.
AT_CHECK_CONFIGURE([--without-x])
AT_CHECK_DEFINES(
[#define X_DISPLAY_MISSING 1
])

AT_CLEANUP


## ------------------------------- ##
## Obsolete non-updatable macros.  ##
## ------------------------------- ##


AT_CHECK_MACRO([AC_SYS_RESTARTABLE_SYSCALLS], , ,[-W no-obsolete])
AT_CHECK_MACRO([AC_FUNC_WAIT3], , ,[-W no-obsolete])