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