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