File: configure.in

package info (click to toggle)
papi 5.7.0+dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 9,856 kB
  • sloc: ansic: 93,265; fortran: 3,338; xml: 2,460; makefile: 815; sh: 290
file content (1835 lines) | stat: -rw-r--r-- 67,466 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
# Process this file with autoconf to produce a configure script.
# File: configure.in

# cross compile sample
# ARCH=mips CC=scgcc ./configure --with-arch=mips --host=mips64el-gentoo-linux-gnu- --with-ffsll --with-libpfm4 --with-perf-events --with-virtualtimer=times --with-walltimer=gettimeofday --with-tls=__thread --with-CPU=mips
# cross compiling should work differently...

AC_PREREQ(2.59)
AC_INIT(PAPI, 5.7.0.0, ptools-perfapi@icl.utk.edu)
AC_CONFIG_SRCDIR([papi.c])
AC_CONFIG_HEADER([config.h])

AC_DEFUN([AS_AC_EXPAND],
         [EXP_VAR=[$1]
          FROM_VAR=[$2]
          prefix_save=$prefix
          exec_prefix_save=$exec_prefix
          if test "x$prefix" = "xNONE"; then
            prefix="$ac_default_prefix"
          fi
          if test "x$exec_prefix" = "xNONE"; then
            exec_prefix=$prefix
          fi
          full_var="$FROM_VAR"
          while true; 
            do
              new_full_var="`eval echo $full_var`"
              if test "x$new_full_var" = "x$full_var"; then 
                break; 
              fi
              full_var=$new_full_var
            done
          full_var=$new_full_var
          AC_DEFINE_UNQUOTED([$1], "$full_var")
          prefix=$prefix_save
          exec_prefix=$exec_prefix_save ])

AC_MSG_CHECKING(for architecture)
AC_ARG_WITH(arch,
	       [  --with-arch=<arch>		Specify architecture (uname -m)],
	       [arch=$withval],
	       [arch=`uname -m`])
AC_MSG_RESULT($arch)

AC_ARG_WITH(bitmode,
            [  --with-bitmode=<32,64>		Specify bit mode of library],
            [bitmode=$withval])

AC_MSG_CHECKING(for OS)
AC_ARG_WITH(OS,
           [  --with-OS=<os>       		Specify operating system],
           [OS=$withval],
	       [OS="`uname | tr '[A-Z]' '[a-z]'`"
            if (test "$OS" = "SunOS" || test "$OS" = "sunos"); then
              OS=solaris
            fi ])
AC_MSG_RESULT($OS)

AC_MSG_CHECKING(for OS version)
AC_ARG_WITH(OSVER,
           [  --with-OSVER=<ver>		Specify operating system version],
           [OSVER=$withval],
	       [if test "$OS" != "bgp" -o "$OS" != "bgq"; then
              OSVER="`uname -r`"
            fi ])
AC_MSG_RESULT($OSVER)

AC_MSG_CHECKING(for perf_event workaround level)
AC_ARG_WITH(assumed_kernel,
		[  --with-assumed-kernel=<ver>	Assume kernel version is <ver> for purposes of workarounds],
		[assumed_kernel=$withval; CFLAGS="$CFLAGS -DASSUME_KERNEL=\\\"$with_assumed_kernel\\\""],
                [assumed_kernel="autodetect"]
		)		
AC_MSG_RESULT($assumed_kernel)

AC_MSG_CHECKING([for if MIC should be used])
		AC_ARG_WITH(mic,
						[ --with-mic To compile for Intel MIC ],
						[MIC=yes
						tls=__thread
						virtualtimer=cputime_id
						perf_events=yes
						walltimer=clock_realtime_hr
						ffsll=no
						cross_compiling=yes
						arch=k1om],
						[MIC=no])
AC_MSG_RESULT($MIC)
AC_SUBST(MIC)

CFLAGS="$CFLAGS -g"
#If not set, set FFLAGS to null to prevent AC_PROG_F77 from defaulting it to -g -O2
if test "x$FFLAGS" = "x"; then
  FFLAGS=""
fi
OPTFLAGS="-O2" 
TOPTFLAGS="-O1" 
AC_PROG_CC([xlc icc gcc cc])
AC_PROG_F77([xlf ifort gfortran f95 f90 f77])
if test "x$F77" = "x"; then
   F77=
fi
AC_CHECK_PROG( [MPICC], mpicc, [mpicc], [])

# Lets figure out what CC actually is...
# Used in later checks to set compiler specific options
if `$CC -V 2>&1 | grep '^Intel(R) C' >/dev/null 2>&1` ; then
	CC_COMMON_NAME="icc"
elif `$CC -v 2>&1 | grep 'gcc version' >/dev/null 2>&1` ; then
	CC_COMMON_NAME="gcc"  
elif `$CC -qversion 2>&1 | grep 'IBM XL C' >/dev/null 2>&1`; then
	CC_COMMON_NAME="xlc"
else
	CC_COMMON_NAME="unknown"
fi

#prevent icc warnings about overriding optimization settings set by AC_PROG_CC
# remark #869: parameter was never referenced 
# remark #271: trailing comma is nonstandard
if test "$CC_COMMON_NAME" = "icc"; then
  CFLAGS="$CFLAGS -diag-disable 188,869,271"
  if test "$MIC" = "yes"; then
     CC="$CC -mmic -fPIC"
  fi
fi

if test "$F77" = "ifort" -a "$MIC" = "yes"; then
  F77="$F77 -mmic -fPIC"
fi

AC_PROG_AWK
AC_PROG_CPP
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_RANLIB   
AC_GNU_SOURCE
AC_HEADER_STDC
AC_C_INLINE
AC_HEADER_TIME
AC_CHECK_HEADERS([sys/time.h c_asm.h intrinsics.h mach/mach_time.h sched.h])
AC_CHECK_FUNCS([gethrtime read_real_time time_base_to_time clock_gettime mach_absolute_time sched_getcpu])

#
# Check if the system provides dl* symbols without -ldl, and if not,
# check for -ldl existance.
#

AC_MSG_CHECKING([for dlopen and dlerror symbols in base system])
AC_TRY_LINK([#include <dlfcn.h>],
	[void *p = dlopen ("", 0); char *c = dlerror();],
	[dlsymbols_in_base="yes"], [dlsymbols_in_base="no"])
if test "${dlsymbols_in_base}" = "yes"; then
	AC_MSG_RESULT([found])
	LDL=""
else
	AC_MSG_RESULT([not found])
	AC_MSG_CHECKING([for dlopen and dlerror symbols in -ldl])
	SAVED_LIBS=${LIBS}
	LIBS="${LIBS} -ldl"
	AC_TRY_LINK([#include <dlfcn.h>],
		[void *p = dlopen ("", 0); char *c = dlerror();],
		[has_ldl="yes"], [has_ldl="no"])
	LIBS=${SAVED_LIBS}
	if test "${has_ldl}" = "yes" ; then
		AC_MSG_RESULT([found])
  	LDL="-ldl"
	else
		AC_MSG_ERROR([cannot find dlopen and dlerror symbols neither in the base system libraries nor in -ldl])
	fi
fi
AC_SUBST(LDL)
        
    
if test "$OS" = "CLE"; then
  virtualtimer=times
  tls=__thread
  walltimer=cycle
  ffsll=yes
  cross_compiling=yes
  STATIC="-static"
  # _rtc is only defined when using the Cray compiler
  AC_MSG_CHECKING([for _rtc intrinsic])
  rtc_ok=yes
  AC_TRY_LINK([#ifdef HAVE_INTRINSICS_H
               #include <intrinsics.h>
               #endif], [_rtc()], [AC_DEFINE(HAVE__RTC,1,[Define for _rtc() intrinsic.])], 
              [rtc_ok=no
               AC_DEFINE(NO_RTC_INTRINSIC,1,[Define if _rtc() is not found.])])
  AC_MSG_RESULT($rtc_ok)
elif test "$OS" = "bgp"; then
  CC=powerpc-bgp-linux-gcc 
  F77=powerpc-bgp-linux-gfortran
  walltimer=cycle
  virtualtimer=perfctr
  tls=no
  ffsll=yes
  cross_compiling=yes
elif test "$OS" = "bgq"; then
  AC_ARG_WITH(bgpm_installdir,
              [  --with-bgpm_installdir=<path> Specify the installation path of BGPM],
              [BGPM_INSTALL_DIR=$withval
              CFLAGS="$CFLAGS -I$withval"],
              [AC_MSG_ERROR([BGQ CPU component requires installation path of BGPM (see --with-bgpm_installdir)])])
  bitmode=64
  tls=no
elif test "$OS" = "linux"; then
  if test "$arch" = "ppc64" -o "$arch" = "x86_64"; then
    if test "$bitmode" = "64" -a "$libdir" = '${exec_prefix}/lib'; then
      libdir='${exec_prefix}/lib64'
    fi
  fi
elif test "$OS" = "solaris"; then
  AC_CHECK_TYPE([hrtime_t],
                [AC_DEFINE(HAVE_HRTIME_T, 1, [Define if hrtime_t is defined in <sys/time.h>])],[],
                [#if HAVE_SYS_TIME_H
                 #include <sys/time.h>
                 #endif])
  if test "x$AR" = "x"; then
    AR=/usr/ccs/bin/ar
  fi

fi

if test "x$AR" = "x"; then
  AR=ar
fi

if test "$cross_compiling" = "yes" ; then
  AC_MSG_CHECKING(for native compiler for header generation)
  AC_ARG_WITH(nativecc,
	         [  --with-nativecc=<path>		Specify native C compiler for header generation ],
	         [nativecc=$withval],
	         [nativecc=gcc])
  AC_MSG_RESULT($nativecc)
fi

AC_ARG_WITH(tests,
        	[  --with-tests=<ctests,ftests,"ctests ftests">		Specify which tests to run on install ],
        	[tests=$withval],
        	[tests="ctests ftests"]) 

AC_MSG_CHECKING(for debug build)
AC_ARG_WITH(debug,
            [  --with-debug=<yes,memory,no>		Build a debug version, debug version plus memory tracker or none ],
            [debug=$withval])
if test "$debug" = "yes"; then
  if test "$CC_COMMON_NAME" = "gcc"; then
    CFLAGS="$CFLAGS -g3"
  fi
  OPTFLAGS="-O0"
  PAPICFLAGS+=" -DDEBUG -DPAPI_NO_MEMORY_MANAGEMENT" 
elif test "$debug" = "memory"; then
  if test "$CC_COMMON_NAME" = "gcc"; then
    CFLAGS="$CFLAGS -g3"
  fi
  OPTFLAGS="-O0"
  PAPICFLAGS+=" -DDEBUG" 
else
  PAPICFLAGS+="-DPAPI_NO_MEMORY_MANAGEMENT" 			
fi
AC_MSG_RESULT($debug)

if test "$CC_COMMON_NAME" = "gcc"; then
  gcc_version=`gcc -v 2>&1 | tail -n 1 | awk '{printf $3}'`
  major=`echo $gcc_version | sed 's/\([[^.]][[^.]]*\).*/\1/'`
  minor=`echo $gcc_version | sed 's/[[^.]][[^.]]*.\([[^.]][[^.]]*\).*/\1/'`
  if (test "$major" -ge 4 || test "$major" = 3 -a "$minor" -ge 4); then
    CFLAGS+=" -Wextra"
  else
    CFLAGS+=" -W"
  fi
# -Wextra => -Woverride-init on gcc >= 4.2
# This issues a warning (error under -Werror) for some libpfm4 code. 
	AC_MSG_CHECKING( for -Wno-override-init)
		oldcflags="$CFLAGS"
		CFLAGS+=" -Wall -Wextra -Werror -Wno-override-init"
		AC_COMPILE_IFELSE([AC_LANG_SOURCE( 
						[ struct A { int x; int y; };
						int main(void) { struct A a = {.x = 0, .y = 0, .y = 5 }; return a.x; }
						])], 
						[HAVE_NO_OVERRIDE_INIT=1],
						[HAVE_NO_OVERRIDE_INIT=0] )
		CFLAGS="$oldcflags"
AC_MSG_RESULT($HAVE_NO_OVERRIDE_INIT)

fi
AC_MSG_CHECKING(for CPU type)
AC_ARG_WITH(CPU,
            [  --with-CPU=<cpu>		Specify CPU type],
            [CPU=$withval
             case "$CPU" in
               core|core2|i7|atom|p4|p3|opteron|athlon)
                   MISCSRCS="$MISCSRCS x86_cpuid_info.c" 
             esac],
	        [case "$OS" in
               aix)
                 CPU="`/usr/sbin/lsattr -E -l proc0 | grep type | cut -d '_' -f 2 | cut -d ' ' -f 1 | tr '[A-Z]' '[a-z]'`"
                 if test "$CPU" = ""; then
                   CPU="`/usr/sbin/lsattr -E -l proc1 | grep type | cut -d '_' -f 2 | cut -d ' ' -f 1 | tr '[A-Z]' '[a-z]'`"
                 fi ;;
	       freebsd)
                   family=`uname -m`

		   if test "$family" = "amd64"; then
                      MISCSRCS="$MISCSRCS x86_cpuid_info.c" 

		   elif test "$family" = "i386"; then
                      MISCSRCS="$MISCSRCS x86_cpuid_info.c" 
		   fi ;;

	       darwin)
                   family=`uname -m`

                   MISCSRCS="$MISCSRCS x86_cpuid_info.c" 

		   ;;

               linux)
                   family=`uname -m`

		   if test "$family" = "x86_64"; then
                      MISCSRCS="$MISCSRCS x86_cpuid_info.c" 
		      CPU="x86"

		   elif test "$family" = "i686"; then
                      MISCSRCS="$MISCSRCS x86_cpuid_info.c" 
		      CPU="x86"

                   elif test "$family" = "ppc64"; then
                     CPU_info="`cat /proc/cpuinfo | grep cpu | cut -d: -f2 | cut -d' ' -f2 | sed '2,$d'`"
                     case "$CPU_info" in
                       PPC970*) CPU="PPC970";;
                       POWER5)  CPU="POWER5";;
                       POWER5+) CPU="POWER5+";;
                       POWER6)  CPU="POWER6";;
                       POWER7)  CPU="POWER7";;
                     esac
	           fi ;;
               solaris)
                 AC_CHECK_HEADER([libcpc.h],
                                 [CFLAGS="$CFLAGS -lcpc"
                                  AC_TRY_RUN([#include <stdlib.h>
                                              #include <libcpc.h> 
                                              int main() {
                                              // Check for libcpc 2
                                              if(CPC_VER_CURRENT == 2) 
                                                exit(0);
                                              exit(1);
                                              } ], 
                                             [cpc_version=2], 
                                             [cpc_version=0])],
                                 [AC_MSG_ERROR([libcpc is needed for running PAPI on Solaris]) ])
                 processor=`uname -p`
                 machinetype=`uname -m`
                 if test "$processor" = "sparc"; then
                   if test "$machinetype" = "sun4u"; then
                     CPU=ultra
                     AC_CHECK_LIB([cpc], [cpc_take_sample], [], 
                                  [AC_MSG_ERROR([libcpc.a is needed on Solaris, install SUNWcpc]) ])
                   elif test "$machinetype" = "sun4v"; then
                     CPU=niagara2
                     if test "$cpc_version" != "2"; then
                       AC_MSG_ERROR([libcpc2 needed for Niagara 2])
                     fi
                   else
                     AC_MSG_ERROR([$machinetype not supported])
                   fi
                 else
                   AC_MSG_ERROR([Only SPARC processors are supported on Solaris])
                 fi ;;
               bgp)
	             CPU=bgp ;;
			   bgq)
	             CPU=bgq ;;
               esac ])
AC_MSG_RESULT($CPU)
AC_DEFINE_UNQUOTED(CPU,$CPU,[cpu type])

# First set pthread-mutexes based on arch                                       
case $arch in
  aarch64|arm*|parisc*)
    pthread_mutexes=yes
    CFLAGS="$CFLAGS -DUSE_PTHREAD_MUTEXES"
    echo "forcing use of pthread mutexes... " >&6
  ;;
esac


AC_ARG_WITH(pthread-mutexes,
              [  --with-pthread-mutexes		Specify use of pthread mutexes rather than custom PAPI locks],
              [pthread_mutexes=yes
	      CFLAGS="$CFLAGS -DUSE_PTHREAD_MUTEXES"
	      ])

  AC_ARG_WITH(ffsll,
	          [  --with-ffsll		Specify use of the ffsll() function ],
	          [ffsll=$withval],
	          [if test "$cross_compiling" = "yes" ; then
                 AC_MSG_ERROR([ffsll must be specified for cross compile])
		       fi
               didcheck=1
               AC_CHECK_FUNC(ffsll,[ffsll=yes],[ffsll=no]) ])
               if test "$ffsll" = "yes" ; then
                 AC_DEFINE(HAVE_FFSLL, 1, This platform has the ffsll() function)
               fi
if test "$didcheck" != "1"; then
  AC_MSG_CHECKING(for ffsll)
  if test "$ffsll" = "yes" ; then
    AC_DEFINE(HAVE_FFSLL, 1, This platform has the ffsll() function)
  fi
  AC_MSG_RESULT($ffsll)
fi

AC_MSG_CHECKING(for working gettid)
AC_LINK_IFELSE([AC_LANG_SOURCE([#include <sys/types.h>
                main() { pid_t a = gettid(); }])],
               [AC_MSG_RESULT(yes)
                AC_DEFINE(HAVE_GETTID, 1, [Full gettid function])],
               [AC_MSG_RESULT(no)
                AC_MSG_CHECKING(for working syscall(SYS_gettid))
                AC_LINK_IFELSE([AC_LANG_SOURCE([#include <sys/types.h>
                                #include <sys/syscall.h>
                                main() { pid_t a = syscall(SYS_gettid); }])],
                               [AC_MSG_RESULT(yes)
                                AC_DEFINE(HAVE_SYSCALL_GETTID, 1, [gettid syscall function])],
                               [AC_MSG_RESULT(no)]) ])

AC_ARG_WITH(walltimer,
            [  --with-walltimer=<gettimeofday,mmtimer,clock_realtime_hr,clock_realtime,cycle>		Specify realtime timer ],
            [walltimer=$withval],
            [if test "$cross_compiling" = "yes" ; then
               AC_MSG_ERROR([walltimer must be specified for cross compile])
             fi
             AC_MSG_CHECKING(for working MMTIMER)
             AC_TRY_RUN([#include <unistd.h>
                         #include <fcntl.h>
                         #include <errno.h>
                         #include <stdlib.h>
                         #include <sys/ioctl.h>
                         #include <linux/mmtimer.h>
                         #ifndef MMTIMER_FULLNAME
                         #define MMTIMER_FULLNAME "/dev/mmtimer"
                         #endif
                         int main() {
                           int offset;
                           int fd;
                           if((fd = open(MMTIMER_FULLNAME, O_RDONLY)) == -1) 
                             exit(1);
                           if ((offset = ioctl(fd, MMTIMER_GETOFFSET, 0)) < 0) 
                             exit(1);
                           close(fd);
                           exit(0);
                         } ],
                        [walltimer="mmtimer"
	                     AC_MSG_RESULT(yes)],
                        [AC_MSG_RESULT(no)
                         AC_MSG_CHECKING(for working CLOCK_REALTIME_HR POSIX 1b timer)
                         AC_TRY_RUN([#include <unistd.h>
                                     #include <stdlib.h>
                                     #include <stdio.h>
                                     #include <time.h>
                                     #include <syscall.h>
                                     main() {
                                       struct timespec t1, t2;
                                       double seconds;
                                       if (syscall(__NR_clock_gettime,CLOCK_REALTIME_HR,&t1) == -1) exit(1);
                                         sleep(1);
                                       if (syscall(__NR_clock_gettime,CLOCK_REALTIME_HR,&t2) == -1) exit(1);
                                         seconds = ((double)t2.tv_sec + (double)t2.tv_nsec/1000000000.0) - ((double)t1.tv_sec + (double)t1.tv_nsec/1000000000.0);
                                       if (seconds > 1.0)
                                         exit(0);
                                       else
                                         exit(1);
                                     } ],
                                    [walltimer="clock_realtime_hr"
	                                 AC_MSG_RESULT(yes)],
                                    [AC_MSG_RESULT(no)
                                     AC_MSG_CHECKING(for working CLOCK_REALTIME POSIX 1b timer)
                                     AC_TRY_RUN([#include <unistd.h>
                                                 #include <stdlib.h>
                                                 #include <stdio.h>
                                                 #include <time.h>
                                                 #include <syscall.h>
                                                 main() {
                                                   struct timespec t1, t2;
                                                   double seconds;
                                                   if (syscall(__NR_clock_gettime,CLOCK_REALTIME,&t1) == -1) exit(1);
                                                     sleep(1);
                                                   if (syscall(__NR_clock_gettime,CLOCK_REALTIME,&t2) == -1) exit(1);
                                                     seconds = ((double)t2.tv_sec + (double)t2.tv_nsec/1000000000.0) - ((double)t1.tv_sec + (double)t1.tv_nsec/1000000000.0);
                                                   if (seconds > 1.0)
                                                     exit(0);
                                                   else
                                                     exit(1);
                                                 } ],
                                                [walltimer="clock_realtime"
	                                             AC_MSG_RESULT(yes)	],
                                                [walltimer="cycle"
	                                             AC_MSG_RESULT(no)]) ]) ])  ])
AC_MSG_CHECKING(for which real time clock to use)
if test "$walltimer" = "gettimeofday"; then
  AC_DEFINE(HAVE_GETTIMEOFDAY, 1, [Normal gettimeofday timer])
elif test "$walltimer" = "mmtimer"; then
  AC_DEFINE(HAVE_MMTIMER, 1, [Altix memory mapped global cycle counter])
  altix="-DALTIX"
elif test "$walltimer" = "clock_realtime_hr"; then
  AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [POSIX 1b clock])
  AC_DEFINE(HAVE_CLOCK_GETTIME_REALTIME_HR, 1, [POSIX 1b realtime HR clock])
elif test "$walltimer" = "clock_realtime"; then
  AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [POSIX 1b clock])
  AC_DEFINE(HAVE_CLOCK_GETTIME_REALTIME, 1, [POSIX 1b realtime clock])
elif test "$walltimer" = "cycle"; then
  AC_DEFINE(HAVE_CYCLE, 1, [Native access to a hardware cycle counter])
else
  AC_MSG_ERROR([Unknown value for walltimer])
fi
AC_MSG_RESULT($walltimer)

SAVED_LIBS=$LIBS
SAVED_LDFLAGS=$LDFLAGS
SAVED_CFLAGS=$CFLAGS
LIBS=""
LDFLAGS=""
CFLAGS="-pthread"

AC_ARG_WITH(tls,
              [  --with-tls=<keyword>		This platform supports thread local storage with a keyword ],
              [tls=$withval],
              [if test "$cross_compiling" = "yes" ; then
                 AC_MSG_ERROR([tls must be specified for cross compile])
               fi
               AC_MSG_CHECKING(for working __thread)
               AC_TRY_RUN([#include <pthread.h>
                           #include <unistd.h>
                           extern __thread int i;
                           static int res1, res2;
                           void thread_main (void *arg) {
                             i = (int)arg;
                             sleep (1);
                             if ((int)arg == 1)
		                       res1 = (i == (int)arg);
                             else
		                       res2 = (i == (int)arg);
                           }
	                       __thread int i;
                           int main () {
                             pthread_t t1, t2;
                             i = 5;
                             pthread_create (&t1, NULL, thread_main, (void *)1);
                             pthread_create (&t2, NULL, thread_main, (void *)2);
                             pthread_join (t1, NULL);
                             pthread_join (t2, NULL);
                             return !(res1 + res2 == 2);
                           } ], 
                          [AC_MSG_RESULT(yes)
	                       tls="__thread"], 
                          [AC_MSG_RESULT(no)
                           tls="no" ])
               if test "$OS" = "linux"; then
                 if test "x$tls" = "x__thread"; then
                   # On some linux distributions, TLS works in executables, but linking against
                   # a shared library containing TLS fails with: undefined reference to `__tls_get_addr'
                   rm -f conftest.c conftest.so conftest
                   echo "static __thread int foo; void main () { foo = 5; }" > conftest.c
                   gcc -fPIC --shared -o conftest.so conftest.c > /dev/null 2>&1
                   gcc -o conftest conftest.so > /dev/null 2>&1
                     if test ! -f conftest; then
                       AC_MSG_WARN([Disabling usage of __thread.]);
                       tls="no"
                     fi
                   rm -f conftest.c conftest.so conftest
                 fi
               fi])
AC_MSG_CHECKING(for high performance thread local storage)
if test "$tls" = "no"; then
  NOTLS="-DNO_TLS"
elif test "x$tls" != "x"; then
  if test "$tls" = "yes"; then
    tls="__thread"
  fi
  NOTLS="-DUSE_COMPILER_TLS"
  AC_DEFINE_UNQUOTED(HAVE_THREAD_LOCAL_STORAGE,$tls,[Keyword for per-thread variables])
fi
AC_MSG_RESULT($tls)

AC_ARG_WITH(virtualtimer,
              [  --with-virtualtimer=<clock_thread_cputime_id,times,proc,getrusage,perfctr>		Specify per-thread virtual timer ],
              [virtualtimer=$withval],
              [if test "$cross_compiling" = "yes" ; then
                 AC_MSG_ERROR([virtualtimer must be specified for cross compile])
               fi
               AC_MSG_CHECKING(for working CLOCK_THREAD_CPUTIME_ID POSIX 1b timer)
               AC_TRY_RUN([#include <pthread.h>
                           #include <sys/signal.h>
                           #include <sys/times.h>
                           #include <assert.h>
                           #include <stdio.h>
                           #include <sys/types.h>
                           #include <unistd.h>
                           #include <sys/unistd.h>
                           #include <syscall.h>
                           #include <stdlib.h>
                           #if !defined( SYS_gettid )
                           #define SYS_gettid 1105
                           #endif
                           struct timespec threadone = { 0, 0 };
                           struct timespec threadtwo = { 0, 0 };
                           pthread_t threadOne, threadTwo;
                           volatile int done = 0;
  
                           int gettid() {
                             return syscall( SYS_gettid );
                           }
  
                           void *doThreadOne( void * v ) {
                             while (!done)
	                           sleep(1);
                             if (syscall(__NR_clock_gettime,CLOCK_THREAD_CPUTIME_ID,&threadone) == -1) {
                               perror("clock_gettime(CLOCK_THREAD_CPUTIME_ID)");
                               exit(1);
                             }
                             return 0;
                           } 
  
                           void *doThreadTwo( void * v ) {
                             long i, j = 0xdeadbeef;     
                             for( i = 0; i < 0xFFFFFFF; ++i ) { j = j ^ i; }
  
                             if (syscall(__NR_clock_gettime,CLOCK_THREAD_CPUTIME_ID,&threadtwo) == -1) {
                               perror("clock_gettime(CLOCK_THREAD_CPUTIME_ID)");
                               exit(1);
                             }        
                             done = 1;
	                         return j;
                           } 
  
                           int main( int argc, char ** argv ) {
                             int status = pthread_create( & threadOne, NULL, doThreadOne, NULL );
                             assert( status == 0 );
                             status = pthread_create( & threadTwo, NULL, doThreadTwo, NULL );
                             assert( status == 0 );  
                             status = pthread_join( threadTwo, NULL );
                             assert( status == 0 );
                             status = pthread_join( threadOne, NULL );
                             assert( status == 0 );
                             if ((threadone.tv_sec != threadtwo.tv_sec) || (threadone.tv_nsec != threadtwo.tv_nsec))
                               exit(0);
                             else {	
                               fprintf(stderr,"T1 %ld %ld T2 %ld %ld\n",threadone.tv_sec,threadone.tv_nsec,threadtwo.tv_sec,threadtwo.tv_nsec);
	                           exit(1); 
                             }
                           } ], 
                          [AC_MSG_RESULT(yes)
                           virtualtimer="clock_thread_cputime_id"], 
                          [AC_MSG_RESULT(no)
                           # *** Checks for working per thread timer***
                           AC_MSG_CHECKING(for working per-thread times() timer)
                           AC_TRY_RUN([#include <pthread.h>
                                       #include <sys/signal.h>
                                       #include <sys/times.h>
                                       #include <assert.h>
                                       #include <stdio.h>
                                       #include <sys/types.h>
                                       #include <unistd.h>
                                       #include <sys/unistd.h>
                                       #include <syscall.h>
                                       #include <stdlib.h>
                                       #if !defined( SYS_gettid )
                                       #define SYS_gettid 1105
                                       #endif
                                       long threadone = 0, threadtwo = 0;
                                       pthread_t threadOne, threadTwo;
                                       volatile int done = 0;
  
                                       int gettid() {
                                         return syscall( SYS_gettid );
                                       } 
                                       int doThreadOne( void * v ) {
                                         struct tms tm;
                                         int status;
                                         while (!done)
	                                       sleep(1);
                                         status = times( & tm );
                                         assert( status != -1 );
                                         threadone = tm.tms_utime;
                                         return 0;
                                       }   
                                       int doThreadTwo( void * v ) {
                                         struct tms tm;
                                         long i, j = 0xdeadbeef;
                                         int status;
                                         for( i = 0; i < 0xFFFFFFF; ++i ) { j = j ^ i; }
                                         status = times( & tm );
                                         assert( status != -1 );
                                         threadtwo = tm.tms_utime;
                                         done = 1;
	                                     return j;
                                       } 
                                       int main( int argc, char ** argv ) {
                                         int status = pthread_create( & threadOne, NULL, doThreadOne, NULL );
                                         assert( status == 0 );
                                         status = pthread_create( & threadTwo, NULL, doThreadTwo, NULL );
                                         assert( status == 0 );  
                                         status = pthread_join( threadTwo, NULL );
                                         assert( status == 0 );
                                         status = pthread_join( threadOne, NULL );
                                         assert( status == 0 );
	                                     return (threadone == threadtwo);
                                       } ],
                                      [AC_MSG_RESULT(yes)
	                                   virtualtimer="times"],
                                      [AC_MSG_RESULT(no)
	                                   virtualtimer="default"]) ]) ])
LDFLAGS=$SAVED_LDFLAGS
CFLAGS=$SAVED_CFLAGS
LIBS=$SAVED_LIBS

AC_MSG_CHECKING(for which virtual timer to use)
case "$virtualtimer" in
  times)
    AC_DEFINE(HAVE_PER_THREAD_TIMES, 1, [Working per thread timer]) ;;
  getrusage)
    AC_DEFINE(HAVE_PER_THREAD_GETRUSAGE, 1, [Working per thread getrusage]) ;;
  clock_thread_cputime_id)
    AC_DEFINE(HAVE_CLOCK_GETTIME_THREAD, CLOCK_THREAD_CPUTIME_ID, [POSIX 1b per-thread clock]) ;;
  proc|default|perfctr)
    AC_DEFINE(USE_PROC_PTTIMER, 1, [Use /proc for per-thread times])
    AC_DEFINE(USE_PERFCTR_PTTIMER, 1, [Use the perfctr virtual TSC for per-thread times]) ;;
esac
AC_MSG_RESULT($virtualtimer)

if test "$OS" = "aix"; then
  AC_ARG_WITH(pmapi,
              [  --with-pmapi=<path>		Specify path of pmapi on aix system ],
              [PMAPI=$withval],
              [PMAPI="/usr/pmapi"])
  LIBS="-L$PMAPI/lib -lpmapi"
  CPPFLAGS="$CPPFLAGS -I$PMAPI/include"
  AC_CHECK_LIB([pmapi], [pm_initialize], 
               [PMINIT="-DPM_INITIALIZE"], 
               [AC_CHECK_LIB([pmapi], [pm_init], 
                             [PMINIT="-DPM_INIT"], 
                             [AC_MSG_ERROR([libpmapi.a not found, rerun configure with different flags]) ]) ])
fi

AC_MSG_CHECKING(for static user preset events)
AC_ARG_WITH(static_user_events,
		  [ --with-static-user-events             Build with a static user events file.],
		  [STATIC_USER_EVENTS=$withval],
		  [STATIC_USER_EVENTS=no])
if test "$STATIC_USER_EVENTS" = "yes"; then
	PAPICFLAGS+=" -DSTATIC_USER_EVENTS"
fi
AC_MSG_RESULT($STATIC_USER_EVENTS)

AC_MSG_CHECKING(for static PAPI preset events)
AC_ARG_WITH(static_papi_events,
		  [ --with-static-papi-events             Build with a static papi events file.],
		  [STATIC_PAPI_EVENTS=$withval],
		  [STATIC_PAPI_EVENTS=yes])
if test "$STATIC_PAPI_EVENTS" = "yes"; then
	PAPICFLAGS+=" -DSTATIC_PAPI_EVENTS_TABLE"
fi
AC_MSG_RESULT($STATIC_PAPI_EVENTS)

AC_MSG_CHECKING(for whether to build static library)
AC_ARG_WITH(static_lib,
            [  --with-static-lib=<yes,no>		Build a static library],
            [static_lib=$withval],
            [static_lib=yes])
AC_MSG_RESULT($static_lib)

AC_MSG_CHECKING(for whether to build shared library)
AC_ARG_WITH(shared_lib,
            [  --with-shared-lib=<yes,no>		Build a shared library],
            [shared_lib=$withval],
            [shared_lib=yes])
AC_MSG_RESULT($shared_lib)

if test "$shared_lib" = "no" -a "$static_lib" = "no"; then
  AC_MSG_ERROR(Both shared and static libs are disabled)
fi

if test "$shared_lib" = "yes"; then
  papiLIBS="shared"
fi
if test "$static_lib" = "yes"; then
  papiLIBS="$papiLIBS static"
fi

AC_MSG_CHECKING(for static compile of tests and utilities)
AC_ARG_WITH(static_tools,
            [  --with-static-tools		Specify static compile of tests and utilities],
            [STATIC="-static"
	    AC_MSG_RESULT(yes)],
	    [AC_MSG_RESULT(no)])

if test "$static_lib" = "no"; then
   AC_MSG_ERROR(Building tests and utilities static but no static papi library to be built)
fi

AC_MSG_CHECKING(for linking with papi shared library of tests and utilities)
AC_ARG_WITH(shlib_tools,
	        [  --with-shlib-tools		Specify linking with papi library of tests and utilities],
 	        [shlib_tools=yes
		AC_MSG_RESULT(yes)],
		[shlib_tools=no
		AC_MSG_RESULT(no)])

if test "$shlib_tools" = "yes"; then
   if test "$shared_lib" != "yes"; then	
      AC_MSG_ERROR(Building static but specified shared linking for tests and utilities)
   fi
   if test "$STATIC" = "-static"; then
      AC_MSG_ERROR([Building shared but specified static linking])
   fi
   LINKLIB='$(SHLIB)'
elif test "$shlib_tools" = "no"; then
   if test "$static_lib" != "yes"; then
      AC_MSG_ERROR([Building shared but specified static linking for tests and utilities])
   fi
   LINKLIB='$(LIBRARY)'	
fi

##################################################
#          perfctr
##################################################
perfctr=0
force_perfctr=no

AC_ARG_WITH(perfctr,
            [  --with-perfctr		Specify perfctr as the performance interface ],
	    force_perfctr=yes
            [user_specified_interface=perfctr
	     if test "$arch" != "ppc64"; then
	     perfctr=6
	     else
	     perfctr=7
	     fi],
            [perfctr=0])

if test "$cross_compiling" = "no" ; then
  AC_CHECK_FILE(/sys/class/perfctr,[perfctr=7],[AC_CHECK_FILE(/dev/perfctr,[perfctr=6])])
fi 

if test "$perfctr" != 0; then 
  pfm_incdir="libpfm-3.y/include/"
  AC_MSG_CHECKING(for perfctr version)
  if test "$perfctr" = 7 -a "$arch" != "ppc64"; then
    AC_MSG_ERROR([Perfctr 2.7.x only works on PPC64 machines. Patch kernel with 2.6.x.])
  fi
  AC_MSG_RESULT(2.$perfctr)
fi

AC_ARG_WITH(perfctr_root,
            [  --with-perfctr-root=<path>		Specify path to source tree (for use by developers only) ],
            [perfctr_root=$withval
             user_specified_interface=perfctr])
AC_ARG_WITH(perfctr_prefix,
            [  --with-perfctr-prefix=<path>		Specify prefix to installed perfctr distribution ],
            [perfctr_prefix=$withval
             user_specified_interface=perfctr])
AC_ARG_WITH(perfctr_incdir,
           [  --with-perfctr-incdir=<path>		Specify directory of perfctr header files in non-standard location ],
           [perfctr_incdir=$withval
            user_specified_interface=perfctr])
AC_ARG_WITH(perfctr_libdir,
           [  --with-perfctr-libdir=<path>		Specify directory of perfctr library in non-standard location ],
           [perfctr_libdir=$withval
            user_specified_interface=perfctr])

if test "$perfctr" != 0; then

  dotest=0
  if test "x$perfctr_root" != "x"; then
    LIBS="-L$perfctr_root/usr.lib -lperfctr"
    CPPFLAGS="$CPPFLAGS -I$perfctr_root/usr.lib -I$perfctr_root/linux/include"
    dotest=1
  elif test "x$perfctr_prefix" != "x"; then
    LIBS="-L$perfctr_prefix/lib -lperfctr"
    CPPFLAGS="$CPPFLAGS -I$perfctr_prefix/include"
    perfctr_libdir="$perfctr_prefix/lib"
    perfctr_incdir="$perfctr_prefix/include"
    dotest=1
  else
    if test "x$perfctr_libdir" != "x"; then
      LIBS="-L$perfctr_libdir -lperfctr"
      dotest=1
    fi
    if test "x$perfctr_incdir" != "x"; then
      CPPFLAGS="-I$perfctr_incdir"
      dotest=1
    fi
  fi

  if test "$dotest" = 1; then
    AC_CHECK_LIB([perfctr], [vperfctr_open], 
                 [AC_CHECK_HEADERS([libperfctr.h], 
                                   [oCFLAGS=$CFLAGS
	                                CFLAGS="$CFLAGS -static"
	                                AC_TRY_RUN([#include <stdlib.h>
	                                            #include "libperfctr.h"
	                                            int main() {
		                                          if ((PERFCTR_ABI_VERSION >> 24) != 5) 
                                                    exit(1); 
                                                  exit(0);
	                                            } ],
                                                [perfctr=6],
                                                [perfctr=7])
	                                CFLAGS=$oCFLAGS], 
                                    [AC_MSG_ERROR([libperfctr.h not found, rerun configure with different flags])])],
                 [AC_MSG_ERROR([libperfctr.a not found, rerun configure with different flags]) ])
  else
    AC_DEFINE(HAVE_LIBPERFCTR_H,1,[perfctr header file])
  fi
fi

user_specified_interface=no
##################################################
#          perfmon
##################################################
old_pfmv2=n
perfmon=0
perfmon2=no
force_perfmon2=no

AC_ARG_WITH(perfmon,
            [  --with-perfmon=<x.y>		Specify perfmon as the performance interface and specify version],
            [perfmon=$withval 
             user_specified_interface=perfmon
	     force_perfmon2=yes
	     pfm_incdir="libpfm-3.y/include"
             perfmon=`echo ${perfmon} | sed 's/^[ \t]*//;s/[ \t]*$//'`
             perfmon=`echo ${perfmon} | grep -e '[[1-9]]\.[[0-9]][[0-9]]*'`
             if test "x$perfmon" = "x"; then
               AC_MSG_ERROR("Badly formed perfmon version string")
             fi
             perfmon=`echo ${perfmon} | sed 's/\.//'`
             if test $perfmon -gt 20; then
               perfmon2=yes
             fi
             if test $perfmon -lt 25; then
               old_pfmv2=y
	       PFMCFLAGS="-DPFMLIB_OLD_PFMV2"
             fi],
            [perfmon=0
	         if test "$cross_compiling" = "no" ; then
	           AC_CHECK_FILE(/sys/kernel/perfmon/version,
                             [perfmon=`cat /sys/kernel/perfmon/version`],
                             [AC_CHECK_FILE(/proc/perfmon,
                                            [perfmon=`cat /proc/perfmon | grep version | cut -d: -f2`],
                                            [perfmon=0])])
               if test "$perfmon" != 0; then
	         pfm_incdir="libpfm-3.y/include"
                 perfmon=`echo ${perfmon} | sed 's/^[ \t]*//;s/[ \t]*$//'`
                 perfmon=`echo ${perfmon} | grep -e '[[1-9]]\.[[0-9]][[0-9]]*'`
                 perfmon=`echo ${perfmon} | sed 's/\.//'`
                 if test $perfmon -gt 20; then
                   perfmon2=yes
                 fi
                 if test $perfmon -lt 25; then
# must be y, not yes, or libpfm breaks
                   old_pfmv2="y"           
                   PFMCFLAGS="-DPFMLIB_OLD_PFMV2"
                 fi
               fi
	         fi])


force_pfm_incdir=no
# default

AC_ARG_WITH(pfm_root,
           [  --with-pfm-root=<path>		Specify path to source tree (for use by developers only) ],
           [pfm_root=$withval
	    pfm_incdir=$withval/include
	    pfm_libdir=$withval/lib])
AC_ARG_WITH(pfm_prefix,
           [  --with-pfm-prefix=<path>		Specify prefix to installed pfm distribution ],
           [pfm_prefix=$withval
	    pfm_incdir=$pfm_prefix/include
	    pfm_libdir=$pfm_prefix/lib])
AC_ARG_WITH(pfm_incdir,
           [  --with-pfm-incdir=<path>		Specify directory of pfm header files in non-standard location ],
           [pfm_incdir=$withval])
AC_ARG_WITH(pfm_libdir,
           [  --with-pfm-libdir=<path>		Specify directory of pfm library in non-standard location ],
           [pfm_libdir=$withval])

# if these are both empty, it means we haven't set either pfm_prefix or pfm_root
# which would have set them. Thus it means that we set this to our included
# libpfm4 library. Shame on the person that sets one but not the other.

if test "x$pfm_incdir" = "x" -a "x$pfm_libdir" = "x"; then
   pfm_root="libpfm4"
   pfm_incdir="libpfm4/include"
   pfm_libdir="libpfm4/lib"
fi

##################################################
#          Linux perf_event/perf_counter
##################################################

if test "x$mic" = "xno"; then
       perf_events=no
fi

force_perf_events=no
disable_uncore=yes

AC_ARG_WITH(perf_events,
              [  --with-perf-events		Specify use of Linux Performance Event (requires kernel 2.6.32 or greater)],
              [force_perf_events=yes
	       user_specified_interface=pe])

# RDPMC support

AC_ARG_ENABLE(perfevent_rdpmc,
AS_HELP_STRING([--enable-perfevent-rdpmc],
		[Enable userspace rdpmc instruction on perf_event, default: yes]),
[case "${enableval}" in
             yes) enable_perfevent_rdpmc=true ;;
             no)  enable_perfevent_rpdmc=false ;;
             *)   AC_MSG_ERROR([bad value ${enableval} for --enable-perfevent-rdpmc]) ;;
esac],
[enable_perfevent_rdpmc=true])

if test "$enable_perfevent_rdpmc" = "true"; then
	PECFLAGS="$PECFLAGS -DUSE_PERFEVENT_RDPMC=1"
fi

# Uncore support
AC_ARG_WITH(pe_incdir,
	      [  --with-pe-incdir=<path>		Specify path to the correct perf header file],
              [pe_incdir=$withval 
               force_perf_events=yes
	       user_specified_interface=pe],
	      [pe_incdir=$pfm_incdir/perfmon])

AC_ARG_ENABLE(perf_event_uncore,
		[  --disable-perf-event-uncore		Disable perf_event uncore component])

AS_IF([test "x$enable_perf_event_uncore" != "xno"],[
	disable_uncore=no
])

# Check for perf_event.h
  if test "$force_perf_events" = "yes"; then
	perf_events="yes"
  fi
  if test "$cross_compiling" = "no"; then 
	AC_CHECK_FILE(/proc/sys/kernel/perf_event_paranoid,[
	AC_CHECK_FILE($pe_incdir/perf_event.h,perf_events="yes")])
  fi
  if test "$perf_events" = "yes"; then
      PECFLAGS="$PECFLAGS -DPEINCLUDE=\\\"$pe_incdir/perf_event.h\\\""
  fi

#
# Sort out the choice of the user vs. what we detected
#
# MESSING WITH CFLAGS IS STUPID!
#
if test "$user_specified_interface" != "no"; then
   if test "$user_specified_interface" = "perfctr"; then
      perfmon=0
      perf_events="no"
   else
	if test "$user_specified_interface" = "perfmon"; then
	   perfctr=0
	   perf_events="no"
	   PAPICFLAGS+=" $PFMCFLAGS"
	else
		if test "$user_specified_interface" = "pe"; then
			   perfctr=0
			   perfmon=0
			   PAPICFLAGS+=" $PECFLAGS"
		else
			AC_MSG_ERROR("Unknown user_specified_interface=$user_specified_interface perfctr=$perfctr perfmon=$perfmon perfmon2=$perfmon2 perf-events=$perf_events")
		fi								 
	fi
   fi
else
	if test "$perfmon" != 0; then
	   PAPICFLAGS+=" $PFMCFLAGS"
	fi
	if test "$perf_events" = "yes"; then
	   PAPICFLAGS+=" $PECFLAGS"
	fi
fi


#
# User has made no choice, so we default to the ordering below in the platform section, if
# we detect more than one.
#

#
# What does this next section do? It determines whether or not to run the tests for libpfm
# based on the settings of pfm_root, pfm_prefix, pfm_incdir, pfm_libdir
#

if test "$perfmon" != 0 -o "$perf_events" = "yes"; then
   # if prefix set, then yes
   if test "x$pfm_prefix" != "x"; then
      dotest=1
   # if root not set and libdir set, then yes
   elif test "x$pfm_root" = "x" -a "x$pfm_libdir" != "x"; then
      dotest=1
   else
      dotest=0
   fi
  if test "$dotest" = 1; then
    LIBS="-L$pfm_libdir -lpfm"
    CPPFLAGS="$CPPFLAGS -I$pfm_incdir"
    AC_CHECK_LIB([pfm], [pfm_initialize], 
                 [AC_CHECK_HEADERS([perfmon/pfmlib.h],
                                   [if test "$arch" = "ia64"; then
   		                              AC_CHECK_HEADERS([perfmon/pfmlib_montecito.h])
                                    fi
   	                                AC_CHECK_FUNC(pfm_get_event_description, 
                                                  [AC_DEFINE(HAVE_PFM_GET_EVENT_DESCRIPTION,1,[event description function])],[])
   	                                AC_CHECK_MEMBER(pfmlib_reg_t.reg_evt_idx, 
                                                    [AC_DEFINE(HAVE_PFM_REG_EVT_IDX,1,[old reg_evt_idx])],[],[#include "perfmon/pfmlib.h"])
   	                                AC_CHECK_MEMBER(pfmlib_output_param_t.pfp_pmd_count, 
                                                    [AC_DEFINE(HAVE_PFMLIB_OUTPUT_PFP_PMD_COUNT,1,[new pfmlib_output_param_t])],[],[#include "perfmon/pfmlib.h"])
   	                                AC_CHECK_MEMBER(pfm_msg_t.type, 
                                                    [AC_DEFINE(HAVE_PFM_MSG_TYPE,1,[new pfm_msg_t])],[],[#include "perfmon/perfmon.h"]) ], 
                                   [AC_MSG_ERROR([perfmon/pfmlib.h not found, rerun configure with different flags]) ]) ], 
                 [AC_MSG_ERROR([libpfm.a not found, rerun configure with different flags]) ])
  else
    AC_DEFINE(HAVE_PERFMON_PFMLIB_MONTECITO_H,1,[Montecito headers])
    AC_DEFINE(HAVE_PFM_GET_EVENT_DESCRIPTION,1,[event description function])
    AC_DEFINE(HAVE_PFMLIB_OUTPUT_PFP_PMD_COUNT,1,[new pfmlib_output_param_t])
  fi
fi

##################################################
#          Checking platform
##################################################
AC_MSG_CHECKING(platform)
case "$OS" in
  aix)
    MAKEVER="$OS"-"$CPU" ;;
  bgp)
    MAKEVER=bgp ;;
  bgq)
    MAKEVER=bgq ;;
  CLE)
    if test "$perfmon2" = "yes"; then
#  major_version=`echo $OSVER | sed 's/\([[^.]][[^.]]*\).*/\1/'`
#  minor_version=`echo $OSVER | sed 's/[[^.]][[^.]]*.\([[^.]][[^.]]*\).*/\1/'`
#  point_version=`echo $OSVER | sed -e 's/[[^.]][[^.]]*.[[^.]][[^.]]*.\(.*\)/\1/' -e 's/[[^0-9]].*//'`
#    if (test "$major_version" = 2 -a "$minor_version" = 6 -a "$point_version" -lt 31 -a "$perfmon2" != "yes" ); then
       MAKEVER="$OS"-perfmon2
    else
       MAKEVER="$OS"-pe
    fi ;;
  freebsd)
    MAKEVER="freebsd"
    LDFLAGS="-lpmc"
    # HWPMC driver is available for FreeBSD >= 6
    FREEBSD_VERSION=`uname -r | cut -d'.' -f1`
    if test "${FREEBSD_VERSION}" -lt 6 ; then
      AC_MSG_ERROR([PAPI requires FreeBSD 6 or greater])
    fi
    # Determine if HWPMC module is on the kernel
    dmesg | grep hwpmc 2> /dev/null > /dev/null
    if test "$?" != "0" ; then
      AC_MSG_ERROR([HWPMC module not found. (see INSTALL.TXT)])
    fi
    # Determine the number of counters
    echo "/* Automatically generated file by configure */" > freebsd-config.h
    echo "#ifndef _FREEBSD_CONFIG_H_" >> freebsd-config.h
    echo "#define _FREEBSD_CONFIG_H_" >> freebsd-config.h
    echo "" >> freebsd-config.h
    AC_TRY_LINK([#include <unistd.h>
                 #include <pmc.h>],
                [int i = pmc_init();],
                [pmc_pmc_init_linked="yes"], [pmc_pmc_init_linked="no"])
    if test "${pmc_init_linked}" = "no" ; then
      AC_MSG_ERROR([Failed to link hwpmc example])
    fi
    AC_TRY_RUN([#include <unistd.h>
                #include <pmc.h>
                int main() { 
                  const struct pmc_cpuinfo *info;
                  if (pmc_init() < 0) return 0;
                  if (pmc_cpuinfo (&info) < 0) return 0;
                  return info->pm_npmc-1;
                } ],
               [ num_counters="0" ], 
               [ num_counters="$?"])
    if test "${num_counters}" = "0" ; then
      AC_MSG_ERROR([pmc_npmc info returned 0. Determine if the HWPMC module is loaded (see hwpmc(4))])
    fi
    echo "#define HWPMC_NUM_COUNTERS ${num_counters}" >> freebsd-config.h
    echo "" >> freebsd-config.h
    echo "#endif" >> freebsd-config.h ;;
  linux)
    if test "$force_perf_events" = "yes" ; then
      MAKEVER="$OS"-pe
    elif test "$force_perfmon2" = "yes" ; then
      MAKEVER="$OS"-perfmon2
    elif test "$force_perfctr" = "yes" ; then
      MAKEVER="$OS"-perfctr-x86
      case "$CPU" in
        itanium2|montecito)
          if test "$bitmode" = "32"; then
            AC_MSG_ERROR([The bitmode you specified is not supported])
          fi
	  MAKEVER="$OS"-pfm-"$CPU"
	  ;;
        POWER5|POWER5+|POWER6|POWER7|PPC970)
          MAKEVER="$OS"-perfctr-"$CPU" ;;
     esac
    elif test "$perf_events" = "yes" ; then
      MAKEVER="$OS"-pe
    elif test "$perfmon2" = "yes" ; then
      MAKEVER="$OS"-perfmon2
    elif test "$old_pfmv2" = "y" ; then
      MAKEVER="$OS"-pfm-"$CPU"
    elif test "$perfctr" != 0 ; then
      case "$CPU" in
        itanium2|montecito)
          if test "$bitmode" = "32"; then
            AC_MSG_ERROR([The bitmode you specified is not supported])
          fi
	  MAKEVER="$OS"-pfm-"$CPU"
	  ;;
        x86)
	        MAKEVER="$OS"-perfctr-x86 ;;
        POWER5|POWER5+|POWER6|POWER7|PPC970)
          MAKEVER="$OS"-perfctr-"$CPU" ;;
        *)
          MAKEVER="$OS"-generic ;;
     esac
    else
      MAKEVER="$OS"-generic
    fi ;;	   
  solaris)
    if test "$bitmode" = "64" -a "`isainfo -v | grep "64"`" = ""; then
      AC_MSG_ERROR([The bitmode you specified is not supported])
    fi
    MAKEVER="$OS"-"$CPU" ;;
  darwin)
    MAKEVER="$OS" ;;
esac

AC_MSG_RESULT($MAKEVER)
if test "x$MAKEVER" = "x"; then
  AC_MSG_NOTICE(This platform is not supported so a generic build without CPU counters will be used)
  MAKEVER="generic_platform"
fi 

##################################################
#          Set build macros 
##################################################
FILENAME=Makefile.inc
SHOW_CONF=showconf
CTEST_TARGETS="all"
FTEST_TARGETS="all"
LIBRARY=libpapi.a
SHLIB='libpapi.so.AC_PACKAGE_VERSION'
PAPISOVER='$(PAPIVER).$(PAPIREV)'
VLIB='libpapi.so.$(PAPISOVER)'
OMPCFLGS=-fopenmp
CC_R='$(CC) -pthread'
CC_SHR='$(CC) -fPIC -DPIC -shared -Wl,-soname -Wl,$(VLIB)'
if test "$CC_COMMON_NAME" = "gcc"; then
	if test "$bitmode" = "32"; then
		BITFLAGS=-m32
	elif test "$bitmode" = "64"; then
		BITFLAGS=-m64
	fi
fi

OPTFLAGS="$OPTFLAGS"
PAPICFLAGS+=" -D_REENTRANT -D_GNU_SOURCE $NOTLS"
CFLAGS="$CFLAGS $BITFLAGS"
if test "$CC_COMMON_NAME" = "gcc"; then
	CFLAGS="$CFLAGS -Wall"
fi
FFLAGS="$CFLAGS $BITFLAGS $FFLAGS -Dlinux"

# OS Support

if (test "$OS" = "aix"); then
    OSFILESSRC=aix-memory.c
    OSLOCK=aix-lock.h
    OSCONTEXT=aix-context.h
elif (test "$OS" = "bgp"); then
    OSFILESSRC=linux-bgp-memory.c
    OSLOCK=linux-bgp-lock.h
    OSCONTEXT=linux-bgp-context.h
elif (test "$OS" = "bgq"); then
    OSFILESSRC=linux-bgq-memory.c
    OSLOCK=linux-bgq-lock.h
    OSCONTEXT=linux-context.h
elif (test "$OS" = "freebsd"); then
    OSFILESSRC=freebsd-memory.c
    OSLOCK="freebsd-lock.h"
    OSCONTEXT="freebsd-context.h"
elif (test "$OS" = "linux"); then
    OSFILESSRC="linux-memory.c linux-timer.c linux-common.c"
    OSFILESHDR="linux-memory.h linux-timer.h linux-common.h"
    OSLOCK="linux-lock.h"
    OSCONTEXT="linux-context.h"
elif (test "$OS" = "solaris"); then
    OSFILESSRC="solaris-memory.c solaris-common.c"
    OSFILESHDR="solaris-memory.h solaris-common.h"
    OSLOCK="solaris-lock.h"
    OSCONTEXT="solaris-context.h"
elif (test "$OS" = "darwin"); then
    OSFILESSRC="darwin-memory.c darwin-common.c"
    OSFILESHDR="darwin-memory.h darwin-common.h"
    OSLOCK="darwin-lock.h"
    OSCONTEXT="darwin-context.h"
fi

OSFILESOBJ='$(OSFILESSRC:.c=.o)'


if (test "$MAKEVER" = "aix-power5" || test "$MAKEVER" = "aix-power6" || test "$MAKEVER" = "aix-power7"); then
  if test "$bitmode" = "64"; then
    LIBRARY=libpapi64.a
    SHLIB=libpapi64.so
# By default AIX enforces a limit on heap space 
#( limiting the heap to share the same 256MB memory segment as stack )
# changing the max data paramater moves the heap off the stack's memory segment
    BITFLAGS='-q64 -bmaxdata:0x07000000000000'
    ARG64=-X64
  else
# If the issue ever comes up, /dsa requires AIX v5.1 or higher
# and the Large address-space model (-bmaxdata) requires v4.3 or later
# see http://publib.boulder.ibm.com/infocenter/pseries/v5r3/topic/com.ibm.aix.genprogc/doc/genprogc/lrg_prg_support.htm#a179c11c5d
    SHLIB=libpapi.so
    BITFLAGS="-bmaxdata:0x80000000/dsa"
  fi

  CPUCOMPONENT_NAME=aix
  CPUCOMPONENT_C=aix.c
  CPUCOMPONENT_OBJ=aix.o
  VECTOR=_aix_vector
  PAPI_EVENTS_CSV="papi_events.csv"
  MISCHDRS="aix.h components/perfctr_ppc/ppc64_events.h papi_events_table.h"
  MISCSRCS="aix.c"
  CFLAGS+='-qenum=4 -Icomponents/perfctr_ppc -DNO_VARARG_MACRO -D_AIX -D_$(CPU_MODEL) -DNEED_FFSLL -DARCH_EVTS=\"$(ARCH_EVENTS).h\" -DCOMP_VECTOR=_ppc64_vectors -DSTATIC_PAPI_EVENTS_TABLE'
  FFLAGS+='-WF,-D_$(CPU_MODEL) -WF,-DARCH_EVTS=\"$(ARCH_EVENTS).h\"'
  CFLAGS+='-I$(PMAPI)/include -Icomponents/perfctr_ppc -qmaxmem=-1 -qarch=$(cpu_option) -qtune=$(cpu_option) -qlanglvl=extended $(BITFLAGS)'
  if test $debug != "yes"; then
	OPTFLAGS='-O3 -qstrict $(PMINIT)'
  else
	OPTFLAGS='$(PMINIT)'
  fi
  SMPCFLGS=-qsmp
  OMPCFLGS='-qsmp=omp'
  LDFLAGS='-L$(PMAPI)/lib -lpmapi'
  CC_R=xlc_r
  CC=xlc
  CC_SHR="xlc -G -bnoentry"
  AC_CHECK_PROGS( [MPICC], [mpicc mpcc], [])
  F77=xlf
  CPP='xlc -E $(CPPFLAGS)'
  if test "$MAKEVER" = "aix-power5"; then
    ARCH_EVENTS=power5_events
    CPU_MODEL=POWER5
    cpu_option=pwr5
    DESCR="AIX 5.1.0 or greater with POWER5"
    if test "$bitmode" = "64"; then
      DESCR="$DESCR 64 bit build"
    fi
  elif test "$MAKEVER" = "aix-power6"; then
    ARCH_EVENTS=power6_events
    CPU_MODEL=POWER6
    cpu_option=pwr6
    DESCR="AIX 5.1.0 or greater with POWER6"
    CPPFLAGS="-qlanglvl=extended"
    if test "$bitmode" = "64"; then
      DESCR="$DESCR 64 bit build"
    fi
  elif test "$MAKEVER" = "aix-power7"; then
    ARCH_EVENTS=power7_events
    CPU_MODEL=POWER7
    cpu_option=pwr7
    DESCR="AIX 5.1.0 or greater with POWER7"
    CPPFLAGS="-qlanglvl=extended"
    if test "$bitmode" = "64"; then
      DESCR="$DESCR 64 bit build"
    fi
  fi
elif test "$MAKEVER" = "bgp"; then
  CPP="$CC -E"
    CPUCOMPONENT_NAME=linux-bgp
    CPUCOMPONENT_C=linux-bgp.c
    CPUCOMPONENT_OBJ=linux-bgp.o
    VECTOR=_bgp_vectors
    PAPI_EVENTS_CSV="papi_events.csv"
    MISCSRCS=
    CFLAGS='-g -gdwarf-2 -O2 -Wall -I. -I$(BGP_SYSDIR)/arch/include -DCOMP_VECTOR=_bgp_vectors'
    tests="$tests bgp_tests"
  SHOW_CONF=show_bgp_conf
  BGP_SYSDIR=/bgsys/drivers/ppcfloor
  BGP_GNU_LINUX_PATH='${BGP_SYSDIR}/gnu-linux'
  LDFLAGS='-L$(BGP_SYSDIR)/runtime/SPI -lSPI.cna'
  FFLAGS='-g -gdwarf-2 -O2 -Wall -I. -Dlinux'
  OPTFLAGS="-g -Wall -O3"
  TOPTFLAGS="-g -Wall -O0"
  SHLIB=libpapi.so
  DESCR="Linux for BlueGene/P"
  LIBS=static
  CC_SHR='$(CC) -shared -Xlinker "-soname" -Xlinker "$(SHLIB)" -Xlinker "-rpath" -Xlinker "$(LIBDIR)"'
  OMPCFLGS=""

elif test "$MAKEVER" = "bgq"; then
  FILENAME=Rules.bgpm
  VECTOR=_bgq_vectors
  CPUCOMPONENT_NAME=linux-bgq
  CPUCOMPONENT_C=linux-bgq.c
  CPUCOMPONENT_OBJ=linux-bgq.o
  PAPI_EVENTS_CSV="papi_events.csv"
  MISCSRCS="linux-bgq-common.c"
  OPTFLAGS="-g -Wall -O3"
  TOPTFLAGS="-g -Wall -O0"
  SHLIB=libpapi.so
  DESCR="Linux for Blue Gene/Q"
  CC_SHR='$(CC) -fPIC -DPIC -shared -Wl,-soname -Wl,$(SHLIB) -Xlinker "-rpath" -Xlinker "$(LIBDIR)"'
  OMPCFLGS=""

elif test "$MAKEVER" = "CLE-perfmon2"; then 
    FILENAME=Rules.perfmon2
    CPUCOMPONENT_NAME=perfmon
    CPUCOMPONENT_C=perfmon.c
    CPUCOMPONENT_OBJ=perfmon.o
    VECTOR=_papi_pfm_vector
    PAPI_EVENTS_CSV="papi_events.csv"
  F77=gfortran
  CFLAGS="$CFLAGS -D__crayxt"
  FFLAGS=""

elif test "$MAKEVER" = "freebsd"; then
    CPUCOMPONENT_NAME=freebsd
    CPUCOMPONENT_C=freebsd.c
    CPUCOMPONENT_OBJ=freebsd.o
    VECTOR=_papi_freebsd_vector
    PAPI_EVENTS_CSV="freebsd_events.csv"
    MISCHDRS="freebsd/map-unknown.h freebsd/map.h freebsd/map-p6.h freebsd/map-p6-m.h freebsd/map-p6-3.h freebsd/map-p6-2.h freebsd/map-p6-c.h freebsd/map-k7.h freebsd/map-k8.h freebsd/map-p4.h freebsd/map-atom.h freebsd/map-core.h freebsd/map-core2.h freebsd/map-core2-extreme.h freebsd/map-i7.h freebsd/map-westme\
re.h"
    MISCSRCS="$MISCSRCS freebsd/map-unknown.c freebsd/map.c freebsd/map-p6.c freebsd/map-p6-m.c freebsd/map-p6-3.c freebsd/map-p6-2.c freebsd/map-p6-c.c freebsd/map-k7.c freebsd/map-k8.c freebsd/map-p4.c freebsd/map-atom.c freebsd/map-core.c freebsd/map-core2.c freebsd/map-core2-extreme.c freebsd/map-i7.c freebsd/map-westme\
re.c"
  DESCR="FreeBSD -over libpmc- "
  CFLAGS+=" -I. -Ifreebsd -DPIC -fPIC"
  CC_SHR='$(CC) -shared -Xlinker "-soname" -Xlinker "libpapi.so" -Xlinker "-rpath" -Xlinker "$(LIBDIR)" -DPIC -fPIC -I. -Ifreebsd'

elif test "$MAKEVER" = "linux-generic"; then
    CPUCOMPONENT_NAME=linux-generic
    CPUCOMPONENT_C=linux-generic.c
    CPUCOMPONENT_OBJ=linux-generic.o
    PAPI_EVENTS_CSV="papi_events.csv"
    VECTOR=_papi_dummy_vector

elif test "$MAKEVER" = "linux-pe"; then
    FILENAME=Rules.pfm4_pe
    CPUCOMPONENT_NAME=perf_event 
    components="perf_event"
    if test "$disable_uncore" = "no"; then
       components="$components perf_event_uncore"
    fi

elif test "$MAKEVER" = "linux-perfctr-x86"; then
    FILENAME=Rules.perfctr-pfm
    CPUCOMPONENT_NAME=perfctr-x86
    VERSION=2.6.x  
    components="perfctr"

elif (test "$MAKEVER" = "linux-perfctr-POWER5" || test "$MAKEVER" = "linux-perfctr-POWER5+" || test "$MAKEVER" = "linux-perfctr-POWER6" || test "$MAKEVER" = "linux-perfctr-POWER7" || test "$MAKEVER" = "linux-perfctr-PPC970"); then
    FILENAME=Rules.perfctr
    CPUCOMPONENT_NAME=perfctr-ppc
    VERSION=2.7.x
    components="perfctr_ppc"
    CPU=ppc64
    if test "$MAKEVER" = "linux-perfctr-POWER5"; then
      CPU_MODEL=POWER5
      ARCH_EVENTS=power5_events
      ARCH_SPEC_EVTS=power5_events_map.c
    elif test "$MAKEVER" = "linux-perfctr-POWER5+"; then
      CPU_MODEL=POWER5p
      ARCH_EVENTS=power5+_events
      ARCH_SPEC_EVTS=power5+_events_map.c
    elif test "$MAKEVER" = "linux-perfctr-POWER6"; then
      CPU_MODEL=POWER6
      ARCH_EVENTS=power6_events
      ARCH_SPEC_EVTS=power6_events_map.c
    elif test "$MAKEVER" = "linux-perfctr-POWER7"; then
      CPU_MODEL=POWER7
      ARCH_EVENTS=power7_events
      ARCH_SPEC_EVTS=power7_events_map.c
    elif test "$MAKEVER" = "linux-perfctr-PPC970"; then
      CPU_MODEL=PPC970
      ARCH_EVENTS=ppc970_events
      ARCH_SPEC_EVTS=ppc970_events_map.c
    fi
    CFLAGS="$CFLAGS -DPPC64 -D_$(CPU_MODEL) -D__perfctr__ -DARCH_EVTS=\"$(ARCH_EVENTS).h\" -DCOMP_VECTOR=_ppc64_vectors"
    FFLAGS='-D_$(CPU_MODEL)'

elif test "$MAKEVER" = "linux-perfmon2"; then
    FILENAME=Rules.perfmon2
    CPUCOMPONENT_NAME=perfmon2
    components="perfmon2"

elif (test "$MAKEVER" = "linux-pfm-ia64" || test "$MAKEVER" = "linux-pfm-itanium2" || test "$MAKEVER" = "linux-pfm-montecito"); then
    FILENAME=Rules.pfm
    CPUCOMPONENT_NAME=perfmon-ia64
    components="perfmon_ia64"
    VERSION=3.y
    if test "$MAKEVER" = "linux-pfm-itanium2"; then
      CPU=2
    else
      CPU=3
    fi
    CFLAGS="$CFLAGS -DITANIUM$CPU"
    FFLAGS="$FFLAGS -DITANIUM$CPU"

  CC_SHR='$(CC) -fPIC -DPIC -shared -Wl,-soname -Wl,$(SHLIB) -Xlinker "-rpath" -Xlinker "$(LIBDIR)"'

elif test "$MAKEVER" = "solaris-ultra"; then
    CPUCOMPONENT_NAME=solaris-ultra
    CPUCOMPONENT_C=solaris-ultra.c
    CPUCOMPONENT_OBJ=solaris-ultra.obj
    VECTOR=_solaris_vector
    PAPI_EVENTS_CSV="papi_events.csv"
  DESCR="Solaris 5.8 or greater with UltraSPARC I, II or III"
  if test "$CC" = "gcc"; then
    F77=g77
    CPP="$CC -E"
    CC_R="$CC" 
    CC_SHR="$CC -shared -fpic"
    OPTFLAGS=-O3
    CFLAGS="$CFLAGS -DNEED_FFSLL"
    FFLAGS=$CFLAGS
  else 
    # Sun Workshop compilers: V5.0 and V6.0 R2
    CPP="$CC -E"
    CC_R="$CC -mt"
    CC_SHR="$CC -ztext -G -Kpic" 
      CFLAGS="-xtarget=ultra3 -xarch=v8plusa -DNO_VARARG_MACRO -D__EXTENSIONS__ -DPAPI_NO_MEMORY_MANAGEMENT -DCOMP_VECTOR=_solaris_vectors"
    SMPCFLGS=-xexplicitpar
    OMPCFLGS=-xopenmp
    F77=f90
    FFLAGS=$CFLAGS
    NOOPT=-xO0 
    OPTFLAGS="-g -fast -xtarget=ultra3 -xarch=v8plusa" 
  fi
  LDFLAGS="$LDFLAGS -lcpc" 
  if test "$bitmode" = "64"; then
    LIBRARY=libpapi64.a
    SHLIB=libpapi64.so
      CFLAGS="-xtarget=ultra3 -xarch=v9a -DNO_VARARG_MACRO -D__EXTENSIONS__ -DPAPI_NO_MEMORY_MANAGEMENT  -DCOMP_VECTOR=_solaris_vectors"
    OPTFLAGS="-g -fast -xtarget=ultra3 -xarch=v9a"
  fi

elif test "$MAKEVER" = "solaris-niagara2"; then
    CPUCOMPONENT_NAME=solaris-niagara2
    CPUCOMPONENT_C=solaris-niagara2.c
    CPUCOMPONENT_OBJ=solaris-niagara2.obj
    VECTOR=_niagara2_vector
    PAPI_EVENTS_CSV="papi_events.csv"
    CFLAGS="-xtarget=native -xarch=native -DNO_VARARG_MACRO -D__EXTENSIONS__ -DCOMP_VECTOR=_niagara2_vector"
    ORY_MANAGEMENT="-DCOMP_VECTOR=_solaris_vector"
  DESCR="Solaris 10 with libcpc2 and UltraSPARC T2 (Niagara 2)"
  CPP="$CC -E"
  CC_R="$CC -mt"
  CC_SHR="$CC -ztext -G -Kpic"  
  SMPCFLGS=-xexplicitpar
  OMPCFLGS=-xopenmp
  F77=f90
  FFLAGS=$CFLAGS
  NOOPT=-xO0 
  OPTFLAGS="-fast" 
  FOPTFLAGS=$OPTFLAGS
  LDFLAGS="$LDFLAGS -lcpc" 
  if test "$bitmode" = "64";  then
    LIBRARY=libpapi64.a
    SHLIB=libpapi64.so
    CFLAGS="$CFLAGS -m64"
    FFLAGS="$FFLAGS -m64"
  fi
elif test "$MAKEVER" = "darwin"; then
  DESCR="Darwin"
  CPUCOMPONENT_NAME=darwin
  CPUCOMPONENT=linux-generic.c
  CPUCOMPONENT=linux-generic.obj
  CFLAGS="-DNEED_FFSLL"
  CC_SHR='$(CC) -fPIC -DPIC -shared -Wl,-dylib -Xlinker "-rpath" -Xlinker "$(LIBDIR)"'
  SHLIB=libpapi.dylib
elif test "$MAKEVER" = "generic_platform"; then
  DESCR="Generic platform"
fi

MISCOBJS='$(MISCSRCS:.c=.o)'



if test "$F77" = "pgf77"; then
  FFLAGS="$FFLAGS -Wall -Mextend"
elif test "$F77" = "ifort"; then
  FFLAGS="$FFLAGS -warn all"
elif test "$F77" != "xlf"; then
  FFLAGS="$FFLAGS -ffixed-line-length-132"
fi

if test "$CC_COMMON_NAME" = "icc"; then
    OMPCFLGS=-qopenmp
fi

AC_MSG_CHECKING(for components to build)
COMPONENT_RULES=components/Rules.components
echo "/* Automatically generated by configure */" > components_config.h
echo "#ifndef COMPONENTS_CONFIG_H" >> components_config.h
echo "#define COMPONENTS_CONFIG_H" >> components_config.h
echo "" >> components_config.h

AC_ARG_WITH(components,
        	[  --with-components=<"component1 component2">		Specify which components to build ],
        	[components="$components $withval"]) 

# This is an ugly hack to keep building on configurations covered by any-null in the past.
if test "$VECTOR" = "_papi_dummy_vector"; then
	if test "x$components" = "x"; then 
		echo "papi_vector_t ${VECTOR} = {" >> components_config.h 
 		echo "	.size = {
		.context = sizeof ( int ),
		.control_state = sizeof ( int ),
		.reg_value = sizeof ( int ),
		.reg_alloc = sizeof ( int ),
	}, 
	.cmp_info = { 
		.num_native_events = 0, 
		.num_preset_events = 0, 
		.num_cntrs = 0,
		.name = \"Your system is unsupported! \",
		.short_name = \"UNSUPPORTED!\" 
	},
	.dispatch_timer = NULL,
    .get_overflow_address = NULL,
    .start = NULL,
    .stop = NULL,
    .read = NULL,
    .reset = NULL,
    .write = NULL,
	.cleanup_eventset = NULL,
    .stop_profiling = NULL,
    .init_component = NULL,
    .init_thread = NULL,
    .init_control_state = NULL,
    .update_control_state = NULL,
    .ctl = NULL,
    .set_overflow = NULL,
    .set_profile	 = NULL,
    .set_domain = NULL,
    .ntv_enum_events = NULL,
    .ntv_name_to_code = NULL,
    .ntv_code_to_name = NULL,
    .ntv_code_to_descr = NULL,
    .ntv_code_to_bits = NULL,
    .ntv_code_to_info = NULL,
    .allocate_registers = NULL,
    .shutdown_thread = NULL,
    .shutdown_component = NULL,
    .user = NULL,
};" >> components_config.h
	# but in the face of actual components, we don't have to do hacky size games
	else
		VECTOR=""
	fi
elif test "x$VECTOR" != "x"; then
   echo "extern papi_vector_t ${VECTOR};" >> components_config.h
fi
    


for comp in $components; do
  idx=`echo "$comp" | sed -n "s/\/.*//p" | wc -c`
  if test "$idx" = 0; then
	subcomp=$comp
  else
      subcomp=`echo $comp | sed -E "s/^.{${idx}}//"`
  fi
  COMPONENT_RULES="$COMPONENT_RULES components/$comp/Rules.$subcomp"
  echo "extern papi_vector_t _${subcomp}_vector;" >> components_config.h
done
echo "" >> components_config.h
echo "struct papi_vectors *_papi_hwd[[]] = {" >> components_config.h

if test "x$VECTOR" != "x"; then
   echo "   &${VECTOR}," >> components_config.h
fi

for comp in $components; do
  idx=`echo "$comp" | sed -n "s/\/.*//p" | wc -c` 
  if test "$idx" = 0; then
	subcomp=$comp
  else
      subcomp=`echo $comp | sed -E "s/^.{${idx}}//"`
  fi
  echo "   &_${subcomp}_vector," >> components_config.h
done
echo "   NULL" >> components_config.h
echo "};" >> components_config.h
echo "" >> components_config.h
echo "#endif" >> components_config.h 

# check for component tests
for comp in $components; do
  if test "`find components/$comp -name "tests"`" != "" ; then
	COMPONENTS="$COMPONENTS $comp"
  fi
done
tests="$tests comp_tests"

AC_MSG_RESULT($components)

AC_MSG_CHECKING(for PAPI event CSV filename to use)
if test "x$PAPI_EVENTS_CSV" == "x"; then
   PAPI_EVENTS_CSV="papi_events.csv"
fi
AC_MSG_RESULT($PAPI_EVENTS_CSV)

AC_SUBST(prefix)
AC_SUBST(exec_prefix)
AC_SUBST(libdir)
AC_SUBST(includedir)
AC_SUBST(mandir)
AC_SUBST(bindir)
AC_SUBST(datadir)
AC_SUBST(datarootdir)
AC_SUBST(docdir)
AC_SUBST(PACKAGE_TARNAME)
AC_SUBST(arch)
AC_SUBST(MAKEVER)
AC_SUBST(PMAPI)
AC_SUBST(PMINIT)
AC_SUBST(F77)
AC_SUBST(CPP)
AC_SUBST(CC)
AC_SUBST(AR)
AC_SUBST(papiLIBS)
AC_SUBST(STATIC)
AC_SUBST(LDFLAGS)
AC_SUBST(altix)
AC_SUBST(perfctr_root)
AC_SUBST(perfctr_prefix)
AC_SUBST(perfctr_incdir)
AC_SUBST(perfctr_libdir)
AC_SUBST(pfm_root)
AC_SUBST(old_pfmv2)
AC_SUBST(pfm_prefix)
AC_SUBST(pfm_incdir)
AC_SUBST(pfm_libdir)
AC_SUBST(OS)
AC_SUBST(CFLAGS)
AC_SUBST(FFLAGS)
AC_SUBST(CPPFLAGS)
AC_SUBST(PAPI_EVENTS)
AC_SUBST(PAPI_EVENTS_CSV)
AC_SUBST(SETPATH)
AC_SUBST(LINKLIB)
AC_SUBST(VERSION)
AC_SUBST(CPU)
AC_SUBST(FILENAME)
AC_SUBST(LIBRARY)
AC_SUBST(SHLIB)
AC_SUBST(PAPISOVER)
AC_SUBST(VLIB)
AC_SUBST(PAPICFLAGS)
AC_SUBST(OPTFLAGS)
AC_SUBST(CPUCOMPONENT_NAME)
AC_SUBST(CPUCOMPONENT_C)
AC_SUBST(CPUCOMPONENT_OBJ)
AC_SUBST(OSFILESSRC)
AC_SUBST(OSFILESOBJ)
AC_SUBST(OSFILESHDR)
AC_SUBST(OSLOCK)
AC_SUBST(OSCONTEXT)
AC_SUBST(DESCR)
AC_SUBST(LIBS)
AC_SUBST(CTEST_TARGETS)
AC_SUBST(CC_R)
AC_SUBST(CC_SHR)
AC_SUBST(SMPCFLGS)
AC_SUBST(OMPCFLGS)
AC_SUBST(NOOPT)
AC_SUBST(MISCSRCS)
AC_SUBST(MISCOBJS)
AC_SUBST(POST_BUILD)
AC_SUBST(ARCH_EVENTS)
AC_SUBST(CPU_MODEL)
AC_SUBST(cpu_option)
AC_SUBST(ARG64)
AC_SUBST(FLAGS)
AC_SUBST(MPICC)
AC_SUBST(MISCHDRS)
AC_SUBST(SHLIBDEPS)
AC_SUBST(TOPTFLAGS)
AC_SUBST(TESTS)
AC_SUBST(tests)
AC_SUBST(SHOW_CONF)
AC_SUBST(BGP_SYSDIR)
AC_SUBST(BITFLAGS)
AC_SUBST(COMPONENT_RULES)
AC_SUBST(COMPONENTS)
AC_SUBST(FTEST_TARGETS)
AC_SUBST(HAVE_NO_OVERRIDE_INIT)
AC_SUBST(BGPM_INSTALL_DIR)
AC_SUBST(CC_COMMON_NAME)

if test "$cross_compiling" = "yes" ; then
  AC_MSG_NOTICE(Compiling genpapifdef with $nativecc because cross compiling)
  $nativecc -I. genpapifdef.c -o genpapifdef
else
  AC_MSG_NOTICE(Compiling genpapifdef with $CC)
  $CC -I. genpapifdef.c -o genpapifdef
fi

AC_MSG_NOTICE(Generating fpapi.h)
./genpapifdef -c > fpapi.h
AC_MSG_NOTICE(Generating f77papi.h)
./genpapifdef -f77 > f77papi.h
AC_MSG_NOTICE(Generating f90papi.h)
./genpapifdef -f90 > f90papi.h

AC_MSG_NOTICE($FILENAME will be included in the generated Makefile)
AC_CONFIG_FILES([Makefile papi.pc])
AC_CONFIG_FILES([components/Makefile_comp_tests.target testlib/Makefile.target utils/Makefile.target ctests/Makefile.target ftests/Makefile.target validation_tests/Makefile.target])
AC_OUTPUT