1AC_DEFUN(ACX_CHECK_CC_FLAGS,
2[
3AC_REQUIRE([AC_PROG_CC])
4AC_CACHE_CHECK(whether ${CC-cc} accepts $1, ac_$2,
5[echo 'void f(){}' > conftest.c
6if test -z "`${CC-cc} $1 -c conftest.c 2>&1`"; then
7	ac_$2=yes
8else
9	ac_$2=no
10fi
11rm -f conftest*
12])
13if test "$ac_$2" = yes; then
14	:
15	$3
16else
17	:
18	$4
19fi
20])
21
22AC_DEFUN(ACX_PROG_GCC_VERSION,
23[
24AC_REQUIRE([AC_PROG_CC])
25AC_CACHE_CHECK(whether we are using gcc $1.$2 or later, ac_cv_prog_gcc_$1_$2,
26[
27dnl The semicolon after "yes" below is to pacify NeXT's syntax-checking cpp.
28cat > conftest.c <<EOF
29#ifdef __GNUC__
30#  if (__GNUC__ > $1) || (__GNUC__ == $1 && __GNUC_MINOR__ >= $2)
31     yes;
32#  endif
33#endif
34EOF
35if AC_TRY_COMMAND(${CC-cc} -E conftest.c) | egrep yes >/dev/null 2>&1; then
36  ac_cv_prog_gcc_$1_$2=yes
37else
38  ac_cv_prog_gcc_$1_$2=no
39fi
40])
41if test "$ac_cv_prog_gcc_$1_$2" = yes; then
42	:
43	$3
44else
45	:
46	$4
47fi
48])
49
50AC_DEFUN(ACX_PROG_CC_EGCS,
51[ACX_PROG_GCC_VERSION(2,90,acx_prog_egcs=yes,acx_prog_egcs=no)])
52
53# Check to see if we are using a version of gcc that aligns the stack
54# (true in gcc-2.95+, which have the -mpreferred-stack-boundary flag).
55# Also check for stack alignment bug in gcc-2.95.x
56# (see http://egcs.cygnus.com/ml/gcc-bugs/1999-11/msg00259.html), and
57# whether main() is correctly aligned by the OS/libc/loader.
58AC_DEFUN(ACX_GCC_ALIGNS_STACK,
59[
60AC_REQUIRE([AC_PROG_CC])
61acx_gcc_aligns_stack=no
62if test "$GCC" = "yes"; then
63ACX_CHECK_CC_FLAGS(-mpreferred-stack-boundary=4, m_pref_stack_boundary_4)
64if test "$ac_m_pref_stack_boundary_4" = "yes"; then
65	AC_MSG_CHECKING([whether the stack is correctly aligned by gcc])
66	save_CFLAGS="$CFLAGS"
67	CFLAGS="-O -malign-double"
68	AC_TRY_RUN([#include <stdlib.h>
69#       include <stdio.h>
70	struct yuck { int blechh; };
71	int one(void) { return 1; }
72	struct yuck ick(void) { struct yuck y; y.blechh = 3; return y; }
73#       define CHK_ALIGN(x) if ((((long) &(x)) & 0x7)) { fprintf(stderr, "bad alignment of " #x "\n"); exit(1); }
74	void blah(int foo) { double foobar; CHK_ALIGN(foobar); }
75	int main(void) { double ok1; struct yuck y; double ok2; CHK_ALIGN(ok1);
76                         CHK_ALIGN(ok2); y = ick(); blah(one()); return 0; }
77	], [acx_gcc_aligns_stack=yes; acx_gcc_stack_align_bug=no],
78	acx_gcc_stack_align_bug=yes, acx_gcc_stack_align_bug=yes)
79	CFLAGS="$save_CFLAGS"
80	AC_MSG_RESULT($acx_gcc_aligns_stack)
81fi
82fi
83if test "$acx_gcc_aligns_stack" = yes; then
84	:
85	$1
86else
87	:
88	$2
89fi
90])
91
92
93AC_DEFUN(ACX_PROG_CC_MAXOPT,
94[
95AC_REQUIRE([AC_PROG_CC])
96AC_REQUIRE([ACX_PROG_CC_EGCS])
97AC_REQUIRE([AC_CANONICAL_HOST])
98
99# Try to determine "good" native compiler flags if none specified on command
100# line
101if test "$ac_test_CFLAGS" != "set"; then
102  CFLAGS=""
103  case "${host_cpu}-${host_os}" in
104
105  *linux*)
106	echo "*******************************************************"
107	echo "*       Congratulations! You are running linux.       *"
108	echo "*******************************************************"
109	;;
110  sparc-solaris2*) if test "$CC" = cc; then
111                    CFLAGS="-native -fast -xO5 -dalign"
112                 fi;;
113
114  alpha*-osf*)  if test "$CC" = cc; then
115                    CFLAGS="-newc -w0 -O5 -ansi_alias -ansi_args -fp_reorder -tune host -arch host -std1"
116                fi;;
117
118  hppa*-hpux*)  if test "$CC" = cc; then
119                    CFLAGS="-Ae +O3 +Oall"
120                fi;;
121
122   *-aix*)
123	if test "$CC" = cc -o "$CC" = xlc; then
124		ACX_CHECK_CC_FLAGS([-qarch=auto -qtune=auto], qarch_auto,
125			[CFLAGS="-O3 -qansialias -w -qarch=auto -qtune=auto"],
126			[CFLAGS="-O3 -qansialias -w"
127	echo "*******************************************************"
128	echo "*  You seem to have AIX and the IBM compiler.  It is  *"
129	echo "*  recommended for best performance that you use:     *"
130	echo "*                                                     *"
131	echo "*    CFLAGS=-O3 -qarch=xxx -qtune=xxx -qansialias -w  *"
132	echo "*                      ^^^        ^^^                 *"
133	echo "*  where xxx is pwr2, pwr3, 604, or whatever kind of  *"
134        echo "*  CPU you have.  (Set the CFLAGS environment var.    *"
135        echo "*  and re-run configure.)  For more info, man cc.     *"
136	echo "*******************************************************"
137			])
138        fi;;
139  esac
140
141  # use default flags for gcc on all systems
142  if test $ac_cv_prog_gcc = yes; then
143     CFLAGS="-O3 -fomit-frame-pointer"
144  fi
145
146  # the egcs scheduler is too smart and destroys our own schedule.
147  # Disable the first instruction scheduling pass.  The second
148  # scheduling pass (after register reload) is ok.
149  if test "$acx_prog_egcs" = yes; then
150     CFLAGS="$CFLAGS -fno-schedule-insns -fschedule-insns2"
151  fi
152
153  # test for gcc-specific flags:
154  if test $ac_cv_prog_gcc = yes; then
155    # -malign-double for x86 systems
156    ACX_CHECK_CC_FLAGS(-malign-double,align_double,
157	CFLAGS="$CFLAGS -malign-double")
158    # -fstrict-aliasing for gcc-2.95+
159    ACX_CHECK_CC_FLAGS(-fstrict-aliasing,fstrict_aliasing,
160	CFLAGS="$CFLAGS -fstrict-aliasing")
161  fi
162
163  CPU_FLAGS=""
164  if test "$GCC" = "yes"; then
165	  dnl try to guess correct CPU flags, at least for linux
166	  case "${host_cpu}" in
167	  i586*)  ACX_CHECK_CC_FLAGS(-mcpu=pentium,cpu_pentium,
168			[CPU_FLAGS=-mcpu=pentium],
169			[ACX_CHECK_CC_FLAGS(-mpentium,pentium,
170				[CPU_FLAGS=-mpentium])])
171		  ;;
172	  i686*)  ACX_CHECK_CC_FLAGS(-mcpu=pentiumpro,cpu_pentiumpro,
173			[CPU_FLAGS=-mcpu=pentiumpro],
174			[ACX_CHECK_CC_FLAGS(-mpentiumpro,pentiumpro,
175				[CPU_FLAGS=-mpentiumpro])])
176		  ;;
177	  alphaev4-*)  ACX_CHECK_CC_FLAGS(-mcpu=ev4,cpu_ev4,
178			[CPU_FLAGS=-mcpu=ev4])
179		  ;;
180	  alphaev56-*)  ACX_CHECK_CC_FLAGS(-mcpu=ev56,cpu_ev56,
181			[CPU_FLAGS=-mcpu=ev56])
182		  ;;
183	  alphaev5-*)  ACX_CHECK_CC_FLAGS(-mcpu=ev5,cpu_ev5,
184			[CPU_FLAGS=-mcpu=ev5])
185		  ;;
186	  alphaev6-*)  ACX_CHECK_CC_FLAGS(-mcpu=ev6,cpu_ev6,
187			[CPU_FLAGS=-mcpu=ev6])
188		  ;;
189	  powerpc*)
190		cputype=`(grep cpu /proc/cpuinfo | head -1 | cut -d: -f2 | sed 's/ //g') 2> /dev/null`
191		is60x=`echo $cputype | egrep "^60[0-9]e?$"`
192		if test -n "$is60x"; then
193			ACX_CHECK_CC_FLAGS(-mcpu=$cputype,m_cpu_60x,
194				CPU_FLAGS=-mcpu=$cputype)
195		elif test "$cputype" = 750; then
196                        ACX_PROG_GCC_VERSION(2,95,
197                                ACX_CHECK_CC_FLAGS(-mcpu=750,m_cpu_750,
198					CPU_FLAGS=-mcpu=750))
199		fi
200		if test -z "$CPU_FLAGS"; then
201		        ACX_CHECK_CC_FLAGS(-mcpu=powerpc,m_cpu_powerpc,
202				CPU_FLAGS=-mcpu=powerpc)
203		fi
204		if test -z "$CPU_FLAGS"; then
205			ACX_CHECK_CC_FLAGS(-mpowerpc,m_powerpc,
206				CPU_FLAGS=-mpowerpc)
207		fi
208	  esac
209  fi
210
211  if test -n "$CPU_FLAGS"; then
212        CFLAGS="$CFLAGS $CPU_FLAGS"
213  fi
214
215  if test -z "$CFLAGS"; then
216	echo ""
217	echo "********************************************************"
218        echo "* WARNING: Don't know the best CFLAGS for this system  *"
219        echo "* Use  make CFLAGS=..., or edit the top level Makefile *"
220	echo "* (otherwise, a default of CFLAGS=-O3 will be used)    *"
221	echo "********************************************************"
222	echo ""
223        CFLAGS="-O3"
224  fi
225
226  ACX_CHECK_CC_FLAGS(${CFLAGS}, guessed_cflags, , [
227	echo ""
228        echo "********************************************************"
229        echo "* WARNING: The guessed CFLAGS don't seem to work with  *"
230        echo "* your compiler.                                       *"
231        echo "* Use  make CFLAGS=..., or edit the top level Makefile *"
232        echo "********************************************************"
233        echo ""
234        CFLAGS=""
235  ])
236
237fi
238])
239