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