Preparing for rpm 4.6.1
[platform/upstream/rpm.git] / configure.ac
1 AC_PREREQ(2.61)
2 AC_INIT(rpm, 4.6.1, rpm-maint@lists.rpm.org)
3
4 AC_CONFIG_SRCDIR([rpmqv.c])
5 AC_CONFIG_HEADERS([config.h])
6 AC_CONFIG_MACRO_DIR([m4])
7
8 AM_INIT_AUTOMAKE([1.10 foreign tar-ustar dist-bzip2 subdir-objects nostdinc])
9
10 AC_CONFIG_TESTDIR(tests)
11
12 AC_USE_SYSTEM_EXTENSIONS
13
14 AC_DISABLE_STATIC
15
16 dnl Checks for programs.
17 AC_PROG_CXX
18 AC_PROG_AWK
19 AC_PROG_CC
20 AC_PROG_CPP
21 AC_PROG_INSTALL
22 AC_PROG_LN_S
23 AC_PROG_MAKE_SET
24 AC_PROG_LIBTOOL
25 AC_PROG_YACC
26
27 AC_SUBST(__CC, $CC)
28 AC_PROG_CC_C99
29 if test "$ac_cv_prog_cc_c99" = no; then
30     AC_MSG_ERROR([ISO C99 capable compiler required])
31 fi
32
33 AS=${AS-as}
34 AC_SUBST(AS)
35 if test "$GCC" = yes; then
36     CFLAGS="$CFLAGS -fPIC -DPIC -D_REENTRANT -Wall -Wpointer-arith -Wmissing-prototypes -Wno-char-subscripts"
37     # XXX disabled for now due to noise from NSPR headers
38     # CFLAGS="$CFLAGS -Wstrict-prototypes"
39     cflags_to_try="-fno-strict-aliasing -fstack-protector"
40     AC_MSG_CHECKING([supported compiler flags])
41     old_cflags=$CFLAGS
42     echo
43     for flag in $cflags_to_try; do
44         CFLAGS="$CFLAGS $flag"
45         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[return 0;]])],[
46                 echo "   $flag"
47                 RPMCFLAGS="$RPMCFLAGS $flag"
48         ],[])
49         CFLAGS=$old_cflags
50     done
51     CFLAGS="$CFLAGS $RPMCFLAGS"
52 fi
53 export CFLAGS
54
55 AC_SYS_LARGEFILE
56
57 dnl
58 dnl look for POSIX chmod attributes
59 dnl
60 AC_MSG_CHECKING(POSIX chmod)
61 touch foo.chmodtest
62 chmod 744 foo.chmodtest
63 chmod +X foo.chmodtest 2>/dev/null
64 a=`ls -l foo.chmodtest | awk '{print $1}'`
65 rm -f foo.chmodtest
66 if test "$a" = "-rwxr-xr-x"; then
67     AC_MSG_RESULT(yes)
68     FIXPERMS=a+rX,u+w,g-w,o-w 
69 else
70     AC_MSG_RESULT(no (tell your OS vendor about GNU fileutils))
71     FIXPERMS=a+r,u+w,g-w,o-w 
72 fi
73 AC_SUBST(FIXPERMS)
74
75 dnl
76 dnl see if we have a mkdir that supports `-p'.
77 dnl
78 AC_PATH_PROGS(RPM_MKDIR, mkdir, mkdir)
79 AC_MSG_CHECKING(if $RPM_MKDIR supports -p)
80 rm -rf conftest
81 $RPM_MKDIR -p conftest/a 2>/dev/null
82 if test $? = 0 ; then
83         rmdir conftest/a 2>/dev/null
84         if test $? = 0  ; then
85                 :
86         else
87                 RPM_MKDIR_P=0
88         fi
89
90         rmdir conftest 2>/dev/null
91         if test $? = 0 ; then
92                 RPM_MKDIR_P="$RPM_MKDIR -p"
93         else
94                 RPM_MKDIR_P=0
95         fi
96 else
97         RPM_MKDIR_P=0
98 fi
99
100 if test X"$RPM_MKDIR_P" = X0 ; then
101         AC_MSG_RESULT(no)
102         RPM_MKDIR_P="`echo ${prefix}/lib/rpm/mkinstalldirs`"
103 else
104         AC_MSG_RESULT(yes)
105 fi
106 dnl
107 dnl substitute this into config.h, so the C source picks it up.
108 dnl
109 AC_DEFINE_UNQUOTED(RPM_MKDIR_P, "${RPM_MKDIR_P}",
110 [A full path to a program, possibly with arguments, that will create a
111    directory and all necessary parent directories, ala 'mkdir -p'])
112 AC_SUBST(RPM_MKDIR_P)
113
114 dnl AM_DISABLE_SHARED
115 AM_PROG_LIBTOOL
116
117 AC_CHECK_TOOL(AR, ar, :)
118
119 dnl
120 dnl use defaults if cross-compiling, otherwise use the default path.
121 dnl
122 if test "$cross_compiling" = "yes"; then
123     MYPATH=":"
124 else
125     MYPATH=$PATH
126 fi
127
128 dnl
129 dnl Find some common programs
130 dnl
131 AC_PATH_PROG(__BZIP2, bzip2, /usr/bin/bzip2, $MYPATH)
132 AC_PATH_PROG(__CAT, cat, /bin/cat, $MYPATH)
133 AC_PATH_PROG(__CHGRP, chgrp, /bin/chgrp, $MYPATH)
134 AC_PATH_PROG(__CHMOD, chmod, /bin/chmod, $MYPATH)
135 AC_PATH_PROG(__CHOWN, chown, /bin/chown, $MYPATH)
136 AC_PATH_PROG(__CP, cp, /bin/cp, $MYPATH)
137 AC_PATH_PROG(__CPIO, cpio, /bin/cpio, $MYPATH)
138 AC_PATH_PROG(__CURL, curl, /usr/bin/curl, $MYPATH)
139 AC_PATH_PROG(__FILE, file, /usr/bin/file, $MYPATH)
140 AC_PATH_PROG(__GPG, gpg, /usr/bin/gpg, $MYPATH)
141 AC_PATH_PROG(__GREP, grep, /bin/grep, $MYPATH)
142 AC_PATH_PROG(__GZIP, gzip, /bin/gzip, $MYPATH)
143 AC_PATH_PROG(__UNZIP, unzip, /usr/bin/unzip, $MYPATH)
144
145 AC_PATH_PROG(__ID, id, /usr/bin/id, $MYPATH)
146 AC_MSG_CHECKING(checking whether id supports -u)
147     if ${__ID} -u 2>&1 > /dev/null ; then
148         __ID_U="%{__id} -u"
149         AC_MSG_RESULT(yes)
150     else
151         __ID_U="%{__id} | %{__sed} 's/[[^=]]*=\\\\([[0-9]][[0-9]]*\\\\).*$/\\\\1/'"
152         AC_MSG_RESULT(no)
153     fi
154 AC_SUBST(__ID_U)
155
156 AC_PATH_PROG(__INSTALL, install, /usr/bin/install, $MYPATH)
157 AC_PATH_PROG(__LZMA, lzma, /usr/bin/lzma, $MYPATH)
158 AC_PATH_PROG(__MAKE, make, /usr/bin/make, $MYPATH)
159 AC_PATH_PROG(__MKDIR, mkdir, /bin/mkdir, $MYPATH)
160 AC_PATH_PROG(__MV, mv, /bin/mv, $MYPATH)
161 AC_PATH_PROG(__PATCH, patch, /usr/bin/patch, $MYPATH)
162 AC_MSG_CHECKING(old version of patch)
163     PATCHVERSION=`patch --version 2>&1`
164
165     if test "$PATCHVERSION" = "Patch version 2.1"; then
166         AC_DEFINE(HAVE_OLDPATCH_21, 1,
167                 [Define if the patch call you'll be using is 2.1 or older])
168         AC_MSG_RESULT(patch older then 2.2 found)
169     else
170         AC_MSG_RESULT(patch later then 2.2 found)
171     fi
172
173 AC_PATH_PROG(__PERL, perl, /usr/bin/perl, $MYPATH)
174 AC_PATH_PROG(__PGP, pgp, /usr/bin/pgp, $MYPATH)
175 AC_PATH_PROG(__PYTHON, python, /usr/bin/python, $MYPATH) 
176 AC_PATH_PROG(__RM, rm, /bin/rm, $MYPATH)
177 AC_PATH_PROG(__RSH, rsh, /usr/bin/rsh, $MYPATH)
178 AC_PATH_PROG(__SED, sed, /bin/sed, $MYPATH)
179 AC_PATH_PROG(__SSH, ssh, /usr/bin/ssh, $MYPATH)
180 AC_PATH_PROG(__TAR, tar, /bin/tar, $MYPATH)
181
182 AC_PATH_PROG(__LD, ld, /usr/bin/ld, $MYPATH)
183 AC_PATH_PROG(__NM, nm, /usr/bin/nm, $MYPATH)
184 AC_PATH_PROG(__OBJCOPY, objcopy, /usr/bin/objcopy, $MYPATH)
185 AC_PATH_PROG(__OBJDUMP, objdump, /usr/bin/objdump, $MYPATH)
186 AC_PATH_PROG(__STRIP, strip, /usr/bin/strip, $MYPATH)
187
188 #=================
189 # Check for zlib library. 
190
191 WITH_ZLIB_INCLUDE=
192 WITH_ZLIB_LIB=
193
194 AC_CHECK_HEADERS([zlib.h],[
195   AS_IF([test -z "${WITH_ZLIB_LIB}"],[
196     for zlib in z gz ; do
197       AC_CHECK_LIB(${zlib}, gzread, 
198         [WITH_ZLIB_LIB="-l${zlib}"; break])
199     done
200
201 dnl zlib-1.0.4 has not gzseek
202     AC_CHECK_LIB(${zlib}, gzseek, [AC_DEFINE(HAVE_GZSEEK, 1, [Define as 1 if your zlib has gzseek()])])
203   ])
204 ])
205
206 AC_SUBST(WITH_ZLIB_INCLUDE)
207 AC_SUBST(WITH_ZLIB_LIB)
208
209 #=================
210 # Check for bzip2 library.
211
212 AC_CHECK_HEADERS([bzlib.h],[
213   AC_CHECK_LIB(bz2, bzread, [WITH_BZ2_LIB=-lbz2],
214   [
215     AC_CHECK_LIB(bz2, BZ2_bzread,[ 
216       WITH_BZ2_LIB="-lbz2"
217       AC_DEFINE(HAVE_BZ2_1_0, 1, [Define as 1 if you bzip2 1.0])
218     ]) 
219   ])
220 ])
221 AC_SUBST(WITH_BZ2_LIB)
222
223 #=================
224 # Check for lzma library.
225
226 AC_CHECK_HEADERS([lzma.h],[
227   AC_CHECK_LIB(lzma, lzma_auto_decoder, [WITH_LZMA_LIB=-llzma])
228 ])
229 AC_SUBST(WITH_LZMA_LIB)
230
231 #=================
232
233 dnl
234 dnl Check for features
235 dnl
236
237 dnl Checks for libraries.
238
239 AC_CHECK_FUNC(setreuid, [], [
240     AC_CHECK_LIB(ucb, setreuid, [if echo $LIBS | grep -- -lucb >/dev/null ;then :; else LIBS="$LIBS -lc -lucb" USEUCB=y;fi])
241 ])
242
243 AC_CHECK_FUNC(rand, [], [
244     AC_CHECK_LIB(rand, rand, [])
245 ])
246
247 AC_CHECK_FUNC(getdomainname, [], [
248     AC_CHECK_LIB(nsl, getdomainname)
249 ])
250 AC_CHECK_FUNC(socket, [], [
251     AC_CHECK_LIB(socket, socket)
252 ])
253
254 AC_CHECK_HEADERS(error.h)
255 AC_CHECK_FUNCS(error)
256
257 AC_CHECK_HEADERS(poll.h)
258
259 AC_CHECK_HEADERS(pthread.h)
260
261 AC_CHECK_LIB(pthread, pthread_mutex_trylock, [], [
262   dnl OSF 5.0 has the the symbols prefixed with __ in libpthread.
263   AC_CHECK_LIB(pthread, __pthread_mutex_trylock, [], [
264     AC_CHECK_LIB(thread, mutex_lock)
265   ])
266 ])
267
268 AC_SEARCH_LIBS(aio_read, [c rt aio posix4])
269
270 AC_CHECK_FUNCS(vsnprintf snprintf)
271
272 dnl Temporary hack for MiNT.  Some functions (writev, snprintf) are
273 dnl not in the libc but in libport (for political reasons).  This check
274 dnl can hopefully be removed soon.  Please use the default action
275 dnl for this macro (not LIBS=...), otherwise the check for dbopen
276 dnl will fail.
277 AC_CHECK_LIB(port, writev)
278
279 #=================
280 # Check for libelf library. Prefer external, otherwise none.
281 WITH_LIBELF_INCLUDE=
282 WITH_LIBELF_LIB=
283 AC_CHECK_HEADER([libelf.h])
284 AC_CHECK_HEADERS([gelf.h], [
285         AC_CHECK_LIB(elf, gelf_getvernaux, [
286             AC_DEFINE(HAVE_LIBELF, 1, [Define to 1 if you have the 'elf' library (-lelf).])
287             WITH_LIBELF_LIB="-lelf"
288             WITH_LIBELF=yes
289         ])
290 ])
291 AC_SUBST(WITH_LIBELF_INCLUDE)
292 AC_SUBST(WITH_LIBELF_LIB)
293 AM_CONDITIONAL(LIBELF,[test "$WITH_LIBELF" = yes])
294
295 AC_CHECK_HEADERS([dwarf.h], [
296   WITH_LIBDWARF=yes
297 ])
298 AM_CONDITIONAL(LIBDWARF,[test "$WITH_LIBDWARF" = yes])
299
300 #=================
301 # Check for NSS library.
302 # We need nss.h from NSS which needs nspr.h. Unfortunately both glibc and NSS 
303 # have a header named nss.h... so make extra check for NSS's sechash.h 
304 # which we use too and hopefully is slightly more unique to NSS.
305 WITH_NSS_INCLUDE=
306 WITH_NSS_LIB=
307 AC_CHECK_HEADERS([nspr.h nss.h sechash.h], [], [
308   AC_MSG_ERROR([missing required NSPR / NSS header])
309 ])
310 AC_CHECK_LIB(nss3, NSS_NoDB_Init, [
311   WITH_NSS_LIB=-lnss3
312 ], [
313   AC_MSG_ERROR([missing required NSS library 'nss3'])
314 ])
315 AC_SUBST(WITH_NSS_INCLUDE)
316 AC_SUBST(WITH_NSS_LIB)
317
318 #=================
319 # Check for magic library.
320 WITH_MAGIC_INCLUDE=
321 WITH_MAGIC_LIB=
322
323 AC_CHECK_HEADER([magic.h], [
324     AC_CHECK_LIB(magic, magic_open, [
325       WITH_MAGIC_INCLUDE=
326       WITH_MAGIC_LIB="-lmagic"
327     ],[
328       AC_MSG_ERROR([missing required library 'libmagic']) 
329     ])
330 ],[
331       AC_MSG_ERROR([missing required header magic.h]) 
332 ])
333
334 AC_SUBST(WITH_MAGIC_INCLUDE)
335 AC_SUBST(WITH_MAGIC_LIB)
336
337 #=================
338 # Check for popt library.
339 WITH_POPT_INCLUDE=
340 WITH_POPT_LIB=
341
342 AC_CHECK_HEADER([popt.h], [
343   AC_CHECK_LIB(popt, poptGetContext, [
344       WITH_POPT_INCLUDE=
345       WITH_POPT_LIB="-lpopt"
346   ],[
347     AC_MSG_ERROR([missing required library popt])
348   ])
349 ],[
350   AC_MSG_ERROR([missing required header popt.h])
351 ])
352
353 AC_SUBST(WITH_POPT_INCLUDE)
354 AC_SUBST(WITH_POPT_LIB)
355
356 #=================
357 # Process --with/without-external-db
358 AC_ARG_WITH(external_db, [  --with-external-db      build against an external Berkeley db],
359 [case "$with_external_db" in
360 yes|no) ;;
361 *) AC_MSG_ERROR([invalid argument to --with-external-db]) ;;
362 esac],
363 [with_external_db=no])
364
365 case "$with_external_db" in
366 yes )
367   AC_CHECK_HEADERS([db.h],[
368     AC_CHECK_TYPE([db_threadid_t],[],
369       [AC_MSG_WARN([missing type db_threadid_t])],
370       [#include <db.h>])
371     save_LIBS="$LIBS"
372     AC_CHECK_LIB([db],[db_create],[],[
373       AC_MSG_ERROR([missing db_create in libdb])
374       ])
375     AC_CHECK_LIB([db],[db_env_create],[],[
376       AC_MSG_ERROR([missing db_env_create in libdb])
377       ])
378     AC_CHECK_LIB([db],[db_env_set_func_fsync],[],[
379       AC_MSG_ERROR([missing db_env_set_func_fsync in libdb])
380       ])
381     AC_CHECK_LIB([db],[db_strerror],[],[
382       AC_MSG_ERROR([missing db_strerror in libdb])
383       ])
384     WITH_DB_LIB=-ldb
385     LIBS="$save_LIBS"
386   ],[
387     AC_MSG_ERROR([missing required header db.h])
388   ])
389   ;;
390 * ) # Fall back to internal db if available
391   if [ test -x db/dist/configure ]; then
392     AC_DEFINE(HAVE_DB_H, 1, [Define if you have the <db3/db.h> header file])
393   else
394     AC_MSG_ERROR([internal Berkeley DB directory not present, see INSTALL])
395   fi
396   ;;
397 esac
398
399 AC_SUBST([WITH_DB_LIB])
400
401 #=================
402 # Check for sqlite3 library.
403 AC_ARG_ENABLE(sqlite3, [  --enable-sqlite3        enable sqlite3 support],
404 [case "$enable_sqlite3" in
405 yes|no) ;;
406 *) AC_MSG_ERROR([invalid argument to --enable-sqlite3])
407   ;;
408 esac],
409 [enable_sqlite3=no])
410
411 WITH_SQLITE3_INCLUDE=
412 WITH_SQLITE3_LIB=
413 WITH_SQLITE3=no
414 AS_IF([test "$enable_sqlite3" = yes],[
415   AC_CHECK_HEADERS([sqlite3.h],
416   [ AC_CHECK_LIB(sqlite3, sqlite3_open, [
417       WITH_SQLITE3_INCLUDE=
418       WITH_SQLITE3_LIB="-lsqlite3"
419       WITH_SQLITE3=yes
420     ],[
421       AC_MSG_ERROR([missing libsqlite3])
422     ])
423   ],[
424     AC_MSG_ERROR([missing sqlite3.h])
425   ])
426 ])
427
428 AC_SUBST(WITH_SQLITE3_INCLUDE)
429 AC_SUBST(WITH_SQLITE3_LIB)
430 AM_CONDITIONAL([SQLITE3],[test "$WITH_SQLITE3" = yes])
431
432 #=================
433
434 dnl AmigaOS and IXEmul have a fork() dummy
435   case "$host" in
436     m68k-*-amigaos ) 
437         echo "Building for AmigaOS: using vfork() instead of fork()"; 
438         CFLAGS="$CFLAGS -Dfork=vfork" 
439         ;;
440   esac
441
442 AM_GNU_GETTEXT_VERSION([0.16.1])
443 AM_GNU_GETTEXT([external])
444
445 dnl Checks for header files we can live without.
446 AC_HEADER_STDC
447 AC_HEADER_MAJOR
448 AC_HEADER_DIRENT
449 AC_HEADER_TIME
450
451 AC_CHECK_HEADERS(locale.h)
452 AC_CHECK_HEADERS(limits.h)
453 AC_CHECK_HEADERS(fcntl.h getopt.h grp.h memory.h netdb.h pwd.h utime.h)
454
455 AC_CHECK_HEADERS(sys/ipc.h sys/socket.h sys/select.h)
456 AC_CHECK_HEADERS(sys/types.h sys/stdtypes.h)
457 AC_CHECK_HEADERS(sys/mman.h sys/resource.h sys/utsname.h sys/wait.h)
458
459 AC_CHECK_HEADERS(netinet/in_systm.h)
460 AC_CHECK_HEADERS(mntent.h sys/mnttab.h sys/systemcfg.h)
461 AC_CHECK_HEADERS(sys/mount.h sys/mntctl.h sys/param.h sys/vmount.h)
462 AC_CHECK_HEADERS(libio.h)
463 AC_CHECK_HEADERS(err.h mcheck.h)
464
465 AC_CHECK_HEADERS(glob.h)
466
467 dnl statfs portability fiddles.
468 dnl
469 dnl We should really emulate/steal sections of the statfs and struct statfs
470 dnl checks from GNU fileutils.
471 dnl
472 AC_MSG_CHECKING(for struct statfs)
473
474 dnl
475 dnl this is easier than nesting AC_TRY_COMPILEs...
476 dnl
477 found_struct_statfs=no
478
479 if test X$found_struct_statfs = Xno ; then
480 dnl Solaris 2.6+ wants to use statvfs
481 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
482 #ifdef HAVE_SYS_TYPES_H
483 #include <sys/types.h>
484 #endif
485 #include <sys/statvfs.h> ]], [[struct statvfs sfs;]])],[AC_MSG_RESULT(in sys/statvfs.h)
486         AC_DEFINE(STATFS_IN_SYS_STATVFS, 1,
487                 [statfs in <sys/statvfs.h> (for solaris 2.6+ systems)])
488         found_struct_statfs=yes],[])
489 fi
490
491 if test X$found_struct_statfs = Xno ; then
492 dnl first try including sys/vfs.h
493 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
494 #ifdef HAVE_SYS_TYPES_H
495 #include <sys/types.h>
496 #endif
497 #include <sys/vfs.h> ]], [[struct statfs sfs;]])],[AC_MSG_RESULT(in sys/vfs.h)
498         AC_DEFINE(STATFS_IN_SYS_VFS, 1, [statfs in <sys/vfs.h> (for linux systems)])
499         found_struct_statfs=yes],[])
500 fi
501
502 if test X$found_struct_statfs = Xno ; then
503 dnl ...next try including sys/mount.h
504 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
505 #ifdef HAVE_SYS_TYPES_H
506 #include <sys/types.h>
507 #endif
508 #ifdef HAVE_SYS_PARAM_H
509 #include <sys/param.h>
510 #endif
511 #include <sys/mount.h> ]], [[struct statfs sfs;]])],[AC_MSG_RESULT(in sys/mount.h)
512         AC_DEFINE(STATFS_IN_SYS_MOUNT, 1, [statfs in <sys/mount.h> (for Digital Unix 4.0D systems)])
513         found_struct_statfs=yes],[])
514 fi
515
516 if test X$found_struct_statfs = Xno ; then
517 dnl ...still no joy.  Try sys/statfs.h
518 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
519 #ifdef HAVE_SYS_TYPES_H
520 #include <sys/types.h>
521 #endif
522 #include <sys/statfs.h> ]], [[struct statfs sfs;]])],[AC_MSG_RESULT(in sys/statfs.h)
523         AC_DEFINE(STATFS_IN_SYS_STATFS, 1, [statfs in <sys/statfs.h> (for Irix 6.4 systems)])
524         found_struct_statfs=yes],[])
525 fi
526
527 if test X$found_struct_statfs = Xno ; then
528 dnl ...no luck.  Warn the user of impending doom.
529 AC_MSG_WARN(not found)
530 fi
531
532 dnl
533 dnl if we found the struct, see if it has the f_bavail member.  Some OSes
534 dnl don't, including IRIX 6.5+
535 dnl
536 if test X$found_struct_statfs = Xyes ; then
537 AC_MSG_CHECKING(for f_bavail member in struct statfs)
538 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
539 #ifdef HAVE_SYS_TYPES_H
540 #include <sys/types.h>
541 #endif
542 #if STATFS_IN_SYS_STATVFS
543 # include <sys/statvfs.h>
544   typedef struct statvfs STATFS_t;
545 #else
546   typedef struct statfs STATFS_t;
547 # if STATFS_IN_SYS_VFS
548 #  include <sys/vfs.h>
549 # elif STATFS_IN_SYS_MOUNT
550 #  include <sys/mount.h>
551 # elif STATFS_IN_SYS_STATFS
552 #  include <sys/statfs.h>
553 # endif
554 #endif ]], [[STATFS_t sfs;
555         sfs.f_bavail = 0;]])],[AC_MSG_RESULT(yes)
556         AC_DEFINE(STATFS_HAS_F_BAVAIL, 1, [Define if struct statfs has the f_bavail member])],[AC_MSG_RESULT(no)
557 ])
558 fi
559
560 if test X$found_struct_statfs = Xyes ; then
561 dnl
562 dnl now check to see if we have the 4-argument variant of statfs()
563 dnl this pretty much requires AC_RUN_IFELSE([AC_LANG_SOURCE([[]])],[],[],[])
564 dnl
565 AC_MSG_CHECKING([if statfs() requires 4 arguments])
566 AC_RUN_IFELSE([AC_LANG_SOURCE([[
567 #ifdef HAVE_SYS_TYPES_H
568 #include <sys/types.h>
569 #endif
570 #ifdef STATFS_IN_SYS_VFS
571 #include <sys/vfs.h>
572 #elif STATFS_IN_SYS_MOUNT
573 #include <sys/mouht.h>
574 #elif STATFS_IN_SYS_STATFS
575 #include <sys/statfs.h>
576 #endif
577 main() {
578         struct statfs sfs;
579         exit (statfs(".", &sfs, sizeof(sfs), 0));
580 }
581 ]])],[AC_MSG_RESULT(yes)
582         AC_DEFINE(STAT_STATFS4, 1, [Define if the statfs() call takes 4 arguments])],[AC_MSG_RESULT(no)],[AC_MSG_RESULT(no)
583 ])
584 fi
585
586 AC_C_INLINE
587
588 dnl look for libc features
589 PROVIDES_ERRNO=no
590 AC_MSG_CHECKING(if <netdb.h> defines h_errno)
591 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <netdb.h>]], [[printf("%d",h_errno)]])],[PROVIDES_ERRNO=yes],[])
592 AC_MSG_RESULT($PROVIDES_ERRNO)
593 if test $PROVIDES_ERRNO = yes; then
594         AC_DEFINE(HAVE_HERRNO, 1, [ Define as 1 if <netdb.h> defines h_errno])
595 fi
596
597 dnl If a system doesn't have S_IFSOCK, define it as 0 which will
598 dnl make S_ISSOCK always return false (nice, eh?)
599 AC_MSG_CHECKING(if <sys/stat.h> defines S_IFSOCK)
600 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/stat.h>]], [[printf("%d", S_IFSOCK)]])],[HAS_S_IFSOCK=yes],[HAS_S_IFSOCK=no])
601 AC_MSG_RESULT($HAS_S_IFSOCK)
602 if test $HAS_S_IFSOCK = yes; then
603         AC_DEFINE(HAVE_S_IFSOCK, 1, [Define as 1 if <sys/stat.h> defines S_IFSOCK])
604 fi
605
606 dnl Some Unix's are missing S_ISLNK, S_ISSOCK
607 AC_MSG_CHECKING(if <sys/stat.h> defines S_ISLNK)
608 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/stat.h>]], [[printf("%d", S_ISLNK(0755))]])],[HAS_S_ISLNK=yes],[HAS_S_ISLNK=no])
609 AC_MSG_RESULT($HAS_S_ISLNK)
610 if test $HAS_S_ISLNK = yes; then
611         AC_DEFINE(HAVE_S_ISLNK, 1, [Define as 1 if <sys/stat.h> defines S_ISLNK])
612 fi
613
614 AC_MSG_CHECKING(if <sys/stat.h> defines S_ISSOCK)
615 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/stat.h>]], [[printf("%d", S_ISSOCK(0755))]])],[HAS_S_ISSOCK=yes],[HAS_S_ISSOCK=no])
616 AC_MSG_RESULT($HAS_S_ISSOCK)
617 if test $HAS_S_ISSOCK = yes; then
618         AC_DEFINE(HAVE_S_ISSOCK, 1, [Define as 1 if <sys/stat.h> defines S_ISSOCK])
619 fi
620
621 AC_MSG_CHECKING(if timezone is defined)
622 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <time.h>]], [[printf("%ld", timezone)]])],[HAS_TIMEZONE=yes],[HAS_TIMEZONE=no])
623 AC_MSG_RESULT($HAS_TIMEZONE)
624
625 dnl Check for missing typedefs
626 AC_TYPE_MODE_T
627 AC_TYPE_OFF_T
628 AC_TYPE_PID_T
629 AC_TYPE_SIZE_T
630
631 dnl Checks for library functions.
632 AC_FUNC_VPRINTF
633 dnl XXX don't want to re-enable code that's been unused for years at this
634 dnl point, but should offer good performance improvements, check after
635 dnl 4.4.2.1...
636 dnl AC_FUNC_MMAP
637
638 AC_CHECK_FUNCS(getaddrinfo getnameinfo inet_aton)
639 AC_CHECK_FUNCS(mtrace)
640 AC_CHECK_FUNCS(strndup strerror)
641
642 AC_REPLACE_FUNCS(basename getcwd getwd)
643 AC_REPLACE_FUNCS(putenv realpath setenv)
644 AC_REPLACE_FUNCS(stpcpy stpncpy strcspn)
645 AC_REPLACE_FUNCS(strdup strtol strtoul strspn strstr)
646
647 AC_CHECK_FUNCS(__secure_getenv)
648
649 AC_CHECK_FUNCS(regcomp)
650
651 AC_CHECK_FUNCS(ftok)
652
653 AC_CHECK_FUNCS([mkstemp], [], [AC_MSG_ERROR([mkstemp() is required by rpm])])
654
655 dnl XXX Glob *is* broken on linux with libc5, solaris and possibly aix when
656 dnl %files gets something like
657 dnl     /usr/*/locale/*/LC_MESSAGES/*.mo
658 dnl (Note: more than one asterisk in glob pattern.)
659 dnl
660 dnl XXX Glob is "fixed" in glibc-2.3.3-61, but the cost is that
661 dnl dangling symlinks are no longer globbed. Always use the internal glob.
662 AC_DEFINE(USE_GNU_GLOB, 1, [Use the included glob.c?])
663 AC_LIBOBJ(glob)
664 AC_LIBOBJ(fnmatch)
665
666 dnl check if python is requested
667 AC_ARG_ENABLE(python, [  --enable-python         build rpm python bindings ],
668 [case "$enable_python" in
669 yes|no) ;;
670 *) AC_MSG_ERROR([invalid argument to --enable-python])
671   ;;
672 esac],
673 [enable_python=no])
674
675 AS_IF([test "$enable_python" = yes],[
676 # rpm-python is based on python-2.5, 
677 # with legacy hacks to allow building against python >= 2.3
678   AM_PATH_PYTHON([2.3],[
679     WITH_PYTHON_INCLUDE=`${PYTHON} -c 'from distutils.sysconfig import *; print get_python_inc()'`
680     WITH_PYTHON_SUBPACKAGE=1
681     save_CPPFLAGS="$CPPFLAGS"
682     CPPFLAGS="$CPPFLAGS -I$WITH_PYTHON_INCLUDE"
683     AC_CHECK_HEADER([Python.h],[],
684       [AC_MSG_ERROR([missing Python.h])
685       ])
686     CPPFLAGS="$save_CPPFLAGS"
687     save_LIBS="$LIBS"
688     AC_SEARCH_LIBS([Py_Main],[python${PYTHON_VERSION} python],[
689       WITH_PYTHON_LIB="$ac_res"
690     ],[AC_MSG_ERROR([missing python library])
691     ])
692     LIBS="$save_LIBS"
693   ])
694 ],[
695     WITH_PYTHON_INCLUDE=
696     WITH_PYTHON_LIB=
697     WITH_PYTHON_SUBPACKAGE=0
698 ])
699
700 AC_SUBST(WITH_PYTHON_INCLUDE)
701 AC_SUBST(WITH_PYTHON_LIB)
702
703 AM_CONDITIONAL(PYTHON,[test "$WITH_PYTHON_SUBPACKAGE" = 1])
704
705 AC_PATH_PROG(DOXYGEN, doxygen, no)
706 dnl
707 dnl Only build internal API + source hacking docs on request
708 dnl
709 AC_ARG_WITH(hackingdocs, [  --with-hackingdocs          build rpm hacking docs ],,[with_hackingdocs=no])
710
711 case "$with_hackingdocs" in
712 auto)
713   AS_IF([test "$DOXYGEN" = no],[with_hackingdocs=no],[with_hackingdocs=no])
714   ;;
715 yes)
716   AS_IF([test "$DOXYGEN" = no],
717     [AC_MSG_ERROR([rpm hacking docs eeds doxygen in PATH])])
718   ;;
719 esac
720 AC_CHECK_PROG(HAVE_DOT,[dot],[YES],[NO])
721
722 WITH_SELINUX_LIB=
723 AC_ARG_WITH(selinux, [  --with-selinux          build with selinux support ],
724 [case "$with_selinux" in
725 yes|no) ;;
726 *) AC_MSG_ERROR([invalid argument to --with-selinux])
727   ;;
728 esac],
729 [with_selinux=no])
730
731 AS_IF([test "$with_selinux" = yes],[
732   AC_CHECK_HEADER([selinux/selinux.h],[
733     AC_CHECK_LIB(selinux,[is_selinux_enabled],[with_selinux=yes],[
734       AC_MSG_ERROR([--with-selinux given, but libselinux not found])])
735   ],[
736     AC_MSG_ERROR([--with-selinux given, but selinux/selinux.h not found])
737   ])
738 ])
739
740 AS_IF([test "$with_selinux" = yes],[
741   AC_DEFINE(WITH_SELINUX, 1, [Build with selinux support?])
742   WITH_SELINUX_LIB="-lselinux"
743 ])
744 AC_SUBST(WITH_SELINUX_LIB)
745 AM_CONDITIONAL(SELINUX,[test "$with_selinux" = yes])
746
747 WITH_LUA_LIB=
748 WITH_LUA_INCLUDE=
749 AC_ARG_WITH(lua, [  --with-lua              build with lua support ],,[with_lua=yes])
750 AS_IF([test "$with_lua" = yes],[
751   AC_CHECK_HEADER([lua.h],[
752     AC_CHECK_LIB(lua,[luaL_openlibs],[with_lua=yes],[
753       AC_MSG_ERROR([--with-lua given, but liblua not found])
754     ], 
755     [-lm])
756   ],[
757       AC_MSG_ERROR([--with-lua given, but lua.h not found])
758   ])
759 ])
760
761 AS_IF([test "$with_lua" = yes],[
762   AC_DEFINE(WITH_LUA, 1, [Build with lua support?])
763   WITH_LUA_INCLUDE=
764   WITH_LUA_LIB="-llua -lm" 
765 ])
766 AC_SUBST(WITH_LUA_LIB)
767 AC_SUBST(WITH_LUA_INCLUDE)
768 AM_CONDITIONAL(WITH_LUAEXT,[test "$with_lua" = yes])
769
770 with_dmalloc=no
771 AC_ARG_WITH(dmalloc, [  --with-dmalloc          build with dmalloc debugging support ])
772 if test "$with_dmalloc" = yes ; then
773   AC_DEFINE(DMALLOC, 1, [Build with dmalloc support?])
774   LIBS="$LIBS -ldmalloc"
775 fi
776
777 AC_CHECK_FUNCS(setlocale)
778
779 AC_CHECK_FUNCS(getpassphrase)
780
781 AC_CHECK_FUNC(getmntent, AC_DEFINE(HAVE_GETMNTENT, 1, [Define if you have the getmntent() function]), [
782   AC_CHECK_FUNC(mntctl, AC_DEFINE(HAVE_MNTCTL, 1, [Define as 1 if you have mntctl() (only aix?)]),[
783     AC_CHECK_FUNC(getmntinfo, AC_DEFINE(HAVE_GETMNTINFO, 1, [Define as 1 if you have getmntinfo() (Mac OS X)]), [
784       AC_CHECK_FUNC(getmntinfo_r, AC_DEFINE(HAVE_GETMNTINFO_R, 1, [Define as 1 if you have getmntinfo_r() (only osf?)]), [
785         AC_CHECK_LIB(c_r, getmntinfo_r, [LIBS="$LIBS -lc_r"; 
786                                         AC_DEFINE(HAVE_GETMNTINFO_R, 1, [Define as 1 if you have getmntinfo_r() (only osf?)])], [
787                  AC_DEFINE([USE_GETMNTENT], 1, [Defined if getmntent replacement is used])
788                  AC_LIBOBJ(getmntent)])
789       ])
790     ])
791   ])
792 ])
793
794 AC_CHECK_FUNC(lchown,
795    [__CHOWN_RHF="%{__chown} -Rhf"
796     __CHGRP_RHF="%{__chgrp} -Rhf"
797     AC_DEFINE(HAVE_LCHOWN, 1, [Define as 1 if you have lchown()])],
798    [__CHOWN_RHF="%{__chown} -Rf"
799     __CHGRP_RHF="%{__chgrp} -Rf"
800     dnl Does chown() follow symlinks? This should be a good enough test.
801     AC_MSG_CHECKING(whether chown() follows symlinks)
802     AC_ARG_ENABLE([broken-chown],
803     [  --enable-broken-chown   this system's chown follows symbolic links], 
804             result=$enableval, result=unknown)
805     if echo "$build" | ${EGREP} "(aix)|(hpux)|(linux)" > /dev/null ; then
806         result=yes
807     elif echo "$build" | ${EGREP} "(nextstep)" > /dev/null ; then
808         result=no
809     fi
810     if test $result = unknown; then
811         if test `${__ID} | cut -f2 -d\= | cut -f1 -d\(` = 0; then
812             rm -f foo bar
813             touch foo
814             ln -s foo bar
815             ${__CHOWN} 10 bar
816             if test `ls -l foo | awk '{print $3}'` != "root"; then
817                 result=yes
818             else
819                 result=no
820             fi
821             ${__RM} -f foo bar
822         else
823             AC_MSG_CHECKING((cannot check by non-root user))
824             result=no
825         fi
826     fi
827
828     AC_MSG_RESULT($result)
829     if test $result = yes; then
830             AC_DEFINE(CHOWN_FOLLOWS_SYMLINK, 1, [Define as 1 if chown() follows symlinks and you don't have lchown()])
831     fi])
832 AC_SUBST(__CHOWN_RHF)
833 AC_SUBST(__CHGRP_RHF)
834
835 if echo "$host_os" | grep sco > /dev/null; then
836         echo "hacking things up for sco"
837         AC_DEFINE(NEED_STRINGS_H, 1, [Define as one if we need to include <strings.h> (along with <string.h>)])
838         AC_DEFINE(HAVE_STRUCT_MNTTAB, 1,
839         [Define as 1 if you have "struct mnttab" (only sco?)])
840 elif echo "$host_os" | grep sunos > /dev/null; then
841         echo "hacking things up for sunos"
842         CFLAGS="$CFLAGS -D__USE_FIXED_PROTOTYPES__"
843         AC_DEFINE(NEED_STRINGS_H, 1, [Define as one if we need to include <strings.h> (along with <string.h>)])
844         AC_DEFINE(NEED_MYREALLOC, 1, [Define as 1 if we need myrealloc])
845         AC_LIBOBJ(myrealloc)
846 fi
847
848 #
849 # get rid of the 4-th tuple, if config.guess returned "linux-gnu" for host_os
850 #
851 host_os_gnu=-gnu
852 if echo "$host_os" | grep '.*-gnulibc1' > /dev/null ; then
853         host_os=`echo "${host_os}" | sed 's/-gnulibc1$//'`
854 fi
855 if echo "$host_os" | grep '.*-gnueabi' > /dev/null ; then
856         host_os=`echo "${host_os}" | sed 's/-gnueabi$//'`
857         host_os_gnu=-gnueabi
858 fi
859 if echo "$host_os" | grep '.*-gnu' > /dev/null ; then
860         host_os=`echo "${host_os}" | sed 's/-gnu$//'`
861 fi
862
863 changequote(<, >)
864 host_os_exact="${host_os}"
865 host_os_major=`echo "${host_os}" | sed 's/\..*$//'`
866 host_os_noversion=`echo "${host_os}" | sed 's/[0-9]*\..*$//'`
867 changequote([, ])
868
869 rm -f ./find-provides
870 if test -f ${srcdir}/autodeps/${host_cpu}-${host_os_exact}.prov ; then
871         echo "using ${srcdir}/autodeps/${host_cpu}-${host_os_exact}.prov for automatic provides generation"
872     ln -s ${srcdir}/autodeps/${host_cpu}-${host_os_exact}.prov ./find-provides
873 elif test -f ${srcdir}/autodeps/${host_os_exact}.prov ; then
874         echo "using ${srcdir}/autodeps/${host_os_exact}.prov for automatic provides generation"
875     ln -s ${srcdir}/autodeps/${host_os_exact}.prov ./find-provides
876 elif test -f ${srcdir}/autodeps/${host_os_major}.prov ; then
877         echo "using ${srcdir}/autodeps/${host_os_major}.prov for automatic provides generation"
878     ln -s ${srcdir}/autodeps/${host_os_major}.prov ./find-provides
879 elif test -f ${srcdir}/autodeps/${host_os_noversion}.prov ; then
880         echo "using ${srcdir}/autodeps/${host_os_noversion}.prov for automatic provides generation"
881     ln -s ${srcdir}/autodeps/${host_os_noversion}.prov ./find-provides
882 else
883     echo "*** no default provides information is available for ${host_os_noversion}"
884     ln -s ${srcdir}/autodeps/none ./find-provides
885 fi
886
887 rm -f ./find-requires
888 if test -f ${srcdir}/autodeps/${host_cpu}-${host_os_exact}.req ; then
889         echo "using ${srcdir}/autodeps/${host_cpu}-${host_os_exact}.req for automatic requires generation"
890     ln -s ${srcdir}/autodeps/${host_cpu}-${host_os_exact}.req ./find-requires
891 elif test -f ${srcdir}/autodeps/${host_os_exact}.req ; then
892         echo "using ${srcdir}/autodeps/${host_os_exact}.req for automatic requires generation"
893     ln -s ${srcdir}/autodeps/${host_os_exact}.req ./find-requires
894 elif test -f ${srcdir}/autodeps/${host_os_major}.req ; then
895         echo "using ${srcdir}/autodeps/${host_os_major}.req for automatic requires generation"
896     ln -s ${srcdir}/autodeps/${host_os_major}.req ./find-requires
897 elif test -f ${srcdir}/autodeps/${host_os_noversion}.req ; then
898         echo "using ${srcdir}/autodeps/${host_os_noversion}.req for automatic requires generation"
899     ln -s ${srcdir}/autodeps/${host_os_noversion}.req ./find-requires
900 else
901     echo "*** no default requires information is available for ${host_os_noversion}"
902     ln -s ${srcdir}/autodeps/none ./find-requires
903 fi
904
905 dnl Determine the canonical arch-vendor-os for the host machine
906 case "${host_cpu}" in
907 *86)            RPMCANONCOLOR=0; RPMCANONARCH=i386 ;;
908 ia32e*)         RPMCANONCOLOR=3; RPMCANONARCH=ia32e ;;
909 amd64*)         RPMCANONCOLOR=3; RPMCANONARCH=amd64 ;;
910 x86_64*)        RPMCANONCOLOR=3; RPMCANONARCH=x86_64 ;;
911 alpha*)         RPMCANONCOLOR=0; RPMCANONARCH=alpha ;;
912 sparc64*)       RPMCANONCOLOR=3; RPMCANONARCH=sparc64 ;;
913 sparc*)         RPMCANONCOLOR=3; RPMCANONARCH=sparc ;;
914 ia64*)          RPMCANONCOLOR=2; RPMCANONARCH=ia64 ;;
915 s390x*)         RPMCANONCOLOR=3; RPMCANONARCH=s390x ;;
916 s390*)          RPMCANONCOLOR=0; RPMCANONARCH=s390 ;;
917 powerpc64*|ppc64*)      RPMCANONCOLOR=3; RPMCANONARCH=ppc64 ;;
918 powerpc*|ppc*)  RPMCANONCOLOR=0; RPMCANONARCH=ppc ;;
919 arm*)           RPMCANONCOLOR=0; RPMCANONARCH=arm ;;
920 mipsel*)        RPMCANONCOLOR=0; RPMCANONARCH=mipsel ;;
921 mips*)          RPMCANONCOLOR=0; RPMCANONARCH=mips ;;
922 m68k*)          RPMCANONCOLOR=0; RPMCANONARCH=m68k ;;
923 sh3*)           RPMCANONCOLOR=0; RPMCANONARCH=sh3 ;;
924 sh4*)           RPMCANONCOLOR=0; RPMCANONARCH=sh4 ;;
925 *)              RPMCANONCOLOR=0; RPMCANONARCH=unknown ;;
926 esac
927 case "${host_os_noversion}" in
928 mint)           RPMCANONARCH=m68kmint ;;
929 esac
930 RPMCANONVENDOR="$build_vendor"
931 case "${build_vendor}" in
932 unknown|pc|ibm|redhat|pld|mandrake|conectiva|lvr|yellowdog|caos|suse)
933         test -f /etc/redhat-release &&          RPMCANONVENDOR=redhat
934         test -f /etc/SuSE-release &&            RPMCANONVENDOR=suse
935         test -f /etc/pld-release &&             RPMCANONVENDOR=pld
936         test -f /etc/mandrake-release &&        RPMCANONVENDOR=mandrake
937         test -f /etc/conectiva-release &&       RPMCANONVENDOR=conectiva
938         test -f /etc/lvr-release &&             RPMCANONVENDOR=lvr
939         test -f /etc/yellowdog-release &&       RPMCANONVENDOR=yellowdog
940         test -f /etc/caos-release &&            RPMCANONVENDOR=caos
941         ;;
942 esac
943 RPMCANONOS="$host_os_noversion"
944 RPMCANONGNU="$host_os_gnu"
945 AC_SUBST(RPMCANONCOLOR)
946 AC_SUBST(RPMCANONARCH)
947 AC_SUBST(RPMCANONVENDOR)
948 AC_SUBST(RPMCANONOS)
949 AC_SUBST(RPMCANONGNU)
950 AC_DEFINE_UNQUOTED([RPMCANONVENDOR],["${RPMCANONVENDOR}"],[canonical vendor])
951
952 if test X"$prefix" = XNONE ; then
953     usrprefix="$ac_default_prefix"
954 else
955     usrprefix=$prefix
956 fi
957
958 RPMCONFIGDIR="`echo ${usrprefix}/lib/rpm`"
959 AC_SUBST(RPMCONFIGDIR)
960
961 AC_SUBST(OBJDUMP)
962
963 if test "$with_external_db" = no; then
964     AC_CONFIG_SUBDIRS(db3)
965 fi
966
967 AM_CONDITIONAL([WITH_INTERNAL_DB],[test "$with_external_db" = no])
968 AM_CONDITIONAL([DOXYGEN],[test "$DOXYGEN" != no])
969 AM_CONDITIONAL([HACKINGDOCS],[test "$with_hackingdocs" = yes])
970
971 AC_PATH_PROG(AUTOM4TE,autom4te,:)
972
973 AS_IF([test "$ac_cv_header_stdint_h" = "yes"],[
974 AC_DEFINE([__RPM_USES_STDINT_H__],[1],[if rpm uses stdint.h])
975 ])
976
977 AC_SUBST([dirstamp],[\${am__leading_dot}dirstamp])
978
979 AC_CONFIG_FILES([Makefile
980         rpmio/Makefile lib/Makefile build/Makefile
981         po/Makefile.in scripts/Makefile 
982         misc/Makefile 
983         doc/Makefile
984         python/Makefile
985         luaext/Makefile
986         tests/Makefile
987   ])
988 AC_OUTPUT