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