summaryrefslogtreecommitdiff
path: root/configure.ac
blob: 4cea0a4a308ca9b0314010884dfd5f0d0ed8ff06 (plain)
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

echo "
****************************************************************************
*                                                                          *
*                   *** WARNING WARNING WARNING ***                        *
*                                                                          *
* This is source code from the development branch of rpm-4.4.2.            *
*                                                                          *
* If you want the "production" rpm-4.3.3 code, then you should use a       *
* rpm-4.3.3 src.rpm. Alternatively, if using a CVS checkout, do            *
* the following:                                                           *
*                                                                          *
*       cvs -d :pserver:anonymous@cvs.rpm.org:/cvs/devel login             *
*       (no password, just carriage return)                                *
*       cvs -d :pserver:anonymous@cvs.rpm.org:/cvs/devel get rpm           *
*       cd rpm                                                             *
*                                                                          *
* Here's the rpm-4_3 branch, latest is rpm-4.3.3:                          *
*       cvs up -r rpm-4_3                                                  *
*                                                                          *
* Here's the rpm-4_2 branch, latest is rpm-4.2.3:                          *
*       cvs up -r rpm-4_2                                                  *
*                                                                          *
****************************************************************************
"
sleep 10

AC_PREREQ(2.59)
AC_INIT(rpm, 4.4.2, rpm-devel@lists.dulug.duke.edu)
AC_CANONICAL_TARGET
AC_CONFIG_SRCDIR([rpmqv.c])
AM_CONFIG_HEADER([config.h])

AM_INIT_AUTOMAKE([foreign])

dnl Set of available languages.
ALL_LINGUAS="cs da de fi fr gl is ja ko no pl pt pt_BR ro ru sk sl sr sv tr"

dnl Checks for programs.
AC_PROG_CXX
AC_PROG_AWK
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_RANLIB
AC_PROG_YACC

AC_AIX
AC_MINIX
AS=${AS-as}
AC_SUBST(AS)
if test "$ac_cv_c_compiler_gnu" = yes; then
    CFLAGS="$CFLAGS -fPIC -DPIC -D_GNU_SOURCE -D_REENTRANT -Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wno-char-subscripts"
fi
export CFLAGS

AC_PROG_GCC_TRADITIONAL
AC_SYS_LARGEFILE

dnl Does this platform require array notation to assign to a va_list?
dnl If cross-compiling, we assume va_list is "normal".  If this breaks
dnl you, set ac_cv_valistisarray=true and maybe define HAVE_VA_LIST_AS_ARRAY
dnl also just to be sure.
AC_MSG_CHECKING(whether va_list assignments need array notation)
AC_CACHE_VAL(ac_cv_valistisarray,
	[AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdlib.h>
		     #include <stdarg.h>
		     void foo(int i, ...) {
			va_list ap1, ap2;
			va_start(ap1, i);
			ap2 = ap1;
			if (va_arg(ap2, int) != 123 || va_arg(ap1, int) != 123)
			    { exit(1); }
			va_end(ap1); va_end(ap2);
		     }
		     int main() { foo(0, 123); return(0); }]])],[ac_cv_valistisarray=false],[ac_cv_valistisarray=true],[ac_cv_valistisarray=false])])

if test "$ac_cv_valistisarray" = true ; then
	AC_DEFINE(HAVE_VA_LIST_AS_ARRAY, 1,
		[Define as 1 if your va_list type is an array])
	AC_MSG_RESULT(yes)
else
       AC_MSG_RESULT(no)
fi

RPMUSER=rpm
RPMUID=37
RPMGROUP=rpm
RPMGID=37
export RPMUSER RPMUID RPMGROUP RPMGID
AC_SUBST(RPMUSER)
AC_SUBST(RPMUID)
AC_SUBST(RPMGROUP)
AC_SUBST(RPMGID)

AC_PATH_PROG(CTAGS, ctags, /bin/true)
AC_PATH_PROG(CSCOPE, cscope, /bin/true)

dnl
dnl This now uses libtool. Put
dnl	LDFLAGS_STATIC="-all"
dnl to attempt static executables using libtool. Otherwise
dnl	LDFLAGS_STATIC=""
dnl
with_selinuxval=no
AC_MSG_CHECKING(flag used by libtool to link rpm)
if test X"$GCC" = Xyes ; then
	case "$target" in
		*-*-linux*)	LDFLAGS_STATIC="-all-static"
				with_selinuxval=yes ;;
		*-*-solaris*)	LDFLAGS_STATIC="-static";;
		*-*-hpux*)	LDFLAGS_STATIC="-static";;
		*-*-darwin*)	LDFLAGS_STATIC="";; # Mac OS X does not do static binaries.
		*-*-sysv5uw*)   LDFLAGS_STATUS="-static";; # Unixware has no shared libthread.
		*-*-*)		LDFLAGS_STATIC="";;
	esac
elif test X"$CC" = Xcc ; then
	case "$target" in
		*-*-linux*)	LDFLAGS_STATIC="-all-static";;
		*-*-freebsd*)	LDFLAGS_STATIC="-all-static";;
		*-*-osf*)	LDFLAGS_STATIC="";; # OSF5 has no shared pthreads libs
		*-*-aix*)	LDFLAGS_STATIC="-static";;  # -Wl,-bnso doesn't seem to work...
		*-*-hpux*)	LDFLAGS_STATIC="-static";;
		*-*-solaris*)	LDFLAGS_STATIC="-static";;
		*-*-irix*)	LDFLAGS_STATIC="-static";;  #should be -non_shared, but can't
											# link because of crt1.o then.
		*-*-ultrix*)	LDFLAGS_STATIC="-all-static";;  #ultrix doesn't have shared libs.
		*-*-*)		LDFLAGS_STATIC=""
AC_MSG_WARN([

Unable to guess what option to pass to $CC to generate a static
executable.  You will need to set the LDFLAGS_STATIC macro in Makefile.inc to
the appropriate argument(s) if you want to build a static rpm executable.

])
		;;
	esac
else
	# just link it dynamically
	LDFLAGS_STATIC=""
fi
LDFLAGS_STATIC="${LDFLAGS} ${LDFLAGS_STATIC}"	# libtool format
AC_MSG_RESULT($LDFLAGS_STATIC)
AC_SUBST(LDFLAGS_STATIC)

dnl
dnl XXX Test for libpthread.a that is NPTL aware (static link only).
dnl
LDFLAGS_NPTL=
if test -f /usr/lib/nptl/libpthread.a ; then
    LDFLAGS_NPTL="-L/usr/lib/nptl"
#    INCPATH="$INCPATH -I/usr/include/nptl"
fi
AC_SUBST(LDFLAGS_NPTL)

dnl
dnl look for POSIX chmod attributes
dnl
AC_MSG_CHECKING(POSIX chmod)
touch foo.chmodtest
chmod 744 foo.chmodtest
chmod +X foo.chmodtest 2>/dev/null
a=`ls -l foo.chmodtest | awk '{print $1}'`
rm -f foo.chmodtest
if test "$a" = "-rwxr-xr-x"; then
    AC_MSG_RESULT(yes)
    FIXPERMS=a+rX,u+w,g-w,o-w 
else
    AC_MSG_RESULT(no (tell your OS vendor about GNU fileutils))
    FIXPERMS=a+r,u+w,g-w,o-w 
fi
AC_SUBST(FIXPERMS)

dnl
dnl see if we have a mkdir that supports `-p'.
dnl
AC_PATH_PROGS(MKDIR, mkdir, mkdir)
AC_MSG_CHECKING(if $MKDIR supports -p)
rm -rf conftest
$MKDIR -p conftest/a 2>/dev/null
if test $? = 0 ; then
	rmdir conftest/a 2>/dev/null
	if test $? = 0  ; then
		:
	else
		MKDIR_P=0
	fi

	rmdir conftest 2>/dev/null
	if test $? = 0 ; then
		MKDIR_P="$MKDIR -p"
	else
		MKDIR_P=0
	fi
else
	MKDIR_P=0
fi

if test X"$MKDIR_P" = X0 ; then
	AC_MSG_RESULT(no)
	MKDIR_P="`echo ${prefix}/lib/rpm/mkinstalldirs`"
else
	AC_MSG_RESULT(yes)
fi
dnl
dnl substitute this into config.h, so the C source picks it up.
dnl
AC_DEFINE_UNQUOTED(MKDIR_P, "${MKDIR_P}",
[A full path to a program, possibly with arguments, that will create a
   directory and all necessary parent directories, ala 'mkdir -p'])
AC_SUBST(MKDIR_P)

AC_ISC_POSIX

dnl This test must precede tests of compiler characteristics like
dnl that for the inline keyword, since it may change the degree to
dnl which the compiler supports such features.
AM_C_PROTOTYPES

dnl AM_DISABLE_SHARED
AM_PROG_LIBTOOL

AC_CHECK_TOOL(AR, ar, :)

dnl
dnl use defaults if cross-compiling, otherwise use the default path.
dnl
if test "$cross_compiling" = "yes"; then
    MYPATH=":"
else
#    MYPATH="/bin:/usr/bin:/usr/local/bin:$PATH:/sbin:/usr/sbin:/usr/local/sbin:/opt/gnu/bin"
    MYPATH=$PATH
fi

dnl
dnl Find some common programs
dnl
AC_PATH_PROG(BZIP2BIN, bzip2, /usr/bin/bzip2, $MYPATH)
AC_PATH_PROG(__CAT, cat, /bin/cat, $MYPATH)
AC_PATH_PROG(__CHGRP, chgrp, /bin/chgrp, $MYPATH)
AC_PATH_PROG(__CHMOD, chmod, /bin/chmod, $MYPATH)
AC_PATH_PROG(__CHOWN, chown, /bin/chown, $MYPATH)
AC_PATH_PROG(__CP, cp, /bin/cp, $MYPATH)
AC_PATH_PROG(__CPIO, cpio, /bin/cpio, $MYPATH)
AC_PATH_PROG(__FILE, file, /usr/bin/file, $MYPATH)
AC_PATH_PROG(__GPG, gpg, /usr/bin/gpg, $MYPATH)
AC_PATH_PROG(__GREP, grep, /bin/grep, $MYPATH)
AC_PATH_PROG(GZIPBIN, gzip, /bin/gzip, $MYPATH)
AC_PATH_PROG(UNZIPBIN, unzip, /usr/bin/unzip, $MYPATH)

AC_PATH_PROG(__ID, id, /usr/bin/id, $MYPATH)
AC_MSG_CHECKING(checking whether id supports -u)
    if ${__ID} -u 2>&1 > /dev/null ; then
	__ID_U="%{__id} -u"
	AC_MSG_RESULT(yes)
    else
dnl XXX Watchout for square brackets fed to m4.
	__ID_U="%{__id} | %{__sed} 's/[[^=]]*=\\\\([[0-9]][[0-9]]*\\\\).*$/\\\\1/'"
	AC_MSG_RESULT(no)
    fi
AC_SUBST(__ID_U)

AC_PATH_PROG(__INSTALL, install, /usr/bin/install, $MYPATH)
AC_PATH_PROG(__MAKE, make, /usr/bin/make, $MYPATH)
AC_PATH_PROG(__MKDIR, mkdir, /bin/mkdir, $MYPATH)
AC_PATH_PROG(__MV, mv, /bin/mv, $MYPATH)
AC_PATH_PROG(__PATCH, patch, /usr/bin/patch, $MYPATH)
AC_MSG_CHECKING(old version of patch)
    PATCHVERSION=`patch --version 2>&1`

    if test "$PATCHVERSION" = "Patch version 2.1"; then
	AC_DEFINE(HAVE_OLDPATCH_21, 1,
		[Define if the patch call you'll be using is 2.1 or older])
	AC_MSG_RESULT(patch older then 2.2 found)
    else
	AC_MSG_RESULT(patch later then 2.2 found)
    fi

AC_PATH_PROG(__PERL, perl, /usr/bin/perl, $MYPATH)
AC_PATH_PROG(PGPBIN, pgp, /usr/bin/pgp, $MYPATH)
AC_PATH_PROG(__PYTHON, python, /usr/bin/python, $MYPATH)
AC_PATH_PROG(__RM, rm, /bin/rm, $MYPATH)
AC_PATH_PROG(__RSH, rsh, /usr/bin/rsh, $MYPATH)
AC_PATH_PROG(__SED, sed, /bin/sed, $MYPATH)
AC_PATH_PROG(__SSH, ssh, /usr/bin/ssh, $MYPATH)
AC_PATH_PROG(__TAR, tar, /bin/tar, $MYPATH)

AC_PATH_PROG(__LD, ld, /usr/bin/ld, $MYPATH)
AC_PATH_PROG(__NM, nm, /usr/bin/nm, $MYPATH)
AC_PATH_PROG(__OBJCOPY, objcopy, /usr/bin/objcopy, $MYPATH)
AC_PATH_PROG(__OBJDUMP, objdump, /usr/bin/objdump, $MYPATH)
AC_PATH_PROG(__STRIP, strip, /usr/bin/strip, $MYPATH)

addlib() {
  l=$1
  shift
  case "$target" in 
    *-*-solaris*)	LIBS="$LIBS -L$l -R$l $*";;
    *)		LIBS="$LIBS -L$l $*";;
  esac
}

#=================
# Check for zlib library. Prefer internal, otherwise external.

WITH_ZLIB_SUBDIR=
WITH_ZLIB_INCLUDE=
WITH_ZLIB_LIB=
if test -d zlib ; then
  WITH_ZLIB_SUBDIR=zlib
  addlib \${top_builddir}/zlib
  WITH_ZLIB_INCLUDE="-I\${top_srcdir}/${WITH_ZLIB_SUBDIR}"
  INCPATH="$INCPATH -I\${top_srcdir}/${WITH_ZLIB_SUBDIR}"
  WITH_ZLIB_LIB="\${top_builddir}/${WITH_ZLIB_SUBDIR}/libz.la"
  AC_DEFINE(HAVE_GZSEEK, 1, [Define as 1 if your zlib has gzseek()])
fi
AC_SUBST(WITH_ZLIB_SUBDIR)
AC_SUBST(WITH_ZLIB_INCLUDE)
AC_SUBST(WITH_ZLIB_LIB)

if test -z "${WITH_ZLIB_LIB}" ; then
  for zlib in z gz ; do
   AC_CHECK_LIB(${zlib}, gzread, 
	[LIBS="$LIBS -l${zlib}"; break], 
	[if test ${zlib} = gz; then 
	    AC_MSG_ERROR([sorry rpm requires libz.a or libgz.a (from the zlib package)]) 
	 fi]
	       )
  done

dnl zlib-1.0.4 has not gzseek
  AC_CHECK_LIB(${zlib}, gzseek, [AC_DEFINE(HAVE_GZSEEK, 1, [Define as 1 if your zlib has gzseek()])])
fi

#=================
# Check for bzip2 library. Prefer external, otherwise none.

AC_CHECK_LIB(bz2, bzread, [LIBS="$LIBS -lbz2"], 
   AC_CHECK_LIB(bz2, BZ2_bzread, [
     WITH_BZIP2=1
     LIBS="$LIBS -lbz2"
     AC_DEFINE(HAVE_BZ2_1_0, 1, [Define as 1 if you bzip2 1.0]) ], 
     WITH_BZIP2=0))
AC_SUBST(WITH_BZIP2)

#=================

localdone=

dirs=$prefix
if test "$cross_compiling" != "yes"; then
  dirs="$dirs /usr/local"
fi
for dir in $dirs
do
	case $dir in
	NONE|/usr)	continue;;
	/usr/local)
		if test X$localdone != X ; then continue; fi
		localdone="$dir"
		;;
	esac

	AC_MSG_CHECKING(for $dir/lib in LIBS)
	if test -d $dir/lib 2> /dev/null ; then
		addlib $dir/lib
		AC_MSG_RESULT(yes)
	else
		AC_MSG_RESULT(no)
	fi

	AC_MSG_CHECKING(for $dir/include in INCPATH)
	if test -d $dir/include 2>/dev/null ; then
		if [[ "$dir" != "/usr/local" ]] ; then
		    INCPATH="$INCPATH -I$dir/include"
		fi
		AC_MSG_RESULT(yes)
	else
		AC_MSG_RESULT(no)
	fi
done

AC_MSG_CHECKING(for /usr/ucblib in LIBS)
if test -d /usr/ucblib ; then
	if test "$build" = "mips-sni-sysv4" ; then
		addlib /usr/ccs/lib -lc
	fi

	addlib /usr/ucblib
	
	AC_MSG_RESULT(yes)
else
	AC_MSG_RESULT(no)
fi

dnl
dnl Check for features
dnl

dnl Checks for libraries.

AC_CHECK_FUNC(setreuid, [], [
    AC_CHECK_LIB(ucb, setreuid, [if echo $LIBS | grep -- -lucb >/dev/null ;then :; else LIBS="$LIBS -lc -lucb" USEUCB=y;fi])
])

AC_CHECK_FUNC(rand, [], [
    AC_CHECK_LIB(rand, rand, [])
])

AC_CHECK_FUNC(getdomainname, [], [
    AC_CHECK_LIB(nsl, getdomainname)
])
AC_CHECK_FUNC(socket, [], [
    AC_CHECK_LIB(socket, socket)
])

AC_CHECK_HEADERS(error.h)
AC_CHECK_FUNCS(error)

AC_CHECK_HEADERS(poll.h)

AC_CHECK_HEADERS(thread.h pthread.h synch.h semaphore.h)

AC_CHECK_LIB(pthread, pthread_mutex_trylock, [], [
  dnl OSF 5.0 has the the symbols prefixed with __ in libpthread.
  AC_CHECK_LIB(pthread, __pthread_mutex_trylock, [], [
    AC_CHECK_LIB(thread, mutex_lock)
  ])
])

AC_CHECK_HEADERS(aio.h)
AC_SEARCH_LIBS(aio_read, [c rt aio posix4])

dnl Better not use fchmod at all.
AC_CHECK_FUNC(fchmod)

AC_CHECK_FUNCS(vsnprintf snprintf)

dnl Temporary hack for MiNT.  Some functions (writev, snprintf) are
dnl not in the libc but in libport (for political reasons).  This check
dnl can hopefully be removed soon.  Please use the default action
dnl for this macro (not LIBS=...), otherwise the check for dbopen
dnl will fail.
AC_CHECK_LIB(port, writev)

#=================
# Check for libelf library. Prefer external, then internal, otherwise none.
WITH_ELFUTILS_SUBDIR=
WITH_LIBELF_INCLUDE=
WITH_LIBELF_LIB=
AC_CHECK_HEADER([libelf.h])
AC_CHECK_HEADER([gelf.h], [
	AC_DEFINE(HAVE_GELF_H, 1, [Define to 1 if you have the <gelf.h> header file.])
	AC_CHECK_LIB(elf, gelf_getvernaux, [
	    AC_DEFINE(HAVE_LIBELF, 1, [Define to 1 if you have the 'elf' library (-lelf).])
	    WITH_LIBELF_LIB="-lelf"
	])
    ], [
	if test -d elfutils/libelf ; then
	    AC_DEFINE(HAVE_GELF_H, 1, [Define to 1 if you have the <gelf.h> header file.])
	    AC_DEFINE(HAVE_LIBELF, 1, [Define to 1 if you have the 'elf' library (-lelf).])
	    WITH_ELFUTILS_SUBDIR=elfutils
	    WITH_LIBELF_INCLUDE="-I\${top_srcdir}/${WITH_ELFUTILS_SUBDIR}/libelf"
	    WITH_LIBELF_LIB="\${top_builddir}/${WITH_ELFUTILS_SUBDIR}/libelf/libelf.a"
	fi
])
AC_SUBST(WITH_ELFUTILS_SUBDIR)
AC_SUBST(WITH_LIBELF_INCLUDE)
AC_SUBST(WITH_LIBELF_LIB)

WITH_LIBDWARF_INCLUDE=
WITH_LIBDWARF_DEBUGEDIT=
AC_CHECK_HEADER([dwarf.h], [
  AC_DEFINE(HAVE_DWARF_H, 1, [Define to 1 if you have the <dwarf.h> header file.])
  WITH_LIBDWARF_DEBUGEDIT="debugedit"
],[
  if test -d elfutils/libdwarf ; then
    AC_DEFINE(HAVE_DWARF_H, 1, [Define to 1 if you have the <dwarf.h> header file.])
    WITH_LIBDWARF_INCLUDE="-I\${top_srcdir}/${WITH_ELFUTILS_SUBDIR}/libdwarf"
    WITH_LIBDWARF_DEBUGEDIT="debugedit"
  fi
])
AC_SUBST(WITH_LIBDWARF_INCLUDE)
AC_SUBST(WITH_LIBDWARF_DEBUGEDIT)

#=================
# Check for beecrypt library. Prefer external, otherwise internal.
WITH_BEECRYPT_SUBDIR=
WITH_BEECRYPT_INCLUDE=
WITH_BEECRYPT_LIB=
AC_CHECK_HEADER([beecrypt/beecrypt.h], [
  AC_CHECK_LIB(beecrypt, mpfprintln, [
    AC_DEFINE(HAVE_LIBBEECRYPT, 1, [Define to 1 if you have the 'beecrypt' library (-lbeecrypt).])
    AC_CHECK_HEADER([beecrypt/api.h], [
      AC_DEFINE(HAVE_BEECRYPT_API_H, 1, [Define to 1 if you have the <beecrypt/api.h> header file.])
    ])
    WITH_BEECRYPT_INCLUDE="-I${includedir}/beecrypt"
    WITH_BEECRYPT_LIB="-lbeecrypt"
  ])
],[
  if test -d beecrypt ; then
    AC_DEFINE(HAVE_LIBBEECRYPT, 1, [Define to 1 if you have the 'beecrypt' library (-lbeecrypt).])
    WITH_BEECRYPT_SUBDIR=beecrypt
    WITH_BEECRYPT_INCLUDE="-I\${top_srcdir}/${WITH_BEECRYPT_SUBDIR}"
    WITH_BEECRYPT_LIB="\${top_builddir}/${WITH_BEECRYPT_SUBDIR}/libbeecrypt.la"
  fi
])
AC_SUBST(WITH_BEECRYPT_SUBDIR)
AC_SUBST(WITH_BEECRYPT_INCLUDE)
AC_SUBST(WITH_BEECRYPT_LIB)

#=================
# Check for neon library. Prefer external, otherwise internal.
WITH_NEON_SUBDIR=
WITH_NEON_INCLUDE=
WITH_NEON_LIB=
AC_CHECK_HEADER([neon/ne_session.h], [
  AC_CHECK_LIB(neon, ne_session_create, [
    AC_DEFINE(HAVE_LIBNEON, 1, [Define to 1 if you have the 'neon' library (-lneon).])
    AC_CHECK_LIB(neon, ne_get_response_header, [
      AC_DEFINE(HAVE_NEON_NE_GET_RESPONSE_HEADER, 1, [Define to 1 if you have ne_get_response_header() in libneon.])
    ])
    AC_CHECK_LIB(neon, ne_send_request_chunk, [
	AC_DEFINE(HAVE_NEON_NE_SEND_REQUEST_CHUNK, 1, [Define to 1 if you have ne_send_request_chunk() in libneon.])
    ])
    WITH_NEON_INCLUDE="-I${includedir}/neon"
    WITH_NEON_LIB="-lneon"
  ])
],[
  if test -d neon ; then
    AC_DEFINE(HAVE_LIBNEON, 1, [Define to 1 if you have the 'neon' library (-lneon).])
# XXX HAVE_NEON_NE_GET_RESPONSE_HEADER assumes libneon-0.25 devel internal
    AC_DEFINE(HAVE_NEON_NE_GET_RESPONSE_HEADER, 1, [Define to 1 if you have ne_get_response_header() in libneon.])
    WITH_NEON_SUBDIR=neon
    WITH_NEON_INCLUDE="-I\${top_srcdir}/${WITH_NEON_SUBDIR}/src"
    WITH_NEON_LIB="\${top_builddir}/${WITH_NEON_SUBDIR}/src/libneon.la"
  fi
])
AC_SUBST(WITH_NEON_SUBDIR)
AC_SUBST(WITH_NEON_INCLUDE)
AC_SUBST(WITH_NEON_LIB)

#=================
# Check for magic library. Prefer internal, otherwise external.
WITH_MAGIC_SUBDIR=
WITH_MAGIC_INCLUDE=
WITH_MAGIC_LIB=

if test -d file ; then
  WITH_RPMFILE=rpmfile
  WITH_MAGIC_SUBDIR=file
  WITH_MAGIC_INCLUDE="-I\${top_srcdir}/${WITH_MAGIC_SUBDIR}/src"
  WITH_MAGIC_LIB="\${top_builddir}/${WITH_MAGIC_SUBDIR}/src/libmagic.la"
else
  WITH_RPMFILE=
  AC_CHECK_HEADER([magic.h], [
    AC_CHECK_LIB(magic, magic_open, [
      WITH_MAGIC_SUBDIR=
      WITH_MAGIC_INCLUDE=
      WITH_MAGIC_LIB="-lmagic"
    ])
  ])
fi

AC_SUBST(WITH_RPMFILE)
AC_SUBST(WITH_MAGIC_SUBDIR)
AC_SUBST(WITH_MAGIC_INCLUDE)
AC_SUBST(WITH_MAGIC_LIB)

#=================
# Check for popt library. Prefer internal, otherwise external.
WITH_POPT_SUBDIR=
WITH_POPT_INCLUDE=
WITH_POPT_LIB=

if test -d popt ; then
  WITH_POPT_SUBDIR=popt
  WITH_POPT_INCLUDE="-I\${top_srcdir}/${WITH_POPT_SUBDIR}"
  WITH_POPT_LIB="\${top_builddir}/${WITH_POPT_SUBDIR}/libpopt.la"
else
  AC_CHECK_HEADER([popt.h], [
    AC_CHECK_LIB(popt, poptGetContext, [
      WITH_POPT_SUBDIR=
      WITH_POPT_INCLUDE=
      WITH_POPT_LIB="-lpopt"
    ])
  ])
fi

AC_SUBST(WITH_POPT_SUBDIR)
AC_SUBST(WITH_POPT_INCLUDE)
AC_SUBST(WITH_POPT_LIB)

#=================

dnl ------------------ with    internal db
AC_DEFINE(HAVE_DB3_DB_H, 1, [Define if you have the <db3/db.h> header file])
WITH_DB_SUBDIR=db3
WITH_INTERNAL_DB=1
DBLIBSRCS="db3.c"

AC_SUBST(WITH_DB_SUBDIR)
AC_SUBST(WITH_INTERNAL_DB)

#=================
# Check for sqlite3 library. Prefer external, then internal, otherwise none.
WITH_SQLITE3_SUBDIR=
WITH_SQLITE3_INCLUDE=
WITH_SQLITE3_LIB=

AC_CHECK_HEADER([sqlite3.h], [
  AC_CHECK_LIB(sqlite3, sqlite3_open, [
    AC_DEFINE(HAVE_SQLITE3_H, 1, [Define if you have the <sqlite3.h> header file])
    WITH_SQLITE3_SUBDIR=
    WITH_SQLITE3_INCLUDE=
    WITH_SQLITE3_LIB="-lsqlite3"
    DBLIBSRCS="$DBLIBSRCS sqlite.c"
  ])
],[
  if test -d sqlite ; then
    AC_DEFINE(HAVE_SQLITE3_H, 1, [Define if you have the <sqlite3.h> header file])
    WITH_SQLITE3_SUBDIR=sqlite
    WITH_SQLITE3_INCLUDE="-I\${top_srcdir}/${WITH_SQLITE3_SUBDIR}/src"
    WITH_SQLITE3_LIB="\${top_builddir}/${WITH_SQLITE3_SUBDIR}/libsqlite3.la"
    DBLIBSRCS="$DBLIBSRCS sqlite.c"
  fi
])

AC_SUBST(WITH_SQLITE3_SUBDIR)
AC_SUBST(WITH_SQLITE3_INCLUDE)
AC_SUBST(WITH_SQLITE3_LIB)

#=================

DBLIBOBJS=`echo $DBLIBSRCS | sed -e "s/\.c/\.lo/g"`

AC_SUBST(DBLIBSRCS)
AC_SUBST(DBLIBOBJS)

dnl AmigaOS and IXEmul have a fork() dummy
  case "$target" in
    m68k-*-amigaos ) 
	echo "Building for AmigaOS: using vfork() instead of fork()"; 
	CFLAGS="$CFLAGS -Dfork=vfork" 
	;;
  esac

AM_GNU_GETTEXT
dnl TVM:
dnl horrible *temporary* hack to make sure that if we found gettext() in
dnl -lintl that we add -lintl *back* to $LIBS.
dnl
dnl if test X$gt_cv_func_gettext_libintl = Xyes ; then
dnl     LIBS="-lintl $LIBS"
dnl fi

dnl Checks for header files we can live without.
AC_HEADER_STDC
AC_HEADER_MAJOR
AC_HEADER_DIRENT
AC_HEADER_TIME

AC_CHECK_HEADERS(fcntl.h getopt.h grp.h memory.h netdb.h pwd.h utime.h)

AC_CHECK_HEADERS(sys/ipc.h sys/socket.h sys/select.h)
AC_CHECK_HEADERS(sys/types.h sys/stdtypes.h)
AC_CHECK_HEADERS(sys/mman.h sys/resource.h sys/utsname.h sys/wait.h)

AC_CHECK_HEADERS(netinet/in_systm.h)
AC_CHECK_HEADERS(machine/types.h)
AC_CHECK_HEADERS(mntent.h sys/mnttab.h sys/systemcfg.h)
AC_CHECK_HEADERS(sys/mount.h sys/mntctl.h sys/param.h sys/vmount.h)
AC_CHECK_HEADERS(bzlib.h libio.h zlib.h)
AC_CHECK_HEADERS(err.h mcheck.h)
AC_CHECK_HEADERS(pthread.h)

dnl popt w float/double needs.
AC_CHECK_HEADERS(float.h)

AC_CHECK_HEADERS(glob.h)

dnl statfs portability fiddles.
dnl
dnl We should really emulate/steal sections of the statfs and struct statfs
dnl checks from GNU fileutils.
dnl
AC_MSG_CHECKING(for struct statfs)

dnl
dnl this is easier than nesting AC_TRY_COMPILEs...
dnl
found_struct_statfs=no

if test X$found_struct_statfs = Xno ; then
dnl Solaris 2.6+ wants to use statvfs
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#include <sys/statvfs.h> ]], [[struct statvfs sfs;]])],[AC_MSG_RESULT(in sys/statvfs.h)
	AC_DEFINE(STATFS_IN_SYS_STATVFS, 1,
		[statfs in <sys/statvfs.h> (for solaris 2.6+ systems)])
	found_struct_statfs=yes],[])
fi

if test X$found_struct_statfs = Xno ; then
dnl first try including sys/vfs.h
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#include <sys/vfs.h> ]], [[struct statfs sfs;]])],[AC_MSG_RESULT(in sys/vfs.h)
	AC_DEFINE(STATFS_IN_SYS_VFS, 1, [statfs in <sys/vfs.h> (for linux systems)])
	found_struct_statfs=yes],[])
fi

if test X$found_struct_statfs = Xno ; then
dnl ...next try including sys/mount.h
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#include <sys/mount.h> ]], [[struct statfs sfs;]])],[AC_MSG_RESULT(in sys/mount.h)
	AC_DEFINE(STATFS_IN_SYS_MOUNT, 1, [statfs in <sys/mount.h> (for Digital Unix 4.0D systems)])
	found_struct_statfs=yes],[])
fi

if test X$found_struct_statfs = Xno ; then
dnl ...still no joy.  Try sys/statfs.h
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#include <sys/statfs.h> ]], [[struct statfs sfs;]])],[AC_MSG_RESULT(in sys/statfs.h)
	AC_DEFINE(STATFS_IN_SYS_STATFS, 1, [statfs in <sys/statfs.h> (for Irix 6.4 systems)])
	found_struct_statfs=yes],[])
fi

if test X$found_struct_statfs = Xno ; then
dnl ...no luck.  Warn the user of impending doom.
AC_MSG_WARN(not found)
fi

dnl
dnl if we found the struct, see if it has the f_bavail member.  Some OSes
dnl don't, including IRIX 6.5+
dnl
if test X$found_struct_statfs = Xyes ; then
AC_MSG_CHECKING(for f_bavail member in struct statfs)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if STATFS_IN_SYS_STATVFS
# include <sys/statvfs.h>
  typedef struct statvfs STATFS_t;
#else
  typedef struct statfs STATFS_t;
# if STATFS_IN_SYS_VFS
#  include <sys/vfs.h>
# elif STATFS_IN_SYS_MOUNT
#  include <sys/mouht.h>
# elif STATFS_IN_SYS_STATFS
#  include <sys/statfs.h>
# endif
#endif ]], [[STATFS_t sfs;
	sfs.f_bavail = 0;]])],[AC_MSG_RESULT(yes)
	AC_DEFINE(STATFS_HAS_F_BAVAIL, 1, [Define if struct statfs has the f_bavail member])],[AC_MSG_RESULT(no)
])
fi

if test X$found_struct_statfs = Xyes ; then
dnl
dnl now check to see if we have the 4-argument variant of statfs()
dnl this pretty much requires AC_RUN_IFELSE([AC_LANG_SOURCE([[]])],[],[],[])
dnl
AC_MSG_CHECKING([if statfs() requires 4 arguments])
AC_RUN_IFELSE([AC_LANG_SOURCE([[
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef STATFS_IN_SYS_VFS
#include <sys/vfs.h>
#elif STATFS_IN_SYS_MOUNT
#include <sys/mouht.h>
#elif STATFS_IN_SYS_STATFS
#include <sys/statfs.h>
#endif
main() {
	struct statfs sfs;
	exit (statfs(".", &sfs, sizeof(sfs), 0));
}
]])],[AC_MSG_RESULT(yes)
	AC_DEFINE(STAT_STATFS4, 1, [Define if the statfs() call takes 4 arguments])],[AC_MSG_RESULT(no)],[AC_MSG_RESULT(no)
])
fi

AC_C_INLINE

dnl look for libc features
PROVIDES_ERRNO=no
AC_MSG_CHECKING(if <netdb.h> defines h_errno)
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <netdb.h>]], [[printf("%d",h_errno)]])],[PROVIDES_ERRNO=yes],[])
AC_MSG_RESULT($PROVIDES_ERRNO)
if test $PROVIDES_ERRNO = yes; then
	AC_DEFINE(HAVE_HERRNO, 1, [ Define as 1 if <netdb.h> defines h_errno])
fi

dnl If a system doesn't have S_IFSOCK, define it as 0 which will
dnl make S_ISSOCK always return false (nice, eh?)
AC_MSG_CHECKING(if <sys/stat.h> defines S_IFSOCK)
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/stat.h>]], [[printf("%d", S_IFSOCK)]])],[HAS_S_IFSOCK=yes],[HAS_S_IFSOCK=no])
AC_MSG_RESULT($HAS_S_IFSOCK)
if test $HAS_S_IFSOCK = yes; then
	AC_DEFINE(HAVE_S_IFSOCK, 1, [Define as 1 if <sys/stat.h> defines S_IFSOCK])
fi

dnl Some Unix's are missing S_ISLNK, S_ISSOCK
AC_MSG_CHECKING(if <sys/stat.h> defines S_ISLNK)
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/stat.h>]], [[printf("%d", S_ISLNK(0755))]])],[HAS_S_ISLNK=yes],[HAS_S_ISLNK=no])
AC_MSG_RESULT($HAS_S_ISLNK)
if test $HAS_S_ISLNK = yes; then
	AC_DEFINE(HAVE_S_ISLNK, 1, [Define as 1 if <sys/stat.h> defines S_ISLNK])
fi

AC_MSG_CHECKING(if <sys/stat.h> defines S_ISSOCK)
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/stat.h>]], [[printf("%d", S_ISSOCK(0755))]])],[HAS_S_ISSOCK=yes],[HAS_S_ISSOCK=no])
AC_MSG_RESULT($HAS_S_ISSOCK)
if test $HAS_S_ISSOCK = yes; then
	AC_DEFINE(HAVE_S_ISSOCK, 1, [Define as 1 if <sys/stat.h> defines S_ISSOCK])
fi

AC_MSG_CHECKING(if timezone is defined)
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <time.h>]], [[printf("%ld", timezone)]])],[HAS_TIMEZONE=yes],[HAS_TIMEZONE=no])
AC_MSG_RESULT($HAS_TIMEZONE)

dnl Check for missing typedefs
AC_TYPE_MODE_T
AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T

dnl Checks for library functions.
AC_FUNC_ALLOCA
AC_FUNC_VPRINTF

dnl XXX AC_FUNC_MEMCMP
dnl XXX AC_FUNC_MMAP
dnl XXX AC_TYPE_SIGNAL
dnl XXX AC_FUNC_STRCOLL
dnl XXX AC_FUNC_STRFTIME
dnl XXX AC_FUNC_UTIME_NULL
dnl XXX AC_FUNC_FORK([])
dnl XXX AC_CHECK_FUNCS(gethostname mkdir mkfifo rmdir select uname)

AC_CHECK_FUNCS(basename getcwd getwd inet_aton mtrace putenv realpath setenv)
AC_CHECK_FUNCS(stpcpy stpncpy strcspn)
AC_CHECK_FUNCS(strdup strndup strerror strtol strtoul strspn strstr)

AC_CHECK_FUNCS(__secure_getenv)

AC_CHECK_FUNCS(regcomp)

AC_CHECK_FUNCS(ftok)

AC_CHECK_FUNCS(mkstemp)

dnl
dnl XXX Regex replacement isn't known to be needed yet.
dnl
dnl AC_ARG_WITH(regex, [  --with-regex            use the GNU regex library ],
dnl     [rpm_cv_regex=yes],
dnl     [AC_CHECK_FUNCS(regcomp, rpm_cv_regex=no, rpm_cv_regex=yes)])
dnl 
dnl if test $rpm_cv_regex = no ; then
dnl     AC_MSG_CHECKING(whether the regexp library is broken)
dnl     AC_RUN_IFELSE([AC_LANG_SOURCE([[
dnl #include <unistd.h>
dnl #include <regex.h>
dnl main() { regex_t blah ; exit(regcomp(&blah, "foo.*bar", REG_NOSUB) || regexec (&blah, "foobar", 0, NULL, 0)); }]])],[dnl     rpm_cv_regex_broken=no],[rpm_cv_regex_broken=yes],[rpm_cv_regex_broken=yes])
dnl     AC_MSG_RESULT([$rpm_cv_regex_broken])
dnl     if test $rpm_cv_regex_broken = yes ; then
dnl 	    echo "   --> using the included GNU regex instead." >&AS_MESSAGE_FD([])
dnl 	    rpm_cv_regex=yes
dnl     fi
dnl fi
dnl 
dnl if test $rpm_cv_regex = yes; then
dnl     AC_DEFINE(USE_GNU_REGEX, 1)
dnl     AC_LIBOBJ(regex)
dnl fi

dnl
dnl XXX Glob *is* broken on linux with libc5, solaris and possibly aix when
dnl %files gets something like
dnl	/usr/*/locale/*/LC_MESSAGES/*.mo
dnl (Note: more than one asterisk in glob pattern.)
dnl
dnl XXX Glob is "fixed" in glibc-2.3.3-61, but the cost is that
dnl dangling symlinks are no longer globbed. Always use the internal glob.
dnl
#AC_ARG_WITH(glob, [  --with-glob             use the internal GNU glob ],
#    [rpm_cv_glob=yes],
#    [AC_CHECK_FUNCS(glob, rpm_cv_glob=no, rpm_cv_glob=yes)])
#
#if test $rpm_cv_glob = no ; then
#    AC_CACHE_CHECK([for GNU extensions to glob], rpm_cv_glob_ext, [
#    rm -f t
#    mkdir t
#    mkdir t/p
#    touch t/p/foo.8
#    AC_RUN_IFELSE([AC_LANG_SOURCE([[
##include <unistd.h>
##include <sys/stat.h>
##include <glob.h>
#main() {
#  glob_t gl ;
#  gl.gl_stat = stat;
#  exit(glob("t/*/*.8", GLOB_PERIOD, NULL, &gl) || gl.gl_pathc < 1);
#} ]])],[rpm_cv_glob_ext=yes],[rpm_cv_glob_ext=no],[rpm_cv_glob_ext=no])
#    rm -r t
#    ])
#    if test "$rpm_cv_glob_ext" = no ; then
#	echo "    --> using the included GNU glob instead." >&AS_MESSAGE_FD([])
#	rpm_cv_glob=yes
#    fi
#fi
#
#if test "$rpm_cv_glob" = yes; then
    AC_DEFINE(USE_GNU_GLOB, 1, [Use the included glob.c?])
    AC_LIBOBJ(glob)
    AC_LIBOBJ(fnmatch)
#fi
dnl
dnl Auto-detect which python bindings should be built.
dnl
withval=auto
AC_ARG_WITH(python, [  --with-python           build rpm python bindings ])

WITH_PYTHON_VERSION=$withval
if test $withval = auto ; then

AC_MSG_CHECKING(for python 2.4)
AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <python2.4/Python.h>
main() {
  exit(strncmp("2.4", PY_VERSION, 3));
} ]])],[withval=yes],[withval=no],[withval=yes])
  AC_MSG_RESULT($withval)
  if test $withval = yes ; then
    WITH_PYTHON_VERSION="2.4"
  else
    
  AC_MSG_CHECKING(for python 2.3)
  AC_RUN_IFELSE([AC_LANG_SOURCE([[
  #include <python2.3/Python.h>
  main() {
    exit(strncmp("2.3", PY_VERSION, 3));
  } ]])],[withval=yes],[withval=no],[withval=yes])
    AC_MSG_RESULT($withval)
    if test $withval = yes ; then
      WITH_PYTHON_VERSION="2.3"
    else
    
      AC_MSG_CHECKING(for python 2.2)
      AC_RUN_IFELSE([AC_LANG_SOURCE([[
    #include <python2.2/Python.h>
    main() {
      exit(strncmp("2.2", PY_VERSION, 3));
    } ]])],[withval=yes],[withval=no],[withval=yes])
      AC_MSG_RESULT($withval)
      if test $withval = yes ; then
        WITH_PYTHON_VERSION="2.2"
      else
    
        AC_MSG_CHECKING(for python 1.5.2)
        AC_RUN_IFELSE([AC_LANG_SOURCE([[
    #include <python1.5/Python.h>
    main() {
      exit(strcmp("1.5.2", PY_VERSION));
    } ]])],[withval=yes],[withval=no],[withval=yes])
        AC_MSG_RESULT($withval)
        if test $withval = yes ; then
          WITH_PYTHON_VERSION="1.5"
        fi
      fi
    fi
  fi
fi

if test "$WITH_PYTHON_VERSION" != no ; then
  WITH_PYTHON_SUBDIR=python
  WITH_PYTHON_SUBPACKAGE=1
else
  WITH_PYTHON_SUBDIR=
  WITH_PYTHON_SUBPACKAGE=0
fi

AC_SUBST(WITH_PYTHON_SUBDIR)
AC_SUBST(WITH_PYTHON_SUBPACKAGE)
AC_SUBST(WITH_PYTHON_VERSION)

AC_PATH_PROG(__DOXYGEN, doxygen, no, $PATH)
dnl
dnl Auto-detect whether doxygen generated API docs should be included.
dnl
withval=auto
AC_ARG_WITH(apidocs, [  --with-apidocs          build rpm API docs ])

if test $withval = auto -a $__DOXYGEN != no ; then
  withval=yes
elif test $withval = yes -a $__DOXYGEN = no ; then
  AC_MSG_ERROR(--> rpm API docs needs doxygen in PATH)
fi

WITH_SELINUX_LIB=
withval=${with_selinuxval}
AC_ARG_WITH(selinux, [  --with-selinux          build with selinux support ])
if test $withval != no ; then
  AC_DEFINE(WITH_SELINUX, 1, [Build with selinux support?])
  WITH_SELINUX_LIB="-lselinux"
fi
AC_SUBST(WITH_SELINUX_LIB)

WITH_LUA_LIB=
WITH_LUA_SUBDIR=
WITH_LUA_INCLUDE=
withval=yes
AC_ARG_WITH(lua, [  --with-lua              build with lua support ])
if test $withval != no -a -d lua ; then
  AC_DEFINE(WITH_LUA, 1, [Build with lua support?])
  WITH_LUA_SUBDIR="lua"
  WITH_LUA_INCLUDE="-I\${top_srcdir}/${WITH_LUA_SUBDIR}/include -I\${top_srcdir}/${WITH_LUA_SUBDIR}/local"
  WITH_LUA_LIB="\$(top_builddir)/${WITH_LUA_SUBDIR}/liblua.la"
fi
AC_SUBST(WITH_LUA_LIB)
AC_SUBST(WITH_LUA_SUBDIR)
AC_SUBST(WITH_LUA_INCLUDE)

if test $withval = yes; then
  WITH_APIDOCS_TARGET=apidocs
  WITH_APIDOCS=1
else
  WITH_APIDOCS=0
fi
AC_SUBST(WITH_APIDOCS_TARGET)
AC_SUBST(WITH_APIDOCS)

withval=no
AC_ARG_WITH(dmalloc, [  --with-dmalloc          build with dmalloc debugging support ])
if test $withval = yes ; then
  AC_DEFINE(DMALLOC, 1, [Build with dmalloc support?])
  LIBS="$LIBS -ldmalloc"
fi

withval=no
AC_ARG_WITH(efence, [  --with-efence           build with efence debugging support ])
if test $withval = yes ; then
  AC_DEFINE(EFENCE, 1, [Build with libefence support?])
  LIBS="$LIBS -lefence"
fi

AC_CHECK_FUNCS(setlocale)

dnl XXX Solaris <= 2.6 only permits 8 chars in password.
AC_CHECK_FUNCS(getpassphrase)

AC_CHECK_FUNC(getmntent, AC_DEFINE(HAVE_GETMNTENT, 1, [Define if you have the getmntent() function]), [
  AC_CHECK_FUNC(mntctl, AC_DEFINE(HAVE_MNTCTL, 1, [Define as 1 if you have mntctl() (only aix?)]),[
    AC_CHECK_FUNC(getmntinfo, AC_DEFINE(HAVE_GETMNTINFO, 1, [Define as 1 if you have getmntinfo() (Mac OS X)]), [
      AC_CHECK_FUNC(getmntinfo_r, AC_DEFINE(HAVE_GETMNTINFO_R, 1, [Define as 1 if you have getmntinfo_r() (only osf?)]), [
        AC_CHECK_LIB(c_r, getmntinfo_r, [LIBS="$LIBS -lc_r"; 
					AC_DEFINE(HAVE_GETMNTINFO_R, 1, [Define as 1 if you have getmntinfo_r() (only osf?)])], [
		 AC_DEFINE([USE_GETMNTENT], 1, [Defined if getmntent replacement is used])
                 AC_LIBOBJ(getmntent)])
      ])
    ])
  ])
])

AC_CHECK_FUNC(lchown,
   [__CHOWN_RHF="%{__chown} -Rhf"
    __CHGRP_RHF="%{__chgrp} -Rhf"
    AC_DEFINE(HAVE_LCHOWN, 1, [Define as 1 if you have lchown()])],
   [__CHOWN_RHF="%{__chown} -Rf"
    __CHGRP_RHF="%{__chgrp} -Rf"
    dnl Does chown() follow symlinks? This should be a good enough test.
    AC_MSG_CHECKING(whether chown() follows symlinks)
    AC_ARG_ENABLE([broken-chown],
    [  --enable-broken-chown   this system's chown follows symbolic links], 
	    result=$enableval, result=unknown)
    if echo "$build" | egrep "(aix)|(hpux)|(linux)" > /dev/null ; then
	result=yes
    elif echo "$build" | egrep "(nextstep)" > /dev/null ; then
	result=no
    fi
    if test $result = unknown; then
	if test `${__ID} | cut -f2 -d\= | cut -f1 -d\(` = 0; then
	    rm -f foo bar
	    touch foo
	    ln -s foo bar
	    ${__CHOWN} 10 bar
	    if test `ls -l foo | awk '{print $3}'` != "root"; then
		result=yes
	    else
		result=no
	    fi
	    ${__RM} -f foo bar
	else
	    AC_MSG_CHECKING((cannot check by non-root user))
	    result=no
	fi
    fi

    AC_MSG_RESULT($result)
    if test $result = yes; then
	    AC_DEFINE(CHOWN_FOLLOWS_SYMLINK, 1, [Define as 1 if chown() follows symlinks and you don't have lchown()])
    fi])
AC_SUBST(__CHOWN_RHF)
AC_SUBST(__CHGRP_RHF)

dnl
dnl figure out what root's primary group is
dnl
AC_MSG_CHECKING(root's primary group)
AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>
#include <sys/types.h>
#include <pwd.h>
#include <grp.h>

int main()
{
	struct passwd *root = NULL;
	struct group *roots_group = NULL;
	FILE * tempfile = NULL;

	root = getpwuid( (uid_t) 0 );
	if (root != NULL) {
		roots_group = getgrgid(root->pw_gid);
		if (roots_group != NULL) {
			tempfile = fopen("conftest_rootg", "w");
			if (tempfile != NULL) {
				fprintf(tempfile, "%s\n", roots_group->gr_name);
				fclose(tempfile);
				exit(0);
			}
		}
	}

	exit(1);
}]])],[ROOT_GROUP=`cat conftest_rootg`],[ROOT_GROUP="root"],[ROOT_GROUP="root"
])
AC_MSG_RESULT($ROOT_GROUP)
AC_SUBST(ROOT_GROUP)

if test "x$varprefix" = "x"; then
    # For /usr and /usr/local, we want the 'var' directory to go
    # in /var and /var/local respectively. For everything else, 
    # just put the 'var' directory in prefix/var.
    case $prefix in
	/usr | /usr/local )
	    varprefix=`echo $prefix | sed 's/usr/var/'` ;;
	NONE)
 	    varprefix=`echo $ac_default_prefix | sed 's/usr/var/'` ;;
	*) 
	    varprefix=$prefix/var ;;
    esac	
fi
AC_SUBST(varprefix)

if test "x$tmpdir" = "x"; then
    if test -d $varprefix/tmp; then
	tmpdir=$varprefix/tmp
    else
	if test -d /var/tmp; then
	    tmpdir=/var/tmp
	else
	    tmpdir=/tmp
	fi
    fi
fi
AC_SUBST(tmpdir)

if echo "$build_os" | grep sco > /dev/null; then
	echo "hacking things up for sco"
	AC_DEFINE(NEED_STRINGS_H, 1, [Define as one if we need to include <strings.h> (along with <string.h>)])
	AC_DEFINE(HAVE_STRUCT_MNTTAB, 1,
	[Define as 1 if you have "struct mnttab" (only sco?)])
elif echo "$build_os" | grep sunos > /dev/null; then
	echo "hacking things up for sunos"
	CFLAGS="$CFLAGS -D__USE_FIXED_PROTOTYPES__"
	AC_DEFINE(NEED_STRINGS_H, 1, [Define as one if we need to include <strings.h> (along with <string.h>)])
	AC_DEFINE(NEED_MYREALLOC, 1, [Define as 1 if we need myrealloc])
	AC_LIBOBJ(myrealloc)
fi

#
# get rid of the 4-th tuple, if config.guess returned "linux-gnu" for build_os
#
if echo "$build_os" | grep '.*-gnulibc1' > /dev/null ; then
	build_os=`echo "${build_os}" | sed 's/-gnulibc1$//'`
fi
if echo "$build_os" | grep '.*-gnu' > /dev/null ; then
	build_os=`echo "${build_os}" | sed 's/-gnu$//'`
fi

changequote(<, >)
build_os_exact="${build_os}"
build_os_major=`echo "${build_os}" | sed 's/\..*$//'`
build_os_noversion=`echo "${build_os}" | sed 's/[0-9]*\..*$//'`
changequote([, ])

rm -f ./find-provides
if test -f ${srcdir}/autodeps/${build_cpu}-${build_os_exact}.prov ; then
	echo "using ${srcdir}/autodeps/${build_cpu}-${build_os_exact}.prov for automatic provides generation"
    ln -s ${srcdir}/autodeps/${build_cpu}-${build_os_exact}.prov ./find-provides
elif test -f ${srcdir}/autodeps/${build_os_exact}.prov ; then
	echo "using ${srcdir}/autodeps/${build_os_exact}.prov for automatic provides generation"
    ln -s ${srcdir}/autodeps/${build_os_exact}.prov ./find-provides
elif test -f ${srcdir}/autodeps/${build_os_major}.prov ; then
	echo "using ${srcdir}/autodeps/${build_os_major}.prov for automatic provides generation"
    ln -s ${srcdir}/autodeps/${build_os_major}.prov ./find-provides
elif test -f ${srcdir}/autodeps/${build_os_noversion}.prov ; then
	echo "using ${srcdir}/autodeps/${build_os_noversion}.prov for automatic provides generation"
    ln -s ${srcdir}/autodeps/${build_os_noversion}.prov ./find-provides
else
    echo "*** no default provides information is available for ${build_os_noversion}"
    ln -s ${srcdir}/autodeps/none ./find-provides
fi

rm -f ./find-requires
if test -f ${srcdir}/autodeps/${build_cpu}-${build_os_exact}.req ; then
	echo "using ${srcdir}/autodeps/${build_cpu}-${build_os_exact}.req for automatic requires generation"
    ln -s ${srcdir}/autodeps/${build_cpu}-${build_os_exact}.req ./find-requires
elif test -f ${srcdir}/autodeps/${build_os_exact}.req ; then
	echo "using ${srcdir}/autodeps/${build_os_exact}.req for automatic requires generation"
    ln -s ${srcdir}/autodeps/${build_os_exact}.req ./find-requires
elif test -f ${srcdir}/autodeps/${build_os_major}.req ; then
	echo "using ${srcdir}/autodeps/${build_os_major}.req for automatic requires generation"
    ln -s ${srcdir}/autodeps/${build_os_major}.req ./find-requires
elif test -f ${srcdir}/autodeps/${build_os_noversion}.req ; then
	echo "using ${srcdir}/autodeps/${build_os_noversion}.req for automatic requires generation"
    ln -s ${srcdir}/autodeps/${build_os_noversion}.req ./find-requires
else
    echo "*** no default requires information is available for ${build_os_noversion}"
    ln -s ${srcdir}/autodeps/none ./find-requires
fi

dnl XXX Choose /usr/lib or /usr/lib64 for library installs.
MARK64=
case "${target_cpu}" in
x86_64*|ppc64*|powerpc64*|sparc64*|s390x*)	MARK64=64 ;;
esac
AC_SUBST(MARK64)

dnl Determine the canonical arch-vendor-os for the build machine
autorelocate_path='%{nil}'
autorelocate_dcolor='0'
case "${build_cpu}" in
*86)		RPMCANONCOLOR=0; RPMCANONARCH=i386 ;;
ia32e*)		RPMCANONCOLOR=3; RPMCANONARCH=ia32e ;;
amd64*)		RPMCANONCOLOR=3; RPMCANONARCH=amd64 ;;
x86_64*)	RPMCANONCOLOR=3; RPMCANONARCH=x86_64 ;;
alpha*)		RPMCANONCOLOR=0; RPMCANONARCH=alpha ;;
sparc64*)	RPMCANONCOLOR=3; RPMCANONARCH=sparc64 ;;
sparc*)		RPMCANONCOLOR=3; RPMCANONARCH=sparc ;;
ia64*)		RPMCANONCOLOR=2; RPMCANONARCH=ia64;
		autorelocate_path='/emul/%%{ARCH}-%%{OS}'
		autorelocate_dcolor='1' ;;
s390x*)		RPMCANONCOLOR=3; RPMCANONARCH=s390x ;;
s390*)		RPMCANONCOLOR=0; RPMCANONARCH=s390 ;;
powerpc64*|ppc64*)	RPMCANONCOLOR=3; RPMCANONARCH=ppc64 ;;
powerpc*|ppc*)	RPMCANONCOLOR=0; RPMCANONARCH=ppc ;;
armv3l*)	RPMCANONCOLOR=0; RPMCANONARCH=armv3l ;;
armv4l*)	RPMCANONCOLOR=0; RPMCANONARCH=armv4l ;;
armv4b*)	RPMCANONCOLOR=0; RPMCANONARCH=armv4b ;;
arm*)		RPMCANONCOLOR=0; RPMCANONARCH="${build_cpu}" ;;
mipsel*)	RPMCANONCOLOR=0; RPMCANONARCH=mipsel ;;
mips*)		RPMCANONCOLOR=0; RPMCANONARCH=mips ;;
m68k*)		RPMCANONCOLOR=0; RPMCANONARCH=m68k ;;
*)		RPMCANONCOLOR=0; RPMCANONARCH=unknown ;;
esac
case "${build_os_noversion}" in
mint)		RPMCANONARCH=m68kmint ;;
esac
RPMCANONVENDOR="$build_vendor"
case "${build_vendor}" in
unknown|pc|ibm|redhat|pld|mandrake|conectiva|lvr|yellowdog|caos)
	test -f /etc/redhat-release &&		RPMCANONVENDOR=redhat
	test -f /etc/pld-release &&		RPMCANONVENDOR=pld
	test -f /etc/mandrake-release &&	RPMCANONVENDOR=mandrake
	test -f /etc/conectiva-release &&	RPMCANONVENDOR=conectiva
	test -f /etc/lvr-release &&		RPMCANONVENDOR=lvr
	test -f /etc/yellowdog-release &&	RPMCANONVENDOR=yellowdog
	test -f /etc/caos-release &&		RPMCANONVENDOR=caos
	;;
esac
RPMCANONOS="$build_os_noversion"
AC_SUBST(RPMCANONCOLOR)
AC_SUBST(autorelocate_path)
AC_SUBST(autorelocate_dcolor)
AC_SUBST(RPMCANONARCH)
AC_SUBST(RPMCANONVENDOR)
AC_SUBST(RPMCANONOS)

if test X"$prefix" = XNONE ; then
    usrprefix="$ac_default_prefix"
else
    usrprefix=$prefix
fi
LOCALEDIR="`echo ${usrprefix}/share/locale`"
AC_DEFINE_UNQUOTED(LOCALEDIR, "$LOCALEDIR",
	[Full path to rpm locale directory (usually /usr/share/locale)])
AC_SUBST(LOCALEDIR)
LIBDIR="`echo $libdir | sed 's-/lib$-/%{_lib}-'`"
AC_SUBST(LIBDIR)
RPMCONFIGDIR="`echo ${usrprefix}/lib/rpm`"
AC_DEFINE_UNQUOTED(RPMCONFIGDIR, "$RPMCONFIGDIR",
	[Full path to rpm global configuration directory (usually /usr/lib/rpm)])
AC_SUBST(RPMCONFIGDIR)

SYSCONFIGDIR="`echo /etc/rpm`"
AC_DEFINE_UNQUOTED(SYSCONFIGDIR, "$SYSCONFIGDIR",
	[Full path to rpm system configuration directory (usually /etc/rpm)])
AC_SUBST(SYSCONFIGDIR)

MACROFILES="${RPMCONFIGDIR}/macros:${RPMCONFIGDIR}/%{_target_platform}/macros:${SYSCONFIGDIR}/macros:${SYSCONFIGDIR}/macros.specspo:${SYSCONFIGDIR}/macros.db1:${SYSCONFIGDIR}/%{_target_platform}/macros:~/.rpmmacros"
AC_DEFINE_UNQUOTED(MACROFILES, "$MACROFILES",
	[Colon separated paths of macro files to read.])
AC_SUBST(MACROFILES)

LIBRPMRC_FILENAME="${RPMCONFIGDIR}/rpmrc"
AC_DEFINE_UNQUOTED(LIBRPMRC_FILENAME, "$LIBRPMRC_FILENAME",
	[Full path to rpmrc configuration file (usually /usr/lib/rpm/rpmrc)])
AC_SUBST(LIBRPMRC_FILENAME)

VENDORRPMRC_FILENAME="${RPMCONFIGDIR}/${RPMCANONVENDOR}/rpmrc"
AC_DEFINE_UNQUOTED(VENDORRPMRC_FILENAME, "$VENDORRPMRC_FILENAME",
       [Full path to vendor rpmrc configuration file (usually /usr/lib/rpm/vendor/rpmrc)])
AC_SUBST(VENDORRPMRC_FILENAME)

LIBRPMALIAS_FILENAME="${RPMCONFIGDIR}/rpmpopt-${VERSION}"
AC_DEFINE_UNQUOTED(LIBRPMALIAS_FILENAME, "$LIBRPMALIAS_FILENAME",
	[Full path to rpmpopt configuration file (usually /usr/lib/rpm/rpmpopt)])
AC_SUBST(LIBRPMALIAS_FILENAME)
FINDREQUIRES="${RPMCONFIGDIR}/find-requires"
AC_DEFINE_UNQUOTED(FINDREQUIRES, "$FINDREQUIRES",
	[Full path to find-requires script (usually /usr/lib/rpm/find-requires)])
AC_SUBST(FINDREQUIRES)
FINDPROVIDES="${RPMCONFIGDIR}/find-provides"
AC_DEFINE_UNQUOTED(FINDPROVIDES, "$FINDPROVIDES",
	[Full path to find-provides script (usually /usr/lib/rpm/find-provides)])
AC_SUBST(FINDPROVIDES)

testdir="`pwd`/tests"
dnl AC_DEFINE_UNQUOTED(testdir, "$testdir")
AC_SUBST(testdir)

AC_SUBST(INCPATH)
AC_SUBST(LIBMISC)

AC_SUBST(RPM)

AC_SUBST(OBJDUMP)

dnl XXX this causes popt to depend on zlib et al
dnl # XXX Propagate -lucb to popt ...
dnl export LIBS INCPATH CONFIG_SITE

AC_CONFIG_SUBDIRS(popt zlib file sqlite db3)

AC_CONFIG_FILES([ Doxyfile Makefile rpmrc macros platform rpmpopt rpm.spec
	rpmio/Makefile rpmdb/Makefile lib/Makefile build/Makefile
	scripts/Makefile scripts/brp-redhat
	scripts/macros.perl scripts/macros.php scripts/macros.python
	tools/Makefile
	tests/Makefile tests/rpmrc tests/macros tests/hello-test/Makefile
	misc/Makefile intl/Makefile po/Makefile.in
	doc/Makefile
	doc/manual/Makefile
	doc/fr/Makefile
	doc/ja/Makefile
	doc/ko/Makefile
	doc/pl/Makefile
	doc/ru/Makefile
	doc/sk/Makefile
	python/Makefile
	python/rpm/Makefile
 	lua/Makefile
  ])
AC_CONFIG_COMMANDS([default],[[	echo timestamp > popt/stamp-h.in
	echo timestamp > stamp-h.in
  
]],[[]])
AC_OUTPUT