summaryrefslogtreecommitdiffstats
path: root/tests/compile.at
blob: 7ea207f0dbc180ae8351360bfecb5ec70c5437d5 (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
#							-*- autoconf -*-

AT_BANNER([Low level compiling/preprocessing macros.])

# Since the macros which compile are required by most tests, check
# them first.  But remember that looking for a compiler is even more
# primitive, so check those first.


## ------------------------------------- ##
## AC_LANG, AC_LANG_PUSH & AC_LANG_POP.  ##
## ------------------------------------- ##

AT_SETUP([AC_LANG, AC_LANG_PUSH & AC_LANG_POP])

AT_DATA([configure.ac],
[[AC_INIT
# C
AC_LANG(C)
# C
AC_LANG_PUSH(C)
# C C
AC_LANG_PUSH(C++)
# C++ C C
AC_LANG(C++)
# C++ C C
AC_LANG_PUSH(Fortran 77)
# F77 C++ C C
AC_LANG_POP(Fortran 77)
# C++ C C
AC_LANG(C++)
# C++ C C
AC_LANG_POP(C++)
# C C
AC_LANG_POP(C)
# C
]])

AT_CHECK_AUTOCONF
AT_CHECK([sed -n 's/^ac_ext=//p' configure], 0,
[c
c
c
cc
cc
f
cc
cc
c
c
])

AT_CLEANUP


## ------------ ##
## Extensions.  ##
## ------------ ##

# As far as we know only `foo', `foo.exe' are possible executable,
# and `foo.o', `foo.obj' are possible object files.  Autoconf must not
# know that, but it is OK for the test suite to take this into account.
AT_CHECK_MACRO([Extensions],
[[AC_PROG_CC
case $ac_exeext in
  '' | '.exe' ) ;;
  * ) AC_MSG_ERROR([suspicious executable suffix: $ac_exeext]);;
esac

case $ac_objext in
  'o' | 'obj' ) ;;
  * ) AC_MSG_ERROR([suspicious object suffix: $ac_objext]);;
esac
AS_EXIT([0])
]])



## -------------------------- ##
## Broken/missing compilers.  ##
## -------------------------- ##


# Check that Autoconf correctly diagnoses broken compilers, and in
# particular, if it does not exit 77, the test suite is in trouble...
# FIXME: Once a precise message decided, check stderr of configure.
AT_SETUP([Broken/missing compilers])

AT_DATA([configure.ac],
[[AC_INIT
CC=no-such-compiler
AC_PROG_CC
]])

AT_CHECK_AUTOCONF
AT_CHECK_CONFIGURE([], 77, ignore, ignore)

AT_CLEANUP


## ------------ ##
## C keywords.  ##
## ------------ ##

# GCC supports `const', `volatile', and `inline'.
AT_CHECK_MACRO([C keywords],
[[AC_PROG_CC
AC_C_CONST
AC_C_INLINE
AC_C_VOLATILE
case $GCC,$ac_cv_c_const,$ac_cv_c_inline,$ac_cv_c_volatile in
 yes,*no*)
   AC_MSG_ERROR([failed to detect `const', `inline' or `volatile' support]);;
esac
]])



## --------------------------------- ##
## AC_PROG_CPP requires AC_PROG_CC.  ##
## --------------------------------- ##

# Must invoke AC_PROG_CC.
AT_CHECK_MACRO([AC_PROG_CPP requires AC_PROG_CC],
[[AC_PROG_CPP
test -z "$CC" &&
   AC_MSG_ERROR([looked for a C preprocessor without looking for a compiler])
]])



## --------------------------- ##
## AC_PROG_CPP with warnings.  ##
## --------------------------- ##


# It's Ok for strict preprocessors to produce warnings.

AT_SETUP([AC_PROG_CPP with warnings])

AT_DATA([mycpp],
[[#! /bin/sh
echo noise >&2
exec ${1+"$@"}
]])

chmod +x mycpp

_AT_CHECK_AC_MACRO(
[[AC_PROG_CPP
# If the preprocessor is not strict, just ignore
test "x$ac_c_preproc_warn_flag" = xyes &&
  AC_MSG_ERROR([preprocessor has no warning option], 77)
CPP="./mycpp $CPP"
AC_CHECK_HEADERS(stdio.h autoconf_io.h)]])

AT_CHECK_DEFINES(
[/* #undef HAVE_AUTOCONF_IO_H */
#define HAVE_STDIO_H 1
])

AT_CLEANUP


## ------------------------------ ##
## AC_PROG_CPP without warnings.  ##
## ------------------------------ ##

AT_SETUP([AC_PROG_CPP without warnings])

# Ignore if /lib/cpp doesn't work
AT_CHECK([/lib/cpp </dev/null || exit 77], [], [ignore], [ignore])

# A cpp which exit status is meaningless.
AT_DATA([mycpp],
[[#! /bin/sh
/lib/cpp ${1+"$@"}
exit 0
]])

chmod +x mycpp

_AT_CHECK_AC_MACRO(
[[CPP=./mycpp
AC_PROG_CPP
test "x$ac_c_preproc_warn_flag" != xyes &&
  AC_MSG_ERROR([failed to detect preprocessor warning option])
AC_CHECK_HEADERS(stdio.h autoconf_io.h)]])

AT_CHECK_DEFINES(
[/* #undef HAVE_AUTOCONF_IO_H */
#define HAVE_STDIO_H 1
])

AT_CLEANUP



## -------------------- ##
## AC_PROG_CPP via CC.  ##
## -------------------- ##


# It's Ok for strict preprocessors to produce warnings.

AT_SETUP([AC_PROG_CPP via CC])

# Ignore if /lib/cpp doesn't work
AT_CHECK([/lib/cpp </dev/null || exit 77], [], [ignore], [ignore])

AT_DATA([mycc],
[[#! /bin/sh
echo "Annoying copyright message" >&2
exec "$@"
]])

chmod +x mycc

# We go through the following contortions, in order to have the
# configure script go down the same codepaths as it would during a
# normal CPP selection check.  If we explicitly set CPP, it goes down
# a different codepath.
_AT_CHECK_AC_MACRO(
[[AC_PROG_CC
CC="./mycc $CC"
AC_PROG_CPP
# The test $CC compiler should have been selected.
test "$CPP" != "$CC -E" &&
  AC_MSG_ERROR([error messages on stderr cause the preprocessor selection to fail])

# Exercise CPP.
AC_CHECK_HEADERS(stdio.h autoconf_io.h)]])

AT_CHECK_DEFINES(
[/* #undef HAVE_AUTOCONF_IO_H */
#define HAVE_STDIO_H 1
])

AT_CLEANUP


## ------------------ ##
## AC_TRY_LINK_FUNC.  ##
## ------------------ ##

AT_CHECK_MACRO([AC_TRY_LINK_FUNC],
[AC_TRY_LINK_FUNC(printf,,
                  [AC_MSG_ERROR([cannot find `printf'])])
AC_TRY_LINK_FUNC(Be_doomed_if_your_libc_has_a_function_named_like_this,
                 [AC_MSG_ERROR([found a nonexistent function])])])



## --------------------- ##
## Fortran 77 Compiler.  ##
## --------------------- ##


AT_CHECK_MACRO([GNU Fortran 77],
[[AC_LANG(Fortran 77)
AC_LANG_COMPILER

if AC_TRY_COMMAND([$F77 --version | grep GNU >&2]); then
  # Be sure to remove files which might be created by compilers that
  # don't support --version.
  rm -f a.exe a.out
  # Has GNU in --version.
  test "$G77" != yes &&
    AC_MSG_ERROR([failed to recognize GNU Fortran 77 compiler])
else
  # Be sure to remove files which might be created by compilers that
  # don't support --version.
  rm -f a.exe a.out
  # Has not.
  test "$G77" = yes &&
    AC_MSG_ERROR([incorrectly recognized a GNU Fortran 77 compiler])
fi]])