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