| 1 |
# Choosing debugging and/or optimization flags for compilation |
| 2 |
# ------------------------------------------------------------ |
| 3 |
# get CPU Type |
| 4 |
cputype=unknow |
| 5 |
if test -x /usr/bin/machine ; then |
| 6 |
cputype=`/usr/bin/machine` |
| 7 |
elif test -x /usr/bin/arch ; then |
| 8 |
cputype=`/usr/bin/arch` |
| 9 |
fi |
| 10 |
cpuintel=no; |
| 11 |
case "$cputype" in |
| 12 |
i386|i486| x86_64*) cpuintel=yes;; |
| 13 |
*) cpuintel=no;; |
| 14 |
esac |
| 15 |
AC_MSG_NOTICE([ ----- CPU kind: $cputype , intel/amd: $cpuintel ]) |
| 16 |
AC_ARG_ENABLE(profiling,[ --enable-profiling Turn on profiling]) |
| 17 |
if test "$enable_profiling" = yes |
| 18 |
then |
| 19 |
CXXFLAGS="$CXXFLAGS -pg" |
| 20 |
LDFLAGS="$LDFLAGS -pg" |
| 21 |
fi |
| 22 |
|
| 23 |
if test "$enable_m64" = yes -a "$enable_m32" |
| 24 |
then |
| 25 |
AC_MSG_ERROR([ Choose 32 or 64 architecture not the both ],1); |
| 26 |
fi |
| 27 |
AC_ARG_ENABLE(m64,[ --enable-m64 Turn on 64 bits architecture]) |
| 28 |
if test "$enable_m64" = yes |
| 29 |
then |
| 30 |
ff_m64=-m64 |
| 31 |
ff_ok=no |
| 32 |
CHECK_COMPILE_FLAG(C,$ff_m64,CFLAGS,ff_ok) |
| 33 |
if test "$ff_ok" = yes ;then CNOFLAGS="$CFLAGS $ff_m64";fi |
| 34 |
CHECK_COMPILE_FLAG(C++,$ff_m64,CXXFLAGS) |
| 35 |
CHECK_COMPILE_FLAG(Fortran 77,$ff_m64,FFLAGS) |
| 36 |
# add -fPIC on on 64 architecture |
| 37 |
if test "$ff_ok" = yes -a "$ff_fpic" != "no" ;then |
| 38 |
CHECK_COMPILE_FLAG(C,-fPIC,CFLAGS,ff_ok) |
| 39 |
CHECK_COMPILE_FLAG(C++,-fPIC,CXXFLAGS) |
| 40 |
CHECK_COMPILE_FLAG(Fortran 77,-fPIC,FFLAGS) |
| 41 |
fi |
| 42 |
|
| 43 |
fi |
| 44 |
AC_ARG_ENABLE(m32,[ --enable-m32 Turn on 32 bits architecture]) |
| 45 |
if test "$enable_m32" = yes |
| 46 |
then |
| 47 |
ff_m32=-m32 |
| 48 |
ff_ok=no |
| 49 |
CHECK_COMPILE_FLAG(C,$ff_m32,CFLAGS,ff_ok) |
| 50 |
if test "$ff_ok" = yes ;then CNOFLAGS="$CFLAGS $ff_m32";fi |
| 51 |
CHECK_COMPILE_FLAG(C,$ff_m32,CNOFLAGS) |
| 52 |
CHECK_COMPILE_FLAG(C++,$ff_m32,CXXFLAGS) |
| 53 |
CHECK_COMPILE_FLAG(Fortran 77,$ff_m32,FFLAGS) |
| 54 |
# add -fPIC on on 64 architecture |
| 55 |
# CHECK_COMPILE_FLAG(C,-fPIC,CFLAGS) |
| 56 |
# CHECK_COMPILE_FLAG(C++,-fPIC,CXXFLAGS) |
| 57 |
# CHECK_COMPILE_FLAG(Fortran 77,-fPIC,FFLAGS) |
| 58 |
|
| 59 |
fi |
| 60 |
|
| 61 |
# Debug mode (no optimisation) |
| 62 |
# ---------------------------- |
| 63 |
|
| 64 |
AC_MSG_CHECKING(whether to generate debugging information) |
| 65 |
|
| 66 |
AC_ARG_ENABLE(debug,[ --enable-debug Turn on debug versions of FreeFem++]) |
| 67 |
AC_ARG_ENABLE(optim,[ --enable-optim Turn on compiler optimization]) |
| 68 |
|
| 69 |
if test "$enable_debug" = yes; |
| 70 |
then |
| 71 |
|
| 72 |
AC_MSG_RESULT(yes) |
| 73 |
CFLAGS="`echo $CFLAGS | sed 's/-O2//g'`" |
| 74 |
FFLAGS="`echo $FFLAGS | sed 's/-O2//g'`" |
| 75 |
CXXFLAGS="`echo $CXXFLAGS | sed 's/-O2//g'`" |
| 76 |
|
| 77 |
else |
| 78 |
AC_MSG_RESULT(no) |
| 79 |
|
| 80 |
# No debugging information in optimized code |
| 81 |
|
| 82 |
CFLAGS="$CFLAGS -DNDEBUG" |
| 83 |
FFLAGS="$FFLAGS -DNDEBUG" |
| 84 |
CXXFLAGS="$CXXFLAGS -DNDEBUG" |
| 85 |
fi |
| 86 |
|
| 87 |
# Hardware-independant optimization |
| 88 |
# --------------------------------- |
| 89 |
|
| 90 |
if test "$enable_debug" != yes -a "$enable_optim" != no; |
| 91 |
then |
| 92 |
CHECK_COMPILE_FLAG(C,-O3,CFLAGS) |
| 93 |
CHECK_COMPILE_FLAG(C++,-O3,CXXFLAGS) |
| 94 |
CHECK_COMPILE_FLAG(Fortran 77,-O3,FFLAGS) |
| 95 |
fi |
| 96 |
|
| 97 |
AC_ARG_ENABLE(generic, |
| 98 |
[ --enable-generic Turn off hardware-dependant optimization options]) |
| 99 |
|
| 100 |
# FFCS: remove "-mcpu=common" to allow other hardware-dependant values of cpu for PowerPC - thank you Fred (20/02/11) |
| 101 |
# FH |
| 102 |
# Generic code |
| 103 |
if test "$enable_generic" = yes |
| 104 |
then |
| 105 |
CHECK_COMPILE_FLAG(C,-mtune=generic,CFLAGS) |
| 106 |
CHECK_COMPILE_FLAG(C++,-mtune=generic,CXXFLAGS) |
| 107 |
CHECK_COMPILE_FLAG(Fortran 77,-mtune=generic,FFLAGS) |
| 108 |
fi |
| 109 |
|
| 110 |
|
| 111 |
# Hardware-dependant optimization |
| 112 |
# ------------------------------- |
| 113 |
|
| 114 |
if test "$enable_debug" != yes \ |
| 115 |
-a "$enable_optim" != no \ |
| 116 |
-a "$enable_generic" != yes |
| 117 |
then |
| 118 |
|
| 119 |
# Autoconf always chooses -O2. -O2 in gcc makes some functions |
| 120 |
# disappear. This is not ideal for debugging. And when we optimize, we |
| 121 |
# do not use -O2 anyway. |
| 122 |
|
| 123 |
CFLAGS="`echo $CFLAGS | sed 's/-O2//g'`" |
| 124 |
FFLAGS="`echo $FFLAGS | sed 's/-O2//g'`" |
| 125 |
CXXFLAGS="`echo $CXXFLAGS | sed 's/-O2//g'`" |
| 126 |
|
| 127 |
if test `grep -e '^flags.*mmx' /proc/cpuinfo|wc -l` -gt 0 |
| 128 |
then |
| 129 |
CHECK_COMPILE_FLAG(C,-mmmx,CFLAGS) |
| 130 |
CHECK_COMPILE_FLAG(C++,-mmmx,CXXFLAGS) |
| 131 |
CHECK_COMPILE_FLAG(Fortran 77,-mmmx,FFLAGS) |
| 132 |
fi |
| 133 |
if test `grep -e '^flags.*avx2' /proc/cpuinfo|wc -l` -gt 0 |
| 134 |
then |
| 135 |
CHECK_COMPILE_FLAG(C,-mavx2,CFLAGS) |
| 136 |
CHECK_COMPILE_FLAG(C++,-mavx2,CXXFLAGS) |
| 137 |
CHECK_COMPILE_FLAG(Fortran 77,-mavx2,FFLAGS) |
| 138 |
fi |
| 139 |
if test `grep -e '^flags.*avx\>' /proc/cpuinfo|wc -l` -gt 0 |
| 140 |
then |
| 141 |
CHECK_COMPILE_FLAG(C,-mavx,CFLAGS) |
| 142 |
CHECK_COMPILE_FLAG(C++,-mavx,CXXFLAGS) |
| 143 |
CHECK_COMPILE_FLAG(Fortran 77,-mavx,FFLAGS) |
| 144 |
fi |
| 145 |
if test `grep -e '^flags.*sse4_2' /proc/cpuinfo|wc -l` -gt 0 |
| 146 |
then |
| 147 |
CHECK_COMPILE_FLAG(C,-msse4.2,CFLAGS) |
| 148 |
CHECK_COMPILE_FLAG(C++,-msse4.2,CXXFLAGS) |
| 149 |
CHECK_COMPILE_FLAG(Fortran 77,-msse4.2,FFLAGS) |
| 150 |
fi |
| 151 |
if test `grep -e '^flags.*sse2' /proc/cpuinfo|wc -l` -gt 0 |
| 152 |
then |
| 153 |
CHECK_COMPILE_FLAG(C,-msse2,CFLAGS) |
| 154 |
CHECK_COMPILE_FLAG(C++,-msse2,CXXFLAGS) |
| 155 |
CHECK_COMPILE_FLAG(Fortran 77,-msse2,FFLAGS) |
| 156 |
fi |
| 157 |
if test `grep -e '^flags.*sse\>' /proc/cpuinfo|wc -l` -gt 0 |
| 158 |
then |
| 159 |
CHECK_COMPILE_FLAG(C,-msse,CFLAGS) |
| 160 |
CHECK_COMPILE_FLAG(C++,-msse,CXXFLAGS) |
| 161 |
CHECK_COMPILE_FLAG(Fortran 77,-msse,FFLAGS) |
| 162 |
fi |
| 163 |
fi |
| 164 |
|
| 165 |
# Defines a variable containing the optimization type, to be used in |
| 166 |
# binary archive names. It may be empty if only generic optimization |
| 167 |
# is used. |
| 168 |
|
| 169 |
AC_SUBST(OPTIM_TYPE,$ff_optim_type) |
| 170 |
AC_MSG_NOTICE([ CXXFLAGS = $CXXFLAGS ]) |