Auto*foo hackery to use rpm pkgconfig if available, resort to old
[apt.git] / configure.ac
1 dnl Process this file with autoconf to produce a configure script.
2
3 AC_PREREQ(2.59)
4 AC_INIT([apt],[0.5.15lorg3.93],[apt-rpm@lists.laiskiainen.org])
5 dnl Check the archs, we want the target type.
6 AC_CONFIG_AUX_DIR([buildlib])
7 AC_CANONICAL_HOST
8 AC_CONFIG_SRCDIR([AUTHORS.RPM])
9 AM_INIT_AUTOMAKE([foreign subdir-objects dist-bzip2 1.9.5])
10 AM_MAINTAINER_MODE
11
12 AC_CONFIG_HEADER([include/config.h:buildlib/config.h.in])
13 AC_CONFIG_HEADER([include/apt-pkg/aptconf.h:apt-pkg/aptconf.h.in])
14 AC_PROG_LIBTOOL
15
16 dnl Check our C compiler
17 AC_PROG_CC
18 AM_PROG_CC_C_O
19 AC_ISC_POSIX
20
21 dnl Check for other programs
22 AC_PROG_CXX
23 AC_PROG_CPP
24
25 dnl Checks for sockets
26 SAVE_LIBS="$LIBS"
27 LIBS=""
28 AC_SEARCH_LIBS(gethostbyname,nsl)
29 AC_SEARCH_LIBS(connect,socket)
30 SOCKETLIBS="$LIBS"
31 AC_SUBST(SOCKETLIBS)
32 LIBS="$SAVE_LIBS"
33  
34 dnl Checks for pthread -- disabled due to glibc bugs jgg
35 dnl AC_CHECK_LIB(pthread, pthread_create,[AC_DEFINE(HAVE_PTHREAD) PTHREADLIB="-lpthread"])
36 AC_SUBST(PTHREADLIB)
37 dnl if test "$PTHREADLIB" != "-lpthread"; then
38 dnl   AC_MSG_ERROR(failed: I need posix threads, pthread)
39 dnl fi
40
41 dnl Apt acquirer methods need bz2 and libz
42 AC_CHECK_LIB(bz2,BZ2_bzopen, [],
43         [AC_MSG_ERROR([Can't find libbz2 library])])
44 AC_CHECK_LIB(z,gzopen, [],
45         [AC_MSG_ERROR([Can't find libz library])])
46
47 dnl See if we have pkgconfig for rpm, resort to old behavior if not
48 PKG_CHECK_MODULES([RPM], [rpm], [
49       RPM_VERSION_RAW=`pkg-config --modversion rpm` 
50       AC_DEFINE_UNQUOTED([HAVE_RPM],1,[Define if RPM backend is available])
51       CPPFLAGS="$RPM_CFLAGS $CPPFLAGS"
52       LDFLAGS="$RPM_LIBS $LDFLAGS"
53    ], [
54       AC_PATH_PROG(RPM_PATH,rpm,none)
55       if test "$RPM_PATH" = "none"; then
56          AC_MSG_ERROR([RPM executable was not found in your system])
57       else
58          AC_DEFINE_UNQUOTED([HAVE_RPM],1,[Define if RPM backend is available])
59          RPM_VERSION_RAW=`LANG= LC_ALL= $RPM_PATH --version | sed 's/^RPM version //'`
60       fi
61    ]
62 )
63
64 AC_MSG_CHECKING(for RPM version)
65 RPM_VERSION_MAJOR=`echo $RPM_VERSION_RAW | cut -d. -f1`
66 RPM_VERSION_MINOR=`echo $RPM_VERSION_RAW | cut -d. -f2`
67 RPM_VERSION_MICRO=`echo $RPM_VERSION_RAW | cut -d. -f3`
68 if test -z "$RPM_VERSION_MAJOR" -o -z "$RPM_VERSION_MINOR"; then
69    AC_MSG_ERROR([can't parse RPM version])
70 fi
71 if test -z "$RPM_VERSION_MICRO"; then
72    RPM_VERSION_MICRO=0
73 fi
74 AC_DEFINE_UNQUOTED([RPM_VERSION_MAJOR],$RPM_VERSION_MAJOR,[RPM major version])
75 AC_DEFINE_UNQUOTED([RPM_VERSION_MINOR],$RPM_VERSION_MINOR,[RPM minor version])
76 AC_DEFINE_UNQUOTED([RPM_VERSION_MICRO],$RPM_VERSION_MICRO,[RPM micro version])
77 AC_DEFINE_UNQUOTED([RPM_VERSION],
78       [((RPM_VERSION_MAJOR<<16)|(RPM_VERSION_MINOR<<8)|RPM_VERSION_MICRO)],
79       [Define to the RPM version])
80 AC_DEFINE_UNQUOTED([RPM_VERSION_RAW],"$RPM_VERSION_RAW",[RPM raw version])
81 AC_MSG_RESULT($RPM_VERSION_RAW)
82
83 dnl No pkgconfig, manually check for RPM libraries and headers
84 if test -z "$RPM_LIBS"; then
85    AC_CHECK_HEADERS(db1/db.h)
86
87    if test $RPM_VERSION_MAJOR -lt 4; then
88       RPM_LIBS="-lrpm -lz -lbz2 -lpopt"
89    else
90       AC_CHECK_LIB(rpmdb,rpmdbOpen,
91          [RPMDBLIBS="-lrpmdb"],
92          [RPMDBLIBS="-ldb-3.1"],
93          [-lrpm -lrpmio -lz -lbz2 -lpopt])
94       RPM_LIBS="-lrpm $RPMDBLIBS -lrpmio -lz -lbz2 -lpopt"
95    fi
96    AC_MSG_CHECKING(for RPM libraries)
97    AC_MSG_RESULT($RPM_LIBS)
98    AC_SUBST(RPM_LIBS)
99 fi
100
101 dnl Various rpm header checks..
102 AC_CHECK_HEADER(rpm/rpmlib.h, [],
103            [AC_MSG_ERROR([Can't find rpmlib.h])])
104 AC_CHECK_HEADERS([rpm/rpmsx.h rpm/misc.h rpm/rpmcallback.h rpm/rpmcb.h \
105              rpm/rpmmessages.h])
106
107 dnl Various rpm variant capability checks
108 AC_MSG_CHECKING(for rpmdsGetconf)
109 AC_EGREP_HEADER(rpmdsGetconf, rpm/rpmds.h,
110         [AC_MSG_RESULT(yes) AC_DEFINE(RPM_HAVE_DSGETCONF, 1, [rpmdsGetconf]) ],
111         [AC_MSG_RESULT(no) ])
112
113 AC_MSG_CHECKING(for rpmdsRpmlib)
114 AC_EGREP_HEADER(rpmdsRpmlib, rpm/rpmds.h,
115         [AC_MSG_RESULT(yes) AC_DEFINE(RPM_HAVE_DSRPMLIB, 1, [rpmdsRpmlib]) ],
116         [AC_MSG_RESULT(no) ])
117         
118 AC_MSG_CHECKING(for fdigests)
119 AC_EGREP_HEADER(RPMTRANS_FLAG_NOFDIGESTS, rpm/rpmlib.h,
120         [AC_MSG_RESULT(yes) AC_DEFINE(RPM_HAVE_FDIGESTS, 1, [fdigests]) ],
121         [AC_MSG_RESULT(no) ])
122
123 dnl Can we use g++ hash_map?
124 AH_TEMPLATE(APT_WITH_GNU_HASH_MAP,
125             [Define to 1 if you want to use the g++ hash_map extension])
126 AC_MSG_CHECKING(for g++ hash_map extension)
127 AC_LANG_PUSH([C++])
128 AC_TRY_LINK(
129 [
130 #include <ext/hash_map>
131 using namespace __gnu_cxx;
132 ],[hash_map<char*,hash<char*> > HashMap;
133 ],[AC_DEFINE_UNQUOTED(APT_WITH_GNU_HASH_MAP, 1) AC_MSG_RESULT(yes)
134 ],[AC_MSG_RESULT(no)])
135 AC_LANG_POP([C++])
136
137 dnl sqlite3
138 SAVE_LIBS="$LIBS"
139 LIBS=""
140 AC_SEARCH_LIBS([sqlite3_open], [sqlite3], [], [have_sqlite3="no"])
141 if test "x$have_sqlite3" != "xno"; then
142    AC_DEFINE([WITH_SQLITE3], [1], [yes])
143    SQLITE3LIBS="$LIBS"
144 fi
145 LIBS="$SAVE_LIBS"
146
147 AM_CONDITIONAL([WITH_SQLITE3], [test ! "x$have_sqlite3" = "no"])
148 AC_SUBST(SQLITE3LIBS)
149
150 dnl CNC:2003-03-20
151 AC_MSG_CHECKING(for --disable-scripts)
152 AC_ARG_ENABLE([scripts],
153               AS_HELP_STRING([--disable-scripts],[disable the lua script extension system]),
154               [enable_scripts="$enableval"],[enable_scripts="yes"])
155 if test "$enable_scripts" != "no"; then
156   AC_MSG_RESULT(no)
157   AC_DEFINE(APT_WITH_LUA, 1, 
158             [Define if you want to enable the extension system]) 
159 else
160   AC_MSG_RESULT(yes)
161 fi
162 AM_CONDITIONAL(WITH_LUA, test "$enable_scripts" != "no")
163
164 dnl SELinux support
165 AC_MSG_CHECKING(for --disable-selinux)
166 AC_ARG_ENABLE([selinux],
167               AS_HELP_STRING([--disable-selinux],
168                              [disable SELinux support]),
169               [enable_selinux="$enableval"],[enable_selinux="yes"])
170 if test "$enable_selinux" != "no"; then
171   AC_MSG_RESULT(no)
172   AC_DEFINE(WITH_SELINUX, 1, 
173             [Define if you want to enable SELinux support]) 
174 else
175   AC_MSG_RESULT(yes)
176 fi
177 AM_CONDITIONAL(WITH_SELINUX, test "$enable_selinux" != "no")
178
179
180 dnl Repomd support
181 AC_MSG_CHECKING(for --disable-repomd)
182 AC_ARG_ENABLE([repomd],
183               AS_HELP_STRING([--disable-repomd],
184                              [disable repomd support]),
185               [enable_repomd="$enableval"],[enable_repomd="yes"])
186 if test "$enable_repomd" != "no"; then
187   AC_MSG_RESULT(no)
188   AC_DEFINE(APT_WITH_REPOMD, 1, [Define if you want to enable repomd support]) 
189   ## xmlReadFile is not available before 2.6.0
190   PKG_CHECK_MODULES([LIBXML2],[libxml-2.0 >= 2.6])
191   RPM_LIBS="$LIBXML2_LIBS $RPM_LIBS"
192   CPPFLAGS="$LIBXML2_CFLAGS $CPPFLAGS"
193   ## FIXME: Conditionalize this properly. We can support xml repomd without 
194   ## sqlite and repodb with libxml2 older than 2.6. In addition, rollback
195   ## will be using sqlite as well, we only want to check for it once.
196   RPM_LIBS="$RPM_LIBS $SQLITE3LIBS"
197 else
198   AC_MSG_RESULT(yes)
199 fi
200 AM_CONDITIONAL(WITH_REPOMD, test "$enable_repomd" != "no")
201
202 dnl Before configuring libtool check for --enable-static-progs option
203 AC_MSG_CHECKING(for --enable-static-progs)
204 AC_ARG_ENABLE(static-progs,
205               AS_HELP_STRING([--enable-static-progs],
206                              [build completely static (standalone) binaries]),
207               [enable_static_progs="$enableval"],[enable_static_progs="no"])
208 AM_CONDITIONAL(COMPILE_STATIC, test "$enable_static_progs" = "yes")
209 if test "$enable_static_progs" = "yes" ; then
210   AC_MSG_RESULT(yes)
211 else
212   AC_MSG_RESULT(no)
213 fi
214
215 dnl Check for apt-shell dependencies
216 AC_CHECK_LIB(ncurses,tputs,
217   [AC_CHECK_HEADER(readline/readline.h,
218      [AC_CHECK_LIB(readline,rl_completion_matches,
219         [compile_aptshell=yes],,[-lncurses])])])
220 AM_CONDITIONAL(COMPILE_APTSHELL, test "$compile_aptshell" = "yes")
221
222 dnl Converts the ARCH to be something singular for this general CPU family
223 dnl This is often the dpkg architecture string.
224 AH_TEMPLATE(COMMON_CPU, [Define the common CPU])
225 AH_TEMPLATE(COMMON_OS, [Define the common OS])
226 AC_MSG_CHECKING(system architecture)
227 archset="`awk \" ! /^#|^\\\$/ { if(match(\\\"$host_cpu\\\",\\\"^\\\"\\\$1\\\"\\\$\\\")) {print \\\$2; exit}}\" $srcdir/buildlib/archtable`"
228 if test "x$archset" = "x"; then
229   AC_MSG_ERROR(failed: use --host=)
230 fi
231 AC_MSG_RESULT($archset)
232 AC_DEFINE_UNQUOTED(COMMON_CPU,"$archset")
233
234 dnl Get a common name for the host OS - this is primarily only for HURD and is
235 dnl non fatal if it fails
236 AC_MSG_CHECKING(system OS)
237 osset="`awk \" ! /^#|^\\\$/ {if (match(\\\"$host_vendor-$host_os\\\",\\\$1)) {print \\\$2; exit}}\" $srcdir/buildlib/ostable`"
238 AC_MSG_RESULT($osset)
239 AC_DEFINE_UNQUOTED(COMMON_OS,"$osset")
240
241 dnl We use C99 types if at all possible
242 AC_CACHE_CHECK([for C99 integer types],c9x_ints,[
243     AC_TRY_COMPILE([#include <inttypes.h>],
244                    [uint8_t Foo1;uint16_t Foo2;uint32_t Foo3;],
245                    c9x_ints=yes,c9x_ints=no)])
246
247 AC_C_BIGENDIAN
248
249 dnl Check the sizes etc. of the architecture
250 dnl Cross compilers can either get a real C library or preload the cache
251 dnl with their size values.
252 AC_CHECK_SIZEOF(char)
253 AC_CHECK_SIZEOF(int)
254 AC_CHECK_SIZEOF(short)
255 AC_CHECK_SIZEOF(long)
256
257 dnl Single Unix Spec statvfs
258 AC_CHECK_FUNC(statvfs,[have_statvfs=yes])
259
260 dnl Arg, linux and bsd put their statfs function in different places
261 AH_TEMPLATE(HAVE_SYS_VFS_H, [Define to 1 if sys/vfs.h is available])
262 AH_TEMPLATE(HAVE_SYS_MOUNT_H, [Define to 1 if sys/mount.h is available])
263 if test "$have_statvfs" != "yes"; then
264    AC_EGREP_HEADER(statfs,sys/vfs.h,[AC_DEFINE(HAVE_SYS_VFS_H)],[
265         AC_EGREP_HEADER(statfs,sys/mount.h,[AC_DEFINE(HAVE_SYS_MOUNT_H)],
266                         [AC_MSG_ERROR(failed: Need statvfs)])
267    ])
268 fi
269
270 dnl We should use the real timegm function if we have it.
271 AH_TEMPLATE(HAVE_TIMEGM, [Define to 1 if timegm is available])
272 AC_CHECK_FUNC(timegm,AC_DEFINE(HAVE_TIMEGM))
273 AC_SUBST(HAVE_TIMEGM)
274
275 dnl HP-UX sux..
276 AH_TEMPLATE(NEED_SOCKLEN_T_DEFINE, [Define to 1 if socket_t is missing])
277 AC_MSG_CHECKING(for missing socklen_t)
278 AC_EGREP_HEADER(socklen_t, sys/socket.h,[AC_MSG_RESULT(no)],[
279         AC_DEFINE(NEED_SOCKLEN_T_DEFINE)
280         NEED_SOCKLEN_T_DEFINE=yes
281         AC_MSG_RESULT(missing.)])
282 AC_SUBST(NEED_SOCKLEN_T_DEFINE)
283
284 dnl HP-UX needs -d_XOPEN_SOURCE_EXTENDED for h_errno
285 AC_MSG_CHECKING(for h_errno)
286 AC_EGREP_HEADER(h_errno, netdb.h, [AC_MSG_RESULT(normal)],
287    [CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE_EXTENDED"
288     AC_EGREP_HEADER(h_errno, netdb.h, 
289        [AC_MSG_RESULT(needs _XOPEN_SOURCE_EXTENDED)],
290        [AC_MSG_ERROR("not found.")])
291    ])
292
293 dnl Check for debiandoc
294 dnl AC_PATH_PROG(DEBIANDOC_HTML,debiandoc2html)
295 dnl AC_PATH_PROG(DEBIANDOC_TEXT,debiandoc2text)
296
297 AC_PATH_PROG([GPG],[gpg],[/usr/bin/gpg])
298
299 AM_GNU_GETTEXT_VERSION([0.14.5])
300 AM_GNU_GETTEXT([external])
301
302 dnl ah_NUM_PROCS
303 dnl rc_GLIBC_VER
304 dnl rc_LIBSTDCPP_VER
305 dnl ah_GCC3DEP
306
307 AC_CONFIG_FILES([
308           Makefile
309           lua/Makefile
310           apt-pkg/Makefile
311           apt-pkg/libapt-pkg.pc
312           methods/Makefile
313           cmdline/Makefile
314           tools/Makefile
315           doc/Makefile
316           test/Makefile
317           po/Makefile.in
318           ])
319 AC_CONFIG_LINKS([include/apti18n.h:buildlib/gettext.h])
320
321 AS_IF([test "$c9x_ints" = "no"],[
322 AC_CONFIG_LINKS([include/inttypes.h:buildlib/inttypes.h])
323 ])
324
325 AS_IF([test "$have_statvfs" != "yes"],[
326 AC_CONFIG_LINKS([include/statvfs.h:buildlib/statvfs.h])
327 ])
328
329 AS_IF([test "$NEED_SOCKLEN_T_DEFINE" = "yes"],[
330 AC_CONFIG_LINKS([include/netdb.h:buildlib/netdb.h])
331 ])
332
333 AC_OUTPUT