added missing #ifdef around #include "thread_mpi.h"
[alexxy/gromacs.git] / configure.ac
1 #######################################################################
2 # Process this file wth autoconf to produce a configure script.
3 #######################################################################
4  
5 AC_PREREQ(2.50)
6
7 # The "-dev" suffix is important to keep because it makes possible to distinguish 
8 # between a build from official release and a build from git release branch on a 
9 # machine with no git. 
10 #
11 # NOTE: when releasing the "-dev" suffix needs to be stripped off!
12 AC_INIT(gromacs, 4.5.5-dev, [gmx-users@gromacs.org])
13 AC_CONFIG_SRCDIR(src/gmxlib/3dview.c)
14 AC_CONFIG_AUX_DIR(config)
15 AC_CANONICAL_HOST
16
17 AM_INIT_AUTOMAKE(tar-ustar)
18 AC_PREFIX_DEFAULT(/usr/local/gromacs)
19
20 AM_CONFIG_HEADER(src/config.h)
21 dnl This is the version info according to the libtool versioning system.
22 dnl It does *not* correspond to the release number.
23 SHARED_VERSION_INFO="6:0:0"
24 AC_SUBST(SHARED_VERSION_INFO)
25
26 AC_ENABLE_SHARED
27 test "$enable_mpi" = "yes" && AC_DISABLE_SHARED
28 PKG_CFLAGS=""
29
30 #######################################################################
31 # Simple options and makefile variables
32 #######################################################################
33
34 ### Single/Double
35 AC_ARG_ENABLE(float,
36              [AC_HELP_STRING([--disable-float],
37                              [Use double instead of single precision])],, enable_float=yes)
38
39 AC_ARG_ENABLE(double,
40              [AC_HELP_STRING([--enable-double],
41                              [Same effect as --disable-float])],, enable_double=no)
42 if test "$enable_double" = "yes"; then
43    enable_float=no;
44 fi
45 if test "$enable_float" = "no"; then
46   AC_DEFINE(GMX_DOUBLE,,[Compile in double precision])
47   PKG_CFLAGS="$PKG_CFLAGS -DGMX_DOUBLE"
48 fi
49 AM_CONDITIONAL([GMX_DOUBLE],[test "$enable_float" = "no"])
50
51
52
53 ### Fortran or not
54 AC_ARG_ENABLE(fortran,
55              [AC_HELP_STRING([--enable-fortran],
56                              [Use Fortran kernels])],, 
57 [case "${host_cpu}-${host_os}" in
58   sparc*-solaris* | alpha*-* | rs6000*-aix* | powerpc*-aix* | mips*-irix*) enable_fortran=yes ;;
59   *) enable_fortran=no ;;
60  esac])
61 # always use CC for linking:
62 AC_SUBST(F77LINK,"\$(LINK)")
63
64 #On some systems GNU libtool's la files are more confusing for libtool than helpful due to the 
65 #hard coded paths/libs in the files. And for better linking we have pkg-config files (.pc).
66 AC_ARG_ENABLE(la-files,
67         [AS_HELP_STRING([--disable-la-files],[Do NOT install GNU libtool's la files])],,
68         [enable_la_files=yes])
69 AM_CONDITIONAL(NO_LA_FILES,[test "$enable_la_files" = no])
70
71
72
73
74 ### MPI or not
75 AC_ARG_ENABLE(mpi,
76               [AC_HELP_STRING([--enable-mpi],
77                               [Compile for parallel runs using MPI]
78                               [(instead of threads)])],,enable_mpi=no)
79
80
81 ### MPI environment
82 AC_ARG_ENABLE(mpi-environment,
83               [AC_HELP_STRING([--enable-mpi-environment=VAR],
84                               [Only start parallel runs when VAR is set])],,
85 [case "${host_cpu}" in
86   mips*-irix*) enable_mpi_environment="MPI_ENVIRONMENT" ;;
87   *) enable_mpi_environment=no ;;
88 esac])
89 if test "$enable_mpi_environment" != "no"; then
90   AC_DEFINE_UNQUOTED(GMX_CHECK_MPI_ENV,"$enable_mpi_environment",[If defined, only start MPI runs when this variable is set])
91 fi
92
93 ### MPI_IN_PLACE
94 AC_ARG_ENABLE(mpi-in-place,
95               [AC_HELP_STRING([--disable-mpi-in-place],
96                               [Disable MPI_IN_PLACE. For MPI implementations]
97                               [that have broken support for it ]
98                               [(some versions of MPICH, for example).])],, enable_mpi_in_place=yes)
99
100
101
102 AC_ARG_ENABLE(debug,
103               [AC_HELP_STRING([--enable-debug],
104                               [Add -g to other command line arguments])],,enable_debug=no)
105
106 ### IA32 assembly code
107 AC_ARG_ENABLE(ia32_sse,
108               [AC_HELP_STRING([--disable-ia32-sse],
109                               [Don't build SSE/SSE2 assembly loops on ia32])],,enable_ia32_sse=yes)
110
111 case "${host_cpu}-${host_vendor}" in
112    i?86-*) ;;
113    *) enable_ia32_sse=no ;;
114 esac
115
116 ### AMD64 assembly code
117 AC_ARG_ENABLE(x86_64_sse,
118               [AC_HELP_STRING([--disable-x86-64-sse],
119                               [Don't build SSE assembly loops on X86_64])],,enable_x86_64_sse=yes)
120 case "${host_cpu}-${host_vendor}" in
121    x86_64-* | amd64-*) ;;
122    i?86-apple) ;;
123    *) enable_x86_64_sse=no ;;
124 esac
125
126
127 ### Altivec on powerpc (motorola)
128 AC_ARG_ENABLE(ppc_altivec,
129               [AC_HELP_STRING([--disable-ppc-altivec],
130                               [Don't build Altivec loops on PowerPC])],,enable_ppc_altivec=undef)
131 # Power3/4/5 running AIX does not support altivec. We identify this with vendor=IBM.
132 # IBM powerpc 970 boxes run linux, and have vendor=unknown.
133 if test "$enable_ppc_altivec" = "undef"; then
134   case "${host_cpu}-${host_vendor}" in
135     ppc*-ibm* | powerpc*-ibm*) enable_ppc_altivec=no ;;
136     ppc*-* | powerpc*-*) enable_ppc_altivec=yes ;; 
137     *) enable_ppc_altivec=no ;;
138   esac
139 fi
140
141 ###################################
142 ## Detect buggy version of gcc
143 ###################################
144 AC_ARG_ENABLE(gcc41_check,
145               [AC_HELP_STRING([--disable-gcc41-check],
146                               [Disable the check for buggy gcc 4.1])],,enable_gcc41_check=yes)
147
148
149
150 ### ia64 assembly code
151 AC_ARG_ENABLE(ia64_asm,
152               [AC_HELP_STRING([--enable-ia64-asm],
153                               [Build assembly loops on ia64])],,enable_ia64_asm=no)
154 case "${host_cpu}" in
155    ia64) ;;
156    *) enable_ia64_asm=no ;;
157 esac
158
159
160 # IBM Power6-specific optimization
161 AC_ARG_ENABLE(power6,
162              [AC_HELP_STRING([--enable-power6],
163                              [Use IBM Power6-specific F77 kernels])],,enable_power6=no)
164 if test "$enable_power6" = "yes"; then
165   AC_DEFINE(GMX_POWER6,,[Enable IBM Power6-specific F77 kernels])
166 fi
167
168 AC_ARG_ENABLE(bluegene,
169               [AC_HELP_STRING([--enable-bluegene],
170                               [Build assembly intrinsics kernels on bluegene])],,enable_bluegene=no)
171
172
173 ### Optimize for host cpu version
174 AC_ARG_ENABLE(cpu-optimization,     
175               [AC_HELP_STRING([--disable-cpu-optimization],
176                               [No detection or tuning flags for cpu version])],, enable_cpu_optimization=yes)
177
178
179 ### Do software 1/sqrt(x)                                                                                                            
180 AC_ARG_ENABLE(software-invsqrt,
181               [AC_HELP_STRING([--disable-software-invsqrt],
182                               [No software 1/sqrt (disabled on sgi,ibm,ia64)])],,
183 [case "${host_cpu}-${host_os}" in
184   mips*-irix* | rs6000*-aix* | powerpc*-aix | powerpc*-none | ia64*-*) enable_software_invsqrt=no ;;
185   *) enable_software_invsqrt=yes ;;
186 esac])
187 if test "$enable_software_invsqrt" = "yes"; then
188   AC_DEFINE(GMX_SOFTWARE_INVSQRT,,[Use the GROMACS software 1/sqrt(x)])
189   PKG_CFLAGS="$PKG_CFLAGS -DGMX_SOFTWARE_INVSQRT"
190 fi
191 AM_CONDITIONAL([GMX_SOFTWARE_INVSQRT],[test "$enable_software_invsqrt" = "yes"])
192
193 AC_ARG_ENABLE(fahcore,
194               [AC_HELP_STRING([--enable-fahcore],
195                               [Create a library with mdrun functionality])],, enable_fahcore=no)
196
197
198
199 # The four options below used to improve code scheduling, but the newest CPUs can usually rearrange
200 # instructions dynamically at runtime, so they might not make much difference now:
201
202
203 AC_ARG_ENABLE(all-static,
204               [AC_HELP_STRING([--enable-all-static],
205                               [Make completely static binaries])],, enable_all_static=no)
206 # Dont add the -all-static flag until after the compiler test.
207
208
209 # FFT libraries - only use one...
210 AC_ARG_WITH(fft,
211             [AC_HELP_STRING([--with-fft=@<:@fftw3/fftw2/mkl(>=6.0)/fftpack@:>@],
212                             [FFT library to use. fftw3 is default, fftpack built in.])],,
213                              with_fft=fftw3)
214
215 AC_ARG_ENABLE(fftw-measure,
216             [AC_HELP_STRING([--disable-fftw-measure],
217                             [Dont optimize FFTs. This produces binary exactly]
218                             [reproducible runs (as the -reprod flag to mdrun),]
219                             [and if you are using FFTW on x86 and specified its]
220                             [--enable-sse/sse2 flag (NOT default in FFTW!) the]
221                             [kernels used are close-to-optimal anyway.])],,
222                              enable_fftw_measure=yes)
223
224
225 AC_ARG_ENABLE(threads,
226               [AC_HELP_STRING([--disable-threads],    
227                               [Disable parallel runs using threads])],,enable_threads=yes)
228
229
230 ### Use external BLAS/LAPACK libraries if the user wants to.
231 ###
232 AC_ARG_WITH(external_blas,
233             [AC_HELP_STRING([--with-external-blas],
234                             [Use system BLAS library (add to LIBS). Automatic on OS X.])],,
235 [
236 # default action - check if we are on OS X
237 case "${host_vendor}-${host_os}" in
238   apple-darwin*) with_external_blas="yes" ; extra_LDFLAGS="-framework Accelerate" ;;
239   *)             with_external_blas="no"  ;;
240 esac
241 ])
242 AM_CONDITIONAL([GMX_EXTERNAL_BLAS], [test "$with_external_blas" = "yes"])
243
244
245 AC_ARG_WITH(external_lapack,
246             [AC_HELP_STRING([--with-external-lapack],
247                             [Use system LAPACK library (add to LIBS). Automatic on OS X.])],,
248 [
249 # default action - check if we are on OS X
250 case "${host_vendor}-${host_os}" in
251   apple-darwin*) with_external_lapack="yes" ; extra_LDFLAGS="-framework Accelerate" ;;
252   *)             with_external_lapack="no"  ;;
253 esac
254 ])
255 AM_CONDITIONAL([GMX_EXTERNAL_LAPACK], [test "$with_external_lapack" = "yes"])
256
257
258
259
260 AC_ARG_WITH(qmmm_gaussian,
261               [AC_HELP_STRING([--without-qmmm-gaussian],
262                               [Use modified Gaussian0x for QM-MM (see website)])],,with_qmmm_gaussian=yes)
263 if test "$with_qmmm_gaussian" = "yes"; then
264   AC_DEFINE(GMX_QMMM_GAUSSIAN,,[Use (modified) Gaussian0x for QM-MM calculations])
265 fi
266
267
268 AC_ARG_WITH(qmmm_gamess,
269               [AC_HELP_STRING([--without-qmmm-gamess],
270                               [Use modified Gamess-UK for QM-MM (see website)])],,with_qmmm_gamess=no)
271 if test "$with_qmmm_gamess" = "yes"; then
272   AC_DEFINE(GMX_QMMM_GAMESS,,[Use (modified) Gamess-UK for QM-MM calculations])
273 fi
274
275
276 AC_ARG_WITH(qmmm_mopac,
277               [AC_HELP_STRING([--without-qmmm-mopac],
278                               [Use modified Mopac 7 for QM-MM (see website)])],,with_qmmm_mopac=no)
279 if test "$with_qmmm_mopac" = "yes"; then
280   AC_DEFINE(GMX_QMMM_MOPAC,,[Use (modified) Mopac 7 for QM-MM calculations])
281 fi
282
283
284 AC_ARG_WITH(qmmm_orca,
285               [AC_HELP_STRING([--without-qmmm-orca],
286                               [Use ORCA for QM-MM])],,with_qmmm_orca=no)
287 if test "$with_qmmm_orca"="yes"; then
288   AC_DEFINE(GMX_QMMM_ORCA,,[Use ORCA for QM-MM calculations])
289 fi
290
291
292 AC_ARG_WITH(dlopen,
293             [AC_HELP_STRING([--without-dlopen],
294                             [do not compile with dlopen, needed to read VMD]
295                             [supported file formats])],,with_dlopen=yes)
296
297
298
299 ############################################################
300 # Add some debug info: Who is building, and on what machine?
301 ############################################################
302 AC_DEFINE_UNQUOTED([BUILD_TIME],["`date`"],[Date and time for build])
303 AC_DEFINE_UNQUOTED([BUILD_USER],["`whoami`@`hostname`"],[User doing build])
304 AC_DEFINE_UNQUOTED([BUILD_MACHINE],["`uname -srm`"],[Hardware and OS version for build host])
305
306
307 ############################################################
308 # Checks for requirements for version information generation
309 ############################################################
310 generate_version=no
311 if test -d $srcdir/.git ; then
312     AC_CHECK_PROG(have_git, git, yes, no)
313     if test "$have_git" = "yes" ; then
314         AC_MSG_CHECKING(for a recent enough git)
315         if git --git-dir=$srcdir/.git rev-list -n1 --pretty=format:%cd HEAD | grep "Mon\|Tue\|Wed\|Thu\|Fri\|Sat\|Sun" >/dev/null 2>&1; then
316             AC_MSG_RESULT(yes)
317             generate_version=yes
318             AC_DEFINE(USE_VERSION_H,,[Use generated version info])
319         else
320             AC_MSG_RESULT(no)
321         fi
322     fi
323     if test "$generate_version" = "no" ; then
324         AC_MSG_WARN([No compatible git version found, won't be able to generate proper development version information.])
325     fi
326 fi
327 AM_CONDITIONAL([USE_VERSION_H],[test "$generate_version" = "yes"])
328
329
330 ############################################################
331 # Checks for programs
332 ############################################################
333
334 # normally we use the default compiler, but on alpha/linux we try the compaq ones first
335 case "${host_cpu}-${host_os}" in
336   alpha*-linux*)
337     cc_names="ccc cc gcc"
338     f77_names="fort f77 gfortran g77"
339     ;;
340   *) 
341     cc_names="cc icc xlc gcc"
342     f77_names="f77 ifort xlf xlf77 cf77 fl32 gfortran g77 fort77 f90 xlf90 pgf77 cf77 fort fort77 pgf90"
343     ;;
344 esac
345 # the (non-mpi) c compiler, which is also used for programs executed during build stage
346 AC_PROG_CC( $cc_names )
347 # Check for environment variable CC_FOR_BUILD before overwriting it
348 if test -z "$CC_FOR_BUILD"; then
349   CC_FOR_BUILD=$CC
350 fi
351
352 if test "$enable_gcc41_check" = "yes"; then
353     if $CC --version 2>&1 | grep 'gcc.* 4\.1' > /dev/null 2>&1; then
354         AC_MSG_ERROR([Uh-oh. Your compilers appears to be GCC version 4.1, which unfortunately produces]
355 [buggy code at high optimimzation levels. It would be a good idea to update or]
356 [use a different compiler. If you are ABSOLUTELY sure what you are doing, you]
357 [can override this check with --disable-gcc41-check.])
358     fi
359 fi
360
361
362
363 AC_SUBST(CC_FOR_BUILD) 
364
365 if test "$enable_fortran" = "yes" -o "$enable_power6" = "yes"; then 
366   AC_PROG_F77( $f77_names )
367   if test -z "$F77"; then
368     AC_MSG_ERROR([No fortran compiler found])
369   fi
370 fi
371
372 AM_PROG_AS( $CC )
373
374 # if we are using mpi, also get an MPICC. We cannot set that in the PROG_CC macro
375 # above, since autoconf checks that the created file can be executed. This would
376 # fail on platforms where MPI executables can only be run through a batchqueue.
377
378 if test "$enable_mpi" = "yes"; then
379   enable_threads="no"
380   AC_CHECK_PROGS(MPICC, mpxlc mpicc mpcc hcc, $CC)
381 # now change the normal cc to the MPI one - see the comment above.
382   CC=$MPICC
383   CXX=$MPICC
384   AC_MSG_CHECKING([whether the MPI cc command works]) # be paranoid
385   AC_TRY_LINK([#include <mpi.h>],[int argc; char **argv; MPI_Init(&argc,&argv);],
386 AC_MSG_RESULT([yes]),AC_MSG_ERROR([Cannot compile and link MPI code with $CC]))
387   AC_DEFINE(GMX_MPI,,[Make a parallel version of GROMACS using MPI])
388   AC_DEFINE(GMX_LIB_MPI,,[Use a real MPI library])
389   PKG_CFLAGS="$PKG_CFLAGS -DGMX_LIB_MPI"
390
391   if test "$enable_mpi_in_place" = "yes"; then
392     # not all MPIs support MPI_IN_PLACE:
393     AC_MSG_CHECKING([for MPI_IN_PLACE in collective operations])
394     AC_TRY_COMPILE([
395 #include <mpi.h>
396 void test(void)
397 {
398     void *buf;
399     MPI_Allreduce(MPI_IN_PLACE, buf, 10, MPI_FLOAT, MPI_SUM, MPI_COMM_WORLD);
400 }
401     ],,[
402         AC_MSG_RESULT([yes])
403         AC_DEFINE(MPI_IN_PLACE_EXISTS,[],[MPI_IN_PLACE available for collective operations])
404     ],[
405         AC_MSG_RESULT([no])
406     ]) 
407   fi
408
409 # on the cray xt3 we have to tell autoconf that we 
410 # are actually cross-compiling even if the architecture
411 # of host and target are the same. so we enforce 
412 # cross-compilation if __QK_USER__ is defined
413   AC_MSG_CHECKING([for catamount])
414   AC_TRY_COMPILE([
415 #if defined __QK_USER__
416 #else
417 #error not catamount
418 #endif
419 ],,[
420   AC_MSG_RESULT([yes])
421   cross_compiling=yes 
422   AC_DEFINE(GMX_CRAY_XT3,[],[Enable special hacks for Cray XT3])
423   PKG_CFLAGS="$PKG_CFLAGS -DGMX_CRAY_XT3"
424   AC_DEFINE(GMX_NO_SYSTEM,[],[Ignore calls to system(3)])
425   AC_DEFINE(GMX_NO_NICE,[],[Ignore calls to nice(3)])
426   AC_DEFINE(GMX_BROKEN_CALLOC,[],[Don't use calloc(3)])
427   extra_LDFLAGS="$extra_LDFLAGS -lgmalloc -lacml"
428 ],[
429   AC_MSG_RESULT([no])
430 ])
431 # end of "$enable_mpi" = "yes"
432 fi
433
434
435 AH_TEMPLATE([F77_OR_C_FUNC],
436             [Set to F77_FUNC(name,NAME) if Fortran used, otherwise 'name' for C.])
437 AH_TEMPLATE([F77_OR_C_FUNC_],
438             [Set to F77_FUNC_(name,NAME) if Fortran used, otherwise 'name' for C.])
439
440
441
442 if test "$enable_fortran" = "yes" -o "$enable_power6" = "yes"; then
443   AC_F77_LIBRARY_LDFLAGS
444   AC_F77_WRAPPERS
445   AC_DEFINE([F77_OR_C_FUNC(name,NAME)],[F77_FUNC(name,NAME)])
446   AC_DEFINE([F77_OR_C_FUNC_(name,NAME)],[F77_FUNC_(name,NAME)])
447 else
448   AC_DEFINE([F77_OR_C_FUNC(name,NAME)],[name])
449   AC_DEFINE([F77_OR_C_FUNC_(name,NAME)],[name])
450 fi
451
452
453
454 AC_PROG_CPP
455 # Needed by libtool scripts?
456 AC_PROG_EGREP
457 AC_PROG_LN_S
458
459 if test "$enable_cpu_optimization" = "yes"; then
460   ACX_DETECT_GMXCPU
461 else
462   gmxcpu=""
463 fi
464 ACX_COMPILER_MAXOPT
465
466
467 # We've postponed the threads check because we need to check with the right
468 # compilers/flags
469 SAVED_LIBS="$LIBS"
470 if test "$enable_threads" = "yes"; then 
471   if test "$enable_mpi" = "yes"; then
472     AC_MSG_ERROR([Cannot use both threads and MPI - yet.])
473   fi
474   if test "$with_fft" = "fftw2"; then
475     AC_MSG_ERROR([fftw2 can't be used with threads. Use fftw3 or mkl.])
476   fi 
477   if test "$enable_fortran" = "yes"; then
478     AC_MSG_ERROR([FORTRAN is incompatible with threads and only provides a speed-up on certain IBM compilers. Use --disable-threads if you really want to use FORTRAN kernels.])
479   fi
480   AC_CHECK_HEADERS(unistd.h)
481   AC_CHECK_HEADERS(sys/time.h)
482   AC_CHECK_HEADERS(sched.h)
483   AC_CHECK_FUNCS(sysconf)
484
485   # for now we just assume pthreads
486   ACX_PTHREAD(,AC_MSG_ERROR([Cannot find POSIX threads - required for thread support using configure!]))
487   LIBS="$PTHREAD_LIBS $LIBS"
488   CFLAGS="$CFLAGS $PTHREAD_CFLAGS -I$srcdir/include"
489   CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS -I$srcdir/include"
490   CC="$PTHREAD_CC "
491   AC_DEFINE(THREAD_PTHREADS,,[Use pthreads for multithreading])
492
493   # profiling
494   AC_ARG_ENABLE(tmpi-profiling,
495               [AC_HELP_STRING([--enable-tmpi-profiling],
496               [Enables profiling of thread_mpi calls and wait times])],,
497               enable_tmpi_profiling=no)
498   if test "x$enable_tmpi_profiling" = "xyes"; then
499     AC_DEFINE(TMPI_PROFILE,,[Enable profiling for call and wait times])
500   fi
501
502   # check the atomics
503   AC_MSG_CHECKING(if atomic operations are supported)
504   CFLAGS_RET="$CFLAGS"
505   CXXFLAGS_RET="$CXXFLAGS"
506   CFLAGS="$CFLAGS -I$srcdir/include -DTMPI_CHECK_ATOMICS"
507   CXXFLAGS="$CXXFLAGS -I$srcdir/include -DTMPI_CHECK_ATOMICS"
508   # this sets a variable 'tmpi_atomics' to 'yes' if there are atomics. 
509   AC_COMPILE_IFELSE([#include "thread_mpi/atomic.h" ],
510                       [AC_MSG_RESULT(yes); tmpi_atomics=yes],
511                       [AC_MSG_WARN(
512 [No atomics.
513
514 This compiler+CPU combination doesn't have working atomics.
515 Thread support will be unbearably slow: disable threads.
516
517 Atomics should work on all but the most obscure CPU+compiler combinations;
518 if your system is not obscure -- like, for example, x86 with gcc --  please
519 contact the developers.
520 ]); tmpi_atomics=no])
521
522
523   # pthread_setaffinity
524   AC_MSG_CHECKING(if pthread_setaffinity_np is available)
525   AC_COMPILE_IFELSE([#define _GNU_SOURCE
526 #include <pthread.h>
527 #include <stdlib.h>
528 #include <stdio.h>
529 #include <errno.h>
530 int main(void)
531 {
532     cpu_set_t set;
533     CPU_ZERO(&set);
534     CPU_SET(0, &set);
535     pthread_setaffinity_np(pthread_self(), sizeof(set), &set);
536     return 0;
537 }],
538   [AC_MSG_RESULT(yes); pthread_setaffinity=yes],
539   [AC_MSG_RESULT(no); pthread_setaffinity=no] )
540
541   if test "x$pthread_setaffinity" = "xyes"; then
542     AC_DEFINE(HAVE_PTHREAD_SETAFFINITY,1,[pthread_setaffinity_np is available])
543   fi
544
545   CFLAGS="$CFLAGS_RET"
546   CXXFLAGS="$CXXFLAGS_RET"
547
548   AC_DEFINE(GMX_THREADS,,[Use threads for parallelization])
549   PKG_CFLAGS="$PKG_CFLAGS -DGMX_THREADS"
550   AC_DEFINE(GMX_MPI,,[Make a parallel version of GROMACS using MPI])
551   AM_CONDITIONAL(THREAD_PARALLEL,true)
552 else
553   AM_CONDITIONAL(THREAD_PARALLEL,false)
554 fi
555 LIBS="$SAVED_LIBS"
556
557
558
559 #############
560 # Check integer endian
561 #############
562 AC_C_BIGENDIAN([AC_DEFINE([GMX_INTEGER_BIG_ENDIAN],,[Integer byte order is big endian.])],[],[
563 AC_MSG_ERROR([Cannot determine endian in compiled output])])
564 # Little endian implied if GMX_INTEGER_BIG_ENDIAN not defined in source.
565
566 #############
567 # Make sure size_t can hold pointers.
568 # On some Nec machines, you reportedly need to specify a flag for size_t to be 64 bits wide.
569 #############
570 AC_MSG_CHECKING([that size_t can hold pointers])
571 AC_TRY_COMPILE([
572 #include <stdlib.h>
573 #include <stddef.h>
574 ],[int chk[sizeof(size_t)-sizeof(int *)+1];],AC_MSG_RESULT([yes]),[
575    AC_MSG_ERROR([size_t is smaller than int*. Check if your compiler needs a flag to make it 64 bit.])])
576
577
578 #############
579 # Check that SIGUSR1 is defined
580 #############
581 AC_MSG_CHECKING([for SIGUSR1])
582 AC_TRY_COMPILE([#include <signal.h>],[int i=SIGUSR1;],[
583 AC_MSG_RESULT([yes])
584 AC_DEFINE(HAVE_SIGUSR1,,[SIGUSR1 supported and defined])
585 ],AC_MSG_RESULT([no]))
586
587 #############
588 # Check if pipes are supported
589 #############
590 AC_MSG_CHECKING([for pipes])
591 AC_TRY_COMPILE([#include <stdio.h>],[
592 FILE *pipe=popen("/tmp/pipe","r");
593 ],[
594 AC_MSG_RESULT([yes])
595 AC_DEFINE(HAVE_PIPES,,[Pipes (popen/pclose) supported])
596 ],AC_MSG_RESULT([no]))
597
598
599
600 #############
601 # Check floating-point format and endian
602 #############
603 ACX_FLOAT_FORMAT
604
605
606 AC_PROG_INSTALL
607 AC_PROG_LN_S
608 AC_PROG_MAKE_SET
609 AC_LIBTOOL_WIN32_DLL
610 AC_LIBTOOL_DLOPEN
611 AC_PROG_LIBTOOL
612 AC_SYS_LARGEFILE
613 #
614 # Use our own version of AC_FUNC_FSEEKO from autoconf 2.63 instead
615 # of the broken one we might get from autoconf 2.61.
616 ACX_FUNC_FSEEKO_FIXED
617
618
619
620
621 ############################################################################
622 # Checks for libraries.
623 ############################################################################
624 #
625 # Don't add math library for intel compilers
626 if $CC -V 2>&1 | grep 'Intel Corporation' > /dev/null 2>&1; then
627   AC_MSG_NOTICE([Using built-in math library with intel compiler])
628 else
629   AC_CHECK_LIB(m,sqrt,,AC_MSG_ERROR([No math library found]))
630 fi
631
632 #####
633 # Disable MASS support for now.
634 #####
635
636 #save current LIBS
637 SAVED_LIBS="$LIBS"
638
639 #set empty defaults
640 PKG_FFT=""
641 FFT_LIBS=""
642 case "$with_fft" in
643 fftw2)
644   if test "$enable_float" = "yes"; then
645     sizeof_real=4
646   else
647     sizeof_real=8
648   fi
649   ACX_CHECK_FFTW2(fftw,$sizeof_real)
650   ACX_CHECK_FFTW2(rfftw,$sizeof_real)
651   FFT_LIBS="-lfftw -lrfftw"
652
653   case ${ac_fftw_savedprefix} in
654    d) AC_DEFINE(FFTW2_NAME_DFFTW,,[Use the d prefix on fftw2 includes]) ;;
655    s) AC_DEFINE(FFTW2_NAME_SFFTW,,[Use the s prefix on fftw2 includes]) ;;
656    *) AC_DEFINE(FFTW2_NAME_FFTW,,[Dont use any prefix on fftw2 includes]) ;;
657   esac
658
659   AC_DEFINE(GMX_FFT_FFTW2,,[Use FFTW2 FFT library])
660
661   ;; #  end of fftw2 check
662
663 fftw3) # Much simpler check than fftw2
664 # Check for header <fftw3.h> AC_CHECK_HEADERS doesnt work, since we must
665 # use mpicc to get includes - cpp isnt always the same compiler.
666 AC_MSG_CHECKING([for fftw3.h])
667 AC_TRY_COMPILE([#include<fftw3.h>],,[
668 # ok, look for library file too
669 AC_MSG_RESULT(yes)
670 if test "$enable_float" = "yes"; then
671   AC_CHECK_LIB([fftw3f],main,,AC_MSG_ERROR([Cannot find fftw3f library]))
672   PKG_FFT="fftw3f"
673   FFT_LIBS="-lfftw3f"
674 else
675   AC_CHECK_LIB([fftw3],main,,AC_MSG_ERROR([Cannot find fftw3 library]))
676   PKG_FFT="fftw3"
677   FFT_LIBS="-lfftw3"
678 fi
679   AC_DEFINE(GMX_FFT_FFTW3,,[Use FFTW3 FFT library])
680 ],[
681 # not ok, echo a warning
682 AC_MSG_ERROR(
683 [Cannot find the default external FFT library (fftw3).
684 Other alternatives are 'fftw2', or 'mkl' for Intel MKL.
685 You are STRONGLY recommended to use one of these - fftw is free.
686
687 Use CPPFLAGS and LDFLAGS if the library is installed in a 
688 non-standard location. (see FAQ at http://www.gromacs.org)
689                                                           
690 If you dont care about performance you can also specify 'fftpack'
691 to use a slower set of FFTs built into Gromacs. 
692 (Just install FFTW3 unless you really know what you are doing).
693 ])
694 ])
695   ;;
696
697 mkl*)
698 ###########
699 # Intel Math Kernel Library version 6 and later.
700 ##########
701 AC_MSG_CHECKING([for mkl_dfti.h])
702 AC_TRY_COMPILE([#include<mkl_dfti.h>],,AC_MSG_RESULT(yes),AC_MSG_ERROR([Cannot find mkl_dfti.h header from Intel Math Kernel Library>=6.0.]\
703 ))
704 ## Check for library
705 #  AC_CHECK_LIB([guide],main,,AC_MSG_ERROR([Cannot find libguide (Intel MKL)]))
706 #  AC_CHECK_LIB([mkl],DftiComputeForward,,
707 #    AC_MSG_ERROR([Cannot find Intel Math Kernel Library >= 6.0]))
708   # first check for older MKLs
709   AC_CHECK_LIB([mkl],DftiComputeForward,,[have_mkl="no"])
710   if test "$have_mkl" = "no"; then
711     # we assume it's a new MKL
712     LIBS="$LIBS -liomp5 -lmkl_sequential -lmkl_core"
713     LMKL=" -liomp5 -lmkl_sequential -lmkl_core"
714     AC_CHECK_LIB([mkl_intel_lp64],DftiComputeForward,,[have_mkl10_64="no"])
715     FFT_LIBS="$LMKL -lmkl_intel_lp64"
716     if test "$have_mkl10_64" = "no"; then
717       AC_CHECK_LIB([mkl_intel],DftiComputeForward,,[have_mkl10_32="no"])
718       FFT_LIBS="$LMKL -lmkl_intel"
719       if test "$have_mkl10_32" = "no"; then
720         AC_MSG_ERROR([Cannot find Intel Math Kernel Library >= 6.0])
721       fi
722     fi
723   fi
724   AC_DEFINE(GMX_FFT_MKL,,[Use Intel MKL FFT library])
725   AC_SUBST(LMKL)
726   ;;
727
728 fftpack | no)
729   AC_MSG_WARN([The built-in FFTPACK routines are slow.
730 Are you sure you don't want to use FFTW? It is free and much faster...])
731   AC_DEFINE(GMX_FFT_FFTPACK,,[Use Built-in FFTPACK FFT library])
732   ;;
733 *)
734   AC_MSG_ERROR([Unknown FFT library])
735   ;;
736 esac
737 #restore LIBS from before fft check
738 LIBS="$SAVED_LIBS"
739
740 #only fftw3 has support for pkg-config
741 AC_SUBST(PKG_FFT)
742 if test -z "${PKG_FFT}"; then
743   AC_SUBST(PKG_FFT_LIBS,"$FFT_LIBS")
744 else
745   AC_SUBST(PKG_FFT_LIBS,"")
746 fi
747 #flag for Makefile
748 AC_SUBST(FFT_LIBS)
749
750 if test "$enable_fftw_measure" != "yes"; then
751    AC_DEFINE(GMX_DISABLE_FFTW_MEASURE,,[Do not optimize FFTW setups (not needed with SSE FFT kernels)])
752 fi
753
754 ######
755 # check for xtc headers
756 case "${host_os}" in
757 cygwin* | mingw*)   # use our own xdr stuff for cygwin/mingw
758   ;;
759 *)
760   AC_CHECK_HEADERS([rpc/rpc.h])
761   AC_CHECK_HEADERS([rpc/xdr.h],,,
762 [#if HAVE_RPC_RPC_H
763 # include <rpc/rpc.h>
764 #endif
765 ])
766   AC_CHECK_LIB(nsl,xdr_float)
767   AC_TRY_LINK([
768 #if HAVE_RPC_RPC_H
769 #include<rpc/rpc.h> 
770 #else
771 #error NO rpc.h header
772 #endif
773 #if HAVE_RPC_XDR_H
774 #include<rpc/xdr.h>
775 #else
776 #error No xdr.h header
777 #endif
778 ],[ XDR *xd; float f; xdr_float(xd,&f);],[have_xdr="yes"])
779
780   if test "$have_xdr" != "yes"; then
781     AC_DEFINE(GMX_INTERNAL_XDR,,[Use our own instead of system XDR libraries])  
782     PKG_CFLAGS="$PKG_CFLAGS -DGMX_INTERNAL_XDR"
783     AC_MSG_WARN([Couldn't find XDR headers and/or libraries - using our own])
784   fi
785   ;;
786 esac
787
788
789 ########################################################################
790 # Checks for header files and types
791 ########################################################################
792
793 AC_CHECK_HEADERS([limits.h unistd.h],,AC_MSG_ERROR([Include headers not found]))
794 AC_CHECK_HEADERS(unistd.h)
795 AC_CHECK_HEADERS(direct.h)
796 AC_CHECK_HEADERS(sys/types.h)
797 AC_CHECK_HEADERS(sys/time.h)
798 AC_CHECK_HEADERS(dirent.h,,[AC_MSG_WARN(
799 [
800 ********************************************************************
801 * WARNING! We could not find the header file dirent.h              *
802 *                                                                  *
803 * Without this header, we will not be able to scan directories for *
804 * files, which completely breaks pdb2gmx. You will still be able   *
805 * to run simulations, but you cannot prepare input data.           *
806 * dirent.h is part of the POSIX 2001-1 standard, and should be     *
807 * present on all UNIX-like systems, CygWin, and MinGW.             *
808 ********************************************************************])])
809 ## NOTE: On native windows we do not use configure.ac
810 AC_CHECK_HEADERS(regex.h,,[AC_MSG_WARN(
811 [No regex.h found.
812 Regular expression matching in selections will be disabled.
813 Selections still work, but the default groups can differ from
814 those obtained with regular expressions enabled.
815 Consider installing the regular expression library from GNU libc.])])
816
817
818
819 #####
820 # Checks for additional and/or optional functions or libraries.
821 #AC_FUNC_MALLOC
822 AC_FUNC_MEMCMP
823 AC_TYPE_SIGNAL
824 AC_TYPE_OFF_T
825 AC_FUNC_VPRINTF
826 AM_WITH_DMALLOC
827 AC_CHECK_FUNCS(strcasecmp)
828 AC_CHECK_FUNCS(strdup)
829 AC_CHECK_FUNCS(gettimeofday)
830 AC_CHECK_FUNCS(cbrt)
831 AC_CHECK_FUNCS(isnan)
832 AC_CHECK_FUNCS(_isnan)
833 AC_CHECK_FUNCS(isfinite)
834 AC_CHECK_FUNCS(_isfinite)
835 AC_CHECK_FUNCS(fsync)
836 AC_CHECK_FUNCS(fileno)
837
838 # check for bool (must come late, since CFLAGS/includes might affect it)
839 AC_CHECK_TYPES([bool])
840 AC_SEARCH_LIBS(posix_memalign, c, AC_DEFINE(HAVE_POSIX_MEMALIGN, 1, Define to 1 if you have the posix_memalign function))
841 AC_SEARCH_LIBS(memalign, c, AC_DEFINE(HAVE_MEMALIGN, 1, Define to 1 if you have the memalign function))
842 AC_CHECK_FUNCS(_aligned_malloc)
843 #AC_SEARCH_LIBS(_aligned_malloc, c, AC_DEFINE(HAVE__ALIGNED_MALLOC, 1, Define to 1 if you have the _aligned_malloc function))
844
845
846
847
848
849
850 #############
851 # Check integer sizes, set to zero if e.g. long long is not supported.
852 # (Note: this must come *after* type checks for the corresponding types!)
853 #############
854 AC_CHECK_SIZEOF(int)
855 AC_CHECK_SIZEOF(long int)
856 AC_CHECK_SIZEOF(long long int)
857 AC_CHECK_SIZEOF(off_t)
858 AC_CHECK_SIZEOF(void*)
859
860
861
862 # Apple OS X is a bit strange/braindead in that it always reports itself as i386, both for
863 # 32 and 64 bit builds (even with the 64 bit kernel!).
864 #
865 # To get the SSE support right we check for the size of void * that we detected above...
866 case "${host_vendor}-${host_os}" in
867   apple-darwin*)
868   if test $ac_cv_sizeof_voidp = 8; then
869      enable_ia32_sse=no;
870   else
871      enable_x86_64_sse=no;
872   fi
873   ;;
874   *) ;;
875 esac
876
877
878
879
880 #####
881 # Look for X
882 AC_PATH_XTRA
883 if test "$no_x" != "yes"; then
884   AM_CONDITIONAL(USE_X11,true)
885 else
886   AM_CONDITIONAL(USE_X11,false)
887 fi
888
889 # GNU Scientific Library or not
890 AC_ARG_WITH(gsl,
891  [AC_HELP_STRING([--with-gsl],[Link to the GNU scientific library, ]
892                  [enables extra functions in analysis])],,with_gsl=no)
893
894 ######
895 PKG_GSL=""
896 GSL_LIBS=""
897 if test "$with_gsl" = "yes"; then
898   SAVED_LIBS="$LIBS"
899   AC_CHECK_HEADERS([gsl/gsl_version.h],[
900 # header found, check for libraries 
901   AC_CHECK_LIB(gslcblas,main,[
902 # gslcblas library found, check main lib
903   AC_CHECK_LIB(gsl,main,[
904 # everything need for gsl found
905   GSL_LIBS="-lgsl -lgslcblas"
906 #gsl has pkg-config support
907   PKG_GSL="gsl"
908   AC_DEFINE(HAVE_LIBGSL,1,[Do we have libgsl])
909   ],[:],[-lgslcblas])])])
910   LIBS="$SAVED_LIBS"
911 #
912 fi
913 AC_SUBST(PKG_GSL)
914 AC_SUBST(GSL_LIBS)
915
916 AC_ARG_WITH(xml,
917  [AC_HELP_STRING([--without-xml],[do not link to the xml2 library,] 
918                  [disallows the use of certain file formats])],,with_xml=yes)
919  
920 #########
921 # Check for libxml2, but it is optional, so dont stop
922 # if it isnt there.
923 PKG_XML=""
924 XML_LIBS=""
925 if test "$with_xml" = "yes"; then
926    SAVED_LIBS="$LIBS"
927    ac_save_CPPFLAGS="$CPPFLAGS"
928    CPPFLAGS="$ac_save_CPPFLAGS -I/usr/include/libxml2"
929    AC_CHECK_HEADERS([libxml/parser.h],AC_CHECK_LIB(xml2,main))
930    if test "$ac_cv_lib_xml2_main" = "yes"; then
931      INCLUDES="$INCLUDES -I/usr/include/libxml2"
932      PKG_XML="libxml-2.0"
933      XML_LIBS="-lxml2"
934      if test "$enable_all_static" = "yes"; then
935        LDFLAGS_RET=$LDFLAGS
936        LDFLAGS="-static $LDFLAGS"
937        LIBS_RET="$LIBS"
938        LIBS="$LIBS -lz"
939        AC_MSG_CHECKING(for broken libxml2)
940        AC_TRY_RUN([
941 #include <libxml/parser.h>
942 main() {
943   xmlInitParser();
944   return 0;
945 }],
946        AC_MSG_RESULT([no]),[AC_MSG_RESULT([yes])
947        AC_MSG_ERROR([Your libxml2 is broken for static linking, recompile it without threads or build gromacs without libxml])],[-lz])
948        LDFLAGS=$LDFLAGS_RET
949        LIBS="$LIBS_RET"
950      fi
951    fi
952 # restore CPPFLAGS
953    CPPFLAGS="$ac_save_CPPFLAGS"
954    LIBS="$SAVED_LIBS"
955 fi
956 AC_SUBST(PKG_XML)
957 AC_SUBST(XML_LIBS)
958
959 #### 
960 # And collect the f77 libs to the linker - on Solaris, f77 stuff must go first,
961 # and we need -L/usr/ucblib to find libucb... (stupid OS)
962 # On e.g. ibm the mass libraries must come before -lm... 
963 case "${host_cpu}-${host_os}" in
964   *-solaris*) 
965     LIBS="$FLIBS $LIBS" 
966     LDFLAGS="$LDFLAGS -L/usr/ucblib"
967     ;;
968   *) LIBS="$LIBS $FLIBS" ;;
969 esac
970
971
972 # add the Accelerate framework if enabled above.
973 # LDFLAGS might have been set in the CPU optimization, so we cant assign it directly before that.
974 LDFLAGS="$LDFLAGS $extra_LDFLAGS"
975
976
977
978
979
980
981 #####
982 # Checks for typedefs, structures, and compiler characteristics.
983 AC_C_CONST
984 AC_TYPE_SIZE_T
985 AC_STRUCT_TM
986 AC_C_INLINE
987 AC_C_RESTRICT
988
989 # AC_TYPE_UID_T is broken on Mac OS X, so use generic tests instead
990 AC_CHECK_TYPES([uid_t],[],[AC_DEFINE(uid_t, int, [Define to `int' if <sys/types.h> doesn't define.])],[[#include <sys/types.h>]])
991 AC_CHECK_TYPES([gid_t],[],[AC_DEFINE(gid_t, int, [Define to `int' if <sys/types.h> doesn't define.])],[[#include <sys/types.h>]])
992
993 AC_CHECK_TYPES([sig_atomic_t],[],[AC_DEFINE(sig_atomic_t, int, [Define to `int' (and hope it's atomic) if <signal.h> doesn't define it.])],[[#include <signal.h>]])
994
995     
996
997
998 # Test stuff for ia32 and x86_64 assembly, and add objects/libraries.
999 if test "$enable_ia32_sse" = "yes" -o "$enable_x86_64_sse" = "yes"; then
1000   AC_MSG_CHECKING([whether your compiler can handle assembly files (*.s)])
1001 #
1002 # Use 64-bit registers (rsp/rbp) on x86_64
1003 #
1004 if test "$enable_x86_64_sse" = "yes"; then
1005 cat > conftestasm.s << EOF
1006 checkasm:
1007         mov     %rsp, %rbp
1008         ret
1009 EOF
1010 else
1011 cat > conftestasm.s << EOF
1012 checkasm:
1013         movl    %esp, %ebp
1014         ret
1015 EOF
1016 fi
1017   if AC_TRY_COMMAND($CC $CFLAGS -c conftestasm.s); then
1018     if test -f conftestasm.o; then
1019       AC_MSG_RESULT([yes])
1020     else
1021       AC_MSG_RESULT([no])
1022       AC_MSG_ERROR([Upgrade your compiler (or disable assembly loops).])
1023     fi
1024   else
1025     AC_MSG_RESULT([no])
1026     AC_MSG_ERROR([Upgrade your compiler (or disable assembly loops).])
1027   fi
1028
1029 # ok, cc understands assembly.
1030 #
1031 # If we are using double precision we need SSE2
1032   if test "$enable_float" = "no"; then
1033 #   test SSE2 on ia32:
1034     if test "$enable_ia32_sse" = "yes"; then
1035       AC_MSG_CHECKING([whether as fully supports ia32 SSE2])
1036 cat > conftest.s << EOF
1037 checkasm:
1038         emms
1039         movapd 32(%esi,%edx,8),%xmm4
1040         emms
1041         ret
1042 EOF
1043       if AC_TRY_COMMAND($CC $CFLAGS -c conftest.s); then
1044         AC_MSG_RESULT([yes])
1045       else
1046         AC_MSG_RESULT([no])
1047         AC_MSG_ERROR([Upgrade to a more recent binutils (or disable assembly loops).])
1048       fi
1049       AC_DEFINE([GMX_IA32_SSE2],,[Double-precision SSE2 instructions on ia32])
1050     fi
1051 #   test SSE2 on X86_64:
1052     if test "$enable_x86_64_sse" = "yes"; then
1053       AC_MSG_CHECKING([whether as fully supports X86_64 SSE2])
1054 cat > conftest.s << EOF
1055 checkasm:
1056         emms
1057         movapd 32(%rsi,%rdx,8),%xmm4
1058         emms
1059         ret
1060 EOF
1061       if AC_TRY_COMMAND($CC $CFLAGS -c conftest.s); then
1062         AC_MSG_RESULT([yes])
1063       else
1064         AC_MSG_RESULT([no])
1065         AC_MSG_ERROR([Upgrade to a more recent binutils (or disable assembly loops).])
1066       fi
1067       AC_DEFINE([GMX_X86_64_SSE2],,[Double-precision SSE2 instructions on X86_64])
1068     fi
1069   else
1070 # end of double precision testing, now do single.
1071     if test "$enable_ia32_sse" = "yes"; then
1072       AC_MSG_CHECKING([whether as fully supports ia32 SSE])
1073 cat > conftest.s << EOF
1074 checkasm:
1075         emms
1076         movaps 32(%esi,%edx,8),%xmm4
1077         emms
1078         ret
1079 EOF
1080       if AC_TRY_COMMAND($CC $CFLAGS -c conftest.s); then
1081         AC_MSG_RESULT([yes])
1082       else
1083         AC_MSG_RESULT([no])
1084         AC_MSG_ERROR([Upgrade to a more recent binutils (or disable assembly loops).])
1085       fi
1086       AC_DEFINE([GMX_IA32_SSE],,[Single-precision SSE instructions on ia32])
1087     fi
1088 #   test SSE2 on X86_64:
1089     if test "$enable_x86_64_sse" = "yes"; then
1090       AC_MSG_CHECKING([whether as fully supports X86_64 SSE instructions])
1091 cat > conftest.s << EOF
1092 checkasm:
1093         emms
1094         movaps 32(%rsi,%rdx,8),%xmm4
1095         emms
1096         ret
1097 EOF
1098       if AC_TRY_COMMAND($CC $CFLAGS -c conftest.s); then
1099         AC_MSG_RESULT([yes])
1100       else
1101         AC_MSG_RESULT([no])
1102         AC_MSG_ERROR([Upgrade to a more recent binutils (or disable assembly loops).])
1103       fi
1104       AC_DEFINE([GMX_X86_64_SSE],,[Single-precision SSE instructions on X86_64])
1105     fi
1106   fi
1107 fi
1108
1109
1110 # Test stuff for ia64 assembly
1111 #
1112 # Nothing to test right now.
1113
1114
1115   
1116
1117 #
1118 # Test altivec support.
1119 #
1120 if test "$enable_ppc_altivec" = "yes"; then
1121   if test "$enable_float" = "no"; then
1122     AC_MSG_WARN([PowerPC Altivec loops can only be used in single precision - disabling])
1123     enable_ppc_altivec=no
1124   else 
1125     # On FSF (vanilla) GCC we must include altivec.h, and on apple we 
1126     # should NOT do it after using -faltivec. Go figure...
1127     case "${host_os}" in
1128     darwin*)                            
1129         # do nothing on Apple systems
1130        ;;
1131     *)
1132         AC_CHECK_HEADERS([altivec.h])
1133        ;;
1134     esac
1135
1136     AC_MSG_CHECKING([whether the compiler supports altivec extensions])
1137     AC_TRY_COMPILE([],[
1138 #ifndef __VEC__
1139 choke_me
1140 #endif
1141 ],[
1142     AC_MSG_RESULT([yes])
1143     AC_DEFINE([GMX_PPC_ALTIVEC],,[Use PowerPC Altivec inner loops])],[
1144       AC_MSG_RESULT([no])
1145       AC_MSG_WARN([no altivec support found - On recent PowerPC CPUs]
1146 [you can get a huge performance gain by using an altivec-enabled compiler.]
1147 [On OS X, you need GCC>=3.3, or the IBM compilers. If you are using standard]
1148 [GCC, you need at least version 4.0])
1149       enable_ppc_altivec=no])
1150   fi  
1151 fi
1152
1153 if test "$enable_ia64_asm" = "yes"; then
1154   AC_DEFINE(GMX_IA64_ASM,,[Use ia64 assembly tuned for Itanium2])
1155   AC_DEFINE(DISABLE_WATER_NLIST,,[Turn off all water neighborlist optimization])
1156   AC_DEFINE(DISABLE_WATERWATER_NLIST,,[Turn off water-water neighborlist optimization only])
1157 fi
1158
1159 if test "$enable_bluegene" = "yes"; then
1160   AC_DEFINE(GMX_BLUEGENE,,[Use assembly intrinsics kernels for BlueGene])
1161   AC_DEFINE_UNQUOTED(GMX_POWERPC_INVSQRT,,[Use the PowerPC hardware 1/sqrt(x)])
1162   PKG_CFLAGS="$PKG_CFLAGS -DGMX_POWERPC_INVSQRT"
1163 fi
1164
1165 if test "$enable_fortran" = "yes"; then
1166   AC_DEFINE(GMX_FORTRAN,,[Enable Fortran support])
1167 fi
1168
1169 ##
1170 # Add the appropriate assembly loops 
1171 #
1172 AM_CONDITIONAL([GMX_IA32_SSE],[test "$enable_ia32_sse" = "yes" -a "$enable_float" = "yes"])
1173 AM_CONDITIONAL([GMX_IA32_SSE2],[test "$enable_ia32_sse" = "yes" -a "$enable_float" = "no"])
1174 AM_CONDITIONAL([GMX_X86_64_SSE],[test "$enable_x86_64_sse" = "yes" -a "$enable_float" = "yes"])
1175 AM_CONDITIONAL([GMX_X86_64_SSE2],[test "$enable_x86_64_sse" = "yes" -a "$enable_float" = "no"])
1176 AM_CONDITIONAL([GMX_FORTRAN],[test "$enable_fortran" = "yes"])
1177 AM_CONDITIONAL([GMX_PPC_ALTIVEC],[test "$enable_ppc_altivec" = "yes" -a "$enable_float" = "yes"])
1178 AM_CONDITIONAL([GMX_IA64_ASM],[test "$enable_ia64_asm" = "yes"])
1179 AM_CONDITIONAL([GMX_BLUEGENE],[test "$enable_bluegene" = "yes"])
1180 AM_CONDITIONAL([GMX_POWER6],[test "$enable_power6" = "yes"])
1181
1182
1183 #############
1184 # Check integer endian
1185 #############
1186 AC_C_BIGENDIAN([AC_DEFINE([GMX_INTEGER_BIG_ENDIAN],,[Integer byte order is big endian.])],[],[
1187 AC_MSG_ERROR([Cannot determine endian in compiled output])])
1188 # Little endian implied if GMX_INTEGER_BIG_ENDIAN not defined in source.
1189
1190
1191
1192 case "${host_cpu}" in
1193    i?86) 
1194          # Check if inline assembly works
1195          AC_MSG_CHECKING(if the compiler supports gcc inline assembly)
1196       AC_TRY_LINK([],[float f;int i; asm("fld %1\nfistpl %0\n" : "=m" (*&i) : "f" (f));],[AC_MSG_RESULT(yes)
1197 AC_DEFINE(GMX_X86_GCC_INLINE_ASM,,[Enable x86 gcc inline assembly])],[AC_MSG_RESULT(no)])
1198          # Check for MSVC inline assembly
1199      AC_MSG_CHECKING(if the compiler supports MSVC inline assembly)
1200       AC_TRY_LINK([],[float f;int i; _asm { fld f } ; _asm { fistpl i };],[AC_MSG_RESULT(yes)
1201 AC_DEFINE(GMX_X86_MSVC_INLINE_ASM,,[Enable x86 MSVC inline assembly])],[AC_MSG_RESULT(no)])
1202         ;;              
1203    *) ;;
1204 esac
1205
1206
1207 ############
1208 # Check dlopen
1209 ###########
1210 if test "$with_dlopen" = "yes"; then
1211       AC_MSG_CHECKING(if dlopen supported)
1212       CFLAGS_RET=$CFLAGS
1213       #LDFLAGS="$lt_cv_dlopen_libs $LDFLAGS" #can't make the macro, which is getting lt_cv_dlopen_libs, to work
1214       LDFLAGS_RET=$LDFLAGS
1215       LIBS_RET=$LIBS
1216       if test "$enable_all_static" = "yes"; then  #make sure we test also whether it works static
1217          LDFLAGS="$LDFLAGS -static"
1218       fi
1219       CFLAGS="-I$srcdir/include -DGMX_DLOPEN $CFLAGS"
1220       LIBS="$DLOPEN_LIBS $LIBS"
1221       AC_TRY_LINK([#include "$srcdir/src/gmxlib/vmddlopen.c"],,[
1222         AC_MSG_RESULT([yes])
1223         AC_DEFINE(GMX_DLOPEN,,[Compile with dlopen])
1224         AC_SUBST(DLOPEN_LIBS)
1225       ],[
1226         AC_MSG_RESULT([no])
1227         AC_SUBST(DLOPEN_LIBS,"")
1228       ])
1229       CFLAGS=$CFLAGS_RET
1230       LIBS=$LIBS_RET
1231       LDFLAGS=$LDFLAGS_RET
1232 fi
1233
1234
1235
1236
1237 ########################################################################
1238 # Final output stage
1239 ########################################################################
1240 AS="$CC"
1241 AC_SUBST(ASFLAGS)
1242 AC_SUBST(AS)
1243 AC_SUBST(INCLUDES)          # should be automatic, but doesnt seem to be?
1244
1245 # To tell libraries apart, we use four versions of the name. For instance, libgmx:
1246 # libgmx                single prec, no mpi.
1247 # libgmx_d              double prec, no mpi.
1248 # libgmx_mpi            single prec, mpi.
1249 # libgmx_mpi_d          double prec, mpi.
1250 # However, the non-suffixed names are linked to the _mpi and/or _d suffixed
1251 # ones upon installation if that is the only version available.
1252
1253 AC_ARG_VAR(
1254   [LIBSUFFIX],
1255   [To tell libraries apart, a suffix can be used. This is normally done
1256    automatically during ./configure (_d|_mpi|_mpi_d). But with this
1257    variable you can overwrite it
1258   ]
1259 )
1260 if test -z "${LIBSUFFIX}" ; then
1261   if test "$enable_mpi" = "yes"; then
1262     LIBSUFFIX="_mpi"
1263   fi
1264   if test "$enable_float" = "no"; then
1265     LIBSUFFIX="${LIBSUFFIX}_d"
1266   fi
1267 fi
1268 AC_SUBST(LIBSUFFIX)
1269
1270 # Unless the user has explicitly requested a prefix/suffix/transform, we
1271 # use _d on double precision files. Don't add anything for mpi, but at the
1272 # end we tell the user it is possible and smart to do in some cases!
1273 if test "$program_transform_name" = "s,x,x,"; then
1274   name_transform_provided=no;
1275   if test "$enable_float" = "no"; then
1276     program_transform_name="s,\$\$,_d,"
1277   fi
1278 else
1279   name_transform_provided=yes;
1280 fi
1281
1282
1283 # Use a variable for RPM - this way it can be 
1284 # overridden with make RPM=rpm3 rpm
1285 RPM=rpm
1286 AC_SUBST(RPM)
1287
1288 if test "$enable_fahcore" = "yes"; then  
1289   CPPFLAGS="$CPPFLAGS -I\$(top_srcdir)/../corewrap -include swindirect.h -DFULLINDIRECT -DUSE_FAH_XDR"  
1290   if test "$enable_mpi" = "yes"; then 
1291     CFLAGS="$CFLAGS -DMPI"  
1292   fi
1293 fi
1294 AM_CONDITIONAL([GMX_FAHCORE],[test "$enable_fahcore" = "yes"])
1295
1296
1297 if test "$enable_all_static" = "yes"; then
1298   LDFLAGS="$LDFLAGS -all-static"
1299 fi
1300
1301 # we have asm source, so this is necessary for automake 1.6
1302 CCAS=$CC
1303 CCASFLAGS=$CFLAGS
1304  
1305 AC_SUBST(CCAS)
1306 AC_SUBST(CCASFLAGS)
1307 AC_SUBST(PKG_CFLAGS)
1308
1309 AC_CONFIG_FILES([ Makefile ])
1310 AC_CONFIG_FILES([ src/Makefile ])
1311 AC_CONFIG_FILES([ src/gmxlib/Makefile ])
1312 AC_CONFIG_FILES([ src/gmxlib/libgmx${LIBSUFFIX}.pc:src/gmxlib/libgmx.pc.in ])
1313 AC_CONFIG_FILES([ src/gmxlib/gmx_blas/Makefile ])
1314 AC_CONFIG_FILES([ src/gmxlib/gmx_lapack/Makefile ])
1315 AC_CONFIG_FILES([ src/gmxlib/selection/Makefile ])
1316 AC_CONFIG_FILES([ src/gmxlib/statistics/Makefile ])
1317 AC_CONFIG_FILES([ src/gmxlib/trajana/Makefile ])
1318 AC_CONFIG_FILES([ src/gmxlib/thread_mpi/Makefile ])
1319 AC_CONFIG_FILES([ src/gmxlib/nonbonded/Makefile ])
1320 AC_CONFIG_FILES([ src/gmxlib/nonbonded/nb_kernel_c/Makefile ])
1321 AC_CONFIG_FILES([ src/gmxlib/nonbonded/nb_kernel_ia32_sse/Makefile ])
1322 AC_CONFIG_FILES([ src/gmxlib/nonbonded/nb_kernel_ia32_sse2/Makefile ])
1323 AC_CONFIG_FILES([ src/gmxlib/nonbonded/nb_kernel_x86_64_sse/Makefile ])
1324 AC_CONFIG_FILES([ src/gmxlib/nonbonded/nb_kernel_x86_64_sse2/Makefile ])
1325 AC_CONFIG_FILES([ src/gmxlib/nonbonded/nb_kernel_ppc_altivec/Makefile ])
1326 AC_CONFIG_FILES([ src/gmxlib/nonbonded/nb_kernel_ia64_single/Makefile ])
1327 AC_CONFIG_FILES([ src/gmxlib/nonbonded/nb_kernel_ia64_double/Makefile ])
1328 AC_CONFIG_FILES([ src/gmxlib/nonbonded/nb_kernel_bluegene/Makefile ])
1329 AC_CONFIG_FILES([ src/gmxlib/nonbonded/nb_kernel_power6/Makefile ])
1330 AC_CONFIG_FILES([ src/gmxlib/nonbonded/nb_kernel_f77_single/Makefile ])
1331 AC_CONFIG_FILES([ src/gmxlib/nonbonded/nb_kernel_f77_double/Makefile ])
1332 AC_CONFIG_FILES([ include/Makefile ])
1333 AC_CONFIG_FILES([ include/types/Makefile ])
1334 AC_CONFIG_FILES([ include/thread_mpi/Makefile ])
1335 AC_CONFIG_FILES([ include/thread_mpi/atomic/Makefile ])
1336 AC_CONFIG_FILES([ src/mdlib/Makefile ])
1337 AC_CONFIG_FILES([ src/mdlib/libmd${LIBSUFFIX}.pc:src/mdlib/libmd.pc.in ])
1338 AC_CONFIG_FILES([ src/kernel/Makefile ])
1339 AC_CONFIG_FILES([ src/kernel/libgmxpreprocess${LIBSUFFIX}.pc:src/kernel/libgmxpreprocess.pc.in ])
1340 AC_CONFIG_FILES([ src/tools/Makefile ])
1341 AC_CONFIG_FILES([ src/tools/libgmxana${LIBSUFFIX}.pc:src/tools/libgmxana.pc.in ])
1342 AC_CONFIG_FILES([ src/ngmx/Makefile ])
1343 AC_CONFIG_FILES([ src/contrib/Makefile ])
1344 AC_CONFIG_FILES([ scripts/Makefile ])
1345 AC_CONFIG_FILES([ admin/Makefile ])
1346 AC_CONFIG_FILES([ share/Makefile ])
1347 AC_CONFIG_FILES([ share/tutor/Makefile ])
1348 AC_CONFIG_FILES([ share/tutor/gmxdemo/Makefile ])
1349 AC_CONFIG_FILES([ share/tutor/nmr1/Makefile ])
1350 AC_CONFIG_FILES([ share/tutor/nmr2/Makefile ])
1351 AC_CONFIG_FILES([ share/tutor/water/Makefile ])
1352 AC_CONFIG_FILES([ share/tutor/mixed/Makefile ])
1353 AC_CONFIG_FILES([ share/tutor/methanol/Makefile ])
1354 AC_CONFIG_FILES([ share/tutor/speptide/Makefile ])
1355 AC_CONFIG_FILES([ share/template/Makefile ])
1356 AC_CONFIG_FILES([ share/top/Makefile ])
1357 AC_CONFIG_FILES([ share/top/gmx.ff/Makefile ])
1358 AC_CONFIG_FILES([ share/top/gmx2.ff/Makefile ])
1359 AC_CONFIG_FILES([ share/top/encadv.ff/Makefile ])
1360 AC_CONFIG_FILES([ share/top/encads.ff/Makefile ])
1361 AC_CONFIG_FILES([ share/top/oplsaa.ff/Makefile ])
1362 AC_CONFIG_FILES([ share/top/gromos43a1.ff/Makefile ])
1363 AC_CONFIG_FILES([ share/top/gromos43a2.ff/Makefile ])
1364 AC_CONFIG_FILES([ share/top/gromos45a3.ff/Makefile ])
1365 AC_CONFIG_FILES([ share/top/gromos53a5.ff/Makefile ])
1366 AC_CONFIG_FILES([ share/top/gromos53a6.ff/Makefile ])
1367 AC_CONFIG_FILES([ share/top/charmm27.ff/Makefile ])
1368 AC_CONFIG_FILES([ share/top/amber94.ff/Makefile ])
1369 AC_CONFIG_FILES([ share/top/amber96.ff/Makefile ])
1370 AC_CONFIG_FILES([ share/top/amberGS.ff/Makefile ])
1371 AC_CONFIG_FILES([ share/top/amber99.ff/Makefile ])
1372 AC_CONFIG_FILES([ share/top/amber99sb.ff/Makefile ])
1373 AC_CONFIG_FILES([ share/top/amber99sb-ildn.ff/Makefile ])
1374 AC_CONFIG_FILES([ share/top/amber03.ff/Makefile ])
1375 AC_CONFIG_FILES([ share/html/Makefile ])
1376 AC_CONFIG_FILES([ share/html/images/Makefile ])
1377 AC_CONFIG_FILES([ share/html/online/Makefile ])
1378 AC_CONFIG_FILES([ man/Makefile man/man1/Makefile man/man7/Makefile ])
1379 AC_CONFIG_FILES([ Doxyfile ])
1380 AC_OUTPUT
1381
1382
1383
1384
1385
1386
1387
1388 #########################################################
1389 # Echo some important info, to avoid stupid mistakes
1390 #
1391
1392 if test "$enable_float" = "no" -a "$name_transform_provided" = "no"; then
1393   echo ""
1394   echo "* You are compiling a double precision version of Gromacs -"
1395   echo "  program names will be suffixed with _d to avoid overwriting single"
1396   echo "  precision files. You can override it with --program-suffix"
1397 fi
1398
1399 if test "$name_transform_provided" = "no" -a "$enable_mpi" = "yes"; then
1400   echo ""
1401   echo "* Seems you are compiling with MPI support. You can install the MPI-"
1402   echo "  enabled programs with suffixed names to have both MPI and non-MPI"
1403   echo "  versions. This is useful e.g. on supercomputers where you usually"
1404   echo "  cannot run MPI-linked programs on the login node."
1405   echo "  Set a suffix with e.g. --program-suffix=_mpi (or _mpi_d for double)."
1406   echo "  You only need MPI for mdrun, so if you already have non-MPI stuff"
1407   echo "  installed you can issue make mdrun; make install-mdrun."
1408   echo ""
1409   echo "  WARNING:"
1410   echo "  There are known problems with some MPI implementations:"
1411   echo "             OpenMPI version < 1.4.1" 
1412   echo "             MVAPICH2 version <= 1.4.1"
1413 fi
1414
1415 if test "$enable_shared" = "no"; then
1416   echo ""
1417   echo "* On most platforms you can save 10X space with dynamic libraries, although"
1418   echo "  the binaries might be less portable. Why not try --enable-shared ?"
1419 fi  
1420
1421
1422 if test "$tmpi_atomics" = "no"; then
1423   echo ""
1424   echo "* This compiler+CPU combination doesn't have working atomic operations."
1425   echo "  Thread support will be unbearably slow: the default number of threads"
1426   echo "  is set to 1."
1427   echo "  Atomics should work on all but the most obscure CPU+compiler"
1428   echo "  combinations; if your system is not obscure (like, for example, x86"
1429   echo "  with gcc) please contact the developers."
1430   echo ""
1431 fi
1432
1433