chiark / gitweb /
79778fddd4d45a6c367b546e2b5569619f046bae
[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 AC_CHECK_FUNCS(GC_get_all_interior_pointers)
479 AC_CHECK_LIB(gcrypt, gcry_md_open,
480              [AC_SUBST(LIBGCRYPT,[-lgcrypt])],
481             [missing_libraries="$missing_libraries libgcrypt"])
482 AC_CHECK_LIB(pcre, pcre_compile,
483              [AC_SUBST(LIBPCRE,[-lpcre])],
484              [missing_libraries="$missing_libraries libpcre"])
485 if test $want_alsa = yes; then
486   AC_CHECK_LIB([asound], [snd_pcm_open],
487                [AC_SUBST(LIBASOUND,[-lasound])])
488 fi
489 if test $want_pulseaudio = yes; then
490   PKG_CHECK_MODULES([PULSEAUDIO],[libpulse],
491                     [AC_DEFINE([HAVE_PULSEAUDIO],[1],[define to 1 for PulseAudio support])],
492                     [missing_libraries="$missing_libraries libpulse"])
493   PKG_CHECK_MODULES([PULSEAUDIO_SIMPLE],[libpulse-simple],,
494                     [missing_libraries="$missing_libraries libpulse-simple"])
495 fi
496 AC_CHECK_LIB([samplerate],[src_new],
497              [AC_SUBST([LIBSAMPLERATE],[-lsamplerate])])
498 if test $want_server = yes; then
499   RJK_CHECK_LIB(db, db_create, [#include <db.h>],
500                [AC_SUBST(LIBDB,[-ldb])],
501                [missing_libraries="$missing_libraries libdb"])
502   AC_CHECK_LIB(vorbis, vorbis_info_clear,
503                [:],
504                [missing_libraries="$missing_libraries libvorbis"])
505   AC_CHECK_LIB(vorbisfile, ov_open,
506                [AC_SUBST(LIBVORBISFILE,["-lvorbisfile -lvorbis"])],
507                [missing_libraries="$missing_libraries libvorbisfile"],
508                [-lvorbis])
509   AC_CHECK_LIB(mad, mad_stream_init,
510                [AC_SUBST(LIBMAD,[-lmad])],
511                [missing_libraries="$missing_libraries libmad"])
512   AC_CHECK_LIB([FLAC], [FLAC__stream_decoder_new],
513                [AC_SUBST(LIBFLAC,[-lFLAC])],
514                [missing_libraries="$missing_libraries libFLAC"])
515 fi
516 AC_CHECK_LIB([pthread], [pthread_create],
517              [AC_SUBST(LIBPTHREAD,[-lpthread])],
518              [missing_libraries="$missing_libraries libpthread"])
519
520 if test $want_gtk = yes; then
521   if test $want_gtkosx = yes; then
522     GTK_CFLAGS="-isystem /Library/Frameworks/Gtk.framework/Headers -isystem /Library/Frameworks/Cairo.framework/Headers"
523     GLIB_CFLAGS="-isystem /Library/Frameworks/GLib.framework/Headers"
524     GTK_LIBS="-framework Gtk -framework GLib"
525   else
526     AM_PATH_GLIB_2_0([],[],[missing_libraries="$missing_libraries libglib"])
527     AM_PATH_GTK_2_0([],[],[missing_libraries="$missing_libraries libgtk"])
528   fi
529 fi
530
531 # Some platforms have iconv already
532 AC_CHECK_FUNC(iconv_open, [:],
533               [RJK_CHECK_LIB(iconv, iconv_open, [#include <iconv.h>],
534                             [AC_SUBST(LIBICONV,[-liconv])],
535                             [missing_functions="$missing_functions iconv_open"])])
536 AC_CHECK_FUNC([gethostbyname],[:],[
537   AC_CHECK_LIB(nsl,gethostbyname,
538                [AC_SUBST(LIBNSL,[-lnsl])],
539                [missing_functions="$missing_functions gethostbyname"])])
540 AC_CHECK_FUNC([socket],[:],[
541   AC_CHECK_LIB(socket,socket,
542                [AC_SUBST(LIBSOCKET,[-lsocket])],
543                [missing_functions="$missing_functions socket"])])
544 AC_CHECK_FUNC([dlopen],[:],[
545   AC_CHECK_LIB(dl,dlopen,
546                [AC_SUBST(LIBDL,[-ldl])],
547                [missing_functions="$missing_functions dlopen"])])
548
549 if test ! -z "$missing_libraries"; then
550   AC_MSG_ERROR([missing libraries:$missing_libraries])
551 fi
552
553 # Checks for header files.
554 RJK_FIND_GC_H
555 if test $want_oss = yes; then
556   AC_CHECK_HEADERS([sys/soundcard.h])
557 fi
558 if test $want_alsa = yes; then
559   AC_CHECK_HEADERS([alsa/asoundlib.h])
560 fi
561 if test $want_coreaudio = yes; then
562   AC_CHECK_HEADERS([CoreAudio/AudioHardware.h])
563 fi
564 AC_CHECK_HEADERS([inttypes.h sys/time.h sys/socket.h netinet/in.h \
565                   arpa/inet.h sys/un.h netdb.h pcre.h pwd.h langinfo.h])
566 # We don't bother checking very standard stuff
567 # Compilation will fail if any of these headers are missing, so we
568 # check for them here and fail early.
569 if test $want_server = yes; then
570   AC_CHECK_HEADERS([db.h],[:],[
571     missing_headers="$missing_headers $ac_header"
572   ])
573 fi
574 AC_CHECK_HEADERS([dlfcn.h gcrypt.h \
575                  getopt.h iconv.h langinfo.h \
576                  pcre.h sys/ioctl.h \
577                  syslog.h unistd.h],[:],[
578   missing_headers="$missing_headers $ac_header"
579 ])
580 AC_CHECK_HEADERS([samplerate.h])
581
582 if test ! -z "$missing_headers"; then
583   AC_MSG_ERROR([missing headers:$missing_headers])
584 fi
585
586 # We require that libpcre support UTF-8
587 RJK_REQUIRE_PCRE_UTF8([-lpcre])
588
589 # Checks for typedefs, structures, and compiler characteristics.
590 AC_C_CONST
591 AC_TYPE_SIZE_T
592 AC_C_INLINE
593 AC_C_BIGENDIAN
594 AC_CHECK_TYPES([struct sockaddr_in6],,,[AC_INCLUDES_DEFAULT
595 #include <netinet/in.h>])
596
597 # Figure out how we'll check for devices being mounted and unmounted
598 AC_CACHE_CHECK([for list of mounted filesystems],[rjk_cv_mtab],[
599   if test -e /etc/mtab; then
600     rjk_cv_mtab=/etc/mtab
601   else
602     rjk_cv_mtab=none
603   fi
604 ])
605 if test $rjk_cv_mtab != none; then
606   AC_DEFINE_UNQUOTED([PATH_MTAB],["$rjk_cv_mtab"],[path to file containing mount list])
607 fi
608
609 # enable -Werror when we check for certain characteristics:
610
611 old_CFLAGS="${CFLAGS}"
612 CFLAGS="${CFLAGS} $gcc_werror"
613 AC_CHECK_TYPES([long long,uint32_t,uint16_t,uint8_t,intmax_t,uintmax_t])
614 CFLAGS="${old_CFLAGS}"
615
616 # gcrypt maintainers keep changing everything.  Design your interface
617 # first, then implement it once, rather than getting it wrong three or
618 # four times and shipping between each attempt.
619 AC_CACHE_CHECK([for hash handle type in <grypt.h>],
620                [rjk_cv_gcrypt_hash_handle],[
621   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
622 #include <gcrypt.h>
623 ],
624                [gcry_md_hd_t h;])],
625                [rjk_cv_gcrypt_hash_handle=gcry_md_hd_t],[
626     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
627 #include <gcrypt.h>
628 ],
629                  [GcryMDHd h;])],
630                  [rjk_cv_gcrypt_hash_handle=GcryMDHd],
631                  [rjk_cv_gcrypt_hash_handle=GCRY_MD_HD])])])
632 AC_DEFINE_UNQUOTED([gcrypt_hash_handle],[$rjk_cv_gcrypt_hash_handle],
633                    [libgcrypt hash handle type])
634
635 AC_CACHE_CHECK([for gcry_error_t in <grypt.h>],
636                [rjk_cv_have_gcry_error_t],[
637   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
638 #include <gcrypt.h>
639 ],
640                  [gcry_error_t e;])],
641                  [rjk_cv_have_gcry_error_t=yes],
642                  [rjk_cv_have_gcry_error_t=no])])
643 if test $rjk_cv_have_gcry_error_t = yes; then
644   AC_DEFINE([HAVE_GCRY_ERROR_T],1,[define if <gcrypt.h> defines gcry_error_t])
645 fi
646
647 # Checks for functions
648 if test $ac_cv_type_long_long = yes; then
649   AC_CHECK_FUNCS([atoll strtoll],[:],[
650     missing_functions="$missing_functions $ac_func"
651   ])
652   # Darwin sometimes fails to declare strtoll (e.g. if you ask for -std=c99)
653   AC_CACHE_CHECK([whether strtoll is declared in <stdlib.h>],
654                  [rjk_cv_strtoll_declared],[
655     AC_EGREP_HEADER([strtoll], [stdlib.h],
656                     [rjk_cv_strtoll_declared=yes],
657                     [rjk_cv_strtoll_declared=no])])
658   if test $rjk_cv_strtoll_declared = yes; then
659     AC_DEFINE([DECLARES_STRTOLL],[1],[define if <stdlib.h> declares strtoll])
660   fi
661   AC_CACHE_CHECK([whether atoll is declared in <stdlib.h>],
662                  [rjk_cv_atoll_declared],[
663     AC_EGREP_HEADER([atoll], [stdlib.h],
664                     [rjk_cv_atoll_declared=yes],
665                     [rjk_cv_atoll_declared=no])])
666   if test $rjk_cv_atoll_declared = yes; then
667     AC_DEFINE([DECLARES_ATOLL],[1],[define if <stdlib.h> declares atoll])
668   fi
669 fi
670 AC_CHECK_FUNCS([ioctl nl_langinfo strsignal setenv unsetenv],[:],[
671   missing_functions="$missing_functions $ac_func"
672 ])
673 # fsync will do if fdatasync not available
674 AC_CHECK_FUNCS([fdatasync],[:],[
675   AC_CHECK_FUNCS([fsync],
676                  [AC_DEFINE([fdatasync],[fsync],[define fdatasync to fsync if not available])],
677                  [missing_functions="$missing_functions fdatasync"])])
678 if test ! -z "$missing_functions"; then
679   AC_MSG_ERROR([missing functions:$missing_functions])
680 fi
681 # dlsym will do if dlfunc not available
682 AC_CHECK_FUNCS([dlfunc],[:],[
683   AC_DEFINE([dlfunc],[dlsym],[define dlfunc to dlsym if not available])
684 ])
685 if test ! -z "$missing_functions"; then
686   AC_MSG_ERROR([missing functions:$missing_functions])
687 fi
688
689 # Functions we can take or leave
690 AC_CHECK_FUNCS([fls getfsstat closesocket])
691
692 if test $want_server = yes; then
693   # <db.h> had better be version 3 or later
694   AC_CACHE_CHECK([db.h version],[rjk_cv_db_version],[
695     AC_PREPROC_IFELSE([AC_LANG_PROGRAM([
696                        #include <db.h>
697                        #ifndef DB_VERSION_MAJOR
698                        # error cannot determine db version
699                        #endif
700                        #if DB_VERSION_MAJOR < 4
701                        # error inadequate db version
702                        #endif
703                        #if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR <= 2
704                        # error inadequate db version
705                        #endif
706                       ],[])],
707                       [rjk_cv_db_version=ok],
708                       [rjk_cv_db_version=inadequate])
709     if test $rjk_cv_db_version = ok; then
710       AC_PREPROC_IFELSE([AC_LANG_PROGRAM([
711                          #include <db.h>
712                          #if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR == 6
713                          # error http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=510270
714                          #endif
715                         ],[])],
716                         [rjk_cv_db_version=ok],
717                         [rjk_cv_db_version=toxic])
718     fi
719   ])
720   case $rjk_cv_db_version in
721   ok )
722     ;;
723   inadequate )
724     AC_MSG_ERROR([need db version at least 4.3 (but not 4.6)])
725     ;;
726   toxic )
727     AC_MSG_ERROR([db version 4.6.x does not work - see debian bug 510270])
728     ;;
729   esac
730 fi
731
732 AM_CONDITIONAL([SERVER], [test x$want_server = xyes])
733 if test $want_gtk = yes; then
734   AC_DEFINE([WITH_GTK], [1], [define if using GTK+])
735 fi
736 AM_CONDITIONAL([GTK], [test x$want_gtk = xyes])
737 AM_CONDITIONAL([GSTDECODE], [test x$want_gstdecode = xyes])
738
739 # Some GCC invocations warn for converting function pointers to void *.
740 # This is fair enough, as it's technically forbidden, but we use dlsym()
741 # which can pretty much only exist if object and function pointers are
742 # interconvertable.  So we disable -Werror if need be.
743 if test ! -z "$gcc_werror" && test "$ac_cv_func_dlfunc" != yes; then
744   CFLAGS="${CFLAGS} $gcc_werror"
745   AC_CACHE_CHECK([whether function pointers can be converted to void * without a warning],
746                  [rjk_cv_function_pointer_cast],[
747     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
748   void somefunction(void);],
749                       [(void *)somefunction])],
750                       [rjk_cv_function_pointer_cast=yes],
751                       [rjk_cv_function_pointer_cast=no])])
752   if test $rjk_cv_function_pointer_cast = no; then
753     gcc_werror=""
754   fi
755   CFLAGS="${old_CFLAGS}"
756 fi
757
758 if test "x$GCC" = xyes; then
759   # We need LLONG_MAX and annoyingly GCC doesn't always give it to us
760   # by default.
761   AC_CACHE_CHECK([what C version to ask for],[rjk_cv_cstd],[
762     AC_TRY_COMPILE([#include <limits.h>],[
763       long long n = LLONG_MAX;
764     ],[rjk_cv_cstd=default],[
765       old_CC="$CC"
766       CC="${CC} -std=gnu99"
767       AC_TRY_COMPILE([#include <limits.h>],[
768         long long n = LLONG_MAX;
769       ],[rjk_cv_cstd=gnu99],[rjk_cv_cstd=unknown])
770       CC="$old_CC"
771     ])
772   ])
773   case $rjk_cv_cstd in
774   default | unknown )
775     ;;
776   * )
777     CC="${CC} -std=${rjk_cv_cstd}"
778     ;;
779   esac
780
781   # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29478
782   AC_CACHE_CHECK([checking for GCC bug 29478],[rjk_cv_pr29478],[
783     old_CC="$CC"
784     if test $GCC = yes; then
785       CC="$CC -Wall -Werror"
786     fi
787     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
788       static int x(char *f) {
789        return *f;
790       }
791       int z(const char *g) {
792         return x((char *)g);
793       }],[])],
794       [rjk_cv_pr29478=no],
795       [rjk_cv_pr29478=yes]
796     )
797     CC="$old_CC"
798   ])
799   if test $rjk_cv_pr29478 = yes; then
800     gcc_werror=''
801   fi
802
803   AC_CACHE_CHECK([checking for excessively strict -Wreturn-type],
804                  [rjk_cv_gcc44_stupidity],[
805     old_CC="$CC"
806     if test $GCC = yes; then
807       CC="$CC -Wreturn-type -Werror"
808     fi
809     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[
810       static void *threadfn(void) {
811         for(;;)
812           ;
813       }],[])],
814       [rjk_cv_gcc44_stupidity=no],
815       [rjk_cv_gcc44_stupidity=yes])
816     CC="$old_CC"
817   ])
818   if test $rjk_cv_gcc44_stupidity = yes; then
819     AC_DEFINE([HAVE_STUPID_GCC44],[1],[Define if your compiler has excessively strict -Wreturn-type])
820   fi
821
822   # a reasonable default set of warnings
823   CC="${CC} -Wall -W -Wpointer-arith \
824         -Wwrite-strings -Wmissing-prototypes \
825         -Wmissing-declarations -Wnested-externs"
826
827   # Fix up GTK+ and GLib compiler flags
828   GTK_CFLAGS="`echo \"$GTK_CFLAGS\"|sed 's/-I/-isystem /g'`"
829   GLIB_CFLAGS="`echo \"$GLIB_CFLAGS\"|sed 's/-I/-isystem /g'`"
830
831   if test "$gcc_werror" != ''; then
832     # GCC 2.95 doesn't know to ignore warnings from system headers
833     AC_CACHE_CHECK([whether -Werror is usable],
834                     rjk_cv_werror, [
835       save_CFLAGS="${CFLAGS}"
836       CFLAGS="${CFLAGS} ${GTK_CFLAGS} -Werror"
837       AC_TRY_COMPILE([#if WITH_GTK
838  #include <gtk/gtk.h>
839 #endif
840
841 struct s { int a, b; };
842 const struct s sv = { .a = 1 };],
843                      [],
844                      [rjk_cv_werror=yes],
845                      [rjk_cv_werror=no])
846       CFLAGS="${save_CFLAGS}"
847     ])
848     if test $rjk_cv_werror = no; then
849       gcc_werror=''
850     fi
851   fi
852   CC="${CC} $gcc_werror"
853
854   # for older GCCs that don't know %ju (etc)
855   AC_CACHE_CHECK([whether -Wno-format is required],
856                  rjk_cv_noformat,
857                  AC_TRY_COMPILE([#include <stdio.h>
858 #include <stdint.h>
859 ],
860                                 [printf("%ju", (uintmax_t)0);],
861                                 [rjk_cv_noformat=no],
862                                 [rjk_cv_noformat=yes]))
863   if test $rjk_cv_noformat = yes; then
864     CC="${CC} -Wno-format"
865   fi
866
867   AC_CACHE_CHECK([whether -Wshadow is OK],
868                  rjk_cv_shadow,
869                  oldCC="${CC}"
870                  CC="${CC} -Wshadow"
871                  [AC_TRY_COMPILE([
872 #include <unistd.h>
873 #include <vorbis/vorbisfile.h>
874 ],
875                                 [],
876                                 [rjk_cv_shadow=yes],
877                                 [rjk_cv_shadow=no])
878                  CC="${oldCC}"])
879   if test $rjk_cv_shadow = yes; then
880     CC="${CC} -Wshadow"
881   fi
882 fi
883
884 RJK_GCOV
885
886 AH_BOTTOM([#ifdef __GNUC__
887 # define attribute(x) __attribute__(x)
888 #else
889 # define attribute(x)
890 #endif])
891
892 AC_CONFIG_FILES([Makefile
893                  images/Makefile
894                  scripts/Makefile
895                  common/Makefile
896                  lib/Makefile
897                  server/Makefile
898                  cgi/Makefile
899                  clients/Makefile
900                  disobedience/Makefile
901                  disobedience/manual/Makefile
902                  doc/Makefile
903                  templates/Makefile
904                  plugins/Makefile
905                  debian/Makefile
906                  sounds/Makefile
907                  python/Makefile
908                  examples/Makefile
909                  libtests/Makefile
910                  tests/Makefile])
911 AC_OUTPUT
912
913 if test $GCC = yes && test "$gcc_werror" = ''; then
914   AC_MSG_WARN([building without -Werror])
915 fi
916 if test $want_python = no; then
917   AC_MSG_WARN([cannot run the test suit without Python])
918 fi
919 if test $want_server = yes && test "$ac_cv_lib_samplerate_src_new" != yes; then
920   AC_MSG_WARN([libsamplerate will be required in a future version])
921 fi
922
923 # Local Variables:
924 # indent-tabs-mode:nil
925 # End: