chiark / gitweb /
Fix rights checking when updating a logged-in user's rights.
[disorder] / configure.ac
1 # Process this file with autoconf to produce a configure script.
2 #
3 # This file is part of DisOrder.
4 # Copyright (C) 2004, 2005, 2006, 2007 Richard Kettlewell
5 # Portions copyright (C) 2007 Ross Younger
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 # USA
21 #
22
23 AC_INIT([disorder], [2.0+], [richard+disorder@sfere.greenend.org.uk])
24 AC_CONFIG_AUX_DIR([config.aux])
25 AM_INIT_AUTOMAKE(disorder, [2.0+])
26 AC_CONFIG_SRCDIR([server/disorderd.c])
27 AM_CONFIG_HEADER([config.h])
28
29 # Find host type
30 AC_CANONICAL_HOST
31
32 # What we want to build
33 want_gtk=yes
34 want_python=yes
35
36 # APIs we want
37 want_alsa=yes
38 want_oss=yes
39 want_coreaudio=yes
40
41 # Checks for programs.
42 AC_PROG_CC
43 AC_SET_MAKE
44 if test "x$GCC" = xyes; then
45   gcc_werror=-Werror
46 else
47   gcc_werror=""
48 fi
49
50 AC_ARG_WITH([alsa],
51             [AS_HELP_STRING([--without-alsa],
52                             [do not build with ALSA support])],
53             [want_alsa=$withval])
54 AC_ARG_WITH([oss],
55             [AS_HELP_STRING([--without-oss],
56                             [do not build with OSS support])],
57             [want_oss=$withval])
58 AC_ARG_WITH([coreaudio],
59             [AS_HELP_STRING([--without-coreaudio],
60                             [do not build with Core Audio support])],
61             [want_coreaudio=$withval])
62
63 AC_MSG_CHECKING([for a known target platform])
64 case "$host" in
65 *empeg* )
66   AC_MSG_RESULT([empeg car stereo])
67   AC_DEFINE([EMPEG_HOST],[1],[define if host is an empeg car stereo])
68   # work around broken toolchain
69   AC_CHECK_LIB([gpg-error], [gpg_strerror])
70   AC_CHECK_LIB([pthread], [pthread_create])
71   want_server=no
72  ;;
73 *linux* | *Linux* )
74   AC_MSG_RESULT([Linux])
75   want_server=yes
76   ;;
77 *-apple-darwin* )
78   AC_MSG_RESULT([Mac OS X])
79   want_server=yes
80   if test $want_coreaudio = yes; then
81     COREAUDIO="-framework CoreAudio"
82   fi
83   browser=open
84   ;;
85 *-freebsd* )
86   AC_MSG_RESULT([FreeBSD])
87   want_server=yes
88   # Ports install to /usr/local but the compiler stupidly doesn't look
89   # there by default
90   LDFLAGS="${LDFLAGS} -L/usr/local/lib"
91   CPPFLAGS="${CPPFLAGS} -isystem /usr/local/include"
92   # libdb installs elsewhere again
93   LDFLAGS="${LDFLAGS} -L/usr/local/lib/db44"
94   CPPFLAGS="${CPPFLAGS} -isystem /usr/local/include/db44"
95   ;;
96 * )
97   AC_MSG_RESULT([unknown, winging it])
98   want_server=no
99   ;;
100 esac
101 AC_SUBST([COREAUDIO])
102
103 AC_ARG_WITH([browser],
104             [AS_HELP_STRING([--with-browser=BROWSER],
105                             [use BROWSER to display HTML])],
106             [browser=$withval])
107
108 AC_CACHE_CHECK([default HTML viewer],[rjk_cv_browser],[
109   rjk_cv_browser=UNKNOWN
110   for candidate in x-www-browser firefox mozilla konqueror netscape; do
111     if type $candidate >/dev/null 2>&1; then
112       rjk_cv_browser="$candidate"
113       break
114     fi
115   done
116 ])
117 if test -z "$browser"; then
118   browser="$rjk_cv_browser"
119 fi
120 AC_DEFINE_UNQUOTED([BROWSER],["$browser"],[HTML viewer])
121
122 AC_ARG_WITH([server],
123             [AS_HELP_STRING([--without-server],
124                             [do not build server])],
125             [want_server=$withval])
126 AC_ARG_WITH([gtk],
127             [AS_HELP_STRING([--without-gtk],
128                             [do not build GTK+ client])],
129             [want_gtk=$withval])
130 AC_ARG_WITH([python],
131             [AS_HELP_STRING([--without-python],
132                             [do not build Python support])],
133             [want_python=$withval])
134
135 subdirs="scripts lib clients doc examples debian"
136
137 if test $want_server = yes; then
138   subdirs="${subdirs} server plugins driver templates sounds images"
139 fi
140 if test $want_gtk = yes; then
141   subdirs="${subdirs} disobedience"
142   if test $want_server = no; then
143     subdirs="${subdirs} images"
144   fi
145 fi
146 if test $want_python = yes; then
147   AM_PATH_PYTHON([2.4])
148   subdirs="${subdirs} python tests"
149 fi
150 AC_SUBST([subdirs])
151
152 # libtool config
153 AC_LIBTOOL_DLOPEN
154 AC_DISABLE_STATIC
155
156 AC_PROG_LIBTOOL
157
158 AC_CACHE_CHECK([for GNU sed],[rjk_cv_gnused],[
159   rjk_cv_gnused="not found"
160   for candidate in sed gsed; do
161     if $candidate --version >/dev/null 2>&1; then
162       rjk_cv_gnused=$candidate 
163     fi
164   done
165 ])
166 GNUSED="${GNUSED:-$rjk_cv_gnused}"
167 if test "$GNUSED" = "not found"; then
168   AC_MSG_ERROR([GNU sed is required to build this program])
169 fi
170 AC_SUBST([GNUSED])
171
172 missing_libraries=""
173 missing_headers=""
174 missing_functions=""
175
176 AC_DEFINE(_GNU_SOURCE, 1, [required for e.g. strsignal])
177
178 # Macs might have libraries under fink's root
179 AC_PATH_PROG([FINK],[fink],[none],[$PATH:/sw/bin])
180 if test "x$FINK" != xnone; then
181   AC_CACHE_CHECK([fink install directory],[rjk_cv_finkprefix],[
182     rjk_cv_finkprefix="`echo "$FINK" | sed 's,/bin/fink$,,'`"
183   ])
184   finkdir="${rjk_cv_finkprefix}"
185   finkbindir="${rjk_cv_finkprefix}/bin"
186   CPPFLAGS="${CPPFLAGS} -I${rjk_cv_finkprefix}/include/gc -I${rjk_cv_finkprefix}/include"
187   if test $want_server = yes; then
188     CPPFLAGS="${CPPFLAGS} -I${rjk_cv_finkprefix}/include/db4"
189   fi
190   LDFLAGS="${LDFLAGS} -L${rjk_cv_finkprefix}/lib"
191 else
192   finkbindir=""
193 fi
194 AC_SUBST([finkdir])
195 AC_SUBST([finkbindir])
196
197 # Checks for libraries.
198 # We save up a list of missing libraries that we can't do without
199 # and report them all at once.
200 AC_CHECK_LIB(gc, GC_malloc,            [AC_SUBST(LIBGC,[-lgc])],
201             [missing_libraries="$missing_libraries libgc"])
202 AC_CHECK_LIB(gcrypt, gcry_md_open,
203              [AC_SUBST(LIBGCRYPT,[-lgcrypt])],
204             [missing_libraries="$missing_libraries libgcrypt"])
205 AC_CHECK_LIB(pcre, pcre_compile,
206              [AC_SUBST(LIBPCRE,[-lpcre])],
207              [missing_libraries="$missing_libraries libpcre"])
208 if test $want_alsa = yes; then
209   AC_CHECK_LIB([asound], [snd_pcm_open],
210                [AC_SUBST(LIBASOUND,[-lasound])])
211 fi
212 if test $want_server = yes; then
213   RJK_CHECK_LIB(db, db_create, [#include <db.h>],
214                [AC_SUBST(LIBDB,[-ldb])],
215                [missing_libraries="$missing_libraries libdb"])
216   AC_CHECK_LIB(vorbis, vorbis_info_clear,
217                [:],
218                [missing_libraries="$missing_libraries libvorbis"])
219   AC_CHECK_LIB(vorbisfile, ov_open,
220                [AC_SUBST(LIBVORBISFILE,["-lvorbisfile -lvorbis"])],
221                [missing_libraries="$missing_libraries libvorbisfile"],
222                [-lvorbis])
223   AC_CHECK_LIB(mad, mad_stream_init,
224                [AC_SUBST(LIBMAD,[-lmad])],
225                [missing_libraries="$missing_libraries libmad"])
226   AC_CHECK_LIB([ao], [ao_initialize],
227                [AC_SUBST(LIBAO,[-lao])],
228                [missing_libraries="$missing_libraries libao"])
229   AC_CHECK_LIB([FLAC], [FLAC__stream_decoder_new],
230                [AC_SUBST(LIBFLAC,[-lFLAC])],
231                [missing_libraries="$missing_libraries libFLAC"])
232 fi
233 AC_CHECK_LIB([pthread], [pthread_create],
234              [AC_SUBST(LIBPTHREAD,[-lpthread])],
235              [missing_libraries="$missing_libraries libpthread"])
236
237 if test $want_gtk = yes; then
238   AM_PATH_GLIB_2_0([],[],[missing_libraries="$missing_libraries libglib"])
239   AM_PATH_GTK_2_0([],[],[missing_libraries="$missing_libraries libgtk"])
240 fi
241
242 # Some platforms have iconv already
243 AC_CHECK_FUNC(iconv_open, [:],
244               [RJK_CHECK_LIB(iconv, iconv_open, [#include <iconv.h>],
245                             [AC_SUBST(LIBICONV,[-liconv])],
246                             [missing_functions="$missing_functions iconv_open"])])
247 AC_CHECK_FUNC([gethostbyname],[:],[
248   AC_CHECK_LIB(nsl,gethostbyname,
249                [AC_SUBST(LIBNSL,[-lnsl])],
250                [missing_functions="$missing_functions gethostbyname"])])
251 AC_CHECK_FUNC([socket],[:],[
252   AC_CHECK_LIB(socket,socket,
253                [AC_SUBST(LIBSOCKET,[-lsocket])],
254                [missing_functions="$missing_functions socket"])])
255 AC_CHECK_FUNC([dlopen],[:],[
256   AC_CHECK_LIB(dl,dlopen,
257                [AC_SUBST(LIBDL,[-ldl])],
258                [missing_functions="$missing_functions dlopen"])])
259
260 if test ! -z "$missing_libraries"; then
261   AC_MSG_ERROR([missing libraries:$missing_libraries])
262 fi
263
264 # Checks for header files.
265 RJK_FIND_GC_H
266 if test $want_oss = yes; then
267   AC_CHECK_HEADERS([sys/soundcard.h])
268 fi
269 if test $want_alsa = yes; then
270   AC_CHECK_HEADERS([alsa/asoundlib.h])
271 fi
272 if test $want_coreaudio = yes; then
273   AC_CHECK_HEADERS([CoreAudio/AudioHardware.h])
274 fi
275 AC_CHECK_HEADERS([inttypes.h])
276 # We don't bother checking very standard stuff
277 # Compilation will fail if any of these headers are missing, so we
278 # check for them here and fail early.
279 if test $want_server = yes; then
280   AC_CHECK_HEADERS([db.h],[:],[
281     missing_headers="$missing_headers $ac_header"
282   ])
283   AC_CHECK_HEADERS([FLAC/file_decoder.h])
284 fi
285 AC_CHECK_HEADERS([dlfcn.h gcrypt.h \
286                  getopt.h iconv.h langinfo.h \
287                  pcre.h sys/ioctl.h \
288                  syslog.h unistd.h],[:],[
289   missing_headers="$missing_headers $ac_header"
290 ])
291
292 if test ! -z "$missing_headers"; then
293   AC_MSG_ERROR([missing headers:$missing_headers])
294 fi
295
296 # We require that libpcre support UTF-8
297 RJK_REQUIRE_PCRE_UTF8([-lpcre])
298
299 # Checks for typedefs, structures, and compiler characteristics.
300 AC_C_CONST
301 AC_TYPE_SIZE_T
302 AC_C_INLINE
303 AC_C_BIGENDIAN
304 AC_CHECK_TYPES([struct sockaddr_in6],,,[AC_INCLUDES_DEFAULT
305 #include <netinet/in.h>])
306
307 # enable -Werror when we check for certain characteristics:
308
309 old_CFLAGS="${CFLAGS}"
310 CFLAGS="${CFLAGS} $gcc_werror"
311 AC_CHECK_TYPES([long long,uint32_t,uint8_t,intmax_t,uintmax_t])
312
313 # Some GCC invocations warn for converting function pointers to void *.
314 # This is fair enough, as it's technically forbidden, but we use dlsym()
315 # which can pretty much only exist if object and function pointers are
316 # interconvertable.  So we disable -Werror if need be.
317 if test ! -z "$gcc_werror"; then
318   AC_CACHE_CHECK([whether function pointers can be converted to void * without a warning],
319                  [rjk_cv_function_pointer_cast],[
320     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
321   void somefunction(void);],
322                       [(void *)somefunction])],
323                       [rjk_cv_function_pointer_cast=yes],
324                       [rjk_cv_function_pointer_cast=no])])
325   if test $rjk_cv_function_pointer_cast = no; then
326     gcc_werror=""
327   fi
328 fi
329
330 CFLAGS="${old_CFLAGS}"
331
332 # gcrypt maintainers keep changing everything.  Design your interface
333 # first, then implement it once, rather than getting it wrong three or
334 # four times and shipping between each attempt.
335 AC_CACHE_CHECK([for hash handle type in <grypt.h>],
336                [rjk_cv_gcrypt_hash_handle],[
337   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
338 #include <gcrypt.h>
339 ],
340                [gcry_md_hd_t h;])],
341                [rjk_cv_gcrypt_hash_handle=gcry_md_hd_t],[
342     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
343 #include <gcrypt.h>
344 ],
345                  [GcryMDHd h;])],
346                  [rjk_cv_gcrypt_hash_handle=GcryMDHd],
347                  [rjk_cv_gcrypt_hash_handle=GCRY_MD_HD])])])
348 AC_DEFINE_UNQUOTED([gcrypt_hash_handle],[$rjk_cv_gcrypt_hash_handle],
349                    [libgcrypt hash handle type])
350
351 AC_CACHE_CHECK([for gcry_error_t in <grypt.h>],
352                [rjk_cv_have_gcry_error_t],[
353   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
354 #include <gcrypt.h>
355 ],
356                  [gcry_error_t e;])],
357                  [rjk_cv_have_gcry_error_t=yes],
358                  [rjk_cv_have_gcry_error_t=no])])
359 if test $rjk_cv_have_gcry_error_t = yes; then
360   AC_DEFINE([HAVE_GCRY_ERROR_T],1,[define if <gcrypt.h> defines gcry_error_t])
361 fi
362
363 # Checks for functions
364 if test $ac_cv_type_long_long = yes; then
365   AC_CHECK_FUNCS([atoll strtoll],[:],[
366     missing_functions="$missing_functions $ac_func"
367   ])
368   # Darwin sometimes fails to declare strtoll (e.g. if you ask for -std=c99)
369   AC_CACHE_CHECK([whether strtoll is declared in <stdlib.h>],
370                  [rjk_cv_strtoll_declared],[
371     AC_EGREP_HEADER([strtoll], [stdlib.h],
372                     [rjk_cv_strtoll_declared=yes],
373                     [rjk_cv_strtoll_declared=no])])
374   if test $rjk_cv_strtoll_declared = yes; then
375     AC_DEFINE([DECLARES_STRTOLL],[1],[define if <stdlib.h> declares strtoll])
376   fi
377   AC_CACHE_CHECK([whether atoll is declared in <stdlib.h>],
378                  [rjk_cv_atoll_declared],[
379     AC_EGREP_HEADER([atoll], [stdlib.h],
380                     [rjk_cv_atoll_declared=yes],
381                     [rjk_cv_atoll_declared=no])])
382   if test $rjk_cv_atoll_declared = yes; then
383     AC_DEFINE([DECLARES_ATOLL],[1],[define if <stdlib.h> declares atoll])
384   fi
385 fi
386 AC_CHECK_FUNCS([ioctl nl_langinfo strsignal],[:],[
387   missing_functions="$missing_functions $ac_func"
388 ])
389 # fsync will do if fdatasync not available
390 AC_CHECK_FUNCS([fdatasync],[:],[
391   AC_CHECK_FUNCS([fsync],
392                  [AC_DEFINE([fdatasync],[fsync],[define fdatasync to fsync if not available])],
393                  [missing_functions="$missing_functions fdatasync"])])
394 if test ! -z "$missing_functions"; then
395   AC_MSG_ERROR([missing functions:$missing_functions])
396 fi
397 if test $want_server = yes; then
398   # <db.h> had better be version 3 or later
399   AC_CACHE_CHECK([db.h version],[rjk_cv_db_version],[
400     AC_PREPROC_IFELSE([
401                        #include <db.h>
402                        #ifndef DB_VERSION_MAJOR
403                        # error cannot determine db version
404                        #endif
405                        #if DB_VERSION_MAJOR < 4
406                        # error inadequate db version
407                        #endif
408                        #if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR <= 2
409                        # error inadequate db version
410                        #endif
411                       ],
412                       [rjk_cv_db_version=ok],
413                       [rjk_cv_db_version=inadequate])
414   ])
415   if test $rjk_cv_db_version != ok; then
416     AC_MSG_ERROR([need db.h version at least 4.2])
417   fi
418 fi
419
420 if test "x$GCC" = xyes; then
421   # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29478
422   AC_CACHE_CHECK([checking for GCC bug 29478],[rjk_cv_pr29478],[
423     old_CC="$CC"
424     if test $GCC = yes; then
425       CC="$CC -Wall -Werror"
426     fi
427     AC_COMPILE_IFELSE([
428       static int x(char *f) {
429        return *f;
430       }
431       int z(const char *g) {
432         return x((char *)g);
433       }],
434       [rjk_cv_pr29478=no],
435       [rjk_cv_pr29478=yes]
436     )
437     CC="$old_CC"
438   ])
439   if test $rjk_cv_pr29478 = yes; then
440     gcc_werror=''
441   fi
442
443   # a reasonable default set of warnings
444   CC="${CC} -Wall -W -Wpointer-arith -Wbad-function-cast \
445         -Wwrite-strings -Wmissing-prototypes \
446         -Wmissing-declarations -Wnested-externs"
447
448   # Fix up GTK+ and GLib compiler flags
449   GTK_CFLAGS="`echo \"$GTK_CFLAGS\"|sed 's/-I/-isystem /g'`"
450   GLIB_CFLAGS="`echo \"$GLIB_CFLAGS\"|sed 's/-I/-isystem /g'`"
451
452   if test "$gcc_werror" != ''; then
453     # GCC 2.95 doesn't know to ignore warnings from system headers
454     AC_CACHE_CHECK([whether -Werror is usable],
455                     rjk_cv_werror, [
456       save_CFLAGS="${CFLAGS}"
457       CFLAGS="${CFLAGS} ${GTK_CFLAGS} -Werror"
458       AC_TRY_COMPILE([#include <gtk/gtk.h>],
459                      [],
460                      [rjk_cv_werror=yes],
461                      [rjk_cv_werror=no])
462       CFLAGS="${save_CFLAGS}"
463     ])
464     if test $rjk_cv_werror = no; then
465       gcc_werror=''
466     fi
467   fi
468   CC="${CC} $gcc_werror"
469
470   # for older GCCs that don't know %ju (etc)
471   AC_CACHE_CHECK([whether -Wno-format is required],
472                  rjk_cv_noformat,
473                  AC_TRY_COMPILE([#include <stdio.h>
474 #include <stdint.h>
475 ],
476                                 [printf("%ju", (uintmax_t)0);],
477                                 [rjk_cv_noformat=no],
478                                 [rjk_cv_noformat=yes]))
479   if test $rjk_cv_noformat = yes; then
480     CC="${CC} -Wno-format"
481   fi
482
483   AC_CACHE_CHECK([whether -Wshadow is OK],
484                  rjk_cv_shadow,
485                  oldCC="${CC}"
486                  CC="${CC} -Wshadow"
487                  [AC_TRY_COMPILE([
488 #include <unistd.h>
489 #include <vorbis/vorbisfile.h>
490 ],
491                                 [],
492                                 [rjk_cv_shadow=yes],
493                                 [rjk_cv_shadow=no])
494                  CC="${oldCC}"])
495   if test $rjk_cv_shadow = yes; then
496     CC="${CC} -Wshadow"
497   fi
498 fi
499
500 RJK_GCOV
501
502 AH_BOTTOM([#ifdef __GNUC__
503 # define attribute(x) __attribute__(x)
504 #else
505 # define attribute(x)
506 #endif])
507
508 AC_CONFIG_FILES([Makefile
509                  templates/Makefile
510                  images/Makefile
511                  scripts/Makefile
512                  lib/Makefile
513                  server/Makefile
514                  clients/Makefile
515                  disobedience/Makefile
516                  doc/Makefile
517                  plugins/Makefile
518                  driver/Makefile
519                  debian/Makefile
520                  sounds/Makefile
521                  python/Makefile
522                  examples/Makefile
523                  tests/Makefile])
524 AC_OUTPUT
525
526 if test $GCC = yes && test "$gcc_werror" = ''; then
527   AC_MSG_WARN([building without -Werror])
528 fi
529 if test $want_python = no; then
530   AC_MSG_WARN([cannot run the test suit without Python])
531 fi