Add missing files
[bcusdk.git] / m4 / ccforbuild.m4
bloba466cab2aee00dfbc13447c266c8dfa0ada74550
1 dnl  GMP specific autoconf macros
4 dnl  Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
5 dnl  Foundation, Inc.
6 dnl
7 dnl  This file is part of the GNU MP Library.
8 dnl
9 dnl  The GNU MP Library is free software; you can redistribute it and/or modify
10 dnl  it under the terms of the GNU Lesser General Public License as published
11 dnl  by the Free Software Foundation; either version 2.1 of the License, or (at
12 dnl  your option) any later version.
13 dnl
14 dnl  The GNU MP Library is distributed in the hope that it will be useful, but
15 dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
17 dnl  License for more details.
18 dnl
19 dnl  You should have received a copy of the GNU Lesser General Public License
20 dnl  along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
21 dnl  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22 dnl  MA 02110-1301, USA.
24 dnl  GMP_PROG_CC_FOR_BUILD
25 dnl  ---------------------
26 dnl  Establish CC_FOR_BUILD, a C compiler for the build system.
27 dnl
28 dnl  If CC_FOR_BUILD is set then it's expected to work, likewise the old
29 dnl  style HOST_CC, otherwise some likely candidates are tried, the same as
30 dnl  configfsf.guess.
32 AC_DEFUN([GMP_PROG_CC_FOR_BUILD],
33 [AC_REQUIRE([AC_PROG_CC])
34 if test -n "$CC_FOR_BUILD"; then
35   GMP_PROG_CC_FOR_BUILD_WORKS($CC_FOR_BUILD,,
36     [AC_MSG_ERROR([Specified CC_FOR_BUILD doesn't seem to work])])
37 elif test -n "$HOST_CC"; then
38   GMP_PROG_CC_FOR_BUILD_WORKS($HOST_CC,
39     [CC_FOR_BUILD=$HOST_CC],
40     [AC_MSG_ERROR([Specified HOST_CC doesn't seem to work])])
41 else
42   for i in "$CC" "$CC $CFLAGS $CPPFLAGS" cc gcc c89 c99; do
43     GMP_PROG_CC_FOR_BUILD_WORKS($i,
44       [CC_FOR_BUILD=$i
45        break])
46   done
47   if test -z "$CC_FOR_BUILD"; then
48     AC_MSG_ERROR([Cannot find a build system compiler])
49   fi
51     
52 AC_ARG_VAR(CC_FOR_BUILD,[build system C compiler])
53 AC_SUBST(CC_FOR_BUILD)
57 dnl  GMP_PROG_CC_FOR_BUILD_WORKS(cc/cflags[,[action-if-good][,action-if-bad]])
58 dnl  -------------------------------------------------------------------------
59 dnl  See if the given cc/cflags works on the build system.
60 dnl
61 dnl  It seems easiest to just use the default compiler output, rather than
62 dnl  figuring out the .exe or whatever at this stage.
64 AC_DEFUN([GMP_PROG_CC_FOR_BUILD_WORKS],
65 [AC_MSG_CHECKING([build system compiler $1])
66 # remove anything that might look like compiler output to our "||" expression
67 rm -f conftest* a.out b.out a.exe a_out.exe
68 cat >conftest.c <<EOF
69 int
70 main ()
72   exit(0);
74 EOF
75 gmp_compile="$1 conftest.c"
76 cc_for_build_works=no
77 if AC_TRY_EVAL(gmp_compile); then
78   if (./a.out || ./b.out || ./a.exe || ./a_out.exe || ./conftest) >&AC_FD_CC 2>&1; then
79     cc_for_build_works=yes
80   fi
82 rm -f conftest* a.out b.out a.exe a_out.exe
83 AC_MSG_RESULT($cc_for_build_works)
84 if test "$cc_for_build_works" = yes; then
85   ifelse([$2],,:,[$2])
86 else
87   ifelse([$3],,:,[$3])
92 dnl  GMP_PROG_CPP_FOR_BUILD
93 dnl  ---------------------
94 dnl  Establish CPP_FOR_BUILD, the build system C preprocessor.
95 dnl  The choices tried here are the same as AC_PROG_CPP, but with
96 dnl  CC_FOR_BUILD.
98 AC_DEFUN([GMP_PROG_CPP_FOR_BUILD],
99 [AC_REQUIRE([GMP_PROG_CC_FOR_BUILD])
100 AC_MSG_CHECKING([for build system preprocessor])
101 if test -z "$CPP_FOR_BUILD"; then
102   AC_CACHE_VAL(gmp_cv_prog_cpp_for_build,
103   [cat >conftest.c <<EOF
104 #define FOO BAR
106   for i in "$CC_FOR_BUILD -E" "$CC_FOR_BUILD -E -traditional-cpp" "/lib/cpp"; do
107     gmp_compile="$i conftest.c"
108     if AC_TRY_EVAL(gmp_compile) >&AC_FD_CC 2>&1; then
109       gmp_cv_prog_cpp_for_build=$i
110       break
111     fi
112   done
113   rm -f conftest* a.out b.out a.exe a_out.exe
114   if test -z "$gmp_cv_prog_cpp_for_build"; then
115     AC_MSG_ERROR([Cannot find build system C preprocessor.])
116   fi
117   ])
118   CPP_FOR_BUILD=$gmp_cv_prog_cpp_for_build
120 AC_MSG_RESULT([$CPP_FOR_BUILD])
122 AC_ARG_VAR(CPP_FOR_BUILD,[build system C preprocessor])
123 AC_SUBST(CPP_FOR_BUILD)
127 dnl  GMP_PROG_EXEEXT_FOR_BUILD
128 dnl  -------------------------
129 dnl  Determine EXEEXT_FOR_BUILD, the build system executable suffix.
131 dnl  The idea is to find what "-o conftest$foo" will make it possible to run
132 dnl  the program with ./conftest.  On Unix-like systems this is of course
133 dnl  nothing, for DOS it's ".exe", or for a strange RISC OS foreign file
134 dnl  system cross compile it can be ",ff8" apparently.  Not sure if the
135 dnl  latter actually applies to a build-system executable, maybe it doesn't,
136 dnl  but it won't hurt to try.
138 AC_DEFUN([GMP_PROG_EXEEXT_FOR_BUILD],
139 [AC_REQUIRE([GMP_PROG_CC_FOR_BUILD])
140 AC_CACHE_CHECK([for build system executable suffix],
141                gmp_cv_prog_exeext_for_build,
142 [cat >conftest.c <<EOF
144 main ()
146   exit (0);
149 for i in .exe ,ff8 ""; do
150   gmp_compile="$CC_FOR_BUILD conftest.c -o conftest$i"
151   if AC_TRY_EVAL(gmp_compile); then
152     if (./conftest) 2>&AC_FD_CC; then
153       gmp_cv_prog_exeext_for_build=$i
154       break
155     fi
156   fi
157 done
158 rm -f conftest*
159 if test "${gmp_cv_prog_exeext_for_build+set}" != set; then
160   AC_MSG_ERROR([Cannot determine executable suffix])
163 AC_SUBST(EXEEXT_FOR_BUILD,$gmp_cv_prog_exeext_for_build)