chiark / gitweb /
Check mp3 decoding too
[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-2009 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 3 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,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU 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, see <http://www.gnu.org/licenses/>.
19 #
20
21 AC_INIT([disorder], [4.3+], [richard+disorder@sfere.greenend.org.uk])
22 AC_CONFIG_AUX_DIR([config.aux])
23 AM_INIT_AUTOMAKE(disorder, [4.3+])
24 AC_CONFIG_SRCDIR([server/disorderd.c])
25 AM_CONFIG_HEADER([config.h])
26
27 # Find host type
28 AC_CANONICAL_HOST
29
30 # What we want to build
31 want_gtk=yes
32 want_python=yes
33 want_tests=yes
34 want_server=yes
35 want_cgi=yes
36
37 # APIs we want
38 want_alsa=yes
39 want_oss=yes
40 want_coreaudio=yes
41
42 # By default we don't want gtk-osx.  But if you ask for --with-gtk-osx...
43 #
44 # Disobedience can be built to a native OS X application.  There are some
45 # caveats:
46 #  - you will still need Fink (or something) for other libraries
47 #  - if you wanted an application bundle you are out of luck
48 #  - the menu bar is still in the main window (not at the top of the screen)
49 #
50 # So it's still rather rough and ready.  But it does work...
51 #
52 # See:
53 #   http://www.gtk-osx.org/
54 #   http://live.gnome.org/GTK%2B/OSX/Framework
55 want_gtkosx=no
56
57 # Checks for programs.
58 AC_PROG_CC
59 AM_PROG_CC_C_O
60 AC_PROG_AWK
61 AC_SET_MAKE
62 if test "x$GCC" = xyes; then
63   gcc_werror=-Werror
64   case "$CC" in
65   *-std=* )
66     ;;
67   * )
68     CC="${CC} -std=gnu99"
69     ;;
70   esac
71 else
72   AC_MSG_ERROR([GNU C is required to build this program])
73   gcc_werror=""
74 fi
75
76 AC_ARG_WITH([alsa],
77             [AS_HELP_STRING([--without-alsa],
78                             [do not build with ALSA support])],
79             [want_alsa=$withval])
80 AC_ARG_WITH([oss],
81             [AS_HELP_STRING([--without-oss],
82                             [do not build with OSS support])],
83             [want_oss=$withval])
84 AC_ARG_WITH([coreaudio],
85             [AS_HELP_STRING([--without-coreaudio],
86                             [do not build with Core Audio support])],
87             [want_coreaudio=$withval])
88 AC_ARG_WITH([tests],
89             [AS_HELP_STRING([--without-tests],
90                             [do not build test suit])],
91             [want_tests=$withval])
92 AC_ARG_WITH([gtk-osx],
93             [AS_HELP_STRING([--with-gtk-osx],
94                             [use native GTK+ (OS X only)])],
95             [want_gtkosx=$withval])
96
97 AC_MSG_CHECKING([for a known target platform])
98 case "$host" in
99 *empeg* )
100   AC_MSG_RESULT([empeg car stereo])
101   AC_DEFINE([EMPEG_HOST],[1],[define if host is an empeg car stereo])
102   # work around broken toolchain
103   AC_CHECK_LIB([gpg-error], [gpg_strerror])
104   AC_CHECK_LIB([pthread], [pthread_create])
105   want_server=no
106   want_cgi=no
107  ;;
108 *linux* | *Linux* )
109   AC_MSG_RESULT([Linux])
110   ;;
111 *-apple-darwin* )
112   AC_MSG_RESULT([Mac OS X])
113   # AudioHardwareGetProperty is deprecated in 10.6, but it's still _there_,
114   # so we'll just turn off the warning.
115   CC="$CC -Wno-deprecated-declarations"
116   if test $want_coreaudio = yes; then
117     COREAUDIO="-framework CoreFoundation -framework CoreServices -framework CoreAudio"
118   fi
119   browser=open
120   AC_MSG_CHECKING([Mac OS X target version])
121   # We honor MACOSX_DEPLOYMENT_TARGET in the environment, emulating gcc's
122   # behaviour.  But we provide a command line option to override it and
123   # we default to wide support instead of supporting only the build platform.
124   #
125   # Currently if you ask for 10.5 you will get a deprecation warning
126   # when building the CoreAudio support code.  For the time being the
127   # answer to this is "don't do that then".  If a good reason to ask
128   # for a 10.5 deployment target emerges then this will be fixed.
129   if test -z "$MACOSX_DEPLOYMENT_TARGET"; then
130     MACOSX_DEPLOYMENT_TARGET=10.0
131   fi
132   AC_ARG_WITH([deployment-target],
133               [AS_HELP_STRING([--with-deployment-target=TARGET],
134                               [set target OS X version])],
135               [MACOSX_DEPLOYMENT_TARGET=$withval])
136   # Convert to desired format
137   underscored=`echo $MACOSX_DEPLOYMENT_TARGET|sed 's/\./_/'`
138   minver="MAC_OS_X_VERSION_$underscored"
139   AC_MSG_RESULT([$minver])
140   AC_DEFINE_UNQUOTED([MAC_OS_X_VERSION_MIN_REQUIRED], [$minver],
141                      [define to minimum version of Mac OS X to support])
142
143   if test $want_gtkosx = no; then
144     # Fink's GTK+ is hopelessly broken
145     PKG_CONFIG_PATH=${PKG_CONFIG_PATH:-/sw/lib/pango-ft219/lib/pkgconfig}
146     export PKG_CONFIG_PATH
147   fi
148
149   ;;
150 *-freebsd* )
151   AC_MSG_RESULT([FreeBSD])
152   # Ports install to /usr/local but the compiler stupidly doesn't look
153   # there by default
154   LDFLAGS="${LDFLAGS} -L/usr/local/lib"
155   CPPFLAGS="${CPPFLAGS} -isystem /usr/local/include"
156   # Look for a suitable version of libdb among the versions found in FreeBSD 7.0
157   AC_CACHE_CHECK([looking for a libdb install],[rjk_cv_libdb],[
158     rjk_cv_libdb="none"
159     for db in db43 db44 db45 db46; do
160       if test -e /usr/local/lib/$db; then
161         rjk_cv_libdb=$db
162         break
163       fi
164     done
165   ])
166   if test $rjk_cv_libdb != none; then
167     LDFLAGS="${LDFLAGS} -L/usr/local/lib/$rjk_cv_libdb"
168     CPPFLAGS="${CPPFLAGS} -isystem /usr/local/include/$rjk_cv_libdb"
169   fi
170   ;;
171 * )
172   AC_MSG_RESULT([unknown, winging it])
173   ;;
174 esac
175 AC_SUBST([COREAUDIO])
176
177 AC_ARG_WITH([browser],
178             [AS_HELP_STRING([--with-browser=BROWSER],
179                             [use BROWSER to display HTML])],
180             [browser=$withval])
181
182 AC_CACHE_CHECK([default HTML viewer],[rjk_cv_browser],[
183   rjk_cv_browser=UNKNOWN
184   for candidate in x-www-browser sensible-browser firefox mozilla konqueror netscape; do
185     if type $candidate >/dev/null 2>&1; then
186       rjk_cv_browser="$candidate"
187       break
188     fi
189   done
190 ])
191 if test -z "$browser"; then
192   browser="$rjk_cv_browser"
193 fi
194 AC_DEFINE_UNQUOTED([BROWSER],["$browser"],[HTML viewer])
195
196 # Figure out what version of sox is installed
197 AC_CACHE_CHECK([sox version],[rjk_cv_soxver],[
198   rjk_cv_soxver=UNKNOWN
199   if sox --version > /dev/null 2>&1; then
200     rjk_cv_soxver=`sox --version|$AWK '{ if(match($0, /[[0-9\.]]+/)) print substr($0,RSTART,RLENGTH)}'`
201   else
202     rjk_cv_soxver=`sox -h 2>&1|$AWK '/Version/ { if(match($0, /[[0-9\.]]+/)) print substr($0,RSTART,RLENGTH)}'`
203   fi
204 ])
205
206 # Decide what command line options to use
207 #
208 # sox version   endian     bits       deployed
209 # 12.17.9       -x         -[bwld]    debian etch, ubuntu dapper
210 # 14.0.0        -x/-[BL]   -[bwld]    ubuntu hardy
211 # 14.0.1        -x/-[BL]   -[1248]    debian lenny
212 # 14.2.0        -x/-[BL]   -[1248]    debian sid (at 2008-12)
213
214 AC_CACHE_CHECK([default sox generation],[rjk_cv_soxgen],[
215   case $rjk_cv_soxver in
216   [[0-9]].* | 1[[0123]].* )
217     rjk_cv_soxgen=0
218     ;;
219   * )
220     rjk_cv_soxgen=1
221     ;;
222   esac
223 ])
224 AC_DEFINE_UNQUOTED([DEFAULT_SOX_GENERATION],[$rjk_cv_soxgen],
225                    [default sox generation])
226
227 AC_ARG_WITH([server],
228             [AS_HELP_STRING([--without-server],
229                             [do not build server])],
230             [want_server=$withval])
231 AC_ARG_WITH([cgi],
232             [AS_HELP_STRING([--without-cgi],
233                             [do not build CGI])],
234             [want_cgi=$withval])
235 AC_ARG_WITH([gtk],
236             [AS_HELP_STRING([--without-gtk],
237                             [do not build GTK+ client])],
238             [want_gtk=$withval])
239 AC_ARG_WITH([python],
240             [AS_HELP_STRING([--without-python],
241                             [do not build Python support])],
242             [want_python=$withval])
243
244 if test $want_server = no; then
245   want_cgi=no
246 fi
247
248 #
249 # OS          Document Root                  CGI directory
250 # ==          =============                  =============
251 # Debian      /var/www                       /usr/lib/cgi-bin
252 # Ubuntu      /var/www                       /usr/lib/cgi-bin
253 # Red Hat     /var/www/html                  /var/www/cgi-bin
254 #      or:    /home/httpd/html/              /home/httpd/cgi-bin
255 # Slackware   /var/www/htdocs                (unknown)
256 # SuSE        /srv/www/html                  /srv/www/cgi-bin
257 # Gentoo      /var/www/localhost/htdocs      /var/www/localhost/cgi-bin/
258 # FreeBSD     /usr/local/www/data            /usr/local/www/cgi-bin
259 #      or:    /usr/local/www/???/data        /usr/local/www/???/cgi-bin
260 # OS X        /Library/WebServer/Documents   /Library/WebServer/CGI-Executables
261 # Apache      /usr/local/apache/htdocs       (none)
262 #
263 # Sources:
264 #   http://wiki.linuxquestions.org/wiki/Apache
265 #   http://mapserver.gis.umn.edu/docs/howto/suse-linux
266 #   http://www.yolinux.com/TUTORIALS/LinuxTutorialWebSiteConfig.html
267 #   http://sources.gentoo.org/viewcvs.py/apache/trunk/dist/2.2/conf/vhosts.d/default_vhost.include?rev=198&view=log
268 #   http://httpd.apache.org/docs/
269 #
270 if test $want_cgi = yes; then
271   if test -z "$httpdir"; then
272     AC_CACHE_CHECK([for httpd document root],[rjk_cv_httpdir],[
273       rjk_cv_httpdir="not found"
274       for dir in /var/www/html \
275                  /var/www/htdocs \
276                  /var/www/localhost/htdocs \
277                  /var/www \
278                  /home/httpd/html \
279                  /srv/www/html \
280                  /usr/local/www/data \
281                  /usr/local/www/*/data \
282                  /Library/WebServer/Documents \
283                  /usr/local/apache/htdocs; do
284         if test -d "$dir"; then
285           rjk_cv_httpdir="$dir"
286         fi
287       done
288     ])
289     if test "$rjk_cv_httpdir" = "not found"; then
290       AC_MSG_ERROR([cannot identify httpd documentroot.  Set httpdir on configure command line])
291     fi
292     httpdir="$rjk_cv_httpdir"
293   fi
294   if test ! -z "$cgidir"; then
295     # This is a bit harsh but should stop any disasters
296     AC_MSG_ERROR([cgidir has been renamed to cgiexecdir])
297   fi
298   if test -z "$cgiexecdir"; then
299     AC_CACHE_CHECK([for CGI directory],[rjk_cv_cgiexecdir],[
300       rjk_cv_cgiexecdir="not found"
301       for dir in /usr/lib/cgi-bin \
302                  /Library/WebServer/CGI-Executables \
303                  /srv/www/cgi-bin \
304                  /var/www/cgi-bin \
305                  /home/httpd/cgi-bin \
306                  /var/www/localhost/cgi-bin \
307                  /usr/local/lib/cgi-bin \
308                  /usr/local/www/cgi-bin \
309                  /usr/local/www/*/cgi-bin; do
310         if test -d "$dir"; then
311           rjk_cv_cgiexecdir="$dir"
312           break
313         fi
314       done
315     ])
316     if test "$rjk_cv_cgiexecdir" = "not found"; then
317       AC_MSG_ERROR([cannot identify CGI install directory.  Set cgiexecdir on configure command line])
318     fi
319     cgiexecdir="$rjk_cv_cgiexecdir"
320   fi
321 fi
322 AC_ARG_VAR([cgiexecdir], [location of cgi-bin directory, e.g. /usr/lib/cgi-bin])
323 AC_ARG_VAR([httpdir], [location of http document root, e.g. /var/www/htdocs])
324 if test -z "$pkghttpdir"; then
325   pkghttpdir='$(httpdir)/disorder'
326 fi
327 AC_SUBST([pkghttpdir])
328
329 subdirs="scripts lib"
330 if test $want_tests = yes; then
331   subdirs="${subdirs} libtests"
332 fi
333 subdirs="${subdirs} clients doc examples debian"
334
335 if test $want_server = yes; then
336   subdirs="${subdirs} server plugins driver sounds"
337 fi
338 if test $want_cgi = yes; then
339   subdirs="${subdirs} cgi templates images"
340 fi
341 if test $want_gtk = yes; then
342   subdirs="${subdirs} disobedience"
343   if test $want_server = no; then
344     subdirs="${subdirs} images"
345   fi
346 fi
347 if test $want_tests = yes && test $want_python = yes; then
348   AM_PATH_PYTHON([2.5])
349   subdirs="${subdirs} python tests"
350 fi
351 AC_SUBST([subdirs])
352
353 # libtool config
354 AC_LIBTOOL_DLOPEN
355 AC_DISABLE_STATIC
356
357 AC_PROG_LIBTOOL
358
359 AC_CACHE_CHECK([for GNU sed],[rjk_cv_gnused],[
360   rjk_cv_gnused="not found"
361   for candidate in sed gsed; do
362     if $candidate --version >/dev/null 2>&1; then
363       rjk_cv_gnused=$candidate 
364     fi
365   done
366 ])
367 GNUSED="${GNUSED:-$rjk_cv_gnused}"
368 if test "$GNUSED" = "not found"; then
369   AC_MSG_ERROR([GNU sed is required to build this program])
370 fi
371 AC_SUBST([GNUSED])
372
373 AC_CHECK_PROGS([GROG],[grog])
374 AM_CONDITIONAL([GROG],[test "x$GROG" != xnone])
375
376 missing_libraries=""
377 missing_headers=""
378 missing_functions=""
379
380 AC_DEFINE(_GNU_SOURCE, 1, [required for e.g. strsignal])
381
382 AC_PATH_PROG([SENDMAIL],[sendmail],[none],[$PATH:/usr/sbin:/usr/lib])
383
384 # Macs might have libraries under fink's root
385 AC_PATH_PROG([FINK],[fink],[none],[$PATH:/sw/bin])
386 if test "x$FINK" != xnone; then
387   # Find Fink prefix
388   AC_CACHE_CHECK([fink install directory],[rjk_cv_finkprefix],[
389     rjk_cv_finkprefix="`echo "$FINK" | sed 's,/bin/fink$,,'`"
390   ])
391   # Add include and link paths
392   finkdir="${rjk_cv_finkprefix}"
393   finkbindir="${rjk_cv_finkprefix}/bin"
394   CPPFLAGS="${CPPFLAGS} -isystem ${rjk_cv_finkprefix}/include/gc -isystem ${rjk_cv_finkprefix}/include"
395   if test $want_server = yes; then
396     CPPFLAGS="${CPPFLAGS} -isystem ${rjk_cv_finkprefix}/include/db4"
397   fi
398   LDFLAGS="${LDFLAGS} -L${rjk_cv_finkprefix}/lib"
399   # Distinguish 32- and 64-bit fink
400   AC_CACHE_CHECK([whether Fink is 32-bit or 64-bit],[rjk_cv_finkbits],[
401     odata=`otool -v -h $finkbindir/dpkg`
402     case "$odata" in
403     *X86_64* )
404       rjk_cv_finkbits=64
405       ;;
406     *I386* )
407       rjk_cv_finkbits=32
408       ;;
409     * )
410       rjk_cv_finkbits=unknown
411       ;;
412     esac
413   ])
414   # Match Fink so we can use its libraries
415   case $rjk_cv_finkbits in
416   32 | 64 )
417     CC="$CC -m$rjk_cv_finkbits"
418     ;;
419   esac
420 else
421   finkbindir=""
422 fi
423 AC_SUBST([finkdir])
424 AC_SUBST([finkbindir])
425
426 # Checks for libraries.
427 # We save up a list of missing libraries that we can't do without
428 # and report them all at once.
429 AC_CHECK_LIB(gc, GC_malloc,            [AC_SUBST(LIBGC,[-lgc])],
430             [missing_libraries="$missing_libraries libgc"])
431 AC_CHECK_LIB(gcrypt, gcry_md_open,
432              [AC_SUBST(LIBGCRYPT,[-lgcrypt])],
433             [missing_libraries="$missing_libraries libgcrypt"])
434 AC_CHECK_LIB(pcre, pcre_compile,
435              [AC_SUBST(LIBPCRE,[-lpcre])],
436              [missing_libraries="$missing_libraries libpcre"])
437 if test $want_alsa = yes; then
438   AC_CHECK_LIB([asound], [snd_pcm_open],
439                [AC_SUBST(LIBASOUND,[-lasound])])
440 fi
441 AC_CHECK_LIB([samplerate],[src_new],
442              [AC_SUBST([LIBSAMPLERATE],[-lsamplerate])])
443 if test $want_server = yes; then
444   RJK_CHECK_LIB(db, db_create, [#include <db.h>],
445                [AC_SUBST(LIBDB,[-ldb])],
446                [missing_libraries="$missing_libraries libdb"])
447   AC_CHECK_LIB(vorbis, vorbis_info_clear,
448                [:],
449                [missing_libraries="$missing_libraries libvorbis"])
450   AC_CHECK_LIB(vorbisfile, ov_open,
451                [AC_SUBST(LIBVORBISFILE,["-lvorbisfile -lvorbis"])],
452                [missing_libraries="$missing_libraries libvorbisfile"],
453                [-lvorbis])
454   AC_CHECK_LIB(mad, mad_stream_init,
455                [AC_SUBST(LIBMAD,[-lmad])],
456                [missing_libraries="$missing_libraries libmad"])
457   AC_CHECK_LIB([ao], [ao_initialize],
458                [AC_SUBST(LIBAO,[-lao])],
459                [missing_libraries="$missing_libraries libao"])
460   AC_CHECK_LIB([FLAC], [FLAC__stream_decoder_new],
461                [AC_SUBST(LIBFLAC,[-lFLAC])],
462                [missing_libraries="$missing_libraries libFLAC"])
463 fi
464 AC_CHECK_LIB([pthread], [pthread_create],
465              [AC_SUBST(LIBPTHREAD,[-lpthread])],
466              [missing_libraries="$missing_libraries libpthread"])
467
468 if test $want_gtk = yes; then
469   if test $want_gtkosx = yes; then
470     GTK_CFLAGS="-isystem /Library/Frameworks/Gtk.framework/Headers -isystem /Library/Frameworks/Cairo.framework/Headers"
471     GLIB_CFLAGS="-isystem /Library/Frameworks/GLib.framework/Headers"
472     GTK_LIBS="-framework Gtk -framework GLib"
473   else
474     AM_PATH_GLIB_2_0([],[],[missing_libraries="$missing_libraries libglib"])
475     AM_PATH_GTK_2_0([],[],[missing_libraries="$missing_libraries libgtk"])
476   fi
477 fi
478
479 # Some platforms have iconv already
480 AC_CHECK_FUNC(iconv_open, [:],
481               [RJK_CHECK_LIB(iconv, iconv_open, [#include <iconv.h>],
482                             [AC_SUBST(LIBICONV,[-liconv])],
483                             [missing_functions="$missing_functions iconv_open"])])
484 AC_CHECK_FUNC([gethostbyname],[:],[
485   AC_CHECK_LIB(nsl,gethostbyname,
486                [AC_SUBST(LIBNSL,[-lnsl])],
487                [missing_functions="$missing_functions gethostbyname"])])
488 AC_CHECK_FUNC([socket],[:],[
489   AC_CHECK_LIB(socket,socket,
490                [AC_SUBST(LIBSOCKET,[-lsocket])],
491                [missing_functions="$missing_functions socket"])])
492 AC_CHECK_FUNC([dlopen],[:],[
493   AC_CHECK_LIB(dl,dlopen,
494                [AC_SUBST(LIBDL,[-ldl])],
495                [missing_functions="$missing_functions dlopen"])])
496
497 if test ! -z "$missing_libraries"; then
498   AC_MSG_ERROR([missing libraries:$missing_libraries])
499 fi
500
501 # Checks for header files.
502 RJK_FIND_GC_H
503 if test $want_oss = yes; then
504   AC_CHECK_HEADERS([sys/soundcard.h])
505 fi
506 if test $want_alsa = yes; then
507   AC_CHECK_HEADERS([alsa/asoundlib.h])
508 fi
509 if test $want_coreaudio = yes; then
510   AC_CHECK_HEADERS([CoreAudio/AudioHardware.h])
511 fi
512 AC_CHECK_HEADERS([inttypes.h])
513 # We don't bother checking very standard stuff
514 # Compilation will fail if any of these headers are missing, so we
515 # check for them here and fail early.
516 if test $want_server = yes; then
517   AC_CHECK_HEADERS([db.h],[:],[
518     missing_headers="$missing_headers $ac_header"
519   ])
520   AC_CHECK_HEADERS([FLAC/file_decoder.h])
521 fi
522 AC_CHECK_HEADERS([dlfcn.h gcrypt.h \
523                  getopt.h iconv.h langinfo.h \
524                  pcre.h sys/ioctl.h \
525                  syslog.h unistd.h],[:],[
526   missing_headers="$missing_headers $ac_header"
527 ])
528 AC_CHECK_HEADERS([samplerate.h])
529
530 if test ! -z "$missing_headers"; then
531   AC_MSG_ERROR([missing headers:$missing_headers])
532 fi
533
534 # We require that libpcre support UTF-8
535 RJK_REQUIRE_PCRE_UTF8([-lpcre])
536
537 # Checks for typedefs, structures, and compiler characteristics.
538 AC_C_CONST
539 AC_TYPE_SIZE_T
540 AC_C_INLINE
541 AC_C_BIGENDIAN
542 AC_CHECK_TYPES([struct sockaddr_in6],,,[AC_INCLUDES_DEFAULT
543 #include <netinet/in.h>])
544
545 # enable -Werror when we check for certain characteristics:
546
547 old_CFLAGS="${CFLAGS}"
548 CFLAGS="${CFLAGS} $gcc_werror"
549 AC_CHECK_TYPES([long long,uint32_t,uint8_t,intmax_t,uintmax_t])
550
551 # Some GCC invocations warn for converting function pointers to void *.
552 # This is fair enough, as it's technically forbidden, but we use dlsym()
553 # which can pretty much only exist if object and function pointers are
554 # interconvertable.  So we disable -Werror if need be.
555 if test ! -z "$gcc_werror"; then
556   AC_CACHE_CHECK([whether function pointers can be converted to void * without a warning],
557                  [rjk_cv_function_pointer_cast],[
558     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
559   void somefunction(void);],
560                       [(void *)somefunction])],
561                       [rjk_cv_function_pointer_cast=yes],
562                       [rjk_cv_function_pointer_cast=no])])
563   if test $rjk_cv_function_pointer_cast = no; then
564     gcc_werror=""
565   fi
566 fi
567
568 CFLAGS="${old_CFLAGS}"
569
570 # gcrypt maintainers keep changing everything.  Design your interface
571 # first, then implement it once, rather than getting it wrong three or
572 # four times and shipping between each attempt.
573 AC_CACHE_CHECK([for hash handle type in <grypt.h>],
574                [rjk_cv_gcrypt_hash_handle],[
575   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
576 #include <gcrypt.h>
577 ],
578                [gcry_md_hd_t h;])],
579                [rjk_cv_gcrypt_hash_handle=gcry_md_hd_t],[
580     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
581 #include <gcrypt.h>
582 ],
583                  [GcryMDHd h;])],
584                  [rjk_cv_gcrypt_hash_handle=GcryMDHd],
585                  [rjk_cv_gcrypt_hash_handle=GCRY_MD_HD])])])
586 AC_DEFINE_UNQUOTED([gcrypt_hash_handle],[$rjk_cv_gcrypt_hash_handle],
587                    [libgcrypt hash handle type])
588
589 AC_CACHE_CHECK([for gcry_error_t in <grypt.h>],
590                [rjk_cv_have_gcry_error_t],[
591   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
592 #include <gcrypt.h>
593 ],
594                  [gcry_error_t e;])],
595                  [rjk_cv_have_gcry_error_t=yes],
596                  [rjk_cv_have_gcry_error_t=no])])
597 if test $rjk_cv_have_gcry_error_t = yes; then
598   AC_DEFINE([HAVE_GCRY_ERROR_T],1,[define if <gcrypt.h> defines gcry_error_t])
599 fi
600
601 # Checks for functions
602 if test $ac_cv_type_long_long = yes; then
603   AC_CHECK_FUNCS([atoll strtoll],[:],[
604     missing_functions="$missing_functions $ac_func"
605   ])
606   # Darwin sometimes fails to declare strtoll (e.g. if you ask for -std=c99)
607   AC_CACHE_CHECK([whether strtoll is declared in <stdlib.h>],
608                  [rjk_cv_strtoll_declared],[
609     AC_EGREP_HEADER([strtoll], [stdlib.h],
610                     [rjk_cv_strtoll_declared=yes],
611                     [rjk_cv_strtoll_declared=no])])
612   if test $rjk_cv_strtoll_declared = yes; then
613     AC_DEFINE([DECLARES_STRTOLL],[1],[define if <stdlib.h> declares strtoll])
614   fi
615   AC_CACHE_CHECK([whether atoll is declared in <stdlib.h>],
616                  [rjk_cv_atoll_declared],[
617     AC_EGREP_HEADER([atoll], [stdlib.h],
618                     [rjk_cv_atoll_declared=yes],
619                     [rjk_cv_atoll_declared=no])])
620   if test $rjk_cv_atoll_declared = yes; then
621     AC_DEFINE([DECLARES_ATOLL],[1],[define if <stdlib.h> declares atoll])
622   fi
623 fi
624 AC_CHECK_FUNCS([ioctl nl_langinfo strsignal setenv unsetenv],[:],[
625   missing_functions="$missing_functions $ac_func"
626 ])
627 # fsync will do if fdatasync not available
628 AC_CHECK_FUNCS([fdatasync],[:],[
629   AC_CHECK_FUNCS([fsync],
630                  [AC_DEFINE([fdatasync],[fsync],[define fdatasync to fsync if not available])],
631                  [missing_functions="$missing_functions fdatasync"])])
632 if test ! -z "$missing_functions"; then
633   AC_MSG_ERROR([missing functions:$missing_functions])
634 fi
635
636 # Functions we can take or leave
637 AC_CHECK_FUNCS([fls])
638
639 if test $want_server = yes; then
640   # <db.h> had better be version 3 or later
641   AC_CACHE_CHECK([db.h version],[rjk_cv_db_version],[
642     AC_PREPROC_IFELSE([
643                        #include <db.h>
644                        #ifndef DB_VERSION_MAJOR
645                        # error cannot determine db version
646                        #endif
647                        #if DB_VERSION_MAJOR < 4
648                        # error inadequate db version
649                        #endif
650                        #if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR <= 2
651                        # error inadequate db version
652                        #endif
653                       ],
654                       [rjk_cv_db_version=ok],
655                       [rjk_cv_db_version=inadequate])
656     if test $rjk_cv_db_version = ok; then
657       AC_PREPROC_IFELSE([
658                          #include <db.h>
659                          #if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR == 6
660                          # error http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=510270
661                          #endif
662                         ],
663                         [rjk_cv_db_version=ok],
664                         [rjk_cv_db_version=toxic])
665     fi
666   ])
667   case $rjk_cv_db_version in
668   ok )
669     ;;
670   inadequate )
671     AC_MSG_ERROR([need db version at least 4.3 (but not 4.6)])
672     ;;
673   toxic )
674     AC_MSG_ERROR([db version 4.6.x does not work - see debian bug 510270])
675     ;;
676   esac
677 fi
678
679 AM_CONDITIONAL([SERVER], [test x$want_server = xyes])
680 if test $want_gtk = yes; then
681   AC_DEFINE([WITH_GTK], [1], [define if using GTK+])
682 fi
683
684 if test "x$GCC" = xyes; then
685   # We need LLONG_MAX and annoyingly GCC doesn't always give it to us
686   # by default.
687   AC_CACHE_CHECK([what C version to ask for],[rjk_cv_cstd],[
688     AC_TRY_COMPILE([#include <limits.h>],[
689       long long n = LLONG_MAX;
690     ],[rjk_cv_cstd=default],[
691       old_CC="$CC"
692       CC="${CC} -std=gnu99"
693       AC_TRY_COMPILE([#include <limits.h>],[
694         long long n = LLONG_MAX;
695       ],[rjk_cv_cstd=gnu99],[rjk_cv_cstd=unknown])
696       CC="$old_CC"
697     ])
698   ])
699   case $rjk_cv_cstd in
700   default | unknown )
701     ;;
702   * )
703     CC="${CC} -std=${rjk_cv_cstd}"
704     ;;
705   esac
706
707   # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29478
708   AC_CACHE_CHECK([checking for GCC bug 29478],[rjk_cv_pr29478],[
709     old_CC="$CC"
710     if test $GCC = yes; then
711       CC="$CC -Wall -Werror"
712     fi
713     AC_COMPILE_IFELSE([
714       static int x(char *f) {
715        return *f;
716       }
717       int z(const char *g) {
718         return x((char *)g);
719       }],
720       [rjk_cv_pr29478=no],
721       [rjk_cv_pr29478=yes]
722     )
723     CC="$old_CC"
724   ])
725   if test $rjk_cv_pr29478 = yes; then
726     gcc_werror=''
727   fi
728
729   AC_CACHE_CHECK([checking for excessively strict -Wreturn-type],
730                  [rjk_cv_gcc44_stupidity],[
731     old_CC="$CC"
732     if test $GCC = yes; then
733       CC="$CC -Wreturn-type -Werror"
734     fi
735     AC_COMPILE_IFELSE([
736       static void *threadfn(void) {
737         for(;;)
738           ;
739       }],
740       [rjk_cv_gcc44_stupidity=no],
741       [rjk_cv_gcc44_stupidity=yes])
742     CC="$old_CC"
743   ])
744   if test $rjk_cv_gcc44_stupidity = yes; then
745     AC_DEFINE([HAVE_STUPID_GCC44],[1],[Define if your compiler has excessively strict -Wreturn-type])
746   fi
747
748   # a reasonable default set of warnings
749   CC="${CC} -Wall -W -Wpointer-arith -Wbad-function-cast \
750         -Wwrite-strings -Wmissing-prototypes \
751         -Wmissing-declarations -Wnested-externs"
752
753   # Fix up GTK+ and GLib compiler flags
754   GTK_CFLAGS="`echo \"$GTK_CFLAGS\"|sed 's/-I/-isystem /g'`"
755   GLIB_CFLAGS="`echo \"$GLIB_CFLAGS\"|sed 's/-I/-isystem /g'`"
756
757   if test "$gcc_werror" != ''; then
758     # GCC 2.95 doesn't know to ignore warnings from system headers
759     AC_CACHE_CHECK([whether -Werror is usable],
760                     rjk_cv_werror, [
761       save_CFLAGS="${CFLAGS}"
762       CFLAGS="${CFLAGS} ${GTK_CFLAGS} -Werror"
763       AC_TRY_COMPILE([#if WITH_GTK
764  #include <gtk/gtk.h>
765 #endif
766
767 struct s { int a, b; };
768 const struct s sv = { .a = 1 };],
769                      [],
770                      [rjk_cv_werror=yes],
771                      [rjk_cv_werror=no])
772       CFLAGS="${save_CFLAGS}"
773     ])
774     if test $rjk_cv_werror = no; then
775       gcc_werror=''
776     fi
777   fi
778   CC="${CC} $gcc_werror"
779
780   # for older GCCs that don't know %ju (etc)
781   AC_CACHE_CHECK([whether -Wno-format is required],
782                  rjk_cv_noformat,
783                  AC_TRY_COMPILE([#include <stdio.h>
784 #include <stdint.h>
785 ],
786                                 [printf("%ju", (uintmax_t)0);],
787                                 [rjk_cv_noformat=no],
788                                 [rjk_cv_noformat=yes]))
789   if test $rjk_cv_noformat = yes; then
790     CC="${CC} -Wno-format"
791   fi
792
793   AC_CACHE_CHECK([whether -Wshadow is OK],
794                  rjk_cv_shadow,
795                  oldCC="${CC}"
796                  CC="${CC} -Wshadow"
797                  [AC_TRY_COMPILE([
798 #include <unistd.h>
799 #include <vorbis/vorbisfile.h>
800 ],
801                                 [],
802                                 [rjk_cv_shadow=yes],
803                                 [rjk_cv_shadow=no])
804                  CC="${oldCC}"])
805   if test $rjk_cv_shadow = yes; then
806     CC="${CC} -Wshadow"
807   fi
808 fi
809
810 RJK_GCOV
811
812 AH_BOTTOM([#ifdef __GNUC__
813 # define attribute(x) __attribute__(x)
814 #else
815 # define attribute(x)
816 #endif])
817
818 AC_CONFIG_FILES([Makefile
819                  images/Makefile
820                  scripts/Makefile
821                  lib/Makefile
822                  server/Makefile
823                  cgi/Makefile
824                  clients/Makefile
825                  disobedience/Makefile
826                  doc/Makefile
827                  templates/Makefile
828                  plugins/Makefile
829                  driver/Makefile
830                  debian/Makefile
831                  sounds/Makefile
832                  python/Makefile
833                  examples/Makefile
834                  libtests/Makefile
835                  tests/Makefile])
836 AC_OUTPUT
837
838 if test $GCC = yes && test "$gcc_werror" = ''; then
839   AC_MSG_WARN([building without -Werror])
840 fi
841 if test $want_python = no; then
842   AC_MSG_WARN([cannot run the test suit without Python])
843 fi
844 if test $want_server = yes && test "$ac_cv_lib_samplerate_src_new" != yes; then
845   AC_MSG_WARN([libsamplerate will be required in a future version])
846 fi
847
848 # Local Variables:
849 # indent-tabs-mode:nil
850 # End: