1#							-*- Autotest -*-
2
3AT_BANNER([C low level compiling/preprocessing macros.])
4
5# Copyright (C) 2000-2006, 2008-2012 Free Software Foundation, Inc.
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20
21# Since the macros which compile are required by most tests, check
22# them first.  But remember that looking for a compiler is even more
23# primitive, so check those first.
24
25
26## ------------ ##
27## Extensions.  ##
28## ------------ ##
29
30# As far as we know only `foo', `foo.exe' are possible executable,
31# and `foo.o', `foo.obj' are possible object files.  Autoconf must not
32# know that, but it is OK for the test suite to take this into account.
33AT_CHECK_MACRO([Extensions],
34[[AC_PROG_CC
35case $ac_exeext in
36  '' | '.exe' ) ;;
37  * ) AC_MSG_ERROR([suspicious executable suffix: $ac_exeext]);;
38esac
39
40case $ac_objext in
41  'o' | 'obj' ) ;;
42  * ) AC_MSG_ERROR([suspicious object suffix: $ac_objext]);;
43esac
44]])
45
46
47
48## -------------------------- ##
49## Broken/missing compilers.  ##
50## -------------------------- ##
51
52
53# Check that Autoconf correctly diagnoses broken compilers, and in
54# particular, if it does not exit 77, the test suite is in trouble...
55# FIXME: Once a precise message decided, check stderr of configure.
56AT_SETUP([Broken/missing compilers])
57
58AT_DATA([configure.ac],
59[[AC_INIT
60CC=no-such-compiler
61AC_PROG_CC
62]])
63
64AT_CHECK_AUTOCONF
65AT_CHECK_CONFIGURE([], 77, ignore, ignore)
66
67AT_CLEANUP
68
69
70## ------------ ##
71## C keywords.  ##
72## ------------ ##
73
74# GCC supports `const', `typeof', and `volatile'.
75AT_CHECK_MACRO([C keywords],
76[[AC_PROG_CC
77AC_C_CONST
78AC_C_TYPEOF
79AC_C_VOLATILE
80case $GCC,$ac_cv_c_const,$ac_cv_c_typeof,$ac_cv_c_volatile in
81 yes,*no*)
82   AC_MSG_ERROR([failed to detect `const', `typeof', or `volatile' support]);;
83esac
84]])
85
86
87
88## --------------------------------- ##
89## AC_PROG_CPP requires AC_PROG_CC.  ##
90## --------------------------------- ##
91
92# Must invoke AC_PROG_CC.
93AT_CHECK_MACRO([AC_PROG_CPP requires AC_PROG_CC],
94[[AC_PROG_CPP
95test -z "$CC" &&
96   AC_MSG_ERROR([looked for a C preprocessor without looking for a compiler])
97]])
98
99
100
101## --------------------------- ##
102## AC_PROG_CPP with warnings.  ##
103## --------------------------- ##
104
105
106# It's Ok for strict preprocessors to produce warnings.
107
108AT_SETUP([AC_PROG_CPP with warnings])
109
110AT_DATA([mycpp],
111[[#! /bin/sh
112echo noise >&2
113exec "$@"
114]])
115
116chmod +x mycpp
117
118_AT_CHECK_AC_MACRO(
119[[AC_PROG_CPP
120# If the preprocessor is not strict, just ignore
121test "x$ac_c_preproc_warn_flag" = xyes &&
122  AC_MSG_ERROR([preprocessor has no warning option], 77)
123CPP="./mycpp $CPP"
124
125# Exercise CPP.
126AC_CHECK_HEADERS(stdio.h autoconf_io.h, [], [], [-])]])
127
128AT_CHECK_DEFINES(
129[/* #undef HAVE_AUTOCONF_IO_H */
130#define HAVE_STDIO_H 1
131])
132
133AT_CLEANUP
134
135
136## ------------------------------ ##
137## AC_PROG_CPP without warnings.  ##
138## ------------------------------ ##
139
140AT_SETUP([AC_PROG_CPP without warnings])
141
142# Ignore if /lib/cpp doesn't work
143AT_CHECK([[echo '#include <stdio.h>' | /lib/cpp || exit 77]],
144  [], [ignore], [ignore])
145
146# A cpp which exit status is meaningless.
147AT_DATA([mycpp],
148[[#! /bin/sh
149/lib/cpp "$@"
150exit 0
151]])
152
153chmod +x mycpp
154
155_AT_CHECK_AC_MACRO(
156[[CPP=./mycpp
157AC_PROG_CPP
158test "x$ac_c_preproc_warn_flag" != xyes &&
159  AC_MSG_ERROR([failed to detect preprocessor warning option])
160
161# Exercise CPP.
162AC_CHECK_HEADERS(stdio.h autoconf_io.h, [], [], [-])]])
163
164AT_CHECK_DEFINES(
165[/* #undef HAVE_AUTOCONF_IO_H */
166#define HAVE_STDIO_H 1
167])
168
169AT_CLEANUP
170
171
172
173## -------------------- ##
174## AC_PROG_CPP via CC.  ##
175## -------------------- ##
176
177
178# It's Ok for strict preprocessors to produce warnings.
179
180AT_SETUP([AC_PROG_CPP via CC])
181
182# Ignore if /lib/cpp doesn't work
183AT_CHECK([[echo '#include <stdio.h>' | /lib/cpp || exit 77]],
184  [], [ignore], [ignore])
185
186AT_DATA([mycc],
187[[#! /bin/sh
188echo "Annoying copyright message" >&2
189exec "$@"
190]])
191
192chmod +x mycc
193
194# We go through the following contortions, in order to have the
195# configure script go down the same codepaths as it would during a
196# normal CPP selection check.  If we explicitly set CPP, it goes down
197# a different codepath.
198_AT_CHECK_AC_MACRO(
199[[AC_PROG_CC
200CC="./mycc $CC"
201AC_PROG_CPP
202# The test $CC compiler should have been selected.
203test "$CPP" != "$CC -E" &&
204  AC_MSG_ERROR([error messages on stderr cause the preprocessor selection to fail])
205
206# Exercise CPP.
207AC_CHECK_HEADERS(stdio.h autoconf_io.h, [], [], [-])]])
208
209AT_CHECK_DEFINES(
210[/* #undef HAVE_AUTOCONF_IO_H */
211#define HAVE_STDIO_H 1
212])
213
214AT_CLEANUP
215
216
217## ------------------------------------ ##
218## AC_NO_EXECUTABLES (working linker).  ##
219## ------------------------------------ ##
220
221AT_CHECK_MACRO([AC_NO_EXECUTABLES (working linker)],
222[AC_NO_EXECUTABLES
223AC_PROG_CC
224])
225
226
227## ----------------------------------- ##
228## AC_NO_EXECUTABLES (broken linker).  ##
229## ----------------------------------- ##
230
231AT_CHECK_MACRO([AC_NO_EXECUTABLES (broken linker)],
232[LDFLAGS=-lnosuchlibrary
233AC_NO_EXECUTABLES
234AC_PROG_CC
235])
236
237
238## -------------------------- ##
239## AC_USE_SYSTEM_EXTENSIONS.  ##
240## -------------------------- ##
241
242AT_SETUP([AC_USE_SYSTEM_EXTENSIONS])
243
244# Some existing configure.ac mixed AC_AIX (now an alias for
245# AC_USE_SYSTEM_EXTENSIONS) and AC_DEFINE([__EXTENSIONS__]), which
246# broke autoheader in 2.62.  Test that this is supported.
247
248_AT_CHECK_AC_MACRO(
249[[AC_AIX
250AC_DEFINE([__EXTENSIONS__], [1], [Manually defined for Solaris])
251]])
252
253_AT_CHECK_AC_MACRO(
254[[AC_USE_SYSTEM_EXTENSIONS
255AC_DEFINE([__EXTENSIONS__], [1], [Manually defined for Solaris])
256]])
257
258AT_CLEANUP
259
260
261## ----------------------- ##
262## AC_C_RESTRICT and C++.  ##
263## ----------------------- ##
264
265AT_SETUP([AC_C_RESTRICT and C++])
266
267# In some compiler suites, the left hand doesn't know about everything
268# the right hand does; or the user mixes the C compiler from one suite
269# with the C++ compiler from another.  In this case, Sun WorkShop CC
270# not like the _Restrict accepted by cc.
271
272AT_DATA([configure.ac],
273[[AC_INIT
274AC_PROG_CC
275AC_PROG_CXX
276AC_C_RESTRICT
277AC_CONFIG_HEADERS([config.h])
278AC_CONFIG_FILES([Makefile])
279AC_OUTPUT
280]])
281
282AT_DATA([Makefile.in],
283[[CC = @CC@
284CXX = @CXX@
285CFLAGS = @CFLAGS@
286CXXFLAGS = @CXXFLAGS@
287CPPFLAGS = -I. @CPPFLAGS@
288OBJEXT = @OBJEXT@
289all: foo.$(OBJEXT) bar.$(OBJEXT)
290cpp-works:
291	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c cpp-works.cpp
292foo.$(OBJEXT): foo.c
293	$(CC) $(CPPFLAGS) $(CFLAGS) -c foo.c
294bar.$(OBJEXT): bar.cpp
295	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c bar.cpp
296]])
297
298AT_DATA([foo.c],
299[[#include <config.h>
300
301int foo (int * restrict i1, int * restrict i2)
302{
303  return i1[0] + i2[0];
304}
305]])
306
307cp foo.c bar.cpp
308
309AT_DATA([cpp-works.cpp],
310[[// This file is just to test whether we have a working C++ compiler at all
311class foo { int x; };
312class foo foobar;
313]])
314
315AT_CHECK([autoconf])
316AT_CHECK([autoheader])
317AT_CHECK([./configure $configure_options], [], [ignore], [ignore])
318AT_CHECK([${MAKE-make} cpp-works || exit 77], [], [ignore], [ignore])
319AT_CHECK([${MAKE-make}], [], [ignore], [ignore])
320
321AT_CLEANUP
322
323
324## ---------------- ##
325## AC_OPENMP and C. ##
326## ---------------- ##
327
328AT_SETUP([AC_OPENMP and C])
329
330AT_DATA([configure.ac],
331[[AC_INIT
332AC_PROG_CC
333AC_OPENMP
334if test "X$ac_cv_prog_c_openmp" = Xunsupported; then
335  AS_EXIT([77])
336fi
337CFLAGS="$CFLAGS $OPENMP_CFLAGS"
338CPPFLAGS="$CPPFLAGS $OPENMP_CFLAGS"
339AC_CONFIG_FILES([Makefile])
340AC_OUTPUT
341]])
342
343AT_DATA([Makefile.in],
344[[foo@EXEEXT@: foo.@OBJEXT@
345	@CC@ @CFLAGS@ @LDFLAGS@ -o $@ foo.@OBJEXT@
346
347foo.@OBJEXT@: foo.c
348	@CC@ @CPPFLAGS@ @CFLAGS@ -c foo.c
349]])
350
351AT_DATA([foo.c],
352[[#ifdef _OPENMP
353#include <omp.h>
354#endif
355#include <stdio.h>
356
357int main ()
358{
359#ifdef _OPENMP
360#pragma omp parallel
361  {
362    int id = omp_get_thread_num ();
363    printf ("hello omp world from %d\n", id);
364  }
365#endif
366  return 0;
367}
368]])
369
370: "${MAKE=make}"
371AT_CHECK([env ACLOCAL=true autoreconf -vi], [], [ignore], [ignore])
372AT_CHECK([./configure $configure_options], [], [ignore], [ignore])
373AT_CHECK([$MAKE], [], [ignore], [ignore])
374
375AT_CLEANUP
376
377
378## ------------------ ##
379## AC_OPENMP anc C++. ##
380## ------------------ ##
381
382AT_SETUP([AC_OPENMP and C++])
383
384AT_DATA([configure.ac],
385[[AC_INIT
386AC_PROG_CXX
387AC_LANG([C++])
388AC_OPENMP
389if test "X$ac_cv_prog_cxx_openmp" = Xunsupported; then
390  AS_EXIT([77])
391fi
392CXXFLAGS="$CXXFLAGS $OPENMP_CXXFLAGS"
393CPPFLAGS="$CPPFLAGS $OPENMP_CXXFLAGS"
394AC_CONFIG_FILES([Makefile])
395AC_OUTPUT
396]])
397
398AT_DATA([Makefile.in],
399[[foo@EXEEXT@: foo.@OBJEXT@
400	@CXX@ @CXXFLAGS@ @LDFLAGS@ -o $@ foo.@OBJEXT@
401
402foo.@OBJEXT@: foo.cpp
403	@CXX@ @CPPFLAGS@ @CXXFLAGS@ -c foo.cpp
404]])
405
406AT_DATA([foo.cpp],
407[[int main ()
408{
409  return 0;
410}
411]])
412
413: "${MAKE=make}"
414AT_CHECK([env ACLOCAL=true autoreconf -vi], [], [ignore], [ignore])
415AT_CHECK([./configure $configure_options], [], [ignore], [ignore])
416AT_CHECK([$MAKE], [], [ignore], [ignore])
417
418AT_CLEANUP
419