Ticket 788: def.mk.in LDFLAGS does not use correct PROJ-flag
[rave-py3.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 rave
3 dnl     installation to configure the system for the local environment.
4
5 AC_INIT([RAVE],[0.65a])
6
7 RAVE_VERSION=0.65a
8 RAVE_PATCH_LEVEL=0
9
10 if test "${prefix}" = "NONE"; then
11         prefix=/usr/local/rave
12 fi
13
14 LIBS=-lm
15
16 dnl It is possible to turn on memory debugging within RAVE
17 PYBIN=python
18 py3support=no
19 AC_ARG_ENABLE(py3support,
20   [  --enable-py3support     Builds rave with support for python3.],
21   py3support=$enableval)
22 if [[ "x$py3support" = "xyes" ]]; then
23   PYOPT="$PYOPT -DPY3_SUPPORT"
24   PYBIN=python3
25 fi
26
27 AC_ARG_WITH(py3bin, [  --with-py3bin=python3  What python 3 binary to use],
28                     ,withval=python3)
29 if [[ "$PYBIN" = "python3" ]]; then
30   AC_MSG_CHECKING(what python3 binary to use)
31   if [[ "$withval" != "python3" ]]; then
32     PYBIN=$withval
33   fi
34   AC_MSG_RESULT($PYBIN)
35 fi
36
37 PYVERSION=`$PYBIN -c "import sys; print(sys.version[[:3]])"`
38 PY_EXEC_INSTALLDIR=`$PYBIN -c "import sys; print(sys.exec_prefix)"`
39
40 PY_PYTHON_BIN="$PYBIN"
41
42 PYCONFIG_BIN="python-config"
43 AC_ARG_WITH(py3bin-config, [  --with-py3bin-config=python3-config  What python 3 config binary to use],
44                     ,withval=default)
45 if [[ "$py3support" = "yes" ]]; then
46   if [[ "$withval" = "default" ]]; then
47     PYCONFIG_BIN="$PYBIN-config"
48   else
49     PYCONFIG_BIN="$withval"
50   fi
51 fi
52
53 AC_MSG_CHECKING(for python Makefile)
54
55 PY_CONFIG_MAKE=
56
57 AC_ARG_WITH(python-makefile, [  --with-python-makefile=Makefile  Where the makefile used for building python can be found],
58                     ,withval=no)
59 if [[ "$withval" != "no" ]]; then
60   if [[ -f $withval ]]; then
61     PY_CONFIG_MAKE="$withval"
62   fi
63 fi
64
65
66 PY_CONFIGDIR=`$PYCONFIG_BIN --configdir`
67 if test $? -eq 0; then
68   if [[ "x$PY_CONFIG_MAKE" = "x" ]]; then
69     if [[ -f "$PY_CONFIGDIR/Makefile" ]]; then
70       PY_CONFIG_MAKE="$PY_CONFIGDIR/Makefile"
71     fi
72   fi
73 fi
74
75 if [[ "x$PY_CONFIG_MAKE" = "x" ]]; then
76   PY_CONFIG_MAKE="$PY_EXEC_INSTALLDIR/lib/python$PYVERSION/config/Makefile"
77   if [[ ! -f "$PY_CONFIG_MAKE" ]]; then
78     PY_CONFIG_MAKE="$PY_EXEC_INSTALLDIR/lib64/python$PYVERSION/config/Makefile"
79   fi
80 fi
81
82 if [[ ! -f "$PY_CONFIG_MAKE" ]]; then
83   AC_MSG_ERROR(Could not successfully find the python Makefile)
84 fi
85 AC_MSG_RESULT($PY_CONFIG_MAKE)
86
87 #
88 # Extract what compiler the python binary was compiled with
89 #
90 AC_MSG_CHECKING("for the compiler used for generating python")
91
92 PYCC=
93
94 PYCC=`cat $PY_CONFIG_MAKE | sed -n "/^CC=/p" | sed -e "s/CC=//g" | awk '{print $1}'`
95 AC_MSG_RESULT("$PYCC")
96 #CC=$PYCC
97
98 dnl Later on we are going to check for pthread support but since we know that
99 dnl python might determine pthread flags we can at least see what python
100 dnl came up with.
101
102 AC_MSG_CHECKING(if python CC defines pthread usage)
103 PYPTHREADCC=`cat $PY_CONFIG_MAKE | sed -n "/^CC=/p" | sed -e "s/CC=//g" | grep "pthread"`
104 PYGOTPTHREAD=no
105 if [[ "$PYPTHREADCC" != "" ]]; then
106   PYGOTPTHREAD=yes
107 fi
108 AC_MSG_RESULT($PYGOTPTHREAD)
109
110 AC_PROG_RANLIB
111 AC_PROG_CC($PYCC gcc cc)
112 AC_PROG_CPP
113 AC_SUBST(AR)
114 AC_CHECK_PROGS(AR, ar aal, ar)
115
116 PYCC=$CC
117
118 PY_INCLUDES=
119 PY_SITEPACK=
120 PYOPT=
121 PYLDFLAGS=
122 PYLDSHARED=
123 PYCCSHARED=
124 PYDEFS=
125
126 AC_MSG_CHECKING("for python includes")
127 PY_INCLUDES="$PY_EXEC_INSTALLDIR/include/python$PYVERSION"
128 AC_MSG_RESULT("$PY_INCLUDES")
129 PY_INCLUDES="-I$PY_INCLUDES"
130 PY_INCLUDES=`$PYCONFIG_BIN --includes`
131
132 AC_MSG_CHECKING("for python lib site-packages")
133 TMP_SITEPACK=`$PYBIN -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))"`
134 if [[ "$TMP_SITEPACK" != "" ]]; then
135   PY_SITEPACK="$TMP_SITEPACK"
136 else
137   PY_SITEPACK="$PY_EXEC_INSTALLDIR/lib/python$PYVERSION/site-packages"
138 fi
139 AC_MSG_RESULT("$PY_SITEPACK")
140
141 dnl Checks for typedefs, structures and compiler characteristics
142 AC_MSG_CHECKING("for python options")
143 PYOPT=`cat $PY_CONFIG_MAKE | sed -n "/^OPT=/p" | sed -n -e"s/^OPT=[[    ]]*\(.*\)/\1/p"`
144 AC_MSG_RESULT("$PYOPT")
145
146 AC_MSG_CHECKING("for ldflags")
147 PYLDFLAGS=`cat $PY_CONFIG_MAKE | sed -n "/^LDFLAGS=/p" | sed -n -e"s/^LDFLAGS=[[        ]]*\(.*\)/\1/p"`
148 AC_MSG_RESULT("$PYLDFLAGS")
149
150 AC_MSG_CHECKING("for ldshared")
151 PYLDSHARED=`cat $PY_CONFIG_MAKE | sed -n "/^LDSHARED=/p" | sed -n -e"s/^LDSHARED=[[     ]]*\(.*\)/\1/p"`
152
153 # Special hack for mac osx.
154 ISMACOS=no
155 case `uname -s` in
156  Darwin*)
157    ISMACOS=yes
158    ;;
159  darwin*)
160    ISMACOS=yes
161    ;;
162 esac
163
164 if [[ "x$ISMACOS" = "xyes" ]]; then
165   PYLDSHARED=`echo $PYLDSHARED | sed -e "s/[[ \t]]-bundle[[ \t]]/ -dynamiclib /g"`
166 fi
167 AC_MSG_RESULT("$PYLDSHARED")
168
169 AC_MSG_CHECKING("for ccshared")
170 PYCCSHARED=`cat $PY_CONFIG_MAKE | sed -n "/^CCSHARED=/p" | sed -n -e"s/^CCSHARED=[[     ]]*\(.*\)/\1/p"`
171 AC_MSG_RESULT("$PYCCSHARED")
172
173 AC_MSG_CHECKING("for defs")
174 PYDEFS=`cat $PY_CONFIG_MAKE | sed -n "/^DEFS=/p" | sed -n -e"s/^DEFS=[[         ]]*\(.*\)/\1/p"`
175 AC_MSG_RESULT("$PYDEFS")
176
177 AC_CHECK_LIB(c,itrunc,GOT_ITRUNC=,GOT_ITRUNC=-DCREATE_ITRUNC)
178
179 dnl Checks for header files.
180 AC_HEADER_STDC
181 AC_CHECK_HEADERS(math.h stdlib.h)
182
183 PROJ_INCLUDE_DIR=
184 PROJ_LIB_DIR=
185 GOT_PROJ_INC=no
186 GOT_PROJ_LIB=no
187 PROJ_SUPPRESSED=no
188 AC_ARG_WITH(proj,[  --with-proj=ROOT or INC,LIB       Use the proj library],
189                 ,withval=yes)
190 case $withval in
191         yes)
192                 AC_CHECK_HEADERS(projects.h,GOT_PROJ_INC=yes)
193                 AC_CHECK_LIB(proj,pj_inv,GOT_PROJ_LIB=yes)
194                 ;;
195         no)
196                 AC_MSG_CHECKING(for Proj lib)
197                 AC_MSG_RESULT(suppressed)
198                 PROJ_SUPPRESSED=yes
199                 ;;
200         *)
201     if [[ "$withval" != "" ]]; then
202       if [[ "`echo $withval | grep ','`" = "" ]]; then
203         proj_inc=$withval/include
204         proj_lib=$withval/lib
205         echo "proj_inc=$proj_inc"
206       else
207         proj_inc="`echo $withval |cut -f1 -d,`"
208         proj_lib="`echo $withval |cut -f2 -d,`"
209       fi
210       
211       if [[ "$proj_inc" != "" ]]; then
212         saved_CPPFLAGS="$CPPFLAGS"
213         CPPFLAGS="$CPPFLAGS -I$proj_inc"
214         AC_CHECK_HEADERS(projects.h,GOT_PROJ_INC=yes)
215         if [[ "$GOT_PROJ_INC" = "yes" ]]; then
216           PROJ_INCLUDE_DIR="-I$proj_inc"
217         else
218           CPPFLAGS="$saved_CPPFLAGS"
219         fi
220       else
221         AC_CHECK_HEADERS(projects.h,GOT_PROJ_INC=yes)
222       fi
223
224       if [[ "$proj_lib" != "" ]]; then
225         saved_LDFLAGS="$LDFLAGS"
226         LDFLAGS="$LDFLAGS -L$proj_lib"
227         AC_CHECK_LIB(proj,pj_inv,GOT_PROJ_LIB=yes)
228         if [[ "$GOT_PROJ_LIB" = "yes" ]]; then
229           PROJ_LIB_DIR="-L$proj_lib"
230         else
231           LDFLAGS="$saved_LDFLAGS"
232         fi
233       else
234         AC_CHECK_LIB(proj,pj_inv,GOT_PROJ_LIB=yes)
235       fi
236     else
237       AC_MSG_ERROR("Odd argument passed for proj")
238     fi
239     ;;
240 esac
241
242 if [[ "x$PROJ_SUPPRESSED" = "xno" ]]; then
243         if [[ "x$GOT_PROJ_INC" = "xno" -o "x$GOT_PROJ_LIB" = "xno" ]]; then
244                 AC_MSG_ERROR("Could not successfully find the proj library")
245         fi
246 fi
247
248 EXPAT_INCLUDE_DIR=
249 EXPAT_LIB_DIR=
250 GOT_EXPAT_INC=no
251 GOT_EXPAT_LIB=no
252 EXPAT_SUPPRESSED=yes
253 AC_ARG_WITH(expat,[  --with-expat=ROOT or INC,LIB       Use the expat library],
254     ,withval=no)
255 case $withval in
256   yes)
257     AC_CHECK_HEADERS(expat.h,GOT_EXPAT_INC=yes)
258     AC_CHECK_LIB(expat,XML_ParserCreate,GOT_EXPAT_LIB=yes)
259     EXPAT_SUPPRESSED=no
260     ;;
261   no)
262     AC_MSG_CHECKING(for expat lib)
263     AC_MSG_RESULT(suppressed)
264     EXPAT_SUPPRESSED=yes
265     ;;
266   *)
267     if [[ "$withval" != "" ]]; then
268       if [[ "`echo $withval | grep ','`" = "" ]]; then
269         expat_inc=$withval/include
270         expat_lib=$withval/lib
271       else
272         expat_inc="`echo $withval |cut -f1 -d,`"
273         expat_lib="`echo $withval |cut -f2 -d,`"
274       fi
275       
276       if [[ "$expat_inc" != "" ]]; then
277         saved_CPPFLAGS="$CPPFLAGS"
278         CPPFLAGS="$CPPFLAGS -I$expat_inc"
279         AC_CHECK_HEADERS(expat.h,GOT_EXPAT_INC=yes)
280         if [[ "$GOT_EXPAT_INC" = "yes" ]]; then
281           EXPAT_INCLUDE_DIR="-I$expat_inc"
282         else
283           CPPFLAGS="$saved_CPPFLAGS"
284         fi
285       else
286         AC_CHECK_HEADERS(expat.h,GOT_EXPAT_INC=yes)
287       fi
288
289       if [[ "$expat_lib" != "" ]]; then
290         saved_LDFLAGS="$LDFLAGS"
291         LDFLAGS="$LDFLAGS -L$expat_lib"
292         AC_CHECK_LIB(expat, XML_ParserCreate, GOT_EXPAT_LIB=yes)
293         if [[ "$GOT_EXPAT_LIB" = "yes" ]]; then
294           EXPAT_LIB_DIR="-L$expat_lib"
295         else
296           LDFLAGS="$saved_LDFLAGS"
297         fi
298       else
299         AC_CHECK_LIB(expat, XML_ParserCreate, GOT_EXPAT_LIB=yes)
300       fi
301     else
302       AC_MSG_ERROR("Odd argument passed for expat")
303     fi
304     EXPAT_SUPPRESSED=no
305     ;;
306 esac
307
308 if [[ "$EXPAT_SUPPRESSED" = "no" ]]; then
309   if [[ "$GOT_EXPAT_INC" = "no" -o "$GOT_EXPAT_LIB" = "no" ]]; then
310     AC_MSG_ERROR("Could not successfully find the expat library")
311   fi
312 fi
313
314 dnl -----------------------------
315 dnl Try to locate the numpy include file 'arrayobject.h' automatically,
316 dnl if this does not succeed, then the user has to specify this argument
317 dnl manually.
318 dnl -----------------------------
319 AC_ARG_WITH(numpy,[  --with-numpy=INC     Use the numpy include file],
320                 ,withval=yes)
321 NUMPY_INCLUDE_DIR=
322 case $withval in
323         no)
324                 AC_MSG_ERROR(You can not remove dependencies to numpy)
325                 ;;
326         *)
327                 numpy_inc="`echo $withval`"
328                 FOUND_NUMPY_INC=no
329                 numpy_inc_app=
330                 
331                 if test "xyes" = "x$numpy_inc"; then
332                   TESTNUMPYDIR=`$PYBIN -c "import numpy; print(eval(\"numpy.__\"+\"file__\"))"`
333                   if test $? -ne 0; then
334                           numpy_inc="$PY_EXEC_INSTALLDIR/include/python$PYVERSION"
335             else
336                           numpy_inc=`echo $TESTNUMPYDIR | sed -e"s/\/__init__.pyc//" | sed -e"s/\/__init__.py//"`
337             fi
338                 fi
339                 if [[ -f $numpy_inc/arrayobject.h ]]; then
340                         numpy_inc_app=
341                         FOUND_NUMPY_INC=yes
342                 elif [[ -f $numpy_inc/numpy/arrayobject.h ]]; then
343                         numpy_inc_app="/numpy"
344                         FOUND_NUMPY_INC=yes
345                 elif [[ -f $numpy_inc/core/include/numpy/arrayobject.h ]]; then
346                     numpy_inc_app="/core/include/numpy"
347                     FOUND_NUMPY_INC=yes
348                 elif [[ -f $numpy_inc/numpy/core/include/numpy/arrayobject.h ]]; then
349                     numpy_inc_app="/numpy/core/include/numpy"
350                     FOUND_NUMPY_INC=yes
351                 fi
352                 if test "xyes" != "x$FOUND_NUMPY_INC"; then
353                         AC_MSG_ERROR(Could not locate arrayobject.h)
354                 fi
355                 NUMPY_INCLUDE_DIR="-I$numpy_inc$numpy_inc_app"
356                 ;;
357 esac
358
359 dnl -----------------------------
360 dnl Is the hlhdf present? It has a header file 'hlhdf.h' and a library -lhlhdf.
361 dnl It also has a include file pyhlhdf_common.h and a library -lpyhlhdf.
362 dnl There should also exist a hldef.mk.
363 dnl If a file hlinstall.sh exists, it is a bonus :)
364 dnl Their locations might be specified with the --with-hlhdf
365 dnl command-line switch. The value is an include path and/or a library path.
366 dnl It the library path is specified then it must be preceded by a comma.
367 dnl -----------------------------
368
369 AC_ARG_WITH(hlhdf,[  --with-hlhdf=ROOT    Use the hlhdf library],
370                 ,withval=yes)
371
372 case $withval in
373   no)
374         AC_MSG_ERROR(You can not remove dependencies to hlhdf)
375     ;;
376   *)
377     hlhdf_root="`echo $withval`"
378     if test "xyes" = "x$hlhdf_root"; then
379       TESTHLDIR=`$PYBIN -c "import _pyhl; print(eval(\"_pyhl.__\"+\"file__\"))"`
380       if test $? -ne 0; then
381         AC_MSG_ERROR("Could not find hlhdf please specify --with-hlhdf=<hlhdfroot>")
382       else
383         hlhdf_root=`echo $TESTHLDIR | sed -e"s/\/lib\/_pyhl.so//"`
384       fi
385     fi
386     if [[ -f $hlhdf_root/mkf/hldef.mk ]]; then
387       HLHDF_ROOTDIR=$hlhdf_root
388     else
389       AC_MSG_ERROR("Could not find hlhdf please specify --with-hlhdf=<hlhdfroot>")
390     fi
391     ;;
392 esac
393
394 dnl We might want to compile rave with a java api
395
396 AC_ARG_WITH(jdk,[  --with-jdk=jdkhome    Compile with java support],
397                 ,withval=no)
398 JDK_ROOT=
399 JDK_SUPRESSED=yes
400 JDK_VERSION=
401 case $withval in
402   no)
403     AC_MSG_CHECKING(for java)
404     AC_MSG_RESULT(suppressed)
405     ;;
406   *)
407     AC_MSG_CHECKING(for java)
408     java_jdk_root="`echo $withval`"
409     if test "yes" = "$java_jdk_root"; then
410       java_bin_dir=`which java | sed -e "s/\/java$//g"`;
411       javac_bin_dir=`which javac | sed -e "s/\/javac$//g"`;
412       jdk_root=`echo $java_bin_dir | sed -e "s/\/bin$//g"`
413     else
414       java_bin_dir="$java_jdk_root/bin";
415       javac_bin_dir="$java_jdk_root/bin";
416       jdk_root="$java_jdk_root"
417     fi
418     if [[ "$java_bin_dir" != "$javac_bin_dir" ]]; then
419       AC_MSG_ERROR(java and javac bin directories seems to be placed at different places)
420     elif [[ "$java_bin_dir" = "" ]]; then
421       AC_MSG_ERROR(Java: No jdk-home dir reckognized)
422     fi
423     javaversion=`$java_bin_dir/java -version 2>&1 | grep "java version \"" | sed -e "s/\(java version \"\)\([[0-9\.]]*\)\(_.*\"\)/\2/g"`
424     if [[ $? -ne 0 ]]; then
425       AC_MSG_ERROR(Failure to execute $java_bin_dir/java -version, is this OpenJDK or SUN JDK?)
426     fi
427     mx_jversion=`echo $javaversion | cut -d '.' -f1`
428     ma_jversion=`echo $javaversion | cut -d '.' -f2`
429     if [[ "$mx_jversion" = "" -o "$ma_jversion" = "" ]]; then
430       AC_MSG_ERROR(Java must be OpenJDK or Sun JDK version 1.6 or higher, found $javaversion)
431     fi
432     if [[ $mx_jversion -ne 1 -o $ma_jversion -lt 6 ]]; then
433       AC_MSG_ERROR(Java must be OpenJDK or SUN version 1.6 or higher, found $javaversion)
434     else
435       JDK_ROOT="$jdk_root"
436       JDK_SUPRESSED=no
437       JDK_VERSION=$javaversion
438       AC_MSG_RESULT($JDK_ROOT)
439     fi    
440     ;;
441 esac
442
443 dnl Do we want to have BUFR support, default is NO
444 GOT_BUFR_INC=no
445 GOT_BUFR_LIB=no
446 BUFR_INCLUDE_DIR=
447 BUFR_LIB_DIR=
448 BUFR_TABLE_DIR=
449 BUFR_SUPPRESSED=yes
450 AC_ARG_WITH(bufr,[  --with-bufr=ROOT       Use the bufr library],
451                 ,withval=no)
452                 
453 case $withval in
454         yes)
455                 AC_CHECK_HEADERS(bufrlib.h,GOT_BUFR_INC=yes)
456                 AC_CHECK_LIB(OperaBufr,bufr_read_file,GOT_BUFR_LIB=yes)
457                 BUFR_SUPPRESSED=no
458                 ;;
459         no)
460                 AC_MSG_CHECKING(for BUFR lib)
461                 AC_MSG_RESULT(suppressed)
462                 BUFR_SUPPRESSED=yes
463                 ;;
464         *)
465     BUFR_SUPPRESSED=no  
466     if [[ "$withval" != "" ]]; then
467       bufr_inc=$withval/include
468       bufr_lib=$withval/lib
469       saved_CPPFLAGS="$CPPFLAGS"
470       CPPFLAGS="$CPPFLAGS -I$bufr_inc"
471       AC_CHECK_HEADERS(bufrlib.h,GOT_BUFR_INC=yes)
472
473       saved_LDFLAGS="$LDFLAGS"
474       LDFLAGS="$LDFLAGS -L$bufr_lib"
475       AC_CHECK_LIB(OperaBufr,bufr_read_file,GOT_BUFR_LIB=yes)
476       
477       CPPFLAGS=$saved_CPPFLAGS
478       LDFLAGS=$saved_LDFLAGS
479       if [[ "$GOT_BUFR_INC" = "yes" -a "$GOT_BUFR_LIB" = "yes" ]]; then
480         BUFR_INCLUDE_DIR="-I$withval/include"
481         BUFR_LIB_DIR="-L$withval/lib"
482       fi
483       if [[ -d "$withval/share/bbufr/tables" ]]; then
484         BUFR_TABLE_DIR="$withval/share/bbufr/tables"
485       fi
486     else
487       AC_MSG_ERROR("Odd argument passed for bufr")
488     fi
489     ;;
490 esac
491
492 if [[ "$BUFR_SUPPRESSED" = "no" ]]; then
493   if [[ "$GOT_BUFR_INC" = "no" -o "$GOT_BUFR_LIB" = "no" ]]; then
494     AC_MSG_ERROR(Could not find opera bufr includes and/or libraries)
495   fi
496 fi
497
498 AC_ARG_WITH(bufr-tables,[  --with-bufr-tables=DIR       Use the bufr tables in specified directory as default],
499                 ,withval=no)
500 case $withval in
501         no)
502           if [[ "$BUFR_SUPPRESSED" = "no" ]]; then
503             if [[ "$BUFR_TABLE_DIR" = "" ]]; then
504               AC_MSG_ERROR(You need to specify a directory where the bufr tables can be found)
505             else
506               if [[ ! -d "$BUFR_TABLE_DIR" ]]; then
507                 AC_MSG_ERROR(Bad bufr table directory)
508               fi
509             fi
510           fi
511           ;;
512     *)
513       if [[ "$withval" != "" ]]; then
514         if [[ -d "$withval" ]]; then
515           BUFR_TABLE_DIR="$withval"
516         else
517           AC_MSG_ERROR(Bad bufr table directory)
518         fi
519       else
520         if [[ "$BUFR_TABLE_DIR" = "" -o -d "$BUFR_TABLE_DIR" ]]; then
521           AC_MSG_ERROR(Bad bufr table directory, have you tried to use with-bufr-tables)
522         fi 
523       fi
524       ;;
525 esac      
526
527 dnl if [[ "x$BUFR_SUPPRESSED" = "xno" ]]; then
528 dnl   if [[ "x$BUFR_TABLE_DIR" = "x" ]]; then
529 dnl     AC_MSG_ERROR("Could not locate any bufr table dir, try  option with bufr tables")
530 dnl   fi
531
532 dnl   if [[ "x$GOT_BUFR_INC" = "xno" -o "x$GOT_BUFR_LIB" = "xno" ]]; then
533 dnl     AC_MSG_ERROR("Could not successfully find the Opera Bufr library")
534 dnl   fi
535 dnl fi
536
537 dnl Do we want to have NETCDF (CF) support, default is NO
538 GOT_NETCDF_INC=no
539 GOT_NETCDF_LIB=no
540 NETCDF_INCLUDE_DIR=
541 NETCDF_LIB_DIR=
542 NETCDF_SUPPRESSED=yes
543 CF_SUPPRESSED=yes
544 AC_ARG_WITH(netcdf,[  --with-netcdf=ROOT or INC,LIB      Use the netcdf library],
545   ,withval=no)
546                 
547 case $withval in
548   yes)
549     AC_CHECK_HEADERS(netcdf.h,GOT_NETCDF_INC=yes)
550     AC_CHECK_LIB(netcdf,nc_create,GOT_NETCDF_LIB=yes)
551     NETCDF_SUPPRESSED=no
552     ;;
553   no)
554     AC_MSG_CHECKING(for NETCDF lib)
555     AC_MSG_RESULT(suppressed)
556     NETCDF_SUPPRESSED=yes
557     ;;
558   *)
559     NETCDF_SUPPRESSED=no        
560     if [[ "$withval" != "" ]]; then
561       if [[ "`echo $withval | grep ','`" = "" ]]; then
562         netcdf_inc=$withval/include
563         netcdf_lib=$withval/lib
564       else
565         netcdf_inc="`echo $withval |cut -f1 -d,`"
566         netcdf_lib="`echo $withval |cut -f2 -d,`"
567       fi
568
569       if [[ "$netcdf_inc" != "" ]]; then
570         saved_CPPFLAGS="$CPPFLAGS"
571         CPPFLAGS="$CPPFLAGS -I$netcdf_inc"
572         AC_CHECK_HEADERS(netcdf.h,GOT_NETCDF_INC=yes)
573         if [[ "$GOT_NETCDF_INC" = "yes" ]]; then
574           NETCDF_INCLUDE_DIR="-I$netcdf_inc"
575         else
576           CPPFLAGS="$saved_CPPFLAGS"
577         fi
578       else
579         AC_CHECK_HEADERS(netcdf.h,GOT_EXPAT_INC=yes)
580       fi
581
582       if [[ "$netcdf_lib" != "" ]]; then
583         saved_LDFLAGS="$LDFLAGS"
584         LDFLAGS="$LDFLAGS -L$netcdf_lib"
585         AC_CHECK_LIB(netcdf,nc_create,GOT_NETCDF_LIB=yes)
586         if [[ "$GOT_NETCDF_LIB" = "yes" ]]; then
587           NETCDF_LIB_DIR="-L$netcdf_lib"
588         else
589           LDFLAGS="$saved_LDFLAGS"
590         fi
591       else
592         AC_CHECK_LIB(netcdf,nc_create,GOT_NETCDF_LIB=yes)
593       fi
594     else
595       AC_MSG_ERROR("Odd argument passed for netcdf")
596     fi
597     ;;
598 esac
599
600 if [[ "$NETCDF_SUPPRESSED" = "no" ]]; then
601   if [[ "$GOT_NETCDF_INC" = "no" -o "$GOT_NETCDF_LIB" = "no" ]]; then
602     AC_MSG_ERROR(Could not find netcdf includes and/or libraries)
603   fi
604   CF_SUPPRESSED=no
605 fi
606
607
608 AC_MSG_CHECKING(if pthread support is default)
609 AC_TRY_RUN([
610 #include <pthread.h>
611 void* runme(void*p){return NULL;}
612 int main(int argc, char** argv) {
613   pthread_t p;
614   if (pthread_create(&p,NULL,runme,NULL) != 0)
615     return 1;
616   (void)pthread_detach(p);
617   return 0;
618 }],try_result=yes,try_result=no,try_result=no)
619 AC_MSG_RESULT($try_result)
620 PTHREAD_SUPPORT_DEFAULT=$try_result
621
622 PTHREAD_CC_OPTION_NEEDED=no
623
624 dnl If pthread support isn't default, we need to try out pthread
625
626 if [[ "$PTHREAD_SUPPORT_DEFAULT" != "yes" ]]; then
627 saved_CC="$CC"
628 CC="$CC -pthread"
629 AC_MSG_CHECKING(if -pthread option is required)
630 AC_TRY_RUN([
631 #include <pthread.h>
632 void* runme(void*p){return NULL;}
633 int main(int argc, char** argv) {
634   pthread_t p;
635   if (pthread_create(&p,NULL,runme,NULL) != 0)
636     return 1;
637   (void)pthread_detach(p);
638   return 0;
639 }],try_result=yes,try_result=no,try_result=no)
640 AC_MSG_RESULT($try_result)
641 CC="$saved_CC"
642 if [[ "$try_result" != "no" ]]; then
643   PTHREAD_CC_OPTION_NEEDED=yes
644 fi
645 fi
646
647 dnl PYGOTPTHREAD is yes/no depending on if python found pthread option necessary
648 dnl
649 GOT_PTHREAD_SUPPORT=no
650 if [[ "$PTHREAD_CC_OPTION_NEEDED" == "yes" ]]; then
651   PYOPT="$PYOPT -pthread"
652   LDFLAGS="$LDFLAGS -pthread"
653 fi
654
655 if [[ "$PTHREAD_CC_OPTION_NEEDED" == "yes" -o "$PTHREAD_SUPPORT_DEFAULT" == "yes" ]]; then
656   GOT_PTHREAD_SUPPORT=yes
657 fi
658
659 dnl It is possible to turn on memory debugging within RAVE
660 debugmemory=no
661 AC_ARG_ENABLE(debug-memory,
662   [  --enable-debug-memory     Turns on the rave memory debugging. This should usually not be activated.],
663   debugmemory=$enableval)
664 if [[ "x$debugmemory" = "xyes" ]]; then
665   PYOPT="$PYOPT -DRAVE_MEMORY_DEBUG"
666 fi
667
668 HLHDF_INCLUDE_DIR=$HLHDF_ROOTDIR/include
669 HLHDF_LIB_DIR=$HLHDF_ROOTDIR/lib
670 HLHDF_INSTALL_BIN=$HLHDF_ROOTDIR/bin/hlinstall.sh
671 HLHDF_HLDEF_MK_FILE=$HLHDF_ROOTDIR/mkf/hldef.mk
672
673 if [[ ! -f $HLHDF_INCLUDE_DIR/hlhdf.h ]]; then
674   AC_MSG_ERROR("There is no file $HLHDF_INCLUDE_DIR/hlhdf.h")
675 fi
676 if [[ ! -f $HLHDF_LIB_DIR/libhlhdf.a ]]; then
677   AC_MSG_ERROR("There is no library $HLHDF_LIB_DIR/libhlhdf.a")
678 fi
679 if [[ ! -f $HLHDF_INSTALL_BIN ]]; then
680   AC_MSG_ERROR("There is no installation script $HLHDF_INSTALL_BIN")
681 fi
682 if [[ ! -f $HLHDF_HLDEF_MK_FILE ]]; then
683   AC_MSG_ERROR("There is no mkfile $HLHDF_HLDEF_MK_FILE")
684 fi
685
686 AC_SUBST(PYCC)
687 AC_SUBST(PY_INCLUDES)
688 AC_SUBST(PY_SITEPACK)
689 AC_SUBST(PY_PYTHON_BIN)
690 AC_SUBST(RAVE_VERSION)
691 AC_SUBST(RAVE_PATCH_LEVEL)
692 AC_SUBST(PYOPT)
693 AC_SUBST(PYLDFLAGS)
694 AC_SUBST(PYLDSHARED)
695 AC_SUBST(PYCCSHARED)
696 AC_SUBST(PYDEFS)
697 AC_SUBST(GOT_ITRUNC)
698
699 #Substitute the PROJ arguments
700 AC_SUBST(PROJ_INCLUDE_DIR)
701 AC_SUBST(PROJ_LIB_DIR)
702
703 #Substitute the numpy argument
704 AC_SUBST(NUMPY_INCLUDE_DIR)
705
706 # Substitute the expat arguments
707 AC_SUBST(EXPAT_INCLUDE_DIR)
708 AC_SUBST(EXPAT_LIB_DIR)
709 AC_SUBST(EXPAT_SUPPRESSED)
710
711 # Substitute the jdk home arguments
712 AC_SUBST(JDK_SUPRESSED)
713 AC_SUBST(JDK_ROOT)
714 AC_SUBST(JDK_VERSION)
715
716 # Substitute the bufr arguments
717 AC_SUBST(BUFR_INCLUDE_DIR)
718 AC_SUBST(BUFR_LIB_DIR)
719 AC_SUBST(BUFR_TABLE_DIR)
720 AC_SUBST(BUFR_SUPPRESSED)
721
722 # Substitute the netcdf arguments
723 AC_SUBST(NETCDF_INCLUDE_DIR)
724 AC_SUBST(NETCDF_LIB_DIR)
725 AC_SUBST(NETCDF_SUPPRESSED)
726 AC_SUBST(CF_SUPPRESSED)
727
728 # Substitute the pthread arguments
729 AC_SUBST(GOT_PTHREAD_SUPPORT)
730
731 #Substitutes for the HLHDF library.The HLHDF
732 #installation contains a mk file that contains
733 #the paths for HDF5 and possibly ZLIB.
734 AC_SUBST(HLHDF_ROOTDIR)
735 AC_SUBST(HLHDF_INCLUDE_DIR)
736 AC_SUBST(HLHDF_LIB_DIR)
737 AC_SUBST(HLHDF_INSTALL_BIN)
738 AC_SUBST(HLHDF_HLDEF_MK_FILE)
739
740 AC_CONFIG_FILES(def.mk librave/toolbox/rave_config.h)
741 AC_OUTPUT