Do not use backslash-b to select backspaces.
[mp-5.x.git] / config.sh
blob6840f0aed2d4ed100bc6e23d0dbd37c486bdbdf7
1 #!/bin/sh
3 # Minimum Profit autoconfiguration script
5 DRIVERS=""
6 DRV_OBJS=""
7 APPNAME="mp-5"
9 # gets program version
10 VERSION=`cut -f2 -d\" VERSION`
12 # default installation prefix
13 PREFIX=/usr/local
15 # store command line args for configuring the libraries
16 CONF_ARGS="$*"
18 # add a default value for WINDRES
19 [ -z "$WINDRES" ] && WINDRES="windres"
21 # No KDE4 by default
22 WITHOUT_KDE4=1
24 # parse arguments
25 while [ $# -gt 0 ] ; do
27 case $1 in
28 --without-curses) WITHOUT_CURSES=1 ;;
29 --without-gtk) WITHOUT_GTK=1 ;;
30 --without-win32) WITHOUT_WIN32=1 ;;
31 --with-kde4) WITHOUT_KDE4=0 ;;
32 --without-qt4) WITHOUT_QT4=1 ;;
33 --help) CONFIG_HELP=1 ;;
35 --mingw32) CC=i586-mingw32msvc-cc
36 WINDRES=i586-mingw32msvc-windres
37 AR=i586-mingw32msvc-ar
38 CFLAGS="-O3 $CFLAGS"
41 --debian) BUILD_FOR_DEBIAN=1
42 PREFIX=/usr
43 APPNAME=mped
46 --prefix) PREFIX=$2 ; shift ;;
47 --prefix=*) PREFIX=`echo $1 | sed -e 's/--prefix=//'` ;;
48 esac
50 shift
51 done
53 if [ "$CONFIG_HELP" = "1" ] ; then
55 echo "Available options:"
56 echo "--prefix=PREFIX Installation prefix ($PREFIX)."
57 echo "--without-curses Disable curses (text) interface detection."
58 echo "--without-gtk Disable GTK interface detection."
59 echo "--without-win32 Disable win32 interface detection."
60 echo "--with-kde4 Enable KDE4 interface detection."
61 echo "--without-qt4 Disable Qt4 interface detection."
62 echo "--without-unix-glob Disable glob.h usage (use workaround)."
63 echo "--with-included-regex Use included regex code (gnu_regex.c)."
64 echo "--with-pcre Enable PCRE library detection."
65 echo "--without-gettext Disable gettext usage."
66 echo "--without-iconv Disable iconv usage."
67 echo "--without-wcwidth Disable system wcwidth() (use workaround)."
68 echo "--with-null-hash Tell MPDM to use a NULL hashing function."
69 echo "--mingw32 Build using the mingw32 compiler."
70 echo "--debian Build for Debian ('make deb')."
72 echo
73 echo "Environment variables:"
74 echo "CC C Compiler."
75 echo "AR Library Archiver."
76 echo "CFLAGS Compile flags (i.e., -O3)."
77 echo "WINDRES MS Windows resource compiler."
79 exit 1
82 echo "Configuring..."
84 echo "/* automatically created by config.sh - do not modify */" > config.h
85 echo "# automatically created by config.sh - do not modify" > makefile.opts
86 > config.ldflags
87 > config.cflags
88 > .config.log
90 # set compiler
91 if [ "$CC" = "" ] ; then
92 CC=cc
93 # if CC is unset, try if gcc is available
94 which gcc > /dev/null 2>&1 && CC=gcc
97 if [ "$CPP" = "" ] ; then
98 CPP=c++
99 # if CC is unset, try if gcc is available
100 which g++ > /dev/null 2>&1 && CPP=g++
103 MOC="moc"
104 which moc-qt4 > /dev/null 2>&1 && MOC=moc-qt4
106 echo "CC=$CC" >> makefile.opts
107 echo "CPP=$CPP" >> makefile.opts
108 echo "MOC=$MOC" >> makefile.opts
110 # add version
111 cat VERSION >> config.h
113 # add installation prefix and application name
114 echo "#define CONFOPT_PREFIX \"$PREFIX\"" >> config.h
115 echo "#define CONFOPT_APPNAME \"$APPNAME\"" >> config.h
117 ################################################################
119 # CFLAGS
120 if [ -z "$CFLAGS" ] ; then
121 CFLAGS="-g -Wall"
124 echo -n "Testing if C compiler supports ${CFLAGS}... "
125 echo "int main(int argc, char *argv[]) { return 0; }" > .tmp.c
127 $CC .tmp.c -o .tmp.o 2>> .config.log
129 if [ $? = 0 ] ; then
130 echo "OK"
131 else
132 echo "No; resetting to defaults"
133 CFLAGS=""
136 echo "CFLAGS=$CFLAGS" >> makefile.opts
138 # Add CFLAGS to CC
139 CC="$CC $CFLAGS"
141 # MPDM
142 echo -n "Looking for MPDM... "
144 for MPDM in ./mpdm ../mpdm NOTFOUND ; do
145 if [ -d $MPDM ] && [ -f $MPDM/mpdm.h ] ; then
146 break
148 done
150 if [ "$MPDM" != "NOTFOUND" ] ; then
151 echo "-I$MPDM" >> config.cflags
152 echo "-L$MPDM -lmpdm" >> config.ldflags
153 echo "OK ($MPDM)"
154 else
155 echo "No"
156 exit 1
159 # If MPDM is not configured, do it
160 if [ ! -f $MPDM/Makefile ] ; then
161 ( echo ; cd $MPDM ; ./config.sh --prefix=$PREFIX --docdir=$PREFIX/share/doc/$APPNAME $CONF_ARGS ; echo )
164 cat $MPDM/config.ldflags >> config.ldflags
165 echo "MPDM=$MPDM" >> makefile.opts
167 # MPSL
168 echo -n "Looking for MPSL... "
170 for MPSL in ./mpsl ../mpsl NOTFOUND ; do
171 if [ -d $MPSL ] && [ -f $MPSL/mpsl.h ] ; then
172 break
174 done
176 if [ "$MPSL" != "NOTFOUND" ] ; then
177 echo "-I$MPSL" >> config.cflags
178 echo "-L$MPSL -lmpsl" >> config.ldflags
179 echo "OK ($MPSL)"
180 else
181 echo "No"
182 exit 1
185 # If MPSL is not configured, do it
186 if [ ! -f $MPSL/Makefile ] ; then
187 ( echo ; cd $MPSL ; ./config.sh --prefix=$PREFIX --docdir=$PREFIX/share/doc/$APPNAME $CONF_ARGS ; echo )
190 cat $MPSL/config.ldflags >> config.ldflags
191 echo "MPSL=$MPSL" >> makefile.opts
193 # Win32
195 echo -n "Testing for win32... "
196 if [ "$WITHOUT_WIN32" = "1" ] ; then
197 echo "Disabled"
198 else
199 grep CONFOPT_WIN32 ${MPDM}/config.h >/dev/null
201 if [ $? = 0 ] ; then
202 echo "-mwindows -lcomctl32" >> config.ldflags
203 echo "#define CONFOPT_WIN32 1" >> config.h
204 echo "OK"
205 DRIVERS="win32 $DRIVERS"
206 DRV_OBJS="mpv_win32.o $DRV_OBJS"
207 WITHOUT_UNIX_GLOB=1
208 WITHOUT_KDE4=1
209 WITHOUT_GTK=1
210 WITHOUT_CURSES=1
211 WITHOUT_QT4=1
212 APPNAME=mp-5.exe
213 else
214 echo "No"
218 # test for curses / ncurses library
219 echo -n "Testing for ncursesw... "
221 if [ "$WITHOUT_CURSES" = "1" ] ; then
222 echo "Disabled"
223 else
224 echo "#include <ncursesw/ncurses.h>" > .tmp.c
225 echo "int main(void) { initscr(); endwin(); return 0; }" >> .tmp.c
227 TMP_CFLAGS="-I/usr/local/include"
228 TMP_LDFLAGS="-L/usr/local/lib -lncursesw"
230 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
231 if [ $? = 0 ] ; then
232 echo "#define CONFOPT_CURSES 1" >> config.h
233 echo $TMP_CFLAGS >> config.cflags
234 echo $TMP_LDFLAGS >> config.ldflags
235 echo "OK (ncursesw)"
236 DRIVERS="ncursesw $DRIVERS"
237 DRV_OBJS="mpv_curses.o $DRV_OBJS"
238 else
239 echo "No"
240 WITHOUT_CURSES=1
244 if [ "$WITHOUT_CURSES" != "1" ] ; then
245 # test for transparent colors in curses
246 echo -n "Testing for transparency support in curses... "
248 echo "#include <ncursesw/ncurses.h>" > .tmp.c
249 echo "int main(void) { initscr(); use_default_colors(); endwin(); return 0; }" >> .tmp.c
251 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
252 if [ $? = 0 ] ; then
253 echo "#define CONFOPT_TRANSPARENCY 1" >> config.h
254 echo "OK"
255 else
256 echo "No"
259 # test now for wget_wch() existence
260 echo -n "Testing for wget_wch()... "
262 echo "#include <wchar.h>" > .tmp.c
263 echo "#include <ncursesw/ncurses.h>" >> .tmp.c
264 echo "int main(void) { wchar_t c[2]; initscr(); wget_wch(stdscr, c); endwin(); return 0; }" >> .tmp.c
266 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
267 if [ $? = 0 ] ; then
268 echo "#define CONFOPT_WGET_WCH 1" >> config.h
269 echo "OK"
270 else
271 echo "No"
275 # KDE4
277 echo -n "Testing for KDE4... "
278 if [ "$WITHOUT_KDE4" = "1" ] ; then
279 echo "Disabled"
280 else
281 if which kde4-config > /dev/null 2>&1
282 then
283 TMP_CFLAGS=$(pkg-config --cflags QtCore)
284 TMP_CFLAGS="$TMP_CFLAGS -I`kde4-config --install include` -I`kde4-config --install include`KDE"
286 TMP_LDFLAGS=$(pkg-config --libs QtCore)
287 TMP_LDFLAGS="$TMP_LDFLAGS -L`kde4-config --install lib` -lkfile -lkdeui -lkdecore"
289 echo "#include <KApplication>" > .tmp.cpp
290 echo "int main(void) { new KApplication() ; return 0; } " >> .tmp.cpp
292 echo "$CPP $TMP_CFLAGS .tmp.cpp $TMP_LDFLAGS -o .tmp.o" >> .config.log
293 $CPP $TMP_CFLAGS .tmp.cpp $TMP_LDFLAGS -o .tmp.o 2>> .config.log
295 if [ $? = 0 ] ; then
296 echo $TMP_CFLAGS >> config.cflags
297 echo $TMP_LDFLAGS >> config.ldflags
299 echo "#define CONFOPT_KDE4 1" >> config.h
300 echo "OK"
302 DRIVERS="kde4 $DRIVERS"
303 DRV_OBJS="mpv_kde4.o $DRV_OBJS"
304 if [ "$CCLINK" = "" ] ; then
305 CCLINK="g++"
308 WITHOUT_GTK=1
309 WITHOUT_QT4=1
310 else
311 echo "No"
313 else
314 echo "No"
318 # Qt4
320 echo -n "Testing for Qt4... "
321 if [ "$WITHOUT_QT4" = "1" ] ; then
322 echo "Disabled"
323 else
324 if which pkg-config > /dev/null 2>&1
325 then
326 TMP_CFLAGS=$(pkg-config --cflags QtGui)
327 TMP_LDFLAGS="$(pkg-config --libs QtGui) -lX11"
329 echo "#include <QtGui>" > .tmp.cpp
330 echo "int main(int argc, char *argv[]) { new QApplication(argc, argv) ; return 0; } " >> .tmp.cpp
332 echo "$CPP $TMP_CFLAGS .tmp.cpp $TMP_LDFLAGS -o .tmp.o" >> .config.log
333 $CPP $TMP_CFLAGS .tmp.cpp $TMP_LDFLAGS -o .tmp.o 2>> .config.log
335 if [ $? = 0 ] ; then
336 echo $TMP_CFLAGS >> config.cflags
337 echo $TMP_LDFLAGS >> config.ldflags
339 echo "#define CONFOPT_QT4 1" >> config.h
340 echo "OK"
342 DRIVERS="qt4 $DRIVERS"
343 DRV_OBJS="mpv_qt4.o $DRV_OBJS"
344 if [ "$CCLINK" = "" ] ; then
345 CCLINK="g++"
348 WITHOUT_GTK=1
349 else
350 echo "No"
352 else
353 echo "No"
357 # GTK
358 echo -n "Testing for GTK... "
360 if [ "$WITHOUT_GTK" = "1" ] ; then
361 echo "Disabled"
362 else
363 echo "#include <gtk/gtk.h>" > .tmp.c
364 echo "#include <gdk/gdkkeysyms.h>" >> .tmp.c
365 echo "int main(void) { gtk_main(); return 0; } " >> .tmp.c
367 # Try first GTK 3.0
368 TMP_CFLAGS=`sh -c 'pkg-config --cflags gtk+-3.0' 2>/dev/null`
369 TMP_LDFLAGS=`sh -c 'pkg-config --libs gtk+-3.0' 2>/dev/null`
371 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
372 if [ $? = 0 ] ; then
373 echo "#define CONFOPT_GTK 3" >> config.h
374 echo "$TMP_CFLAGS " >> config.cflags
375 echo "$TMP_LDFLAGS " >> config.ldflags
376 echo "OK (3.0)"
377 DRIVERS="gtk $DRIVERS"
378 DRV_OBJS="mpv_gtk.o $DRV_OBJS"
379 else
380 # Try now GTK 2.0
381 TMP_CFLAGS=`sh -c 'pkg-config --cflags gtk+-2.0' 2>/dev/null`
382 TMP_LDFLAGS=`sh -c 'pkg-config --libs gtk+-2.0' 2>/dev/null`
384 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
385 if [ $? = 0 ] ; then
386 echo "#define CONFOPT_GTK 2" >> config.h
387 echo "$TMP_CFLAGS " >> config.cflags
388 echo "$TMP_LDFLAGS " >> config.ldflags
389 echo "OK (2.0)"
390 DRIVERS="gtk $DRIVERS"
391 DRV_OBJS="mpv_gtk.o $DRV_OBJS"
392 else
393 echo "No"
398 # msgfnt
399 echo -n "Testing for msgfmt... "
401 if which msgfmt > /dev/null 2>&1 ; then
402 echo "OK"
403 echo "BUILDMO=build-mo" >> makefile.opts
404 echo "INSTALLMO=install-mo" >> makefile.opts
405 echo "UNINSTALLMO=uninstall-mo" >> makefile.opts
406 else
407 echo "No"
408 echo "BUILDMO=" >> makefile.opts
409 echo "INSTALLMO=" >> makefile.opts
410 echo "UNINSTALLMO=" >> makefile.opts
413 if [ "$CCLINK" = "" ] ; then
414 CCLINK=$CC
417 echo >> config.h
419 grep DOCS $MPDM/makefile.opts >> makefile.opts
420 echo "VERSION=$VERSION" >> makefile.opts
421 echo "WINDRES=$WINDRES" >> makefile.opts
422 echo "PREFIX=\$(DESTDIR)$PREFIX" >> makefile.opts
423 echo "APPNAME=$APPNAME" >> makefile.opts
424 echo "DRV_OBJS=$DRV_OBJS" >> makefile.opts
425 echo "CCLINK=$CCLINK" >> makefile.opts
426 echo >> makefile.opts
428 cat makefile.opts makefile.in makefile.depend > Makefile
430 ##############################################
432 if [ "$DRIVERS" = "" ] ; then
434 echo
435 echo "*ERROR* No usable drivers (interfaces) found"
436 echo "See the README file for the available options."
438 exit 1
441 echo
442 echo "Configured drivers:" $DRIVERS
443 echo
444 echo "Type 'make' to build Minimum Profit."
446 # insert driver detection code into config.h
448 TRY_DRIVERS="#define TRY_DRIVERS() ("
449 echo >> config.h
450 for drv in $DRIVERS ; do
451 echo "int ${drv}_drv_detect(int * argc, char *** argv);" >> config.h
452 TRY_DRIVERS="$TRY_DRIVERS ${drv}_drv_detect(&argc, &argv) || "
453 done
455 echo >> config.h
456 echo $TRY_DRIVERS '0)' >> config.h
458 # cleanup
459 rm -f .tmp.c .tmp.cpp .tmp.o
461 exit 0