acx_prog_cc_optim.m4 5.36 KB
Newer Older
Emmanuel Bertin's avatar
Emmanuel Bertin committed
1
dnl
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
dnl				acx_prog_cc_optim.m4
dnl
dnl Enable a reasonable set of optimization flags for the C compiler. 
dnl
dnl %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
dnl
dnl	This file part of:	AstrOmatic software
dnl
dnl	Copyright:		(C) 2002-2010 IAP/CNRS/UPMC (this version)
dnl				(C) 2002 Ville Lauriki (original version)
dnl
dnl	Authors:		Emmanuel Bertin (IAP)
dnl				Ville Lauriki (original VL_PROG_CC_WARNINGS)
dnl
dnl	Licenses:		GPL (this version)
dnl				MIT AllPermissive (original script)
dnl
dnl	AstrOmatic software is free software: you can redistribute it and/or
dnl	modify it under the terms of the GNU General Public License as
dnl	published by the Free Software Foundation, either version 3 of the
dnl	License, or (at your option) any later version.
dnl	AstrOmatic software is distributed in the hope that it will be useful,
dnl	but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
dnl	GNU General Public License for more details.
dnl	You should have received a copy of the GNU General Public License
dnl	along with AstrOmatic software.
dnl	If not, see <http://www.gnu.org/licenses/>.
dnl
dnl	Last modified:		09/10/2010
dnl
dnl %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
dnl
dnl @synopsis ACX_PROG_CC_OPTIM
Emmanuel Bertin's avatar
Emmanuel Bertin committed
36
37
38
39
40
41
42
43
dnl
dnl Currently this macro knows about GCC, Solaris C compiler,
dnl Digital Unix C compiler, C for AIX Compiler, HP-UX C compiler,
dnl IRIX C compiler, NEC SX-5 (Super-UX 10) C compiler, and Cray J90
dnl (Unicos 10.0.0.8) C compiler.
dnl
dnl This macro is a modification of Ville Laurikari's VL_PROG_CC_WARNINGS
dnl
44

Emmanuel Bertin's avatar
Emmanuel Bertin committed
45
46
AC_DEFUN([ACX_PROG_CC_OPTIM], [
  msg="for C compiler optimization flags"
47
  AC_CACHE_CHECK($msg, prog_cc_optim_cv_flags, [
Emmanuel Bertin's avatar
Emmanuel Bertin committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
    if test -n "$CC"; then
      cat > conftest.c <<EOF
int main(int argc, char **argv) { return 0; }
EOF

      dnl Most compilers print some kind of a version string with some command
      dnl line options (often "-V").  The version string should be checked
      dnl before doing a test compilation run with compiler-specific flags.
      dnl This is because some compilers (like the Cray compiler) only
      dnl produce a warning message for unknown flags instead of returning
      dnl an error, resulting in a false positive.  Also, compilers may do
      dnl erratic things when invoked with flags meant for a different
      dnl compiler.

Emmanuel Bertin's avatar
Emmanuel Bertin committed
62
63
64
65
      dnl INTEL C 64bits compiler
      if $CC -V 2>&1 | grep -i "Intel(R) 64" > /dev/null 2>&1 &&
           $CC -c -O conftest.c > /dev/null 2>&1 &&
           test -f conftest.o; then
66
67
        prog_cc_optim_cv_flags="-O3 -axSSE3,SSE4.1,SSE4.2 -ip -no-prec-div -unroll"
        prog_ld_optim_cv_flags="-static-intel"
Emmanuel Bertin's avatar
Emmanuel Bertin committed
68
69
70
71
72

      dnl INTEL C 32bits compiler
      elif $CC -V 2>&1 | grep -i "Intel(R)" > /dev/null 2>&1 &&
           $CC -c -O conftest.c > /dev/null 2>&1 &&
           test -f conftest.o; then
73
74
        prog_cc_optim_cv_flags="-O3 -axSSE2,SSE3,SSE4.1,SSE4.2 -ip -no-prec-div -unroll"
        prog_ld_optim_cv_flags="-static-intel"
Emmanuel Bertin's avatar
Emmanuel Bertin committed
75
76
77

      dnl GCC
      elif test "$GCC" = "yes"; then
78
79
        prog_cc_optim_cv_flags="-O3 -g -funroll-loops -fomit-frame-pointer -Wall"
        prog_ld_optim_cv_flags=""
Emmanuel Bertin's avatar
Emmanuel Bertin committed
80

Emmanuel Bertin's avatar
Emmanuel Bertin committed
81
82
83
84
      dnl Solaris C compiler
      elif $CC -V 2>&1 | grep -i "WorkShop" > /dev/null 2>&1 &&
           $CC -c -O conftest.c > /dev/null 2>&1 &&
           test -f conftest.o; then
85
86
        prog_cc_optim_cv_flags="-O"
        prog_ld_optim_cv_flags=""
Emmanuel Bertin's avatar
Emmanuel Bertin committed
87
88
89
90
91
92

      dnl Digital Unix/Compaq C compiler
      elif ($CC -V 2>&1 | grep -i "Digital UNIX Compiler"> /dev/null 2>&1 ||
	   $CC -V 2>&1 | grep -i "Compaq C"> /dev/null 2>&1) &&
           $CC -c -fast conftest.c > /dev/null 2>&1 &&
           test -f conftest.o; then
93
94
        prog_cc_optim_cv_flags="-fast -tune host"
        prog_ld_optim_cv_flags=""
Emmanuel Bertin's avatar
Emmanuel Bertin committed
95
96
97
98
99

      dnl C for AIX Compiler
      elif $CC 2>&1 | grep -i "C for AIX Compiler" > /dev/null 2>&1 &&
           $CC -c -qinfo=all -O2 conftest.c > /dev/null 2>&1 &&
           test -f conftest.o; then
100
101
        prog_cc_optim_cv_flags="-O2"
        prog_ld_optim_cv_flags=""
Emmanuel Bertin's avatar
Emmanuel Bertin committed
102
103
104
105
106

      dnl IRIX C compiler
      elif $CC -version 2>&1 | grep -i "MIPSpro Compilers" > /dev/null 2>&1 &&
           $CC -c -fullwarn -O3 conftest.c > /dev/null 2>&1 &&
           test -f conftest.o; then
107
108
        prog_cc_optim_cv_flags="-O3"
        prog_ld_optim_cv_flags=""
Emmanuel Bertin's avatar
Emmanuel Bertin committed
109
110
111
112
113

      dnl HP-UX C compiler
      elif what $CC 2>&1 | grep -i "HP C Compiler" > /dev/null 2>&1 &&
           $CC -c -Aa +O3 conftest.c > /dev/null 2>&1 &&
           test -f conftest.o; then
114
115
        prog_cc_optim_cv_flags="+O3"
        prog_ld_optim_cv_flags=""
Emmanuel Bertin's avatar
Emmanuel Bertin committed
116
117
118
119
120

      dnl The NEC SX-5 (Super-UX 10) C compiler
      elif $CC -V 2>&1 | grep "/SX" > /dev/null 2>&1 &&
           $CC -c -Xc -O conftest.c > /dev/null 2>&1 &&
           test -f conftest.o; then
121
122
        prog_cc_optim_cv_flags="-O"
        prog_ld_optim_cv_flags=""
Emmanuel Bertin's avatar
Emmanuel Bertin committed
123
124
125
126
127

      dnl The Cray C compiler (Unicos)
      elif $CC -V 2>&1 | grep -i "Cray" > /dev/null 2>&1 &&
           $CC -c -h conform -O3 conftest.c > /dev/null 2>&1 &&
           test -f conftest.o; then
128
129
        prog_cc_optim_cv_flags="-O3"
        prog_ld_optim_cv_flags=""
Emmanuel Bertin's avatar
Emmanuel Bertin committed
130
131
132
133

      fi
      rm -f conftest.*
    fi
134
135
136
    if test -n "$prog_cc_optim_cv_flags"; then
      AM_CFLAGS="$CFLAGS $prog_cc_optim_cv_flags"
      AM_LDFLAGS="$LDFLAGS $prog_ld_optim_cv_flags"
Emmanuel Bertin's avatar
Emmanuel Bertin committed
137
    else
138
139
      prog_cc_optim_cv_flags=""
      prog_ld_optim_cv_flags=""
Emmanuel Bertin's avatar
Emmanuel Bertin committed
140
141
142
    fi
  ])
])dnl
Emmanuel Bertin's avatar
Emmanuel Bertin committed
143