File: configure.ac

package info (click to toggle)
metview 4.4.8+dfsg.1-8
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 34,112 kB
  • ctags: 35,138
  • sloc: cpp: 185,595; ansic: 61,514; sh: 12,517; xml: 4,003; makefile: 3,583; yacc: 1,183; fortran: 762; lex: 761; perl: 333; f90: 41; python: 10
file content (1926 lines) | stat: -rw-r--r-- 61,110 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
AC_INIT(Metview)
AC_CONFIG_AUX_DIR(config)
AC_CONFIG_MACRO_DIR([m4])
AC_CANONICAL_SYSTEM

# take a copy of LDFLAGS so we can export it for inline C/Fortran
LDFLAGS_INLINE=${LDFLAGS}


AC_ARG_WITH([site],
       AS_HELP_STRING([--with-site],[Name of installation site]),
       [SITE_NAME="${with_site:-outside_ecmwf}"]
)
SITE_WMO_CODE="255"
AC_ARG_WITH([wmo-code],
       AS_HELP_STRING([--with-wmo-code],[WMO code for BUFR tables]),
       [SITE_WMO_CODE="${with_wmo_code}"]
)
if test "x$with_site" = xecmwf; then
  SITE_WMO_CODE="098"
fi
AC_SUBST(SITE_NAME)
AC_SUBST(SITE_WMO_CODE)

# Source file containing package/library versioning information.
. ${srcdir}/version.sh

if test "x$prefix" != xNONE; then
  ac_default_prefix=${prefix}
else
  prefix=${ac_default_prefix}
fi

echo ""
echo "configuring ${METVIEW_PACKAGE_NAME} ${METVIEW_PACKAGE_VERSION}${METVIEW_PACKAGE_VERSION_ADDENDUM} at ${SITE_NAME}"
echo ""

AC_SUBST(METVIEW_PACKAGE_NAME)
AC_SUBST(METVIEW_PACKAGE_VERSION)
AC_SUBST(METVIEW_PACKAGE_RELEASE_DATE)
AC_SUBST(METVIEW_MAGICS_MIN_VERSION)
AC_SUBST(METVIEW_GRIBAPI_MIN_VERSION)

AC_DEFINE_UNQUOTED(METVIEW_VERSION, "${METVIEW_PACKAGE_VERSION}")
AC_DEFINE_UNQUOTED(METVIEW_NAME, "${METVIEW_PACKAGE_NAME}")
AC_DEFINE_UNQUOTED(METVIEW_RELEASE_DATE, "${METVIEW_PACKAGE_RELEASE_DATE}")
AC_DEFINE_UNQUOTED(METVIEW_INSTALL_PATH, "${prefix}")
AC_DEFINE_UNQUOTED(METVIEW_SITE, "${SITE_NAME}")

printf ${METVIEW_PACKAGE_VERSION} > share/metview/app-defaults/MvVersion

# this is so that Metview can report accurately which version it is
# the first number is a version number in case we change the format of this file
mv_version_details=share/metview/app-defaults/MvVersionDetails
printf "1 "                                    >  ${mv_version_details}
printf "${METVIEW_PACKAGE_NAME} "              >> ${mv_version_details}
printf "${METVIEW_PACKAGE_VERSION_MAJOR} "     >> ${mv_version_details}
printf "${METVIEW_PACKAGE_VERSION_MINOR} "     >> ${mv_version_details}
printf "${METVIEW_PACKAGE_VERSION_REVISION} "  >> ${mv_version_details}
printf "${METVIEW_PACKAGE_VERSION_LABEL} "     >> ${mv_version_details}
printf "${METVIEW_PACKAGE_COPYRIGHT_YEAR} "    >> ${mv_version_details}
printf "${METVIEW_PACKAGE_COPYRIGHT_PERIOD} "  >> ${mv_version_details}
printf "${METVIEW_PACKAGE_RELEASE_DATE}\n"       >> ${mv_version_details}


# Ensure that make can run correctly
AC_CONFIG_SRCDIR(src/libMetview/MvDate.cc)
AM_CONFIG_HEADER(src/metview_config.h)

AM_INIT_AUTOMAKE($METVIEW_PACKAGE_NAME,"${METVIEW_PACKAGE_VERSION}${METVIEW_PACKAGE_VERSION_ADDENDUM}",[http://www.ecmwf.int/publications/manuals/metview/index.html])
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])

AC_PROG_CC([xlc_r icc gcc cc CC])
AC_PROG_CXX([xlC_r icpc g++ c++ CC])
AC_PROG_F77([pgf90 gfortran pgf77 xlf90_r xlf90 xlf77_r f90 g77])
AC_PROG_FC([pgf90 gfortran xlf90_r xlf90 f90])
AM_PROG_LEX([lex flex])
AC_PROG_YACC([yacc])
AM_PROG_CC_C_O
AC_AIX

#
# Checks for programs.
#
#AC_DISABLE_FAST_INSTALL   # TEMPORARY !!!!
AC_PROG_LIBTOOL
AC_SUBST(LIBTOOL_DEPS)
AC_PROG_LD
AC_SUBST(LD)
AC_PROG_INSTALL



MVINCLUDE=include
AC_SUBST(MVINCLUDE)



############################################
#
#  Metview startup script name --startup-script
#

STARTUP_SCRIPT=metview

AC_ARG_WITH([startup-script],
            [AS_HELP_STRING([--with-startup-script],[Name of the startup script [default=metview]])],
            [STARTUP_SCRIPT=$with_startup_script])

AC_SUBST(STARTUP_SCRIPT)



############################################
#
#  32 bit addressing  --enable-32bit
#
AC_ARG_ENABLE([32-bits-addressing-mode],
        [AC_HELP_STRING([--enable-32-bits-addressing-mode],
		                [Force 32 bits addressing mode on 64 bits machines])],
        enable_32_bits_addressing_mode='yes', enable_32_bits_addressing_mode='no')



######################################################################
#
#     Experimental
#
######################################################################

AC_ARG_ENABLE(experimental, [[  --enable-experimental             enable experimental component use only in developments [default=no]]],
      experimental=$enableval, experimental=no)

if test "x${experimental}" = xyes ; then
	CXXFLAGS="${CXXFLAGS} -DMETVIEW_EXPERIMENTAL"
fi

############################################
#
#   pkg-config
#
if test x$PKG_CONFIG = x; then
  PKG_CONFIG=pkg-config
fi

case `$PKG_CONFIG --version` in
[0.?|0.?.?|0.1[0-7]|0.1[0-7].?]) PKGCONFIG_REQUIRES="Requires"; ;;
*) PKGCONFIG_REQUIRES="Requires.private"; ;;
esac

AC_SUBST(PKGCONFIG_REQUIRES)



AC_CHECK_PROG(HAVE_KSH, ksh, true, false)

if test "x$HAVE_KSH" = "xfalse" ; then
    AC_MSG_ERROR([Could not find Korn Shell. Please ensure that ksh is installed.])
fi



###########################################
#
# Architecture dependent Compiler options
#
windows=no
LIBNAME="${LIBNAME:-lib}"
OPTI=""
OS=NA
MAJOR_VERSION=NA
QT_EXT=""

EMOS_I32_R64="-DR64 -DREAL_8 -DREAL_BIGGER_THAN_INTEGER"
#MAGICS_I32_R64="-DREAL_IS_DOUBLE -DMAGINT_IS_INT"
METVIEW_I32_R64="-DI32 -DMAGINT_IS_INT -DREAL_IS_DOUBLE"

PLATFORM_METVIEW_BITFLAGS="${METVIEW_I32_R64}"
PLATFORM_EMOS_BITFLAGS="${EMOS_I32_R64}"


FDBLIB="-L/usr/local/lib -L/usr/local/lib/metaps/lib -lfdb -lrt"
LEX="${LEX:-lex}"
make="${MAKE:-make}"

case "${host}" in
	*linux*)
		case "${host}" in
			x86_64*linux*)
				AXX="-m64 -fPIC"
				LIBNAME="lib64"
                QT_EXT="-64"  # used at ECMWF only
				MV_ENVIRON="ecm_lnx64"
				FDBLIB="-L/usr/local/lib/metaps/lib -lfdb"
###				X11LIB_DIR=" -L/usr/X11R6/${LIBNAME}"
				if test "x$enable_32_bits_addressing_mode" == xyes; then
					echo " "
					echo "You are on AMD 64 and building a 32 bit version of Metview."
					echo " "
					LIBNAME="lib"
					libdir=${prefix}/${LIBNAME}
					AXX="-m32"
				fi
				;;
			*)
				AXX=""
				LIBNAME="lib"
				MV_ENVIRON="ecm_lnx"
                CFLAGS="${CFLAGS} -Dlinux"
                CXXFLAGS="${CXXFLAGS} -Dlinux"
				;;
		esac
		OS="linux"
		CC_FLAGS="\$(PLATFORM_WARNING_LEVEL)"
		CXXFLAGS="${CXXFLAGS} -DUSE_NEW_IO"
#		AR="ar rlv"
		AR="ar"
		RANLIB="/usr/bin/ranlib -t"
		LEX="flex -l"
		F2o_RULE="\$(FC) -c \$(FC_FLAGS) \$(FPP_FLAGS) \$*.F"
		MAJOR_VERSION=`uname -r | awk -F. '{ print $1 }'`
		METVIEW_DEFINES="-DLITTLE -DLITTLE_END -DH_INCLUDES_CC"

		CPPFLAGS="$CPPFLAGS -I/usr/include/freetype2 -I/usr/include -I/usr/X11R6/include -I/usr/local/include"
###		LDFLAGS="$LDFLAGS -L/usr/local/${LIBNAME} -L/usr/${LIBNAME}"
		libdir=${prefix}/${LIBNAME}
		;;
	# IBM Server
	*-ibm-aix* )
		OS="AIX"
		MV_ENVIRON="ecm_ibm"
		make="gmake"
		PLATFORM_PROFILER="-qfullpath"
		PLATFORM_CLEAN_MAGIGS="-rm -f \$(SRC.f)"
		AIX_COMMON_FLAGS="-qstrict -qarch=auto -qtune=auto"
		CC_FLAGS="${PLATFORM_PROFILER} ${AIX_COMMON_FLAGS}"
		AIX_CXX_TEMPLATES="-qfuncsect -DH_INCLUDES_CC"
		CXXFLAGS="${CXXFLAGS} -DUSE_NEW_IO -qrtti ${PLATFORM_PROFILER} -DGL_GLEXT_PROTOTYPES ${AIX_COMMON_FLAGS} ${AIX_CXX_TEMPLATES}"
		# AR="ar -r -l -v -X32"
		#AR="ar -X64 cru"
		#ARFLAGS="${ARFLAGS} -X64"
		#AR_FLAGS="-X64 cru"
		#echo "ARFLAGS  = ${ARFLAGS}"
		#echo "AR_FLAGS = ${AR_FLAGS}"
		RANLIB="/bin/true"
		LEX="flex -l"
		CPP="xlc -E -C"
		CFLAGS="${CFLAGS} -DAIX"
		CXXFLAGS="${CXXFLAGS} -DAIX"
		#F2o_RULE="\$(CPP) \$(CPP_FLAGS) \$(FPP_FLAGS) -c \$*.F > \$*.f ; echo \"FC=\$(FC)\" ; \$(FC) -c \$(FC_FLAGS) \$*.f"
		MAJOR_VERSION=`uname -v`
		FDBLIB="-L/usr/local/lib/metaps/lib -lfdb"
		#METVIEW_DEFINES="-DXMSTRINGDEFINES"   DO WE NEED THIS?????
		EMOS_DEFINES="-DIBM -Drs6000"

		CPPFLAGS="${CPPFLAGS} -DMETVIEW_AIX_XLC -I/usr/include/freetype2" # -I/usr/include/freetype2 -I/opt/freeware/include -I/usr/local/include"
		LIBS="${LIBS} -lfreetype $LIBS -lpng -lz -liconv"  # for terralib
		AIX_GD_LIBS="-lfontconfig -liconv"
		METVIEW_3RDPARTY_LIBS="${METVIEW_3RDPARTY_LIBS} -lfreetype -lpng"
		;;
	# HP - aCC
	*-*-hpux* )
		OS="hpux"
		F2o_RULE="\$(FC) -c \$(FC_FLAGS) \$(FPP_FLAGS) \$*.F"
		MAJOR_VERSION=`uname -r | awk -F. ' { print $2 }'`
		AXX="-AA -Wp,-H30000"
		RANLIB="/usr/bin/ranlib"
		;;
    # MacOSX 10.8
    *darwin* )
        OS="macosx"
        F2o_RULE="\$(FC) -c \$(FC_FLAGS) \$(FPP_FLAGS) \$*.F"
        MAJOR_VERSION=`uname -r | awk -F. ' { print $2 }'`
        AXX=""
        CFLAGS="$CFLAGS -I/usr/local/include"
        CPPFLAGS="$CPPFLAGS -I/usr/include/sys -I/usr/local/include"
        LDFLAGS="$LDFLAGS -L/usr/local/lib"
    ;;
	# Compaq alpha ev68-dec-osf5.1 compiler
	*-dec-osf5.* )
		OS="osf1"
		F2o_RULE="\$(FC) -c \$(FC_FLAGS) \$(FPP_FLAGS) \$*.F"
		MAJOR_VERSION=`uname -r | awk -F. '{ print $1 }' | sed 's/V//'`
		AXX="-std strict_ansi -noimplicit_include"
		;;
	*-irix* )
		OS="irix"
		F2o_RULE="\$(FC) -c \$(FC_FLAGS) \$(FPP_FLAGS) \$*.F"
		MAJOR_VERSION=`uname -r | awk -F. '{ print $1 }'`
		RANLIB="/bin/true"
		;;
	*-sun* )
		OS="sun"
		F2o_RULE="\$(FC) -c \$(FC_FLAGS) \$(FPP_FLAGS) \$*.F"
		MAJOR_VERSION=`uname -r | awk -F. '{ print $1 }'`
		METVIEW_DEFINES="-D__GLX_MOTIF -DGLX_PROBLEMS"
		RANLIB="/usr/bin/true"
		;;
	*-*-cygwin* | *-*-mingw32*)
		echo " "
		echo "You try to install Metview on Windows!"
		echo " "
		echo " Please be aware that Windows is NOT a supported platform!!!"
		echo " "
		;;
esac


# overwrite MV_ENVIRON if at non-ECMWF site
if test "x$SITE_NAME" != 'xecmwf'; then
 MV_ENVIRON="common"
fi

# at ECMWF on Red Hat 6 (ecgb), libfdb is in a difference place

EXTRA_LD_LIBRARY_PATHS=""

if test "x$SITE_NAME" = 'xecmwf'; then
    if test "x$OS_VERSION" = 'xrhel6'; then
        FDBLIB="-L/usr/local/apps/fdb/current/lib -lfdb"
    fi

    if test "x$OS_VERSION" = 'xopensuse131'; then
        FDBLIB_PATH="/usr/local/apps/fdb/4.6.0/lib"
        FDBLIB="-L${FDBLIB_PATH} -lfdb"
        EXTRA_LD_LIBRARY_PATHS="${FDBLIB_PATH}:${EXTRA_LD_LIBRARY_PATHS}"
    fi
fi




AC_SUBST(MV_ENVIRON)
AC_SUBST(AXX)
#AC_SUBST(ARFLAGS)
#AC_SUBST(AR_FLAGS)



#
# Compiler dependent Compiler options
#
case "${CXX}" in
	# GNU GCC
	g++* )
		CFLAGS="$CFLAGS $AXX" # -std=c99 -ansi -fpermissive
		CXXFLAGS="${CXXFLAGS} ${AXX} -fno-gnu-keywords -Wno-deprecated -Wno-write-strings" # -ansi -std=c++98
		CPPLIBS="-lstdc++"
		OPTI="${OPTI} -O2"

		AC_CHECK_LIB(quadmath,sqrtq,LIBS="${LIBS} -lquadmath",
			AC_MSG_WARN([No libquadmath found --- you only need it if you use GCC 4.6 or newer.]))
		;;
	# Intel compiler 9.x
	icpc | icc )
		OPTI="${OPTI} -O2"
		# replace -i-static with -static-intel  !!!!
		CFLAGS="${CFLAGS} -i-static -wr654 -wr1125 -wr1011"
		CXXFLAGS="${CXXFLAGS} -i-static -wr654 -wr1125 -wr1011"
		# -i-static does the job but if any libraries compiled with g++ are used this is needed
		CPPLIBS="-lstdc++"
		;;
	# Portland C++
	pgCC )
		CPPLIBS=""     # assumes you use pgf90 or pgf77
		;;
	# IBM C++ compiler
	xlC_r | xlC )
		#  -qtune=auto
		#
		# -qfuncsect
		#
		# -qmkshrobj   --> no entry point message??? (570 MB)
		#
		#- qtemplateregistry=/scratch/graphics/cgm/metview/IBM/templateregistry
		#
		#	rm -f ${PWD}/templateregistry
		#	CXXFLAGS="-qstrict -qfuncsect -qtemplateregistry=${PWD}/templateregistry -qmaxmem=-1 -qarch=auto -bmaxdata:2000000000"
		# AR_BITFLAGS="-X32"
		OPTI="${OPTI} -O2"
		LDFLAGS="$LDFLAGS -Wl,-bbigtoc"  # to allow a larger number of symbols
		CFLAGS="-qtune=auto -qstrict -qmaxmem=-1 -qarch=auto -bmaxdata:3000000000 $CFLAGS"
		CXXFLAGS="-qtune=auto -qstrict -qfuncsect -qmaxmem=-1 -qarch=auto -bmaxdata:3000000000 ${CXXFLAGS}"
		CPPLIBS="${CPPLIBS} -lC"     # should strictly not nessecary when xlf is used
		;;
	# all other C++ compilers ...
	* )
		;;
esac

AC_SUBST(CPPLIBS)

# end of C++

############################################################################
AC_LANG_PUSH(Fortran)
############################################################################
#
# Which fortran compiler should be used?
#
# FLIBS is determined which Fortran compiler was used for Emoslib!!!
#
F77_ODB=""
MAGICS_DEFINES=""
MV_FLIBS=""

case "${F77}" in
	gfortran* )
		MAGICS_DEFINES="${MAGICS_DEFINES} -DGFORTRAN"
		FC_BITFLAGS="${AXX} -DGFORTRAN -fno-second-underscore -fpic -fdefault-real-8 -fcray-pointer"
		FLIBS="${FLIBS} -lgfortran"
		LDFLAGS="${LDFLAGS} -lgfortran"
		FFLAGS="${FFLAGS} ${AXX}"
		MV_FLIBS="${FLIBS}"
		FC_FLAGS="${FC_BITFLAGS}"
		FFLAGS="${FFLAGS} ${FC_BITFLAGS}"
		;;

	g77 )
		echo "Oops ... $F77 not implemented yet"
		FFLAGS="${FFLAGS}"
		FLIBS="${FLIBS}"
		;;

	# Intel compiler
	ifc | ifort)
		#echo "Oops ... $F77 not implemented yet"
		FC_BITFLAGS=""
		FFLAGS="${FFLAGS}"
		FLIBS="${FLIBS} -lifcore -lifport"
		FC_FLAGS="${FC_BITFLAGS}"
		;;

	# Portland C++
	pgf90 | pgf77 )
		#FLIBS="${FLIBS} -lpgftnrtl -lpgc"        # PGI 5.2
		FLIBS="${FLIBS} -lpgf90rtl -lpgftnrtl -lrt -lpgf90 -lpgf902 -lpghpf -lpgf90_rpm1 -lpghpf2 -lpgc"    # PGI 7.1
		#MV_FLIBS="${FLIBS} -lpgf90 -lpgf90_rpm1 -lpgf902 -lpgftnrtl -lpgsse2 -lpgsse1 -lm -lpgc -lrt"
		FC_BITFLAGS="-r8"
		FLIBS="$FLIBS -lpgftnrtl -lpgc -lrt"   # PGI 7.1
		MV_FLIBS="${FLIBS}"
		F77_ODB="-lifsaux -lmpi_serial -lodbdummy -lpgmp -lpgf90 -lpgf90_rpm1 -lpgf902"
		case "${host}" in
			x86_64*linux*)
				FFLAGS="${FFLAGS} -r8 -tp amd64 ${FC_BITFLAGS}"
				;;
			# Linux workstations x86
			*86-*-linux* )
				FFLAGS="${FFLAGS} -r8 -tp px ${FC_BITFLAGS}"
				;;
		esac
		FC_BITFLAGS="${FC_BITFLAGS} ${FFLAGS}"
        FCFLAGS="${FC_BITFLAGS} ${FCFLAGS}"
		;;

	# IBM fortran compiler
	xlf | xlf90 | xlf_r | xlf90_r )
		MAGICS_DEFINES="${MAGICS_DEFINES}"
		FC_BITFLAGS="${AXX} -qrealsize=8 -qintsize=4"
		FC_LINK_BITFLAGS="$AXX"
		FCFLAGS="\$(AIX_COMMON_FLAGS) -qextname -qddim -bdynamic -qnoescape -qmaxmem=-1 ${FC_BITFLAGS} ${PLATFORM_PROFILER}"
		#FFLAGS="${FFLAGS} ${AXX}"
		#METVIEW_FC_FLAGS="-I${grib_location}/include64 ${METVIEW_FC_FLAGS}"
		EMOS_FC_FLAGS="-qfixed -qintlog"
		#APTRA_FC_FLAGS="\$(PLATFORM_FC_FLAGS) \$(METVIEW_FC_FLAGS)"
		MACRO_F90_FLAGS="-qsuffix=f=f90"
		FLIBS="-lxlf90"
		MV_FLIBS="-lxlfpad -lxlf90 -lxlf"
		FFLAGS="${FFLAGS} ${AXX} ${FC_BITFLAGS}"
		FFIXED_FLAGS="-qfixed=72"
		F77_ODB="-lodbec -lifsaux -lmpi_serial -lesslsmp -lodbdummy -L/usr/lpp/xlf/lib -lxlf90 -lxlopt -lxlf -lxlsmp -lpthreads -lm -lc"
		;;
	# all other C++ compilers ...
	* )
		if test "x${F77}" = "x"; then
			echo "No Fortran compiler defined! Use F77=<name> to set one."
			FLIBS=""
		else
		echo "Oops ... $F77 not supported yet"
		fi
		;;
esac
AC_SUBST(FLIBS)
AC_SUBST(FFIXED_FLAGS)

AC_LANG_POP

# end of F O R T R A N


#########################################################################################
#
#  CHECKING CONFIGURE OPTIONS!!!!
#
#  enabling graphical user interface
#
#########################################################################################


AC_ARG_ENABLE(new_ui, [[  --enable-new-ui	 enable the new graphics user interface [default=yes]]],
  new_ui=$enableval, new_ui=yes)

if test "x$new_ui" = xyes ; then
   AC_DEFINE(METVIEW_NEW_GUI, 1)
fi



AC_ARG_ENABLE(ui, [[  --enable-ui	          enable the graphics user interface [default=yes]]],
  ui=$enableval, ui=yes)

if test "x$ui" = xyes; then
    case "${host}" in
	    *linux*)
		    AC_DEFINE(METVIEW_GUI, 1)
		    echo ""
		    #echo "Your OpenGL setup:"
		    #glxinfo | grep rendering
		    #glxinfo | grep "OpenGL vendor"
		    #glxinfo | grep "OpenGL version"
		    #glxinfo | grep "glx vendor"
		    #glxinfo | grep "glx version"
		    #echo ""
		    AC_CHECK_HEADERS([Xm/Xm.h])
		    ;;
        *aix*)
            AC_DEFINE(METVIEW_GUI, 1)
            ;;
        *darwin*)
            AC_DEFINE(METVIEW_GUI, 1)
            ;;
	    * )
		    echo "**************************************************"
		    echo ""
		    echo "  Currently the Graphical User Interface is not"
		    echo "  supported on this platform!!!"
		    echo ""
		    echo "**************************************************"
		    ui=no
		    ;;
    esac


    # ImageMagick


    AC_CHECK_PROG(HAVE_CONVERT, convert, true, false)

    if test "x$HAVE_CONVERT" = "xfalse" ; then
        AC_MSG_ERROR([Could not find the ImageMagick convert command])
    fi

    ######################################################################
    #
    #     Qt
    #
    ######################################################################

    qt=yes

    # Qt with AutoTroll.
    m4_include([aux_build/autotroll.m4])

    if test "x$new_ui" = "xyes" ; then
        AT_WITH_QT([+xmlpatterns +xml +network +webkit],[+help])
    else
        AT_WITH_QT([+xmlpatterns +xml +network],[+help])
    fi

    AC_MSG_CHECKING([for Qt])
    AT_REQUIRE_QT_VERSION([4.6],
       AC_MSG_WARN([Qt version >= 4.6 is required]))

    # ensure that the Qt/XmlPatterns headers are installed
    SAVED_CPPFLAGS=${CPPFLAGS} # save CPPFLAGS
    CPPFLAGS="${CPPFLAGS} ${QT_INCPATH}"
    AC_LANG_PUSH(C++)
    AC_CHECK_HEADER(QXmlQuery, ,AC_MSG_ERROR([Could not successfully find or compile with QXmlQuery. This should be in the Qt/XmlPatterns or Qt/Webkit dev package]))
    AC_LANG_POP
    CPPFLAGS=${SAVED_CPPFLAGS} # restore CPPFLAGS


    AC_DEFINE(METVIEW_QT, 1)
    CXXFLAGS="${CXXFLAGS} -DMETVIEW_QT"
    MAGPLUS_LIB_QT="-lMagPlusQt"
    echo "set"

    # remove any optmisation flags that we get from Qt - we want to control our own
    QT_CFLAGS=`echo ${QT_CFLAGS} | sed "s/-O.//g"`
    QT_CXXFLAGS=`echo ${QT_CXXFLAGS} | sed "s/-O.//g"`
    QT_CPPFLAGS=`echo ${QT_CPPFLAGS} | sed "s/-O.//g"`

    # unfortunately, qmake combines its linker flags with its libraries in its LIBS variable
    # which is translated into QT_LIBS. On some systems we need finer-grain control over the
    # positioning of these elements, so we need to do a search & replace with some 'sed' magic
    # in order to extract the different components: QT_EXTRACTED_LDFLAGS should contain just the
    # -L/library/path elements, and QT_EXTRACTED_LIBS should contain everything else. We then
    # put these back into QT_LIBS and QT_LDFLAGS.
    QT_EXTRACTED_LIBS=`echo " ${QT_LIBS}" | sed 's/ -L[[^ ]]*//g'`
    QT_EXTRACTED_LDFLAGS=`echo " ${QT_LIBS}" | sed 's/ -[[^L]][[^ ]]*//g' | sed 's/ [[^-]][[^L]][[^ ]]*//g'`

    QT_LIBS=$QT_EXTRACTED_LIBS
    QT_LDFLAGS="$QT_LDFLAGS $QT_EXTRACTED_LDFLAGS"

    AC_SUBST(QT_LIBS)
    AC_SUBST(QT_LDFLAGS)


    ######################################################################
    #
    #     Qt debug
    #
    ######################################################################

    AC_ARG_ENABLE(qtdebug, [[  --enable-qtdebug        enable QDebug output in Qt-based modules [default=no]]],
          qtdebug=$enableval, qtdebug=no)

    if test "x${qt}" = xyes -a "x${qtdebug}" = xno ; then
	    CXXFLAGS="${CXXFLAGS} -DQT_NO_DEBUG_OUTPUT"
    fi

else
    ui=no
    qt=no
    new_ui=no
    echo "                         ***"
    echo "Building batch version with no graphical user interface."
    echo "                         ***"
fi






######################################################################
#
#  Magics++ support  --enable-magics
#
######################################################################
AC_ARG_ENABLE(magics,[[  --enable-magics         enable the Magics++ library support [default=yes]]],
  magics=$enableval, magics=yes)

magics_odb=no

if test "x$magics" = xyes; then

  #################################################
  #
  #   M A G P L U S  H O M E
  #
  AC_ARG_WITH([magics-home],
       [AS_HELP_STRING([--with-magics-home],[Location of Magics libraries])],
       []
    )

  # if no magics home is set we try /usr/local or assume /usr as default
  if test "x${with_magics_home}" = "x" ; then
    if test -e ${MAGPLUS_HOME}/bin/magics-config ; then
       with_magics_home=${MAGPLUS_HOME}
    else
       AC_MSG_WARN([$MAGPLUS_HOME is not a valid Magics directory, so we test for more ...])
       if test -e /usr/local/bin/magics-config ; then
         with_magics_home=/usr/local
         echo " FOUND Magics in /usr/local"
       elif test -e /usr/bin/magics-config ; then
         with_magics_home=/usr
         echo " FOUND Magics in /usr"
       else
         AC_MSG_ERROR([No location found for Magics!!!])
       fi
    fi
  fi
  MAGPLUS_HOME="${with_magics_home}"
  AC_SUBST(MAGPLUS_HOME)
  ##################################################

  export PKG_CONFIG_PATH=${MAGPLUS_HOME}/lib64/pkgconfig/:${MAGPLUS_HOME}/lib/pkgconfig/:${PKG_CONFIG_PATH}
  PKG_CHECK_MODULES(MAGICS, [magics >= ${METVIEW_MAGICS_MIN_VERSION}],
  [
    # check where the libraries are
    MAGPLUS_LIBDIR=`${MAGPLUS_HOME}/bin/magics-config --libdir`
    AC_SUBST(MAGPLUS_LIBDIR)

    MAGPLUSLIB_APPEND=${MAGPLUS_LIB}  # to add to the end, later
    AC_SUBST(MAGICS_CFLAGS)
    #CPPFLAGS="$MAGICS_CFLAGS $CPPFLAGS"

    MAGPLUS_CPPFLAGS="-I${with_magics_home}/include/magics ${MAGPLUS_CPPFLAGS}"
    MAGPLUS_LDFLAGS="-L${MAGPLUS_LIBDIR} ${MAGPLUS_LDFLAGS}"
    MAGPLUS_LIB="-L${MAGPLUS_LIBDIR} -lMagWrapper -lMagPlus"
    # note: the NetCDF libraries will be added to MAGPLUS_LIB later in this script

    if test "x`${MAGPLUS_HOME}/bin/magics-config --with-metview`" = xno; then
     AC_MSG_ERROR([Magics has not been buiilt with Metview support! Please re-configure Magics with the --enable-metview flag.])
    fi
    if test "x`${MAGPLUS_HOME}/bin/magics-config --with-cairo`" = xyes; then
     magics_cairo=yes
    else
     magics_cairo=no
    fi
    if test "x`${MAGPLUS_HOME}/bin/magics-config --with-bufr`" = xyes; then
     magics_bufr=yes
    else
     magics_bufr=no
    fi
    if test "x`${MAGPLUS_HOME}/bin/magics-config --with-odb`" = xyes; then
     magics_odb=yes
    else
     magics_odb=no
    fi
    if test "x`${MAGPLUS_HOME}/bin/magics-config --with-gd`" = xyes; then
     magics_gd=yes
     MAGPLUS_LIB="${MAGPLUS_LIB} -lgd -lfreetype -ljpeg -lpng"
    else
     magics_gd=no
    fi

    # the autotools installation of Magics does not have the following flag,
    # so we test for it by trying to ask for it and read the return value
    if test "`grep with.qtlib ${MAGPLUS_HOME}/bin/magics-config > /dev/null; echo $?`" = 1; then
        echo "Magics has a separate Qt library (autotools installation)"
    else
        if test "x`${MAGPLUS_HOME}/bin/magics-config --with-qtlib`" = xno; then
            MAGPLUS_LIB_QT=""
            echo "Magics does not have a separate Qt library (cmake installation)"
        else
            echo "Magics has a separate Qt library (cmake installation)"
        fi
    fi
    MAGPLUS_LIB="${MAGPLUS_LIB} ${MAGPLUSLIB_APPEND}"

    ##################################
    # check whether the static MagPlus library exists - if so, it should be a dependency of any
    # Metview module which uses Magics++
    DEPEND_MAGPLUS_LIBS=$${MAGPLUS_LIBDIR}/libMagWrapper.a
    if test -e $${MAGPLUS_LIBDIR}/libMagPlus.a ; then
      DEPEND_MAGPLUS_LIBS="${DEPEND_MAGPLUS_LIBS} ${MAGPLUS_LIBDIR}/libMagPlus.a"
    fi
    ##################################

    AC_DEFINE(METVIEW_MAGICS, 1)
    echo "Magics version detected:  `${MAGPLUS_HOME}/bin/magics-config --version`"
],
[
    magics=no
    magics_ver=`${MAGPLUS_HOME}/bin/magics-config --version`
    AC_MSG_WARN([Magics version ${METVIEW_MAGICS_MIN_VERSION} is required. Detected: ${magics_ver}])
    AC_MSG_ERROR([If you do not want Magics support, use the --disable-magics option.])
])
fi




#
#   FREETYPE
#
AC_CHECK_LIB([fontconfig], [FcInitLoadConfigAndFonts], [
		  AC_CHECK_HEADER([fontconfig/fontconfig.h], [
		    LIBS="-lfontconfig ${LIBS}"
		  ])
		])

#
# Find the X11 include and library directories.
#
if test "x$ui" = xyes ; then

  #
  #  OpenMotif
  #
  AC_CHECK_LIB(Xext,XShmAttach,LIB_XEXT='-lXext',,)
  AC_CHECK_LIB(Xext,XShapeCombineMask)
  AC_CHECK_LIB(Xt,XtAppMainLoop)
  AC_CHECK_LIB(Xm,XmCreatePushButton,,AC_MSG_ERROR([Motif not found.]))

  # Extra Motif libraries (XPM)
  AC_CHECK_LIB(X11,XDefaultScreen)
  AC_CHECK_LIB(Xpm,XpmReadFileToImage,,AC_MSG_ERROR([Library Xpm not found]))
  AC_CHECK_LIB(Xmu,XmuClientWindow,   ,AC_MSG_ERROR([Library Xmu not found.]))

  CPPFLAGS="${CPPFLAGS} -I/usr/include/X11"
  AC_CHECK_HEADER(xpm.h,              ,AC_MSG_ERROR([could not successfully find or compile with xpm.h]))

  # Check for a suitable Motif implementation
  AC_COMPILE_IFELSE(
	[AC_LANG_PROGRAM(
		[[#include <Xm/DrawingAP.h>]],
		[[XmDrawingAreaConstraintPart* p;]]
	)],
	[],
	[AC_MSG_FAILURE([Your Motif does not implement XmDrawingAreaConstraintPart (are you using Lesstif? It is not supported).])]
  )
  AC_CHECK_LIB(pthread,pthread_key_create)

  CPPFLAGS="${CPPFLAGS} -DMETVIEW_MOTIF"

fi
#### end GUI


################################################################################################
#
#  Trajectory support  --enable-trajectory
#
#AC_ARG_ENABLE(traj, [[  --enable-trajectory	  enable the Trajectory package (ECMWF internal) [default=no]]],
#  traj=$enableval, traj=no)
#if test "x$traj" = xyes; then
#  AC_DEFINE(METVIEW_TRAJ, 1)
#fi



AC_LANG([C++])
#
# freetype
#
if test "x$raster" = xyes; then
  AC_CHECK_HEADER(ft2build.h,,AC_MSG_WARN([could not successfully compile with FreeType2]))
fi

#
# For XML parser expat
#
AC_CHECK_HEADER(expat.h,,
  AC_MSG_WARN([could not successfully compile with expat using the])
  AC_MSG_WARN([default compiler flags;])
  unset ac_cv_header_expat_h)
AC_CHECK_LIB(expat, XML_ParserCreate ,,AC_MSG_ERROR([expat xml parser library not found.]))

#
#   GDBM
#
AC_CHECK_HEADER(gdbm.h,,AC_MSG_ERROR([could not successfully compile with gdbm.h]))
AC_CHECK_LIB(gdbm,gdbm_open)



#########################################################################################
#
# For netcdf header file
#
#########################################################################################
AC_ARG_WITH([netcdf],
       [AS_HELP_STRING([--with-netcdf],
       [Prefix of NetCDF libraries and headers.])],
       [CPPFLAGS="-I${with_netcdf}/include ${CPPFLAGS}";LDFLAGS="-L${with_netcdf}/lib ${LDFLAGS}"]
)
AC_CHECK_HEADER(netcdfcpp.h,,
  AC_MSG_WARN([could not successfully compile with netcdfcpp.h!])
  unset ac_cv_header_netcdf_h)

AC_CHECK_LIB(netcdf,ncvarid ,NETCDF_LIBS="-lnetcdf_c++ -lnetcdf",AC_MSG_ERROR([netcdf library not found.]))
#AC_CHECK_LIB(netcdf_c++, nctypelen        ,echo "",AC_MSG_ERROR([netcdf_c++ library not found.]))


#########################################################################################
#
# Check for curl - required by MARS web access, and sometimes needed by NetCDF
#
#########################################################################################
AC_MSG_CHECKING([for curl library required by MARS web access and sometimes needed by NetCDF])

AC_CHECK_LIB(curl,curl_easy_setopt,  [have_curl="yes"], have_curl="no")

# NetCDF can be built with a dependency on curl. Therefore, we add it to the libraries if it is
# installed; otherwise, issue a warning.

if test "${have_curl}" = "yes"
then
	NETCDF_LIBS="${NETCDF_LIBS} -lcurl"
else
    echo "    No curl library - ensure that your NetCDF library does not require it."
    echo "    NOTE: the MARS web access will not be built if curl is not installed."
fi


# add the NetCDF libaries to MAGPLUS__LIB
MAGPLUS_LIB="${MAGPLUS_LIB} ${NETCDF_LIBS}"


#########################################################################################
#
# Check for GRIB API
#
#########################################################################################
AC_MSG_CHECKING([for JPEG libraries needed by GRIB_API])

AC_CHECK_LIB(openjpeg,opj_image_create,  [have_openjpeg="yes"], have_openjpeg="no")
AC_CHECK_LIB(jasper,  jas_stream_memopen,[have_jasper="yes"], have_jasper="no")

# GRIB_API prefers openjpeg over jasper, so we do the same - if openjpeg is installed,
# then use it; otherwise, if jasper is installed, then use that. If neither is installed,
# then issue a warning.

if test "${have_openjpeg}" = "yes"
then
	JPEG_LIB="-lopenjpeg -lm";LIBS="${LIBS} ${JPEG_LIB}"
fi


if test "${have_jasper}" = "yes"
then
	JPEG_LIB="-ljasper";LIBS="${LIBS} ${JPEG_LIB}"
fi

if test "${have_jasper}" = "no" -a "${have_openjpeg}" = "no"
then
		echo " "
		echo "    No OpenJPEG or Jasper (JPEG 2000) library could be found!"
		echo "    Your Metview programs should work nevertheless as long as"
		echo "    your installed GRIB_API does NOT require it! Compile GRIB_API"
		echo "    without JPEG support."
		echo " "
fi


GRIB_API_INCLUDE_SUBDIR="include"

if test "x$SITE_NAME" = 'xecmwf'  # only at ECMWF we use 'include64'
then
  case "${host}" in
    *-ibm-aix* )   # IBM Server
          GRIB_API_INCLUDE_SUBDIR="include64"
          echo "ecgate machine detected - using ${GRIB_API_INCLUDE_SUBDIR} for grib_api include subdirectory"
    ;;
    *x86_64* )   # Linux 64-bit
        GRIB_API_INCLUDE_SUBDIR="include64"
        echo "64-bit Linux machine detected - using ${GRIB_API_INCLUDE_SUBDIR} for grib_api include subdirectory"
    ;;
  esac
fi

grib_location=/usr/local
AC_ARG_WITH([grib-api],
       [AS_HELP_STRING([--with-grib-api],
       [Prefix of GRIB API libraries and headers.])],
       [GRIB_API_INC="-I${with_grib_api}/${GRIB_API_INCLUDE_SUBDIR}";CPPFLAGS="${GRIB_API_INC} ${CPPFLAGS}";GRIB_API_LIB="-L${with_grib_api}/${LIBNAME}";LDFLAGS="${GRIB_API_LIB} ${LDFLAGS}";grib_location=${with_grib_api};]
)

# if no grib_api dir is set, we still need to add its 'include' dir to the fortran compilation flags
if test "x${with_grib_api}" = "x" ; then
    GRIB_API_INC="-I${grib_location}/${GRIB_API_INCLUDE_SUBDIR}"
fi



#METVIEW_FC_FLAGS="${FCFLAGS} -I${grib_location}/include ${METVIEW_FC_FLAGS}"

# Note: we add "-I/usr/include" to FCFLAGS for the case where GRIB_API has been installed by RPM
FCFLAGS="${FCFLAGS} ${GRIB_API_INC} ${METVIEW_FC_FLAGS} -I/usr/include"

AC_CHECK_LIB(grib_api,grib_get_message,GRIBAPI_LIBS="-lgrib_api",AC_MSG_ERROR([Grib API could not be linked! Try setting --with-grib-api .]))

GRIB_API_LIB="${GRIB_API_LIB} ${GRIBAPI_LIBS} ${JPEG_LIB}" # for inline fortran/c macros
AC_SUBST(GRIB_API_INC) # for inline fortran/c macros
AC_SUBST(GRIB_API_LIB) # for inline fortran/c macros
AC_SUBST(GRIBAPI_LIBS)
AC_SUBST(LDFLAGS_INLINE)  # for inline fortran/c macros



#############################################################################################################
#
#     E M O S L I B -- always DOUBLE precision !!!
#

# emoslib is currently required (or libMars interpolation/subarea extraction, etc)
# so remove the option to disable it.

#AC_ARG_ENABLE(emos, [[  --enable-emos	          enable the EmosLib support [default=yes]]],
#  emos=$enableval, emos=yes)

emos="yes"

if test "x$emos" = xyes; then

    AC_MSG_CHECKING([for EmosLib (ECMWF)])

    EMOS_LIB_NAME="emosR64"

    emos_path=/usr/local/${LIBNAME}

    AC_ARG_WITH([emos-libraries],
           [AS_HELP_STRING([--with-emos-libraries],[Location of EMOS libraries @<:@default is /usr/local/lib@:>@])],
           [EMOS_LIB_FLAGS="-L$with_emos_libraries";LDFLAGS="$EMOS_LIB_FLAGS $LDFLAGS"; emos_path=$with_emos_libraries]
    )

    AC_ARG_WITH([emos-libname],
           [AC_HELP_STRING([--with-emos-libname],[Name of EMOS library @<:@default is emosR64@:>@ ])],
           [EMOS_LIB_NAME="$with_emos_libname"]
    )

    AC_CHECK_LIB(${EMOS_LIB_NAME},pbopen,echo "EmosLib detected",
                AC_MSG_ERROR([Emoslib (${EMOS_LIB_NAME}) could not be linked! Metview requires emoslib with 64-bit reals (usually libemosR64.a). Try setting --with-emos-libraries and --with-emos-libname.]))

    AC_CHECK_LIB(${EMOS_LIB_NAME},intf2,echo "EmosLib has GRIB_API support",
                AC_MSG_ERROR([Emoslib (${EMOS_LIB_NAME}) appears to have been built without GRIB_API support. Please enable this option when rebuilding emoslib.]),
                ${GRIBAPI_LIBS} ${FLIBS})


    AC_DEFINE(METVIEW_EMOS, 1)
    METVIEW_3RDPARTY_LIBS="$METVIEW_3RDPARTY_LIBS -l${EMOS_LIB_NAME}"

    MV_EMOSLIB="${EMOS_LIB_FLAGS} -l${EMOS_LIB_NAME}"
    AC_SUBST(MV_EMOSLIB)

else
    emos="no"
fi




#########################################################################################
#
# For ecRegrid header file
#
#########################################################################################
AC_ARG_ENABLE(ecregrid, [[  --enable-ecregrid	          enable the ecRegrid support (only at ECMWF) [default=no]]],
  ecregrid=$enableval, ecregrid=no)

if test "x$ecregrid" = xyes ; then
   AC_MSG_CHECKING([for ecRegrid (ECMWF)])
   AC_DEFINE(METVIEW_ECREGRID, 1)

   AC_ARG_WITH([ecregrid],
       [AS_HELP_STRING([--with-ecregrid],
       [Prefix of ecRegrid libraries and headers.])],
       [CPPFLAGS="-I${with_ecregrid}/include ${CPPFLAGS}";LDFLAGS="-L${with_ecregrid}/lib ${LDFLAGS}"]
   )
   AC_CHECK_HEADER(ecregrid_api.h,,
   AC_MSG_ERROR([could not successfully compile with ecregrid_api.h!])
    unset ac_cv_header_ecregrid_h)

#   AC_CHECK_LIB(ecregrid,ecregrid_set_increments,LIBS="-lecregrid",AC_MSG_ERROR([ecregrid library not found.]))
   ECREGRID_LIBS="-lecregrid"
fi
AC_SUBST(ECREGRID_LIBS)
AC_SUBST(METVIEW_ECREGRID)

#########################################################################################
#
# For INPE data access
#
#########################################################################################
AC_ARG_ENABLE(inpe, [[  --enable-inpe             enable the INPE support (only at INPE) [default=yes]]],
  inpe=$enableval, inpe=yes)

if test "x$inpe" = xyes ; then
   AC_MSG_CHECKING([for INPE (INPE)])
   AC_DEFINE(METVIEW_INPE, 1)
fi

#####################################################################
#
#    M A R S   ODB  access
#
AC_ARG_ENABLE(mars-odb, [[  --enable-mars-odb	          enable the MARS ODB accesss [default=no]]],
  marsodb=$enableval, marsodb=no)

#####################################################################
#
# ODB access
#
AC_ARG_ENABLE(odb, [[  --enable-odb	          enable the ODB support [default=no]]],
  odb=$enableval, odb=no)

if test "x${marsodb}" = xyes -o "x${magics_odb}" = xyes ; then
	odb=yes
fi

odbnew=no
odbold=no
odbplot=no
ODB_CPPFLAGS=""
ODB_LDFLAGS=""
ODB_LIBS=""

ECKIT_LIBS="-lEc"     # ODB_API 0.9.x


# we may need to use eckit, depending on the version of ODB_API
# NOTE: at least for the autotools version, we make the assumption that if
# --with-eckit is supplied, then we are using at least ODB_API 0.10.0, which
# relies on eckit.
# Note that we should not really have -I${with_odb}/include/odb_api, but
# src/libMArs/odb.cc needs it.

AC_ARG_WITH([eckit],
     [AS_HELP_STRING([--with-eckit],
     [Prefix of eckit libraries and headers, used in ODB_API 0.10])],
     [ECKIT_INC="-I${with_eckit}/include -I${with_eckit}/include/eckit/exception";CPPFLAGS="-DODB_ECKIT ${ECKIT_INC} ${CPPFLAGS}";
      ECKIT_LDFLAGS="-L${with_eckit}/lib";ECKIT_LIBS="-leckit";
      EXTRA_LD_LIBRARY_PATHS="${with_eckit}/lib:${EXTRA_LD_LIBRARY_PATHS}"]
  )


if test "x$odb" = xyes ; then

  # Test if we can support ODB-2
  ODB_LIBDIR=""
  AC_MSG_CHECKING([for ODB-2 ])
  AC_ARG_WITH([odb],
  [AS_HELP_STRING([--with-odb],
     [Prefix of ODB libraries and headers.])],
     [ODB_CPPFLAGS="-DODB_SUPPORT -I${with_odb}/include -I${with_odb}/include/odb_api -I${with_odb}/include/eclib  -I${with_odb}/include/eclib/eclib -I${with_odb}/include";
     ODB_LIBDIR="${with_odb}/lib";
     ODB_LDFLAGS="-L${ODB_LIBDIR} ${ECKIT_LDFLAGS}";
     ODB_LIBS="-lOdb ${ECKIT_LIBS}";
     AC_CHECK_FILE(${with_odb}/lib/libOdb.a,odbnewstatic=yes,odbnewstatic=no)
     AC_CHECK_FILE(${with_odb}/lib/libOdb.so,odbnewshared=yes,odbnewshared=no)]
   )
   AC_SUBST(ODB_LIBDIR)


  if test "x$odbnewstatic" = xyes -o "x$odbnewshared" = xyes; then
    odbnew=yes
  else
    odbnew=no
  fi

# if using ODB_API 0.9.21:
#     [ODB_CPPFLAGS="-DODB_SUPPORT -DOLD_ODB_API -I${with_odb}/include";

# if using ODB_API 0.9.24:
#     [ODB_CPPFLAGS="-DODB_SUPPORT -I${with_odb}/include -I${with_odb}/include/eclib -I${with_odb}/include/odb_api -I${with_odb}/include/odb_api/odblib";
  if test "x$odbnew" = xyes; then 
      AC_DEFINE(METVIEW_ODB_NEW, 1,["Support for the ODB-2 API"])
      CPPFLAGS="${CPPFLAGS} -DMETVIEW_ODB_NEW" 

      #Test if we can plot ODB
      if test "x${magics_odb}" = xyes ; then	
 	 AC_DEFINE(METVIEW_ODB_PLOT, 1,["Support for plotting ODB data"])
     	 CPPFLAGS="${CPPFLAGS} -DMETVIEW_ODB_PLOT" 
	 odbplot=yes
      else
	 AC_MSG_WARN(["ODB plotting is disabled, because Magics was built without ODB support! Please, rebuild Magics with ODB support to enable ODB plotting!"])
      fi

      ODB1_BIN=""   # default - assume the user will not need to know the bin directory (ie it's in their PATH)
      AC_MSG_CHECKING([for ODB-1])
      AC_ARG_WITH([odb1-bin],
          [AS_HELP_STRING([--with-odb1-bin],
          [Path to the ODB-1 bin directory.])],
          [AC_CHECK_FILE(${with_odb1_bin},odboldbin=yes,odboldbin=no)]
       )


      # Test if we can support ODB-1
      # Note that we used to test for odbsql2, but now it
      # appears that we only need to test for odbsql.

      if test "x$odboldbin" = xyes; then
          ODB1_BIN=${with_odb1_bin} 
          AC_SUBST(ODB1_BIN)
          AC_CHECK_FILE(${with_odb1_bin}/odbsql,odbold=yes,odbold=no) 
             
          if test "x$odbold" = xyes; then
              AC_DEFINE(METVIEW_ODB_OLD, 1,["Support for the ODB-1 API"])
              CPPFLAGS="${CPPFLAGS} -DMETVIEW_ODB_OLD" 

              ODB1_VERSION=ANY    # did the user supply a required ODB-1 version?
              AC_ARG_WITH([odb1-version],
                 [AS_HELP_STRING([--with-odb1-version],[Required version of ODB-1 environment [default=ANY.]])],
                 [ODB1_VERSION=$with_odb1_version])
              AC_SUBST(ODB1_VERSION)

              ODB1_USE_SCRIPT="$ODB1_BIN/use_odb.sh"       # ODB-1 use script
              AC_ARG_WITH([odb1-use-script],
                  [AS_HELP_STRING([--with-odb1-use-script],[Path to ODB-1 'use' script (normally 'use_odb.sh').])],
                  [ODB1_USE_SCRIPT=$with_odb1_use_script])
              AC_SUBST(ODB1_USE_SCRIPT)
              echo "ODB1_USE_SCRIPT: $ODB1_USE_SCRIPT"

              AC_ARG_WITH([odb1-module],
                  [AS_HELP_STRING([--with-odb1-module],[Name of the ODB-1 module, e.g. 'odb' or 'odb/CY40R1.001').])],
                  [ODB1_MODULE=$with_odb1_module])
              AC_SUBST(ODB1_MODULE)
              echo "ODB1_MODULE: $ODB1_MODULE"
          else
	       AC_MSG_WARN("ODB-1 support is DISABLED - No odbsql script found!")
	  fi
     else
	   AC_MSG_WARN("ODB-1 support is DISABLED - No ODB-1 bin directory found!")
     fi
	
  # If no ODB-2 libraries found
  else		
     ODB_CPPFLAGS=""
     ODB_LDFLAGS=""
     ODB_LIBS=""

     if test "x${magics_odb}" = xyes ; then
         AC_MSG_FAILURE("[Cannot build Metview! Magics was built with ODB support but no ODB-2 library was found! Please provide a valid ODB-2 library path via --with-odb"])
     else	
     	 AC_MSG_FAILURE(["Cannot build Metview! ODB support is enabled but no ODB-2 library was found! Please provide a valid ODB-2 library path via --with-odb"])
     fi	
  fi
fi

# ODB is supported if either ODB-2 or ODB-1 is supported
if test "x$odbnew" = xyes -o "x$odbold" = xyes ; then
    AC_DEFINE(METVIEW_ODB, 1)
    CPPFLAGS="${CPPFLAGS} -DMETVIEW_ODB"
else
    odb=no
fi

#We disable MARS ODB if no ODB-2 library is found
if test "x$odbnew" != xyes ; then
    marsodb=no
fi


#####################################################################
#
#    M A R S   ODB  access
#
#AC_ARG_ENABLE(mars-odb, [[  --enable-mars-odb	          enable the MARS ODB accesss (client-server) [default=no]]],
#  marsodb=$enableval, marsodb=no)

MARS_ODB_ACCESS=MARS_none

if test "x${marsodb}" = xyes ; then
  AC_DEFINE(METVIEW_MARS_ODB, 1)

  MARS_ODB_ACCESS=MARS_local
fi

AC_SUBST(MARS_ODB_ACCESS)

#####################################################################
#
#    M A R S  access
#
AC_ARG_ENABLE(mars-access, [[  --enable-mars-access	          enable the MARS accesss (client-server) [default=no]]],
  mars=$enableval, mars=no)

MARS_ACCESS=MARS_none

if test "x$mars" = xyes ; then
  AC_DEFINE(METVIEW_MARS, 1)

  MARS_ACCESS=MARS_local

    # MARS local home
    mars_lh_found='not_supplied'
    AC_ARG_WITH([local-mars-home],
           [AS_HELP_STRING([--with-local-mars-home],
           [Local MARS home directory])],
           [MARS_HOME="${with_local_mars_home}";
            AC_CHECK_FILE(${with_local_mars_home},mars_lh_found=yes,mars_lh_found=no)]
    )

    if test "x$mars_lh_found" = xnot_supplied; then
       echo ""
       AC_MSG_ERROR([If enabling local MARS support, please supply the --with-local-mars-home path.])
fi


    if test "x$mars_lh_found" = xno; then
       echo ""
       AC_MSG_ERROR([Could not find Mars home directory. Please check the --with-local-mars-home path.])
    fi

    AC_SUBST(MARS_HOME)
fi



#####################################################################
#
#    M A R S  catalog support
#
AC_ARG_ENABLE(marscatalog, [[  --enable-marscatalog	          enable the MARS catalog support only at ECMWF) [default=no]]],
  marscatalog=$enableval, marscatalog=no)

#MARS_CATALOG=MARS_none

if test "x$marscatalog" = xyes ; then
  AC_DEFINE(METVIEW_MARS_CATALOG, 1)

  #MARS_ACCESS=MARS_local
fi

#####################################################################
#
#    M A R S  CURL support
#
AC_ARG_ENABLE(mars-web-access, [[  --enable-mars-web-access	          enable the MARS web access (requires curl library) [default=yes]]],
  mars_web_access=$enableval, mars_web_access=yes)



if test "${mars_web_access}" = "yes" -a  "${have_curl}" = "no" ; then
    mars_web_access=no
    AC_MSG_WARN([The curl library was not found, so MARS web access has been disabled.])
fi


if test "x$mars_web_access" = xno ; then
    CPPFLAGS="${CPPFLAGS} -DNOCURL"
else
    echo "MARS web api will be built"
fi


# if MARS_ACCESS is none, but web-api support is there, then set MARS_ACCESS to MARS_webapi
if test "x$MARS_ACCESS" = "xMARS_none" -a "x$mars_web_access" = "xyes" ; then
    MARS_ACCESS=MARS_webapi
fi


#####################################################################
#
# OBSTAT support
#
AC_ARG_ENABLE(obstat, [[  --enable-obstat	          enable the OBSTAT support (only at ECMWF) [default=no]]],
  obstat=$enableval, obstat=no)

if test "x$obstat" = xyes ; then
  AC_DEFINE(METVIEW_OBSTAT, 1)
fi

#####################################################################
#
# OPERA radar support (requires proj4)
#
AC_ARG_ENABLE(opera-radar, [[  --enable-opera-radar	          enable OPERA radar support (requires proj4) [default=yes]]],
  operaradar=$enableval, operaradar=yes)

if test "x$operaradar" = xyes ; then
  proj4="yes"
  AC_DEFINE(METVIEW_OPERA, 1)
fi

if test "x$proj4" = "xyes" ; then
  AC_ARG_WITH([proj4],
       [AS_HELP_STRING([--with-proj4],
       [Prefix of Proj4 libraries and headers.])],
       [PROJ4_LIBS="-lproj";CPPFLAGS="-I${with_proj4}/include ${CPPFLAGS}";LDFLAGS="-L${with_proj4}/lib ${LDFLAGS}"]
  )
  AC_MSG_CHECKING([for Proj4 header])
  AC_CHECK_HEADER(proj_api.h,,AC_MSG_ERROR([could not successfully find proj_api.h (proj4 development package)]))
  AC_MSG_CHECKING([for Proj4 library])
  AC_CHECK_LIB(proj,pj_init,,AC_MSG_ERROR([Proj4 could not be linked! Try --disable-opera-radar]))
fi




#####################################################################
#
# FLEXTRA support
#

  AC_MSG_CHECKING([for FLEXTRA])

  AC_ARG_WITH([flextra],
  [AS_HELP_STRING([--with-flextra],
  [FLEXTRA executable path.])],
  [MV_FLEXTRA_EXE="${with_flextra}";
    AC_CHECK_FILE(${with_flextra},flextra=yes,flextra=no)]
  )

  if test "x$flextra" = xno; then
     echo ""
     echo "  No FLEXTRA executable is found!"
  fi

#####################################################################
#
# SCM support
#

  AC_MSG_CHECKING([for SCM])

  AC_ARG_WITH([scm],
  [AS_HELP_STRING([--with-scm],
  [SCM executable path.])],
  [MV_SCM_EXE="${with_scm}";
    AC_CHECK_FILE(${with_scm},scm=yes,scm=no)]
  )

  if test "x$scm" = xno; then
     echo ""
     echo "  No SCM executable is found!"
  fi


AC_ARG_ENABLE(scm-aux-files, [[  --enable-scm-aux-files       enable SCM auxillary files [default=no]]],
      scm_aux=$enableval, scm_aux=no)



#####################################################################
#
# ECMWF Weather Room support
# This option enables Metview to export plots directly to a screen
# in the Weather Room.
#


AC_ARG_ENABLE(weather-room, [[  --enable-weather-room	  enable the ECMWF Weather Room support (only at ECMWF) [default=no]]],
  weather_room=$enableval, weather_room=no)

if test "x$weather_room" = xyes ; then
  if test "x$SITE_NAME" = 'xecmwf' ; then
    m4_include([aux_build/ax_boost_base.m4])
    AX_BOOST_BASE(1.47,,AC_MSG_ERROR([Boost library not found - if you use RPM do not forget boost-devel]))
    AC_CHECK_HEADER(boost/property_tree/json_parser.hpp,,
        AC_MSG_ERROR([could not successfully compile with Boost::property_tree/json_parser.hpp])
        unset ac_cv_header_boost_h)


    AC_DEFINE(METVIEW_WEATHER_ROOM, 1)
    echo ""
    echo "ECMWF Weather Room support enabled"
  else
    weather_room="no"
    echo ""
    AC_MSG_ERROR([ECMWF Weather Room option only supported at ECMWF.])
  fi
fi




#####################################################################
#
#  python interpreter
#
MV_PYTHON_COMMAND="python"
AC_ARG_WITH([python-command],
       [AS_HELP_STRING([--with-python-command],
       [Python interpreter's path.])],
       [MV_PYTHON_COMMAND="${with_python_command}"]
)



###########################################################
#
# Additional title text
#

AC_ARG_WITH([extra-title],
       [AS_HELP_STRING([--with-extra-title],
       [Extra information for the title bar])],
       [METVIEW_EXTRA_TITLE="${with_extra_title}"]
)

AC_SUBST(METVIEW_EXTRA_TITLE)



###########################################################
#
# Local ECMWF flags
#
if test "x$SITE_NAME" = 'xecmwf'
then
  CFLAGS="${CFLAGS} -DECMWF"
  CXXFLAGS="${CXXFLAGS} -DECMWF"
else
  CFLAGS="${CFLAGS} -DSiteIsNotECMWF"
  CXXFLAGS="${CXXFLAGS} -DSiteIsNotECMWF"
  FDBLIB=""
  external="yes"
  AC_DEFINE(METVIEW_EXTERNAL, 1)
fi


###########################################################
#
# Because Metview has many executables, we avoid filling up the 'bin'
# dir by putting them in a sub-directory
#
bindir=${bindir}/Metview
MVSTARTDIR=${bindir}/..    # where the startup script will go
AC_SUBST(MVSTARTDIR)



AC_SUBST(EXTRA_LD_LIBRARY_PATHS)



# Autoheader
AH_TEMPLATE(METVIEW_MAGICS,       [Turn on Magics++ related modules.])
AH_TEMPLATE(METVIEW_QT,           [Turn on Qt related modules.])
AH_TEMPLATE(METVIEW_QTDEBUG,      [Turn on QDebug output in Qt related modules.])
AH_TEMPLATE(METVIEW_MARS,         [Turn on MARS related modules.])
AH_TEMPLATE(METVIEW_MARS_CATALOG, [Turn on the MARS catalog support.])
AH_TEMPLATE(METVIEW_DEBUG,        [Turn on any additional debugging support])
AH_TEMPLATE(METVIEW_PROF,         [Turn on any additional profiling information])
AH_TEMPLATE(METVIEW_GUI,          [Turn on the graphical user interface])
AH_TEMPLATE(METVIEW_NEW_GUI,      [Turn on the Qt-based graphical user interface])
AH_TEMPLATE(METVIEW_32BIT,        [Turn on 32 bit addressing])
AH_TEMPLATE(METVIEW_EMOS,         [Turn off the Emoslib support])
AH_TEMPLATE(METVIEW_ODB,          [Turn on the ODB support])
AH_TEMPLATE(METVIEW_ODB_NEW,      [Turn on the ODB-2 support])
AH_TEMPLATE(METVIEW_ODB_OLD,      [Turn on the ODB-1 support])
AH_TEMPLATE(METVIEW_ODB_PLOT,     [Turn on the ODB plotting])
AH_TEMPLATE(METVIEW_MARS_ODB,     [Turn on the MARS ODB support])
AH_TEMPLATE(METVIEW_OBSTAT,       [Turn on the OBSTAT support])
AH_TEMPLATE(METVIEW_OPERA,        [Turn on the OPERA radar support])
AH_TEMPLATE(METVIEW_VERSION,      [Version of Metview.])
AH_TEMPLATE(METVIEW_NAME,         [Name of this package.])
AH_TEMPLATE(METVIEW_RELEASE_DATE, [Release date of this version.])
AH_TEMPLATE(METVIEW_INSTALL_PATH, [Install path.])
AH_TEMPLATE(METVIEW_SITE,         [Name of installation site.])
#AH_TEMPLATE(METVIEW_TRAJ,         [Trajectory model.])
AH_TEMPLATE(METVIEW_EXTERNAL,     [Extra data modules used outside ECMWF.])
AH_TEMPLATE(METVIEW_EXPERIMENTAL, [Turn on experimental components used only in developments.])
AH_TEMPLATE(METVIEW_ECREGRID,     [Turn on experimental interpolation library - only in developments.])
AH_TEMPLATE(METVIEW_INPE,         [Turn on the INPE support])
AH_TEMPLATE(METVIEW_SCM_AUX,      [Turn on the SCM auxillary files])
AH_TEMPLATE(METVIEW_WEATHER_ROOM, [Turn on the Weather Room export facility])

#
#  Enable Debug information
#
AC_ARG_ENABLE(debug,
     [[  --enable-debug          Turn on debugging [default=no] ]],
     [case "${enableval}" in
       yes) debug=true ;;
       no)  debug=false ;;
       *) AC_MSG_ERROR(bad value ${enableval} for --enable-debug) ;;
     esac],[debug=false])

#
#  Enable Profiling information
#
AC_ARG_ENABLE(prof,
     [[  --enable-prof           Turn on profiling (ECMWF internal) [default=no]]],
     [case "${enableval}" in
       yes) prof=true ;;
       no)  prof=false ;;
       *) AC_MSG_ERROR(bad value ${enableval} for --enable-prof) ;;
     esac],[prof=false])

# if no debug and no profiling
if test "x$debug" = xfalse -a "x$prof" = xfalse; then
	CFLAGS="${OPTI} $CFLAGS"
	CXXFLAGS="${OPTI} ${CXXFLAGS}"
    FFLAGS="${FFLAGS} ${OPTI}"
# otherwise ...
else
    # if DEBUG
     if test "x$debug" = xtrue; then
         AC_DEFINE(METVIEW_DEBUG, 1)
         CFLAGS="-g -O0 $CFLAGS"
         CXXFLAGS="-g -O0 ${CXXFLAGS}"
     fi

    # if PROFILING
     if test "x$prof" = xtrue; then
       case "${host}" in
	*-linux* )
		CFLAGS="-pg -fno-omit-frame-pointer -ggdb2 -g -O0 ${CFLAGS}"
		CXXFLAGS="-pg -fno-omit-frame-pointer -ggdb2  -g -O0 ${CXXFLAGS}"
		;;
	# IBM Server
	*-ibm-aix* )
		LDFLAGS="-L${SITE_TOTALVIEW}/rs6000/lib ${LDFLAGS}"
		LIBS="${SITE_TOTALVIEW}/rs6000/lib/aix_malloctype.o ${LIBS}"
		;;
      esac
      AC_DEFINE(METVIEW_PROF, 1)
     fi
fi


CFLAGS="$CFLAGS $METVIEW_DEFINES $PLATFORM_EMOS_BITFLAGS $PLATFORM_METVIEW_BITFLAGS"
CPPFLAGS="$CPPFLAGS $METVIEW_DEFINES $PLATFORM_EMOS_BITFLAGS $PLATFORM_METVIEW_BITFLAGS"
CXXFLAGS="$CXXFLAGS $METVIEW_DEFINES $PLATFORM_EMOS_BITFLAGS $PLATFORM_METVIEW_BITFLAGS"


AM_CONDITIONAL(METVIEW_DEBUG, test x$debug = xtrue)
AM_CONDITIONAL(METVIEW_PROF,  test x$prof = xtrue)


METVIEW_3RDPARTY_INCLUDE="$CPPFLAGS"
METVIEW_3RDPARTY_LIBS="$METVIEW_3RDPARTY_LIBS $NETCDF_LIBS $GRIBAPI_LIBS"

AC_SUBST(METVIEW_3RDPARTY_INCLUDE)
AC_SUBST(METVIEW_3RDPARTY_LIBS)
#AC_SUBST(METVIEW_FC_FLAGS)
AC_SUBST(LIBNAME)
AC_SUBST(MAGPLUS_CPPFLAGS)
AC_SUBST(MAGPLUS_LDFLAGS)
AC_SUBST(MAGPLUS_LIB)
AC_SUBST(MAGPLUS_LIB_QT)
AC_SUBST(EMOS_LIB_NAME)
AC_SUBST(ODB_CPPFLAGS)
AC_SUBST(ODB_LDFLAGS)
AC_SUBST(ODB_LIBS)
AC_SUBST(PROJ4_LIBS)

############################################
#
#   standard compiler options that we always want
#


STANDARD_METVIEW_DEFINES="-DMETVIEW"
STANDARD_METVIEW_FLAGS="-I../libMetview -I../libUtil -I../libMars  -I../libFTimeUtil"
CPPFLAGS="$STANDARD_METVIEW_DEFINES $STANDARD_METVIEW_FLAGS $CPPFLAGS"


# if we want to be able to have modules which use FLIBS and modules which don't, then we can't put everything
# into $LIBS and then put $FLIBS into _LDADD, because $LIBS is added at the end, and therefore $FLIBS will be before
# libMetview, etc. This will not work, because the Linux linker will not link in the FLIBS if they occur on the
# command line before any objects/libraries which use them. Therefore, the solution is to define STANDARD_METVIEW_LIBS,
# and have all modules have this in their LDADD, and then they can always add FLIBS to the end of that line if they
# need it.
# some more useful defines...

METVIEW_UTIL_LIB="../../lib/libUtil.a"
AC_SUBST(METVIEW_UTIL_LIB)


STANDARD_METVIEW_LIBS="../../lib/libMetview.a ../../lib/libMars.a ../../lib/libFTimeUtil.a ${METVIEW_UTIL_LIB} ${METVIEW_3RDPARTY_LIBS}"
STANDARD_METVIEW_LIBS_NO_UTIL="../../lib/libMetview.a ../../lib/libMars.a ../../lib/libFTimeUtil.a ${METVIEW_3RDPARTY_LIBS}"


# the AIX linker is more demanding, and requires libraries to be linked in, even if nothing
# is actually used from them
case "${host}" in
*-ibm-aix* )
    STANDARD_METVIEW_LIBS="${STANDARD_METVIEW_LIBS} ${FLIBS} ${METVIEW_UTIL_LIB}"
    STANDARD_METVIEW_LIBS_NO_UTIL="${STANDARD_METVIEW_LIBS} ${FLIBS} ${METVIEW_UTIL_LIB}"
    ;;
esac

AC_SUBST(STANDARD_METVIEW_LIBS)
AC_SUBST(STANDARD_METVIEW_LIBS_NO_UTIL)



METVIEW_NETCDF_FLAGS="-I../libMvNetCDF"
AC_SUBST(METVIEW_NETCDF_FLAGS)

METVIEW_NETCDF_LIB="../../lib/libMvNetCDF.a"
AC_SUBST(METVIEW_NETCDF_LIB)


MV_MOTIF_FLAGS=" -I../libMvMotif"
AC_SUBST(MV_MOTIF_FLAGS)

MV_MOTIF_UTIL_LIB="../../lib/libMvMotif.a"
AC_SUBST(MV_MOTIF_UTIL_LIB)


DBMLIB="-lgdbm"
AC_SUBST(DBMLIB)




AC_SUBST(FDBLIB)


AC_SUBST(MARS_ACCESS)

#echo "X11LIB_DIR = ${X11LIB_DIR}" >> $config_file
#echo "X11LIB = \${X11LIB_DIR} -lXm -lXmu -lXpm -lXt -lSM -lXp -lICE -lXext -lX11" >> $config_file
#echo "XPM_LIB = ${X11LIB_DIR} -lXpm" >> $config_file






AM_CONDITIONAL(METVIEW_MAGICS,     test "$magics"    = yes)
AM_CONDITIONAL(METVIEW_QT,         test "$qt"        = yes)
AM_CONDITIONAL(METVIEW_QTDEBUG,    test "$qtdebug"   = yes)
AM_CONDITIONAL(METVIEW_32BIT,      test "$bit"       = yes)
AM_CONDITIONAL(METVIEW_EMOS,       test "$emos"      = yes)
AM_CONDITIONAL(METVIEW_MARS,       test "$mars"      = yes)
AM_CONDITIONAL(METVIEW_MARS_CATALOG,  test "$marscatalog"      = yes)
AM_CONDITIONAL(METVIEW_ODB,        test "$odbnew"    = yes  -o  "$odbold" = yes)
AM_CONDITIONAL(METVIEW_ODB_NEW,    test "$odbnew"    = yes)
AM_CONDITIONAL(METVIEW_ODB_OLD,    test "$odbold"    = yes)
AM_CONDITIONAL(METVIEW_ODB_PLOT,   test "$odbplot"   = yes)
AM_CONDITIONAL(METVIEW_MARS_ODB,   test "${marsodb}" = yes)
AM_CONDITIONAL(METVIEW_OBSTAT,     test "$obstat"    = yes)
AM_CONDITIONAL(METVIEW_OPERA,      test "$operaradar" = yes)
AM_CONDITIONAL(METVIEW_GUI,        test "$ui"        = yes)
AM_CONDITIONAL(METVIEW_NEW_GUI,    test "$new_ui"    = yes)
#AM_CONDITIONAL(METVIEW_TRAJ,    test "$traj"        = yes)
AM_CONDITIONAL(METVIEW_EXTERNAL,   test "$external"  = yes)
AM_CONDITIONAL(METVIEW_EXPERIMENTAL,   test "$experimental"  = yes)
AM_CONDITIONAL(METVIEW_ECREGRID,    test "$ecregrid"        = yes)
AM_CONDITIONAL(METVIEW_INPE,        test "$inpe"     = yes)
AM_CONDITIONAL(METVIEW_SCM_AUX,     test "$scm_aux"  = yes)
AM_CONDITIONAL(METVIEW_WEATHER_ROOM,test "$weather_room"  = yes)

AC_CONFIG_FILES([Makefile
		src/Makefile
		src/AppMod/Makefile
		src/Event/Makefile
		src/BufrExaminer/Makefile
		src/CptecAccess/Makefile
		src/Datacoverage/Makefile
		src/DebugTools/Makefile
		src/Desktop/Makefile
		src/Divrot/Makefile
		src/Ecfile/Makefile
		src/ExamineManager/Makefile
		src/Flextra/Makefile
		src/FlextraExaminer/Makefile
		src/GeopExaminer/Makefile
		src/GribExaminer/Makefile
		src/GribVectors/Makefile
		src/Hovmoeller/Makefile
		src/KML/Makefile
		src/Macro/Makefile
		src/MacroEditor/Makefile
		src/MagML/Makefile
		src/MarsCatalog/Makefile
		src/Meteogram/Makefile
		src/MetviewUI/Makefile
		src/MvApp/Makefile
		src/NcExaminer/Makefile
		src/ObsFilter/Makefile
		src/Obstat/Makefile
		src/ObstatScatterTool/Makefile
		src/ObstatCurveTool/Makefile
		src/OdbExaminer/Makefile
		src/Odb/Makefile
		src/OgcClient/Makefile
		src/OperaRadar/Makefile
		src/Percentile/Makefile
		src/PottF/Makefile
		src/Relhum/Makefile
		src/Reprojection/Makefile
		src/Rttov/Makefile
		src/Scm/Makefile
		src/ScmEditor/Makefile
		src/Spectra/Makefile
		src/StdAppManager/Makefile
		src/images/Makefile
		src/libFTimeUtil/Makefile
		src/libMars/Makefile
		src/libMars-ecregrid/Makefile
		src/libMetview/Makefile
		src/libMvMotif/Makefile
		src/libMvNetCDF/Makefile
		src/libMvQtGui/Makefile
		src/libUtil/Makefile
		src/libMvQtUtil/Makefile
		src/Thermo/Makefile
		src/uPlot/Makefile
		src/Velstr/Makefile
		src/VisTools/Makefile
		src/XSection/Makefile
		src/Stations/Makefile
		src/Vapor/Makefile
		src/WebAccess/Makefile
		scripts/Makefile
		share/metview/Makefile
		share/metview/app-defaults/Makefile
		share/metview/etc/Makefile
		share/metview/etc/ifsdata/Makefile
		share/metview/icons/Makefile
		share/metview/icons_mv5/Makefile
		rpms/Makefile
		rpms/Metview.spec
		test/Makefile
		test/macros/Makefile
		])
AC_OUTPUT


# items that have been removed from AC_CONFIG_FILES, but still have
# valid Makefile.am files and could be reintroduced:
#		src/Curve/Makefile
#		src/ForwardApp/Makefile
#		src/MetviewUI_qt/Makefile
#		src/ObsExam/Makefile
#		src/Spectra/Makefile
#		src/TimeSeries/Makefile
#		src/TropCycTrack/Makefile
#		src/ObsExam/Makefile




# add all the flags that will be written into the config files to the standard
# XFLAGS variables so that configure-generated Makefiles can also use them



PWD=`echo ${PWD}`

config_file="config/CONFIG.site"
rm -f $config_file
echo "#" > $config_file
echo "# THIS FILE IS GENERATED BY configure `date`" >> $config_file
echo "#" >> $config_file
echo "WMO_SITE_NR=${SITE_WMO_CODE}"  >> $config_file
if test "x$SITE_NAME" = 'xecmwf'; then
  echo "QT_DIR_LIB=/usr/local/apps/qt/4.6.2${QT_EXT}/lib" >> $config_file
  if test "x${with_netcdf}" != "x" ; then
    echo "PATH=${with_netcdf}/bin:\${PATH}" >> $config_file
fi
fi
echo "INSTALLDIR=${prefix}" >> $config_file
echo "METVIEW_SCRIPT=${prefix}/bin/$STARTUP_SCRIPT" >> $config_file
echo "MV_MARS_ACCESS=${MARS_ACCESS}" >> $config_file
echo "MARS_HOME=${MARS_HOME}" >> $config_file
echo "METVIEW_DIR_DEV=${PWD}" >> $config_file
echo "METVIEW_TITLE_PROD=\"Production ${METVIEW_EXTRA_TITLE}\"" >> $config_file
echo "METVIEW_TITLE_DEV=\"Development autotools ${METVIEW_EXTRA_TITLE}\"" >> $config_file
echo "MV_ENVIRON=${MV_ENVIRON}" >> $config_file
echo "OS=${OS}" >> $config_file
echo "MAJOR_VERSION=${MAJOR_VERSION}" >> $config_file
echo "SHELL=/bin/sh" >> $config_file
echo "MAGPLUS_HOME=${MAGPLUS_HOME:-none}" >> $config_file
#echo "MAGPLUS_SRC_HOME=${MAGPLUS_SRC}" >> $config_file
echo "GRIBAPI_DIR=${grib_location}" >> $config_file
echo "MV_PYTHON_COMMAND=${MV_PYTHON_COMMAND}" >> $config_file

if test "x$odbold" = 'xyes' ; then
  echo "MV_ODB1_VERSION=${ODB1_VERSION}"       >> $config_file

  # we don't need both the module and the use script at the same time
  if test "x$ODB1_MODULE" != 'x' ; then
    echo "MV_ODB1_MODULE=${ODB1_MODULE}"         >> $config_file
  else
    echo "MV_ODB1_BIN=${ODB1_BIN}"               >> $config_file
    echo "MV_ODB1_USE_SCRIPT=${ODB1_USE_SCRIPT}" >> $config_file
  fi
fi

if test "x$flextra" = 'xyes' ; then
  echo "MV_FLEXTRA_EXE=\${MV_FLEXTRA_EXE:=${MV_FLEXTRA_EXE}}" >> $config_file
fi

if test "x$scm" = 'xyes' ; then
  echo "MV_SCM_EXE=\${MV_SCM_EXE:=${MV_SCM_EXE}}" >> $config_file
fi

# If we are building this outside ECMWF, then we want different proxy settings
# (used currently by the OGC clients). We achieve this by simply changing the
# default setting in the ConfigDef file. We can do this with a  a search/replace
# operation. This relies very much on the proxy setting having a uniqe 'signature'
# so that the search/replace can operate on a single line.

if test "x$SITE_NAME" != 'xecmwf'; then
    configdef=share/metview/etc/ConfigDef
    configtmp=${configdef}.tmp
    echo "Not at ECMWF: resetting the default proxy setting in ${configdef}."
    chmod u+w $configdef
    sed "s/	} = YES/	} = NO/g"  $configdef > $configtmp
    mv $configtmp $configdef
fi



\mkdir -p bin lib
touch share/metview/icons/make.dep

echo ""
echo " Metview is configured as follows for host type: $host"
echo ""
echo "Option            Configure option = Configured value"
echo "------------------------------------------------------"
echo ""
echo "Graphical UI      --enable-ui=$ui"
echo "Magics++          --enable-magics=$magics"
if test "x$magics" = xyes ; then
 if test "x$magics_cairo" = xno ; then
  echo "MISSING:          NO PNG and PDF support (disabled in Magics)"
 fi
 if test "x$magics_gd" = xno ; then
  echo "MISSING:          NO GIF support (disabled in Magics)"
 fi
 if test "x$magics_bufr" = xno ; then
  echo "MISSING:          NO BUFR plotting support (disabled in Magics)"
 fi
 echo ""
 echo "  \$MAGPLUS_HOME is defined as: $MAGPLUS_HOME"
 echo ""
 echo "ecRegrid          --enable-ecregrid=$ecregrid"
fi
echo "MARS              --enable-mars-access=$mars"
if test  "x$mars" = xyes -a "x$mars_lh_found" = xyes ; then
  echo "MARS_HOME           $MARS_HOME"
fi
echo "MARS WEB ACCESS   --enable-mars-web-access=$mars_web_access"
echo "ODB               --enable-odb=$odb"
echo "MARS ODB          --enable-mars-odb=${marsodb}"
echo "OBSTAT            --enable-obstat=$obstat"
echo "User Interface    --enable-ui=$ui"
echo "INPE              --enable-inpe=$inpe"
if test "x$SITE_NAME" = 'xecmwf'; then
    echo "WEATHER ROOM      --enable-weather-room=$weather_room"
fi

echo ""
echo ""
if test "x$odbnew" = 'xyes' -a "x$odbplot" = 'xno' ; then
  echo "WARNING:"
  echo "  ODB plotting is disabled, because Magics was built without ODB support!"
  echo "  Please rebuild Magics with ODB support to enable ODB plotting!"
  echo ""
  echo ""
fi


echo "Options used to compile and install:"
echo ""
echo " CXX     = $CXX $CXXFLAGS"
echo " CC      = $CC $CFLAGS"
echo " F77     = $F77 ${FFLAGS}"
echo " FC      = $FC ${FFLAGS}"
echo ""
echo " Metview will be installed in   ${prefix}"
echo ""