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