File: configure.ac

package info (click to toggle)
gfarm 2.3.2-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 10,972 kB
  • ctags: 10,894
  • sloc: ansic: 84,510; sh: 13,707; java: 6,866; makefile: 2,286; python: 771; perl: 325; sql: 130; xml: 50; asm: 37; csh: 2
file content (1397 lines) | stat: -rw-r--r-- 36,179 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
dnl Process this file with autoconf to produce a configure script.
AC_INIT
AC_CONFIG_SRCDIR(RELNOTES)
AC_CONFIG_AUX_DIR(makes)
AC_CONFIG_HEADER(include/gfarm/gfarm_config.h)

# Determine target system
# This is called "host" on autotools, because its terminology is following:
# build system - system which is used to build a tool
# host system - system which is used to run a tool
# target system - system which is used to run a program generated by a tool
AC_CANONICAL_HOST

# "linux-gnu" -> "linux", "netbsdelf" -> "netbsd", "osf5.1b" -> "osf1"
case $host_os in
  linux-gnu*)
    host_os_nickname=linux
    ;;
  kfreebsd-gnu)
    host_os_nickname=linux
    ;;
  gnu*)
    host_os_nickname=linux
    ;;
  netbsdelf)
    host_os_nickname=netbsd
    ;;
  osd5.1b)
    host_os_nickname=osf1
    ;;
  *)
    host_os_nickname=$host_os
    ;;
esac

######
###### Checks for programs.
######

AC_PROG_CC(cc gcc) # search cc before gcc
if test x"$GCC" = x"yes"; then # CFLAGS='-g -O2'
  CFLAGS="${CFLAGS} -Wall"
else # CFLAGS='-g'
  CFLAGS="-O" # don't use -g, but use -O
fi

if mkdir -p . 2>/dev/null; then
  MKDIR_P='mkdir -p'
else
  test -d ./-p && rmdir ./-p
  MKDIR_P='$(top_srcdir)/makes/mkdirhier'
fi
AC_SUBST(MKDIR_P)

AC_PROG_INSTALL
AC_PROG_LIBTOOL

######
###### parsing command line options
######

###
### --with-pthread=PTHREAD_ROOT, or --without-pthread
###

AC_MSG_CHECKING([pthread])
AC_ARG_WITH(pthread,
[  --with-pthread=PTHREAD_ROOT	pthread root directory
				[[default=/usr]]
  --without-pthread             disable pthread support],
[with_pthread="${withval}"
])

ax_cv_have_pthread=no

if test x"${with_pthread}" != x"no"; then

  AC_DEFUN([AC_TRY_PTHREAD], [
    CPPFLAGS_SAVE="$CPPFLAGS"
    LIBS_SAVE="$LIBS"
    CPPFLAGS="${pthread_includes} $1 $CPPFLAGS_SAVE"
    # -R is not portable without libtool, and not necessary for AC_TRY_LINK
    LIBS="`echo $2 | sed 's/-R[[^ ]]*//g'` $LIBS_SAVE"
    AC_TRY_LINK([
#include <pthread.h>

void *foo(void *p){ return 0; }],[
	pthread_t thread_id;
	pthread_create(&thread_id, NULL, foo, NULL);
], [	ax_cv_have_pthread=yes
	pthread_includes="${pthread_includes} $1"
	pthread_libs="${pthread_libs} $2"
    ], [
	if test x"${pthread_specified}" = x"explicit"; then
	  AC_MSG_ERROR([\"$3\" is specified, but cannot be linked, aborted])
	fi
    ])
    CPPFLAGS="$CPPFLAGS_SAVE"
    LIBS="$LIBS_SAVE"
  ])

  # always define _REENTRANT
  pthread_includes="-D_REENTRANT"
  pthread_libs=

  if expr x"${with_pthread}" : x"/.*" >/dev/null; then # pathname specified?
    pthread_specified=explicit
    case ${with_pthread} in
    /usr)
      AC_TRY_PTHREAD(,-lpthread,${with_pthread})
      ;;
    *)
      AC_TRY_PTHREAD(-I${with_pthread}/include,-R${with_pthread}/lib -L${with_pthread}/lib -lpthread,${with_pthread})
      ;;
    esac
  elif test x"${with_pthread}" != x && test x"${with_pthread}" != x"yes"; then
    pthread_specified=explicit
    AC_TRY_PTHREAD(${with_pthread},${with_pthread},${with_pthread})
  elif test x"${PTHREAD_CFLAGS+1}${PTHREAD_LDFLAGS+2}${PTHREAD_LIBS+3}" != x""
  then # NetBSD pkgsrc configuration is specified?
    pthread_specified=explicit
    AC_TRY_PTHREAD(${PTHREAD_CFLAGS},${PTHREAD_LDFLAGS} ${PTHREAD_LIBS},${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS} ${PTHREAD_LIBS})
  else # otherwise try system supplied pthread library
    pthread_specified=yes
    case $host in
    *-*-aix*)
	AC_TRY_PTHREAD(-mthreads,-mthreads,);;
    *-*-freebsd[[2-4]].*) # FreeBSD 2.X ... 4.X (-lc_r) needs -D_THREAD_SAFE
	AC_TRY_PTHREAD(-D_THREAD_SAFE -pthread,-pthread,);;
    *-*-hpux*)
	AC_TRY_PTHREAD(-D_POSIX_C_SOURCE=199506L -D_HPUX_SOURCE,-lpthread,);;
    *-*-solaris*)
	if test x"$GCC" = x"yes"; then
		AC_TRY_PTHREAD(-pthread,-pthread,)
	else
		AC_TRY_PTHREAD(-mt -D_POSIX_PTHREAD_SEMANTICS,-mt -lpthread,)
	fi;;
    *-*-sysv5uw7*) # UnixWare 7
	if test x"$GCC" = x"yes"; then
		AC_TRY_PTHREAD(-pthread,-pthread,)
	else
		AC_TRY_PTHREAD(-Kthread,-Kthread,)
	fi;;
    *)
	# Tru64 (OSF1): -pthread
	# FreeBSD 5.X: -pthread, 3 libraries are available as follows:
	#	-lpthread (M:N, default), -lc_r (1:N), and -lthr (1:1)
	# NetBSD 2.X or later: -pthread
	# Linux: -pthread
	AC_TRY_PTHREAD(-pthread,-pthread,);;
    esac

    # and if it fails too, just try default ${CFLAGS}, ${LDFLAGS} and ${LIBS}
    if test x"${ax_cv_have_pthread}" != x"yes"; then
      AC_TRY_PTHREAD(,,)
    fi
  fi
fi

case ${ax_cv_have_pthread} in
yes)
  AC_MSG_RESULT([using CFLAGS=\"${pthread_includes}\" and LDLIBS=\"${pthread_libs}\"])
  AC_DEFINE(HAVE_PTHREAD, 1, [pthread library exists])

  pthread_srcs='${PTHREAD_SRCS}'
  pthread_objs='${PTHREAD_OBJS}'
  pthread_cflags='${PTHREAD_CFLAGS}'
  pthread_targets='${PTHREAD_TARGETS}'
  ;;
*)
  if test x"${with_pthread}" = x"no"; then
    AC_MSG_RESULT([disabled])
  else
    # in this case, must be: test x"${pthread_specified}" != x"explicit"
    AC_MSG_RESULT([no])
  fi

  pthread_includes=
  pthread_libs=
  pthread_srcs=
  pthread_objs=
  pthread_cflags=
  pthread_targets=
  ;;
esac

AC_SUBST(pthread_includes)
AC_SUBST(pthread_libs)
# for conditional compilation which depends on pthread
AC_SUBST(pthread_srcs)
AC_SUBST(pthread_objs)
AC_SUBST(pthread_cflags)
AC_SUBST(pthread_targets)

###
### --with-openssl=OpenSSL_ROOT
###

# sanity check for OpenSSL is deferred, because ${openssl_includes}
# and ${openssl_lib} may be overrided by Globus autoconfiguration.

AC_ARG_WITH(openssl,
[  --with-openssl=OpenSSL_ROOT	openssl root directory
				[[default=/usr]]],
[with_openssl="${withval}"
],
[with_openssl=/usr
])
AC_MSG_RESULT([using \"${with_openssl}\"])

openssl_libs='-lcrypto'
if test x"${with_openssl}" = x"/usr"; then
   openssl_includes=
else
   openssl_includes="-I${with_openssl}/include"
   openssl_libs="-R${with_openssl}/lib -L${with_openssl}/lib ${openssl_libs}"
fi


AC_SUBST(openssl_includes)
AC_SUBST(openssl_libs)

###
### --with-globus=GLOBUS_ROOT --with-globus-flavor=FLAVOR -with-globus-static
###

AC_ARG_WITH(globus_static,
[  --with-globus-static		link static version of globus libraries instead of shared version
				[[default=disable]]],
[globus_static="${withval}"
],
[globus_static=""
])



AC_ARG_WITH(globus_flavor,
[  --with-globus-flavor=FLAVOR	globus flavor name
				[[default=guessed]]],
[globus_flavor="${withval}"
],
[globus_flavor=
])

AC_SUBST(globus_flavor)


AC_MSG_CHECKING([globus])
AC_ARG_WITH(globus,
[  --with-globus=GLOBUS_ROOT	globus root directory
				[[default=disable]]],
[globus_location="${withval}"
 case "${globus_location}" in yes) globus_location=${GLOBUS_LOCATION};; esac

 GLBlocation_candidates=${globus_location:-/usr/grid}
 if test -n "$globus_flavor"; then
	GLBflavor_candidates="$globus_flavor"
 else
	GLBflavor_candidates=
	if test x"$GCC" = x"yes"; then
		tmp='gcc vendorcc'
	else
		tmp='vendorcc gcc'
	fi
	for GLBbits in 64 32; do
		for GLBcc in $tmp; do
			for GLBdebug in "" dbg; do
				for GLBpthread in "" pthr; do
					GLBflavor_candidates="$GLBflavor_candidates $GLBcc$GLBbits$GLBdebug$GLBpthread"
				done
			done
		done
	done
 fi
 globus_found=
 for d in ${GLBlocation_candidates}; do
	for f in ${GLBflavor_candidates}; do
		if test -f "$d/include/$f/gssapi.h"; then
			globus_location=$d
			globus_flavor=$f
			globus_found=yes
			break
		fi
	done
	if test x"$globus_found" = x"yes"; then break; fi
 done
 if test x"$globus_found" != x"yes"; then
	AC_MSG_RESULT([not found])
	AC_MSG_RESULT([searched directories are: ${GLBlocation_candidates}])
	AC_MSG_RESULT([searched flavors are: ${GLBflavor_candidates}])
	if test -n "$globus_flavor"; then
		AC_MSG_ERROR([cannot find the globus flavor \"$globus_flavor\", missing include/$globus_flavor/gssapi.h under ${GLBlocation_candidates}.])
	else
		AC_MSG_ERROR([cannot automatically find include/\${GLOBUS_FLAVOR}/gssapi.h under ${GLBlocation_candidates}, please specify the flavor by --with-globus-flavor=GLOBUS_FLAVOR])
	fi
	exit 1
 fi
 AC_MSG_RESULT([found in \"${globus_location}\" with \"${globus_flavor}\" flavor])

 globus_includes="-I${globus_location}/include/${globus_flavor}"
 globus_libdir="${globus_location}/lib"

 cfgmhtmp=/tmp/cfgmh$$
 AC_MSG_CHECKING([globus library names])
 if	case ${globus_static} in
	yes)	env GLOBUS_LOCATION=${globus_location} ${globus_location}/bin/globus-makefile-header -static -flavor=${globus_flavor} globus_gssapi_gsi;;
	*)	env GLOBUS_LOCATION=${globus_location} ${globus_location}/bin/globus-makefile-header         -flavor=${globus_flavor} globus_gssapi_gsi;;
	esac > $cfgmhtmp
 then
	AC_MSG_RESULT([done])
 else
	rm -f $cfgmhtmp
	AC_MSG_RESULT([failed to call ${globus_location}/bin/globus-makefile-header command.])
	AC_MSG_RESULT([Please run \${GPT_LOCATION}/sbin/gpt-postinstall, if it is not invoked yet.])
	AC_MSG_ERROR([Globus installation is incomplete, aborted.])
 fi
 globus_gssapi_libs=`sed -n '/^GLOBUS_PKG_LIBS *=/s///p' $cfgmhtmp`
 rm -f $cfgmhtmp
 case ${globus_static} in
 yes)	:;;
 *)	globus_gssapi_libs="-R${globus_libdir} -L${globus_libdir} $globus_gssapi_libs"
 esac

 # for conditional compilation which depends on whether globus is enabled or not
 globus_srcs='${GLOBUS_SRCS}'
 globus_objs='${GLOBUS_OBJS}'
 globus_cflags='${GLOBUS_CFLAGS}'
 globus_targets='${GLOBUS_TARGETS}'

 # replace openssl library with that included in globus
 if test -x ${globus_location}/bin/globus-version; then
   globus_version=`env GLOBUS_LOCATION=${globus_location} ${globus_location}/bin/globus-version`
   case ${globus_version} in
   4.0*|3*|2*)
     openssl_includes="${globus_includes}"
     case ${globus_static} in
     yes) openssl_libs="${globus_libdir}/libssl_${globus_flavor}.a ${globus_libdir}/libcrypto_${globus_flavor}.a"
	AC_MSG_RESULT([using globus static library: yes]);;
     *)	  openssl_libs="-R${globus_libdir} -L${globus_libdir} -lssl_${globus_flavor} -lcrypto_${globus_flavor}"
	AC_MSG_RESULT([using globus static library: no]);;
     esac;;
   *) # after 4.2.0, globus does not include openssl libarary.
     ;;
   esac
 fi

 AC_DEFINE(HAVE_GSI, 1, [Grid Security Infrastructure exists])
],
[AC_MSG_RESULT([disabled])
 globus_location=
 globus_includes=
 globus_gssapi_libs=

 # for conditional compilation which depends on whether globus is enabled or not
 globus_srcs=
 globus_objs=
 globus_cflags=
 globus_targets=
])

AC_SUBST(globus_location)
AC_SUBST(globus_includes)
AC_SUBST(globus_gssapi_libs)

# for conditional compilation which depends on whether globus is enabled or not
AC_SUBST(globus_srcs)
AC_SUBST(globus_objs)
AC_SUBST(globus_cflags)
AC_SUBST(globus_targets)

###
### --with-gfshook
###

AC_ARG_WITH(gfshook,
[  --with-gfshook		build libgfs_hook.so syscall hooking library
				[[default]]
  --without-gfshook             disable to build syscall hooking library])

if test x${with_gfshook} != xno
then
 gfshook_srcs='${GFSHOOK_SRCS}'
 gfshook_objs='${GFSHOOK_OBJS}'
 gfshook_cflags='${GFSHOOK_CFLAGS}'
 gfshook_targets='${GFSHOOK_TARGETS}'
else
 AC_MSG_CHECKING([gfshook])
 AC_MSG_RESULT([disable])

 gfshook_srcs=
 gfshook_objs=
 gfshook_cflags=
 gfshook_targets=
fi

# for conditional compilation related to syscall hooking library
AC_SUBST(gfshook_srcs)
AC_SUBST(gfshook_objs)
AC_SUBST(gfshook_cflags)
AC_SUBST(gfshook_targets)

###
### --with-mpi=MPI_ROOT
###

AC_MSG_CHECKING([mpi])
AC_ARG_WITH(mpi,
[  --with-mpi=MPI_ROOT		MPI root directory
				[[default=disable]]],
[with_mpi="${withval}"
 if test x"${withval}" = x'yes'; then
  mpicc="mpicc"
 else
  mpicc="${with_mpi}/bin/mpicc"
 fi
 AC_MSG_RESULT([using \"${mpicc}\"])

 # for conditional compilation which depends on whether MPI is enabled or not
 mpi_srcs='${MPI_SRCS}'
 mpi_objs='${MPI_OBJS}'
 mpi_cflags='${MPI_CFLAGS}'
 mpi_targets='${MPI_TARGETS}'
],
[AC_MSG_RESULT([disabled])
 with_mpi=

 mpicc=
 # for conditional compilation which depends on whether MPI is enabled or not
 mpi_srcs=
 mpi_objs=
 mpi_cflags=
 mpi_targets=
])

AC_SUBST(mpicc)
# for conditional compilation which depends on whether globus is enabled or not
AC_SUBST(mpi_srcs)
AC_SUBST(mpi_objs)
AC_SUBST(mpi_cflags)
AC_SUBST(mpi_targets)

### The following options are all "ns" specific

###
### --with-readline=READLINE_ROOT
###

AC_MSG_CHECKING([readline])
AC_ARG_WITH(readline,
[  --with-readline=READLINE_ROOT	readline root directory
				[[default=disable]]],
[with_readline="${withval}"
],
[with_readline=
])

readline_specified=
case ${with_readline} in
/*)
  if test -f "${with_readline}"/include/readline/readline.h; then
	readline_specified=explicit
  else
	AC_MSG_ERROR([not found in \"${with_readline}\", aborted])
  fi;;
yes)
  for d in /usr/local /usr/pkg /usr
  do
    if test -f $d/include/readline/readline.h; then
	with_readline=$d
	readline_specified=yes
	break
    fi
  done;;
no|'')
  ;;
*)
  readline_specified=explicit;;
esac

readline_includes=
readline_libs=

if test x"${readline_specified}" = x""; then
  AC_MSG_RESULT([no])
else
  AC_MSG_RESULT([using \"${with_readline}\"])
  AC_DEFINE(HAVE_READLINE, 1, [readline-compatible library exists])
  readline_libs="-lreadline -ltermcap"
  case ${with_readline} in
  /usr)	;;
  /*)	readline_includes="-I${with_readline}/include ${readline_includes}"
	readline_libs="-R${with_readline}/lib -L${with_readline}/lib ${readline_libs}"
	;;
  *)	readline_includes=${with_readline}
	readline_libs=${with_readline}
	;;
  esac
fi

AC_SUBST(readline_includes)
AC_SUBST(readline_libs)

###
### --with-default-ns-server=HOSTNAME
###

AC_ARG_WITH(default_ns_server,
[  --with-default-ns-server=HOSTNAME	default hostname of ns server
				[[default=localhost]]],
[default_ns_server="${withval}"], [default_ns_server='localhost'])
AC_SUBST(default_ns_server)

###
### --with-default-ns-port=PORTNUMBER
###

AC_ARG_WITH(default_ns_port,
[  --with-default-ns-port=PORTNUMBER	default port number of ns server
				[[default=5000]]],
[default_ns_port="${withval}"], [default_ns_port='5000'])
AC_SUBST(default_ns_port)

###
### --with-default-ns-exec-root=DIR
###

AC_ARG_WITH(default_ns_exec_root,
[  --with-default-ns-exec-root=DIR	default top directory of ns_exec
				[[default=PREFIX]]],
[default_ns_exec_root="${withval}"
 default_ns_exec_bindir="${default_ns_exec_root}/bin"
],
[default_ns_exec_root='$(prefix)'
 default_ns_exec_bindir='$(bindir)'
])

AC_SUBST(default_ns_exec_root)
AC_SUBST(default_ns_exec_bindir)

###
### --with-gfarm-rsh=RSH_COMMAND
###

AC_ARG_WITH(gfarm_rsh,
[  --with-gfarm-rsh=RSH		command name equivalent to rsh
				[[default=rsh]]],
[gfarm_rsh="${withval}"], [gfarm_rsh='rsh'])
AC_SUBST(gfarm_rsh)

###
### --with-gfarmd-username=DIR
###

AC_ARG_WITH(gfarmd_username,
[  --with-gfarmd-username=DIR	default username of gfarmd
				[[default=nobody]]],
[gfarmd_username="${withval}"], [gfarmd_username='nobody'])
AC_SUBST(gfarmd_username)

###
### --without-mtsafe-netdb ... are getaddrinfo(3) and getnameinfo(3) MT-Safe?
###

AC_ARG_WITH(mtsafe_netdb,
[  --without-mtsafe-netdb	getaddrinfo(3) and getnameinfo(3) are MT-Safe?
				[[default=yes]]],
[mtsafe_netdb="${withval}"], [mtsafe_netdb="yes"])

case ${mtsafe_netdb} in
no) :;;
*)  AC_DEFINE(HAVE_MTSAFE_NETDB, 1, [getaddrinfo(3) and getnameinfo(3) are MT-Safe]);;
esac

######
###### Checks for libraries.
######

### check sanity of $CC, $CFLAGS and $CPPFLAGS

AC_CHECK_HEADERS(stdio.h)
if test x"${ac_cv_header_stdio_h}" != x"yes"; then
	AC_MSG_RESULT([preprocessor option error on: \"$ac_cpp\"])
	#exit 1
fi

### check sanity of $CC, $CFLAGS, $CPPFLAGS and $LDFLAGS setting

AC_CHECK_FUNCS(printf)
if test x"${ac_cv_func_printf}" != x"yes"; then
	AC_MSG_RESULT([linker option error on: \"$ac_link\"])
	exit 1
fi

# We need to add those libraries to $LIBS at first,
# otherwise some libraries (e.g. OpenLDAP and OpenSSL) cannot be linked.
# AC_CHECK_LIB(dl, dlopen)
# AC_CHECK_LIB(nsl, gethostname)	# SVR4 and derived
AC_CHECK_LIB(socket, socket)	# SVR4 and derived
# AC_CHECK_LIB(crypt, crypt)	# 4.4BSD and derived
AC_CHECK_LIB(compat, cuserid)	# NetBSD
AC_CHECK_LIB(gen, basename)	# IRIX
# AC_CHECK_LIB(rt, fdatasync)	# Solaris
AC_CHECK_LIB(cext, seteuid)	# HP-UX
AC_CHECK_LIB(perfstat, perfstat_cpu_total) # AIX, to implement getloadavg()

# have pthread_attr_setstacksize(3)?
case ${ax_cv_have_pthread} in
yes)
  AC_MSG_CHECKING([for pthread_attr_setstacksize])
  CPPFLAGS_SAVE="$CPPFLAGS"
  LIBS_SAVE="$LIBS"
  CPPFLAGS="${pthread_includes} $CPPFLAGS"
  LIBS="$LIBS ${pthread_libs}"

  AC_TRY_LINK([
#   include <pthread.h>

    void test(void){}],[
      pthread_attr_t at;
      if (pthread_attr_init(&at) == 0)
        pthread_attr_setstacksize(&at, 64 * 1024);
    ], [
      AC_MSG_RESULT([yes])
      AC_DEFINE(HAVE_PTHREAD_ATTR_SETSTACKSIZE, 1, [pthread_attr_setstacksize() exists])
    ], [
      AC_MSG_RESULT([no])
    ])

  CPPFLAGS="$CPPFLAGS_SAVE"
  LIBS="$LIBS_SAVE"
  ;;
esac

# Since gfarm-1.3, libgfarm calls pthread functions internally,
# thus, we need to link ${pthread_libs}, unless libc supplies weak symbols.
# e.g. using 3rd party pthread library, FreeBSD-4.x, or NetBSD-2.x
AC_MSG_CHECKING([whether libc supplies weak symbols for pthread])
AC_TRY_LINK([
#include <pthread.h>

void init(void){}],[
    pthread_once_t once;
    pthread_once(&once, init);
], [
	AC_MSG_RESULT([yes])
], [
	AC_MSG_RESULT([no. WARNING: always link pthread])
	LIBS="${LIBS} ${pthread_libs}"
])

### use 64bit off_t, if possible.

AC_MSG_CHECKING([Large File extention for 64bit off_t])
if ( getconf LFS_CFLAGS &&
     getconf LFS_LDFLAGS &&
     getconf LFS_LIBS ) > /dev/null 2>&1; then
	AC_MSG_RESULT([yes])

	largefile_cflags="`getconf LFS_CFLAGS`"
	largefile_ldflags="`getconf LFS_LDFLAGS`"
	LIBS="$LIBS `getconf LFS_LIBS`"

	if test x"$host_os" = x"linux-gnu"; then
		# glibc requires _GNU_SOURCE for pwrite64(2)
		largefile_cflags="${largefile_cflags} -D_GNU_SOURCE"
	fi

else
	AC_MSG_RESULT([no])

	largefile_cflags=
	largefile_ldflags=
fi

AC_SUBST(largefile_cflags)
AC_SUBST(largefile_ldflags)

### is _LARGEFILE64_SOURCE API supported? i.e. can be _LFS64_LARGEFILE=1?

AC_MSG_CHECKING([_LARGEFILE64_SOURCE API])
if ( getconf LFS64_CFLAGS &&
     getconf LFS64_LDFLAGS &&
     getconf LFS64_LIBS ) > /dev/null 2>&1; then
	AC_MSG_RESULT([yes])

	largefile64_srcs='${LARGEFILE64_SRCS}'
	largefile64_objs='${LARGEFILE64_OBJS}'
	largefile64_cflags='${LARGEFILE64_CFLAGS}'
	largefile64_targets='${LARGEFILE64_TARGETS}'
else
	AC_MSG_RESULT([no])

	largefile64_srcs=
	largefile64_objs=
	largefile64_cflags=
	largefile64_targets=
fi

# for conditional compilation which depends on _LARGEFILE64_SOURCE API
AC_SUBST(largefile64_srcs)
AC_SUBST(largefile64_objs)
AC_SUBST(largefile64_cflags)
AC_SUBST(largefile64_targets)

### sanity check whether OpenSSL is really usable or not

AC_MSG_CHECKING([openssl])

CPPFLAGS_SAVE="$CPPFLAGS"
LIBS_SAVE="$LIBS"
CPPFLAGS="${openssl_includes} $CPPFLAGS_SAVE"
# -R is not portable without libtool, and not necessary for AC_TRY_LINK
LIBS="`echo ${openssl_libs} | sed 's/-R[[^ ]]*//g'` $LIBS_SAVE"

AC_TRY_LINK([
#include <openssl/evp.h>],[
EVP_MD_CTX md_ctx;
EVP_MD *md_type = EVP_get_digestbyname("sha1");

EVP_DigestInit(&md_ctx, md_type);
], [], [
  AC_MSG_ERROR([OpenSSL cannot be linked with \"${openssl_includes} ${openssl_libs}\" options, aborted])
])

CPPFLAGS="$CPPFLAGS_SAVE"
LIBS="$LIBS_SAVE"

AC_MSG_RESULT([using \"${openssl_includes} ${openssl_libs}\"])

###
### --with-openldap=OpenLDAP_ROOT
###

# This command line option must be handled here,
# because this needs AC_CHECK_LIB(nsl, ...)

AC_MSG_CHECKING([openldap])
AC_ARG_WITH(openldap,
[  --with-openldap=OpenLDAP_ROOT	openldap root directory
				[[default=guessed]]
  --without-openldap			disable openldap],
[with_openldap="${withval}"
],
[with_openldap=
])

ldap_specified=
case ${with_openldap} in
/*)
  if test -f "${with_openldap}"/include/ldap.h; then
	ldap_specified=explicit
  else
	AC_MSG_ERROR([not found in \"${with_openldap}\", aborted])
  fi;;
yes|'')
  for d in /usr/local/openldap /usr/local /usr/pkg /usr
  do
    if test -f $d/include/ldap.h; then
	with_openldap=$d
	ldap_specified=yes
	break
    fi
  done;;
no)
  ;;
*)
  ldap_specified=explicit;;
esac

ldap_usable=

if test x"${ldap_specified}" = x""; then
  AC_MSG_RESULT([no])
else
  AC_DEFUN([AC_TRY_LDAP], [
    CPPFLAGS_SAVE="$CPPFLAGS"
    LIBS_SAVE="$LIBS"
    CPPFLAGS="$1 $CPPFLAGS_SAVE"
    # -R is not portable without libtool, and not necessary for AC_TRY_LINK
    LIBS="`echo $2 | sed 's/-R[[^ ]]*//g'` $3 $4 ${openssl_libs} $LIBS_SAVE"
	# OpenLDAP may need OpenSSL due to its SSL/TLS support.
    AC_TRY_LINK([
#include <lber.h>
#include <ldap.h>],[
	LDAP *ldap_server = ldap_open("example.com", 389);
], [
	if test x"$4" != x""; then
		AC_MSG_RESULT([using \"$1 $2 $3\" with \"$4\" for LDAP])
		ldap_libs="$2 $3 $4"
	else
		AC_MSG_RESULT([using \"$1 $2 $3\" for LDAP])
		ldap_libs="$2 $3"
	fi
	ldap_usable=yes
	# this needs to be checked here due to settings of $CPPFLAGS and $LIBS
	AC_CHECK_FUNCS(ldap_memfree ldap_set_option ldap_start_tls_s ldap_perror)
    ], [])
    CPPFLAGS="$CPPFLAGS_SAVE"
    LIBS="$LIBS_SAVE"
  ])

  case ${with_openldap} in
  /*)	case ${with_openldap} in
	/usr)	ldap_includes=
		ldap_libs=;;
	*)	ldap_includes="-I${with_openldap}/include"
		ldap_libs="-R${with_openldap}/lib -L${with_openldap}/lib";;
	esac
	# OpenLDAP since 2.x calls res_query() and dn_expand(), if dnssrv is
	# configured, and DNS resolver library doesn't belongs to libc on some
	# systems.
	# But we cannot blindly link libresolv, because it may change behaviour
	# of gethostbyname() and friends.
	for libs in "-lldap -llber" "-lldap"; do
	  for extra_lib in "" "-lresolv" "-lbind"; do
	    AC_TRY_LDAP(${ldap_includes},${ldap_libs},${libs},${extra_lib})
	    if test x"${ldap_usable}" = x"yes"; then
	      break 2
	    fi
	  done
	done
	;;
  *)	ldap_includes=${with_openldap}
	ldap_libs=${with_openldap}
	AC_TRY_LDAP(${ldap_includes},${ldap_libs},,)
	;;
  esac

  if test x"${ldap_usable}" != x"yes"; then
    case $ldap_specified in
    explicit)
	  AC_MSG_ERROR([\"${with_openldap}\" is specified, but cannot be linked, aborted]);;
    yes)
	  AC_MSG_RESULT([found in \"${with_openldap}\", but cannot be linked, ignored]);;
    esac
  fi
fi

case $ldap_usable in
yes)	AC_DEFINE(HAVE_LDAP, 1, [LDAP library exists])
	ldap_srcs='${LDAP_SRCS}'
	ldap_objs='${LDAP_OBJS}'
	ldap_cflags='${LDAP_CFLAGS}'
	ldap_targets='${LDAP_TARGETS}'
	;;
*)	ldap_includes=
	ldap_libs=
	ldap_srcs=
	ldap_objs=
	ldap_cflags=
	ldap_targets=
	;;
esac

AC_SUBST(ldap_includes)
AC_SUBST(ldap_libs)

# for conditional compilation which depends on LDAP
AC_SUBST(ldap_srcs)
AC_SUBST(ldap_objs)
AC_SUBST(ldap_cflags)
AC_SUBST(ldap_targets)

###
### --with-postgresql=PostgreSQL_ROOT
###

AC_MSG_CHECKING([PostgreSQL])
AC_ARG_WITH(postgresql,
[  --with-postgresql=PostgreSQL_ROOT	PostgreSQL root directory
				[[default=guessed]]
  --without-postgresql			disable PostgreSQL],
[with_postgresql="${withval}"
],
[with_postgresql=
])

postgresql_specified=
case ${with_postgresql} in
/*)
  if test -f "${with_postgresql}"/bin/pg_config; then
	postgresql_specified=explicit
  else
	AC_MSG_ERROR([not found in \"${with_postgresql}\", aborted])
  fi;;
yes|'')
  for d in /usr/local/pgsql /usr/local /usr/pkg /usr
  do
    if test -f $d/bin/pg_config; then
	with_postgresql=$d
	postgresql_specified=yes
	break
    fi
  done;;
no)
  ;;
*)
  postgresql_specified=explicit;;
esac

postgresql_usable=

if test x"${postgresql_specified}" = x""; then
  AC_MSG_RESULT([no])
else
  if test -x ${with_postgresql}/bin/pg_config; then
    if ! ${with_postgresql}/bin/pg_config --version > /dev/null 2>&1; then
	AC_MSG_RESULT([failed to call ${with_postgresql}/bin/pg_config command.])
	AC_MSG_ERROR([PostgreSQL installation is incomplete, aborted.])
    fi
    postgresql_include_dir=`${with_postgresql}/bin/pg_config --includedir`
    postgresql_lib_dir=`${with_postgresql}/bin/pg_config --libdir`
    case ${postgresql_include_dir} in
    /usr/include) postgresql_includes= ;;
    *) postgresql_includes="-I${postgresql_include_dir}" ;;
    esac
    case ${postgresql_lib_dir} in
    /usr/lib) postgresql_libs="-lpq" ;;
    *) postgresql_libs="-R${postgresql_lib_dir} -L${postgresql_lib_dir} -lpq" ;;
    esac
  else
    postgresql_includes="${with_postgresql}"
    postgresql_libs="${with_postgresql}"
  fi

  CPPFLAGS_SAVE="$CPPFLAGS"
  LIBS_SAVE="$LIBS"

  CPPFLAGS="${postgresql_includes} $CPPFLAGS_SAVE"
  # -R is not portable without libtool, and not necessary for AC_TRY_LINK
  LIBS="`echo $postgresql_libs | sed 's/-R[[^ ]]*//g'` $LIBS_SAVE"

  AC_TRY_LINK([
#include <stdio.h>
#include <libpq-fe.h>],[
	PGconn *conn = PQconnectdb("");
	PGresult *res = PQexecParams(conn, "", 0, NULL, NULL, NULL, NULL, 0);
  ], [
	postgresql_usable=yes
	AC_MSG_RESULT([using \"${with_postgresql}\"])
  ], [
	case $postgresql_specified in
	explicit)
		AC_MSG_ERROR([\"${with_postgresql}\" is specified, but cannot be linked, aborted]);;
	yes)
		AC_MSG_RESULT([found in \"${with_postgresql}\", but cannot be linked, ignored]);;
	esac
  ])

  CPPFLAGS="$CPPFLAGS_SAVE"
  LIBS="$LIBS_SAVE"
fi

case $postgresql_usable in
yes)	AC_DEFINE(HAVE_POSTGRESQL, 1, [PostgreSQL library exists])
	postgresql_srcs='${POSTGRESQL_SRCS}'
	postgresql_objs='${POSTGRESQL_OBJS}'
	postgresql_cflags='${POSTGRESQL_CFLAGS}'
	postgresql_targets='${POSTGRESQL_TARGETS}'
	;;
*)	postgresql_includes=
	postgresql_libs=
	postgresql_srcs=
	postgresql_objs=
	postgresql_cflags=
	postgresql_targets=
	;;
esac

AC_SUBST(postgresql_includes)
AC_SUBST(postgresql_libs)

# for conditional compilation which depends on PostgreSQL
AC_SUBST(postgresql_srcs)
AC_SUBST(postgresql_objs)
AC_SUBST(postgresql_cflags)
AC_SUBST(postgresql_targets)

###
### sanity check. We need either PostgreSQL or LDAP.
###

if test x"${ldap_usable}" != x"yes" && test x"${postgresql_usable}" != x"yes"
then
	AC_MSG_RESULT([WARNING: neither LDAP or PostgreSQL is found])
fi

######
###### Checks for header files.
######

AC_CHECK_HEADERS(inttypes.h shadow.h crypt.h machine/endian.h attr/xattr.h sys/xattr.h sys/loadavg.h)

######
###### Checks for types.
######

AC_C_BIGENDIAN

AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(long long)

### socklen_t is available?

AC_MSG_CHECKING([socklen_t])

case $host_os_nickname in
hpux)
  # There are two ways to deal with socklen_t on HP-UX 11i.
  # 1. Use system supplied socklen_t.
  #   This requires CPPFLAGS=-D_XOPEN_SOURCE_EXTENDED and LIBS=-lxnet.
  # 2. Use int.
  #   This is incompatible with both -D_XOPEN_SOURCE_EXTENDED and -lxnet.
  # socklen_t had been also usable for the case 2 on HP-UX before LP64 support.
  # But this is no longer true on LP64 HP-UX, because socklen_t is now always
  # size_t on HP-UX, and size_t is uint64_t on LP64 systems. The problem is
  # that 1 and 2 are incompatible, and cannot be linked each other.
  # We choose 2 here, because that seems to be the way most third party
  # libraries are using now.
  ax_cv_have_socklen_t=no # don't try linking, it's linkable, but doesn't work.
  ;;

*)
  AC_TRY_LINK([
# include <sys/types.h>
# include <sys/socket.h>],[
  int rv, s = socket(PF_INET, SOCK_STREAM, 0);
  struct sockaddr addr;
  socklen_t len;

  rv = getpeername(s, &addr, &len);
  ], [ax_cv_have_socklen_t=yes], [ax_cv_have_socklen_t=no])
  ;;
esac

if test "$ax_cv_have_socklen_t" = yes; then
  AC_MSG_RESULT([yes])
else

  # determine size of socklen_t

  AC_TRY_RUN([
# include <sys/types.h>
# include <sys/socket.h>

  main() {
	struct msghdr h;

	/* h.msg_namelen should be socklen_t */
	h.msg_namelen = -1;
	if (sizeof(h.msg_namelen) == sizeof(int) && h.msg_namelen < 0)
		return (0); /* int */
	else
		return (1); /* size_t */
  }
  ], [ax_cv_socklen_t=int], [ax_cv_socklen_t=size_t])

  AC_MSG_RESULT([$ax_cv_socklen_t])
  AC_DEFINE_UNQUOTED(socklen_t, $ax_cv_socklen_t,
   [3rd argument type of bind(2)/connect(2), if <sys/socket.h> doesn't define])
fi

######
###### Checks for structures.
######

AC_MSG_CHECKING([struct dirent::d_off])
AC_TRY_COMPILE([
#include <sys/types.h>
#include <dirent.h>],[
struct dirent d;
long off;

off = d.d_off;
], [ax_cv_have_d_off=yes], [ax_cv_have_d_off=no])
AC_MSG_RESULT([$ax_cv_have_d_off])
if test "$ax_cv_have_d_off" = yes; then
  AC_DEFINE(HAVE_D_OFF, 1, [struct dirent has d_off member])
fi

AC_MSG_CHECKING([struct dirent::d_namlen])
AC_TRY_COMPILE([
#include <sys/types.h>
#include <dirent.h>],[
struct dirent d;
int len;

len = d.d_namlen;
], [ax_cv_have_d_namlen=yes], [ax_cv_have_d_namlen=no])
AC_MSG_RESULT([$ax_cv_have_d_namlen])
if test "$ax_cv_have_d_namlen" = yes; then
  AC_DEFINE(HAVE_D_NAMLEN, 1, [struct dirent has d_namlen member])
fi

AC_MSG_CHECKING([struct dirent::d_type])
AC_TRY_COMPILE([
#include <sys/types.h>
#include <dirent.h>],[
struct dirent d;
int len;

len = d.d_type;
], [ax_cv_have_d_type=yes], [ax_cv_have_d_type=no])
AC_MSG_RESULT([$ax_cv_have_d_type])
if test "$ax_cv_have_d_type" = yes; then
  AC_DEFINE(HAVE_D_TYPE, 1, [struct dirent has d_type member])
fi

###### Checks for compiler characteristics.
# empty for now

######
###### Checks for library functions.
######

AC_CHECK_FUNCS(epoll_wait getdents fdatasync fdopendir poll pread pwrite snprintf getpassphrase mkdtemp setlogin strtoll strtoq setrlimit daemon getloadavg statvfs statfs)

### SUSv2 getpwnam_r() has 5 args, but Solaris's only has 4.

AC_MSG_CHECKING([SUSv2 compliant getpwnam_r])
AC_TRY_LINK([
#include <sys/types.h>
#include <pwd.h>],[
int rv;
struct passwd *pwd;
char buffer[1024];

rv = getpwnam_r("root", pwd, buffer, sizeof buffer, &pwd);
], [ax_cv_have_getpwnam_r=yes], [ax_cv_have_getpwnam_r=no])
AC_MSG_RESULT([$ax_cv_have_getpwnam_r])
if test "$ax_cv_have_getpwnam_r" = yes; then
  AC_DEFINE(HAVE_GETPWNAM_R, 1,
	[5 arguments getpwnam_r() which is compatible with SUSv2 exists])
fi

### SUSv2 getspnam_r() has 5 args, but Solaris's only has 4.

AC_MSG_CHECKING([SUSv2 compliant getspnam_r])
AC_TRY_LINK([
#include <shadow.h>],[
int rv;
struct spwd *sp;
char buffer[1024];

rv = getspnam_r("root", sp, buffer, sizeof buffer, &sp);
], [ax_cv_have_getspnam_r=yes], [ax_cv_have_getspnam_r=no])
AC_MSG_RESULT([$ax_cv_have_getspnam_r])
if test "$ax_cv_have_getspnam_r" = yes; then
  AC_DEFINE(HAVE_GETSPNAM_R, 1, [5 arguments getspnam_r() exists])
fi

### Solaris no longer defines sys_nerr/sys_errlist

AC_MSG_CHECKING([sys_nerr])
AC_TRY_LINK([
#include <stdio.h>
#include <errno.h>],[
int i = sys_nerr;
], [ax_cv_have_sys_nerr=yes], [ax_cv_have_sys_nerr=no])
AC_MSG_RESULT([$ax_cv_have_sys_nerr])
if test "$ax_cv_have_sys_nerr" = yes; then
  AC_DEFINE(HAVE_SYS_NERR, 1, [sys_nerr is defined])
fi

###### Checks for system services.
# empty for now

######
###### miscellaneous
######

###
### config.h template
###

AH_TOP([
#ifndef GFARM_CONFIG_H
#define GFARM_CONFIG_H
])

AH_BOTTOM([
/* Grid Security Infrastructure exists */
#undef HAVE_GSI

/* 5 arguments getpwnam_r() which is compatible with SUSv2 exists */
#undef HAVE_GETPWNAM_R

/* 5 arguments getspnam_r() exists */
#undef HAVE_GETSPNAM_R

/* sys_nerr is defined */
#undef HAVE_SYS_NERR

/* 3rd argument type of bind(2)/connect(2), if <sys/socket.h> doesn't define */
#undef socklen_t

#if SIZEOF_LONG == 8
	typedef long gfarm_int64_t;
	typedef unsigned long gfarm_uint64_t;
#	define GFARM_INT64_MAX		0x7fffffffffffffffL
#	define GFARM_PRId64 "ld"
#	define gfarm_strtoi64(s, endptr)	strtol(s, endptr, 0)
#elif SIZEOF_LONG_LONG == 8
	typedef long long gfarm_int64_t;
	typedef unsigned long long gfarm_uint64_t;
#	define GFARM_INT64_MAX		0x7fffffffffffffffLL
#	define GFARM_PRId64 "lld"
#	define gfarm_strtoi64(s, endptr)	strtoll(s, endptr, 0)
#else
	error! cannot find 64bit integer type
#endif

#endif /* GFARM_CONFIG_H */
])

###
### lib/gfs_hook
###

# need to make system dependent source?

gfs_hook_sysdep=lib/gfs_hook/sysdep/${host_os_nickname}
if test -f ${srcdir}/${gfs_hook_sysdep}/Makefile; then
	AC_MSG_RESULT([using ${gfs_hook_sysdep} directory for system dependent objects.])
	gfs_hook_sysdep_subdir=${host_os_nickname}
else
	gfs_hook_sysdep_subdir=default
fi

AC_SUBST(gfs_hook_sysdep_subdir)

###
### gftool/config-gfarm
###

config_gfarm_sysdep=gftool/config-gfarm/sysdep/${host_os_nickname}
if test -f ${srcdir}/${config_gfarm_sysdep}/Makefile; then
	AC_MSG_RESULT([using ${config_gfarm_sysdep} directory for system dependent part of config-gfarm.])
	config_gfarm_sysdep_subdir=${host_os_nickname}
else
	config_gfarm_sysdep_subdir=default
fi

AC_SUBST(config_gfarm_sysdep_subdir)

###
### --enable-voms
###
AC_ARG_ENABLE(voms,
AS_HELP_STRING([--enable-voms],[Enable voms collaboration.[[default=yes]]]),
[if test "${enable_voms}" = "yes"; then
  AC_CHECK_PROG(PYTHON_SPECIFIED, python, yes, no)
  gfvoms_sync_targets=''
  AC_MSG_CHECKING(voms-collaboration available)
  voms_available="no"
  if test "${PYTHON_SPECIFIED}" = "yes" ;then
    py_ver=`python -V 2>&1 | sed -e 's/Python \([[0-9\.]]*\).*/\1/'`
    case $py_ver in
      2.[[3456]].*)
        imp_path=`python -c "import sys; print sys.path" | sed -e 's/^\[[\(.*\)\]]$/\1/' | sed -e "s/[[,']]//g"`
        found=0
        for d in $imp_path
        do
          if test -d $d/ZSI ; then
            found=1
            break 1
          fi
        done
        if test $found -eq 0 ; then
          break 1
        fi
        found=0
        for d in $imp_path
        do
          if test -d $d/_xmlplus ; then
            found=1
            break 1
          fi
        done
        if test $found -eq 0 ; then
          break 1
        fi
        imp_test=`python -c "import ZSI" 2>&1`
        if test ${#imp_test} == 0; then
          gfvoms_sync_targets='${GFVOMS_SYNC_TARGETS}'
          voms_available="yes"
        fi
        ;;
    esac
  fi
  AC_MSG_RESULT(${voms_available})
else
  gfvoms_sync_targets=''
fi
],
[gfvoms_sync_targets=''
])
AC_SUBST(gfvoms_sync_targets)

###
###  --enable-xmlattr		support XML extended attributs and searching by XPath
###

AC_ARG_ENABLE(xmlattr,
AS_HELP_STRING([--enable-xmlattr],[support XML extended attributs and searching by XPath.[[default=yes]]]),
[if test "${enable_xmlattr}" = "yes"; then
	AC_DEFINE(ENABLE_XMLATTR, 1, [support XML extended attributs and searching by XPath])
fi],[])

###
### ns
###

if test -d ${srcdir}/ns; then
	ns_makefiles='
		ns/nslib/Makefile
		ns/gfarmd/Makefile
		ns/nstool/file/Makefile'

	# The following is for --srcdir option.
	# AC_OUTPUT() assumes that parent directory of the Makefile exists
	test -d ns || mkdir ns
	test -d ns/nstool || mkdir ns/nstool
fi

###
### --with-private-srcdir
###

private_srcdir=''
AC_MSG_CHECKING([use of private source directory])
AC_ARG_WITH(private_srcdir,
[  --with-private-srcdir=DIR	private source directory
],
[private_srcdir="${withval}"
],
[private_srcdir=""
])

top_private_dir=''
if test "x${private_srcdir}" = "x"; then
  AC_MSG_RESULT([not use.])
else
  if test -d "${private_srcdir}"; then
    top_private_dir="`(cd ${private_srcdir}; /bin/pwd)`"
    AC_MSG_RESULT([use ${top_private_dir}])
  else
    AC_MSG_RESULT([${private_srcdir} is not a directory.])
    exit 1
  fi
fi

AC_SUBST(top_private_dir)

if test "x${top_private_dir}" = "x"; then
    # use public source directory.
    optional_config=/dev/null
    optional_rule='${PUBLIC_RULE}'
    optional_srcs='${PUBLIC_SRCS}'
    optional_objs='${PUBLIC_OBJS}'
    optional_cflags='${PUBLIC_CFLAGS}'
    optional_targets='${PUBLIC_TARGETS}'
else
    # use private source directory.
    optional_config='${top_private_dir}/private_config.mk'
    optional_rule='${PRIVATE_RULE}'
    optional_srcs='${PRIVATE_SRCS}'
    optional_objs='${PRIVATE_OBJS}'
    optional_cflags='${PRIVATE_CFLAGS}'
    optional_targets='${PRIVATE_TARGETS}'
fi

AC_SUBST(optional_config)
AC_SUBST(optional_rule)
AC_SUBST(optional_srcs)
AC_SUBST(optional_objs)
AC_SUBST(optional_cflags)
AC_SUBST(optional_targets)

##
## private sources macros end here.
##

# The following is for --srcdir option.
# AC_OUTPUT() assumes that parent directory of the Makefile exists
test -d include || mkdir include
test -d gfptool || mkdir gfptool
test -d package || mkdir package
test -d util || mkdir util

AC_CONFIG_FILES(Makefile makes/config.mk makes/install-doc
	${ns_makefiles}
	gftool/config-gfarm/config-gfarm gftool/config-gfarm/config-gfsd
	gftool/config-gfarm/config-gfarm-update gftool/gfdump/gfdump.postgresql
	package/solaris/gfmd package/solaris/gfsd
)
AC_OUTPUT