Fixed minor config bug
[baltrad-wrwp.git] / configure.in
1 dnl     This file is an input file used by the GNU "autoconf" program to
2 dnl     generate the file "configure", which is run during bRopo
3 dnl     installation to configure the system for the local environment.
4
5 AC_INIT([baltrad-wrwp],[0.1])
6
7 if test "${prefix}" = "NONE"; then
8         prefix=/opt/baltrad/baltrad-wrwp
9 fi
10
11 AC_PROG_RANLIB
12 AC_PROG_CC
13 AC_PROG_CPP
14 AC_SUBST(AR)
15 AC_CHECK_PROGS(AR, ar aal, ar)
16
17 LIBS=-lm
18
19 dnl First verify that we have a proper rave installation. We can not live without it
20 dnl
21 RAVE_ROOT_DIR=
22 RAVE_INCLUDE_FLAG=
23 RAVE_LIB_FLAG=
24 AC_ARG_WITH(rave,[  --with-rave=ROOT  The RAVE root installation directory],
25      ,withval=yes)
26 case $withval in
27   no)
28     AC_MSG_ERROR(You cannot remove dependencies to RAVE);
29     ;;
30   *)
31     AC_MSG_CHECKING(for RAVE installation)
32     TMPDIR=
33     if [[ "yes" = "$withval" ]]; then
34       TMPFIL=`python -c "import _rave; print eval(\"_rave.__\"+\"file__\")" 2>&1 | head -1`
35       if [[ -f "$TMPFIL" ]]; then
36         TMPDIR=`echo "$TMPFIL" | sed -e"s/\/Lib\/_rave\.so//"`
37       fi
38     else
39       if [[ -d "$withval" -a -f "$withval/Lib/_rave.so" ]]; then
40         TMPDIR=$withval
41       fi
42     fi
43     if [[ "$TMPDIR" = "" ]]; then
44       AC_MSG_RESULT(not found)
45     else
46       AC_MSG_RESULT(found)
47       RAVE_ROOT_DIR=$TMPDIR
48     fi    
49     ;;
50 esac
51
52 if [[ "$RAVE_ROOT_DIR" = "" ]]; then
53   AC_MSG_ERROR("Could not identify a RAVE installation")
54 fi
55
56 AC_MSG_CHECKING(existance of RAVE build configuration)
57 if [[ -f "$RAVE_ROOT_DIR/mkf/def.mk" ]]; then
58   RAVE_INCLUDE_FLAG=-I$RAVE_ROOT_DIR/include
59   RAVE_LIB_FLAG=-L$RAVE_ROOT_DIR/lib
60   AC_MSG_RESULT(found)
61 else
62   AC_MSG_RESULT(not found);
63   AC_MSG_FAILURE(The RAVE installation does not contain def.mk. Is this an old installation);
64 fi
65
66 dnl Now we should extract some variables from raves def.mk file to give user a possibility to change
67 dnl then when necessary
68 AC_MSG_CHECKING(for RAVE cc compiler)
69 RAVECC=`cat $RAVE_ROOT_DIR/mkf/def.mk | sed -n "/^CC=/p" | sed -n -e"s/^CC=[[ \t]]*\(.*\)/\1/p"`
70 AC_MSG_RESULT($RAVECC)
71
72 AC_MSG_CHECKING(for RAVE cc options)
73 RAVECCOPTS=`cat $RAVE_ROOT_DIR/mkf/def.mk | sed -n "/^OPTS=/p" | sed -n -e"s/^OPTS=[[   ]]*\(.*\)/\1/p"`
74 AC_MSG_RESULT($RAVECCOPTS)
75
76 dnl Remove strict prototype from cc options
77 dnl
78 AC_MSG_CHECKING(for cpp options)
79 CPPOPTS=`echo "$RAVECCOPTS" | sed -e "s/-Wstrict-prototypes//"`
80 AC_MSG_RESULT($CPPOPTS)
81
82 AC_MSG_CHECKING(for RAVE ld flags)
83 RAVELDFLAGS=`cat $RAVE_ROOT_DIR/mkf/def.mk | sed -n "/^LDFLAGS=/p" | sed -n -e"s/^LDFLAGS=[[    ]]*\(.*\)/\1/p"`
84 AC_MSG_RESULT($RAVELDFLAGS)
85
86 AC_MSG_CHECKING(for RAVE shared flag)
87 RAVECCSHARED=`cat $RAVE_ROOT_DIR/mkf/def.mk | sed -n "/^CCSHARED=/p" | sed -n -e"s/^CCSHARED=[[         ]]*\(.*\)/\1/p"`
88 AC_MSG_RESULT($RAVECCSHARED)
89
90 AC_MSG_CHECKING(for Python include flag)
91 PYTHON_INCLUDE_FLAG=`cat $RAVE_ROOT_DIR/mkf/def.mk | sed -n "/^INCLUDE_PYTHON=/p" | sed -n -e"s/^INCLUDE_PYTHON=[[      ]]*\(.*\)/\1/p"`
92 AC_MSG_RESULT($INCLUDE_PYTHON)
93
94 AC_MSG_CHECKING(for numpy include flag)
95 NUMPY_INCLUDE_FLAG=`cat $RAVE_ROOT_DIR/mkf/def.mk | sed -n "/^NUMPY_INCLUDE_DIR=/p" | sed -n -e"s/^NUMPY_INCLUDE_DIR=[[         ]]*\(.*\)/\1/p"`
96 AC_MSG_RESULT($PROJ_INCLUDE_FLAG)
97
98 AC_MSG_CHECKING(for proj include flag used by RAVE)
99 PROJ_INCLUDE_FLAG=`cat $RAVE_ROOT_DIR/mkf/def.mk | sed -n "/^PROJ_INCLUDE_DIR=/p" | sed -n -e"s/^PROJ_INCLUDE_DIR=[[    ]]*\(.*\)/\1/p"`
100 AC_MSG_RESULT($PROJ_INCLUDE_FLAG)
101
102 AC_MSG_CHECKING(for proj library flag used by RAVE)
103 PROJ_LIBRARY_FLAG=`cat $RAVE_ROOT_DIR/mkf/def.mk | sed -n "/^PROJ_LIB_DIR=/p" | sed -n -e"s/^PROJ_LIB_DIR=[[    ]]*\(.*\)/\1/p"`
104 AC_MSG_RESULT($PROJ_INCLUDE_FLAG)
105
106 AC_MSG_CHECKING(for expat include flag used by RAVE)
107 EXPAT_INCLUDE_FLAG=`cat $RAVE_ROOT_DIR/mkf/def.mk | sed -n "/^EXPAT_INCLUDE_DIR=/p" | sed -n -e"s/^EXPAT_INCLUDE_DIR=[[         ]]*\(.*\)/\1/p"`
108 AC_MSG_RESULT($EXPAT_INCLUDE_FLAG)
109
110 AC_MSG_CHECKING(for expat library flag used by RAVE)
111 EXPAT_LIBRARY_FLAG=`cat $RAVE_ROOT_DIR/mkf/def.mk | sed -n "/^EXPAT_LIB_DIR=/p" | sed -n -e"s/^EXPAT_LIB_DIR=[[         ]]*\(.*\)/\1/p"`
112 AC_MSG_RESULT($EXPAT_INCLUDE_FLAG)
113
114 AC_MSG_CHECKING(if expat is supressed)
115 EXPAT_SUPPRESSED=`cat $RAVE_ROOT_DIR/mkf/def.mk | sed -n "/^EXPAT_SUPPRESSED=/p" | sed -n -e"s/^EXPAT_SUPPRESSED=[[     ]]*\(.*\)/\1/p"`
116 AC_MSG_RESULT($EXPAT_SUPPRESSED)
117
118 AC_MSG_CHECKING(for hlhdf include flag used by RAVE)
119 HLHDF_INCLUDE_FLAG=-I`cat $RAVE_ROOT_DIR/mkf/def.mk | sed -n "/^HLHDF_INCLUDE_DIR=/p" | sed -n -e"s/^HLHDF_INCLUDE_DIR=[[       ]]*\(.*\)/\1/p"`
120 AC_MSG_RESULT($HLHDF_INCLUDE_FLAG)
121
122 AC_MSG_CHECKING(for hlhdf library flag used by RAVE)
123 HLHDF_LIBRARY_FLAG=-L`cat $RAVE_ROOT_DIR/mkf/def.mk | sed -n "/^HLHDF_LIB_DIR=/p" | sed -n -e"s/^HLHDF_LIB_DIR=[[       ]]*\(.*\)/\1/p"`
124 AC_MSG_RESULT($HLHDF_LIBRARY_FLAG)
125
126 AC_MSG_CHECKING(for hlhdf config file)
127 HLHDF_MK_FILE=`cat $RAVE_ROOT_DIR/mkf/def.mk | sed -n "/^HLHDF_HLDEF_MK_FILE=/p" | sed -n -e"s/^HLHDF_HLDEF_MK_FILE=[[  ]]*\(.*\)/\1/p"`
128 AC_MSG_RESULT($HLHDF_MK_FILE)
129
130 AC_MSG_CHECKING(for hlhdf ld shared)
131 HLHDFLDSHARED=`cat $HLHDF_MK_FILE | sed -n "/^LDSHARED=/p" | sed -n -e"s/^LDSHARED=[[   ]]*\(.*\)/\1/p"`
132 AC_MSG_RESULT($HLHDFLDSHARED)
133
134 AC_MSG_CHECKING(for g++ ld shared options)
135 LDCPPSHARED=`echo "$HLHDFLDSHARED" | awk '{$1=""}1'`
136 AC_MSG_RESULT($LDCPPSHARED)
137
138 AC_MSG_CHECKING(for hdf5 software used by hlhdf)
139 HLHDF_HDF5_LIB=`cat $HLHDF_MK_FILE | sed -n "/^HDF5_LIBDIR=/p" | sed -n -e"s/^HDF5_LIBDIR=[[    ]]*\(.*\)/\1/p"`
140 AC_MSG_RESULT($HLHDF_HDF5_LIB)
141
142 AC_MSG_CHECKING(for zlib software used by hlhdf)
143 HLHDF_ZLIB_LIB=`cat $HLHDF_MK_FILE | sed -n "/^ZLIB_LIBDIR=/p" | sed -n -e"s/^ZLIB_LIBDIR=[[    ]]*\(.*\)/\1/p"`
144 AC_MSG_RESULT($HLHDF_ZLIB_LIB)
145
146 AC_MSG_CHECKING(for szlib software used by hlhdf)
147 HLHDF_SZLIB_LIB=`cat $HLHDF_MK_FILE | sed -n "/^SZLIB_LIBDIR=/p" | sed -n -e"s/^SZLIB_LIBDIR=[[         ]]*\(.*\)/\1/p"`
148 AC_MSG_RESULT($HLHDF_SZLIB_LIB)
149
150 dnl Generate the ld library printout
151 dnl
152 LD_PRINTOUT=$prefix/lib
153 if [[ "$RAVE_LIB_FLAG" != "" ]]; then
154   LD_PRINTOUT=$LD_PRINTOUT:`echo "$RAVE_LIB_FLAG" | sed -e"s/[[ \t]]*-L//"`
155 fi
156
157 if [[ "$HLHDF_LIBRARY_FLAG" != "" ]]; then
158   LD_PRINTOUT=$LD_PRINTOUT:`echo "$HLHDF_LIBRARY_FLAG" | sed -e"s/[[ \t]]*-L//"`
159 fi
160
161 if [[ "$HLHDF_HDF5_LIB" != "" ]]; then
162   LD_PRINTOUT=$LD_PRINTOUT:`echo "$HLHDF_HDF5_LIB" | sed -e"s/[[ \t]]*-L//"`
163 fi
164
165 if [[ "$PROJ_LIB_FLAG" != "" ]]; then
166   LD_PRINTOUT=$LD_PRINTOUT:`echo "$PROJ_LIB_FLAG" | sed -e"s/[[ \t]]*-L//"`
167 fi
168
169 if [[ "$EXPAT_LIBRARY_FLAG" != "" ]]; then
170   LD_PRINTOUT=$LD_PRINTOUT:`echo "$EXPAT_LIBRARY_FLAG" | sed -e"s/[[ \t]]*-L//"`
171 fi
172
173 if [[ "$HLHDF_ZLIB_LIB" != "" ]]; then
174   LD_PRINTOUT=$LD_PRINTOUT:`echo "$HLHDF_ZLIB_LIB" | sed -e"s/[[ \t]]*-L//"`
175 fi
176
177 if [[ "$HLHDF_SZLIB_LIB" != "" ]]; then
178   LD_PRINTOUT=$LD_PRINTOUT:`echo "$HLHDF_SZLIB_LIB" | sed -e"s/[[ \t]]*-L//"`
179 fi
180
181 dnl We need BLAS, CBLAS and LAPACK(E) as well, so we start figuring out where to find them. We need
182 dnl to do it in the order, BLAS, CBLAS and LAPACK but first, do we have fortran or gfortran available.
183 dnl AC_FC_LIBRARY_LDFLAGS
184 AC_MSG_RESULT([Setting F77=gfortran, needed for baltrad-wrwp])
185 F77=gfortran
186 AC_PROG_F77([$F77 ])
187
188 AC_MSG_CHECKING([system version])
189 system=`uname -s`-`uname -r`
190 if test "$?" -ne 0; then
191     AC_MSG_RESULT([unknown (can't find uname command)])
192     system=unknown
193 else
194     # Special check for weird MP-RAS system (uname returns weird
195     # results, and the version is kept in special file).
196     
197     if test -r /etc/.relid -a "X`uname -n`" = "X`uname -s`" ; then
198         #system=MP-RAS-`awk '{print $3}' /etc/.relid'`
199         system=MP-RAS-`awk '{print $3}' /etc/.relid`
200     fi
201     if test "`uname -s`" = "AIX" ; then
202         system=AIX-`uname -v`.`uname -r`
203     fi
204     AC_MSG_RESULT($system)
205 fi
206
207 dnl While digging out fortran information, keep LIBS saved"
208 saved_LIBS="$LIBS"
209
210 TMPFOUNDCOMPINFO=0
211 TMPCOMPINFO=`$F77 -V 2>/dev/null`
212 if test $? -eq 0; then
213   TMPFOUNDCOMPINFO=1
214 fi
215
216 TMPCOMPILERNAME=`echo $TMPCOMPINFO | cut -d' ' -f1-2`
217 TMPCOMPILERNAME=$F77
218
219 # Set the Fortran linker flags
220 if [[ "x$COMPILE_FOR_FORTRAN" != "xno" ]]; then
221   try_ok=no
222   # Check the fortran libraries, so that they can be loaded
223   case $system in
224     OSF1*)
225       FDFLAGS=-nofor_main
226       FFLAGS="-C -O3 -fast -fpe2"
227       EXTRA_LIBS=
228       ;;
229     SunO*)
230       FFLAGS=-O3
231       FDFLAGS=
232       EXTRA_LIBS=-lsunmath
233       ;;
234     Linux*)
235       case $TMPCOMPILERNAME in
236         pgf90*)
237           FDFLAGS=-Mnomain
238           FFLAGS="-O3"
239           EXTRA_LIBS=
240               ;;
241         ifort*)
242           FDFLAGS=-nofor_main
243           FFLAGS="-O3"
244           EXTRA_LIBS=
245           ;;
246         ifc*)
247           FDFLAGS=-nofor_main
248           FFLAGS="-O3"
249           EXTRA_LIBS=
250               ;;
251         gfortran*)
252           FDFLAGS=
253           if [[ "x$bit64" = "xyes" ]]; then
254             FFLAGS="${FFLAGS} -fPIC -fno-automatic -ffixed-line-length-none"
255           else
256             FFLAGS="${FFLAGS} -fno-automatic -ffixed-line-length-none"
257           fi
258           EXTRA_LIBS=
259           ;;
260             *)
261               AC_MSG_RESULT("The configure cant determine what fortran linker options to use on $system")
262           ;;  
263       esac
264       ;;
265     *)
266       AC_MSG_RESULT("The configure cant determine what fortran library that should be used on $system")
267       ;;
268   esac
269 fi
270
271 # When trying to use AC_F77_LIBRARY_LDFLAGS it fails so we try it on our own
272
273 C_FORTRAN_LINK_LIBS=
274 FORTRAN_CLINK_LIBS=
275 FORTRAN_CLINK_LDFLAG=
276 if [[ "x$COMPILE_FOR_FORTRAN" != "xno" ]]; then
277   # What fortran compiler is it?
278   
279   try_ok=no
280   LIBS=
281   LDFLAGS=
282   # Step 3: Check the fortran libraries, so that they can be loaded
283   case $system in
284     Linux*)
285      case $TMPCOMPILERNAME in
286        pgf90*)
287          TMPLDPATH=`which pgf90 | sed -e"s/bin\/pgf90/lib/g"`
288          LDFLAGS=-L$TMPLDPATH
289          LIBS="$LINKER_FORCED_STATIC -lg2c -lpgf90 -lpgf90_rpm1 -lpgf902 -lpgf90rtl -lpgftnrtl -lpgc $LINKER_FORCED_SHARED"
290          ;;
291        ifc*)
292          TMPLDPATH=`which ifc | sed -e"s/bin\/ifc/lib/g"`
293          LDFLAGS=-L$TMPLDPATH
294          FFLAGS="${FFLAGS} -cm -WB -w90 -w95"
295          LIBS="$FC_LINKER_FORCED_STATIC -lIEPCF90 -lintrins -lF90 -limf $FC_LINKER_FORCED_SHARED"
296          ;;
297        ifort*)
298          TMPLDPATH=`which ifort | sed -e"s/bin\/ifort/lib/g"`
299          LDFLAGS=-L$TMPLDPATH
300          FFLAGS="${FFLAGS} -fpp -save -132 -w90 -w95 -cm"
301          LIBS="$FC_LINKER_FORCED_STATIC -lifport -limf -lcxa -lcprts -lunwind -lguide -lguide_stats -lifcoremt -lifcore -lirc $FC_LINKER_FORCED_SHARED"
302          ;;
303        gfortran*)
304              if [[ "x$bit64" = "xyes" ]]; then
305            TMPLDPATH=`which gfortran | sed -e"s/bin\/gfortran/lib64/g"`
306          else
307            TMPLDPATH=`which gfortran | sed -e"s/bin\/gfortran/lib/g"`
308          fi
309          LDFLAGS=-L$TMPLDPATH
310          LIBS="$LINKER_FORCED_SHARED -lgfortran"
311          FDFLAGS=
312          ;;
313        *)
314          AC_MSG_RESULT("The configure cant determine what settings are needed on $system with compiler $TMPCOMPILERNAME")
315          ;;
316      esac
317      if [[ "x$LDFLAGS" != "x" ]]; then
318        AC_MSG_CHECKING([Linker Options for $TMPCOMPILERNAME on $system with $LDFLAGS $LIBS])
319        AC_TRY_RUN([
320 #include <stdio.h>
321 main()
322 {
323   int i;
324   return 0;
325 }],try_ok=yes,try_ok=no,try_ok=no)
326      fi
327      if [[ "x$try_ok" = "xyes" ]]; then
328        AC_MSG_RESULT(Yes)
329        C_FORTRAN_LINK_LIBS="$LIBS"
330        FORTRAN_CLINK_LIBS="$LIBS"
331        FORTRAN_CLINK_LDFLAG="$LDFLAGS"
332      else
333        AC_MSG_RESULT(No try do it manually)
334      fi
335      ;;
336     OSF1*)
337      C_FORTRAN_LINK_LIBS=-lfor
338      FORTRAN_CLINK_LIBS=-lfor
339      ;;
340     SunO*)
341      C_FORTRAN_LINK_LIBS="-lf77compat -lfsu -lsunmath -lfui"
342      FORTRAN_CLINK_LIBS="-lf77compat -lfsu -lsunmath -lfui"
343      ;;
344     *)
345      AC_MSG_RESULT("The configure cant determine what fortran library that should be used on $system")
346      ;;
347   esac
348 fi
349
350 AC_LANG(Fortran 77)
351         
352 dnl I have to force the suffix to be .F90 to know how the
353 dnl actual fortran code will behave, some compilers differs
354 dnl in how they work depending on the suffix, for example
355 dnl this is the case with the Portland Group fortran compilers.
356 ac_ext=F90
357
358 dnl Check what linker options that has to be used to force dynamic and static
359 dnl linking when using the fortran compiler.
360 dnl Currently only supported are -Bstatic/-Bdynamic
361 dnl and -no_so/-so_archive
362 dnl Also, the first to try should be -Xlinker -Bdynamic and
363 dnl -Xlinker -Bstatic since the gnu compiler behaves a bit
364 dnl different and just warns when options not are supported.
365 FC_LINKER_FORCED_SHARED=""
366 FC_LINKER_FORCED_STATIC=""
367
368 LIBS="-Xlinker -Bstatic -Xlinker -Bdynamic"
369
370 AC_MSG_CHECKING(Fortran Linker options ($LIBS))
371 AC_TRY_RUN([
372     PROGRAM CONFTEST
373     IMPLICIT real*8 (A-H, O-Z)
374     END
375 ],try_ok=yes,try_ok=no,try_ok=no)
376
377 if [[ "x$try_ok" = "xyes" ]]; then
378   AC_MSG_RESULT("Yes")
379   FC_LINKER_FORCED_SHARED="-Xlinker -Bdynamic"
380   FC_LINKER_FORCED_STATIC="-Xlinker -Bstatic"
381 else
382   AC_MSG_RESULT("No")
383 fi
384
385 if [[ "x$FC_LINKER_FORCED_SHARED" = "x" ]]; then
386   LIBS="-no_so -so_archive"
387   AC_MSG_CHECKING(Fortran Linker options ($LIBS))
388   AC_TRY_RUN([
389     PROGRAM CONFTEST
390     IMPLICIT real*8 (A-H, O-Z)
391     END
392 ],try_ok=yes,try_ok=no,try_ok=no)
393
394   if [[ "x$try_ok" = "xyes" ]]; then
395     AC_MSG_RESULT("Yes")
396     FC_LINKER_FORCED_SHARED="-so_archive"
397     FC_LINKER_FORCED_STATIC="-no_so"
398   else
399     AC_MSG_RESULT("No")
400   fi
401 fi
402
403 if [[ "x$FC_LINKER_FORCED_SHARED" = "x" ]]; then
404   LIBS="-Bstatic -Bdynamic"
405   AC_MSG_CHECKING(Fortran Linker options ($LIBS))
406   AC_TRY_RUN([
407     PROGRAM CONFTEST
408     IMPLICIT real*8 (A-H, O-Z)
409     END
410 ],try_ok=yes,try_ok=no,try_ok=no)
411
412   if [[ "x$try_ok" = "xyes" ]]; then
413     AC_MSG_RESULT("Yes")
414     FC_LINKER_FORCED_SHARED="-Bdynamic"
415     FC_LINKER_FORCED_STATIC="-Bstatic"
416   else
417     AC_MSG_RESULT("No")
418   fi
419 fi
420
421 if [[ "x$FC_LINKER_FORCED_SHARED" = "x" ]]; then
422   LIBS="-static -dynamic"
423   AC_MSG_CHECKING(Fortran Linker options ($LIBS))
424   AC_TRY_RUN([
425     PROGRAM CONFTEST
426     IMPLICIT real*8 (A-H, O-Z)
427     END
428 ],try_ok=yes,try_ok=no,try_ok=no)
429
430   if [[ "x$try_ok" = "xyes" ]]; then
431     AC_MSG_RESULT("Yes")
432     FC_LINKER_FORCED_SHARED="-dynamic"
433     FC_LINKER_FORCED_STATIC="-static"
434   else
435     AC_MSG_RESULT("No")
436   fi
437 fi
438
439 LD_FORCE_STATIC=$FC_LINKER_FORCED_STATIC
440 LD_FORCE_SHARE=$FC_LINKER_FORCED_SHARED
441 AC_MSG_RESULT([Setting LD_FORCE_STATIC =  $LD_FORCE_STATIC])
442 AC_MSG_RESULT([Setting LD_FORCE_SHARE = $LD_FORCE_SHARE])
443
444 AC_LANG(C)
445 LIBS="$saved_LIBS"
446
447 LIBS="$FORTRAN_CLINK_LIBS $LIBS"
448 LDFLAGS="$FORTRAN_CLINK_LDFLAG $LDFLAGS"
449
450 dnl       C_FORTRAN_LINK_LIBS="$LIBS"
451 dnl       FORTRAN_CLINK_LIBS="$LIBS"
452 dnl       FORTRAN_CLINK_LDFLAG="$LDFLAGS"
453
454 BLAS_LIB_DIR=
455 GOT_BLAS_LIB=no
456 AC_ARG_WITH(blas, [ --with-blas=LIBDIR       Use the blas library],
457             ,withval=yes)
458 case $withval in
459   yes)
460     AC_CHECK_LIB(blas,sasum_,GOT_BLAS_LIB=yes)
461     ;;
462   no)
463     AC_MSG_ERROR(You cannot remove dependencies to BLAS);
464     ;;
465   *)
466     if [[ "$withval" != "" ]]; then
467       saved_LDFLAGS="$LDFLAGS"
468       LDFLAGS="$LDFLAGS -L$withval"
469       AC_CHECK_LIB(blas, sasum_, GOT_BLAS_LIB=yes)
470       if [[ "$GOT_BLAS_LIB" = "yes" ]]; then
471         BLAS_LIB_DIR="-L$withval"
472       else
473         LDFLAGS="$saved_LDFLAGS"
474       fi
475     else
476       AC_MSG_ERROR("Odd argument passed for BLAS")
477     fi
478     ;;  
479 esac            
480
481 if [[ "$GOT_BLAS_LIB" = "no" ]]; then
482   AC_MSG_ERROR("Could not successfully find the blas library")
483 fi
484
485 dnl Both CBLAS and LAPACKE needs CBLAS
486 LDFLAGS="$BLAS_LIB_DIR $LDFLAGS"
487 LIBS="-lblas $LIBS"
488
489 CBLAS_INC_DIR=
490 CBLAS_LIB_DIR=
491 GOT_CBLAS_INC=no
492 GOT_CBLAS_LIB=no
493 AC_ARG_WITH(cblas, [ --with-cblas=ROOT or INC,LIB       Use the cblas library],
494             ,withval=yes)
495 case $withval in
496   yes)
497     AC_CHECK_HEADERS(cblas.h,GOT_CBLAS_INC=yes)
498     AC_CHECK_LIB(cblas,cblas_sasum,GOT_CBLAS_LIB=yes)
499     ;;
500   no)
501     AC_MSG_ERROR(You cannot remove dependencies to CBLAS);
502     ;;
503   *)
504     if [[ "$withval" != "" ]]; then
505       if [[ "`echo $withval | grep ','`" = "" ]]; then
506         cblas_inc="$withval/include"
507         cblas_lib="$withval/lib"
508       else
509         cblas_inc="`echo $withval |cut -f1 -d,`"
510         cblas_lib="`echo $withval |cut -f2 -d,`"
511       fi
512       
513       if [[ "$cblas_inc" != "" ]]; then
514         saved_CPPFLAGS="$CPPFLAGS"
515         CPPFLAGS="$CPPFLAGS -I$cblas_inc"
516         AC_CHECK_HEADERS(cblas.h,GOT_CBLAS_INC=yes)
517         if [[ "$GOT_CBLAS_INC" = "yes" ]]; then
518           CBLAS_INCLUDE_DIR="-I$cblas_inc"
519         else
520           CPPFLAGS="$saved_CPPFLAGS"
521         fi
522       else
523         AC_CHECK_HEADERS(cblas.h,GOT_CBLAS_INC=yes)
524       fi
525
526       if [[ "$cblas_lib" != "" ]]; then
527         saved_LDFLAGS="$LDFLAGS"
528         LDFLAGS="$LDFLAGS -L$cblas_lib"
529         AC_CHECK_LIB(cblas, cblas_sasum, GOT_CBLAS_LIB=yes)
530         if [[ "$GOT_CBLAS_LIB" = "yes" ]]; then
531           CBLAS_LIB_DIR="-L$cblas_lib"
532         else
533           LDFLAGS="$saved_LDFLAGS"
534         fi
535       else
536         AC_CHECK_LIB(cblas, cblas_sasum, GOT_CBLAS_LIB=yes)
537       fi
538     else
539       AC_MSG_ERROR("Odd argument passed for CBLAS")
540     fi
541     ;;
542 esac
543
544 if [[ "$GOT_CBLAS_INC" = "no" -o "$GOT_CBLAS_LIB" = "no" ]]; then
545   AC_MSG_ERROR("Could not successfully find the cblas library")
546 fi
547
548 dnl LAPACKE needs CBLAS
549 LDFLAGS="$CBLAS_LIB_DIR $LDFLAGS"
550 LIBS="-lcblas $LIBS"
551
552 dnl Now we need to locate lapack that just is a library
553 LAPACK_LIB_DIR=
554 GOT_LAPACK_LIB=no
555 AC_ARG_WITH(lapack, [ --with-lapack=LIBDIR       Use the lapack library],
556             ,withval=yes)
557 case $withval in
558   yes)
559     AC_CHECK_LIB(lapack,dgels_,GOT_LAPACK_LIB=yes)
560     ;;
561   no)
562     AC_MSG_ERROR(You cannot remove dependencies to LAPACK);
563     ;;
564   *)
565     if [[ "$withval" != "" ]]; then
566       saved_LDFLAGS="$LDFLAGS"
567       LDFLAGS="$LDFLAGS -L$withval"
568       AC_CHECK_LIB(lapack,dgels_,GOT_LAPACK_LIB=yes)
569       if [[ "$GOT_LAPACK_LIB" = "yes" ]]; then
570         LAPACK_LIB_DIR="-L$withval"
571       else
572         LDFLAGS="$saved_LDFLAGS"
573       fi
574     else
575       AC_MSG_ERROR("Odd argument passed for LAPACK")
576     fi
577     ;;  
578 esac            
579
580 if [[ "$GOT_LAPACK_LIB" = "no" ]]; then
581   AC_MSG_ERROR("Could not successfully find the lapack library")
582 fi
583
584 LIBS="-llapack $LIBS"
585 LDFLAGS="$LAPACK_LIB_DIR $LDFLAGS"
586
587 dnl We also need to locate lapack(e)
588 LACPACKE_INCLUDE_DIR=
589 LAPACKE_LIB_DIR=
590 GOT_LAPACKE_INC=no
591 GOT_LAPACKE_LIB=no
592 AC_ARG_WITH(lapacke,[  --with-lapacke=ROOT or INC,LIB       Use the lapacke library],
593     ,withval=yes)
594 dnl LDFLAGS="$LDFLAGS -L/projects/baltrad/SMHI_WRWP/CBLAS/lib -L/projects/baltrad/SMHI_WRWP/BLAS" 
595 dnl CPPFLAGS="$CFLAGS -I/projects/baltrad/SMHI_WRWP/CBLAS/include -I/projects/baltrad/SMHI_WRWP/lapack-3.4.2/lapacke/include"
596 dnl LIBS="$LIBS -llapack -lcblas -lblas -lgfortran -lm"
597 case $withval in
598   yes)
599     AC_CHECK_HEADERS(lapacke.h,GOT_LAPACKE_INC=yes)
600     AC_CHECK_LIB(lapacke,LAPACKE_dgels,GOT_LAPACKE_LIB=yes)
601     ;;
602   no)
603     AC_MSG_ERROR(You cannot remove dependencies to LAPACK);
604     ;;
605   *)
606     if [[ "$withval" != "" ]]; then
607       if [[ "`echo $withval | grep ','`" = "" ]]; then
608         lapacke_inc="$withval/include"
609         lapacke_lib="$withval/lib"
610       else
611         lapacke_inc="`echo $withval |cut -f1 -d,`"
612         lapacke_lib="`echo $withval |cut -f2 -d,`"
613       fi
614       
615       if [[ "$lapacke_inc" != "" ]]; then
616         saved_CPPFLAGS="$CPPFLAGS"
617         CPPFLAGS="$CPPFLAGS -I$lapacke_inc"
618         AC_CHECK_HEADERS(lapacke.h,GOT_LAPACKE_INC=yes)
619         if [[ "$GOT_LAPACKE_INC" = "yes" ]]; then
620           LAPACKE_INCLUDE_DIR="-I$lapacke_inc"
621         else
622           CPPFLAGS="$saved_CPPFLAGS"
623         fi
624       else
625         AC_CHECK_HEADERS(lapacke.h,GOT_LAPACKE_INC=yes)
626       fi
627
628       if [[ "$lapacke_lib" != "" ]]; then
629         saved_LDFLAGS="$LDFLAGS"
630         LDFLAGS="$LDFLAGS -L$lapacke_lib"
631         AC_CHECK_LIB(lapack, dgels_, GOT_LAPACKE_LIB=yes)
632         AC_CHECK_LIB(lapacke, LAPACKE_dgels, GOT_LAPACKE_LIB=yes)
633         if [[ "$GOT_LAPACKE_LIB" = "yes" ]]; then
634           LAPACKE_LIB_DIR="-L$lapacke_lib"
635         else
636           LDFLAGS="$saved_LDFLAGS"
637         fi
638       else
639         AC_CHECK_LIB(lapacke, LAPACKE_dgels, GOT_LAPACKE_LIB=yes)
640       fi
641     else
642       AC_MSG_ERROR("Odd argument passed for lapacke")
643     fi
644     ;;
645 esac
646
647 if [[ "$GOT_LAPACKE_INC" = "no" -o "$GOT_LAPACKE_LIB" = "no" ]]; then
648   AC_MSG_ERROR("Could not successfully find the lapacke library")
649 fi
650
651 AC_SUBST(FORTRAN_CLINK_LIBS)
652 AC_SUBST(FORTRAN_CLINK_LDFLAG)
653 AC_SUBST(BLAS_LIB_DIR)
654 AC_SUBST(CBLAS_INCLUDE_DIR)
655 AC_SUBST(CBLAS_LIB_DIR)
656 AC_SUBST(LAPACK_LIB_DIR)
657 AC_SUBST(LAPACKE_INCLUDE_DIR)
658 AC_SUBST(LAPACKE_LIB_DIR)
659
660 AC_SUBST(RAVE_ROOT_DIR)
661 AC_SUBST(RAVE_INCLUDE_FLAG)
662 AC_SUBST(RAVE_LIB_FLAG)
663 AC_SUBST(RAVECC)
664 AC_SUBST(RAVECCOPTS)
665 AC_SUBST(RAVELDFLAGS)
666 AC_SUBST(RAVECCSHARED)
667 AC_SUBST(PYTHON_INCLUDE_FLAG)
668 AC_SUBST(NUMPY_INCLUDE_FLAG)
669 AC_SUBST(PROJ_INCLUDE_FLAG)
670 AC_SUBST(PROJ_LIBRARY_FLAG)
671 AC_SUBST(EXPAT_INCLUDE_FLAG)
672 AC_SUBST(EXPAT_LIBRARY_FLAG)
673 AC_SUBST(EXPAT_SUPPRESSED)
674 AC_SUBST(HLHDF_INCLUDE_FLAG)
675 AC_SUBST(HLHDF_LIBRARY_FLAG)
676 AC_SUBST(HLHDFLDSHARED)
677 AC_SUBST(LD_PRINTOUT)
678
679 dnl AC_CONFIG_FILES(def.mk lib/config.h)
680 AC_CONFIG_FILES(def.mk)
681 AC_OUTPUT