devel-pre-1.0: coin.m4

File coin.m4, 82.1 KB (added by lou, 13 years ago)

BuildTools?/coin.m4, 06.11.28

Line 
1# Copyright (C) 2006 International Business Machines..
2# All Rights Reserved.
3# This file is distributed under the Common Public License.
4#
5## $Id: coin.m4 119 2006-10-18 20:24:24Z andreasw $
6#
7# Author: Andreas Wachter    IBM      2006-04-14
8
9# This file defines the common autoconf macros for COIN
10#
11
12# Check requirements
13AC_PREREQ(2.61)
14
15###########################################################################
16#                           COIN_MAIN_SUBDIRS                             #
17###########################################################################
18
19# This macro sets up the recursion into configure scripts into
20# subdirectories.  Each possible subdirectory should be provided as a
21# new argument to this macro.  The current limit is 10 subdirectories.
22# This automatically also checks for the Data subdirectory.
23
24AC_DEFUN([AC_COIN_MAIN_SUBDIRS],
25[AC_ARG_VAR([COIN_SKIP_PROJECTS],[Set to the subdirectories of projects that should be skipped in the configuration])
26
27m4_ifvaln([$1],[AC_MSG_CHECKING(whether directory $1 is available)
28                coin_skip=no
29                if test x"$COIN_SKIP_PROJECTS" != x; then
30                  for dir in $COIN_SKIP_PROJECTS; do
31                    if test $dir = $1; then
32                      coin_skip=yes
33                    fi
34                  done
35                fi
36                if test $coin_skip = yes; then
37                  AC_MSG_RESULT(skipping)
38                elif test -r $srcdir/$1/configure; then
39                  coin_subdirs="$coin_subdirs $1"
40                  AC_MSG_RESULT(yes)
41                  AC_CONFIG_SUBDIRS($1)
42                else
43                  AC_MSG_RESULT(no)
44                fi])
45m4_ifvaln([$2],[AC_MSG_CHECKING(whether directory $2 is available)
46                coin_skip=no
47                if test x"$COIN_SKIP_PROJECTS" != x; then
48                  for dir in $COIN_SKIP_PROJECTS; do
49                    if test $dir = $2; then
50                      coin_skip=yes
51                    fi
52                  done
53                fi
54                if test $coin_skip = yes; then
55                  AC_MSG_RESULT(skipping)
56                elif test -r $srcdir/$2/configure; then
57                  coin_subdirs="$coin_subdirs $2"
58                  AC_MSG_RESULT(yes)
59                  AC_CONFIG_SUBDIRS($2)
60                else
61                  AC_MSG_RESULT(no)
62                fi])
63m4_ifvaln([$3],[AC_MSG_CHECKING(whether directory $3 is available)
64                coin_skip=no
65                if test x"$COIN_SKIP_PROJECTS" != x; then
66                  for dir in $COIN_SKIP_PROJECTS; do
67                    if test $dir = $3; then
68                      coin_skip=yes
69                    fi
70                  done
71                fi
72                if test $coin_skip = yes; then
73                  AC_MSG_RESULT(skipping)
74                elif test -r $srcdir/$3/configure; then
75                  coin_subdirs="$coin_subdirs $3"
76                  AC_MSG_RESULT(yes)
77                  AC_CONFIG_SUBDIRS($3)
78                else
79                  AC_MSG_RESULT(no)
80                fi])
81m4_ifvaln([$4],[AC_MSG_CHECKING(whether directory $4 is available)
82                coin_skip=no
83                if test x"$COIN_SKIP_PROJECTS" != x; then
84                  for dir in $COIN_SKIP_PROJECTS; do
85                    if test $dir = $4; then
86                      coin_skip=yes
87                    fi
88                  done
89                fi
90                if test $coin_skip = yes; then
91                  AC_MSG_RESULT(skipping)
92                elif test -r $srcdir/$4/configure; then
93                  coin_subdirs="$coin_subdirs $4"
94                  AC_MSG_RESULT(yes)
95                  AC_CONFIG_SUBDIRS($4)
96                else
97                  AC_MSG_RESULT(no)
98                fi])
99m4_ifvaln([$5],[AC_MSG_CHECKING(whether directory $5 is available)
100                coin_skip=no
101                if test x"$COIN_SKIP_PROJECTS" != x; then
102                  for dir in $COIN_SKIP_PROJECTS; do
103                    if test $dir = $5; then
104                      coin_skip=yes
105                    fi
106                  done
107                fi
108                if test $coin_skip = yes; then
109                  AC_MSG_RESULT(skipping)
110                elif test -r $srcdir/$5/configure; then
111                  coin_subdirs="$coin_subdirs $5"
112                  AC_MSG_RESULT(yes)
113                  AC_CONFIG_SUBDIRS($5)
114                else
115                  AC_MSG_RESULT(no)
116                fi])
117m4_ifvaln([$6],[AC_MSG_CHECKING(whether directory $6 is available)
118                coin_skip=no
119                if test x"$COIN_SKIP_PROJECTS" != x; then
120                  for dir in $COIN_SKIP_PROJECTS; do
121                    if test $dir = $6; then
122                      coin_skip=yes
123                    fi
124                  done
125                fi
126                if test $coin_skip = yes; then
127                  AC_MSG_RESULT(skipping)
128                elif test -r $srcdir/$6/configure; then
129                  coin_subdirs="$coin_subdirs $6"
130                  AC_MSG_RESULT(yes)
131                  AC_CONFIG_SUBDIRS($6)
132                else
133                  AC_MSG_RESULT(no)
134                fi])
135m4_ifvaln([$7],[AC_MSG_CHECKING(whether directory $7 is available)
136                coin_skip=no
137                if test x"$COIN_SKIP_PROJECTS" != x; then
138                  for dir in $COIN_SKIP_PROJECTS; do
139                    if test $dir = $7; then
140                      coin_skip=yes
141                    fi
142                  done
143                fi
144                if test $coin_skip = yes; then
145                  AC_MSG_RESULT(skipping)
146                elif test -r $srcdir/$7/configure; then
147                  coin_subdirs="$coin_subdirs $7"
148                  AC_MSG_RESULT(yes)
149                  AC_CONFIG_SUBDIRS($7)
150                else
151                  AC_MSG_RESULT(no)
152                fi])
153m4_ifvaln([$8],[AC_MSG_CHECKING(whether directory $8 is available)
154                coin_skip=no
155                if test x"$COIN_SKIP_PROJECTS" != x; then
156                  for dir in $COIN_SKIP_PROJECTS; do
157                    if test $dir = $8; then
158                      coin_skip=yes
159                    fi
160                  done
161                fi
162                if test $coin_skip = yes; then
163                  AC_MSG_RESULT(skipping)
164                elif test -r $srcdir/$8/configure; then
165                  coin_subdirs="$coin_subdirs $8"
166                  AC_MSG_RESULT(yes)
167                  AC_CONFIG_SUBDIRS($8)
168                else
169                  AC_MSG_RESULT(no)
170                fi])
171m4_ifvaln([$9],[AC_MSG_CHECKING(whether directory $9 is available)
172                coin_skip=no
173                if test x"$COIN_SKIP_PROJECTS" != x; then
174                  for dir in $COIN_SKIP_PROJECTS; do
175                    if test $dir = $9; then
176                      coin_skip=yes
177                    fi
178                  done
179                fi
180                if test $coin_skip = yes; then
181                  AC_MSG_RESULT(skipping)
182                elif test -r $srcdir/$9/configure; then
183                  coin_subdirs="$coin_subdirs $9"
184                  AC_MSG_RESULT(yes)
185                  AC_CONFIG_SUBDIRS($9)
186                else
187                  AC_MSG_RESULT(no)
188                fi])
189m4_ifvaln([$10],[AC_MSG_CHECKING(whether directory $10 is available)
190                coin_skip=no
191                if test x"$COIN_SKIP_PROJECTS" != x; then
192                  for dir in $COIN_SKIP_PROJECTS; do
193                    if test $dir = $10; then
194                      coin_skip=yes
195                    fi
196                  done
197                fi
198                if test $coin_skip = yes; then
199                  AC_MSG_RESULT(skipping)
200                elif test -r $srcdir/$10/configure; then
201                  coin_subdirs="$coin_subdirs $10"
202                  AC_MSG_RESULT(yes)
203                  AC_CONFIG_SUBDIRS($10)
204                else
205                  AC_MSG_RESULT(no)
206                fi])
207]) # AC_COIN_MAIN_SUBDIRS
208
209###########################################################################
210#                        COIN_THIRDPARTY_SUBDIRS                          #
211###########################################################################
212
213# This macro sets up the recursion into the configure script in a
214# subdirectory for compilation of third party code.  The first
215# argument is just the string that appears in the configure output.
216# The second argument is the directory with the configure script, and
217# the third one is a file that should exists in that directory.  If
218# this file does not exist, we assume that the user has not downloaded
219# the code, and we are not going to compile it
220
221AC_DEFUN([AC_COIN_THIRDPARTY_SUBDIRS],
222[AC_MSG_CHECKING(whether code for third party package $1 is available)
223coin_skip=no
224if test x"$COIN_SKIP_PROJECTS" != x; then
225  for dir in $COIN_SKIP_PROJECTS; do
226    if test $dir = $2; then
227      coin_skip=yes
228    fi
229  done
230fi
231if test $coin_skip = yes; then
232  AC_MSG_RESULT(skipping)
233elif test -r $srcdir/$2/$3; then
234  coin_subdirs="$coin_subdirs $2"
235  AC_MSG_RESULT(yes)
236  AC_CONFIG_SUBDIRS($2)
237else
238  AC_MSG_RESULT(no)
239fi
240]) # AC_COIN_THIRDPARTY_SUBDIRS
241
242###########################################################################
243#                           COIN_CHECK_VPATH                              #
244###########################################################################
245
246# This macro sets the variable coin_vpath_config to true if this is a
247# VPATH configuration, otherwise it sets it to false.
248AC_DEFUN([AC_COIN_CHECK_VPATH],
249[AC_MSG_CHECKING(whether this is a VPATH configuration)
250if test `cd $srcdir; pwd` != `pwd`; then
251  coin_vpath_config=yes;
252else
253  coin_vpath_config=no;
254fi
255AC_MSG_RESULT($coin_vpath_config)
256]) # AC_COIN_CHECK_VPATH
257
258###########################################################################
259#                         COIN_PROJECTDIR_INIT                            #
260###########################################################################
261
262# This macro does everything that is required in the early part in the
263# configure script, such as defining a few variables.  This should only
264# be used in the main directory of a project directory (the one under
265# which src is)
266
267AC_DEFUN([AC_COIN_PROJECTDIR_INIT],
268[# Initialize the ADDLIBS variable
269ADDLIBS='-lm'
270AC_SUBST(ADDLIBS)
271
272# Initialize the FADDLIBS variable (which is to be used with a fortran
273# compiler and will not include FLIBS)
274FADDLIBS=
275AC_SUBST(FADDLIBS)
276
277# A useful makefile conditional that is always false
278AM_CONDITIONAL(ALWAYS_FALSE, false)
279
280# We set the following variable so that we know later in AC_COIN_FINALIZE
281# that we are in a project main directory
282coin_projectdir=yes
283]) # AC_COIN_PROJECTDIR_INIT
284
285###########################################################################
286#                          COIN_DEBUG_COMPILE                             #
287###########################################################################
288
289# enable the configure flags --enable-debug and --enable-debug-prjct
290# (where prcjt is the name of the project in lower case) and set the
291# variable coin_debug_compile to true or false This is used by
292# COIN_PROG_CXX, COIN_PROG_CC and COIN_PROG_F77 to determine the
293# compilation flags.  This macro also makes the switches
294# --with-prjct-verbosity and --with-prjct-checklevel available, which
295# define the preprocessor macros COIN_PRJCT_VERBOSITY and
296# COIN_PRJCT_CHECKLEVEL to the specified value (default is 0).
297#
298# The project specific flags are only made available, if one gives the
299# name of the project as first argument to this macro.
300
301AC_DEFUN([AC_COIN_DEBUG_COMPILE],
302[AC_BEFORE([$0],[AC_COIN_PROG_CXX])dnl
303AC_BEFORE([$0],[AC_COIN_PROG_CC])dnl
304AC_BEFORE([$0],[AC_COIN_PROG_F77])dnl
305
306AC_MSG_CHECKING([whether we want to compile in debug mode])
307
308AC_ARG_ENABLE([debug],
309[AC_HELP_STRING([--enable-debug],
310                [compile all projects with debug options tests])],
311[case "${enableval}" in
312   yes) coin_debug_compile=true
313        enable_shared=no
314        ;;
315   no)  coin_debug_compile=false
316        ;;
317   *) AC_MSG_ERROR(bad value ${enableval} for --enable-debug)
318        ;;
319esac],
320[coin_debug_compile=false])
321
322m4_ifvaln([$1],
323[AC_ARG_ENABLE(debug-m4_tolower($1),
324 [AC_HELP_STRING([--enable-debug-m4_tolower($1)],
325                 [compile this project ($1) with debug options])],
326 [case "${enableval}" in
327    yes) coin_debug_compile=true
328         enable_shared=no
329         ;;
330    no)  coin_debug_compile=false
331         ;;
332    *) AC_MSG_ERROR(bad value ${enableval} for --enable-debug-m4_tolower($1))
333         ;;
334 esac],[:])
335]) # m4_ifvaln([$1],
336
337if test $coin_debug_compile = true; then
338  AC_MSG_RESULT([yes])
339else
340  AC_MSG_RESULT([no])
341fi
342
343m4_ifvaln([$1],
344[AC_ARG_WITH(m4_tolower($1)-verbosity,
345             AC_HELP_STRING([--with-m4_tolower($1)-verbosity],
346                            [specify the debug verbosity level for project $1]),
347             [m4_tolower(coin_$1_verbosity)=$withval],
348             [m4_tolower(coin_$1_verbosity)=0])
349 AC_DEFINE_UNQUOTED(m4_toupper(COIN_$1_VERBOSITY),
350                    m4_tolower($coin_$1_verbosity),
351                    [Define to the debug verbosity level (0 is no output)])
352
353 AC_ARG_WITH(m4_tolower($1)-checklevel,
354             AC_HELP_STRING([--with-m4_tolower($1)-checklevel],
355                            [specify the sanity check level for project $1]),
356             [m4_tolower(coin_$1_checklevel)=$withval],
357             [m4_tolower(coin_$1_checklevel)=0])
358 AC_DEFINE_UNQUOTED(m4_toupper(COIN_$1_CHECKLEVEL),
359                    m4_tolower($coin_$1_checklevel),
360                    [Define to the debug sanity check level (0 is no test)])
361
362# We use the following variable to have a string with the upper case
363# version of the project name
364COIN_PRJCT=m4_toupper($1)
365
366]) # m4_ifvaln([$1],
367 
368]) # AC_COIN_DEBUG_COMPILE
369
370###########################################################################
371#                          COIN_MINGW_LD_FIX                              #
372###########################################################################
373
374# This macro is included by any PROG_compiler macro, to set the LD
375# environment variable on MinGW to the correct value (link).
376
377AC_DEFUN([AC_COIN_MINGW_LD_FIX],
378[case $build in
379  *-mingw*)
380    if test "${LD+set}" = set; then :; else
381      LD=link
382    fi
383    ;;
384 esac
385 case $enable_doscompile in
386   msvc|mingw)
387     if test "x${LD+set}" = xset; then :; else
388       LD=link
389     fi
390     ;;
391 esac
392])
393
394###########################################################################
395#                        COIN_ENABLE_DOSCOMPILE                           #
396###########################################################################
397
398# This macro is included by any PROG_compiler macro, to enable the
399# --enable-doscompile option which is to be used when one wants to build an
400# executable under Cygwin which also runs directly under DOS (without requiring
401# Cygwin1.dll). Using --enable-doscompile=msvc will direct configure to use cl
402# and link as the compiler and linker, respectively.  Using --enable-doscompile
403# =mingw will use GCC tools and add the -mno-cygwin flag.  Specifying a bare
404# --enable-doscompile is the same as choosing mingw.
405
406AC_DEFUN([AC_COIN_ENABLE_DOSCOMPILE],
407[AC_REQUIRE([AC_CANONICAL_BUILD])
408 AC_ARG_ENABLE([doscompile],
409  [AC_HELP_STRING([--enable-doscompile],
410                  [Under Cygwin, compile so that executables run under DOS.
411Set to msvc to use cl & link, instead of gcc/g++/ld.
412Set to mingw to use gcc/g++/ld with -mno-cygwin.
413Default when mentioned: mingw. Default when not mentioned: disabled.])],
414  [if test "$enable_doscompile" != no; then
415     case $build in
416       *-cygwin*) ;;
417       *) AC_MSG_ERROR([--enable-doscompile option makes sense only under Cygwin]) ;;
418     esac
419   fi],
420  [enable_doscompile=no])
421 case "$enable_doscompile" in
422   msvc|mingw|no) ;;
423   yes) enable_doscompile=mingw ;;
424   *) AC_MSG_ERROR([Invalid value $enable_doscompile for --enable-doscompile.
425Try configure --help=recursive.])
426      ;;
427  esac
428 AC_MSG_NOTICE([DOS compile style is: $enable_doscompile])
429])
430
431###########################################################################
432#                             COIN_PROG_CXX                               #
433###########################################################################
434
435# Find the compile command by running AC_PROG_CXX (with compiler names
436# for different operating systems) and put it into CXX (unless it was
437# given my the user), and find an appropriate value for CXXFLAGS.  It is
438# possible to provide additional -D flags in the variable CXXDEFS.
439
440AC_DEFUN([AC_COIN_PROG_CXX],
441[AC_REQUIRE([AC_COIN_PROG_CC]) #Let's try if that overcomes configuration problem with VC++ 6.0
442AC_REQUIRE([AC_COIN_ENABLE_DOSCOMPILE])
443AC_LANG_PUSH(C++)
444
445AC_ARG_VAR(CXXDEFS,[Additional -D flags to be used when compiling C++ code.])
446AC_ARG_VAR(ADD_CXXFLAGS,[Additional C++ compiler options])
447AC_ARG_VAR(DBG_CXXFLAGS,[Debug C++ compiler options])
448AC_ARG_VAR(OPT_CXXFLAGS,[Optimize C++ compiler options])
449
450coin_has_cxx=yes
451
452save_cxxflags="$CXXFLAGS"
453
454# Choosing an msvc build under cygwin forces the cl compiler. Arguably one
455# could include g++ as the second choice, but that amounts to changing on the
456# fly to the mingw option.
457
458case $build in
459  *-cygwin* | *-mingw*)
460             if test "$enable_doscompile" = msvc ; then
461               comps="cl"
462             else
463               comps="g++ cl"
464             fi ;;
465  *-darwin*) comps="g++ c++ CC" ;;
466          *) comps="xlC aCC CC g++ c++ pgCC icpc gpp cxx cc++ cl FCC KCC RCC" ;;
467esac
468
469# We delete the cached value, since the test might not have been
470# performed with our choice of compilers earlier
471$as_unset ac_cv_prog_CXX || test "${ac_cv_prog_CXX+set}" != set || { ac_cv_prog_CXX=; export ac_cv_prog_CXX; }
472AC_MSG_NOTICE([C++ compiler candidates: $comps])
473AC_PROG_CXX([$comps])
474if test -z "$CXX" ; then
475  AC_MSG_ERROR([Failed to find a C++ compiler!])
476fi
477
478# Autoconf incorrectly concludes that cl recognises -g. It doesn't.
479case "$CXX" in
480  cl* | */cl*)
481    if test "$ac_cv_prog_cxx_g" = yes ; then
482      ac_cv_prog_cxx_g=no
483      AC_MSG_NOTICE([Overruling autoconf; cl does not recognise -g.])
484    fi ;;
485esac
486CXXFLAGS="$save_cxxflags"
487
488# Check if a project specific CXXFLAGS variable has been set
489if test x$COIN_PRJCT != x; then
490  eval coin_tmp=\${${COIN_PRJCT}_CXXFLAGS+set}
491  if test x$coin_tmp = xset; then
492    eval CXXFLAGS=\${${COIN_PRJCT}_CXXFLAGS}
493  fi
494fi
495
496if test x"$CXXFLAGS" = x; then
497
498# ToDo decide whether we want -DNDEBUG for optimization
499  coin_add_cxxflags=
500  coin_opt_cxxflags=
501  coin_dbg_cxxflags=
502  coin_warn_cxxflags=
503
504  if test "$GXX" = "yes"; then
505    case "$CXX" in
506      icpc* | */icpc*)
507        ;;
508      *)
509# ToDo decide about unroll-loops
510        coin_opt_cxxflags="-O3 -fomit-frame-pointer"
511        coin_add_cxxflags="-pipe"
512        coin_dbg_cxxflags="-g"
513        coin_warn_cxxflags="-pedantic-errors -Wimplicit -Wparentheses -Wreturn-type -Wcast-qual -Wall -Wpointer-arith -Wwrite-strings -Wconversion"
514        if test "$enable_doscompile" != no; then
515          case $build in
516            *-cygwin*)
517              CXXFLAGS="-mno-cygwin"
518              AC_TRY_LINK([],[int i=0; i++;],
519                          [coin_add_cxxflags="-mno-cygwin $coin_add_cxxflags"])
520              CXXFLAGS=
521              ;;
522          esac
523        fi
524    esac
525  fi
526
527  if test -z "$coin_opt_cxxflags"; then
528    case $build in
529      *-cygwin* | *-mingw*)
530        case "$CXX" in
531          # Warning 4996 points to versions of standard library functions that
532          # are `secure'. Generates a huge number of warnings that swamp other
533          # output.
534          cl* | */cl*)
535            coin_opt_cxxflags='-O2'
536            coin_add_cxxflags='-nologo -EHsc -GR -MT -wd4996'
537            coin_dbg_cxxflags='-Z7'
538            ;;
539        esac
540        ;;
541      *-linux-*)
542        case "$CXX" in
543          icpc* | */icpc*)
544            coin_opt_cxxflags="-O3 -ip"
545            coin_add_cxxflags=""
546            coin_dbg_cxxflags="-g"
547            # Check if -i_dynamic is necessary (for new glibc library)
548            CXXFLAGS=
549            AC_TRY_LINK([],[int i=0; i++;],[],
550                        [coin_add_cxxflags="-i_dynamic $coin_add_cxxflags"])
551            ;;
552          pgCC* | */pgCC*)
553            coin_opt_cxxflags="-fast"
554            coin_add_cxxflags="-Kieee -pc 64"
555            coin_dbg_cxxflags="-g"
556            ;;
557        esac
558        ;;
559      *-ibm-*)
560        case "$CXX" in
561          xlC* | */xlC* | mpxlC* | */mpxlC*)
562            coin_opt_cxxflags="-O3 -qarch=auto -qcache=auto -qtune=auto -qmaxmem=-1"
563            coin_add_cxxflags="-bmaxdata:0x80000000 -qrtti=dyna"
564            coin_dbg_cxxflags="-g"
565            ;;
566        esac
567        ;;
568      *-hp-*)
569        case "$CXX" in
570          aCC* | */aCC* )
571            coin_opt_cxxflags="-O"
572            coin_add_cxxflags="-AA"
573            coin_dbg_cxxflags="-g"
574            ;;
575        esac
576        ;;
577      *-sun-*)
578          coin_opt_cxxflags="-O4"
579          coin_dbg_cxxflags="-g"
580        ;;
581    esac
582  fi
583
584  if test "$ac_cv_prog_cxx_g" = yes && test -z "$coin_dbg_cxxflags" ; then
585    coin_dbg_cxxflags="-g"
586  fi
587
588  if test -z "$coin_opt_cxxflags"; then
589    # Try if -O option works if nothing else is set
590    CXXFLAGS=-O
591    AC_TRY_LINK([],[int i=0; i++;],[coin_opt_cxxflags="-O"])
592  fi
593
594  # if PM doesn't want the warning messages, take them out
595  if test x"$coin_skip_warn_cxxflags" = xyes; then
596    coin_warn_cxxflags=
597  fi
598
599  if test x${DBG_CXXFLAGS+set} != xset; then
600    DBG_CXXFLAGS="$coin_dbg_cxxflags $coin_add_cxxflags $coin_warn_cxxflags"
601  fi
602  if test x${OPT_CXXFLAGS+set} != xset; then
603    OPT_CXXFLAGS="$coin_opt_cxxflags $coin_add_cxxflags -DNDEBUG $coin_warn_cxxflags"
604  fi
605
606  DBG_CXXFLAGS="$DBG_CXXFLAGS $ADD_CXXFLAGS $CXXDEFS"
607  OPT_CXXFLAGS="$OPT_CXXFLAGS $ADD_CXXFLAGS $CXXDEFS"
608
609  if test "$coin_debug_compile" = "true"; then
610    CXXFLAGS="$DBG_CXXFLAGS"
611  else
612    CXXFLAGS="$OPT_CXXFLAGS"
613  fi
614else
615  CXXFLAGS="$CXXFLAGS $ADD_CXXFLAGS $CXXDEFS"
616  if test x${DBG_CXXFLAGS+set} != xset; then
617    DBG_CXXFLAGS="$CXXFLAGS"
618  fi
619  if test x${OPT_CXXFLAGS+set} != xset; then
620    OPT_CXXFLAGS="$CXXFLAGS"
621  fi
622fi
623
624# Try if CXXFLAGS works
625save_CXXFLAGS="$CXXFLAGS"
626AC_TRY_LINK([],[int i=0; i++;],[],[CXXFLAGS=])
627if test -z "$CXXFLAGS"; then
628  AC_MSG_WARN([The flags CXXFLAGS="$save_CXXFLAGS" do not work.  I will now just try '-O', but you might want to set CXXFLAGS manually.])
629  CXXFLAGS='-O'
630  AC_TRY_LINK([],[int i=0; i++;],[],[CXXFLAGS=])
631  if test -z "$CXXFLAGS"; then
632    AC_MSG_WARN([This value for CXXFLAGS does not work.  I will continue with empty CXXFLAGS, but you might want to set CXXFLAGS manually.])
633  fi
634fi
635
636AC_MSG_NOTICE([C++ compiler options are: $CXXFLAGS])
637
638AC_ARG_VAR(MPICXX,[C++ MPI Compiler])
639if test x"$MPICXX" = x; then :; else
640  AC_MSG_NOTICE([Will use MPI C++ compiler $MPICXX])
641  CXX="$MPICXX"
642fi
643
644case "$CXX" in
645  cl* | */cl*)
646    AC_COIN_MINGW_LD_FIX
647    ;;
648esac
649
650AC_LANG_POP(C++)
651]) # AC_COIN_PROG_CXX
652
653
654###########################################################################
655#                             COIN_CXXLIBS                                #
656###########################################################################
657
658# Determine the C++ runtime libraries required for linking a C++ library
659# with a Fortran or C compiler.  The result is available in CXXLIBS.
660
661AC_DEFUN([AC_COIN_CXXLIBS],
662[AC_REQUIRE([AC_PROG_CXX])dnl
663AC_LANG_PUSH(C++)
664AC_ARG_VAR(CXXLIBS,[Libraries necessary for linking C++ code with Fortran compiler])
665if test -z "$CXXLIBS"; then
666  if test "$GXX" = "yes"; then
667    case "$CXX" in
668      icpc* | */icpc*)
669        CXXLIBS=""
670        ;;
671      *)
672        CXXLIBS="-lstdc++ -lm" # -lgcc"
673        ;;
674    esac
675  else
676    case $build in
677     *-mingw32 | *-cygwin* )
678      case "$CXX" in
679      cl* | */cl*)
680        CXXLIBS=nothing;;
681      esac;;
682     *-linux-*)
683      case "$CXX" in
684      icpc* | */icpc*)
685        CXXLIBS=""
686             ;;
687      pgCC* | */pgCC*)
688        CXXLIBS="-lstd -lC -lc"
689             ;;
690      esac;;
691    *-ibm-*)
692      CXXLIBS="-lC -lc"
693      ;;
694    *-hp-*)
695      CXXLIBS="-L/opt/aCC/lib -l++ -lstd_v2 -lCsup_v2 -lm -lcl -lc"
696      ;;
697    *-sun-*)
698      CXXLIBS="-lCstd -lCrun"
699    esac
700  fi
701fi
702if test -z "$CXXLIBS"; then
703  AC_MSG_WARN([Could not automatically determine CXXLIBS (C++ link libraries; necessary if main program is in Fortran of C).])
704else
705  AC_MSG_NOTICE([Assuming that CXXLIBS is \"$CXXLIBS\".])
706fi
707if test x"$CXXLIBS" = xnothing; then
708  CXXLIBS=
709fi
710AC_LANG_POP(C++)
711]) # AC_COIN_CXXLIBS
712
713###########################################################################
714#                           COIN_CHECK_HEADER                             #
715###########################################################################
716
717# This macro checks for a header file, but it does so without the
718# standard header.  This avoids warning messages like:
719#
720# configure: WARNING: dlfcn.h: present but cannot be compiled
721# configure: WARNING: dlfcn.h:     check for missing prerequisite headers?
722# configure: WARNING: dlfcn.h: see the Autoconf documentation
723# configure: WARNING: dlfcn.h:     section "Present But Cannot Be Compiled"
724# configure: WARNING: dlfcn.h: proceeding with the preprocessor's result
725# configure: WARNING: dlfcn.h: in the future, the compiler will take precedence
726
727AC_DEFUN([AC_COIN_CHECK_HEADER],
728[if test x"$4" = x; then
729  hdr="#include <$1>"
730else
731  hdr="$4"
732fi
733AC_CHECK_HEADERS([$1],[$2],[$3],[$hdr])
734]) # AC_COIN_CHECK_HEADER
735
736###########################################################################
737#                       COIN_CHECK_CXX_CHEADER                             #
738###########################################################################
739
740# This macro checks for C header files that are used from C++.  For a give
741# stub (e.g., math), it first checks if the C++ library (cmath) is available.
742# If it is, it defines HAVE_CMATH (or whatever the stub is).  If it is not
743# available, it checks for the old C head (math.h) and defines HAVE_MATH_H
744# if that one exists.
745
746AC_DEFUN([AC_COIN_CHECK_CXX_CHEADER],
747[AC_LANG_PUSH(C++)
748AC_COIN_CHECK_HEADER([c$1],[$2],[$3],[$4])
749if test "$ac_cv_header_c$1" != "yes"; then
750  AC_COIN_CHECK_HEADER([$1.h],[$2],[$3],[$4])
751fi
752AC_LANG_POP(C++)
753]) # AC_COIN_CHECK_CXX_CHEADER
754
755###########################################################################
756#                             COIN_PROG_CC                                #
757###########################################################################
758
759# Find the compile command by running AC_PROG_CC (with compiler names
760# for different operating systems) and put it into CC (unless it was
761# given my the user), and find an appropriate value for CFLAGS.  It is
762# possible to provide additional -D flags in the variable CDEFS. See
763# COIN_PROG_CXX for additional comments regarding the cl compiler.
764
765AC_DEFUN([AC_COIN_PROG_CC],
766[AC_REQUIRE([AC_COIN_MINGW_LD_FIX])
767AC_REQUIRE([AC_COIN_ENABLE_DOSCOMPILE])
768AC_LANG_PUSH(C)
769
770# For consistency, we set the C compiler to the same value of the C++
771# compiler, if the C++ is set, but the C compiler isn't (only for CXX=cl)
772if test x"$CXX" != x; then
773  case "$CXX" in
774    cl* | */cl*)
775      if test x"$CC" = x; then
776        CC="$CXX"
777        AC_MSG_WARN([C++ compiler name provided as $CXX, but CC is unset. Setting CC to $CXX])
778      fi
779      ;;
780  esac
781fi
782
783AC_ARG_VAR(CDEFS,[Additional -D flags to be used when compiling C code.])
784AC_ARG_VAR(ADD_CFLAGS,[Additional C compiler options])
785AC_ARG_VAR(DBG_CFLAGS,[Debug C compiler options])
786AC_ARG_VAR(OPT_CFLAGS,[Optimize C compiler options])
787
788coin_has_cc=yes
789
790save_cflags="$CFLAGS"
791case $build in
792  *-cygwin* | *-mingw*)
793             if test "$enable_doscompile" = msvc ; then
794               comps="cl"
795             else
796               comps="gcc cl"
797             fi ;;
798  *-linux-*) comps="xlc gcc cc pgcc icc" ;;
799  *)         comps="xlc_r xlc cc gcc pgcc icc" ;;
800esac
801
802# We delete the cached value, since the test might not have been
803# performed with our choice of compilers earlier
804$as_unset ac_cv_prog_CC || test "${ac_cv_prog_CC+set}" != set || { ac_cv_prog_CC=; export ac_cv_prog_CC; }
805AC_MSG_NOTICE([C compiler candidates: $comps])
806AC_PROG_CC([$comps])
807if test -z "$CC" ; then
808  AC_MSG_ERROR([Failed to find a C compiler!])
809fi
810# Autoconf incorrectly concludes that cl recognises -g. It doesn't.
811case "$CC" in
812  cl* | */cl*)
813    if test "$ac_cv_prog_cc_g" = yes ; then
814      ac_cv_prog_cc_g=no
815      AC_MSG_NOTICE([Overruling autoconf; cl does not recognise -g.])
816    fi ;;
817esac
818CFLAGS="$save_cflags"
819
820# Check if a project specific CFLAGS variable has been set
821if test x$COIN_PRJCT != x; then
822  eval coin_tmp=\${${COIN_PRJCT}_CFLAGS+set}
823  if test x$coin_tmp = xset; then
824    eval CFLAGS=\${${COIN_PRJCT}_CFLAGS}
825  fi
826fi
827
828if test x"$CFLAGS" = x; then
829
830  coin_add_cflags=
831  coin_opt_cflags=
832  coin_dbg_cflags=
833  coin_warn_cflags=
834
835  if test "$GCC" = "yes"; then
836    case "$CC" in
837      icc* | */icc*)
838        ;;
839      *)
840        coin_opt_cflags="-O3 -fomit-frame-pointer"
841        coin_add_cflags="-pipe"
842        coin_dbg_cflags="-g"
843        coin_warn_cflags="-pedantic-errors -Wimplicit -Wparentheses -Wsequence-point -Wreturn-type -Wcast-qual -Wall"
844        if test "$enable_doscompile" != no ; then
845          case $build in
846            *-cygwin*)
847              CFLAGS="-mno-cygwin"
848              AC_TRY_LINK([],[int i=0; i++;],
849                          [coin_add_cflags="-mno-cygwin $coin_add_cflags"])
850              CFLAGS=
851            ;;
852          esac
853        fi
854    esac
855  fi
856  if test -z "$coin_opt_cflags"; then
857    case $build in
858      *-cygwin* | *-mingw*)
859        case "$CC" in
860          cl* | */cl*)
861            coin_opt_cflags='-O2'
862            coin_add_cflags='-nologo -wd4996'
863            coin_dbg_cflags='-Z7'
864            ;;
865        esac
866        ;;
867      *-linux-*)
868        case "$CC" in
869          icc* | */icc*)
870            coin_opt_cflags="-O3 -ip"
871            coin_add_cflags=""
872            coin_dbg_cflags="-g"
873            # Check if -i_dynamic is necessary (for new glibc library)
874            CFLAGS=
875            AC_TRY_LINK([],[int i=0; i++;],[],
876                        [coin_add_cflags="-i_dynamic $coin_add_cflags"])
877            ;;
878          pgcc* | */pgcc*)
879            coin_opt_cflags="-fast"
880            coin_add_cflags="-Kieee -pc 64"
881            coin_dbg_cflags="-g"
882            ;;
883        esac
884        ;;
885      *-ibm-*)
886        case "$CC" in
887          xlc* | */xlc* | mpxlc* | */mpxlc*)
888            coin_opt_cflags="-O3 -qarch=auto -qcache=auto -qtune=auto -qmaxmem=-1"
889            coin_add_cflags="-bmaxdata:0x80000000"
890            coin_dbg_cflags="-g"
891          ;;
892        esac
893        ;;
894      *-hp-*)
895        coin_opt_cflags="-O"
896        coin_add_cflags="-Ae"
897        coin_dbg_cflags="-g"
898        ;;
899      *-sun-*)
900        coin_opt_cflags="-xO4"
901        coin_dbg_cflags="-g"
902        ;;
903      *-sgi-*)
904        coin_opt_cflags="-O -OPT:Olimit=0"
905        coin_dbg_cflags="-g"
906        ;;
907    esac
908  fi
909
910  if test "$ac_cv_prog_cc_g" = yes && test -z "$coin_dbg_cflags" ; then
911    coin_dbg_cflags="-g"
912  fi
913
914  if test -z "$coin_opt_cflags"; then
915    # Try if -O option works if nothing else is set
916    CFLAGS="-O"
917    AC_TRY_LINK([],[int i=0; i++;],[coin_opt_cflags="-O"])
918  fi
919
920  # if PM doesn't want the warning messages, take them out
921  if test x"$coin_skip_warn_cflags" = xyes; then
922    coin_warn_cflags=
923  fi
924
925  if test x${DBG_CFLAGS+set} != xset; then
926    DBG_CFLAGS="$coin_dbg_cflags $coin_add_cflags $coin_warn_cflags"
927  fi
928  if test x${OPT_CFLAGS+set} != xset; then
929    OPT_CFLAGS="$coin_opt_cflags $coin_add_cflags -DNDEBUG $coin_warn_cflags"
930  fi
931
932  DBG_CFLAGS="$DBG_CFLAGS $ADD_CFLAGS $CDEFS"
933  OPT_CFLAGS="$OPT_CFLAGS $ADD_CFLAGS $CDEFS"
934
935  if test "$coin_debug_compile" = "true"; then
936    CFLAGS="$DBG_CFLAGS"
937  else
938    CFLAGS="$OPT_CFLAGS"
939  fi
940else
941  CFLAGS="$CFLAGS $ADD_CFLAGS $CDEFS"
942  if test x${DBG_CFLAGS+set} != xset; then
943    DBG_CFLAGS="$CFLAGS"
944  fi
945  if test x${OPT_CFLAGS+set} != xset; then
946    OPT_CFLAGS="$CFLAGS"
947  fi
948fi
949
950# Check if user wants to have additional CFLAGS options
951AC_ARG_VAR(ADD_CFLAGS,[Additional C compiler options])
952if test x"$ADD_CFLAGS" != x; then
953  CFLAGS="$CFLAGS $ADD_CFLAGS"
954fi
955
956# Try if CFLAGS works
957save_CFLAGS="$CFLAGS"
958AC_TRY_LINK([],[int i=0; i++;],[],[CFLAGS=])
959if test -z "$CFLAGS"; then
960  AC_MSG_WARN([The value CFLAGS="$save_CFLAGS" do not work.  I will now just try '-O', but you might want to set CFLAGS manually.])
961  CFLAGS='-O'
962  AC_TRY_LINK([],[int i=0; i++;],[],[CFLAGS=])
963  if test -z "$CFLAGS"; then
964    AC_MSG_WARN([This value for CFLAGS does not work.  I will continue with empty CFLAGS, but you might want to set CFLAGS manually.])
965  fi
966fi
967
968AC_MSG_NOTICE([C compiler options are: $CFLAGS])
969
970AC_ARG_VAR(MPICC,[C MPI Compiler])
971if test x"$MPICC" = x; then :; else
972  AC_MSG_NOTICE([Will use MPI C compiler $MPICC])
973  CC="$MPICC"
974fi
975
976# Correct ADDLIBS initialization if we are using the MS compiler
977case "$CC" in
978  cl* | */cl*)
979    ADDLIBS=
980    AC_COIN_MINGW_LD_FIX
981    ;;
982esac
983
984AC_LANG_POP(C)
985]) # AC_COIN_PROG_CC
986
987###########################################################################
988#                             COIN_PROG_F77                               #
989###########################################################################
990
991# Find the compile command by running AC_PROG_F77 (with compiler names
992# for different operating systems) and put it into F77 (unless it was
993# given my the user), and find an appropriate value for FFLAGS
994
995AC_DEFUN([AC_COIN_PROG_F77],
996[AC_REQUIRE([AC_COIN_MINGW_LD_FIX])
997AC_REQUIRE([AC_COIN_ENABLE_DOSCOMPILE])
998AC_REQUIRE([AC_COIN_PROG_CC])
999AC_LANG_PUSH([Fortran 77])
1000
1001AC_ARG_VAR(ADD_FFLAGS,[Additional Fortran compiler options])
1002AC_ARG_VAR(DBG_FFLAGS,[Debug Fortran compiler options])
1003AC_ARG_VAR(OPT_FFLAGS,[Optimize Fortran compiler options])
1004
1005coin_has_f77=yes
1006
1007save_fflags="$FFLAGS"
1008case $build in
1009  *-cygwin* | *-mingw*)
1010     if test "$enable_doscompile" = msvc ; then
1011       comps="ifort fl32"
1012     else
1013       comps="gfortran g77 ifort fl32"
1014     fi ;;
1015  *) comps="xlf fort77 gfortran f77 g77 pgf90 pgf77 ifort ifc frt af77" ;;
1016esac
1017
1018# We delete the cached value, since the test might not have been
1019# performed with our choice of compilers earlier
1020$as_unset ac_cv_prog_F77 || test "${ac_cv_prog_F77+set}" != set || { ac_cv_prog_F77=; export ac_cv_prog_F77; }
1021AC_MSG_NOTICE([Fortran compiler candidates: $comps])
1022AC_PROG_F77($comps)
1023if test -z "$F77" ; then
1024  AC_MSG_WARN([Failed to find a Fortran compiler!])
1025fi
1026FFLAGS="$save_fflags"
1027
1028# Check if a project specific FFLAGS variable has been set
1029if test x$COIN_PRJCT != x; then
1030  eval coin_tmp=\${${COIN_PRJCT}_FFLAGS+set}
1031  if test x$coin_tmp = xset; then
1032    eval FFLAGS=\${${COIN_PRJCT}_FFLAGS}
1033  fi
1034fi
1035
1036if test x"$FFLAGS" = x; then
1037
1038  coin_add_fflags=
1039  coin_opt_fflags=
1040  coin_dbg_fflags=
1041  coin_warn_fflags=
1042
1043  if test "$G77" = "yes"; then
1044    coin_opt_fflags="-O3 -fomit-frame-pointer"
1045    coin_add_fflags="-pipe"
1046    coin_dbg_fflags="-g"
1047    if test "$enable_doscompile" != no ; then
1048      case $build in
1049        *-cygwin*)
1050          FFLAGS="-mno-cygwin"
1051          AC_TRY_LINK([],[      write(*,*) 'Hello world'],
1052                      [coin_add_fflags="-mno-cygwin $coin_add_fflags"])
1053          FFLAGS=
1054        ;;
1055      esac
1056    fi
1057  else
1058    case $build in
1059      *-cygwin* | *-mingw*)
1060        case $F77 in
1061          ifort* | */ifort*)
1062            coin_opt_fflags='-O3'
1063            coin_add_fflags='-nologo -MT'
1064            coin_dbg_fflags='-debug'
1065          ;;
1066        esac
1067        ;;
1068      *-linux-*)
1069        case $F77 in
1070          ifc* | */ifc* | ifort* | */ifort*)
1071            coin_opt_fflags="-O3 -ip"
1072            coin_add_fflags="-cm -w90 -w95"
1073            coin_dbg_fflags="-g -CA -CB -CS"
1074            # Check if -i_dynamic is necessary (for new glibc library)
1075            FFLAGS=
1076            AC_TRY_LINK([],[      write(*,*) 'Hello world'],[],
1077                        [coin_add_fflags="-i_dynamic $coin_add_fflags"])
1078            ;;
1079          pgf77* | */pgf77* | pgf90* | */pgf90*)
1080            coin_opt_fflags="-fast"
1081            coin_add_fflags="-Kieee -pc 64"
1082            coin_dbg_fflags="-g"
1083          ;;
1084        esac
1085        ;;
1086      *-ibm-*)
1087        case "$F77" in
1088          xlf* | */xlf* | mpxlf* | */mpxlf* )
1089            coin_opt_fflags="-O3 -qarch=auto -qcache=auto -qtune=auto -qmaxmem=-1"
1090            coin_add_fflags="-bmaxdata:0x80000000"
1091            coin_dbg_fflags="-g -C"
1092            ;;
1093        esac
1094        ;;
1095      *-hp-*)
1096        coin_opt_fflags="+O3"
1097        coin_add_fflags="+U77"
1098        coin_dbg_fflags="-C -g"
1099        ;;
1100      *-sun-*)
1101        coin_opt_fflags="-O4"
1102        coin_dbg_fflags="-g"
1103        ;;
1104      *-sgi-*)
1105        coin_opt_fflags="-O5 -OPT:Olimit=0"
1106        coin_dbg_fflags="-g"
1107        ;;
1108    esac
1109  fi
1110
1111  if test "$ac_cv_prog_f77_g" = yes && test -z "$coin_dbg_fflags" ; then
1112    coin_dbg_fflags="-g"
1113  fi
1114
1115  if test -z "$coin_opt_fflags"; then
1116    # Try if -O option works if nothing else is set
1117    FFLAGS=-O
1118    AC_TRY_LINK([],[      integer i], [coin_opt_fflags="-O"])
1119  fi
1120
1121  # if PM doesn't want the warning messages, take them out
1122  if test x"$coin_skip_warn_fflags" = xyes; then
1123    coin_warn_fflags=
1124  fi
1125
1126  if test x${DBG_FFLAGS+set} != xset; then
1127    DBG_FFLAGS="$coin_dbg_fflags $coin_add_fflags $coin_warn_fflags"
1128  fi
1129  if test x${OPT_FFLAGS+set} != xset; then
1130    OPT_FFLAGS="$coin_opt_fflags $coin_add_fflags $coin_warn_fflags"
1131  fi
1132
1133  DBG_FFLAGS="$DBG_FFLAGS $ADD_FFLAGS"
1134  OPT_FFLAGS="$OPT_FFLAGS $ADD_FFLAGS"
1135
1136  if test "$coin_debug_compile" = "true"; then
1137    FFLAGS="$DBG_FFLAGS"
1138  else
1139    FFLAGS="$OPT_FFLAGS"
1140  fi
1141else
1142  FFLAGS="$FFLAGS $ADD_FFLAGS"
1143  if test x${DBG_FFLAGS+set} != xset; then
1144    DBG_FFLAGS="$FFLAGS"
1145  fi
1146  if test x${OPT_FFLAGS+set} != xset; then
1147    OPT_FFLAGS="$FFLAGS"
1148  fi
1149fi
1150
1151# Try if FFLAGS works
1152AC_TRY_LINK([],[      integer i],[],[FFLAGS=])
1153if test -z "$FFLAGS"; then
1154  AC_MSG_WARN([The flags FFLAGS="$FFLAGS" do not work.  I will now just try '-O', but you might want to set FFLAGS manually.])
1155  FFLAGS='-O'
1156  AC_TRY_LINK([],[      integer i],[],[FFLAGS=])
1157  if test -z "$FFLAGS"; then
1158    AC_MSG_WARN([This value for FFLAGS does not work.  I will continue with empty FFLAGS, but you might want to set FFLAGS manually.])
1159  fi
1160fi
1161
1162AC_MSG_NOTICE([Fortran compiler options are: $FFLAGS])
1163
1164AC_ARG_VAR(MPIF77,[Fortran MPI Compiler])
1165if test x"$MPIF77" = x; then :; else
1166  AC_MSG_NOTICE([Will use MPI Fortran compiler $MPIF77])
1167  F77="$MPIF77"
1168fi
1169
1170case "$F77" in
1171  ifort*)
1172    AC_COIN_MINGW_LD_FIX
1173    ;;
1174esac
1175
1176AC_LANG_POP([Fortran 77])
1177]) # AC_COIN_PROG_F77
1178
1179###########################################################################
1180#                           COIN_F77_WRAPPERS                             #
1181###########################################################################
1182
1183# Calls autoconfs AC_F77_WRAPPERS and does additional corrections to FLIBS
1184
1185AC_DEFUN([AC_COIN_F77_WRAPPERS],
1186[AC_BEFORE([AC_COIN_PROG_F77],[$0])dnl
1187AC_BEFORE([AC_PROG_F77],[$0])dnl
1188
1189AC_LANG_PUSH([Fortran 77])
1190
1191AC_F77_WRAPPERS
1192
1193# This is to correct a missing exclusion in autoconf 2.59
1194if test x"$FLIBS" != x; then
1195  my_flibs=
1196  for flag in $FLIBS; do
1197    case flag in
1198      -lcrt*.o) ;;
1199             *) my_flibs="$my_flibs $flag" ;;
1200    esac
1201  done
1202  FLIBS="$my_flibs"
1203fi
1204
1205case $build in
1206# The following is a fix to define FLIBS for ifort on Windows
1207   *-cygwin* | *-mingw*)
1208     case "$F77" in
1209       ifort* | */ifort*)
1210           FLIBS="-link libifcorert.lib $LIBS /NODEFAULTLIB:libc.lib";;
1211     esac;;
1212   *-hp-*)
1213       FLIBS="$FLIBS -lm";;
1214   *-ibm-*)
1215       FLIBS=`echo $FLIBS | sed 's/-lc)/-lc/g'` ;;
1216   *-linux-*)
1217     case "$F77" in
1218       pgf77* | */pgf77* | pgf90* | */pgf90*)
1219# ask linker to go through the archives multiple times
1220# (the Fortran compiler seems to do that automatically...
1221         FLIBS="-Wl,--start-group $FLIBS -Wl,--end-group" ;;
1222     esac
1223esac
1224
1225]) # AC_COIN_F77_WRAPPERS
1226
1227###########################################################################
1228#                             COIN_FIND_F77                               #
1229###########################################################################
1230
1231# Attempt to preempt autoconf by locating an appropriate F77 program. This
1232# macro will not trigger a fatal error if a suitable compiler cannot be
1233# found. It should be called before COIN_PROG_F77 or COIN_TRY_FLINK.
1234
1235AC_DEFUN([AC_COIN_FIND_F77],
1236[ AC_REQUIRE([AC_COIN_ENABLE_DOSCOMPILE])
1237  case $build in
1238    *-cygwin* | *-mingw*)
1239       if test "$enable_doscompile" = msvc ; then
1240         comps="ifort fl32"
1241       else
1242         comps="gfortran g77 ifort fl32"
1243       fi ;;
1244    *) comps="xlf fort77 gfortran f77 g77 pgf90 pgf77 ifort ifc frt af77" ;;
1245  esac
1246  AC_CHECKING([for presence of a Fortran compiler.])
1247  AC_MSG_NOTICE([Fortran compiler candidates: $comps.])
1248  AC_CHECK_PROGS([F77],[$comps],[unavailable])
1249 
1250  AC_MSG_NOTICE([Setting F77 to "$F77".])
1251])
1252
1253
1254###########################################################################
1255#                          COIN_INIT_AUTOMAKE                             #
1256###########################################################################
1257
1258# This macro calls the regular INIT_AUTOMAKE and MAINTAINER_MODE
1259# macros, and defines additional variables and makefile conditionals,
1260# that are used in the maintainer parts of the makfile.  It also
1261# checks if the correct versions of the autotools are used.
1262#
1263# This also defines the AC_SUBST variables:
1264# abs_source_dir     absolute path to source code for this package
1265# abs_bin_dir        absolute path to the directory where binaries are
1266#                    going to be installed (prefix/bin)
1267# abs_lib_dir        absolute path to the directory where libraries are
1268#                    going to be installed (prefix/lib)
1269# abs_include_dir    absolute path to the directory where the header files
1270#                    are installed (prefix/include)
1271
1272AC_DEFUN([AC_COIN_INIT_AUTOMAKE],
1273[AC_REQUIRE([AC_PROG_EGREP])
1274
1275AC_MSG_NOTICE([Beginning automake initialisation.])
1276# Stuff for automake
1277AM_INIT_AUTOMAKE
1278AM_MAINTAINER_MODE
1279
1280coin_have_externals=no
1281if test "$enable_maintainer_mode" = yes; then
1282
1283  # If maintainer mode is chosen, we make sure that the correct versions
1284  # of the tools are used, and that we know where libtool.m4 is (to
1285  # recreate acinclude.m4)
1286
1287  AC_SUBST(LIBTOOLM4)
1288  LIBTOOLM4=
1289  # Normally, $HOME
1290  AUTOTOOLS_DFLT=$HOME
1291
1292  # Check if we have autoconf
1293  AC_CHECK_PROG([have_autoconf],[autoconf],[yes],[no])
1294  if test $have_autoconf = no; then
1295    AC_MSG_ERROR([You specified you want to use maintainer mode, but I cannot find autoconf in your path.])
1296  fi
1297
1298  # Check whether autoconf is the correct version
1299  correct_version='2.61'
1300  grep_version=`echo  $correct_version | sed -e 's/\\./\\\\\\./g'`
1301  AC_MSG_CHECKING([whether we are using the correct version ($correct_version) of autoconf])
1302  autoconf --version > confauto.out 2>&1
1303  if $EGREP $grep_version confauto.out >/dev/null 2>&1; then
1304    AC_MSG_RESULT([yes])
1305  else
1306    rm -f confauto.out
1307    AC_MSG_RESULT([no])
1308    AC_MSG_ERROR([You don't have the correct version of autoconf as the first one in your path.])
1309  fi
1310  rm -f confauto.out
1311
1312  # Check if the executable autoconf is picked up from the correct location
1313  AC_MSG_CHECKING([whether autoconf is coming from the correct location])
1314  autoconf_dir=`which autoconf | sed -e 's=/autoconf=='`
1315  autoconf_dir=`cd $autoconf_dir; pwd`
1316  if test x$AUTOTOOLS_DIR = x; then
1317    want_dir=$AUTOTOOLS_DFLT/bin
1318  else
1319    want_dir=$AUTOTOOLS_DIR/bin
1320  fi
1321  if test $autoconf_dir = `cd $want_dir; pwd`; then
1322    AC_MSG_RESULT([yes])
1323  else
1324    rm -f confauto.out
1325    AC_MSG_RESULT([no])
1326    AC_MSG_ERROR([The autoconf executable should be picked up from \$AUTOTOOLS_DFLT/bin or \$AUTOTOOLS_DIR/bin.])
1327  fi
1328
1329  # Check if we have automake
1330  AC_CHECK_PROG([have_automake],[automake],[yes],[no])
1331  if test $have_automake = no; then
1332    AC_MSG_ERROR([You specified you want to use maintainer mode, but I cannot find automake in your path.])
1333  fi
1334 
1335  # Check whether automake is the correct version
1336  correct_version='1.9.6'
1337  grep_version=`echo  $correct_version | sed -e 's/\\./\\\\\\./g'`
1338  AC_MSG_CHECKING([whether we are using the correct version ($correct_version) of automake])
1339  automake --version > confauto.out 2>&1
1340  if $EGREP $grep_version confauto.out >/dev/null 2>&1; then
1341    AC_MSG_RESULT([yes])
1342  else
1343    rm -f confauto.out
1344    AC_MSG_RESULT([no])
1345    AC_MSG_ERROR([You don't have the correct version of automake as the first one in your path.])
1346  fi
1347  rm -f confauto.out
1348
1349  # Check if the executable automake is picked up from the correct location
1350  AC_MSG_CHECKING([whether automake is coming from the correct location])
1351  automake_dir=`which automake | sed -e 's=/automake=='`
1352  automake_dir=`cd $automake_dir; pwd`
1353  if test x$AUTOTOOLS_DIR = x; then
1354    want_dir=$AUTOTOOLS_DFLT/bin
1355  else
1356    want_dir=$AUTOTOOLS_DIR/bin
1357  fi
1358  if test $automake_dir = `cd $want_dir; pwd`; then
1359    AC_MSG_RESULT([yes])
1360  else
1361    rm -f confauto.out
1362    AC_MSG_RESULT([no])
1363    AC_MSG_ERROR([The automake executable should be picked up from \$AUTOTOOLS_DFLT/bin or \$AUTOTOOLS_DIR/bin.])
1364  fi
1365
1366  # Check if we can find the libtool file
1367  if test x$AUTOTOOLS_DIR = x; then
1368    want_dir=$AUTOTOOLS_DFLT/share
1369  else
1370    want_dir=$AUTOTOOLS_DIR/share
1371  fi
1372  AC_CHECK_FILE([$want_dir/aclocal/libtool.m4],
1373                [LIBTOOLM4="$want_dir/aclocal/libtool.m4"],
1374                [AC_MSG_ERROR([I cannot find the libtool.m4 file.])])
1375
1376  # Check if this is the correct version of libtool (with escaped dots)
1377  correct_version='1.5.22'
1378  grep_version=`echo  $correct_version | sed -e 's/\\./\\\\\\./g'`
1379  AC_CHECK_FILE([$want_dir/libtool/ltmain.sh],
1380                [have_ltmain=yes],
1381                [have_ltmain=no])
1382  AC_MSG_CHECKING([whether we are using the correct version ($correct_version) of libtool.])
1383  if test $have_ltmain = yes; then
1384    if $EGREP $grep_version $want_dir/libtool/ltmain.sh >/dev/null 2>&1; then
1385      AC_MSG_RESULT([yes])
1386    else
1387      AC_MSG_RESULT([no])
1388      AC_MSG_ERROR([You don't have the correct version of libtool.])
1389    fi
1390  else
1391    AC_MSG_RESULT([no])
1392    AC_MSG_ERROR([I cannot find the ltmain.sh file.])
1393  fi 
1394
1395  # Check if we have an Externals file
1396  if test -r $srcdir/Externals; then
1397    coin_have_externals=yes
1398  fi
1399  # Check if subversion is installed and understands https
1400  AC_CHECK_PROG([have_svn],[svn],[yes],[no])
1401  if test x$have_svn = xyes; then
1402    AC_MSG_CHECKING([svn understands https])
1403    svn --version > confauto.out 2>&1
1404    if $EGREP https confauto.out >/dev/null 2>&1; then
1405      AC_MSG_RESULT(yes)
1406    else
1407      AC_MSG_RESULT(no)
1408      have_svn=no
1409    fi
1410    rm -f confauto.out
1411  fi
1412
1413  # Find the location of the BuildTools directory
1414  BUILDTOOLSDIR=
1415  if test -r $srcdir/BuildTools/coin.m4; then
1416    BUILDTOOLSDIR=$srcdir/BuildTools
1417  else
1418    if test -r $srcdir/../BuildTools/coin.m4; then
1419      BUILDTOOLSDIR=$srcdir/../BuildTools
1420    else
1421      if test -r $srcdir/../../BuildTools/coin.m4; then
1422        BUILDTOOLSDIR=$srcdir/../../BuildTools
1423      else
1424        AC_MSG_ERROR(Cannot find the BuildTools directory)
1425      fi
1426    fi
1427  fi
1428  AC_SUBST(BUILDTOOLSDIR)
1429
1430  # The following variable is set to the name of the directory where
1431  # the autotool scripts are located
1432  AC_SUBST(AUX_DIR)
1433  AUX_DIR=$ac_aux_dir
1434fi
1435
1436# helpful variable for the base directory of this package
1437abs_source_dir=`cd $srcdir; pwd`
1438AC_SUBST(abs_source_dir)
1439
1440# Stuff for example Makefiles
1441if test x$prefix = xNONE; then
1442  full_prefix=$ac_default_prefix
1443else
1444  full_prefix=$prefix
1445fi
1446full_prefix=`cd $full_prefix ; pwd`
1447AC_SUBST(abs_lib_dir)
1448abs_lib_dir=$full_prefix/lib
1449AC_SUBST(abs_include_dir)
1450abs_include_dir=$full_prefix/include
1451AC_SUBST(abs_bin_dir)
1452abs_bin_dir=$full_prefix/bin
1453
1454AM_CONDITIONAL(HAVE_EXTERNALS,
1455               test $coin_have_externals = yes && test x$have_svn = xyes)
1456
1457AC_MSG_NOTICE([End automake initialisation.])
1458
1459]) # AC_COIN_INIT_AUTOMAKE
1460
1461###########################################################################
1462#                         COIN_INIT_AUTO_TOOLS                            #
1463###########################################################################
1464
1465# Initialize the auto tools automake and libtool, with all
1466# modifications we want for COIN packages.
1467#
1468# RPATH_FLAGS        link flags for hardcoding path to shared objects
1469
1470# This is a trick to have this code before AC_COIN_PROG_LIBTOOL
1471AC_DEFUN([AC_COIN_DISABLE_STATIC],
1472[
1473# On Cygwin, building DLLs doesn't work
1474case $build in
1475  *-cygwin*)
1476    coin_disable_shared=yes
1477    platform=Cygwin
1478  ;;
1479  *-mingw*)
1480    coin_disable_shared=yes
1481    platform="Msys"
1482#    case "$CXX" in
1483#      cl*)
1484#        coin_disable_shared=yes
1485#        platform="Msys with cl"
1486#    ;;
1487#    esac
1488  ;;
1489esac
1490if test x"$coin_disable_shared" = xyes; then
1491  if test x"$enable_shared" = xyes; then
1492    AC_MSG_WARN([On $platform, shared objects are not supported. I'm disabling your choice.])
1493  fi
1494  enable_shared=no
1495fi
1496# By default, we only want the shared objects to be compiled
1497AC_DISABLE_STATIC
1498])
1499
1500# Somewhere down in the expansion of this macro, tests are made that involve
1501# the Fortran compiler. If F77 is unset, autoconf will make incorrect
1502# assumptions.
1503
1504AC_DEFUN([AC_COIN_INIT_AUTO_TOOLS],
1505[AC_REQUIRE([AC_COIN_DISABLE_STATIC])
1506 AC_REQUIRE([AC_COIN_FIND_F77])
1507
1508# Initialize automake
1509AC_COIN_INIT_AUTOMAKE
1510
1511# Stuff for libtool
1512AC_COIN_PROG_LIBTOOL
1513
1514# set RPATH_FLAGS to the compiler link flags required to hardcode location
1515# of the shared objects
1516AC_COIN_RPATH_FLAGS($abs_lib_dir)
1517]) # AC_COIN_INIT_AUTO_TOOLS
1518
1519###########################################################################
1520#                           COIN_PROG_LIBTOOL                             #
1521###########################################################################
1522
1523# Setup the libtool stuff together with any modifications to make it
1524# work on additional platforms
1525
1526AC_DEFUN([AC_COIN_PROG_LIBTOOL],
1527[AC_REQUIRE([AC_COIN_DLFCN_H])
1528
1529AC_MSG_NOTICE([Beginning libtool initialisation.])
1530
1531# We check for this header here in a non-standard way to avoid warning
1532# messages
1533AC_PROG_LIBTOOL
1534
1535# Fix bugs in libtool script for Windows native compilation:
1536# - cygpath is not correctly quoted in fix_srcfile_path
1537# - paths generated for .lib files is not run through cygpath -w
1538
1539
1540# - lib includes subdirectory information; we want to replace
1541#
1542# old_archive_cmds="lib /OUT:\$oldlib\$oldobjs\$old_deplibs"
1543#
1544# by
1545#
1546# old_archive_cmds="echo \$oldlib | grep .libs >/dev/null; if test \$? = 0; then cd .libs; lib /OUT:\`echo \$oldlib\$oldobjs\$old_deplibs | sed -e s@\.libs/@@g\`; cd .. ; else lib /OUT:\$oldlib\$oldobjs\$old_deplibs ; fi"
1547#
1548#          -e 's%old_archive_cmds="lib /OUT:\\\$oldlib\\\$oldobjs\\\$old_deplibs"%old_archive_cmds="echo \\\$oldlib \| grep .libs >/dev/null; if test \\\$? = 0; then cd .libs; lib /OUT:\\\`echo \\\$oldlib\\\$oldobjs\\\$old_deplibs \| sed -e s@\\.libs/@@g\\\`; cd .. ; else lib /OUT:\\\$oldlib\\\$oldobjs\\\$old_deplibs; fi"%' \
1549
1550# The following was a hack for chaniing @BACKSLASH to \
1551#          -e 'sYcompile_command=`\$echo "X\$compile_command" | \$Xsed -e '"'"'s%@OUTPUT@%'"'"'"\$output"'"'"'%g'"'"'`Ycompile_command=`\$echo "X\$compile_command" | \$Xsed -e '"'"'s%@OUTPUT@%'"'"'"\$output"'"'"'%g'"'"' | \$Xsed -e '"'"'s%@BACKSLASH@%\\\\\\\\\\\\\\\\%g'"'"'`Y' \
1552
1553# Correct cygpath for minGW (ToDo!)
1554case $build in
1555  *-mingw*)
1556    CYGPATH_W=echo
1557    ;;
1558esac
1559
1560case $build in
1561  *-cygwin* | *-mingw*)
1562  case "$CXX" in
1563    cl* | */cl*)
1564      AC_MSG_NOTICE(Applying patches to libtool for cl compiler)
1565      sed -e 's|fix_srcfile_path=\"`cygpath -w \"\$srcfile\"`\"|fix_srcfile_path=\"\\\`'"$CYGPATH_W"' \\\"\\$srcfile\\\"\\\`\"|' \
1566          -e 's|fix_srcfile_path=\"\"|fix_srcfile_path=\"\\\`'"$CYGPATH_W"' \\\"\\$srcfile\\\"\\\`\"|' \
1567          -e 's%compile_deplibs=\"\$dir/\$old_library \$compile_deplibs\"%compile_deplibs="'\`"$CYGPATH_W"' \$dir/\$old_library | sed -e '"'"'sY\\\\\\\\Y/Yg'"'"\`' \$compile_deplibs\"'% \
1568          -e 's%compile_deplibs=\"\$dir/\$linklib \$compile_deplibs\"%compile_deplibs="'\`"$CYGPATH_W"' \$dir/\$linklib | sed -e '"'"'sY\\\\\\\\Y/Yg'"'"\`' \$compile_deplibs\"'% \
1569          -e 's%lib /OUT:%lib -OUT:%' \
1570          -e "s%cygpath -w%$CYGPATH_W%" \
1571          -e 's%$AR x \\$f_ex_an_ar_oldlib%bla=\\`lib -nologo -list \\$f_ex_an_ar_oldlib | xargs echo\\`; echo \\$bla; for i in \\$bla; do lib -nologo -extract:\\$i \\$f_ex_an_ar_oldlib; done%' \
1572          -e 's/$AR t/lib -nologo -list/' \
1573          -e 's%f_ex_an_ar_oldlib="\($?*1*\)"%f_ex_an_ar_oldlib='\`"$CYGPATH_W"' \1`%' \
1574          -e  's%^archive_cmds=.*%archive_cmds="\\$CC -o \\$lib \\$libobjs \\$compiler_flags \\\\\\`echo \\\\\\"\\$deplibs\\\\\\" | \\$SED -e '"\'"'s/ -lc\\$//'"\'"'\\\\\\` -link -dll~linknames="%' \
1575      libtool > conftest.bla
1576
1577      mv conftest.bla libtool
1578      chmod 755 libtool
1579      ;;
1580    *)
1581      AC_MSG_NOTICE(Applying patches to libtool for GNU compiler)
1582      sed -e 's|fix_srcfile_path=\"`cygpath -w \"\$srcfile\"`\"|fix_srcfile_path=\"\\\`'"$CYGPATH_W"' \\\"\\$srcfile\\\"\\\`\"|' \
1583          -e 's|"lib /OUT:\\$oldlib\\$oldobjs\\$old_deplibs"|"\\$AR \\$AR_FLAGS \\$oldlib\\$oldobjs\\$old_deplibs~\\$RANLIB \\$oldlib"|' \
1584          -e 's|libext="lib"|libext="a"|' \
1585      libtool > conftest.bla
1586
1587      mv conftest.bla libtool
1588      chmod 755 libtool
1589      ;;
1590  esac
1591esac
1592
1593# ToDo
1594# For now, don't use the -no-undefined flag, since the Makefiles are
1595# not yet set up that way.  But we need to fix this, when we want
1596# to comile DLLs under Windows.
1597LT_LDFLAGS=
1598AC_SUBST(LT_LDFLAGS)
1599AC_MSG_NOTICE([End libtool initialisation.])
1600]) # AC_COIN_PROG_LIBTOOL
1601
1602# This is a trick to force the check for the dlfcn header to be done before
1603# the checks for libtool
1604AC_DEFUN([AC_COIN_DLFCN_H],
1605[AC_LANG_PUSH(C)
1606AC_COIN_CHECK_HEADER([dlfcn.h])
1607AC_LANG_POP(C)
1608]) # AC_COIN_DLFCN_H
1609
1610###########################################################################
1611#                            COIN_RPATH_FLAGS                             #
1612###########################################################################
1613
1614# This macro, in case shared objects are used, defines a variable
1615# RPATH_FLAGS that can be used by the linker to hardwire the library
1616# search path for the given directories.  This is useful for example
1617# Makefiles
1618
1619AC_DEFUN([AC_COIN_RPATH_FLAGS],
1620[RPATH_FLAGS=
1621
1622if test $enable_shared = yes; then
1623  case $build in
1624    *-linux-*)
1625      if test "$GXX" = "yes"; then
1626        RPATH_FLAGS=
1627        for dir in $1; do
1628          RPATH_FLAGS="$RPATH_FLAGS -Wl,--rpath -Wl,$dir"
1629        done
1630      fi ;;
1631    *-darwin*)
1632        RPATH_FLAGS=nothing ;;
1633    *-ibm-*)
1634      case "$CXX" in
1635      xlC* | */xlC* | mpxlC* | */mpxlC*)
1636        RPATH_FLAGS=nothing ;;
1637      esac ;;
1638    *-hp-*)
1639        RPATH_FLAGS=nothing ;;
1640    *-mingw32)
1641        RPATH_FLAGS=nothing ;;
1642    *-sun-*)
1643        RPATH_FLAGS=
1644        for dir in $1; do
1645          RPATH_FLAGS="$RPATH_FLAGS -R$dir"
1646        done
1647  esac
1648
1649  if test "$RPATH_FLAGS" = ""; then
1650    AC_MSG_WARN([Could not automatically determine how to tell the linker about automatic inclusion of the path for shared libraries.  The test examples might not work if you link against shared objects.  You will need to set the LD_LIBRARY_PATH, DYLP_LIBRARY_PATH, or LIBDIR variable manually.])
1651  fi
1652  if test "$RPATH_FLAGS" = "nothing"; then
1653    RPATH_FLAGS=
1654  fi
1655fi
1656
1657AC_SUBST(RPATH_FLAGS)
1658]) # AC_COIN_RPATH_FLAGS
1659
1660###########################################################################
1661#                              COIN_FINALIZE                              #
1662###########################################################################
1663
1664# This macro should be called at the very end of the configure.ac file.
1665# It creates the output files (by using AC_OUTPUT), and might do some other
1666# things (such as generating links to data files in a VPATH configuration).
1667# It also prints the "success" message.
1668
1669AC_DEFUN([AC_COIN_FINALIZE],
1670[
1671FADDLIBS="$ADDLIBS"
1672if test x"$coin_need_flibs" = xyes; then
1673  ADDLIBS="$ADDLIBS $FLIBS"
1674fi
1675
1676# library extension
1677AC_SUBST(LIBEXT)
1678case "$CC" in
1679  cl* | */cl*) LIBEXT=lib ;;
1680    *) LIBEXT=a ;;
1681esac
1682
1683# Define VPATH_DISTCLEANFILES to be everything that needs to be
1684# cleaned for distclean in a vpath configuration
1685AC_SUBST(VPATH_DISTCLEANFILES)
1686VPATH_DISTCLEANFILES="$coin_vpath_link_files"
1687
1688AC_OUTPUT
1689
1690if test x"$coin_vpath_link_files" = x; then : ; else
1691  AC_MSG_NOTICE(Creating VPATH links for data files)
1692  for file in $coin_vpath_link_files; do
1693    rm -f $file
1694    $LN_S $abs_source_dir/$file $file
1695  done
1696fi
1697
1698if test x$coin_projectdir = xyes; then
1699  AC_MSG_NOTICE([Configuration of $PACKAGE_NAME successful])
1700else
1701  AC_MSG_NOTICE([Main configuration of $PACKAGE_NAME successful])
1702fi
1703]) #AC_COIN_FINALIZE
1704
1705###########################################################################
1706#                             COIN_VPATH_LINK                             #
1707###########################################################################
1708
1709# This macro makes sure that a symbolic link is created to a file in
1710# the source code directory tree if we are in a VPATH compilation, and
1711# if this package is the main package to be installed
1712
1713AC_DEFUN([AC_COIN_VPATH_LINK],
1714[AC_REQUIRE([AC_COIN_CHECK_VPATH])
1715if test $coin_vpath_config = yes; then
1716  coin_vpath_link_files="$coin_vpath_link_files $1"
1717fi
1718]) #AC_COIN_VPATH_LINK
1719
1720###########################################################################
1721#                       COIN_ENABLE_GNU_PACKAGES                          #
1722###########################################################################
1723
1724# This macro defined the --enable-gnu-packages flag.  This can be used
1725# to check if a user wants to compile GNU packges (such as readline or
1726# zlib) into the executable.  By default, GNU packages are disabled.
1727# This also defines the automake conditional COIN_ENABLE_GNU_PACKAGES
1728
1729AC_DEFUN([AC_COIN_ENABLE_GNU_PACKAGES],
1730[AC_ARG_ENABLE([gnu-packages],
1731               [AC_HELP_STRING([--enable-gnu-packages],
1732                               [compile with GNU packages (disabled by default)])],
1733               [coin_enable_gnu=$enableval],
1734               [coin_enable_gnu=no])
1735]) # AC_COIN_ENABLE_GNU_PACKAGES
1736
1737###########################################################################
1738#                           COIN_CHECK_GNU_ZLIB                           #
1739###########################################################################
1740
1741# This macro checks for the libz library.
1742
1743AC_DEFUN([AC_COIN_CHECK_GNU_ZLIB],
1744[AC_REQUIRE([AC_COIN_ENABLE_GNU_PACKAGES])
1745AC_BEFORE([AC_COIN_PROG_CXX],[$0])
1746AC_BEFORE([AC_COIN_PROG_CC],[$0])
1747AC_BEFORE([AC_COIN_PROG_F77],[$0])
1748AC_BEFORE([$0],[AC_COIN_FINISH])
1749
1750coin_has_zlib=no
1751if test $coin_enable_gnu = yes; then
1752  AC_COIN_CHECK_HEADER([zlib.h],[coin_has_zlib=yes])
1753
1754  if test $coin_has_zlib = yes; then
1755    AC_CHECK_LIB([z],[gzopen],
1756                 [ADDLIBS="-lz $ADDLIBS"],
1757                 [coin_has_zlib=no])
1758  fi
1759
1760  if test $coin_has_zlib = yes; then
1761    AC_DEFINE([COIN_HAS_ZLIB],[1],[Define to 1 if zlib is available])
1762  fi
1763fi
1764
1765AM_CONDITIONAL(COIN_HAS_ZLIB,test x$coin_has_zlib = xyes)
1766]) # AC_COIN_CHECK_GNU_ZLIB
1767
1768
1769###########################################################################
1770#                          COIN_CHECK_GNU_BZLIB                           #
1771###########################################################################
1772
1773# This macro checks for the libbz2 library.
1774
1775AC_DEFUN([AC_COIN_CHECK_GNU_BZLIB],
1776[AC_REQUIRE([AC_COIN_ENABLE_GNU_PACKAGES])
1777AC_BEFORE([AC_COIN_PROG_CXX],[$0])
1778AC_BEFORE([AC_COIN_PROG_CC],[$0])
1779AC_BEFORE([AC_COIN_PROG_F77],[$0])
1780AC_BEFORE([$0],[AC_COIN_FINISH])
1781
1782coin_has_bzlib=no
1783if test $coin_enable_gnu = yes; then
1784  AC_COIN_CHECK_HEADER([bzlib.h],[coin_has_bzlib=yes])
1785
1786  if test $coin_has_bzlib = yes; then
1787    AC_CHECK_LIB([bz2],[BZ2_bzReadOpen],
1788                 [ADDLIBS="-lbz2 $ADDLIBS"],
1789                 [coin_has_bzlib=no])
1790  fi
1791
1792  if test $coin_has_bzlib = yes; then
1793    AC_DEFINE([COIN_HAS_BZLIB],[1],[Define to 1 if bzlib is available])
1794  fi
1795fi
1796]) # AC_COIN_CHECK_GNU_BZLIB
1797
1798
1799###########################################################################
1800#                         COIN_CHECK_GNU_READLINE                         #
1801###########################################################################
1802
1803# This macro checks for GNU's readline.  It verifies that the header
1804# readline/readline.h is available, and that the -lreadline library
1805# contains "readline".  It is assumed that #include <stdio.h> is included
1806# in the source file before the #include<readline/readline.h>
1807
1808AC_DEFUN([AC_COIN_CHECK_GNU_READLINE],
1809[AC_REQUIRE([AC_COIN_ENABLE_GNU_PACKAGES])
1810AC_BEFORE([AC_COIN_PROG_CXX],[$0])
1811AC_BEFORE([AC_COIN_PROG_CC],[$0])
1812AC_BEFORE([AC_COIN_PROG_F77],[$0])
1813AC_BEFORE([$0],[AC_COIN_FINISH])
1814
1815coin_has_readline=no
1816if test $coin_enable_gnu = yes; then
1817  AC_COIN_CHECK_HEADER([readline/readline.h],
1818                       [coin_has_readline=yes],[],
1819                       [#include <stdio.h>])
1820
1821  coin_save_LIBS="$LIBS"
1822  LIBS=
1823  # First we check if tputs and friends are available
1824  if test $coin_has_readline = yes; then
1825    AC_SEARCH_LIBS([tputs],[ncurses termcap curses],[],
1826                   [coin_has_readline=no])
1827  fi
1828
1829  # Now we check for readline
1830  if test $coin_has_readline = yes; then
1831    AC_CHECK_LIB([readline],[readline],
1832                 [ADDLIBS="-lreadline $LIBS $ADDLIBS"],
1833                 [coin_has_readline=no])
1834  fi
1835
1836  if test $coin_has_readline = yes; then
1837    AC_DEFINE([COIN_HAS_READLINE],[1],[Define to 1 if readline is available])
1838  fi
1839
1840  LIBS="$coin_save_LIBS"
1841fi
1842]) # AC_COIN_CHECK_GNU_READLINE
1843
1844###########################################################################
1845#                             COIN_DATA_PATH                              #
1846###########################################################################
1847
1848# This macro defines a preprocessor macro with the absolute path to a
1849# subdirectory of Data.  The argument of this macro is the name of the
1850# subdirectory (in correct case), and the name of the macro is
1851# COIN_DATA_DIR_PATH, where dir is replaced by the capitalized name of
1852# the directory.  The path ends with a separator ("/" for linux and
1853# '\\' for Windows).  The default value for this path can be
1854# overwritten with the input variable with the same name
1855# (COIN_DATA_DIR_PATH).  At this point we chech only for the
1856# $srcdir/../Data subdirectory.
1857
1858AC_DEFUN([AC_COIN_DATA_PATH],
1859[AC_MSG_CHECKING([absolute path to data directory $1])
1860
1861AC_ARG_VAR(m4_toupper(COIN_DATA_$1_PATH),[Set to absolute path to Data/$1 subdirectory])
1862
1863if test x"$m4_toupper(COIN_DATA_$1_PATH)" = x; then
1864  m4_toupper(COIN_DATA_$1_PATH)=`cd $srcdir/../Data/$1; pwd`
1865fi
1866
1867# Under Cygwin, use Windows path.  Add separator
1868case $build in
1869  *-cygwin*)
1870    m4_toupper(COIN_DATA_$1_PATH)=`cygwin -w $m4_toupper(COIN_DATA_$1_PATH)`\\
1871    ;;
1872  *)
1873    m4_toupper(COIN_DATA_$1_PATH)="$m4_toupper(COIN_DATA_$1_PATH)/"
1874    ;;
1875esac
1876
1877if test -r $m4_toupper(COIN_DATA_$1_PATH); then
1878  AC_DEFINE_UNQUOTED(m4_toupper(COIN_DATA_$1_PATH),["$m4_toupper(COIN_DATA_$1_PATH)"],
1879            [Define to absolute path for Data subdirectory $1])
1880  AC_MSG_RESULT($m4_toupper(COIN_DATA_$1_PATH))
1881else
1882  AC_MSG_ERROR(Directory $m4_toupper(COIN_DATA_$1_PATH) does not exist)
1883fi
1884]) # AC_COIN_HAS_DATA
1885
1886###########################################################################
1887#                          COIN_EXAMPLE_FILES                             #
1888###########################################################################
1889
1890# This macro determines the names of the example files (using the
1891# argument in an "ls" command) and sets up the variables EXAMPLE_FILES
1892# and EXAMPLE_CLEAN_FILES.  If this is a VPATH configuration, it also
1893# creates soft links to the example files.
1894
1895AC_DEFUN([AC_COIN_EXAMPLE_FILES],
1896[AC_REQUIRE([AC_COIN_CHECK_GNU_ZLIB])
1897AC_REQUIRE([AC_COIN_CHECK_VPATH])
1898files=`cd $srcdir; ls $1`
1899# We need to do the following loop to make sure that are no newlines
1900# in the variable
1901for file in $files; do
1902  EXAMPLE_FILES="$EXAMPLE_FILES $file"
1903done
1904if test $coin_vpath_config = yes; then
1905  lnkcmd=
1906  if test "$enable_doscompile" != no; then
1907    lnkcmd=cp
1908  fi
1909  case "$CC" in
1910    cl* | */cl*)
1911      lnkcmd=cp ;;
1912  esac
1913  if test "$lnkcmd" = cp; then
1914    AC_MSG_NOTICE([Copying example files ($1)])
1915  else
1916    AC_PROG_LN_S
1917    AC_MSG_NOTICE([Creating links to the example files ($1)])
1918    lnkcmd="$LN_S"
1919  fi
1920  for file in $EXAMPLE_FILES; do
1921    rm -f $file
1922    $lnkcmd $srcdir/$file $file
1923  done
1924  EXAMPLE_CLEAN_FILES='$1'
1925else
1926  EXAMPLE_CLEAN_FILES=
1927fi
1928
1929# In case there are compressed files, we create a variable with the
1930# uncompressed names
1931EXAMPLE_UNCOMPRESSED_FILES=
1932for file in $EXAMPLE_FILES; do
1933  case $file in
1934    *.gz)
1935      EXAMPLE_UNCOMPRESSED_FILES="$EXAMPLE_UNCOMPRESSED_FILES `echo $file | sed -e s/.gz//`"
1936      ;;
1937  esac
1938done
1939
1940AC_SUBST(EXAMPLE_UNCOMPRESSED_FILES)
1941AC_SUBST(EXAMPLE_FILES)
1942AC_SUBST(EXAMPLE_CLEAN_FILES)
1943]) #AC_COIN_EXAMPLE_FILES
1944
1945###########################################################################
1946#                            COIN_HAS_PROJECT                             #
1947###########################################################################
1948
1949# This macro sets up usage of a Coin package.  It defines the
1950# PKGSRCDIR and PKGOBJDIR variables, refering to the main source and
1951# object directory of the package, respectively.  It also defines
1952# a COIN_HAS_PKG preprocessor macro and makefile conditional.  The
1953# argument should be the name (Pkg) of the project (in correct lower
1954# and upper case)
1955
1956AC_DEFUN([AC_COIN_HAS_PROJECT],
1957[AC_MSG_CHECKING([for COIN project $1])
1958
1959# First check, if the sub-project is actually available (ToDo: allow
1960# other locations)
1961
1962m4_tolower(coin_has_$1)=unavailable
1963if test x"$COIN_SKIP_PROJECTS" != x; then
1964  for dir in $COIN_SKIP_PROJECTS; do
1965    if test $dir = $1; then
1966      m4_tolower(coin_has_$1)=skipping
1967    fi
1968  done
1969fi
1970
1971if test $m4_tolower(coin_has_$1) != skipping; then
1972  if test $PACKAGE_TARNAME = m4_tolower($1); then
1973    m4_tolower(coin_has_$1)=.
1974  else
1975    if test -d $srcdir/../$1; then
1976      m4_tolower(coin_has_$1)=../$1
1977    fi
1978  fi
1979fi
1980
1981if test $m4_tolower(coin_has_$1) != unavailable &&
1982   test $m4_tolower(coin_has_$1) != skipping; then
1983  # Set the #define if the component is available
1984  AC_DEFINE(m4_toupper(COIN_HAS_$1),[1],[Define to 1 if the $1 package is used])
1985
1986  # Set the variables for source and object code location
1987  AC_SUBST(m4_toupper($1SRCDIR))
1988  m4_toupper($1SRCDIR)=`cd $srcdir/$m4_tolower(coin_has_$1); pwd`
1989  AC_SUBST(m4_toupper($1OBJDIR))
1990  m4_toupper($1OBJDIR)=`pwd`/$m4_tolower(coin_has_$1)
1991fi
1992
1993  # Define the Makefile conditional
1994AM_CONDITIONAL(m4_toupper(COIN_HAS_$1),
1995               [test $m4_tolower(coin_has_$1) != unavailable &&
1996                test $m4_tolower(coin_has_$1) != skipping])
1997AC_MSG_RESULT([$m4_tolower(coin_has_$1)])
1998]) # AC_COIN_HAS
1999
2000###########################################################################
2001#                        COIN_HAS_USER_LIBRARY                            #
2002###########################################################################
2003
2004# This macro sets up usage of a library with header files.  It defines
2005# the LBRYINCDIR variable, and it defines COIN_HAS_LBRY preprocessor
2006# macro and makefile conditional.  The first argument should be the
2007# full name (LibraryName) of the library, and the second argument (in
2008# upper case letters) the abbreviation (LBRY).  This macro also
2009# introduces the configure arguments --with-libraryname-incdir and
2010# --with-libraryname-lib which have to be both given by a user to use
2011# this solver to tell the configure script where the include files and
2012# the library are located.  Those arguments can also be given as
2013# environement variables LBRYINCDIR and LBRYLIB, but a --with-*
2014# argument overwrites an environment variable.  If a third argument is
2015# given, it is assumed that this is the name of a header file that can
2016# be checked for in the given include directory, and if a fourth
2017# argument is given, it is assumed to be the name of a C function
2018# which is given and defined in the library, and a test is done to
2019# check if that symbol is defined in the library.
2020# If it possible to disable the check, by specifying
2021# --disable-libraryname-libcheck - this is a workaround for platforms
2022# where checks don't work (yet) properly.
2023
2024AC_DEFUN([AC_COIN_HAS_USER_LIBRARY],
2025[AC_REQUIRE([AC_COIN_PROJECTDIR_INIT])
2026AC_MSG_CHECKING(if user provides library for $1)
2027
2028# Check for header file directory
2029AC_ARG_WITH(m4_tolower($1)-incdir,
2030            AC_HELP_STRING([--with-m4_tolower($1)-incdir],
2031                           [specify the directory with the header files for library $1]),
2032                           [$2INCDIR=`cd $withval; pwd`])
2033# Check for library directory
2034AC_ARG_WITH(m4_tolower($1)-lib,
2035            AC_HELP_STRING([--with-m4_tolower($1)-lib],
2036                           [specify the flags to link with the library $1]),
2037                           [$2LIB=$withval])
2038# Switch to disable library check if requested
2039AC_ARG_ENABLE(m4_tolower($1)-libcheck,
2040              AC_HELP_STRING([--enable-m4_tolower($1)-libcheck],
2041                             [use disable-m4_tolower($1)-libcheck to skip the link check at configuration time]),
2042              [m4_tolower($1)_libcheck=$enableval],
2043              [m4_tolower($1)_libcheck=yes])
2044
2045if test x"$$2INCDIR" != x || test x"$$2LIB" != x; then
2046  m4_tolower(coin_has_$2)=true
2047else
2048  m4_tolower(coin_has_$2)=false
2049fi
2050
2051if test $m4_tolower(coin_has_$2) = true; then
2052# Check either both arguments or none are given
2053  if test x"$$2INCDIR" = x || test x"$$2LIB" = x; then
2054    AC_MSG_ERROR([You need to specify both --with-m4_tolower($1)-incdir and --with-m4_tolower($1)-lib if you want to use library $1])
2055  fi
2056  AC_MSG_RESULT(yes)
2057  # Check if the given header file is there
2058  m4_ifvaln([$3],[AC_CHECK_FILE([$$2INCDIR/$3],[],
2059                 [AC_MSG_ERROR([Cannot find file $3 in $$2INCDIR])])])
2060  # Check if the symbol is provided in the library
2061  # ToDo: FOR NOW WE ASSUME THAT WE ARE USING THE C++ COMPILER
2062  m4_ifvaln([$4],[if test x"$m4_tolower($1)_libcheck" != xno; then
2063                    coin_save_LIBS="$LIBS"
2064                    LIBS="$$2LIB $ADDLIBS"
2065                    AC_MSG_CHECKING([whether symbol $4 is available with $2])
2066# ToDo find out what to do about extern "C"
2067#                    AC_TRY_LINK([extern "C" {void $4();}],[$4()],
2068                    AC_TRY_LINK([void $4();],[$4()],
2069                                [AC_MSG_RESULT(yes)],
2070                                [AC_MSG_RESULT(no)
2071                                 AC_MSG_ERROR([Cannot find symbol $4 with $2])])
2072                    LIBS="$coin_save_LIBS"
2073                  fi])
2074  ADDLIBS="$$2LIB $ADDLIBS"
2075  AC_DEFINE(COIN_HAS_$2,[1],[Define to 1 if the $1 package is used])
2076else
2077  AC_MSG_RESULT(no)
2078fi
2079
2080AC_SUBST($2INCDIR)
2081AC_SUBST($2LIB)
2082AM_CONDITIONAL(COIN_HAS_$2,
2083               test $m4_tolower(coin_has_$2) = true)
2084]) #AC_COIN_HAS_SOLVER
2085
2086###########################################################################
2087#                               COIN_HAS_ASL                              #
2088###########################################################################
2089
2090# This macro checks if the user has provide arguments that say where
2091# the precompiled ASL files should be found (with the --with-asldir
2092# flag).  If this is not the case, we check if the ThirdParty/ASL
2093# directory has been configured, which indicates that the files will
2094# be in that directory and can be used.
2095
2096AC_DEFUN([AC_COIN_HAS_ASL],
2097[coin_aslobjdir=../ThirdParty/ASL
2098coin_aslsrcdir=$srcdir/$coin_aslobjdir
2099
2100# Determine the name of the ASL library
2101case "$CXX" in
2102  cl* | */cl*)
2103    ampllib=amplsolv.lib ;;
2104  *)
2105    ampllib=amplsolver.a ;;
2106esac
2107
2108AC_ARG_WITH([asldir],
2109            AC_HELP_STRING([--with-asldir],
2110                           [specify path to AMPL solver directory (or BUILD for compilation, or "no" for disabling AMPL)]),
2111            [use_asldir=$withval], [use_asldir=])
2112
2113if test "$use_asldir" = BUILD; then
2114  AC_CHECK_FILE([$coin_aslobjdir/Makefile],[],
2115                [AC_MSG_ERROR([option \"BUILD\" specified for asldir, but directory is not configure (sources missing?)])])
2116elif test -z "$use_asldir"; then
2117 # try to find sources - if not given don't compile
2118  AC_CHECK_FILE([$coin_aslobjdir/Makefile],[use_asldir=BUILD],[use_asldir=no])
2119elif test "$use_asldir" != "no"; then
2120  AC_CHECK_FILE([$use_asldir/$ampllib],[],
2121                [AC_MSG_ERROR([ASL directory \"$use_asldir\" specified, but library missing])])
2122  AC_CHECK_FILE([$use_asldir/asl.h],[],
2123                [AC_MSG_ERROR([ASL directory \"$use_asldir\" specified, but header files are missing])])
2124  use_asldir=`cd $use_asldir; pwd`
2125  case $build in
2126    *-cygwin*) use_asldir=`cygpath -w $use_asldir | sed -e sX\\\\\\\\X/Xg` ;;
2127  esac
2128fi
2129
2130# Variable containing ASL library (including full path)
2131AC_SUBST(ASLLIB)
2132# Variable containing flags for including ASL header files
2133AC_SUBST(ASL_CPPFLAGS)
2134
2135if test "$use_asldir" = BUILD; then
2136  coin_aslobjdir=`cd $coin_aslobjdir; pwd`
2137  ASLLIB=`$CYGPATH_W $coin_aslobjdir/$ampllib | sed -e sX\\\\\\\\X/Xg`
2138  coin_aslsrcdir=`cd $coin_aslsrcdir; pwd`
2139  ASL_CPPFLAGS="-I"`$CYGPATH_W $coin_aslobjdir | sed -e sX\\\\\\\\X/Xg`" -I"`$CYGPATH_W $coin_aslsrcdir/solvers | sed -e sX\\\\\\\\X/Xg`
2140elif test "$use_asldir" != no; then
2141  ASLLIB=`$CYGPATH_W $use_asldir/$ampllib | sed -e sX\\\\\\\\X/Xg`
2142  ASL_CPPFLAGS="-I"`$CYGPATH_W $use_asldir | sed -e sX\\\\\\\\X/Xg`
2143fi
2144
2145if test "$use_asldir" != no; then
2146  AC_CHECK_LIB(dl,[dlopen],[ASLLIB="$ASLLIB -ldl"],[])
2147  coin_has_asl=yes
2148  AC_DEFINE([COIN_HAS_ASL],[1],
2149            [If defined, the Ampl Solver Library is available.])
2150else
2151  coin_has_asl=no
2152fi
2153AM_CONDITIONAL(COIN_HAS_ASL, test $coin_has_asl = yes)
2154]) # AC_COIN_HAS_ASL
2155
2156###########################################################################
2157#                            COIN_TRY_FLINK                               #
2158###########################################################################
2159
2160# Auxilliary macro to test if a Fortran function name can be linked,
2161# given the current settings of LIBS.  We determine from the context, what
2162# the currently active programming language is, and cast the name accordingly.
2163# The first argument is the name of the function/subroutine, in small letters,
2164# the second argument are the actions taken when the test works, and the
2165# third argument are the actions taken if the test fails.
2166
2167AC_DEFUN([AC_COIN_TRY_FLINK],
2168[case $ac_ext in
2169  f)
2170    AC_TRY_LINK([],[      call $1],[$2],[$3])
2171    ;;
2172  c)
2173    AC_F77_FUNC($1,cfunc$1)
2174    if test x"$coin_need_flibs" = xyes; then
2175      flink_try=no;
2176    else
2177      AC_TRY_LINK([void $cfunc$1();],[$cfunc$1()],
2178                  [flink_try=yes],[flink_try=no])
2179    fi
2180    if test $flink_try = yes; then
2181      $2
2182    else
2183      if test x"$FLIBS" != x; then
2184        flink_save_libs="$LIBS"
2185        LIBS="$LIBS $FLIBS"
2186        AC_TRY_LINK([void $cfunc$1();],[$cfunc$1()],
2187                    [LIBS="$flink_save_libs"
2188                     $2
2189                     coin_need_flibs=yes],
2190                    [LIBS="$flink_save_libs"
2191                     $3])
2192      else
2193        $3
2194      fi
2195    fi
2196    ;;
2197  cc|cpp)
2198    AC_F77_FUNC($1,cfunc$1)
2199    if test x"$coin_need_flibs" = xyes; then
2200      flink_try=no;
2201    else
2202      AC_TRY_LINK([extern "C" {void $cfunc$1();}],[$cfunc$1()],
2203                  [flink_try=yes],[flink_try=no])
2204    fi
2205    if test $flink_try = yes; then
2206      $2
2207    else
2208      if test x"$FLIBS" != x; then
2209        flink_save_libs="$LIBS"
2210        LIBS="$LIBS $FLIBS"
2211        AC_TRY_LINK([extern "C" {void $cfunc$1();}],[$cfunc$1()],
2212                    [LIBS="$flink_save_libs"
2213                     $2
2214                     coin_need_flibs=yes],
2215                    [LIBS="$flink_save_libs"
2216                     $3])
2217      else
2218        $3
2219      fi
2220    fi
2221    ;;
2222esac
2223]) # AC_COIN_TRY_FLINK
2224
2225###########################################################################
2226#                             COIN_HAS_BLAS                               #
2227###########################################################################
2228
2229# This macro checks for a library containing the BLAS library.  It tries
2230# standard libraries, and if none is found to be working, it checks whether the
2231# BLAS ThirdParty/Blas directory has been configured.  It adds to ADDLIBS any
2232# flags required to link with an externally provided BLAS.  It defines the
2233# makefile conditional and preprocessor macro COIN_HAS_BLAS, if BLAS is
2234# available, and it defines the makefile conditional COIN_BUILD_BLAS, if BLAS
2235# is compiled within COIN.
2236
2237# This macro will trigger a hard failure of configure if basic operational
2238# tests fail for the Fortran compiler. The failure originates in autoconf
2239# boilerplate.
2240
2241AC_DEFUN([AC_COIN_HAS_BLAS],
2242[coin_blasobjdir=../ThirdParty/Blas
2243 coin_blassrcdir=$srcdir/$coin_blasobjdir
2244
2245AC_ARG_WITH([blas],
2246            AC_HELP_STRING([--with-blas],
2247                           [specify BLAS library (or BUILD for compilation)]),
2248            [use_blas=$withval], [use_blas=])
2249
2250# Check if user supplied option makes sense
2251if test x"$use_blas" != x; then
2252  if test "$use_blas" = "BUILD"; then
2253    AC_CHECK_FILE([$coin_blasobjdir/Makefile],[],
2254                  [AC_MSG_ERROR([option \"BUILD\" specified for Blas, but $coin_blasobjdir directory is not configured])])
2255  elif test "$use_blas" != no ; then
2256    AC_MSG_CHECKING([whether user supplied BLASLIB=\"$use_blas\" works])
2257    LIBS="$use_blas $LIBS"
2258    ADDLIBS="$use_blas $ADDLIBS"
2259    AC_COIN_TRY_FLINK([daxpy],
2260                      [AC_MSG_RESULT([yes])],
2261                      [AC_MSG_RESULT([no])
2262                       AC_MSG_ERROR([user supplied BLAS library \"$use_blas\" does not work])])
2263  fi
2264else
2265# Try to autodetect the library for blas based on build system
2266  AC_MSG_CHECKING([default locations for BLAS])
2267  case $build in
2268    *-sgi-*)
2269      SAVE_LIBS="$LIBS"
2270      AC_MSG_CHECKING([whether -lcomplib.sgimath has BLAS])
2271      LIBS="-lcomplib.sgimath $LIBS"
2272      AC_COIN_TRY_FLINK([daxpy],
2273                        [AC_MSG_RESULT([yes])
2274                         use_blas=-lcomplib.sgimath;
2275                         ADDLIBS="-lcomplib.sgimath $ADDLIBS"],
2276                        [AC_MSG_RESULT([no])
2277                         SAVE_LIBS="$LIBS"])
2278      ;;
2279    *-sun-*)
2280      SAVE_LIBS="$LIBS"
2281      AC_MSG_CHECKING([whether -xlic_lib=sunperf has BLAS])
2282      LIBS="-xlic_lib=sunperf $LIBS"
2283      AC_COIN_TRY_FLINK([daxpy],
2284                        [AC_MSG_RESULT([yes])
2285                         use_blas='-xlic_lib=sunperf'
2286                         ADDLIBS="-xlic_lib=sunperf $ADDLIBS"],
2287                        [AC_MSG_RESULT([no])
2288                         LIBS="$SAVE_LIBS"])
2289      ;;
2290# On cygwin, consider -lblas only if doscompile is disabled. The prebuilt
2291# library will want to link with cygwin, hence won't run standalone in DOS.
2292    *-cygwin*)
2293      if test "$enable_doscompile" = no; then
2294        if test -z "$use_blas"; then
2295          SAVE_LIBS="$LIBS"
2296          AC_MSG_CHECKING([whether -lblas has BLAS])
2297          LIBS="-lblas $LIBS"
2298          AC_COIN_TRY_FLINK([daxpy],
2299                            [AC_MSG_RESULT([yes])
2300                             ADDLIBS="-lblas $ADDLIBS"
2301                             use_blas='-lblas'],
2302                            [AC_MSG_RESULT([no])
2303                             LIBS="$SAVE_LIBS"])
2304        fi
2305      fi
2306      ;;
2307    esac
2308
2309# If we have no other ideas, consider building BLAS.
2310  if test -z "$use_blas"; then
2311    AC_MSG_CHECKING([if BLAS can be built.])
2312    AC_CHECK_FILE([$coin_blasobjdir/Makefile],[use_blas=BUILD])
2313  fi
2314fi
2315
2316AM_CONDITIONAL([COIN_HAS_BLAS],[test x"$use_blas" != x])
2317AM_CONDITIONAL([COIN_BUILD_BLAS],[test "$use_blas" = BUILD])
2318
2319if { test x"$use_blas" = x || test "$use_blas" = no ; } ; then
2320  coin_has_blas=no
2321else
2322  coin_has_blas=yes
2323  AC_DEFINE([COIN_HAS_BLAS],[1],
2324            [If defined, the BLAS Library is available.])
2325fi
2326]) # AC_COIN_HAS_BLAS
2327
2328###########################################################################
2329#                            COIN_HAS_LAPACK                              #
2330###########################################################################
2331
2332# This macro checks for a library containing the LAPACK library.  It tries
2333# standard libraries, and if none is found to be working, it checks whether the
2334# LAPACK ThirdParty/Lapack directory has been configured.  It adds to ADDLIBS
2335# any flags required to link with an externally provided LAPACK.  It defines
2336# the makefile conditional and preprocessor macro COIN_HAS_LAPACK, if lapack is
2337# available, and it defines the makefile conditional COIN_BUILD_LAPACK, if
2338# lapack is compiled within COIN.
2339
2340# This macro will trigger a hard failure of configure if basic operational
2341# tests fail for the Fortran compiler. The failure originates in autoconf
2342# boilerplate.
2343
2344AC_DEFUN([AC_COIN_HAS_LAPACK],
2345[coin_lapackobjdir=../ThirdParty/Lapack
2346 coin_lapacksrcdir=$srcdir/$coin_lapackobjdir
2347
2348AC_ARG_WITH([lapack],
2349            AC_HELP_STRING([--with-lapack],
2350                           [specify LAPACK library (or BUILD for compilation)]),
2351            [use_lapack=$withval], [use_lapack=])
2352
2353# Check if user supplied option makes sense
2354if test x"$use_lapack" != x; then
2355  if test "$use_lapack" = "BUILD"; then
2356    AC_CHECK_FILE([$coin_lapackobjdir/Makefile],[],
2357                  [AC_MSG_ERROR([option \"BUILD\" specified for LAPACK, but $coin_lapackobjdir directory is not configured])])
2358  else
2359    AC_MSG_CHECKING([whether user supplied LAPACKLIB=\"$use_lapack\" works])
2360    LIBS="$use_lapack $LIBS"
2361    ADDLIBS="$use_lapack $ADDLIBS"
2362    AC_COIN_TRY_FLINK([dsyev],
2363                      [AC_MSG_RESULT([yes])],
2364                      [AC_MSG_RESULT([no])
2365                       AC_MSG_ERROR([user supplied LAPACK library \"$use_lapack\" does not work])])
2366  fi
2367else
2368  if test x$coin_has_blas = xyes; then
2369    # First try to see if LAPACK is already available with BLAS library
2370    AC_MSG_CHECKING([whether LAPACK is already available with BLAS library])
2371    AC_COIN_TRY_FLINK([dsyev],
2372                      [AC_MSG_RESULT([yes]); use_lapack=ok],
2373                      [AC_MSG_RESULT([no])])
2374  fi
2375  if test -z "$use_lapack"; then
2376    # Try to autodetect the library for lapack based on build system
2377    case $build in
2378      *-sgi-*)
2379        SAVE_LIBS="$LIBS"
2380        AC_MSG_CHECKING([whether -lcomplib.sgimath has LAPACK])
2381        LIBS="-lcomplib.sgimath $LIBS"
2382        AC_COIN_TRY_FLINK([dsyev],
2383                          [AC_MSG_RESULT([yes])
2384                           use_lapack=-lcomplib.sgimath;
2385                           ADDLIBS="-lcomplib.sgimath $ADDLIBS"],
2386                          [AC_MSG_RESULT([no])
2387                           SAVE_LIBS="$LIBS"])
2388        ;;
2389      *-sun-*)
2390        SAVE_LIBS="$LIBS"
2391        AC_MSG_CHECKING([whether -xlic_lib=sunperf has LAPACK])
2392        LIBS="-xlic_lib=sunperf $LIBS"
2393        AC_COIN_TRY_FLINK([dsyev],
2394                          [AC_MSG_RESULT([yes])
2395                           use_lapack='-xlic_lib=sunperf'
2396                           ADDLIBS="-xlic_lib=sunperf $ADDLIBS"],
2397                          [AC_MSG_RESULT([no])
2398                           LIBS="$SAVE_LIBS"])
2399        ;;
2400# On cygwin, do this check only if doscompile is disabled. The prebuilt library
2401# will want to link with cygwin, hence won't run standalone in DOS.
2402      *-cygwin*)
2403        if test "$enable_doscompile" = no; then
2404          if test -z "$use_lapack"; then
2405            SAVE_LIBS="$LIBS"
2406            AC_MSG_CHECKING([whether -llapack has LAPACK])
2407            LIBS="-llapack $LIBS"
2408            AC_COIN_TRY_FLINK([dsyev],
2409                              [AC_MSG_RESULT([yes])
2410                               ADDLIBS="-llapack $ADDLIBS"
2411                               use_lapack='-llapack'],
2412                              [AC_MSG_RESULT([no])
2413                               LIBS="$SAVE_LIBS"])
2414          fi
2415        fi
2416        ;;
2417    esac
2418  fi
2419# If we have no other ideas, consider building LAPACK.
2420  if test -z "$use_lapack"; then
2421    AC_CHECK_FILE([$coin_lapackobjdir/Makefile],[use_lapack=BUILD])
2422  fi
2423fi
2424
2425AM_CONDITIONAL([COIN_HAS_LAPACK],[test x"$use_lapack" != x])
2426AM_CONDITIONAL([COIN_BUILD_LAPACK],[test "$use_lapack" = BUILD])
2427
2428if test x"$use_lapack" = x; then
2429  coin_has_lapack=no
2430else
2431  coin_has_lapack=yes
2432  AC_DEFINE([COIN_HAS_LAPACK],[1],
2433            [If defined, the LAPACK Library is available.])
2434fi
2435]) # AC_COIN_HAS_LAPACK