2003-04-05 Havoc Pennington <hp@pobox.com>
[platform/upstream/dbus.git] / configure.in
1 dnl -*- mode: m4 -*-
2 AC_PREREQ(2.52)
3
4 AC_INIT(dbus/dbus.h)
5
6 AM_INIT_AUTOMAKE(dbus, 0.6)
7
8 AM_CONFIG_HEADER(config.h)
9
10 # Honor aclocal flags
11 ACLOCAL="$ACLOCAL $ACLOCAL_FLAGS"
12
13 GETTEXT_PACKAGE=dbus-1
14 AC_SUBST(GETTEXT_PACKAGE)
15 AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE",[The name of the gettext domain])
16
17  ## must come before we use the $USE_MAINTAINER_MODE variable later
18 AM_MAINTAINER_MODE
19
20 AC_PROG_CC
21 AC_PROG_CXX
22 AC_ISC_POSIX
23 AC_HEADER_STDC
24 AM_PROG_LIBTOOL
25
26 AC_ARG_ENABLE(qt,      [  --enable-qt      enable Qt-friendly client library],enable_qt=$enableval,enable_qt=auto)
27 AC_ARG_ENABLE(glib,    [  --enable-glib    enable GLib-friendly client library],enable_glib=$enableval,enable_glib=auto)
28 AC_ARG_ENABLE(tests,   [  --enable-tests   enable unit test code],enable_tests=$enableval,enable_tests=$USE_MAINTAINER_MODE)
29 AC_ARG_ENABLE(ansi,    [  --enable-ansi    enable -ansi -pedantic gcc flags],enable_ansi=$enableval,enable_ansi=no)
30 AC_ARG_ENABLE(verbose-mode, [  --enable-verbose-mode support verbose debug mode],enable_verbose_mode=$enableval,enable_verbose_mode=yes)
31 AC_ARG_ENABLE(asserts, [  --enable-asserts include assertion checks],enable_asserts=$enableval,enable_asserts=yes)
32 AC_ARG_ENABLE(gcov,    [  --enable-gcov compile with coverage profiling instrumentation (gcc only)],enable_gcov=$enableval,enable_gcov=no)
33
34 AC_ARG_WITH(xml,          [  --with-xml=[libxml/expat] XML library to use])
35 AC_ARG_WITH(init-scripts, [  --with-init-scripts=[redhat] Style of init scripts to install])
36
37 dnl DBUS_BUILD_TESTS controls unit tests built in to .c files 
38 dnl and also some stuff in the test/ subdir
39 AM_CONDITIONAL(DBUS_BUILD_TESTS, test x$enable_tests = xyes)
40 if test x$enable_tests = xyes; then
41     AC_DEFINE(DBUS_BUILD_TESTS,1,[Build test code])
42 fi
43
44 if test x$enable_verbose_mode = xyes; then
45     AC_DEFINE(DBUS_ENABLE_VERBOSE_MODE,1,[Support a verbose mode])
46 fi
47 if test x$enable_asserts = xno; then
48     AC_DEFINE(DBUS_DISABLE_ASSERT,1,[Disable assertion checking])
49 fi
50
51 #### gcc warning flags
52
53 if test "x$GCC" = "xyes"; then
54   changequote(,)dnl
55   case " $CFLAGS " in
56   *[\ \ ]-Wall[\ \      ]*) ;;
57   *) CFLAGS="$CFLAGS -Wall" ;;
58   esac
59
60   case " $CFLAGS " in
61   *[\ \ ]-Wchar-subscripts[\ \  ]*) ;;
62   *) CFLAGS="$CFLAGS -Wchar-subscripts" ;;
63   esac
64
65   case " $CFLAGS " in
66   *[\ \ ]-Wmissing-declarations[\ \     ]*) ;;
67   *) CFLAGS="$CFLAGS -Wmissing-declarations" ;;
68   esac
69
70   case " $CFLAGS " in
71   *[\ \ ]-Wmissing-prototypes[\ \       ]*) ;;
72   *) CFLAGS="$CFLAGS -Wmissing-prototypes" ;;
73   esac
74
75   case " $CFLAGS " in
76   *[\ \ ]-Wnested-externs[\ \   ]*) ;;
77   *) CFLAGS="$CFLAGS -Wnested-externs" ;;
78   esac
79
80   case " $CFLAGS " in
81   *[\ \ ]-Wpointer-arith[\ \    ]*) ;;
82   *) CFLAGS="$CFLAGS -Wpointer-arith" ;;
83   esac
84
85   case " $CFLAGS " in
86   *[\ \ ]-Wcast-align[\ \       ]*) ;;
87   *) CFLAGS="$CFLAGS -Wcast-align" ;;
88   esac
89
90   case " $CFLAGS " in
91   *[\ \ ]-Wsign-compare[\ \     ]*) ;;
92   *) CFLAGS="$CFLAGS -Wsign-compare" ;;
93   esac
94
95   if test "x$enable_ansi" = "xyes"; then
96     case " $CFLAGS " in
97     *[\ \       ]-ansi[\ \      ]*) ;;
98     *) CFLAGS="$CFLAGS -ansi" ;;
99     esac
100
101     case " $CFLAGS " in
102     *[\ \       ]-pedantic[\ \  ]*) ;;
103     *) CFLAGS="$CFLAGS -pedantic" ;;
104     esac
105   fi
106   if test x$enable_gcov = xyes; then
107     case " $CFLAGS " in
108     *[\ \       ]-fprofile-arcs[\ \     ]*) ;;
109     *) CFLAGS="$CFLAGS -fprofile-arcs" ;;
110     esac
111     case " $CFLAGS " in
112     *[\ \       ]-ftest-coverage[\ \    ]*) ;;
113     *) CFLAGS="$CFLAGS -ftest-coverage" ;;
114     esac
115
116     ## remove optimization
117     CFLAGS=`echo "$CFLAGS" | sed -e 's/-O[0-9]*//g'`
118   fi
119   changequote([,])dnl
120 else
121   if test x$enable_gcov = xyes; then
122     AC_MSG_ERROR([--enable-gcov can only be used with gcc])
123   fi
124 fi
125
126 if test x$enable_gcov = xyes; then
127      ## so that config.h changes when you toggle gcov support
128      AC_DEFINE_UNQUOTED(DBUS_GCOV_ENABLED, 1, [Defined if gcov is enabled to force a rebuild due to config.h changing])
129 fi
130 AM_CONDITIONAL(DBUS_GCOV_ENABLED, test x$enable_gcov = xyes)
131
132 #### Integer sizes 
133
134 AC_CHECK_SIZEOF(char)
135 AC_CHECK_SIZEOF(short)
136 AC_CHECK_SIZEOF(long)
137 AC_CHECK_SIZEOF(int)
138 AC_CHECK_SIZEOF(void *)
139 AC_CHECK_SIZEOF(long long)
140 AC_CHECK_SIZEOF(__int64)
141
142 ### this is only used in decode-gcov.c right now
143 case 8 in
144 $ac_cv_sizeof_int)
145   dbusint64=int
146   ;;
147 $ac_cv_sizeof_long)
148   dbusint64=long
149   ;;
150 $ac_cv_sizeof_long_long)
151   dbusint64='long long'
152   ;;
153 $ac_cv_sizeof___int64)
154   dbusint64=__int64
155   ;;
156 esac
157
158 AC_DEFINE_UNQUOTED(DBUS_INT64_TYPE, $dbusint64, [64-bit integer type])
159
160 ## byte order
161 AC_C_BIGENDIAN
162
163 AC_CHECK_LIB(socket,socket)
164 AC_CHECK_LIB(nsl,gethostbyname)
165
166 AC_CHECK_FUNCS(vsnprintf vasprintf nanosleep usleep poll setenv unsetenv socketpair getgrouplist)
167
168 AC_CHECK_HEADERS(execinfo.h, [AC_CHECK_FUNCS(backtrace)])
169
170 AC_CACHE_CHECK([for posix getpwnam_r],
171                 ac_cv_func_posix_getpwnam_r,
172                 [AC_TRY_RUN([
173 #include <errno.h>
174 #include <pwd.h>
175 int main () { 
176     char buffer[10000];
177     struct passwd pwd, *pwptr = &pwd;
178     int error;
179     errno = 0;
180     error = getpwnam_r ("", &pwd, buffer, 
181                         sizeof (buffer), &pwptr);
182    return (error < 0 && errno == ENOSYS) 
183            || error == ENOSYS; 
184 }               ],
185         [ac_cv_func_posix_getpwnam_r=yes],
186         [ac_cv_func_posix_getpwnam_r=no])])
187 if test "$ac_cv_func_posix_getpwnam_r" = yes; then
188         AC_DEFINE(HAVE_POSIX_GETPWNAM_R,1,
189                 [Have POSIX function getpwnam_r])
190 else
191         AC_CACHE_CHECK([for nonposix getpwnam_r],
192                 ac_cv_func_nonposix_getpwnam_r,
193                 [AC_TRY_LINK([#include <pwd.h>],
194                         [char buffer[10000];
195                         struct passwd pwd;
196                         getpwnam_r ("", &pwd, buffer, 
197                                         sizeof (buffer));],
198                         [ac_cv_func_nonposix_getpwnam_r=yes],
199                         [ac_cv_func_nonposix_getpwnam_r=no])])
200                 if test "$ac_cv_func_nonposix_getpwnam_r" = yes; then
201                 AC_DEFINE(HAVE_NONPOSIX_GETPWNAM_R,1,
202                         [Have non-POSIX function getpwnam_r])
203         fi
204 fi
205
206 dnl check for writev header and writev function so we're 
207 dnl good to go if HAVE_WRITEV gets defined.
208 AC_CHECK_HEADERS(sys/uio.h, [AC_CHECK_FUNCS(writev)])
209
210 dnl check for flavours of varargs macros (test from GLib)
211 AC_MSG_CHECKING(for ISO C99 varargs macros in C)
212 AC_TRY_COMPILE([],[
213 int a(int p1, int p2, int p3);
214 #define call_a(...) a(1,__VA_ARGS__)
215 call_a(2,3);
216 ],dbus_have_iso_c_varargs=yes,dbus_have_iso_c_varargs=no)
217 AC_MSG_RESULT($dbus_have_iso_c_varargs)
218
219 AC_MSG_CHECKING(for GNUC varargs macros)
220 AC_TRY_COMPILE([],[
221 int a(int p1, int p2, int p3);
222 #define call_a(params...) a(1,params)
223 call_a(2,3);
224 ],dbus_have_gnuc_varargs=yes,dbus_have_gnuc_varargs=no)
225 AC_MSG_RESULT($dbus_have_gnuc_varargs)
226
227 dnl Output varargs tests
228 if test x$dbus_have_iso_c_varargs = xyes; then
229     AC_DEFINE(HAVE_ISO_VARARGS,1,[Have ISO C99 varargs macros])
230 fi
231 if test x$dbus_have_gnuc_varargs = xyes; then
232     AC_DEFINE(HAVE_GNUC_VARARGS,1,[Have GNU-style varargs macros])
233 fi
234
235 dnl Check for various credentials.
236 AC_MSG_CHECKING(for struct cmsgcred)
237 AC_TRY_COMPILE([
238 #include <sys/types.h>
239 #include <sys/socket.h>
240 ],[
241 struct cmsgcred cred;
242
243 cred.cmcred_pid = 0;
244 ],dbus_have_struct_cmsgcred=yes,dbus_have_struct_cmsgcred=no)
245 AC_MSG_RESULT($dbus_have_struct_cmsgcred)
246
247 if test x$dbus_have_struct_cmsgcred = xyes; then
248     AC_DEFINE(HAVE_CMSGCRED,1,[Have cmsgcred structure])
249 fi
250
251
252 #### Sort out XML library
253
254 # see what we have
255 AC_CHECK_LIB(expat, XML_ParserCreate_MM, 
256              [ AC_CHECK_HEADERS(expat.h, have_expat=true, have_expat=false) ],
257              have_expat=false)
258
259 PKG_CHECK_MODULES(LIBXML, libxml-2.0, have_libxml=true, have_libxml=false)
260
261 # see what we want to use
262 dbus_use_libxml=false
263 dbus_use_expat=false
264 if test x$with_xml = xexpat; then
265         dbus_use_expat=true
266         if ! $have_expat ; then
267            AC_MSG_ERROR([Explicitly requested expat but expat not found])
268         fi
269 elif test x$with_xml = xlibxml; then
270         dbus_use_libxml=true
271         if ! $have_libxml ; then
272            AC_MSG_ERROR([Explicitly requested libxml but libxml not found])
273         fi
274 else
275         ### expat is the default because libxml can't currently survive 
276         ### our brutal OOM-handling unit test setup.
277         ### http://bugzilla.gnome.org/show_bug.cgi?id=109368
278         if $have_expat ; then
279                 with_xml=expat
280                 dbus_use_expat=true
281         elif $have_libxml ; then
282                 with_xml=libxml
283                 dbus_use_libxml=true
284         else
285                 AC_MSG_ERROR([No XML library found, check config.log for failed attempts])
286         fi
287 fi
288
289 AM_CONDITIONAL(DBUS_USE_EXPAT, $dbus_use_expat)
290 AM_CONDITIONAL(DBUS_USE_LIBXML, $dbus_use_libxml)
291
292 if $dbus_use_expat; then
293    XML_LIBS=-lexpat
294    XML_CFLAGS=
295 fi
296 if $dbus_use_libxml; then
297    XML_LIBS=$LIBXML_LIBS
298    XML_CFLAGS=$LIBXML_CFLAGS
299 fi
300
301 #### Set up final flags
302 DBUS_CLIENT_CFLAGS=
303 DBUS_CLIENT_LIBS=
304 AC_SUBST(DBUS_CLIENT_CFLAGS)
305 AC_SUBST(DBUS_CLIENT_LIBS)
306
307 DBUS_BUS_CFLAGS=$XML_CFLAGS
308 DBUS_BUS_LIBS=$XML_LIBS
309 AC_SUBST(DBUS_BUS_CFLAGS)
310 AC_SUBST(DBUS_BUS_LIBS)
311
312 DBUS_TEST_CFLAGS=
313 DBUS_TEST_LIBS=
314 AC_SUBST(DBUS_TEST_CFLAGS)
315 AC_SUBST(DBUS_TEST_LIBS)
316
317 # Glib detection
318 PKG_CHECK_MODULES(DBUS_GLIB, glib-2.0, have_glib=yes, have_glib=no)
319 PKG_CHECK_MODULES(DBUS_GLIB_THREADS, glib-2.0 gthread-2.0, have_glib_threads=yes, have_glib_threads=no)
320
321 if test x$have_glib = xno ; then
322     AC_MSG_WARN([GLib development libraries not found])
323 fi
324
325 if test x$enable_glib = xyes; then
326     if test x$have_glib = xno; then
327         AC_MSG_ERROR([GLib explicitly required, and GLib development libraries not found])
328     fi
329 fi
330
331 if test x$enable_glib = xno; then
332    have_glib=no;
333 fi
334
335 AM_CONDITIONAL(HAVE_GLIB, test x$have_glib = xyes)
336 AM_CONDITIONAL(HAVE_GLIB_THREADS, test x$have_glib_threads = xyes)
337
338 dnl GLib flags
339 AC_SUBST(DBUS_GLIB_CFLAGS)
340 AC_SUBST(DBUS_GLIB_LIBS)
341 AC_SUBST(DBUS_GLIB_THREADS_LIBS)
342
343 # Qt detection
344 have_qt=no
345 if test -n "$QTDIR" -a -f $QTDIR/include/qglobal.h; then
346     have_qt=yes
347     DBUS_QT_CXXFLAGS=-I$QTDIR/include
348 fi
349
350 dnl linking to kdecore will give us a bit of help from libtool
351 if (! kde-config >& /dev/null); then
352     have_qt=no
353 else
354     kdelibs=`kde-config --install lib --expandvars 2>/dev/null`
355     if test -z $kdelibs -a -f $kdelibs/libkdecore.la; then
356         have_qt=no
357     else
358         DBUS_QT_LIBS=$kdelibs/libkdecore.la
359     fi
360 fi
361
362 if test x$have_qt = xno ; then
363     AC_MSG_WARN([Qt development libraries not found])
364 fi
365
366 if test x$enable_qt = xyes; then
367     if test x$have_qt = xno; then
368         AC_MSG_ERROR([Qt integration explicitly required, and Qt libraries not found])
369     fi
370 fi
371
372 if test x$enable_qt = xno; then
373    have_qt=no;
374 fi
375
376 AM_CONDITIONAL(HAVE_QT, test x$have_qt = xyes)
377
378 dnl Qt flags
379 AC_SUBST(DBUS_QT_CXXFLAGS)
380 AC_SUBST(DBUS_QT_LIBS)
381
382 ##### Set up location for system bus socket
383 ## name of socket relative to localstatedir
384 DBUS_SYSTEM_SOCKET=run/dbus/system_bus_socket
385 AC_SUBST(DBUS_SYSTEM_SOCKET)
386
387 #### find the actual value for $prefix that we'll end up with
388 REAL_PREFIX=
389 if test "x$prefix" = "xNONE"; then
390   REAL_PREFIX=$ac_default_prefix
391 else
392   REAL_PREFIX=$prefix
393 fi
394
395 #### Have to go $localstatedir->$prefix/var->/usr/local/var   
396 #### someone please fix this a better way...
397 LOCALSTATEDIR_TMP="$localstatedir"
398 old_prefix=$prefix
399 prefix=$REAL_PREFIX
400 EXPANDED_LOCALSTATEDIR=`eval echo $LOCALSTATEDIR_TMP`
401 prefix=$old_prefix
402 AC_SUBST(EXPANDED_LOCALSTATEDIR)
403
404 SYSCONFDIR_TMP="$sysconfdir"
405 old_prefix=$prefix
406 prefix=$REAL_PREFIX
407 EXPANDED_SYSCONFDIR=`eval echo $SYSCONFDIR_TMP`
408 prefix=$old_prefix
409 AC_SUBST(EXPANDED_SYSCONFDIR)
410
411 BINDIR_TMP="$bindir"
412 old_prefix=$prefix
413 prefix=$REAL_PREFIX
414 EXPANDED_BINDIR=`eval echo $BINDIR_TMP`
415 prefix=$old_prefix
416 AC_SUBST(EXPANDED_BINDIR)
417
418 #### Sort out init scripts
419
420 if test x$with_init_scripts = x; then
421         if test -f /etc/redhat-release || test -f $EXPANDED_SYSCONFDIR/redhat-release ; then
422                 with_init_scripts=redhat
423         else
424                 with_init_scripts=none
425         fi
426 fi
427
428 AM_CONDITIONAL(DBUS_INIT_SCRIPTS_RED_HAT, test x$with_init_scripts = xredhat)
429
430 #### Tell tests where to find certain stuff in builddir
431 ABSOLUTE_TOP_BUILDDIR=`cd ${ac_top_builddir}. && pwd`
432
433 AC_DEFUN(TEST_PATH, [
434 TEST_$1=${ABSOLUTE_TOP_BUILDDIR}/test/$2
435 AC_DEFINE_UNQUOTED(TEST_$1, "$TEST_$1",
436                    [Full path to test file test/$2 in builddir])
437 AC_SUBST(TEST_$1)
438 ])
439
440 TEST_PATH(SERVICE_DIR, data/valid-service-files)
441 TEST_PATH(SERVICE_BINARY, test-service)
442 TEST_PATH(EXIT_BINARY, test-exit)
443 TEST_PATH(SEGFAULT_BINARY, test-segfault)
444 TEST_PATH(SLEEP_FOREVER_BINARY, test-sleep-forever)
445
446 AC_OUTPUT([
447 Doxyfile
448 bus/system.conf
449 bus/session.conf
450 bus/messagebus
451 Makefile
452 dbus/Makefile
453 glib/Makefile
454 qt/Makefile
455 bus/Makefile
456 test/Makefile
457 doc/Makefile
458 dbus-1.0.pc
459 dbus-glib-1.0.pc
460 test/data/valid-config-files/debug-allow-all.conf
461 test/data/valid-service-files/debug-echo.service
462 ])
463
464 dnl ==========================================================================
465 echo "
466                     D-BUS $VERSION
467                   ==============
468
469         prefix:                 ${prefix}
470         source code location:   ${srcdir}
471         compiler:               ${CC}
472         cflags:                 ${CFLAGS}
473
474         Maintainer mode:        ${USE_MAINTAINER_MODE}
475         gcc coverage profiling: ${enable_gcov}
476         Building unit tests:    ${enable_tests}
477         Building verbose mode:  ${enable_verbose_mode}
478         Building assertions:    ${enable_asserts}
479         Building Qt bindings:   ${have_qt}
480         Building GLib bindings: ${have_glib}
481         Using XML parser:       ${with_xml}
482         System bus socket:      ${EXPANDED_LOCALSTATEDIR}/${DBUS_SYSTEM_SOCKET}
483         Init scripts style:     ${with_init_scripts}
484 "
485
486 if test x$enable_tests = xyes; then
487         echo "NOTE: building with unit tests increases the size of the installed library and renders it insecure."
488 fi
489 if test x$enable_gcov = xyes; then
490         echo "NOTE: building with coverage profiling is definitely for developers only."
491 fi
492 if test x$enable_verbose_mode = xyes; then
493         echo "NOTE: building with verbose mode increases library size, may slightly increase security risk, and may cause a slight performance decrease, but aids debugging."
494 fi
495 if test x$enable_asserts = xyes; then
496         echo "NOTE: building with assertions increases library size, but will help a lot when tracking down bugs in software using D-BUS."
497 fi