2003-03-31 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
36 dnl DBUS_BUILD_TESTS controls unit tests built in to .c files 
37 dnl and also some stuff in the test/ subdir
38 AM_CONDITIONAL(DBUS_BUILD_TESTS, test x$enable_tests = xyes)
39 if test x$enable_tests = xyes; then
40     AC_DEFINE(DBUS_BUILD_TESTS,1,[Build test code])
41 fi
42
43 if test x$enable_verbose_mode = xyes; then
44     AC_DEFINE(DBUS_ENABLE_VERBOSE_MODE,1,[Support a verbose mode])
45 fi
46 if test x$enable_asserts = xno; then
47     AC_DEFINE(DBUS_DISABLE_ASSERT,1,[Disable assertion checking])
48 fi
49
50 #### gcc warning flags
51
52 if test "x$GCC" = "xyes"; then
53   changequote(,)dnl
54   case " $CFLAGS " in
55   *[\ \ ]-Wall[\ \      ]*) ;;
56   *) CFLAGS="$CFLAGS -Wall" ;;
57   esac
58
59   case " $CFLAGS " in
60   *[\ \ ]-Wchar-subscripts[\ \  ]*) ;;
61   *) CFLAGS="$CFLAGS -Wchar-subscripts" ;;
62   esac
63
64   case " $CFLAGS " in
65   *[\ \ ]-Wmissing-declarations[\ \     ]*) ;;
66   *) CFLAGS="$CFLAGS -Wmissing-declarations" ;;
67   esac
68
69   case " $CFLAGS " in
70   *[\ \ ]-Wmissing-prototypes[\ \       ]*) ;;
71   *) CFLAGS="$CFLAGS -Wmissing-prototypes" ;;
72   esac
73
74   case " $CFLAGS " in
75   *[\ \ ]-Wnested-externs[\ \   ]*) ;;
76   *) CFLAGS="$CFLAGS -Wnested-externs" ;;
77   esac
78
79   case " $CFLAGS " in
80   *[\ \ ]-Wpointer-arith[\ \    ]*) ;;
81   *) CFLAGS="$CFLAGS -Wpointer-arith" ;;
82   esac
83
84   case " $CFLAGS " in
85   *[\ \ ]-Wcast-align[\ \       ]*) ;;
86   *) CFLAGS="$CFLAGS -Wcast-align" ;;
87   esac
88
89   case " $CFLAGS " in
90   *[\ \ ]-Wsign-compare[\ \     ]*) ;;
91   *) CFLAGS="$CFLAGS -Wsign-compare" ;;
92   esac
93
94   if test "x$enable_ansi" = "xyes"; then
95     case " $CFLAGS " in
96     *[\ \       ]-ansi[\ \      ]*) ;;
97     *) CFLAGS="$CFLAGS -ansi" ;;
98     esac
99
100     case " $CFLAGS " in
101     *[\ \       ]-pedantic[\ \  ]*) ;;
102     *) CFLAGS="$CFLAGS -pedantic" ;;
103     esac
104   fi
105   if test x$enable_gcov = xyes; then
106     case " $CFLAGS " in
107     *[\ \       ]-fprofile-arcs[\ \     ]*) ;;
108     *) CFLAGS="$CFLAGS -fprofile-arcs" ;;
109     esac
110     case " $CFLAGS " in
111     *[\ \       ]-ftest-coverage[\ \    ]*) ;;
112     *) CFLAGS="$CFLAGS -ftest-coverage" ;;
113     esac
114
115     ## remove optimization
116     CFLAGS=`echo "$CFLAGS" | sed -e 's/-O[0-9]*//g'`
117   fi
118   changequote([,])dnl
119 else
120   if test x$enable_gcov = xyes; then
121     AC_MSG_ERROR([--enable-gcov can only be used with gcc])
122   fi
123 fi
124
125 #### Assorted checks
126
127 AC_CHECK_SIZEOF(char)
128 AC_CHECK_SIZEOF(short)
129 AC_CHECK_SIZEOF(long)
130 AC_CHECK_SIZEOF(int)
131 AC_CHECK_SIZEOF(void *)
132 AC_CHECK_SIZEOF(long long)
133 AC_CHECK_SIZEOF(__int64)
134
135 ## byte order
136 AC_C_BIGENDIAN
137
138 AC_CHECK_LIB(socket,socket)
139 AC_CHECK_LIB(nsl,gethostbyname)
140
141 AC_CHECK_FUNCS(vsnprintf vasprintf nanosleep usleep poll setenv socketpair getgrouplist)
142
143 AC_CHECK_HEADERS(execinfo.h, [AC_CHECK_FUNCS(backtrace)])
144
145 AC_CACHE_CHECK([for posix getpwnam_r],
146                 ac_cv_func_posix_getpwnam_r,
147                 [AC_TRY_RUN([
148 #include <errno.h>
149 #include <pwd.h>
150 int main () { 
151     char buffer[10000];
152     struct passwd pwd, *pwptr = &pwd;
153     int error;
154     errno = 0;
155     error = getpwnam_r ("", &pwd, buffer, 
156                         sizeof (buffer), &pwptr);
157    return (error < 0 && errno == ENOSYS) 
158            || error == ENOSYS; 
159 }               ],
160         [ac_cv_func_posix_getpwnam_r=yes],
161         [ac_cv_func_posix_getpwnam_r=no])])
162 if test "$ac_cv_func_posix_getpwnam_r" = yes; then
163         AC_DEFINE(HAVE_POSIX_GETPWNAM_R,1,
164                 [Have POSIX function getpwnam_r])
165 else
166         AC_CACHE_CHECK([for nonposix getpwnam_r],
167                 ac_cv_func_nonposix_getpwnam_r,
168                 [AC_TRY_LINK([#include <pwd.h>],
169                         [char buffer[10000];
170                         struct passwd pwd;
171                         getpwnam_r ("", &pwd, buffer, 
172                                         sizeof (buffer));],
173                         [ac_cv_func_nonposix_getpwnam_r=yes],
174                         [ac_cv_func_nonposix_getpwnam_r=no])])
175                 if test "$ac_cv_func_nonposix_getpwnam_r" = yes; then
176                 AC_DEFINE(HAVE_NONPOSIX_GETPWNAM_R,1,
177                         [Have non-POSIX function getpwnam_r])
178         fi
179 fi
180
181 dnl check for writev header and writev function so we're 
182 dnl good to go if HAVE_WRITEV gets defined.
183 AC_CHECK_HEADERS(sys/uio.h, [AC_CHECK_FUNCS(writev)])
184
185 dnl check for flavours of varargs macros (test from GLib)
186 AC_MSG_CHECKING(for ISO C99 varargs macros in C)
187 AC_TRY_COMPILE([],[
188 int a(int p1, int p2, int p3);
189 #define call_a(...) a(1,__VA_ARGS__)
190 call_a(2,3);
191 ],dbus_have_iso_c_varargs=yes,dbus_have_iso_c_varargs=no)
192 AC_MSG_RESULT($dbus_have_iso_c_varargs)
193
194 AC_MSG_CHECKING(for GNUC varargs macros)
195 AC_TRY_COMPILE([],[
196 int a(int p1, int p2, int p3);
197 #define call_a(params...) a(1,params)
198 call_a(2,3);
199 ],dbus_have_gnuc_varargs=yes,dbus_have_gnuc_varargs=no)
200 AC_MSG_RESULT($dbus_have_gnuc_varargs)
201
202 dnl Output varargs tests
203 if test x$dbus_have_iso_c_varargs = xyes; then
204     AC_DEFINE(HAVE_ISO_VARARGS,1,[Have ISO C99 varargs macros])
205 fi
206 if test x$dbus_have_gnuc_varargs = xyes; then
207     AC_DEFINE(HAVE_GNUC_VARARGS,1,[Have GNU-style varargs macros])
208 fi
209
210 dnl Check for various credentials.
211 AC_MSG_CHECKING(for struct cmsgcred)
212 AC_TRY_COMPILE([
213 #include <sys/types.h>
214 #include <sys/socket.h>
215 ],[
216 struct cmsgcred cred;
217
218 cred.cmcred_pid = 0;
219 ],dbus_have_struct_cmsgcred=yes,dbus_have_struct_cmsgcred=no)
220 AC_MSG_RESULT($dbus_have_struct_cmsgcred)
221
222 if test x$dbus_have_struct_cmsgcred = xyes; then
223     AC_DEFINE(HAVE_CMSGCRED,1,[Have cmsgcred structure])
224 fi
225
226
227 #### Sort out XML library
228
229 # see what we have
230 AC_CHECK_LIB(expat, XML_ParserCreate_MM, 
231              [ AC_CHECK_HEADERS(expat.h, have_expat=true, have_expat=false) ],
232              have_expat=false)
233
234 PKG_CHECK_MODULES(LIBXML, libxml-2.0, have_libxml=true, have_libxml=false)
235
236 # see what we want to use
237 dbus_use_libxml=false
238 dbus_use_expat=false
239 if test x$with_xml = xexpat; then
240         dbus_use_expat=true
241         if ! $have_expat ; then
242            AC_MSG_ERROR([Explicitly requested expat but expat not found])
243         fi
244 elif test x$with_xml = xlibxml; then
245         dbus_use_libxml=true
246         if ! $have_libxml ; then
247            AC_MSG_ERROR([Explicitly requested libxml but libxml not found])
248         fi
249 else
250         ### expat is the default because libxml can't currently survive 
251         ### our brutal OOM-handling unit test setup.
252         ### http://bugzilla.gnome.org/show_bug.cgi?id=109368
253         if $have_expat ; then
254                 with_xml=expat
255                 dbus_use_expat=true
256         elif $have_libxml ; then
257                 with_xml=libxml
258                 dbus_use_libxml=true
259         else
260                 AC_MSG_ERROR([No XML library found, check config.log for failed attempts])
261         fi
262 fi
263
264 AM_CONDITIONAL(DBUS_USE_EXPAT, $dbus_use_expat)
265 AM_CONDITIONAL(DBUS_USE_LIBXML, $dbus_use_libxml)
266
267 if $dbus_use_expat; then
268    XML_LIBS=-lexpat
269    XML_CFLAGS=
270 fi
271 if $dbus_use_libxml; then
272    XML_LIBS=$LIBXML_LIBS
273    XML_CFLAGS=$LIBXML_CFLAGS
274 fi
275
276 #### Set up final flags
277 DBUS_CLIENT_CFLAGS=
278 DBUS_CLIENT_LIBS=
279 AC_SUBST(DBUS_CLIENT_CFLAGS)
280 AC_SUBST(DBUS_CLIENT_LIBS)
281
282 DBUS_BUS_CFLAGS=$XML_CFLAGS
283 DBUS_BUS_LIBS=$XML_LIBS
284 AC_SUBST(DBUS_BUS_CFLAGS)
285 AC_SUBST(DBUS_BUS_LIBS)
286
287 DBUS_TEST_CFLAGS=
288 DBUS_TEST_LIBS=
289 AC_SUBST(DBUS_TEST_CFLAGS)
290 AC_SUBST(DBUS_TEST_LIBS)
291
292 # Glib detection
293 PKG_CHECK_MODULES(DBUS_GLIB, glib-2.0, have_glib=yes, have_glib=no)
294 PKG_CHECK_MODULES(DBUS_GLIB_THREADS, glib-2.0 gthread-2.0, have_glib_threads=yes, have_glib_threads=no)
295
296 if test x$have_glib = xno ; then
297     AC_MSG_WARN([GLib development libraries not found])
298 fi
299
300 if test x$enable_glib = xyes; then
301     if test x$have_glib = xno; then
302         AC_MSG_ERROR([GLib explicitly required, and GLib development libraries not found])
303     fi
304 fi
305
306 if test x$enable_glib = xno; then
307    have_glib=no;
308 fi
309
310 AM_CONDITIONAL(HAVE_GLIB, test x$have_glib = xyes)
311 AM_CONDITIONAL(HAVE_GLIB_THREADS, test x$have_glib_threads = xyes)
312
313 dnl GLib flags
314 AC_SUBST(DBUS_GLIB_CFLAGS)
315 AC_SUBST(DBUS_GLIB_LIBS)
316 AC_SUBST(DBUS_GLIB_THREADS_LIBS)
317
318 # Qt detection
319 have_qt=no
320 if test -n "$QTDIR" -a -f $QTDIR/include/qglobal.h; then
321     have_qt=yes
322     DBUS_QT_CXXFLAGS=-I$QTDIR/include
323 fi
324
325 dnl linking to kdecore will give us a bit of help from libtool
326 if (! kde-config >& /dev/null); then
327     have_qt=no
328 else
329     kdelibs=`kde-config --install lib --expandvars 2>/dev/null`
330     if test -z $kdelibs -a -f $kdelibs/libkdecore.la; then
331         have_qt=no
332     else
333         DBUS_QT_LIBS=$kdelibs/libkdecore.la
334     fi
335 fi
336
337 if test x$have_qt = xno ; then
338     AC_MSG_WARN([Qt development libraries not found])
339 fi
340
341 if test x$enable_qt = xyes; then
342     if test x$have_qt = xno; then
343         AC_MSG_ERROR([Qt integration explicitly required, and Qt libraries not found])
344     fi
345 fi
346
347 if test x$enable_qt = xno; then
348    have_qt=no;
349 fi
350
351 AM_CONDITIONAL(HAVE_QT, test x$have_qt = xyes)
352
353 dnl Qt flags
354 AC_SUBST(DBUS_QT_CXXFLAGS)
355 AC_SUBST(DBUS_QT_LIBS)
356
357 ##### Set up location for system bus socket
358 ## name of socket relative to localstatedir
359 DBUS_SYSTEM_SOCKET=run/dbus/system_bus_socket
360 AC_SUBST(DBUS_SYSTEM_SOCKET)
361
362 #### find the actual value for $prefix that we'll end up with
363 REAL_PREFIX=
364 if test "x$prefix" = "xNONE"; then
365   REAL_PREFIX=$ac_default_prefix
366 else
367   REAL_PREFIX=$prefix
368 fi
369
370 #### Have to go $localstatedir->$prefix/var->/usr/local/var   
371 #### someone please fix this a better way...
372 LOCALSTATEDIR_TMP="$localstatedir"
373 old_prefix=$prefix
374 prefix=$REAL_PREFIX
375 EXPANDED_LOCALSTATEDIR=`eval echo $LOCALSTATEDIR_TMP`
376 prefix=$old_prefix
377 AC_SUBST(EXPANDED_LOCALSTATEDIR)
378
379 AC_OUTPUT([
380 Doxyfile
381 bus/system.conf
382 bus/session.conf
383 Makefile
384 dbus/Makefile
385 glib/Makefile
386 qt/Makefile
387 bus/Makefile
388 test/Makefile
389 doc/Makefile
390 dbus-1.0.pc
391 dbus-glib-1.0.pc
392 ])
393
394 dnl ==========================================================================
395 echo "
396                     D-BUS $VERSION
397                   ==============
398
399         prefix:                 ${prefix}
400         source code location:   ${srcdir}
401         compiler:               ${CC}
402         cflags:                 ${CFLAGS}
403
404         Maintainer mode:        ${USE_MAINTAINER_MODE}
405         gcc coverage profiling: ${enable_gcov}
406         Building unit tests:    ${enable_tests}
407         Building verbose mode:  ${enable_verbose_mode}
408         Building assertions:    ${enable_asserts}
409         Building Qt bindings:   ${have_qt}
410         Building GLib bindings: ${have_glib}
411         Using XML parser:       ${with_xml}
412         System bus socket:      ${EXPANDED_LOCALSTATEDIR}/${DBUS_SYSTEM_SOCKET}
413 "
414
415 if test x$enable_tests = xyes; then
416         echo "NOTE: building with unit tests increases the size of the installed library and renders it insecure."
417 fi
418 if test x$enable_gcov = xyes; then
419         echo "NOTE: building with coverage profiling is definitely for developers only."
420 fi
421 if test x$enable_verbose_mode = xyes; then
422         echo "NOTE: building with verbose mode increases library size, may slightly increase security risk, and may cause a slight performance decrease, but aids debugging."
423 fi
424 if test x$enable_asserts = xyes; then
425         echo "NOTE: building with assertions increases library size, but will help a lot when tracking down bugs in software using D-BUS."
426 fi