This is the release 1.0 version
[gromacs/libxdrfile.git] / acinclude.m4
blob02259e8b07f2c532161a1de525df63661393721b
1 # ACX_CHECK_FFTW2()
2 # ----------------
3 # This macro checks for fftw-2.x header files and libraries,
4 # including the possible prefixing with s or d to determine precision.
5 # Arg 1 is the fftw header/library name to check for, without
6 # prefix or anything else (e.g. rfftw_mpi for real MPI transforms)
7 # Arg 2 is the size of the real variable used.
8 AC_DEFUN([ACX_CHECK_FFTW2],
10 if test -z "$ac_fftw_firstname"; then
12 sizeof_real=$2
13 if test $sizeof_real = 8; then
14   prec="double"
15   fftwcheckprefix=d
16 else
17   prec="single"
18   fftwcheckprefix=s
21 xfftwname=${fftwcheckprefix}$1
23 ok="no"
24 # check header doesn't work, since we must use mpicc to get includes,
25 # we cant trust cpp.
26 AC_MSG_CHECKING([for $xfftwname.h])
27 AC_TRY_COMPILE([#include <$xfftwname.h>],,
29 fftwname=$xfftwname
30 AC_MSG_RESULT(yes)
32 AC_MSG_RESULT(no))
34 # fftwname was set if we found a header
36 if test -n "$fftwname"; then
37 # we cannot run the code since an MPI program might not be allowed
38 # on a login node of a supercomputer
39 AC_TRY_COMPILE([#include <$fftwname.h>],
40 [int _array_ [1 - 2 * !((sizeof(fftw_real)) == $sizeof_real)]; ],
42 ok=yes
43 usedprefix=$fftwcheckprefix
44 ],[ok=no])
47 if test "$ok" != "yes"; then
48   AC_MSG_CHECKING([for $1.h])
49   AC_TRY_COMPILE([#include <$1.h>],,AC_MSG_RESULT(yes),
51 AC_MSG_RESULT(no)
52 AC_MSG_ERROR([Cannot find any $prec precision $xfftwname.h or $1.h]
53 [Do you have $prec precision FFTW-2.x installed? If you are using packages,]
54 [note that you also need fftw-devel to compile GROMACS. You can find the ]
55 [software at www.fftw.org, and detailed instructions at www.gromacs.org.]
56 [If you compiled FFTW-2.x yourself:                                    ]
57 [Note that the default FFTW-2.x setup is double precision. Change the FFTW]
58 [configuration to single with --enable-float. If you want MPI support,]
59 [use --enable-mpi. It is a good idea to install both single & double.]
60 [If your sysadm doesn't want to install it you can do it to a location]
61 [in your home directory and provide the correct paths in the CPPFLAGS]
62 [and LDFLAGS environment variables before running configure.]
63 [That is also necessary to do if your compiler doesn't search]
64 [/usr/local/include and /usr/local/lib by default.]
65 [You can find information at www.gromacs.org, or in the INSTALL file.])
67 AC_TRY_COMPILE([#include <$1.h>],
68 [int _array_ [1 - 2 * !((sizeof(fftw_real)) == $sizeof_real)];],
70 usedprefix=""
71 fftwname=$1
74 AC_MSG_ERROR([Cannot find any $prec precision $xfftwname.h or $1.h]
75 [Do you have $prec precision FFTW-2.x installed? If you are using packages,]
76 [note that you also need fftw-devel to compile GROMACS. You can find the ]
77 [software at www.fftw.org, and detailed instructions at www.gromacs.org.]
78 [If you compiled FFTW-2.x yourself:                                   ]
79 [Note that the default FFTW-2.x setup is double precision. Change the FFTW]
80 [configuration to single with --enable-float. If you want MPI support,]
81 [use --enable-mpi. It is a good idea to install both single & double.]
82 [If your sysadm doesn't want to install it you can do it to a location]
83 [in your home directory and provide the correct paths in the CPPFLAGS]
84 [and LDFLAGS environment variables before running configure.]
85 [That is also necessary to do if your compiler doesn't search]
86 [/usr/local/include and /usr/local/lib by default.]
87 [You can find information at www.gromacs.org, or in the INSTALL file.])])
90 AC_CHECK_LIB($fftwname,main,,
91 AC_MSG_ERROR([Can't find a library to match the $fftwname header]))
92 ac_fftw_savedprefix=$usedprefix
93 ac_fftw_firstname=$fftwname
95 else
97 fftwname=${ac_fftw_savedprefix}$1
98 AC_MSG_CHECKING([for $fftwname.h])
99 AC_TRY_COMPILE(
100 [#include <$fftwname.h>],,
101 [AC_MSG_RESULT(yes)
102 LIBS="-l$fftwname $LIBS"
103 AC_TRY_LINK_FUNC([main],,,
104 AC_MSG_ERROR([Can't find a library to match the $fftwname header]))],
106 AC_MSG_RESULT(no)
107 AC_MSG_ERROR([Cant find $fftwname.h header. Make sure all your
108 fftw prefixes match - we already use $ac_fftw_firstname.h])
120 dnl Check for floating-point format and double precision word order.
121 dnl We dont require IEEE, but there are optimizations we can only do with it.
122 dnl Just as for integers, the bytes in a word can be small of big endian.
123 dnl There is already a standard autoconf macro (AC_C_BIGENDIAN) that you 
124 dnl should use to check this for integers - I have never heard of a machine
125 dnl where it is not the same for integer and fp variables, but we still check
126 dnl it separately for fp variables here to be sure.
128 dnl However, in double precision there are also two ways to arrange the words
129 dnl forming a double (8-byte=2-word) variable.
130 dnl Normally this order is the same as the endian, but there are 
131 dnl exceptions (e.g. ARM)
132 dnl We detect it by compiling a small test program and grepping into it.
134 AC_DEFUN([ACX_FLOAT_FORMAT],
135 [AC_CACHE_CHECK(floating-point format, acx_float_format,
136 [cat >conftest.$ac_ext <<EOF
137 [/* Check that a double is 8 bytes - die if it isnt */
138 extern char xyz [sizeof(double) == 8 ? 1 : -1];
139 double abc [] = {
140   /* "GROMACSX" in ascii    */
141   (double)  3.80279098314984902657e+35 , 
142   /* "GROMACSX" in ebcdic   */
143   (double) -1.37384666579378297437e+38 , 
144   /* "D__float" (vax)       */
145   (double)  3.53802595280598432000e+18 , 
146   /* "IBMHEXFP" s390/ascii  */
147   (double)  1.77977764695171661377e+10 , 
148   /* "IBMHEXFP" s390/ebcdic */
149   (double) -5.22995989424860458374e+10 };
152 if AC_TRY_EVAL(ac_compile); then
153 # dont match first and last letter because of rounding errors.
154 # next: big-endian - string is GROMACSX 
155   if   grep 'ROMACS' conftest.o >/dev/null 2>&1; then
156     acx_float_format='IEEE754 (big-endian byte and word order)'
157 # next: big-endian byte order, but little-endian word order - ACSXGROM
158   elif grep 'CSXGRO' conftest.o >/dev/null 2>&1; then
159     acx_float_format='IEEE754 (big-endian byte, little-endian word order)'
160 # next: little-endian - XSCAMORG
161   elif grep 'SCAMOR' conftest.o >/dev/null 2>&1; then
162     acx_float_format='IEEE754 (little-endian byte and word order)'
163 # next: little-endian byte order, but big-endian word order - MORGXSCA
164   elif grep 'ORGXSC' conftest.o >/dev/null 2>&1; then
165     acx_float_format='IEEE754 (big-endian byte, little-endian word order)'
166   elif grep '__floa' conftest.o >/dev/null 2>&1; then
167     acx_float_format='VAX D-float'
168   elif grep 'BMHEXF' conftest.o >/dev/null 2>&1; then
169     acx_float_format='IBM 370 hex'
170   else
171     AC_MSG_WARN([Unknown floating-point format])
172   fi
173 else
174   AC_MSG_ERROR(compile failed)
176 rm -rf conftest*])
177 case $acx_float_format in
178     'IEEE754 (big-endian byte and word order)' )
179        format=IEEE754
180        byteorder=big
181        wordorder=big            
182        ;;
183     'IEEE754 (little-endian byte and word order)' )
184        format=IEEE754
185        byteorder=little
186        wordorder=little
187        ;;
188     'IEEE754 (big-endian byte, little-endian word order)' )
189        format=IEEE754
190        byteorder=big
191        wordorder=little
192        ;;
193     'IEEE754 (litte-endian byte, big-endian word order)' )
194        format=IEEE754
195        byteorder=little
196        wordorder=big            
197        ;;
198     'VAX D-float' )
199        AC_DEFINE(FLOAT_FORMAT_VAX,,[VAX floating-point format if set])
200        ;;
201     'IBM 370 hex' )
202        AC_DEFINE(FLOAT_FORMAT_IBM_HEX,,[IBM HEX floating-point format if set (s390?)])
203        ;;   
204      * )
205        format=Unknown   
206        ;;
207 esac
208 if test "$format" = "IEEE754"; then
209        AC_DEFINE(FLOAT_FORMAT_IEEE754,,[IEEE754 floating-point format. Memory layout is defined by
210 macros IEEE754_BIG_ENDIAN_BYTE_ORDER and IEEE754_BIG_ENDIAN_WORD_ORDER.])
212 if test "$byteorder" = "big"; then
213   AC_DEFINE(IEEE754_BIG_ENDIAN_BYTE_ORDER,,[Bytes in IEEE fp word are in big-endian order if set,
214  little-endian if not. Only relevant when FLOAT_FORMAT_IEEE754 is defined.])
216 if test "$wordorder" = "big"; then
217   AC_DEFINE(IEEE754_BIG_ENDIAN_WORD_ORDER,,[The two words in a double precision variable are in b
218 ig-endian order if set, little-endian if not. Do NOT assume this is the same as the byte order! 
219 Only relevant when FLOAT_FORMAT_IEEE754 is defined.])
230 dnl AC_FIND_MOTIF : find OSF/Motif or LessTif, and provide variables
231 dnl     to easily use them in a Makefile.
233 dnl Adapted from a macro by Andreas Zeller.
235 dnl The variables provided are :
236 dnl     link_motif              (e.g. -L/usr/lesstif/lib -lXm -lXt)
237 dnl     include_motif           (e.g. -I/usr/lesstif/lib)
238 dnl     motif_libraries         (e.g. /usr/lesstif/lib)
239 dnl     motif_includes          (e.g. /usr/lesstif/include)
241 dnl The link_motif and include_motif variables should be fit to put on
242 dnl your application's link line in your Makefile.
244 AC_DEFUN([AC_FIND_MOTIF],
246 AC_REQUIRE([AC_PATH_XTRA])
248 motif_includes=
249 motif_libraries=
251 dnl AC_ARG_WITH(motif,
252 dnl [  --without-motif         do not use Motif widgets])
253 dnl Treat --without-motif like
254 dnl --without-motif-includes --without-motif-libraries.
256 if test "$no_x" = "yes"
257 then
258   motif_includes=no
259   motif_libraries=no
262 AC_ARG_WITH(motif-includes,
263 [  --with-motif-includes=DIR     Motif include files are in DIR],
264 motif_includes="$withval")
266 AC_ARG_WITH(motif-libraries,
267 [  --with-motif-libraries=DIR    Motif libraries are in DIR],
268 motif_libraries="$withval")
271 AC_MSG_CHECKING(for Motif)
275 # Search the include files.
277 if test "$motif_includes" = ""; then
278 AC_CACHE_VAL(ac_cv_motif_includes,
280 ac_motif_save_LIBS="$LIBS"
281 ac_motif_save_INCLUDES="$INCLUDES"
282 ac_motif_save_CPPFLAGS="$CPPFLAGS"
283 ac_motif_save_LDFLAGS="$LDFLAGS"
285 LIBS="$X_PRE_LIBS -lXm -lXt -lX11 $X_EXTRA_LIBS $LIBS"
286 INCLUDES="$X_CFLAGS $INCLUDES"
287 CPPFLAGS="$X_CFLAGS $CPPFLAGS"
288 LDFLAGS="$X_LIBS $LDFLAGS"
290 ac_cv_motif_includes="no"
291 AC_TRY_COMPILE([#include <Xm/Xm.h>],[int a;],
293 # Xm/Xm.h is in the standard search path.
294 ac_cv_motif_includes=
297 # Xm/Xm.h is not in the standard search path.
298 # Locate it and put its directory in `motif_includes'
300 # /usr/include/Motif* are used on HP-UX (Motif).
301 # /usr/include/X11* are used on HP-UX (X and Athena).
302 # /usr/dt is used on Solaris (Motif).
303 # /usr/openwin is used on Solaris (X and Athena).
304 # Other directories are just guesses.
305 for dir in "$x_includes" "${prefix}/include" /usr/include /usr/local/include \
306            /usr/include/Motif2.0 /usr/include/Motif1.2 /usr/include/Motif1.1 \
307            /usr/include/X11R6 /usr/include/X11R5 /usr/include/X11R4 \
308            /usr/dt/include /usr/openwin/include \
309            /usr/dt/*/include /opt/*/include /usr/include/Motif* \
310            "${prefix}"/*/include /usr/*/include /usr/local/*/include \
311            "${prefix}"/include/* /usr/include/* /usr/local/include/*; do
312 if test -f "$dir/Xm/Xm.h"; then
313 ac_cv_motif_includes="$dir"
314 break
316 done
319 LIBS="$ac_motif_save_LIBS"
320 INCLUDES="$ac_motif_save_INCLUDES"
321 CPPFLAGS="$ac_motif_save_CPPFLAGS"
322 LDFLAGS="$ac_motif_save_LDFLAGS"
324 motif_includes="$ac_cv_motif_includes"
328 # Now for the libraries.
330 if test "$motif_libraries" = ""; then
331 AC_CACHE_VAL(ac_cv_motif_libraries,
333 ac_motif_save_LIBS="$LIBS"
334 ac_motif_save_INCLUDES="$INCLUDES"
335 ac_motif_save_CPPFLAGS="$CPPFLAGS"
336 ac_motif_save_LDFLAGS="$LDFLAGS"
338 LIBS="$X_PRE_LIBS -lXm -lXt -lX11 $X_EXTRA_LIBS $LIBS"
339 INCLUDES="$X_CFLAGS $INCLUDES"
340 CPPFLAGS="$X_CFLAGS $CPPFLAGS"
341 LDFLAGS="$X_LIBS $LDFLAGS"
343 ac_cv_motif_libraries="no"
344 AC_TRY_LINK([#include <Xm/Xm.h>],[XtToolkitInitialize();],
346 # libXm.a is in the standard search path.
347 ac_cv_motif_libraries=
350 # libXm.a is not in the standard search path.
351 # Locate it and put its directory in `motif_libraries'
353 # /usr/lib/Motif* are used on HP-UX (Motif).
354 # /usr/lib/X11* are used on HP-UX (X and Athena).
355 # /usr/dt is used on Solaris (Motif).
356 # /usr/lesstif is used on Linux (Lesstif).
357 # /usr/openwin is used on Solaris (X and Athena).
358 # Other directories are just guesses.
359 for dir in "$x_libraries" "${prefix}/lib" /usr/lib /usr/local/lib \
360            /usr/lib/Motif2.0 /usr/lib/Motif1.2 /usr/lib/Motif1.1 \
361            /usr/lib/X11R6 /usr/lib/X11R5 /usr/lib/X11R4 /usr/lib/X11 \
362            /usr/dt/lib /usr/openwin/lib \
363            /usr/dt/*/lib /opt/*/lib /usr/lib/Motif* \
364            /usr/lesstif*/lib /usr/lib/Lesstif* \
365            "${prefix}"/*/lib /usr/*/lib /usr/local/*/lib \
366            "${prefix}"/lib/* /usr/lib/* /usr/local/lib/*; do
367 if test -d "$dir" && test "`ls $dir/libXm.* 2> /dev/null`" != ""; then
368 ac_cv_motif_libraries="$dir"
369 break
371 done
374 LIBS="$ac_motif_save_LIBS"
375 INCLUDES="$ac_motif_save_INCLUDES"
376 CPPFLAGS="$ac_motif_save_CPPFLAGS"
377 LDFLAGS="$ac_motif_save_LDFLAGS"
380 motif_libraries="$ac_cv_motif_libraries"
383 # Provide an easier way to link
385 if test "$motif_includes" = "no" -o "$motif_libraries" = "no"; then
386         with_motif="no"
387 else
388         with_motif="yes"
391 if test "$with_motif" != "no"; then
392         if test "$motif_libraries" = ""; then
393                 link_motif="-lXm -lXt"
394                 MOTIF_LIBS="-lXm -lXt"
395         else
396                 link_motif="-L$motif_libraries -lXm -lXt"
397                 MOTIF_LIBS="-L$motif_libraries -lXm -lXt"
398         fi
399         if test "$motif_includes" != ""; then
400                 include_motif="-I$motif_includes"
401                 MOTIF_INCLUDES="-I$motif_includes"
402         fi
403         LIBS="$LIBS $MOTIF_LIBS"
404         INCLUDES="$INCLUDES $MOTIF_INCLUDES"
405         AC_DEFINE(HAVE_MOTIF,,[Use motif/lesstif libraries])
406 else
407         with_motif="no"
413 motif_libraries_result="$motif_libraries"
414 motif_includes_result="$motif_includes"
415 test "$motif_libraries_result" = "" && motif_libraries_result="in default path"
416 test "$motif_includes_result" = "" && motif_includes_result="in default path"
417 test "$motif_libraries_result" = "no" && motif_libraries_result="(none)"
418 test "$motif_includes_result" = "no" && motif_includes_result="(none)"
419 AC_MSG_RESULT([libraries $motif_libraries_result, headers $motif_includes_result])
420         
421 # seems as if Xm depends on -lXext and/or -lXp on old redhat and OS X. 
422 ac_motif_save_LIBS="$LIBS"
423 ac_motif_save_INCLUDES="$INCLUDES"
424 ac_motif_save_CPPFLAGS="$CPPFLAGS"
425 ac_motif_save_LDFLAGS="$LDFLAGS"
426 CPPFLAGS="$CPPFLAGS $X_CFLAGS"
427 INCLUDE="$INCLUDE $X_CFLAGS"
428 LDFLAGS="$X_LIBS $LDFLAGS"
429 # first try both - they are crossdependent! urk...
430 LIBS="$X_PRE_LIBS -lX11 $X_EXTRA_LIBS $ac_motif_save_LIBS -lXext -lXp"
431 AC_MSG_CHECKING(for libXext and libXp)
432 AC_TRY_LINK([#include <Xm/Xm.h>],[XtToolkitInitialize();],
433   [AC_MSG_RESULT(yes)
434    X_PRE_LIBS="$X_PRE_LIBS -lXext -lXp"],[
435    AC_MSG_RESULT(no)
436    # both libs didnt work, try libXext separately
437    LIBS="$X_PRE_LIBS -lX11 $X_EXTRA_LIBS $ac_motif_save_LIBS -lXext"
438    AC_MSG_CHECKING(for only libXext)
439    AC_TRY_LINK([#include <Xm/Xm.h>],[XtToolkitInitialize();],
440   [AC_MSG_RESULT(yes)
441   X_PRE_LIBS="$X_PRE_LIBS -lXext"],[AC_MSG_RESULT(no)])
442   ])
443 LIBS=$ac_motif_save_LIBS
444 INCLUDES="$ac_motif_save_INCLUDES"
445 CPPFLAGS=$ac_motif_save_CPPFLAGS
446 LDFLAGS="$ac_motif_save_LDFLAGS"
447 ])dnl
450 dnl macro modified from the fftw distribution (www.fftw.org)
451 AC_DEFUN([ACX_CHECK_CC_FLAGS],
453 AC_REQUIRE([AC_PROG_CC])
454 AC_CACHE_CHECK(whether $CC accepts $1, ac_$2,
455 [echo 'void f(){}' > conftest.c
456 res=`$CC $1 -c conftest.c 2>&1`
458 # The stupid intel compiler echos the filename on stderr...
460 if test -z "$res" -o "$res" = "conftest.c:"; then
461         ac_$2=yes
462 else
463         ac_$2=no
465 rm -rf conftest*
467 if test "$ac_$2" = yes; then
468         :
469         $3
470 else
471         :
472         $4
476 dnl macro modified from the fftw distribution (www.fftw.org)
477 AC_DEFUN([ACX_CHECK_F77_FLAGS],
479 AC_REQUIRE([AC_PROG_F77])
480 AC_CACHE_CHECK(whether $F77 accepts $1, ac_$2,
481 [cat > conftest.f << EOF
482       subroutine f
483       return 
484       end
486 if test -z "`$F77 $1 -c conftest.f `"; then
487         ac_$2=yes
488 else
489         ac_$2=no
491 rm -rf conftest*
493 if test "$ac_$2" = yes; then
494         :
495         $3
496 else
497         :
498         $4
503 # ACX_DETECT_GMXCPU
504 # ---------------------------
505 # Macro to extend the exact CPU for some hosts
506 AC_DEFUN([ACX_DETECT_GMXCPU],
508 AC_REQUIRE([AC_CANONICAL_HOST])
511 # Determine the exact cpu type on some common systems where it is 
512 # not visible from the host triplet.
513 # (on e.g. intel and dec/tru64 the host type is enough)
515 gmxcpu="";
517 case "${host_cpu}-${host_os}" in
519 *-aix*)
520   # some versions of config.status says these systems are PowerPC even
521   # when they have Power3 CPUs (they used to be recognized as rs6000), 
522   # so we need to work around that.
523   # 
524   # we need to fool the combination of m4, sh and awk - thus the seemingly unnecessary n
525   if test -f /usr/sbin/lsdev && test -f /usr/sbin/lsattr; then
526     IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | head -1 | awk '{ n=1; print $n }'`
527     if /usr/sbin/lsattr -EHl ${IBM_CPU_ID} | grep POWER5 >/dev/null 2>&1; then
528       gmxcpu=power5
529     elif /usr/sbin/lsattr -EHl ${IBM_CPU_ID} | grep POWER4 >/dev/null 2>&1; then
530       gmxcpu=power4
531     elif /usr/sbin/lsattr -EHl ${IBM_CPU_ID} | grep POWER3 >/dev/null 2>&1; then
532       gmxcpu=power3
533     elif /usr/sbin/lsattr -EHl ${IBM_CPU_ID} | grep POWER2 >/dev/null 2>&1; then
534       gmxcpu=power2
535     fi
536   fi
537   if test -z "${gmxcpu}" && test -f /usr/sbin/lscfg; then
538     if /usr/sbin/lscfg -vp | grep PowerPC | grep 604 >/dev/null 2>&1; then
539       gmxcpu=ppc604
540     elif /usr/sbin/lscfg -vp | grep PowerPC | grep 603 >/dev/null 2>&1; then
541       gmxcpu=ppc603
542     elif /usr/sbin/lscfg -vp | grep PowerPC | grep rs64a >/dev/null 2>&1; then
543       gmxcpu=rs64a
544     elif /usr/sbin/lscfg -vp | grep PowerPC | grep rs64b >/dev/null 2>&1; then
545       gmxcpu=rs64b
546     elif /usr/sbin/lscfg -vp | grep PowerPC | grep rs64c >/dev/null 2>&1; then
547       gmxcpu=rs64c
548     elif /usr/sbin/lscfg -vp | grep POWER2 >/dev/null 2>&1; then
549       gmxcpu=power2
550     elif /usr/sbin/lscfg -vp | grep POWER3 >/dev/null 2>&1; then
551       gmxcpu=power3
552     elif /usr/sbin/lscfg -vp | grep POWER4 >/dev/null 2>&1; then
553       gmxcpu=power4
554     fi
555   fi
556   ;;
558 mips*-irix*)
559   if /sbin/hinv | grep CPU | grep R12000 >/dev/null 2>&1; then
560     gmxcpu=r12000
561   elif /sbin/hinv | grep CPU | grep R10000 >/dev/null 2>&1; then
562     gmxcpu=r10000
563   elif /sbin/hinv | grep CPU | grep R8000 >/dev/null 2>&1; then
564     gmxcpu=r8000
565   elif /sbin/hinv | grep CPU | grep R5000 >/dev/null 2>&1; then
566     gmxcpu=r5000
567   else
568     gmxcpu=""
569   fi
570   ;;
572 sparc*-solaris*)
573   if /usr/sbin/prtconf | grep UltraSPARC-III >/dev/null 2>&1; then
574     gmxcpu=ultrasparc3
575   elif /usr/sbin/prtconf | grep UltraSPARC-IIi >/dev/null 2>&1; then
576     gmxcpu=ultrasparc2i
577   elif /usr/sbin/prtconf | grep UltraSPARC-II >/dev/null 2>&1; then
578     gmxcpu=ultrasparc2
579   elif /usr/sbin/prtconf | grep UltraSPARC >/dev/null 2>&1; then
580     gmxcpu=ultrasparc
581   else
582     gmxcpu=""
583   fi
584   ;;
586   gmxcpu=""
587   ;;
589 esac
594 ###############################################################
595 # Macro modified from the fftw distribution (www.fftw.org)
596 # to determine optimization flags.
597 # Note that we have modified config.guess and config.sub
598 # to provide extended information on the detailed type of CPU.
599 # In general we assume you have recent versions of the compilers
600 # that support the highest optimization we know of. If not, you 
601 # can always override these flags, but it's better to upgrade :-)
602 ###############################################################
603 AC_DEFUN([ACX_COMPILER_MAXOPT],
605 AC_REQUIRE([AC_PROG_CC])
606 AC_REQUIRE([AC_PROG_F77])
607 AC_REQUIRE([AC_CANONICAL_HOST])
609 # Try to determine "good" native compiler flags if none specified on command
610 # line. To avoid repeating the entire procedure for fortran flags, we first
611 # determine our suggested choices for both C and fortran, and then possibly
612 # override them with user choices.
614 cc_vendor="unknown"
616 case "${host_cpu}-${host_os}" in
618   *-solaris2*) 
619     case "${gmxcpu}" in
620       ultrasparc3*)
621         xCFLAGS="-fast -xO5 -xtarget=ultra3 -fsimple=2 -fnonstd -dalign"
622         xFFLAGS=$xCFLAGS
623         ;;
624       ultrasparc2i*)
625         xCFLAGS="-fast -xO5 -xtarget=ultra2i -fsimple=2 -fnonstd -dalign"
626         xFFLAGS=$xCFLAGS
627         ;;
628       ultrasparc2*)
629         xCFLAGS="-fast -xO5 -xtarget=ultra2 -fsimple=2 -fnonstd -dalign"
630         xFFLAGS=$xCFLAGS
631         ;;
632       ultrasparc*)
633         xCFLAGS="-fast -xO5 -xtarget=ultra -fsimple=2 -fnonstd -dalign"
634         xFFLAGS=$xCFLAGS
635         ;;
636       *)
637         xCFLAGS="-native -fast -xO5 -fsimple=2 -fnonstd -dalign"
638         xFFLAGS=$xCFLAGS
639         ;;
640     esac
641     ;;
643   *-hpux*)  
644     xCFLAGS="-Ae +O3 +Oall"
645     xFFLAGS=$xCFLAGS
646     # If you haven't noticed, we don't like hp very much...
647     # but perhaps that will change if they make something nice out of ia64.
648     ;;
650   ia64*-*)
651     # The GNU compilers are checked outside this case statement.
652     # Check for Intel Compilers. The SGI one was killed before
653     # it went final, so I cant imagine anyone is using it...
655     # Apparently, -O2 is better than -O3 for villin at least,
656     # but I have not yet had time to test all the other benchmarks
657     # on both optimization levels. Might need further tweaking.
659     # The Intel compilers are _really_ chatty when it comes to
660     # warnings, and also echo a lot of incomprehensible internal
661     # stuff (not gromacs-related) when we are using ia64 assembly.
662     # For this reason we disable warnings...
664    if $CC -V 2>&1 | grep 'Intel' > /dev/null 2>&1; then
665      xCFLAGS="-O3 -w"
666      xASFLAGS=$xCFLAGS
667      ac_cv_prog_gcc="no"        
668    fi  
669    if $F77 -V 2>&1 | grep 'Intel' > /dev/null 2>&1; then
670      xFFLAGS="-O3 -w90 -w95 -w"
671      ac_cv_prog_g77="no"
672    fi  
673    # PORTME 2. Check for intel compilers when we get our hands on one!
674    ;;   
675   *-aix*)
676     # dont use inter-procedure analysis for the innerloops - they take
677     # forever to compile with it, and it doesnt help at all.
679     # use 8 segments (max 2Gb) instead of 1 (max 256Meg) by default.
680     xLDFLAGS="$xLDFLAGS -bmaxdata:0x80000000"
681     case "${gmxcpu}" in
682       power5*)
683         xCFLAGS="-O3 -qarch=pwr5 -qtune=pwr5 -qmaxmem=16384"
684         xFFLAGS="-O3 -Q -qarch=pwr5 -qtune=pwr5 -qmaxmem=16384 -qhot -qnoipa"
685         ;;
686       power4*)
687         xCFLAGS="-O3 -qarch=pwr4 -qtune=pwr4 -qmaxmem=16384"
688         xFFLAGS="-O3 -Q -qarch=pwr4 -qtune=pwr4 -qmaxmem=16384 -qhot -qnoipa"
689         ;;
690       power3*)
691         xCFLAGS="-O3 -qarch=pwr3 -qtune=pwr3 -qmaxmem=16384"
692         xFFLAGS="-O3 -Q -qarch=pwr3 -qtune=pwr3 -qmaxmem=16384 -qhot -qnoipa"
693         ;;
694       power2*)
695         xCFLAGS="-O3 -qarch=pwr2 -qtune=pwr2 -qmaxmem=16384"
696         xFFLAGS="-O3 -Q -qarch=pwr2 -qtune=pwr2 -qmaxmem=16384 -qhot -qnoipa"
697         ;;
698       power)
699         xCFLAGS="-O3 -qarch=pwr -qtune=pwr -qmaxmem=16384"
700         xFFLAGS="-O3 -Q -qarch=pwr -qtune=pwr -qmaxmem=16384 -qhot -qnoipa"
701         ;;
702       ppc604)
703         xCFLAGS="-O3 -qarch=604 -qtune=604 -qmaxmem=16384"
704         xFFLAGS="-O3 -Q -qarch=604 -qtune=604 -qmaxmem=16384 -qhot"
705         ;;
706       ppc603)
707         xCFLAGS="-O3 -qarch=603 -qtune=603 -qmaxmem=16384"
708         xFFLAGS="-O3 -Q -qarch=603 -qtune=603 -qmaxmem=16384 -qhot"
709         ;;
710       rs64a)
711         xCFLAGS="-O3 -qarch=rs64a -qtune=rs64a -qmaxmem=16384"
712         xFFLAGS="-O3 -Q -qarch=rs64a -qtune=rs64a -qmaxmem=16384 -qhot"
713         ;;
714       rs64b)
715         xCFLAGS="-O3 -qarch=rs64b -qtune=rs64b -qmaxmem=16384"
716         xFFLAGS="-O3 -Q -qarch=rs64b -qtune=rs64b -qmaxmem=16384 -qhot"
717         ;;
718       rs64c)
719         xCFLAGS="-O3 -qarch=rs64c -qtune=rs64c -qmaxmem=16384"
720         xFFLAGS="-O3 -Q -qarch=rs64c -qtune=rs64c -qmaxmem=16384 -qhot"
721         ;;
722       *)
723         xCFLAGS="-O3 -qmaxmem=16384"
724         xFFLAGS="-O3 -Q -qmaxmem=16384 -qhot"
725         ;;
726     esac
727     ;;
729   powerpc*-darwin* | powerpc*-linux* )
730     # Check for IBM compilers on OS X     
731     if $CC 2>&1 | grep 'IBM' > /dev/null 2>&1; then
732        xCFLAGS="-O4 -Q=500 -qaltivec -qnoipa"
733     fi
734     if $F77 -V 2>&1 | grep 'IBM' > /dev/null 2>&1; then
735       xFFLAGS="-O4 -Q=500 -qnoipa"
736     fi
737     ;;
739   mips*-irix*)
740     xCFLAGS="-O3 -OPT:IEEE_arithmetic=3 -OPT:rsqrt=ON -SWP:loop_overhead -INLINE:=ON -LNO:opt=1 -LNO:ou_further=3 -OPT:Olimit=0:roundoff=3:alias=typed -woff 1174 -D__INLINE_INTRINSICS"
741     xFFLAGS="-O3 -OPT:IEEE_arithmetic=3 -OPT:rsqrt=ON -SWP:loop_overhead -INLINE:=ON -LNO:opt=1 -LNO:ou_further=3 -OPT:Olimit=0:roundoff=3:alias=typed -OPT:cray_ivdep=TRUE"
742     
743     if $CC -version | grep "Version 7.1" > /dev/null 2>&1; then
744       xCFLAGS="$xCFLAGS -GCM:aggressive_speculation -GCM:array_speculation" 
745       xFFLAGS="$xFFLAGS -GCM:aggressive_speculation -GCM:array_speculation" 
746     fi
748     if $CC -version | grep "Version 7.3" > /dev/null 2>&1; then
749       xCFLAGS="$xCFLAGS -SWP:heur=fdms,nhms,fdnms" 
750       xFFLAGS="$xFFLAGS -SWP:heur=fdms,nhms,fdnms" 
751     fi
752     xLDFLAGS="-woff 84"
754     # I have removed -n32 from the flags since it causes too many problems.
755     # New SGIs should use the right objects automatically, and it's not
756     # worth the hassle for 5-10 year old machines...  
758     case "${gmxcpu}" in
759       r12000*)
760         xCFLAGS="$IRIXOBJFLAG -r12000 -mips4 $xCFLAGS"
761         xFFLAGS="$IRIXOBJFLAG -r12000 -mips4 $xFFLAGS"
762         xLDFLAGS="$IRIXOBJFLAG -r12000 -mips4 $xLDFLAGS"
763         ;;
764       r10000*)
765         xCFLAGS="$IRIXOBJFLAG -r10000 -mips4 $xCFLAGS"
766         xFFLAGS="$IRIXOBJFLAG -r10000 -mips4 $xFFLAGS"
767         xLDFLAGS="$IRIXOBJFLAG -r10000 -mips4 $xLDFLAGS"
768         ;;
769       r8000*)
770         xCFLAGS="$IRIXOBJFLAG -r8000 -mips4 $xCFLAGS"
771         xFFLAGS="$IRIXOBJFLAG -r8000 -mips4 $xFFLAGS"
772         xLDFLAGS="$IRIXOBJFLAG -r8000 -mips4 $xLDFLAGS"
773         ;;
774       r5000*)
775         xCFLAGS="$IRIXOBJFLAG -r5000 -mips4 $xCFLAGS"
776         xFFLAGS="$IRIXOBJFLAG -r5000 -mips4 $xFFLAGS"
777         xLDFLAGS="$IRIXOBJFLAG -r5000 -mips4 $xLDFLAGS"
778         ;;
779       *)                
780         xCFLAGS="$IRIXOBJFLAG $xCFLAGS"
781         xFFLAGS="$IRIXOBJFLAG $xFFLAGS"
782         xLDFLAGS="$IRIXOBJFLAG $xLDFLAGS"
783         ;;
784     esac
785     ;;
787   alpha*-osf*) 
788      # NB: -arch implies -tune according to the cc manual.
789      # We dont use -ifo since it conflicts with dependency
790      # generation on old versions of the compiler.
791     case "${host_cpu}" in
792       alphaev*)
793         # extract the processor from cpu type (e.g. alphaev56 -> ev56)
794         evtype=`echo ${host_cpu} | sed 's/alpha//'`
795         xCFLAGS="-std1 -fast -O4 -no_ifo -arch $evtype -unroll 2 -fp_reorder"
796         xFFLAGS="$xCFLAGS -assume noaccuracy_sensitive"
797         xASFLAGS="-O4 -no_ifo -arch $evtype"
798         xLDFLAGS="-O4"
799         ;;
800       *)
801         xCFLAGS="-std1 -fast -O4 -no_ifo -arch host -unroll 2 -fp_reorder"
802         xFFLAGS="$xCFLAGS -assume noaccuracy_sensitive"
803         xASFLAGS="-O4 -no_ifo -arch host"
804         xLDFLAGS="-O4"
805         ;;
806     esac
807     ;;
809   alpha*-linux*)
810     case "${host_cpu}" in
811       alphaev*)
812         # extract the processor from cpu type (e.g. alphaev56 -> ev56)
813         evtype=`echo ${host_cpu} | sed 's/alpha//'`
814         tmpCFLAGS="-std1 -fast -O4 -no_ifo -arch $evtype -unroll 2 -fp_reorder"
815         tmpFFLAGS="$tmpCFLAGS -assume noaccuracy_sensitive"
816         tmpASFLAGS="-O4 -no_ifo -arch $evtype"
817         tmpLDFLAGS="-O4"
818         ;;
819       *)
820         tmpCFLAGS="-std1 -fast -O4 -no_ifo -arch host -unroll 2 -fp_reorder"
821         tmpFFLAGS="$tmpCFLAGS -assume noaccuracy_sensitive"
822         tmpASFLAGS="-O4 -no_ifo -arch host"
823         tmpLDFLAGS="-O4"
824         ;;
825     esac
826         # Compaq sometimes uses -version and sometimes -V
827         # Not 100% sure if ccc always has -V and F77 -version, so 
828         # we check both alternatives to be sure.
829     if (($CC -V 2>&1 | grep ompaq > /dev/null) || 
830         ($CC -version 2>&1 | grep ompaq > /dev/null)); then
831       xCFLAGS="$tmpCFLAGS"
832       xASFLAGS="$tmpASFLAGS"
833       cc_vendor="Compaq"
834     fi
835     if test "$enable_fortran" = "yes"; then
836       if (($F77 -V 2>&1 | grep ompaq > /dev/null) || 
837           ($F77 -version 2>&1 | grep ompaq > /dev/null)); then
838         xFFLAGS="$tmpFFLAGS"
839       fi
840     fi
841     ;;
843   *-*)
844     # most of these systems (e.g. linux, FreeBSD) use gcc which is treated
845     # further down, but check for some specific compilers.
846     # Portland group compilers:
847     if $CC -V 2>  /dev/null | grep ortland > /dev/null 2>&1; then
848       case "${host_cpu}" in
849         i586)
850           pgiopt="-tp p5" 
851           ;;
852         i686)
853           pgiopt="-tp p6" 
854           ;;
855       esac
856       xCFLAGS="$pgiopt -fast -pc 32"
857       xASFLAGS="$xCFLAGS"
858     fi
859     if test "$enable_fortran" = "yes"; then
860       if $F77 -version 2>  /dev/null | grep Portland > /dev/null 2>&1; then
861         xFFLAGS="$xCFLAGS"
862       fi        
863     fi
865     # Intel compilers
866     # The Intel compilers are _really_ chatty when it comes to
867     # warnings, and also echo a lot of incomprehensible internal
868     # stuff (not gromacs-related) when we are using assembly.
869     # For this reason we disable warnings...
871     if $CC -V 2>&1 | grep 'Intel' > /dev/null 2>&1; then
872       ac_cv_prog_gcc="no"       
873       case "${host_cpu}" in
874         x86_64)
875           xCFLAGS="-O3 -tpp7 -axW -ip -w"
876           ;;
877         i686)
878           xCFLAGS="-O3 -tpp6 -axK -ip -w" 
879           ;;
880         ia64)
881           xCFLAGS="-O3 -ip -w" 
882           ;;
883       esac
884       xASFLAGS="$xCFLAGS"
885       # search in /usr/local/include too, just as gcc does. (handy for fftw)
886       CPPFLAGS="$CPPFLAGS -I/usr/local/include"
887     fi
888     if test "$enable_fortran" = "yes"; then
889       if $F77 -V 2>&1 | grep 'Intel' > /dev/null 2>&1; then
890         ac_cv_prog_g77="no"
891         xFFLAGS="$xCFLAGS -w90 -w95"
892       fi        
893     fi
894         
895     ;;
896 esac    
897 # Phew, end of all those operating systems and processors!                      
899 # use default flags for gcc/g77 on all systems
900 if test $ac_cv_prog_gcc = yes; then
901   ACX_CHECK_CC_FLAGS(-O3,o3,xCFLAGS="$xCFLAGS -O3")
902   xCFLAGS="$xCFLAGS -fomit-frame-pointer -finline-functions -Wall -Wno-unused"
903   # For alpha axp assembly we need the preprocessor to tell elf from ecoff.
904   # The compaq ccc compiler only knows .s files, and always runs them
905   # through cpp. We support this by telling gcc to preprocess .s files.
906   case "${host_cpu}" in
907     alphaev*)
908       xASFLAGS="$xCFLAGS -x assembler-with-cpp"
909       ;;
910     *)
911       ;;
912   esac
913   # -malign-double for x86 systems
914   ACX_CHECK_CC_FLAGS(-malign-double,align_double,xCFLAGS="$xCFLAGS -malign-double")
916   
917 if test $enable_fortran = yes; then
918   if test $ac_cv_prog_g77 = yes; then
919     xFFLAGS="-O3 -ffast-math -fomit-frame-pointer -finline-functions -funroll-all-loops -Wall -Wno-unused"
920     # -malign-double for f77 on x86 systems - haven't checked that this works yet.
921     #ACX_CHECK_F77_FLAGS(-malign-double,align_double,xFFLAGS="$xFFLAGS -malign-double")
922   fi
925 CPU_FLAGS=""
927 if test "$GCC" = "yes"; then
928   # try to guess correct CPU flags, at least for powerpc linux
929   case "${host_cpu}" in
930     # i586/i686 cpu flags don't improve speed, thus no need to use them.
931     # don't check f77 separately - we assume f77 and gcc are similar      
932     powerpc*)
933         # don't use the separate apple cpp on OS X
934 #        ACX_CHECK_CC_FLAGS(-no-cpp-precomp,no_cpp_precomp,xCFLAGS="$xCFLAGS -no-cpp-precomp")
935         if test "$enable_ppc_altivec" = "yes"; then
936             # Apple (darwin) uses a hacked version of gcc with special flags 
937             case "${host_os}" in
938             darwin*)                            
939                 ACX_CHECK_CC_FLAGS(-faltivec,faltivec,xCFLAGS="$xCFLAGS -faltivec")
940                 ;;
941             *)
942                 # Need to update CPPFLAGS too, since we later call 
943                 # AC_CHECK_HEADER for altivec.h, and then autoconf complains
944                 # if it cannot process it with the preprocessor.
945                 ACX_CHECK_CC_FLAGS(-maltivec,maltivec,xCFLAGS="$xCFLAGS -maltivec" CPPFLAGS="$CPPFLAGS -maltivec")
946                 ACX_CHECK_CC_FLAGS(-mabi=altivec,mabialtivec,xCFLAGS="$xCFLAGS -mabi=altivec" CPPFLAGS="$CPPFLAGS -mabi=altivec")
947                 ;;
948             esac 
949         fi
950         # -funroll-all-loops exposes a bug in altivec-enabled gcc-2.95.3
951         # on powerpc, so we only enable it on other platforms or gcc3.    
952         # The gcc 2.95 instruction scheduler also destroys our handcoded altivec,
953         # so disable instruction scheduling on 2.95
954         if $CC --version 2>&1 | grep '2.95' > /dev/null 2>&1; then
955           echo "*****************************************************************************"
956           echo "* IMPORTANT INFO: You are using gcc-2.95.x on PowerPC. This compiler works, *"
957           echo "* but you will get better performance with gcc-3.3 or later. If you are     *"
958           echo "* running OS X, download the latest devtools from http://developer.apple.com*"
959           echo "*****************************************************************************"
960           ACX_CHECK_CC_FLAGS(-fno-schedule-insns,fno_schedule_insns,xCFLAGS="$xCFLAGS -fno-schedule-insns")
961         fi
962         ACX_CHECK_CC_FLAGS(-mcpu=7450,m_cpu_7450,CPU_FLAGS="-mcpu=7450")
963         ACX_CHECK_CC_FLAGS(-mtune=970,m_tune_970,CPU_FLAGS="$CPU_FLAGS -mtune=970")
964         if test -z "$CPU_FLAGS"; then
965           ACX_CHECK_CC_FLAGS(-mcpu=powerpc,m_cpu_powerpc,CPU_FLAGS="-mcpu=powerpc")
966         fi      
967       ;;
968    *)
969         ACX_CHECK_CC_FLAGS(-funroll-all-loops,funroll_all_loops,xCFLAGS="$xCFLAGS -funroll-all-loops")
970       ;;
971    esac
974 if test -n "$CPU_FLAGS"; then
975   xCFLAGS="$xCFLAGS $CPU_FLAGS"
976   xFFLAGS="$xFFLAGS $CPU_FLAGS"
977   xASFLAGS="$xASFLAGS $CPU_FLAGS"
980 # Now check if the user provided anything special for C or fortran...
981 # Not nice to have checked everything then, but otherwise we would have
982 # to use entirely separate checks for C and fortran flags, doubling the code.
983 if test "$ac_test_CFLAGS" != "set"; then
984   CFLAGS="$xCFLAGS"
985   # Use the extra link optimization flags on e.g. irix only when
986   # we are using our own C compiler flags
987   LDFLAGS="$LDFLAGS $xLDFLAGS"
988   
989   if test -z "$CFLAGS"; then
990     echo "********************************************************************"
991     echo "* Note: We have not optimized the C compiler flags on your target  *"
992     echo "* yet, but the default CFLAGS=-O3 should be OK in most cases.      *"
993     echo "* You can override this by setting the CFLAGS environment variable.*"
994     echo "*******************************************************************"
995     CFLAGS="-O3"
996   fi
997   ACX_CHECK_CC_FLAGS(${CFLAGS}, guessed_cflags, , [
998     echo "*******************************************************************"
999     echo "* Sorry, these optimization settings don't seem to work for       *"
1000     echo "* your C compiler. Use make CFLAGS=..., or edit the top Makefile. *"
1001     echo "*******************************************************************"
1002     CFLAGS=""
1003   ])
1004 else
1005   echo "******************************************"
1006   echo "* Using CFLAGS from environment variable *"
1007   echo "******************************************"
1010 if test "$enable_fortran" = "yes"; then 
1011   if test "$ac_test_FFLAGS" != "set"; then
1012     FFLAGS="$xFFLAGS"
1013     if test -z "$FFLAGS"; then
1014     echo "********************************************************************"
1015     echo "* Note: We have not optimized the Fortran compiler flags on your   *"
1016     echo "* target, but the default FFLAGS=-O3 should be OK in most cases.   *"
1017     echo "* You can override this by setting the CFLAGS environment variable.*"
1018     echo "********************************************************************"
1019       FFLAGS="-O3"
1020     fi
1021     ACX_CHECK_F77_FLAGS(${FFLAGS}, guessed_fflags, , [
1022       echo "*******************************************************************"
1023       echo "* Sorry, these optimization settings don't seem to work for       *"
1024       echo "* your f77 compiler. Use make FFLAGS=.., or edit the top Makefile.*"
1025       echo "*******************************************************************"
1026       FFLAGS=""
1027     ])
1028   else
1029     echo "******************************************"
1030     echo "* Using FFLAGS from environment variable *"
1031     echo "******************************************"
1032   fi
1034 # Be silent for assembly flags, they are usually not important anyway
1035 if test "${ASFLAGS+set}" != set; then
1036   if test "${xASFLAGS+set}" != set; then
1037     xASFLAGS="$CFLAGS"
1038   fi
1039   ASFLAGS="$xASFLAGS"
1045 dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
1047 dnl This macro figures out how to build C programs using POSIX
1048 dnl threads. It sets the PTHREAD_LIBS output variable to the threads
1049 dnl library and linker flags, and the PTHREAD_CFLAGS output variable
1050 dnl to any special C compiler flags that are needed. (The user can also
1051 dnl force certain compiler flags/libs to be tested by setting these
1052 dnl environment variables.)
1054 dnl Also sets PTHREAD_CC to any special C compiler that is needed for
1055 dnl multi-threaded programs (defaults to the value of CC otherwise).
1056 dnl (This is necessary on AIX to use the special cc_r compiler alias.)
1058 dnl If you are only building threads programs, you may wish to
1059 dnl use these variables in your default LIBS, CFLAGS, and CC:
1061 dnl LIBS="$PTHREAD_LIBS $LIBS"
1062 dnl CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
1063 dnl CC="$PTHREAD_CC"
1065 dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute
1066 dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE
1067 dnl to that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
1069 dnl ACTION-IF-FOUND is a list of shell commands to run if a threads
1070 dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands
1071 dnl to run it if it is not found. If ACTION-IF-FOUND is not specified,
1072 dnl the default action will define HAVE_PTHREAD.
1074 dnl Please let the authors know if this macro fails on any platform,
1075 dnl or if you have any other suggestions or comments. This macro was
1076 dnl based on work by SGJ on autoconf scripts for FFTW (www.fftw.org)
1077 dnl (with help from M. Frigo), as well as ac_pthread and hb_pthread
1078 dnl macros posted by AFC to the autoconf macro repository. We are also
1079 dnl grateful for the helpful feedback of numerous users.
1081 dnl @version $Id$
1082 dnl @author Steven G. Johnson <stevenj@alum.mit.edu> and Alejandro Forero Cuervo <bachue@bachue.com>
1084 AC_DEFUN([ACX_PTHREAD], [
1085 AC_REQUIRE([AC_CANONICAL_HOST])
1086 AC_LANG_SAVE
1087 AC_LANG_C
1088 acx_pthread_ok=no
1090 # We used to check for pthread.h first, but this fails if pthread.h
1091 # requires special compiler flags (e.g. on True64 or Sequent).
1092 # It gets checked for in the link test anyway.
1094 # First of all, check if the user has set any of the PTHREAD_LIBS,
1095 # etcetera environment variables, and if threads linking works using
1096 # them:
1097 if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
1098         save_CFLAGS="$CFLAGS"
1099         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
1100         save_LIBS="$LIBS"
1101         LIBS="$PTHREAD_LIBS $LIBS"
1102         AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
1103         AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
1104         AC_MSG_RESULT($acx_pthread_ok)
1105         if test x"$acx_pthread_ok" = xno; then
1106                 PTHREAD_LIBS=""
1107                 PTHREAD_CFLAGS=""
1108         fi
1109         LIBS="$save_LIBS"
1110         CFLAGS="$save_CFLAGS"
1113 # We must check for the threads library under a number of different
1114 # names; the ordering is very important because some systems
1115 # (e.g. DEC) have both -lpthread and -lpthreads, where one of the
1116 # libraries is broken (non-POSIX).
1118 # Create a list of thread flags to try. Items starting with a "-" are
1119 # C compiler flags, and other items are library names, except for "none"
1120 # which indicates that we try without any flags at all.
1122 acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt"
1124 # The ordering *is* (sometimes) important. Some notes on the
1125 # individual items follow:
1127 # pthreads: AIX (must check this before -lpthread)
1128 # none: in case threads are in libc; should be tried before -Kthread and
1129 # other compiler flags to prevent continual compiler warnings
1130 # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
1131 # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
1132 # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
1133 # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
1134 # -pthreads: Solaris/gcc
1135 # -mthreads: Mingw32/gcc, Lynx/gcc
1136 # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
1137 # doesn't hurt to check since this sometimes defines pthreads too;
1138 # also defines -D_REENTRANT)
1139 # pthread: Linux, etcetera
1140 # --thread-safe: KAI C++
1142 case "${host_cpu}-${host_os}" in
1143         *solaris*)
1145         # On Solaris (at least, for some versions), libc contains stubbed
1146         # (non-functional) versions of the pthreads routines, so link-based
1147         # tests will erroneously succeed. (We need to link with -pthread or
1148         # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
1149         # a function called by this macro, so we could check for that, but
1150         # who knows whether they'll stub that too in a future libc.) So,
1151         # we'll just look for -pthreads and -lpthread first:
1153         acx_pthread_flags="-pthread -pthreads pthread -mt $acx_pthread_flags"
1154         ;;
1155 esac
1157 if test x"$acx_pthread_ok" = xno; then
1158 for flag in $acx_pthread_flags; do
1160         case $flag in
1161                 none)
1162                 AC_MSG_CHECKING([whether pthreads work without any flags])
1163                 ;;
1165                 -*)
1166                 AC_MSG_CHECKING([whether pthreads work with $flag])
1167                 PTHREAD_CFLAGS="$flag"
1168                 ;;
1170                 *)
1171                 AC_MSG_CHECKING([for the pthreads library -l$flag])
1172                 PTHREAD_LIBS="-l$flag"
1173                 ;;
1174         esac
1176         save_LIBS="$LIBS"
1177         save_CFLAGS="$CFLAGS"
1178         LIBS="$PTHREAD_LIBS $LIBS"
1179         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
1181         # Check for various functions. We must include pthread.h,
1182         # since some functions may be macros. (On the Sequent, we
1183         # need a special flag -Kthread to make this header compile.)
1184         # We check for pthread_join because it is in -lpthread on IRIX
1185         # while pthread_create is in libc. We check for pthread_attr_init
1186         # due to DEC craziness with -lpthreads. We check for
1187         # pthread_cleanup_push because it is one of the few pthread
1188         # functions on Solaris that doesn't have a non-functional libc stub.
1189         # We try pthread_create on general principles.
1190         AC_TRY_LINK([#include <pthread.h>],
1191                     [pthread_t th; pthread_join(th, 0);
1192                      pthread_attr_init(0); pthread_cleanup_push(0, 0);
1193                      pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
1194                     [acx_pthread_ok=yes])
1196         LIBS="$save_LIBS"
1197         CFLAGS="$save_CFLAGS"
1199         AC_MSG_RESULT($acx_pthread_ok)
1200         if test "x$acx_pthread_ok" = xyes; then
1201                 break;
1202         fi
1204         PTHREAD_LIBS=""
1205         PTHREAD_CFLAGS=""
1206 done
1209 # Various other checks:
1210 if test "x$acx_pthread_ok" = xyes; then
1211         save_LIBS="$LIBS"
1212         LIBS="$PTHREAD_LIBS $LIBS"
1213         save_CFLAGS="$CFLAGS"
1214         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
1216         # Detect AIX lossage: threads are created detached by default
1217         # and the JOINABLE attribute has a nonstandard name (UNDETACHED).
1218         AC_MSG_CHECKING([for joinable pthread attribute])
1219         AC_TRY_LINK([#include <pthread.h>],
1220                     [int attr=PTHREAD_CREATE_JOINABLE;],
1221                     ok=PTHREAD_CREATE_JOINABLE, ok=unknown)
1222         if test x"$ok" = xunknown; then
1223                 AC_TRY_LINK([#include <pthread.h>],
1224                             [int attr=PTHREAD_CREATE_UNDETACHED;],
1225                             ok=PTHREAD_CREATE_UNDETACHED, ok=unknown)
1226         fi
1227         if test x"$ok" != xPTHREAD_CREATE_JOINABLE; then
1228                 AC_DEFINE(PTHREAD_CREATE_JOINABLE, $ok,
1229                           [Define to the necessary symbol if this constant
1230                            uses a non-standard name on your system.])
1231         fi
1232         AC_MSG_RESULT(${ok})
1233         if test x"$ok" = xunknown; then
1234                 AC_MSG_WARN([we do not know how to create joinable pthreads])
1235         fi
1237         AC_MSG_CHECKING([if more special flags are required for pthreads])
1238         flag=no
1239         case "${host_cpu}-${host_os}" in
1240                 *-aix* | *-freebsd*) flag="-D_THREAD_SAFE";;
1241                 *solaris* | alpha*-osf*) flag="-D_REENTRANT";;
1242         esac
1243         AC_MSG_RESULT(${flag})
1244         if test "x$flag" != xno; then
1245                 PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
1246         fi
1248         LIBS="$save_LIBS"
1249         CFLAGS="$save_CFLAGS"
1251         # More AIX lossage: must compile with cc_r
1252         AC_CHECK_PROG(PTHREAD_CC, cc_r, cc_r, ${CC})
1253 else
1254         PTHREAD_CC="$CC"
1257 AC_SUBST(PTHREAD_LIBS)
1258 AC_SUBST(PTHREAD_CFLAGS)
1259 AC_SUBST(PTHREAD_CC)
1261 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
1262 if test x"$acx_pthread_ok" = xyes; then
1263         ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
1264         :
1265 else
1266         acx_pthread_ok=no
1267         $2
1269 AC_LANG_RESTORE
1270 ])dnl ACX_PTHREAD