File: configure.in

package info (click to toggle)
mpich 1.2.5.3-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 53,880 kB
  • ctags: 44,904
  • sloc: ansic: 260,029; cpp: 91,556; sh: 42,421; java: 33,448; makefile: 8,959; fortran: 4,601; tcl: 3,548; f90: 3,517; perl: 2,251; asm: 999; csh: 856
file content (1516 lines) | stat: -rw-r--r-- 40,588 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
# -*- shell-script -*-

# This file is part of the University of Notre Dame implementation of
# the MPI 2 C++ bindings package.  See the LICENSE file in the top
# level directory for license and copyright information.

# Disable caching.
define([AC_CACHE_LOAD], )
define([AC_CACHE_SAVE], )

AC_INIT(src/mpi2c++/comm.h)

VERSION=`cat $srcdir/VERSION | cut -f5 -d\ `
echo "Configuring MPI-2 C++ bindings, version $VERSION"
AC_SUBST(VERSION)


# The third argument to AM_INIT_AUTOMAKE surpresses the PACKAGE and
# VERSION macors

AM_INIT_AUTOMAKE(mpi2c++, $VERSION, 'no')
AM_CONFIG_HEADER(src/mpi2c++/mpi2c++_config.h)

#
# Configure script for MPI C++ Bindings.
# Set some directories and some defaults.
#

TOPDIR=`pwd`
DISTDIR=`dirname $TOPDIR`


#
# Directories for other packages
#

if test "$prefix" != "NONE"; then
    INSTALLDIR=$prefix
else
    INSTALLDIR="/usr/local"
fi

MPI_IMP=other_vendor
MPI_DIR=$prefix
MPI_INCDIR=

#MPI_CXX=
# Do this later -- #$%^#$ HP-UX!!
MPI_CXXFLAGS=
MPI_LDFLAGS=
MPI_LIBS=


#
# Balky flags
#

BALKY_CXX=
BALKY_CXXFLAGS=
BALKY_LIBS=
BALKY_LDFLAGS=


#
# Compiler flags
#

NOOPT=
OPTFLAGS="-O"
EXAM_OPTFLAGS=$OPTFLAGS
TEST_OPTFLAGS=$OPTFLAGS


#
# Miscellaneous flags
#

MPICH_DEV=
LAM_CXXFLAGS=
EXTRA_CXXFLAGS=
EXCPTN_CXXFLAGS=
EXCPTN_LDFLAGS=
WANT_SOCKET_LIBS=
WANT_THREAD_LIBS=
ARCH=
EXFLAGS=
FORCE_EXFLAGS=

#
HAVE_BROKEN_NAMESPACES=0
UNDERLYING_CXX=
USING_MPICH=0
MPI_MIDDLE_NAME=
MINI_BALKY_CXXFLAGS=
BALKY_CXXFLAGS=


#
# Ensure not to get a user aliased grep
#

if test -x /bin/grep; then
    GREP=/bin/grep
elif test -x /usr/bin/grep; then
    GREP=/usr/bin/grep
elif test -x /sbin/grep; then
    GREP=/sbin/grep
elif test -x /usr/sbin/grep; then
    GREP=/usr/sbin/grep
else
    AC_PATH_PROG(GREP, grep, grep)
fi

#
# Get our system type
# Set up for some screwy machines
#

AC_CANONICAL_HOST

# 
# WDG: It is *wrong* to set these options before we know what compiler
# we are using.  After all, we may be using g++!
#
# (case on host moved to later)
case "$host" in
    *-hp-hpux*)
        # WDG, 11/9/99:
	# It is *NOT* correct to chose compiler flags based on the system
        # For example, what if g++ is being used?
        # The following flags for are the aCC compiler.  
        # Unfortunately, the compiler isn't available yet, so I can't
	# add the appropriate tests.  Errg.  
	if test "$GXX" = ""; then
	    EXTRA_CXXFLAGS="+W829,736"
	    CXXFLAGS="$CXXFLAGS $EXTRA_CXXFLAGS"
	    EXFLAGS="+eh"

	    NOOPT="-Wl,+vnocompatwarnings"
	    OPTFLAGS="+O1 -Wl,+vnocompatwarnings"
	    EXAM_OPTFLAGS=$OPTFLAGS
	    TEST_OPTFLAGS=$OPTFLAGS
	    
	    MPI_CXX_SAVE=$MPI_CXX
	    
	    ARCH=HPUX
	fi
        ;;

    mips-sgi-irix*)
        OPTFLAGS="-O3"
        TEST_OPTFLAGS=$OPTFLAGS
        EXAM_OPTFLAGS=$OPTFLAGS
	ARCH=IRIX
        ;;

    *-cray-unicos*)
	# Yuk!  We have to turn off all optimization in the test suite because
	# Cray's CC version 3.0.0.0 runs out of memory when compiling modules
	# like port_test.cc and request_array_test.cc.  Doh!!

	NOOPT="-O0"
	OPTFLAGS="-O3"
	TEST_OPTFLAGS=$NOOPT
	EXAM_OPTFLAGS=$OPTFLAGS

	EXFLAGS="-h exceptions"
	ARCH=CRAY
	;;
esac

#
# Now we can clear MPI_CXX
#

MPI_CXX=


#
# Set autoconf for C++
#

AC_LANG_CPLUSPLUS


#
# Figure out which brand of echo we have and define
# prompt and print shell functions accordingly.
#
# Blatently stolen from the TIFF configure file.
#

if test `echo foo\\\c`@ = "foo@"; then
    prompt()
    {
        echo "$* \\c"
    }
elif test "`echo -n foo`@" = "foo@"; then
    prompt()
    {
        echo -n "$* "
    }
else
    prompt()
    {
        echo "$*"
    }
fi


#
# Find some extra programs
#

AC_PATH_PROG(AWK, awk)
AC_PATH_PROG(WC, wc)


#
# Check --with values for specific MPI implementations.  Check for:
#  - wrapper compilers that come with some implementations
#  - specific options necessary for some MPI implementations
#
# LAM 6.3/6.4
#

AC_ARG_WITH(lam,	 [--with-lam=MPI_DIR	Top-level install directory for LAM/MPI], MPI_IMP="lam" WITHDIR=$withval)

if test "$MPI_IMP" = "lam"; then

    # Run lamboot with a dummy hostfile to find out what version it is

    MPI_CXX=no
    if test "$WITHDIR" != "" -a -x "$WITHDIR/bin/hcp"; then
	AC_MSG_CHECKING([for hcp])
	MPI_CXX=$WITHDIR/bin/hcp
	LAMBOOT=$WITHDIR/bin/lamboot
	LAMWIPE=$WITHDIR/bin/wipe
	AC_MSG_RESULT([$MPI_CXX])
    elif test "$WITHDIR" != "" -a -x "$WITHDIR/hcp"; then
	AC_MSG_CHECKING([for hcp])
	MPI_CXX=$WITHDIR/hcp
	LAMBOOT=$WITHDIR/lamboot
	LAMWIPE=$WITHDIR/wipe
	AC_MSG_RESULT([$MPI_CXX])
    else
	AC_PATH_PROG(MPI_CXX, hcp, no)
    fi

    if test "$MPI_CXX" = "no"; then
        AC_MSG_ERROR([cannot continue -- put hcp in your path])
    else
	LAMBOOT=`dirname $MPI_CXX`/lamboot
	LAMWIPE=`dirname $MPI_CXX`/wipe
    fi
    CXX=$MPI_CXX

    MPI_LIBS=" "

    AC_MSG_CHECKING([for LAM/MPI version])
    VER=`$LAMBOOT -V | $GREP LAM`
    if test "`echo $VER | $GREP 6.1`" != ""; then
	AC_MSG_RESULT([$LAMVER (you should upgrade)])
	AC_MSG_WARN([*** LAM/MPI 6.1 is no longer supported.])
	WANT_UPGRADE=1

    elif test "`echo $VER | $GREP 6.2`" != ""; then
	AC_MSG_RESULT([$LAMVER (you should upgrade)])
	AC_MSG_WARN([*** LAM/MPI 6.2 is no longer supported.])
	WANT_UPGRADE=1

    elif test "`echo $VER | $GREP 6.3.1`" != ""; then
	AC_DEFINE(MPI2CPP_LAM631, 1)
	AC_MSG_RESULT([$LAMVER (you should upgrade)])
	AC_MSG_WARN([*** LAM/MPI 6.3.1 is no longer supported.])
	WANT_UPGRADE=1

    elif test "`echo $VER | $GREP 6.3.2`" != ""; then
	AC_DEFINE(MPI2CPP_LAM632, 1)
	AC_MSG_RESULT([$LAMVER (you should upgrade)])
	AC_MSG_WARN([*** LAM/MPI 6.3.2 is no longer supported.])
	WANT_UPGRADE=1

    elif test "`echo $VER | $GREP 6.3.3`" != ""; then
	LAMVER=6.3.3
	LAMCXXFLAGS="-DLAM_BUILDING=1"
	AC_DEFINE(MPI2CPP_LAM633, 1)
	AC_MSG_RESULT([$LAMVER (good)])
	WANT_UPGRADE=0

    elif test "`echo $VER | $GREP 6.3`" != ""; then
	LAMVER=6.3
	AC_MSG_RESULT([$LAMVER (you should upgrade)])
	AC_MSG_WARN([*** LAM/MPI 6.3 is no longer supported.])
	WANT_UPGRADE=1

    elif test "`echo $VER | $GREP 6.4`" != ""; then
	LAMVER=6.4
	AC_DEFINE(MPI2CPP_LAM64, 1)
	AC_MSG_RESULT([$LAMVER (good)])
	WANT_UPGRADE=0
    else
	LAMVER=no
	AC_DEFINE(MPI2CPP_LAMUNKNOWN, 1)
	AC_MSG_RESULT([cannot determine LAM version -- good luck])
    fi
    if test "$WANT_UPGRADE" = "1"; then
	AC_MSG_WARN([*** WARNING: You are using an old version of LAM/MPI.])
	AC_MSG_WARN([*** You should upgrade to the latest version.])
	AC_MSG_WARN([*** See http://www.mpi.nd.edu/lam/])
	AC_MSG_ERROR([*** Cannot continue])
    fi
    MPI_MIDDLE_NAME="lam"

    # Get the underlying compiler name so that we can check for
    # exception flags properly

    AC_MSG_CHECKING([for LAM's underlying C++ compiler])
    full="`hcp -showme`"
    first="`echo $full | awk '{ print $1 }'`"
    UNDERLYING_CXX="`basename $first`"
    if test "$UNDERLYING_CXX" = "libtool"; then
	first=1
	done=0
	for word in $full ; do
	    if test "$done" = "0"; then
		name="`basename $word`"
		if test "$first" != "1" -a \
			"`echo $word | cut -c1-2`" != "--"; then
		    UNDERLYING_CXX="$word"
		    done=1
		fi
		first=0
	    fi
	done
	AC_MSG_RESULT([$UNDERLYING_CXX (via libtool)])
    else
	AC_MSG_RESULT([$UNDERLYING_CXX])
    fi

    # If we're building LAM (and we should be -- we shouldn't be
    # compiling this from outside of LAM anymore!), set some flags

    AC_ARG_WITH(lam-building, [--with-lam-building   Only used internally to LAM/MPI], MINI_BALKY_CXXFLAGS="-lam-building")
fi

#
# MPICH 1.2.0 (or higher)
#

MPICH_BIN=
MPICH_SRC=
MPILIB_DIR=

AC_ARG_WITH(mpich,	[--with-mpich=MPI_DIR    Top-level install directory for MPICH/MPI], MPI_IMP="mpich" WITHDIR=$withval)
AC_ARG_WITH(mpichdev,	[--with-mpichdev=LIBDIR  Library subdirectory for MPICH/MPI], MPI_IMP="mpich" MPICH_DEV=$withval)
AC_ARG_WITH(mpichbin,   [--with-mpichbin=BINDIR  bin subdirectory for MPICH/MPI], MPI_IMP="mpich" MPICH_BIN=$withval)
AC_ARG_WITH(mpichsrc,   [--with-mpichsrc=SRCDIR  source home for MPICH/MPI], MPI_IMP="mpich" MPICH_SRC=$withval)
AC_ARG_WITH(mpichlib,   [--with-mpichlib=LIBDIR  Library directory for MPICH/MPI], MPI_IMP="mpich" MPILIB_DIR=$withval)
AC_ARG_WITH(mpichlibname,[--with-mpichlibname=NAME Alternate name for MPICH library],MPI_IMP="mpich" MPICH_LIBNAME=$withval,MPICH_LIBNAME="mpich")
if test "$MPI_IMP" = "mpich"; then

    if test "$WITHDIR" = "yes"; then
        AC_MSG_ERROR([supplied --with-mpich without a directory])
    fi
    USING_MPICH=1

    AC_MSG_CHECKING([MPICH version])
    patchfile=$WITHDIR/include/patchlevel.h
    if test ! -s $patchfile -a -n "$MPICH_SRC" ; then
	# look for it in the source location
        if test -s $MPICH_SRC/include/patchlevel.h ; then
	    patchfile=$MPICH_SRC/include/patchlevel.h
	fi
    fi

    if test ! -s $patchfile; then
	AC_MSG_WARN([Cannot find the patchfile.  Hence, cannot determine])
	AC_MSG_WARN([MPICH's version.  Perhaps you need to])
	AC_MSG_WARN([specify where the MPICH source tree is with the])
	AC_MSG_WARN([--with-mpich-srcdir flag...?])
	AC_MSG_WARN([Going to make a best guess... (good luck!)])
	# Stoopid emacs mode: '
	AC_DEFINE(MPI2CPP_MPICHUNKNOWN, 1)
    else
	MPICH_VERSION=`cat $patchfile | awk '{print $3}' | sed -e 's/\.[0-9]//' | tr '\012' '.'`
	if test "$MPICH_VERSION" = "1.0.0.13."; then
	    AC_MSG_RESULT([1.0.13 (you should upgrade)])
	    WANT_UPGRADE=1
	elif test "$MPICH_VERSION" = "1.1.0."; then
	    AC_MSG_RESULT([1.1.0 (you should upgrade)])
	    WANT_UPGRADE=1
	else
	
	    #
	    # Argh!  MPICH changed the format of their patchlevel file
	    # as of version 1.1.1.
	    #

	    MPICH_VERSION=`grep 'PATCHLEVEL ' $patchfile | awk '{print $3}'`
	    mv1=`grep 'PATCHLEVEL_SUBMINOR' $patchfile | awk '{print $3}'`
	    MPICH_VERSION="$MPICH_VERSION.$mv1."
	    
	    if test -z "$MPILIB_DIR" ; then
		MPILIB_DIR=$WITHDIR/$MPICH_DEV
	    fi
	    if test "$MPICH_VERSION" = "1.1.1."; then
		AC_MSG_RESULT([1.1.1 (you should upgrade)])
		WANT_UPGRADE=1
	    elif test "$MPICH_VERSION" = "1.1.2."; then
		AC_MSG_RESULT([1.1.2 (you should upgrade)])
		WANT_UPGRADE=1
	    elif test "$MPICH_VERSION" = "1.1.3."; then
		# Need to make this MPICH113 eventually
		AC_MSG_RESULT([1.1.3 (you should upgrade)])
		WANT_UPGRADE=1
	    elif test "$MPICH_VERSION" = "1.2.0."; then
		AC_DEFINE(MPI2CPP_MPICH120)
		AC_MSG_RESULT([1.2.0 (good)])
		WANT_UPGRADE=0
		if test -z "$MPICH_BIN"; then
		    AC_MSG_ERROR([when configuring for 1.2.0, --with-mpichbin must be specified])
		fi
	    elif test "$MPICH_VERSION" = "1.2.1."; then
		AC_DEFINE(MPI2CPP_MPICH121)
		AC_MSG_RESULT([1.2.1 (good)])
		WANT_UPGRADE=0
		if test -z "$MPICH_BIN"; then
		    AC_MSG_ERROR([when configuring for 1.2.1, --with-mpichbin must be specified])
		fi
	    elif test "$MPICH_VERSION" = "1.2.2."; then
		AC_DEFINE(MPI2CPP_MPICH121)
		AC_MSG_RESULT([1.2.2 (good)])
		WANT_UPGRADE=0
		if test -z "$MPICH_BIN"; then
		    AC_MSG_ERROR([when configuring for 1.2.2, --with-mpichbin must be specified])
		fi
	    elif test "$MPICH_VERSION" = "1.2.3."; then
		AC_DEFINE(MPI2CPP_MPICH121)
		AC_MSG_RESULT([1.2.3 (good)])
		WANT_UPGRADE=0
		if test -z "$MPICH_BIN"; then
		    AC_MSG_ERROR([when configuring for 1.2.3, --with-mpichbin must be specified])
		fi
	    elif test "$MPICH_VERSION" = "1.2.4."; then
		AC_DEFINE(MPI2CPP_MPICH121)
		AC_MSG_RESULT([1.2.4 (good)])
		WANT_UPGRADE=0
		if test -z "$MPICH_BIN"; then
		    AC_MSG_ERROR([when configuring for 1.2.4, --with-mpichbin must be specified])
		fi
	    elif test "$MPICH_VERSION" = "1.2.5."; then
		AC_DEFINE(MPI2CPP_MPICH121)
		AC_MSG_RESULT([1.2.5 (good)])
		WANT_UPGRADE=0
		if test -z "$MPICH_BIN"; then
		    AC_MSG_ERROR([when configuring for 1.2.5, --with-mpichbin must be specified])
		fi
	    elif test "$MPICH_VERSION" = "1.2.6."; then
		AC_DEFINE(MPI2CPP_MPICH121)
		AC_MSG_RESULT([1.2.6 (good)])
		WANT_UPGRADE=0
		if test -z "$MPICH_BIN"; then
		    AC_MSG_ERROR([when configuring for 1.2.6, --with-mpichbin must be specified])
		fi
	    else
		AC_DEFINE(MPI2CPP_MPICHUNKNOWN, 1)
		AC_MSG_RESULT([unrecognized MPICH level -- good luck!])
	    fi
	    
	fi
    fi
    
    if test "$WANT_UPGRADE" = "1"; then
	AC_MSG_WARN([*** WARNING: It looks like you are using an old])
	AC_MSG_WARN([*** version of MPICH.])
	AC_MSG_WARN([*** You need to upgrade to the latest version.])
	AC_MSG_WARN([*** See http://www.mcs.anl.gov/mpi/mpich/])
	AC_MSG_ERROR([*** Cannot continue.])
    fi

    if test -z "$MPILIB_DIR" ; then
        MPILIB_DIR=$WITHDIR/$MPICH_DEV
    fi

    OLD_ARCH=$ARCH
    if test -x $WITHDIR/util/tarch; then 
	ARCH=`$WITHDIR/util/tarch | sed s/-/_/g`
    elif test -x $WITHDIR/bin/tarch; then
	ARCH=`$WITHDIR/bin/tarch | sed s/-/_/g`
    fi

    if test -d "$WITHDIR/lib"; then
      MPICHLIBDIR=$WITHDIR/lib/$ARCH
    elif test -d "$WITHDIR/build"; then
      MPICHLIBDIR=$WITHDIR/build/$ARCH
    elif test ! -z "$MPILIB_DIR"; then
      MPICHLIBDIR="$MPILIB_DIR"
    else
	AC_MSG_ERROR([could not find MPICH support for $ARCH])
    fi

    if test ! "$MPICH_DEV" = ""; then
	DEVICE=$MPICH_DEV
    elif test -d "$MPICHLIBDIR"; then
	echo "no MPICH device specified"
	AC_MSG_CHECKING([for existing MPICH devices])
	devices=""
	for device in `/bin/ls $MPICHLIBDIR`; do
	    if test -d $MPICHLIBDIR/$device; then
		devices="$device $devices"
	    fi
	done
	devices=`echo "$devices" | sed -e 's/^[ 	]*//' -e 's/[ 	]*$//'`
	
	device_count=`echo $devices | $WC | $AWK '{ print $2 }'`

	#
	# How many did we find?
	#

	if test "$device_count" = "0"; then
	    AC_MSG_RESULT([none found])
	    AC_MSG_ERROR([cannot continue])
	elif test "$device_count" = "1"; then
	    DEVICE=$devices
	    AC_MSG_RESULT([found $DEVICE MPICH device])
	else
	    AC_MSG_RESULT([found multiple MPICH devices])
	    DEVICE=0
	    while test "$DEVICE" = "0"; do
		prompt "Please select an MPICH device ($devices):"
		read DEVICE
		DEVICE=`echo "$DEVICE" | sed -e 's/^[	]*//' -e 's/[	]*$//'`

		if test ! -d "$MPICHLIBDIR/$DEVICE"; then
		    echo "$DEVICE MPICH device not found"
		    DEVICE=0
		fi
	    done
	fi
	MPICH_DEV=$MPICHLIBDIR/$DEVICE

	# #$%^$#%^$@%@#%@#$!!!!!!!
	# Don't ask.  Trust us.
	# (the directory structure for MPICH changed between 1.1.1 and 1.1.2
	if test "$MPICH_VERSION" = "1.1.2."; then
	    MPICH_DEV=$MPICH_DEV/lib
	fi
    else
	AC_MSG_ERROR([could not find MPICH support for $ARCH])
    fi
    
    ARCH=$OLD_ARCH

    # Look for the actual PROGRAMS; don't use the versions!
    if test -x $MPICH_BIN/mpiCC ; then
        # MPICH 1.2.0 and later
        MPI_CXX=$MPICH_BIN/mpiCC
    else
	MPI_CXX=mpiCC
    fi
    CXX=$MPI_CXX
    # Tell mpiCC to not load mpi++.h when reading mpi.h
    CXXFLAGS="$CXXFLAGS -DMPICH_SKIP_MPICXX"
    MPI_LIBS="-l$MPICH_LIBNAME"

    # JGS not sure were these should go
    MPI_CXXFLAGS="-I$WITHDIR/include -I$WITHDIR"
    MPI_LDFLAGS="-L$WITHDIR/$MPICH_DEV"

    # Get the underlying compiler name so that we can check for
    # exception flags properly

    AC_MSG_CHECKING([for MPICH's underlying C++ compiler])
    full="`$MPI_CXX -show`"
    first="`echo $full | awk '{ print $1 }'`"
    UNDERLYING_CXX="`basename $first`"
    if test "$UNDERLYING_CXX" = "libtool"; then
	first=1
	done=0
	for word in $full ; do
	    if test "$done" = "0"; then
		name="`basename $word`"
		if test "$first" != "1" -a \
			"`echo $word | cut -c1-2`" != "--"; then
		    UNDERLYING_CXX="$word"
		    done=1
		fi
		first=0
	    fi
	done
	AC_MSG_RESULT([$UNDERLYING_CXX (via libtool)])
    else
	AC_MSG_RESULT([$UNDERLYING_CXX])
    fi


    if test "$ARCH" != "IRIX"; then
	WANT_SOCKET_LIBS=1
    else
	#MPI_CXXFLAGS="$MPI_CXXFLAGS -64"
	#MPI_LDFLAGS="$MPI_LDFLAGS -64"

	#CXXFLAGS="$CXXFLAGS -64"
	#LDFLAGS="$LDFLAGS -64"
        :
    fi
    WANT_THREAD_LIBS=1
fi


#
# IBM SP
#

AC_ARG_WITH(sp,	[--with-sp		Use IBM's SP/MPI], MPI_IMP="ibm-sp" CXX=mpCC)

# Stoopid emacs mode: '

if test "$MPI_IMP" = "ibm-sp"; then
    AC_PATH_PROG(MPI_CXX, mpCC, doh)
    if test "$MPI_CXX" = "doh"; then
        AC_MSG_CHECKING([for mpCC (elsewhere)])
        foreach comp /bin/mpCC /usr/bin/mpCC
            if test "$MPI_CXX" = "" -a -x $comp; then
                AC_MSG_RESULT([yes])
                MPI_CXX=$comp
            fi
        end
        if test "$MPI_CXX" = ""; then
            AC_MSG_RESULT([no])
            AC_MSG_ERROR([cannot continue -- put mpCC in your path])
        fi
    fi
    CXX=$MPI_CXX
   
    OPTFLAGS="-O3 -qstrict -qarch=pwr2 -qtune=pwr2s -Q"
    TEST_OPTFLAGS=$OPTFLAGS
    EXAM_OPTFLAGS=$OPTFLAGS

    AC_MSG_CHECKING([POE version])
    POE_VERSION=`lslpp -L ppe.poe | $GREP poe | awk '{ print $2 }'`
    if test "$POE_VERSION" = "2.1.0.14"; then
        AC_DEFINE(MPI2CPP_IBM21014)
        AC_MSG_RESULT([2.1.0.14 (you should upgrade)])
    elif test "$POE_VERSION" = "2.1.0.15"; then
        AC_DEFINE(MPI2CPP_IBM21015)
        AC_MSG_RESULT([2.1.0.15 (you should upgrade)])
    elif test "$POE_VERSION" = "2.1.0.16"; then
        AC_DEFINE(MPI2CPP_IBM21016)
        AC_MSG_RESULT([2.1.0.16 (you should upgrade)])
    elif test "$POE_VERSION" = "2.1.0.17"; then
        AC_DEFINE(MPI2CPP_IBM21017)
        AC_MSG_RESULT([2.1.0.17 (you should upgrade)])
    elif test "$POE_VERSION" = "2.1.0.18"; then
        AC_DEFINE(MPI2CPP_IBM21018)
        AC_MSG_RESULT([2.1.0.18 (you should upgrade)])
    elif test "$POE_VERSION" = "2.3.0.0"; then
        AC_DEFINE(MPI2CPP_IBM2_3_0_0)
        AC_MSG_RESULT([2.3.0.0 (you should upgrade)])
    elif test "$POE_VERSION" = "2.4.0.0"; then
        AC_DEFINE(MPI2CPP_IBM2_4_0_0)
        AC_MSG_RESULT([2.4.0.0 (good)])
    else
        AC_DEFINE(MPI2CPP_IBMUNKNOWN)
        AC_MSG_RESULT([Unknown version -- $POE_VERSION (good luck)])
    fi
fi


#
# SGI IRIX 6.4
#

AC_ARG_WITH(sgi,	[--with-sgi		Use SGI's IRIX/64 MPI], MPI_IMP="sgi" CXX=CC)
AC_ARG_WITH(sgi64,	[--with-sgi64		Use SGI's IRIX/64 MPI (force 64 bit mode)], MPI_IMP="sgi64" CXX=CC)

if test "$MPI_IMP" = "sgi" -o "$MPI_IMP" = "sgi64"; then
    MPI_LIBS="-lmpi"

    # Strategy: build up a list of all the libdirs.  Then search for
    # the appropriate libmpi.so or libmpi.a.  

    libpaths=/tmp
    if test "?$LD_LIBRARY64_PATH" != "0"; then
	libpaths="$LD_LIBRARY64_PATH"
    fi
    if test "?$LD_LIBRARYN32_PATH" != "0"; then
	libpaths="$LD_LIBRARYN32_PATH:$libpaths"
    fi
    if test "?$LD_LIBRARY_PATH" != "0"; then
	libpaths="$LD_LIBRARY_PATH:$libpaths"
    fi

    # If they just said "--with-sgi", go find the libmpi.so

    LIBDIR=
    if test "$MPI_IMP" = "sgi"; then
	num=1
	dir="`echo $libpaths | cut -d: -f$num`"

	# Iterate through the dirs, look for a libmpi.a or libmpi.so

	while test "$dir" != ""; do
	    if test -f $dir/libmpi.so -o -f $dir/libmpi.a; then
		LIBDIR="$dir"
		dir=""
	    else
		num="`expr $num + 1`"
		dir="`echo $libpaths | cut -d: -f$num`"
	    fi
	done
	if test "$LIBDIR" = ""; then
	    AC_MSG_WARN([Cannot find libmpi.(a|so)])
	    AC_MSG_ERROR([Cannot continue])
	fi
	isn32="`echo $LIBDIR | $GREP /libn32/`"
	is64="`echo $LIBDIR | $GREP /lib64/`"
        if test "$isn32" != ""; then
            SGIFLAGS="-n32"
            SGIBIT="n32"
        elif test "$is64" != ""; then
            SGIFLAGS="-64"
            SGIBIT="64"
	else
	    SGIFLAGS=""
	    SGIBIT="32"
        fi
    elif test "$MPI_IMP" = "sgi64"; then
	num=1
	dir="`echo $libpaths | cut -d: -f$num`"

	# Iterate through the dirs, look for libmpi.a or libmpi.so,
	# but it must have /lib64/ in the directory name.

	while test "$dir" != ""; do
	    if test \( -f $dir/libmpi.so -o -f $dir/libmpi.a \) -a \
	      "`echo $dir | $GREP /lib64/`" != ""; then
		LIBDIR="$dir"
		dir=""
	    else
		num="`expr $num + 1`"
		dir="`echo $libpaths | cut -d: -f$num`"
	    fi
	done
	if test "$LIBDIR" = ""; then
	    AC_MSG_WARN([Cannot find 64 bit libmpi.(a|so)])
	    AC_MSG_ERROR([Cannot continue])
	fi
        SGIFLAGS="-64"
        SGIBIT="64"
    fi

    # Now that we found it, find the version number

    AC_MSG_CHECKING([SGI MPI version])
    WANT_UPGRADE=
    IS20=`strings $LIBDIR/libmpi.so | $GREP "SGI MPI 2.0"`
    if test "$IS20" != ""; then    
        AC_MSG_RESULT([2.0 ($SGIBIT) -- you should upgrade])
	WANT_UPGRADE=1
    else

      IS20=`strings $LIBDIR/libmpi.so | $GREP "SGI MPI 2.0"`
      if test "$IS20" != ""; then    
        AC_MSG_RESULT([2.0 ($SGIBIT) -- you should upgrade])
	WANT_UPGRADE=1
      else

        IS30=`strings $LIBDIR/libmpi.so | $GREP "SGI MPI 3.0"`
        if test "$IS30" != ""; then
            AC_DEFINE(MPI2CPP_SGI30)
            AC_MSG_RESULT([3.0 ($SGIBIT) -- you should upgrade])
	    WANT_UPGRADE=1
        else

          IS31=`strings $LIBDIR/libmpi.so | $GREP "SGI MPI 3.1"`
          if test "$IS31" != ""; then
              AC_DEFINE(MPI2CPP_SGI31)
              AC_MSG_RESULT([3.1 ($SGIBIT) -- you should upgrade])
	      WANT_UPGRADE=1
          else

	    IS32=`strings $LIBDIR/libmpi.so | $GREP "SGI MPI 3.2.0.0"`
	    if test "$IS32" != ""; then
		AC_DEFINE(MPI2CPP_SGI32)
		AC_MSG_RESULT([3.2 ($SGIBIT) -- you should upgrade])

		# We'll let this one go, 'cause it's the last one that
		# real users can use this package with -- SGI already
		# includes this package in every version after this.

	    else
              VER=`strings $LIBDIR/libmpi.so | $GREP "SGI MPI"`
              AC_DEFINE(MPI2CPP_SGIUNKNOWN)
              
              AC_MSG_RESULT([Unknown version ($SGIBIT) -- $VER (good luck)])
	      AC_MSG_WARN([*** WARNING: It is likely that you are using a version])
	      AC_MSG_WARN([*** later than SGI MPI 3.2.0.0 (or later than the])
	      AC_MSG_WARN([*** Message Passing Toolkit 1.3).  SGI started including])
	      AC_MSG_WARN([*** this package in their MPI starting with MPT 1.4.])
	      AC_MSG_WARN([*** As such, you probably do not need this package, and])
	      AC_MSG_WARN([*** it is likely that this compilation will fail.])
	    fi
          fi
        fi
      fi
    fi

    if test "$WANT_UPGRADE" = "1"; then
        AC_MSG_WARN([*** You are advised to get the latest version of SGI's MPI])
        AC_MSG_WARN([*** See http://www.sgi.com/Products/Evaluation/evaluation.html])
	AC_MSG_ERROR([*** Cannot continue.])
    fi

    MPI_CXXFLAGS="$SGIFLAGS"
    MPI_LDFLAGS="$SGIFLAGS"
fi


#
# Cray
#

AC_ARG_WITH(cray,       [--with-cray             Use Cray's native MPI], MPI_IMP="cray")

if test "$MPI_IMP" = "cray"; then
    MPI_LIBS="-lmpi"
# Per jitterbug PR#59, assuming the native compiler is not necessarily
# a good thing
    if test "$?CXX" = "0"; then
	CXX=CC
    fi
    MPI_CXX="$CXX"

    AC_DEFINE(MPI2CPP_CRAY)
    AC_MSG_CHECKING([Cray MPI version])
    CRAYVER=`ls -ld /opt/ctl/mpt/mpt | awk '{ print $11 }' | cut -d/ -f5`
    if test "$CRAYVER" = "1.1.0.4"; then
        AC_DEFINE(MPI2CPP_CRAY1104)
	AC_MSG_RESULT([1.1.0.4 (good)])
    else
	AC_DEFINE(MPI2CPP_CRAYUNKNOWN)
	AC_MSG_RESULT([unknown Cray MPI version -- good luck!])
    fi

# It seems that this flag is way outdated (per C++ jitterbut PR#59)
#    MPI_CXXFLAGS="-hnomessage=427"
    MPI_CXXFLAGS=
    MPI_LDFLAGS=""
fi


#
# HP-UX
#

AC_ARG_WITH(hp,		[--with-hp		Use HP's HP-UX 10.x MPI], MPI_IMP="hp")

if test "$MPI_IMP" = "hp"; then
        if test "$MPI_ROOT" = ""; then
                MPI_ROOT="/opt/mpi"
                AC_MSG_WARN([\$MPI_ROOT is defaulting to /opt/mpi.])
                AC_MSG_WARN([Override it by setting it manually and re-running configure.])
        fi

	MPI_CXX=$MPI_CXX_SAVE
        if test "$MPI_CXX" = ""; then
                MPI_CXX=aCC
                AC_MSG_WARN([You need to set \$MPI_CXX to the appropriate compiler.])
                AC_MSG_WARN([Defaulting to aCC.])
        fi

        AC_MSG_CHECKING([HP-UX MPI version])
        if ! test -r $MPI_ROOT/lib/pa1.1/libmpi.a; then
                AC_MSG_RESULT([cannot find libmpi.a!])
                AC_MSG_ERROR([Is \$MPI_ROOT set properly?])
        fi

        HPSTR=`what $MPI_ROOT/lib/pa1.1/libmpi.a | $GREP "HP MPI"`
	HPVER=`echo $HPSTR | cut -d. -f2-3`
        if test "$HPVER" = "01.02"; then
                AC_DEFINE(MPI2CPP_HPUX0102)
                AC_MSG_RESULT([1.2 (you should upgrade)])
	else
		HPVER=`echo "$HPSTR" | sed -e "s/[[^0-9\.]]*//" | cut -c1-5`
               	if test "$HPVER" = "01.03"; then
			AC_DEFINE(MPI2CPP_HPUX0103)
			AC_MSG_RESULT([1.3 (good )])
                elif test "$HPVER" = "01.05"; then
                        AC_DEFINE(MPI2CPP_HPUX0105)
                        AC_MSG_RESULT([1.5 (good)])
		else
                	AC_DEFINE(MPI2CPP_HPUXUNKNOWN)
                	AC_MSG_RESULT([Unknown version -- $HPVER (good luck)])
        	fi
	fi

        AC_MSG_CHECKING([for mpiCC compiler])
        if test -x $MPI_ROOT/bin/mpiCC; then
                CXX="$MPI_ROOT/bin/mpiCC"
                AC_MSG_RESULT([$CXX])
        else
                AC_MSG_RESULT([not found!])
                AC_MSG_ERROR([ensure that mpiCC is in \$MPI_ROOT/bin])
        fi
fi


#
# Generic MPI: Top-level dir
#

AC_ARG_WITH(mpidir,	[--with-mpidir=MPI_DIR	Top-level MPI directory (if not listed above)], MPI_IMP="supplied-topdir" MPI_DIR=$withval)

if test "$MPI_IMP" = "supplied-topdir"; then
    if test ! -d $WITHDIR; then
        AC_MSG_ERROR([$WITHDIR does not exist])
    elif test ! -d $WITHDIR/include; then
        AC_MSG_ERROR([$WITHDIR/include does not exist])
    elif test ! -d $WITHDIR/lib; then
        AC_MSG_ERROR([$WITHDIR/lib does not exist])
    fi

    MPI_CXXFLAGS="-I$MPIDIR/include"
    MPI_LDFLAGS="-L$WITHDIR/$MPICHLIBDIR"
    MPI_LIBS="-lmpi"
    WANT_SOCKET_LIBS=1
fi


#
# Generic MPI: Include directory / library directory
#

AC_ARG_WITH(mpiinc,	[--with-mpiinc=MPI_INC	Directory where mpi.h exists], MPI_IMP="supplied-indiv" INCDIR=$withval)
AC_ARG_WITH(mpilib,	[--with-mpilib=MPI_INC	Directory where libmpi.a exists], MPI_IMP="supplied-indiv" LIBDIR=$withval)

if test "$MPI_IMP" = "supplied-indiv"; then
    if test "$INCDIR" = ""; then
        AC_MSG_ERROR([no include directory specified (--with-mpiinc)])
    elif test "$LIBDIR" = ""; then
        AC_MSG_ERROR([no library directory specified (--with-mpilib)])
    elif test ! -d "$INCDIR"; then
        AC_MSG_ERROR([$INCDIR does not exist])
    elif test ! -d "$LIBDIR"; then
        AC_MSG_ERROR([$LIBDIR does not exist])
    fi

    MPI_CXXFLAGS="-I$INCDIR/include"
    MPI_LDFLAGS="-L$LIBDIR/lib"
    MPI_LIBS="-lmpi"
    WANT_SOCKET_LIBS=1
fi

#
# Profilable option for MPI C++ Bindings
#

AC_ARG_WITH(profiling,	[--with-profiling	Make the profilable C++ bindings], WANT_PROFILE=$withval, WANT_PROFILE="no")
AC_MSG_CHECKING([if want profiling support])
if test "$WANT_PROFILE" = "yes"; then 
    AC_DEFINE(_MPIPP_PROFILING_,1) 
    MPI2CPP_LIBRARY="libpmpi++.a"
    MPI2CPP_LIB="-lpmpi++"
    MPI2CPP_INSTALLED_LIB="-l${MPI_MIDDLE_NAME}pmpi++"
else
    AC_DEFINE(_MPIPP_PROFILING_, 0) 
    MPI2CPP_LIBRARY="libmpi++.a"
    MPI2CPP_LIB="-lmpi++"
    MPI2CPP_INSTALLED_LIB="-l${MPI_MIDDLE_NAME}mpi++"
fi
AC_SUBST(WANT_PROFILE)
AC_SUBST(MPI2CPP_LIBRARY)
AM_CONDITIONAL(WANT_PROFILING, test "$WANT_PROFILE" = "yes")
AC_MSG_RESULT([$WANT_PROFILE])

#
# We need to do a bunch of tests with <mpi.h> and "-lmpi", so
# temporarily change the CXXFLGAS.  Restore them later before they get
# substituted into various Makefiles.
#

CXXFLAGS_SAVE="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS $MINI_BALKY_CXXFLAGS"

#
# Setup C++ compiler
#

if test "$CXX" = "" -a "$MPI_CXX" != ""; then
    CXX=$MPI_CXX
fi

#
# $%@#!@#% AC_PROG_CXX changes CXXFLAGS...
#

LOCAL_CXXFLAGS_SAVE=$CXXFLAGS
CXXFLAGS="$CXXFLAGS"
AC_PROG_CXX
AC_PROG_CXXCPP
CXXFLAGS="$LOCAL_CXXFLAGS_SAVE"
AC_AIX
AC_PROG_LN_S

BALKY_CXX=$CXX
AC_SUBST(BALKY_CXX)


#
# See if the compiler makes template repository directories
#

LSC_CXX_TEMPLATE_REPOSITORY


#
# Force automake to delete emacs ~ files at "make clean"
#

CLEANFILES='-r *~ $(TEMPLATE_REP)'
AC_SUBST(CLEANFILES)


#
# Exception handling flags
#

if test "$UNDERLYING_CXX" != ""; then
    CXX_save="$CXX"
    CXX="$UNDERLYING_CXX";
fi
LSC_CHECK_CXX_EXCEPTION_FLAGS
if test "$UNDERLYING_CXX" != ""; then
    CXX="$CXX_save";
fi


EXCPTN_CXXFLAGS=$LSC_EXCEPTION_CXXFLAGS
CXXFLAGS="$EXCPTN_CXXFLAGS $CXXFLAGS"
EXCPTN_LDFLAGS="$LSC_EXCEPTION_LDFLAGS"


#
# Check to see if this compiler can handle exceptions 
#

# Since our errhandling test in the testsuite fails
# when compiling with g++ (both 2.8 and with egcs)
# we'll specify no exceptions for g++
#
# This needs to test for the problem, so that when g++/egcs is fixed, this
# will still work! - WDG
#
# I Agree! - PWR

AC_MSG_CHECKING([for throw/catch])
AC_TRY_COMPILE(, int i=1; throw(i);, have_excep=yes, have_excep=no)
if test "$GXX" = "yes"; then
    AC_DEFINE(_MPIPP_USEEXCEPTIONS_, 0)
    AC_MSG_RESULT([no (g++ exceptions broken)])
elif test "$have_excep" = "yes"; then
    AC_DEFINE(_MPIPP_USEEXCEPTIONS_, 1)
    AC_MSG_RESULT([yes])
else
    AC_DEFINE(_MPIPP_USEEXCEPTIONS_, 0)
    AC_MSG_RESULT([no])
fi


#
# Set final compiler flags
#

MINI_BALKY_CXXFLAGS="$EXCPTN_CXXFLAGS $EXTRA_CXXFLAGS $MPI_CXXFLAGS -I`pwd`/src $MINI_BALKY_CXXFLAGS"
BALKY_CXXFLAGS="$EXCPTN_CXXFLAGS $EXTRA_CXXFLAGS $MPI_CXXFLAGS -I$INSTALLDIR/include $CXXFLAGS_SAVE $BALKY_CXXFLAGS"

CXXFLAGS_SAVE="$CXXFLAGS_SAVE $MPI_CXXFLAGS"
CXXFLAGS="$CXXFLAGS $MPI_CXXFLAGS"
DEPFLAGS="$CXXFLAGS_SAVE"

AC_SUBST(MINI_BALKY_CXXFLAGS)
AC_SUBST(BALKY_CXXFLAGS)
AC_SUBST(DEPFLAGS)


#
# Try to compile with the Balky flags, see if we can find <mpi.h>
#

LSC_CHECK_MPI_H


#
# Look for extra libraries
#

if test "$WANT_SOCKET_LIBS" = "1"; then
    AC_CHECK_LIB(socket, getservbyname, socket_lib="-lsocket", socket_lib="")
    AC_CHECK_LIB(nsl, gethostbyaddr, nsl_lib="-lnsl", nsl_lib="")
fi
if test "$WANT_THREAD_LIBS" = "1"; then
    AC_CHECK_LIB(thread, sigwait, thread_lib="-lthread", thread_lib="")
fi
EXTRA_LIBS="$socket_lib $nsl_lib $thread_lib"


#
# Set final linker flags
#

LDFLAGS="$LDFLAGS $MPI_LDFLAGS"
LIBS="$MPI_LIBS $EXTRA_LIBS"

MINI_BALKY_LDFLAGS="$EXCPTN_LDFLAGS $EXTRA_LDFLAGS $MPI_LDFLAGS -L`pwd`/src $MPI2CPP_LIB $MPI_LIBS $EXTRA_LIBS $LDFLAGS"
BALKY_LDFLAGS="$EXCPTN_LDFLAGS $EXTRA_LDFLAGS $MPI_LDFLAGS -L$INSTALLDIR/lib $MPI2CPP_INSTALLED_LIB $MPI_LIBS $EXTRA_LIBS $LDFLAGS"

AC_SUBST(MINI_BALKY_LDFLAGS)
AC_SUBST(BALKY_LDFLAGS)

#
# Try to link with the Balky flags, see if we can find libmpi.*
# (if necessary)
#

if test "$MPI_LIBS" != ""; then
    LSC_CHECK_LMPI
fi


#
# Override optimization flags, if supplied
#

AC_ARG_WITH(opt,	[--without-opt		Compile with no optimization (for debugging)], withoutopt=$withval, withoutopt=$withval)
if test "$withoutopt" = "no"; then
    OPTFLAGS="$NOOPT" 
    TEST_OPTFLAGS="$NOOPT" 
    EXAM_OPTFLAGS="$NOOPT"
fi
AC_ARG_WITH(libopt,     [--with-libopt		Opt flags for use when compiling libmpi++.a], OPTFLAGS=$withval)
AC_ARG_WITH(testopt,    [--with-testopt		Opt flags for use when compiling test suite], TEST_OPTFLAGS=$withval)
AC_ARG_WITH(examopt,    [--with-examopt		Opt flags for use when compiling examples], EXAM_OPTFLAGS=$withval)
AC_SUBST(OPTFLAGS)
AC_SUBST(TEST_OPTFLAGS)
AC_SUBST(EXAM_OPTFLAGS)


#
# At least one implementation has this problem
# (no names mentioned...)
#

LSC_MPI_ERR_PENDING
if test "$LSC_HAVE_PENDING" = "1"; then
    AC_DEFINE(MPI2CPP_HAVE_PENDING, 1)
else
    AC_DEFINE(MPI2CPP_HAVE_PENDING, 0)
fi


#
# Check for MPI_GET_VERSION
#

AC_MSG_CHECKING([for MPI_GET_VERSION])
AC_TRY_LINK([#include<mpi.h>],
[int v, s; MPI_Get_version(&v, &s);],
[HAVE_GET_VERSION=1], [HAVE_GET_VERSION=1])
AC_DEFINE_UNQUOTED(MPI2CPP_HAVE_MPI_GET_VERSION, $HAVE_GET_VERSION)
if test "$HAVE_GET_VERSION" = "1"; then
    AC_MSG_RESULT([yes])
else
    AC_MSG_RESULT([no])
fi


#
# See if we have MPI_STATUS_IGNORE / MPI_STATUSES_IGNORE
#
# Unfortunately, the implementation of STATUS_IGNORE in MPICH is
# broken.  Can't really figure out a good way how to have a generic
# test to see if the underlying MPI has a broken STATUS_IGNORE because
# there are so many different ways to run a different MPI program (and
# it depends on several variables in the users' setup).  So we just
# have to put in a hardwired "if MPICH, don't use MPI_STATUS_IGNORE"
# switch.  This will probably have to be removed in the future.  Ick.
#

if test "$USING_MPICH" = "1"; then
    AC_MSG_CHECKING([for MPI_STATUS_IGNORE])
    AC_DEFINE(MPI2CPP_HAVE_STATUS_IGNORE, 0)
    AC_MSG_RESULT([yes, but broken])
    
    AC_MSG_CHECKING([for MPI_STATUSES_IGNORE])
    AC_DEFINE(MPI2CPP_HAVE_STATUSES_IGNORE, 0)
    AC_MSG_RESULT([yes, but broken])
else
    AC_MSG_CHECKING([for MPI_STATUS_IGNORE])
    AC_TRY_LINK([#include <mpi.h>],[MPI_Status *foo = MPI_STATUS_IGNORE;],
    [HAVE_STATUS_IGNORE=1],[HAVE_STATUS_IGNORE=0])
    AC_DEFINE_UNQUOTED(MPI2CPP_HAVE_STATUS_IGNORE, $HAVE_STATUS_IGNORE)
    if test "$HAVE_STATUS_IGNORE" = "1"; then
	AC_MSG_RESULT([yes])
    else
	AC_MSG_RESULT([no])
    fi
    AC_MSG_CHECKING([for MPI_STATUSES_IGNORE])
    AC_TRY_LINK([#include <mpi.h>],[MPI_Status *foo = MPI_STATUSES_IGNORE;],
    [HAVE_STATUSES_IGNORE=1],[HAVE_STATUSES_IGNORE=0])
    AC_DEFINE_UNQUOTED(MPI2CPP_HAVE_STATUSES_IGNORE, $HAVE_STATUSES_IGNORE)
    if test "$HAVE_STATUSES_IGNORE" = "1"; then
	AC_MSG_RESULT([yes])
    else
	AC_MSG_RESULT([no])
    fi
fi

#
# Find out how to make libraries
#

AC_PROG_INSTALL
# Override the buggy /bin/installbsd in AIX
case "$host" in
    rs6000-ibm-aix*)
        if test "$INSTALL" = "/bin/installbsd" -o \
            "$INSTALL" = "/bin/installbsd -c" -o \
            "$INSTALL" = "/usr/bin/installbsd" -o \
            "$INSTALL" = "/usr/bin/installbsd -c" -o \
            "$INSTALL" = "/bin/install" -o \
            "$INSTALL" = "/bin/install -c" -o \
            "$INSTALL" = "/etc/install" -o \
            "$INSTALL" = "/etc/install -c" -o \
            "$INSTALL" = "/usr/bin/install" -o \
            "$INSTALL" = "/usr/bin/install -c" -o \
            "$INSTALL" = "/usr/ucb/install" -o \
            "$INSTALL" = "/usr/ucb/install -c"; then
            AC_MSG_WARN([overriding buggy AIX $INSTALL... ./install-sh -c])
            INSTALL="./install-sh -c"
        fi

	AC_DEFINE(MPI2CPP_AIX, 1)
        ;;

    *aix*)
	AC_DEFINE(MPI2CPP_AIX, 1)
	;;
esac
AC_PROG_RANLIB
AC_CHECK_PROG(AR, ar, ar, ;)
AC_PATH_PROG(BINSH, sh)


#
# Various compiler checks
#
# Check for the "bool" type, and for the items "true" and "false"
# Autoconf 2.9 AC-CHECK-TYPE is buggy, hence this workaround
#

LSC_CHECK_CXX_BOOL
if test "$LSC_HAVE_BOOL" = "1"; then
    AC_DEFINE(MPI2CPP_HAVE_BOOL, 1)
    BOOL_TYPE="bool"
else
    AC_DEFINE(MPI2CPP_HAVE_BOOL, 0)
    BOOL_TYPE="unsigned int"
fi
AC_DEFINE_UNQUOTED(MPI2CPP_BOOL_T, $BOOL_TYPE)


#
# Check to see if the resulting bool type is the same size as an int
# Just to make it easy (and uniform), always check, even if this compiler
# does not have a native "bool" type.
#
# I don't know why autoconf is forcing me to put in cross compiling sizes!
# Reset the LDFLAGS and LIBS arguments so that we don't get -lmpi or
# other extraneous libraries in the test executables.
#

SAVE_LDFLAGS=$LDFLAGS
SAVE_LIBS=$LIBS
LDFLAGS=
LIBS=

MPI2CPP_GET_SIZEOF(int, MPI2CPP_SIZEOF_INT)
MPI2CPP_GET_SIZEOF(MPI2CPP_BOOL_T, SIZEOF_MPI2CPP_BOOL_T)

LDFLAGS=$SAVE_LDFLAGS
LIBS=$SAVE_LIBS


#
# MPI says that attributes will be at least as large as pointers.
# If we're on a 64 bit system, the pointers may be 8 bytes, not 4.
# Attributes must be typed/sized appropriately.
#

AC_MSG_CHECKING([type of MPI attributes])
AC_TRY_RUN(int main() 
{
  if (sizeof(int) != sizeof(int *))
    return -1;
  return 0;
}, sizeof_same=yes, sizeof_same=no, sizeof_same=no)
if test "$sizeof_same" = "yes"; then
    ATTR_TYPE="int"
    AC_DEFINE(MPI2CPP_ATTR, int)     
else
    ATTR_TYPE="long"
    AC_DEFINE(MPI2CPP_ATTR, long)
fi
AC_MSG_RESULT([$ATTR_TYPE])


#
# Do we have BSD or SYSV style signals?
# (or something that we haven't thought of yet?)
#

AC_MSG_CHECKING([for signal declaration])
AC_TRY_COMPILE(#include<signal.h>
extern "C" void bsd_handler(int sig, int code, struct sigcontext *scp, char *addr);
, 
signal(1, bsd_handler);
  struct sigaction n;
  n.sa_handler= bsd_handler;
, bsd_signal="yes", bsd_signal="no")
if test "$bsd_signal" = "yes"; then
    AC_DEFINE(MPI2CPP_BSD_SIGNAL, 1)
    AC_MSG_RESULT([BSD])
else
#
# Sanity check.  Make sure that it is SYSV
#

AC_TRY_COMPILE(#include<signal.h>
extern "C" void sysv_handler(int sig) {};
, 
signal(1, sysv_handler);
, sysv_signal="yes", sysv_signal="no")
    if test "$sysv_signal" = "yes"; then
        AC_DEFINE(MPI2CPP_SYSV_SIGNAL, 1)
        AC_MSG_RESULT([SYSV])
    else
        AC_MSG_RESULT([not found])
        AC_MSG_ERROR([cannot determine if signals are bsd/sysv])
        exit
    fi
fi

#
#  Check for namespaces
#  @#%$@#^ g++!  It has namespaces, but is VERY broken
#

FORCE_NAMESPACE=
AC_ARG_WITH(namespace,  [--with-namespace        Force the use of C++ namespaces], FORCE_NAMESPACE=$withval)

AC_MSG_CHECKING([for namespace support])
if test "$FORCE_NAMESPACE" = "yes"; then
    AC_DEFINE(_MPIPP_USENAMESPACE_, 1)
    AC_MSG_RESULT([yes (forced)])
elif test "$FORCE_NAMESPACE" = "no"; then 
    AC_DEFINE(_MPIPP_USENAMESPACE_, 0)
    AC_MSG_RESULT([no (forced)])
else
    AC_TRY_COMPILE([void blah();
namespace N {
  extern const int global;
  class foo {
    //g++ does not like :: operator for global scope
    // but I think I can work around this
    //    friend void ::blah();
  public:
    static int foobar();
  };
  // Sun CC 5.0 has problem with overloaded static namespace functions
  static inline int foofoo();
  static inline int foofoo(int yow, double baz);
}

//aCC con't handle the following line confuses namespaces and classes
const int N::global = 0;

//g++ does not like namespace'd return types
N::foo blahblah() { N::foo f; return f; }
//g++ does not like functions of classes in namespaces
int N::foo::foobar() { return 1; }
inline int N::foofoo() { return 0; }
inline int N::foofoo(int, double) { return 0; }
void blah() { }]
,  , namespace_found=yes, namespace_found=no)
    if test "$namespace_found" = "yes"; then
	AC_DEFINE(_MPIPP_USENAMESPACE_, 1)
	AC_MSG_RESULT([yes])
    else
	AC_DEFINE(_MPIPP_USENAMESPACE_, 0)
	AC_MSG_RESULT([no])
    fi
fi

#
# Test to see if the no namespace workaround will work.  If not (broken g++
# version 2.7.2 and others), exit so that the user won't waste time
if test "$namespace_found" = "no" ; then
    AC_MSG_CHECKING([that workaround for missing namespace works])
    AC_TRY_COMPILE([
class PMPI {
    public:
    class Comm;
   class Comm {
       public:
       typedef void Efn( Comm& );
   };
};
class MPI { 
    public:
    class Comm;
    class Comm {
       public:
       typedef void Efn( Comm& );
    };
};],[int a=0;],
[AC_MSG_RESULT(yes)],
[AC_MSG_RESULT(no)
AC_MSG_ERROR([C++ interface requires working namespace or nested classes])]
)
fi

#
# Check to see if the FORTRAN constants are there, 
# and then check for the optional FORTRAN constants.
#

AC_MSG_CHECKING([for FORTRAN constants])
AC_TRY_COMPILE(#include <mpi.h>
, MPI_Datatype a = MPI_INTEGER;, fortran_found=yes, fortran_found=no)
if test "$fortran_found" = "yes"; then
    AC_DEFINE(MPI2CPP_FORTRAN, 1)
    AC_MSG_RESULT([yes])
    AC_MSG_CHECKING([for optional FORTRAN constants])
    AC_TRY_COMPILE(#include <mpi.h>
    , MPI_Datatype b = MPI_8REAL;, all_found=yes, all_found=no)
    if test "$all_found" = "yes"; then
	AC_DEFINE(MPI2CPP_ALL_OPTIONAL_FORTRAN, 1)
	AC_MSG_RESULT([all])
    else
	AC_DEFINE(MPI2CPP_ALL_OPTIONAL_FORTRAN, 0)
	AC_TRY_COMPILE(#include <mpi.h>
	, MPI_Datatype c = MPI_2REAL;, some_found=yes, some_found=no)
	if test "$some_found" = "yes"; then
	    AC_DEFINE(MPI2CPP_SOME_OPTIONAL_FORTRAN, 1)
	    AC_MSG_RESULT([some])
	else
	    AC_DEFINE(MPI2CPP_SOME_OPTIONAL_FORTRAN, 0)
	    AC_MSG_RESULT([none])
	fi
    fi
else
    AC_DEFINE(MPI2CPP_FORTRAN, 0)
    AC_MSG_RESULT([no])
fi

#
# Check for optional C stuff.
#

AC_MSG_CHECKING([for optional C constants])
AC_TRY_COMPILE(#include <mpi.h>
, MPI_Datatype d = MPI_UNSIGNED_LONG_LONG; MPI_Datatype e = MPI_LONG_LONG;, c_found=yes, c_found=no)
if test "$c_found" = "yes"; then
    AC_DEFINE(MPI2CPP_OPTIONAL_C, 1)
    AC_MSG_RESULT([yes])
else
    AC_DEFINE(MPI2CPP_OPTIONAL_C, 0)
    AC_MSG_RESULT([no])
fi
CXXFLAGS=$CXXFLAGS_SAVE

#
# Substitute them in...
#

AC_SUBST(MPI_CXX)
AC_SUBST(MPILIB_DIR)

AC_SUBST(INSTALL)
AC_SUBST(AR)
AC_SUBST(RANLIB)

AC_SUBST(DEFS)

AC_SUBST(TOPDIR)
AC_SUBST(INSTALLDIR)
AC_SUBST(IV_DESTRUCTORS)
AC_SUBST(TEMPLATE_REP)


#
# Party on
#

AC_OUTPUT([Makefile
    src/Makefile
    src/mpi2c++/Makefile
    contrib/Makefile
    contrib/test_suite/Makefile
    contrib/examples/Makefile
    balky/Makefile
    balky/balky
    balky/mini-balky], [chmod +x balky/balky balky/mini-balky])