Suppressed error in window initialisation.
[mp-5.x.git] / config.sh
blobb5e901f26b3732ce437ec45b53cf95c94bd9562c
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 # parse arguments
22 while [ $# -gt 0 ] ; do
24 case $1 in
25 --without-curses) WITHOUT_CURSES=1 ;;
26 --without-gtk) WITHOUT_GTK=1 ;;
27 --without-win32) WITHOUT_WIN32=1 ;;
28 --without-kde4) WITHOUT_KDE4=1 ;;
29 --without-qt4) WITHOUT_QT4=1 ;;
30 --help) CONFIG_HELP=1 ;;
32 --mingw32) CC=i586-mingw32msvc-cc
33 WINDRES=i586-mingw32msvc-windres
34 AR=i586-mingw32msvc-ar
35 CFLAGS="-O3 $CFLAGS"
38 --debian) BUILD_FOR_DEBIAN=1
39 PREFIX=/usr
40 APPNAME=mped
43 --prefix) PREFIX=$2 ; shift ;;
44 --prefix=*) PREFIX=`echo $1 | sed -e 's/--prefix=//'` ;;
45 esac
47 shift
48 done
50 if [ "$CONFIG_HELP" = "1" ] ; then
52 echo "Available options:"
53 echo "--prefix=PREFIX Installation prefix ($PREFIX)."
54 echo "--without-curses Disable curses (text) interface detection."
55 echo "--without-gtk Disable GTK interface detection."
56 echo "--without-win32 Disable win32 interface detection."
57 echo "--without-kde4 Disable KDE4 interface detection."
58 echo "--without-qt4 Disable Qt4 interface detection."
59 echo "--without-unix-glob Disable glob.h usage (use workaround)."
60 echo "--with-included-regex Use included regex code (gnu_regex.c)."
61 echo "--with-pcre Enable PCRE library detection."
62 echo "--without-gettext Disable gettext usage."
63 echo "--without-iconv Disable iconv usage."
64 echo "--without-wcwidth Disable system wcwidth() (use workaround)."
65 echo "--with-null-hash Tell MPDM to use a NULL hashing function."
66 echo "--mingw32 Build using the mingw32 compiler."
67 echo "--debian Build for Debian ('make deb')."
69 echo
70 echo "Environment variables:"
71 echo "CC C Compiler."
72 echo "AR Library Archiver."
73 echo "CFLAGS Compile flags (i.e., -O3)."
74 echo "WINDRES MS Windows resource compiler."
76 exit 1
79 echo "Configuring..."
81 echo "/* automatically created by config.sh - do not modify */" > config.h
82 echo "# automatically created by config.sh - do not modify" > makefile.opts
83 > config.ldflags
84 > config.cflags
85 > .config.log
87 # set compiler
88 if [ "$CC" = "" ] ; then
89 CC=cc
90 # if CC is unset, try if gcc is available
91 which gcc > /dev/null && CC=gcc
94 if [ "$CPP" = "" ] ; then
95 CPP=c++
96 # if CC is unset, try if gcc is available
97 which g++ > /dev/null && CPP=g++
100 MOC="moc"
101 which moc-qt4 > /dev/null && MOC=moc-qt4
103 echo "CC=$CC" >> makefile.opts
104 echo "CPP=$CPP" >> makefile.opts
105 echo "MOC=$MOC" >> makefile.opts
107 # set cflags
108 if [ "$CFLAGS" = "" -a "$CC" = "gcc" ] ; then
109 CFLAGS="-g -Wall"
112 echo "CFLAGS=$CFLAGS" >> makefile.opts
114 # Add CFLAGS to CC
115 CC="$CC $CFLAGS"
117 # add version
118 cat VERSION >> config.h
120 # add installation prefix and application name
121 echo "#define CONFOPT_PREFIX \"$PREFIX\"" >> config.h
122 echo "#define CONFOPT_APPNAME \"$APPNAME\"" >> config.h
124 ################################################################
126 # MPDM
127 echo -n "Looking for MPDM... "
129 for MPDM in ./mpdm ../mpdm NOTFOUND ; do
130 if [ -d $MPDM ] && [ -f $MPDM/mpdm.h ] ; then
131 break
133 done
135 if [ "$MPDM" != "NOTFOUND" ] ; then
136 echo "-I$MPDM" >> config.cflags
137 echo "-L$MPDM -lmpdm" >> config.ldflags
138 echo "OK ($MPDM)"
139 else
140 echo "No"
141 exit 1
144 # If MPDM is not configured, do it
145 if [ ! -f $MPDM/Makefile ] ; then
146 ( echo ; cd $MPDM ; ./config.sh --prefix=$PREFIX --docdir=$PREFIX/share/doc/$APPNAME $CONF_ARGS ; echo )
149 cat $MPDM/config.ldflags >> config.ldflags
150 echo "MPDM=$MPDM" >> makefile.opts
152 # MPSL
153 echo -n "Looking for MPSL... "
155 for MPSL in ./mpsl ../mpsl NOTFOUND ; do
156 if [ -d $MPSL ] && [ -f $MPSL/mpsl.h ] ; then
157 break
159 done
161 if [ "$MPSL" != "NOTFOUND" ] ; then
162 echo "-I$MPSL" >> config.cflags
163 echo "-L$MPSL -lmpsl" >> config.ldflags
164 echo "OK ($MPSL)"
165 else
166 echo "No"
167 exit 1
170 # If MPSL is not configured, do it
171 if [ ! -f $MPSL/Makefile ] ; then
172 ( echo ; cd $MPSL ; ./config.sh --prefix=$PREFIX --docdir=$PREFIX/share/doc/$APPNAME $CONF_ARGS ; echo )
175 cat $MPSL/config.ldflags >> config.ldflags
176 echo "MPSL=$MPSL" >> makefile.opts
178 # Win32
180 echo -n "Testing for win32... "
181 if [ "$WITHOUT_WIN32" = "1" ] ; then
182 echo "Disabled"
183 else
184 grep CONFOPT_WIN32 ${MPDM}/config.h >/dev/null
186 if [ $? = 0 ] ; then
187 echo "-mwindows -lcomctl32" >> config.ldflags
188 echo "#define CONFOPT_WIN32 1" >> config.h
189 echo "OK"
190 DRIVERS="win32 $DRIVERS"
191 DRV_OBJS="mpv_win32.o $DRV_OBJS"
192 WITHOUT_UNIX_GLOB=1
193 WITHOUT_KDE4=1
194 WITHOUT_GTK=1
195 WITHOUT_CURSES=1
196 APPNAME=mp-5.exe
197 else
198 echo "No"
202 # test for curses / ncurses library
203 echo -n "Testing for ncursesw... "
205 if [ "$WITHOUT_CURSES" = "1" ] ; then
206 echo "Disabled"
207 else
208 echo "#include <ncursesw/ncurses.h>" > .tmp.c
209 echo "int main(void) { initscr(); endwin(); return 0; }" >> .tmp.c
211 TMP_CFLAGS="-I/usr/local/include"
212 TMP_LDFLAGS="-L/usr/local/lib -lncursesw"
214 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
215 if [ $? = 0 ] ; then
216 echo "#define CONFOPT_CURSES 1" >> config.h
217 echo $TMP_CFLAGS >> config.cflags
218 echo $TMP_LDFLAGS >> config.ldflags
219 echo "OK (ncursesw)"
220 DRIVERS="ncursesw $DRIVERS"
221 DRV_OBJS="mpv_curses.o $DRV_OBJS"
222 else
223 echo "No"
224 WITHOUT_CURSES=1
228 if [ "$WITHOUT_CURSES" != "1" ] ; then
229 # test for transparent colors in curses
230 echo -n "Testing for transparency support in curses... "
232 echo "#include <ncursesw/ncurses.h>" > .tmp.c
233 echo "int main(void) { initscr(); use_default_colors(); endwin(); return 0; }" >> .tmp.c
235 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
236 if [ $? = 0 ] ; then
237 echo "#define CONFOPT_TRANSPARENCY 1" >> config.h
238 echo "OK"
239 else
240 echo "No"
243 # test now for wget_wch() existence
244 echo -n "Testing for wget_wch()... "
246 echo "#include <wchar.h>" > .tmp.c
247 echo "#include <ncursesw/ncurses.h>" >> .tmp.c
248 echo "int main(void) { wchar_t c[2]; initscr(); wget_wch(stdscr, c); endwin(); return 0; }" >> .tmp.c
250 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
251 if [ $? = 0 ] ; then
252 echo "#define CONFOPT_WGET_WCH 1" >> config.h
253 echo "OK"
254 else
255 echo "No"
259 # KDE4
261 echo -n "Testing for KDE4... "
262 if [ "$WITHOUT_KDE4" = "1" ] ; then
263 echo "Disabled"
264 else
265 if which kde4-config > /dev/null
266 then
267 TMP_CFLAGS=$(pkg-config --cflags QtCore)
268 TMP_CFLAGS="$TMP_CFLAGS -I`kde4-config --install include` -I`kde4-config --install include`KDE"
270 TMP_LDFLAGS=$(pkg-config --libs QtCore)
271 TMP_LDFLAGS="$TMP_LDFLAGS -L`kde4-config --install lib` -lkfile -lkdeui -lkdecore"
273 echo "#include <KApplication>" > .tmp.cpp
274 echo "int main(void) { new KApplication() ; return 0; } " >> .tmp.cpp
276 echo "$CPP $TMP_CFLAGS .tmp.cpp $TMP_LDFLAGS -o .tmp.o" >> .config.log
277 $CPP $TMP_CFLAGS .tmp.cpp $TMP_LDFLAGS -o .tmp.o 2>> .config.log
279 if [ $? = 0 ] ; then
280 echo $TMP_CFLAGS >> config.cflags
281 echo $TMP_LDFLAGS >> config.ldflags
283 echo "#define CONFOPT_KDE4 1" >> config.h
284 echo "OK"
286 DRIVERS="kde4 $DRIVERS"
287 DRV_OBJS="mpv_kde4.o $DRV_OBJS"
288 if [ "$CCLINK" = "" ] ; then
289 CCLINK="g++"
292 WITHOUT_GTK=1
293 else
294 echo "No"
296 else
297 echo "No"
301 # Qt4
303 echo -n "Testing for Qt4... "
304 if [ "$WITHOUT_QT4" = "1" ] ; then
305 echo "Disabled"
306 else
307 if which pkg-config > /dev/null
308 then
309 TMP_CFLAGS=$(pkg-config --cflags QtGui)
310 TMP_LDFLAGS=$(pkg-config --libs QtGui)
312 echo "#include <QtGui>" > .tmp.cpp
313 echo "int main(int argc, char *argv[]) { new QApplication(argc, argv) ; return 0; } " >> .tmp.cpp
315 echo "$CPP $TMP_CFLAGS .tmp.cpp $TMP_LDFLAGS -o .tmp.o" >> .config.log
316 $CPP $TMP_CFLAGS .tmp.cpp $TMP_LDFLAGS -o .tmp.o 2>> .config.log
318 if [ $? = 0 ] ; then
319 echo $TMP_CFLAGS >> config.cflags
320 echo $TMP_LDFLAGS >> config.ldflags
322 echo "#define CONFOPT_KDE4 1" >> config.h
323 echo "OK"
325 DRIVERS="qt4 $DRIVERS"
326 DRV_OBJS="mpv_qt4.o $DRV_OBJS"
327 if [ "$CCLINK" = "" ] ; then
328 CCLINK="g++"
331 WITHOUT_GTK=1
332 else
333 echo "No"
335 else
336 echo "No"
340 # GTK
341 echo -n "Testing for GTK... "
343 if [ "$WITHOUT_GTK" = "1" ] ; then
344 echo "Disabled"
345 else
346 echo "#include <gtk/gtk.h>" > .tmp.c
347 echo "#include <gdk/gdkkeysyms.h>" >> .tmp.c
348 echo "int main(void) { gtk_main(); return 0; } " >> .tmp.c
350 # Try first GTK 2.0
351 TMP_CFLAGS=`sh -c 'pkg-config --cflags gtk+-2.0' 2>/dev/null`
352 TMP_LDFLAGS=`sh -c 'pkg-config --libs gtk+-2.0' 2>/dev/null`
354 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
355 if [ $? = 0 ] ; then
356 echo "#define CONFOPT_GTK 2" >> config.h
357 echo "$TMP_CFLAGS " >> config.cflags
358 echo "$TMP_LDFLAGS " >> config.ldflags
359 echo "OK (2.0)"
360 DRIVERS="gtk $DRIVERS"
361 DRV_OBJS="mpv_gtk.o $DRV_OBJS"
362 else
363 echo "No"
367 if [ "$CCLINK" = "" ] ; then
368 CCLINK=$CC
371 echo >> config.h
373 grep DOCS $MPDM/makefile.opts >> makefile.opts
374 echo "VERSION=$VERSION" >> makefile.opts
375 echo "WINDRES=$WINDRES" >> makefile.opts
376 echo "PREFIX=\$(DESTDIR)$PREFIX" >> makefile.opts
377 echo "APPNAME=$APPNAME" >> makefile.opts
378 echo "DRV_OBJS=$DRV_OBJS" >> makefile.opts
379 echo "CCLINK=$CCLINK" >> makefile.opts
380 echo >> makefile.opts
382 cat makefile.opts makefile.in makefile.depend > Makefile
384 ##############################################
386 if [ "$DRIVERS" = "" ] ; then
388 echo
389 echo "*ERROR* No usable drivers (interfaces) found"
390 echo "See the README file for the available options."
392 exit 1
395 echo
396 echo "Configured drivers:" $DRIVERS
397 echo
398 echo "Type 'make' to build Minimum Profit."
400 # insert driver detection code into config.h
402 TRY_DRIVERS="#define TRY_DRIVERS() ("
403 echo >> config.h
404 for drv in $DRIVERS ; do
405 echo "int ${drv}_drv_detect(int * argc, char *** argv);" >> config.h
406 TRY_DRIVERS="$TRY_DRIVERS ${drv}_drv_detect(&argc, &argv) || "
407 done
409 echo >> config.h
410 echo $TRY_DRIVERS '0)' >> config.h
412 # cleanup
413 rm -f .tmp.c .tmp.cpp .tmp.o
415 exit 0