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