Don't forget to include <stdint.h>.
[herrie-working.git] / herrie / configure
blobc69ef4dfdc5e2a848b67e5d7629329d490af102c
1 #!/bin/sh
2 #
3 # Copyright (c) 2006-2009 Ed Schouten <ed@80386.nl>
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 # SUCH DAMAGE.
28 APP_NAME=herrie
29 APP_VERSION=2.2
30 APP_LINGUAS='ca da de es fi fr ga nl pl pt_BR ru sv tr uk vi zh_CN'
32 # Default compilation switches
33 CFG_AO=oss
34 unset CFG_BINEXT
35 CFG_CURSES_HEADER=ncurses
36 CFG_CURSES_LIB=ncursesw
37 CFG_DBUS=yes
38 CFG_HTTP=yes
39 CFG_MODPLUG=yes
40 CFG_MP3=yes
41 CFG_RES_INIT=yes
42 CFG_SCROBBLER=yes
43 unset CFG_SETPROCTITLE
44 CFG_SNDFILE=yes
45 unset CFG_DEBUG
46 unset CFG_STRICT
47 CFG_STRIP=-s
48 unset CFG_VOLUME
49 CFG_VORBIS=yes
50 CFG_XSPF=yes
51 DOIT=@
53 # Operating system defaults
54 [ "$OS" != "" ] || OS=`uname`
55 case $OS in
56 CYGWIN*|Windows_*)
57 CFG_BINEXT=.exe
58 unset CFG_HTTP
59 unset CFG_RES_INIT
60 [ "$CONFDIR" = "" ] && CONFDIR=/etc
61 [ "$PREFIX" = "" ] && PREFIX=/usr
63 Darwin)
64 CFG_AO=coreaudio
65 LDFLAGS="$LDFLAGS -lresolv"
66 [ "$PREFIX" = "" ] && PREFIX=/opt/local
68 FreeBSD)
69 CFG_SETPROCTITLE=yes
70 [ "$PREFIX" = "" ] && PREFIX=/usr/local
71 [ "$MANDIR" = "" ] && MANDIR=$PREFIX/man
73 GNU/kFreeBSD)
74 [ "$CONFDIR" = "" ] && CONFDIR=/etc
75 [ "$PREFIX" = "" ] && PREFIX=/usr
77 Linux)
78 CFG_AO=alsa
79 [ "$CONFDIR" = "" ] && CONFDIR=/etc
80 [ "$PREFIX" = "" ] && PREFIX=/usr
82 NetBSD)
83 CFG_SETPROCTITLE=yes
84 [ "$PREFIX" = "" ] && PREFIX=/usr/pkg
86 OpenBSD)
87 CFG_SETPROCTITLE=yes
88 [ "$PREFIX" = "" ] && PREFIX=/usr/local
89 [ "$MANDIR" = "" ] && MANDIR=$PREFIX/man
91 SunOS)
92 CFG_AO=ao
93 unset CFG_HTTP
94 [ "$PREFIX" = "" ] && PREFIX=/opt/sfw
95 LDFLAGS="$LDFLAGS -lresolv"
96 [ "$INSTALL" = "" ] && INSTALL=ginstall
99 echo "Warning: unknown operating system: $OS"
100 CFG_AO=ao
101 [ "$PREFIX" = "" ] && PREFIX=/usr/local
102 esac
103 SRCDIR=`dirname $0`
104 BINDIR=$PREFIX/bin
105 [ "$CONFDIR" = "" ] && CONFDIR=$PREFIX/etc
106 CONFFILE=$CONFDIR/$APP_NAME.conf
107 [ "$LINGUAS" = "" ] && LINGUAS=$APP_LINGUAS
108 [ "$MANDIR" = "" ] && MANDIR=$PREFIX/share/man
109 TRANSDIR=$PREFIX/share/locale
110 [ "$CC" = "" ] && CC=cc
111 [ "$INSTALL" = "" ] && INSTALL=install
112 MANPARTS="00-man 02-man 04-man 06-man"
113 MANREGEX="-e 's|%%CONFFILE%%|$CONFFILE|'"
115 # Command line options
116 while [ $# -gt 0 ]
118 case $1 in
119 no_dbus)
120 unset CFG_DBUS
122 no_http)
123 unset CFG_HTTP
125 no_modplug)
126 unset CFG_MODPLUG
128 no_mp3)
129 unset CFG_MP3
131 no_scrobbler)
132 unset CFG_SCROBBLER
134 no_sndfile)
135 unset CFG_SNDFILE
137 no_nls)
138 unset LINGUAS
140 no_vorbis)
141 unset CFG_VORBIS
143 no_xspf)
144 unset CFG_XSPF
147 alsa|ao|coreaudio|null|oss|pulse)
148 CFG_AO=$1
151 no_strip)
152 unset CFG_STRIP
154 debug)
155 CFG_DEBUG=yes
156 unset CFG_STRIP
158 strict)
159 CFG_STRICT=yes
161 verbose)
162 unset DOIT
165 ncurses)
166 CFG_CURSES_HEADER=ncurses
167 CFG_CURSES_LIB=ncurses
169 xcurses)
170 CFG_CURSES_HEADER=xcurses
171 CFG_CURSES_LIB=XCurses
175 echo "Error: unknown option: $1"
176 echo "See the README file for a list of valid options"
177 exit 1
178 esac
180 shift
181 done
183 test_pkgconfig()
185 PKG_CFLAGS="`pkg-config --cflags $2 2> /dev/null`"
186 if [ $? -ne 0 ]
187 then
188 echo "Error: $1 not found"
189 exit 1
191 eval CFLAGS$3="\"\$CFLAGS$3 \$PKG_CFLAGS\""
193 LDFLAGS="$LDFLAGS `pkg-config --libs $2`"
196 [ "$CFLAGS" = "" ] && CFLAGS="-O"
197 CFLAGS="$CFLAGS -DAPP_NAME=\\\"$APP_NAME\\\" \
198 -DAPP_VERSION=\\\"$APP_VERSION\\\" \
199 -I$PREFIX/include -I$PREFIX/include/ncursesw \
200 -I$PREFIX/include/ncurses -DCURSES_HEADER=\\<$CFG_CURSES_HEADER.h\\>"
201 if [ $? -ne 0 ]
202 then
203 echo "Error: Glib not found"
204 exit 1
206 CFLAGS_main="-DAUDIO_OUTPUT=\\\"$CFG_AO\\\" -DCONFFILE=\\\"$CONFFILE\\\""
207 LDFLAGS="$LDFLAGS -L$PREFIX/lib -l$CFG_CURSES_LIB"
208 SRCS="audio_file audio_output_$CFG_AO config gui_browser gui_draw \
209 gui_input gui_msgbar gui_playq gui_vfslist main playq playq_party \
210 playq_xmms vfs vfs_playlist vfs_regular"
212 # We always use glib
213 test_pkgconfig "GLib" "glib-2.0" ""
214 test_pkgconfig "GLib threading library" "gthread-2.0" ""
216 # DBus integration
217 if [ "$CFG_DBUS" != "" ]
218 then
219 test_pkgconfig "dbus-glib" "dbus-glib-1" ""
220 CFLAGS="$CFLAGS -DBUILD_DBUS -I."
221 SRCS="$SRCS dbus"
222 DEPENDS_EXTRA_dbus="dbus_binding.h"
225 # HTTP and Scrobbler code need cURL
226 if [ "$CFG_HTTP" != "" -o "$CFG_SCROBBLER" != "" ]
227 then
228 if [ "$CFG_HTTP" != "" ]
229 then
230 CFLAGS="$CFLAGS -DBUILD_HTTP"
231 SRCS="$SRCS vfs_http"
233 if [ "$CFG_SCROBBLER" != "" ]
234 then
235 CFLAGS="$CFLAGS -DBUILD_SCROBBLER"
236 SRCS="$SRCS md5 scrobbler util"
237 MANPARTS="$MANPARTS 05-scrobbler"
239 test_pkgconfig "cURL" "libcurl" ""
241 # Modplug support
242 if [ "$CFG_MODPLUG" != "" ]
243 then
244 CFLAGS="$CFLAGS -DBUILD_MODPLUG"
245 test_pkgconfig "libmodplug" "libmodplug" "_audio_format_modplug"
246 SRCS="$SRCS audio_format_modplug"
248 # MP3 support
249 if [ "$CFG_MP3" != "" ]
250 then
251 CFLAGS="$CFLAGS -DBUILD_MP3"
252 LDFLAGS="$LDFLAGS -lmad -lid3tag"
253 #test_pkgconfig "libmad" "mad" "_audio_format_mp3"
254 #test_pkgconfig "libid3tag" "id3tag" "_audio_format_mp3"
255 SRCS="$SRCS audio_format_mp3"
257 # res_init() usage
258 [ "$CFG_RES_INIT" != "" ] && CFLAGS="$CFLAGS -DBUILD_RES_INIT"
259 # setproctitle() usage
260 [ "$CFG_SETPROCTITLE" != "" ] && CFLAGS_gui_playq="-DBUILD_SETPROCTITLE"
261 # libsndfile support
262 if [ "$CFG_SNDFILE" != "" ]
263 then
264 CFLAGS="$CFLAGS -DBUILD_SNDFILE"
265 LDFLAGS="$LDFLAGS -lsndfile"
266 SRCS="$SRCS audio_format_sndfile"
268 # Strict compilation
269 [ "$CFG_STRICT" != "" ] && CFLAGS="$CFLAGS -Wall -Wmissing-prototypes -Wsign-compare -Werror"
270 [ "$CFG_DEBUG" != "" ] && CFLAGS="$CFLAGS -g -DBUILD_DEBUG"
271 # Translation support
272 # Remove all broken translations
273 unset CFG_LINGUAS
274 unset MOS
275 for i in `echo $LINGUAS | xargs -n 1 | sort | uniq`
277 for j in $APP_LINGUAS
279 if [ "$i" = "$j" ]
280 then
281 CFG_LINGUAS="$CFG_LINGUAS $i"
282 MOS="$MOS $i.mo"
283 continue 2
285 done
286 echo "Warning: unknown language: $i"
287 done
288 if [ "$CFG_LINGUAS" != "" ]
289 then
290 CFLAGS="$CFLAGS -DBUILD_NLS"
291 CFLAGS_main="$CFLAGS_main -DTRANSDIR=\\\"$TRANSDIR\\\""
293 # Ogg Vorbis support
294 if [ "$CFG_VORBIS" != "" ]
295 then
296 CFLAGS="$CFLAGS -DBUILD_VORBIS"
297 LDFLAGS="$LDFLAGS -lvorbisfile"
298 SRCS="$SRCS audio_format_vorbis"
300 # XSPF support
301 if [ "$CFG_XSPF" != "" ]
302 then
303 CFLAGS="$CFLAGS -DBUILD_XSPF"
304 test_pkgconfig "libxspf" "xspf" "_vfs_xspf"
305 SRCS="$SRCS util vfs_xspf"
306 PLAYQ_DUMPFILE="autosave.xspf"
307 else
308 PLAYQ_DUMPFILE="autosave.pls"
310 CFLAGS_config="$CFLAGS_config -DPLAYQ_DUMPFILE=\\\"$PLAYQ_DUMPFILE\\\""
311 MANREGEX="$MANREGEX -e 's|%%PLAYQ_DUMPFILE%%|$PLAYQ_DUMPFILE|'"
313 # Audio output options
314 case $CFG_AO in
315 alsa)
316 CFG_VOLUME=yes
317 CFLAGS="$CFLAGS -DBUILD_ALSA"
318 LDFLAGS="$LDFLAGS -lasound"
319 MANPARTS="$MANPARTS 03-alsa"
322 CFLAGS="$CFLAGS -DBUILD_AO"
323 CFLAGS_main="$CFLAGS_main -DCLOSE_STDERR"
324 LDFLAGS="$LDFLAGS -lao"
325 MANPARTS="$MANPARTS 03-ao"
327 coreaudio)
328 CFG_VOLUME=yes
329 LDFLAGS="$LDFLAGS -framework CoreAudio"
331 oss)
332 case $OS in
333 NetBSD|OpenBSD)
334 CFLAGS="$CFLAGS -DOSS_HEADER=\\<soundcard.h\\>"
335 LDFLAGS="$LDFLAGS -lossaudio"
336 OSS_DEVICE="/dev/audio"
339 # The OSS-through-ALSA compat may generate noise
340 [ "$OS" = "Linux" ] && CFLAGS_main="$CFLAGS_main -DCLOSE_STDERR"
341 CFLAGS="$CFLAGS -DOSS_HEADER=\\<sys/soundcard.h\\>"
342 OSS_DEVICE="/dev/dsp"
344 esac
345 CFG_VOLUME=yes
346 CFLAGS="$CFLAGS -DBUILD_OSS -I$PREFIX/lib/oss/include"
347 CFLAGS_config="$CFLAGS_config -DOSS_DEVICE=\\\"$OSS_DEVICE\\\""
348 MANPARTS="$MANPARTS 03-oss"
349 MANREGEX="$MANREGEX -e 's|%%OSS_DEVICE%%|$OSS_DEVICE|'"
351 pulse)
352 CFLAGS="$CFLAGS -DBUILD_PULSE"
353 test_pkgconfig "PulseAudio" "libpulse-simple" "_audio_output_pulse"
355 esac
357 if [ "$CFG_VOLUME" != "" ]
358 then
359 CFLAGS="$CFLAGS -DBUILD_VOLUME"
360 MANPARTS="$MANPARTS 01-volume"
363 echo "Configuration:"
364 echo "- Installing $APP_NAME$CFG_BINEXT in $BINDIR"
365 echo "- Installing manual page in $MANDIR"
366 echo "- Using $CONFFILE configuration file"
367 [ "$CFG_LINGUAS" != "" ] && echo "- Installing translations$CFG_LINGUAS in $TRANSDIR"
368 echo "- Using -l$CFG_CURSES_LIB and <$CFG_CURSES_HEADER.h>"
369 echo "- Using $CFG_AO audio output"
370 [ "$CFG_DBUS" != "" ] && echo "- Support for DBus integration"
371 [ "$CFG_HTTP" != "" ] && echo "- Support for HTTP streams"
372 [ "$CFG_MODPLUG" != "" ] && echo "- Support for libmodplug"
373 [ "$CFG_MP3" != "" ] && echo "- Support for MP3"
374 [ "$CFG_SCROBBLER" != "" ] && echo "- Support for AudioScrobbler"
375 [ "$CFG_SNDFILE" != "" ] && echo "- Support for libsndfile"
376 [ "$CFG_VORBIS" != "" ] && echo "- Support for Ogg Vorbis"
377 [ "$CFG_XSPF" != "" ] && echo "- Support for XSPF (\`Spiff')"
378 echo
380 # Perform a simple compiler test
381 eval $CC $SRCDIR/src/conftest.c $CFLAGS $LDFLAGS -o conftest$CFG_BINEXT
382 if [ $? -ne 0 ]
383 then
384 echo "Error: some dependencies are missing"
385 echo "See the README file for a list of dependencies"
386 exit 1
388 rm -f conftest$CFG_BINEXT
389 rm -Rf conftest.dSYM
391 # Don't generate duplicate rules
392 SRCS=`echo $SRCS | xargs -n 1 | sort | uniq`
394 unset OBJS
395 for i in $SRCS
397 OBJS="$OBJS $i.o"
398 done
399 unset MANFILES
400 for i in `echo $MANPARTS | xargs -n 1 | sort | uniq`
402 MANFILES="$MANFILES $SRCDIR/man/$i"
403 done
405 (cat << EOF
406 all: $APP_NAME$CFG_BINEXT $APP_NAME.1.gz $SRCDIR/$APP_NAME.conf.sample $MOS
407 $APP_NAME$CFG_BINEXT: $OBJS
408 # Linking $APP_NAME$CFG_BINEXT
409 $DOIT$CC $OBJS $LDFLAGS -o $APP_NAME$CFG_BINEXT
410 $APP_NAME.1.gz: $MANFILES Makefile
411 # Generating manual page $APP_NAME.1.gz
412 ${DOIT}sed $MANREGEX $MANFILES | gzip -9 > $APP_NAME.1.gz
413 clean:
414 # Removing $APP_NAME$CFG_BINEXT $APP_NAME.1.gz dbus_binding.h *.mo *.o
415 ${DOIT}rm -f $APP_NAME$CFG_BINEXT $APP_NAME.1.gz dbus_binding.h *.mo *.o
416 distclean: clean
417 # Removing Makefile
418 ${DOIT}rm -f Makefile
419 Makefile: $0 `dirname $0`/depends
420 # WARNING: Your Makefile is outdated. Please re-run $0!
421 dbus_binding.h: Makefile $SRCDIR/src/dbus.xml
422 # Generating dbus_binding.h
423 ${DOIT}dbus-binding-tool --mode=glib-server --prefix=dbus_server --output=dbus_binding.h $SRCDIR/src/dbus.xml
424 install: all
425 # Installing \$(DESTDIR)$BINDIR/$APP_NAME$CFG_BINEXT
426 ${DOIT}mkdir -p \$(DESTDIR)$BINDIR
427 $DOIT$INSTALL $CFG_STRIP $APP_NAME$CFG_BINEXT \$(DESTDIR)$BINDIR/$APP_NAME$CFG_BINEXT
428 # Installing \$(DESTDIR)$MANDIR/man1/$APP_NAME.1.gz
429 ${DOIT}mkdir -p \$(DESTDIR)$MANDIR/man1
430 $DOIT$INSTALL -m 444 $APP_NAME.1.gz \$(DESTDIR)$MANDIR/man1/$APP_NAME.1.gz
431 # Installing \$(DESTDIR)$CONFDIR/$APP_NAME.conf.sample
432 ${DOIT}mkdir -p \$(DESTDIR)$CONFDIR
433 $DOIT$INSTALL -m 444 $SRCDIR/$APP_NAME.conf.sample \$(DESTDIR)$CONFDIR/$APP_NAME.conf.sample
435 for i in $CFG_LINGUAS
437 echo " # Installing \$(DESTDIR)$TRANSDIR/$i/LC_MESSAGES/$APP_NAME.mo"
438 echo " ${DOIT}mkdir -p \$(DESTDIR)$TRANSDIR/$i/LC_MESSAGES"
439 echo " $DOIT$INSTALL -m 444 $i.mo \$(DESTDIR)$TRANSDIR/$i/LC_MESSAGES/$APP_NAME.mo"
440 done
441 cat << EOF
442 uninstall:
443 # Uninstalling \$(DESTDIR)$BINDIR/$APP_NAME$CFG_BINEXT
444 ${DOIT}rm -f \$(DESTDIR)$BINDIR/$APP_NAME$CFG_BINEXT
445 # Uninstalling \$(DESTDIR)$MANDIR/man1/$APP_NAME.1.gz
446 ${DOIT}rm -f \$(DESTDIR)$MANDIR/man1/$APP_NAME.1.gz
447 # Uninstalling \$(DESTDIR)$CONFDIR/$APP_NAME.conf.sample
448 ${DOIT}rm -f \$(DESTDIR)$CONFDIR/$APP_NAME.conf.sample
450 for i in $CFG_LINGUAS
452 echo " # Uninstalling \$(DESTDIR)$TRANSDIR/$i/LC_MESSAGES/$APP_NAME.mo"
453 echo " ${DOIT}rm -f \$(DESTDIR)$TRANSDIR/$i/LC_MESSAGES/$APP_NAME.mo"
454 done
455 . $SRCDIR/depends
456 for i in $SRCS
458 unset DEPS
459 for j in `eval echo \\\$DEPENDS_\$i`
461 DEPS="$DEPS $SRCDIR/src/$j.h"
462 done
463 echo "$i.o: Makefile $SRCDIR/src/$i.c $SRCDIR/src/stdinc.h $DEPS `eval echo \\\$DEPENDS_EXTRA_\$i`"
464 echo " # Compiling $i.o"
465 echo " $DOIT$CC -c $SRCDIR/src/$i.c $CFLAGS `eval echo \\\$CFLAGS_\$i` -o $i.o"
466 done
467 for i in $CFG_LINGUAS
469 echo "$i.mo: $SRCDIR/po/$i.po"
470 echo " # Generating translation $i.mo"
471 echo " ${DOIT}msgfmt -o $i.mo $SRCDIR/po/$i.po"
472 done) > Makefile
474 echo "Run \`make' to compile $APP_NAME"