1#							-*- Autotest -*-
2
3AT_BANNER([C low level compiling/preprocessing macros.])
4
5# Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
6# Foundation, Inc.
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2, or (at your option)
11# any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program; if not, write to the Free Software
20# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21# 02110-1301, USA.
22
23
24# Since the macros which compile are required by most tests, check
25# them first.  But remember that looking for a compiler is even more
26# primitive, so check those first.
27
28
29## ------------ ##
30## Extensions.  ##
31## ------------ ##
32
33# As far as we know only `foo', `foo.exe' are possible executable,
34# and `foo.o', `foo.obj' are possible object files.  Autoconf must not
35# know that, but it is OK for the test suite to take this into account.
36AT_CHECK_MACRO([Extensions],
37[[AC_PROG_CC
38case $ac_exeext in
39  '' | '.exe' ) ;;
40  * ) AC_MSG_ERROR([suspicious executable suffix: $ac_exeext]);;
41esac
42
43case $ac_objext in
44  'o' | 'obj' ) ;;
45  * ) AC_MSG_ERROR([suspicious object suffix: $ac_objext]);;
46esac
47]])
48
49
50
51## -------------------------- ##
52## Broken/missing compilers.  ##
53## -------------------------- ##
54
55
56# Check that Autoconf correctly diagnoses broken compilers, and in
57# particular, if it does not exit 77, the test suite is in trouble...
58# FIXME: Once a precise message decided, check stderr of configure.
59AT_SETUP([Broken/missing compilers])
60
61AT_DATA([configure.ac],
62[[AC_INIT
63CC=no-such-compiler
64AC_PROG_CC
65]])
66
67AT_CHECK_AUTOCONF
68AT_CHECK_CONFIGURE([], 77, ignore, ignore)
69
70AT_CLEANUP
71
72
73## ------------ ##
74## C keywords.  ##
75## ------------ ##
76
77# GCC supports `const', `typeof', and `volatile'.
78AT_CHECK_MACRO([C keywords],
79[[AC_PROG_CC
80AC_C_CONST
81AC_C_TYPEOF
82AC_C_VOLATILE
83case $GCC,$ac_cv_c_const,$ac_cv_c_typeof,$ac_cv_c_volatile in
84 yes,*no*)
85   AC_MSG_ERROR([failed to detect `const', `typeof', or `volatile' support]);;
86esac
87]])
88
89
90
91## --------------------------------- ##
92## AC_PROG_CPP requires AC_PROG_CC.  ##
93## --------------------------------- ##
94
95# Must invoke AC_PROG_CC.
96AT_CHECK_MACRO([AC_PROG_CPP requires AC_PROG_CC],
97[[AC_PROG_CPP
98test -z "$CC" &&
99   AC_MSG_ERROR([looked for a C preprocessor without looking for a compiler])
100]])
101
102
103
104## --------------------------- ##
105## AC_PROG_CPP with warnings.  ##
106## --------------------------- ##
107
108
109# It's Ok for strict preprocessors to produce warnings.
110
111AT_SETUP([AC_PROG_CPP with warnings])
112
113AT_DATA([mycpp],
114[[#! /bin/sh
115echo noise >&2
116exec "$@"
117]])
118
119chmod +x mycpp
120
121_AT_CHECK_AC_MACRO(
122[[AC_PROG_CPP
123# If the preprocessor is not strict, just ignore
124test "x$ac_c_preproc_warn_flag" = xyes &&
125  AC_MSG_ERROR([preprocessor has no warning option], 77)
126CPP="./mycpp $CPP"
127AC_CHECK_HEADERS(stdio.h autoconf_io.h)]])
128
129AT_CHECK_DEFINES(
130[/* #undef HAVE_AUTOCONF_IO_H */
131#define HAVE_STDIO_H 1
132])
133
134AT_CLEANUP
135
136
137## ------------------------------ ##
138## AC_PROG_CPP without warnings.  ##
139## ------------------------------ ##
140
141AT_SETUP([AC_PROG_CPP without warnings])
142
143# Ignore if /lib/cpp doesn't work
144AT_CHECK([echo '#include <stdio.h>' | /lib/cpp || exit 77],
145  [], [ignore], [ignore])
146
147# A cpp which exit status is meaningless.
148AT_DATA([mycpp],
149[[#! /bin/sh
150/lib/cpp "$@"
151exit 0
152]])
153
154chmod +x mycpp
155
156_AT_CHECK_AC_MACRO(
157[[CPP=./mycpp
158AC_PROG_CPP
159test "x$ac_c_preproc_warn_flag" != xyes &&
160  AC_MSG_ERROR([failed to detect preprocessor warning option])
161AC_CHECK_HEADERS(stdio.h autoconf_io.h)]])
162
163AT_CHECK_DEFINES(
164[/* #undef HAVE_AUTOCONF_IO_H */
165#define HAVE_STDIO_H 1
166])
167
168AT_CLEANUP
169
170
171
172## -------------------- ##
173## AC_PROG_CPP via CC.  ##
174## -------------------- ##
175
176
177# It's Ok for strict preprocessors to produce warnings.
178
179AT_SETUP([AC_PROG_CPP via CC])
180
181# Ignore if /lib/cpp doesn't work
182AT_CHECK([echo '#include <stdio.h>' | /lib/cpp || exit 77],
183  [], [ignore], [ignore])
184
185AT_DATA([mycc],
186[[#! /bin/sh
187echo "Annoying copyright message" >&2
188exec "$@"
189]])
190
191chmod +x mycc
192
193# We go through the following contortions, in order to have the
194# configure script go down the same codepaths as it would during a
195# normal CPP selection check.  If we explicitly set CPP, it goes down
196# a different codepath.
197_AT_CHECK_AC_MACRO(
198[[AC_PROG_CC
199CC="./mycc $CC"
200AC_PROG_CPP
201# The test $CC compiler should have been selected.
202test "$CPP" != "$CC -E" &&
203  AC_MSG_ERROR([error messages on stderr cause the preprocessor selection to fail])
204
205# Exercise CPP.
206AC_CHECK_HEADERS(stdio.h autoconf_io.h)]])
207
208AT_CHECK_DEFINES(
209[/* #undef HAVE_AUTOCONF_IO_H */
210#define HAVE_STDIO_H 1
211])
212
213AT_CLEANUP
214