The 'save_as' action accepts additional arguments.
[mp-5.x.git] / config.sh
blobfa80f0e60980ebe2148865821e51e47ced0bfa93
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 # set cflags
111 if [ "$CFLAGS" = "" -a "$CC" = "gcc" ] ; then
112 CFLAGS="-g -Wall"
115 echo "CFLAGS=$CFLAGS" >> makefile.opts
117 # Add CFLAGS to CC
118 CC="$CC $CFLAGS"
120 # add version
121 cat VERSION >> config.h
123 # add installation prefix and application name
124 echo "#define CONFOPT_PREFIX \"$PREFIX\"" >> config.h
125 echo "#define CONFOPT_APPNAME \"$APPNAME\"" >> config.h
127 ################################################################
129 # MPDM
130 echo -n "Looking for MPDM... "
132 for MPDM in ./mpdm ../mpdm NOTFOUND ; do
133 if [ -d $MPDM ] && [ -f $MPDM/mpdm.h ] ; then
134 break
136 done
138 if [ "$MPDM" != "NOTFOUND" ] ; then
139 echo "-I$MPDM" >> config.cflags
140 echo "-L$MPDM -lmpdm" >> config.ldflags
141 echo "OK ($MPDM)"
142 else
143 echo "No"
144 exit 1
147 # If MPDM is not configured, do it
148 if [ ! -f $MPDM/Makefile ] ; then
149 ( echo ; cd $MPDM ; ./config.sh --prefix=$PREFIX --docdir=$PREFIX/share/doc/$APPNAME $CONF_ARGS ; echo )
152 cat $MPDM/config.ldflags >> config.ldflags
153 echo "MPDM=$MPDM" >> makefile.opts
155 # MPSL
156 echo -n "Looking for MPSL... "
158 for MPSL in ./mpsl ../mpsl NOTFOUND ; do
159 if [ -d $MPSL ] && [ -f $MPSL/mpsl.h ] ; then
160 break
162 done
164 if [ "$MPSL" != "NOTFOUND" ] ; then
165 echo "-I$MPSL" >> config.cflags
166 echo "-L$MPSL -lmpsl" >> config.ldflags
167 echo "OK ($MPSL)"
168 else
169 echo "No"
170 exit 1
173 # If MPSL is not configured, do it
174 if [ ! -f $MPSL/Makefile ] ; then
175 ( echo ; cd $MPSL ; ./config.sh --prefix=$PREFIX --docdir=$PREFIX/share/doc/$APPNAME $CONF_ARGS ; echo )
178 cat $MPSL/config.ldflags >> config.ldflags
179 echo "MPSL=$MPSL" >> makefile.opts
181 # Win32
183 echo -n "Testing for win32... "
184 if [ "$WITHOUT_WIN32" = "1" ] ; then
185 echo "Disabled"
186 else
187 grep CONFOPT_WIN32 ${MPDM}/config.h >/dev/null
189 if [ $? = 0 ] ; then
190 echo "-mwindows -lcomctl32" >> config.ldflags
191 echo "#define CONFOPT_WIN32 1" >> config.h
192 echo "OK"
193 DRIVERS="win32 $DRIVERS"
194 DRV_OBJS="mpv_win32.o $DRV_OBJS"
195 WITHOUT_UNIX_GLOB=1
196 WITHOUT_KDE4=1
197 WITHOUT_GTK=1
198 WITHOUT_CURSES=1
199 WITHOUT_QT4=1
200 APPNAME=mp-5.exe
201 else
202 echo "No"
206 # test for curses / ncurses library
207 echo -n "Testing for ncursesw... "
209 if [ "$WITHOUT_CURSES" = "1" ] ; then
210 echo "Disabled"
211 else
212 echo "#include <ncursesw/ncurses.h>" > .tmp.c
213 echo "int main(void) { initscr(); endwin(); return 0; }" >> .tmp.c
215 TMP_CFLAGS="-I/usr/local/include"
216 TMP_LDFLAGS="-L/usr/local/lib -lncursesw"
218 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
219 if [ $? = 0 ] ; then
220 echo "#define CONFOPT_CURSES 1" >> config.h
221 echo $TMP_CFLAGS >> config.cflags
222 echo $TMP_LDFLAGS >> config.ldflags
223 echo "OK (ncursesw)"
224 DRIVERS="ncursesw $DRIVERS"
225 DRV_OBJS="mpv_curses.o $DRV_OBJS"
226 else
227 echo "No"
228 WITHOUT_CURSES=1
232 if [ "$WITHOUT_CURSES" != "1" ] ; then
233 # test for transparent colors in curses
234 echo -n "Testing for transparency support in curses... "
236 echo "#include <ncursesw/ncurses.h>" > .tmp.c
237 echo "int main(void) { initscr(); use_default_colors(); endwin(); return 0; }" >> .tmp.c
239 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
240 if [ $? = 0 ] ; then
241 echo "#define CONFOPT_TRANSPARENCY 1" >> config.h
242 echo "OK"
243 else
244 echo "No"
247 # test now for wget_wch() existence
248 echo -n "Testing for wget_wch()... "
250 echo "#include <wchar.h>" > .tmp.c
251 echo "#include <ncursesw/ncurses.h>" >> .tmp.c
252 echo "int main(void) { wchar_t c[2]; initscr(); wget_wch(stdscr, c); endwin(); return 0; }" >> .tmp.c
254 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
255 if [ $? = 0 ] ; then
256 echo "#define CONFOPT_WGET_WCH 1" >> config.h
257 echo "OK"
258 else
259 echo "No"
263 # KDE4
265 echo -n "Testing for KDE4... "
266 if [ "$WITHOUT_KDE4" = "1" ] ; then
267 echo "Disabled"
268 else
269 if which kde4-config > /dev/null 2>&1
270 then
271 TMP_CFLAGS=$(pkg-config --cflags QtCore)
272 TMP_CFLAGS="$TMP_CFLAGS -I`kde4-config --install include` -I`kde4-config --install include`KDE"
274 TMP_LDFLAGS=$(pkg-config --libs QtCore)
275 TMP_LDFLAGS="$TMP_LDFLAGS -L`kde4-config --install lib` -lkfile -lkdeui -lkdecore"
277 echo "#include <KApplication>" > .tmp.cpp
278 echo "int main(void) { new KApplication() ; return 0; } " >> .tmp.cpp
280 echo "$CPP $TMP_CFLAGS .tmp.cpp $TMP_LDFLAGS -o .tmp.o" >> .config.log
281 $CPP $TMP_CFLAGS .tmp.cpp $TMP_LDFLAGS -o .tmp.o 2>> .config.log
283 if [ $? = 0 ] ; then
284 echo $TMP_CFLAGS >> config.cflags
285 echo $TMP_LDFLAGS >> config.ldflags
287 echo "#define CONFOPT_KDE4 1" >> config.h
288 echo "OK"
290 DRIVERS="kde4 $DRIVERS"
291 DRV_OBJS="mpv_kde4.o $DRV_OBJS"
292 if [ "$CCLINK" = "" ] ; then
293 CCLINK="g++"
296 WITHOUT_GTK=1
297 WITHOUT_QT4=1
298 else
299 echo "No"
301 else
302 echo "No"
306 # Qt4
308 echo -n "Testing for Qt4... "
309 if [ "$WITHOUT_QT4" = "1" ] ; then
310 echo "Disabled"
311 else
312 if which pkg-config > /dev/null 2>&1
313 then
314 TMP_CFLAGS=$(pkg-config --cflags QtGui)
315 TMP_LDFLAGS="$(pkg-config --libs QtGui) -lX11"
317 echo "#include <QtGui>" > .tmp.cpp
318 echo "int main(int argc, char *argv[]) { new QApplication(argc, argv) ; return 0; } " >> .tmp.cpp
320 echo "$CPP $TMP_CFLAGS .tmp.cpp $TMP_LDFLAGS -o .tmp.o" >> .config.log
321 $CPP $TMP_CFLAGS .tmp.cpp $TMP_LDFLAGS -o .tmp.o 2>> .config.log
323 if [ $? = 0 ] ; then
324 echo $TMP_CFLAGS >> config.cflags
325 echo $TMP_LDFLAGS >> config.ldflags
327 echo "#define CONFOPT_QT4 1" >> config.h
328 echo "OK"
330 DRIVERS="qt4 $DRIVERS"
331 DRV_OBJS="mpv_qt4.o $DRV_OBJS"
332 if [ "$CCLINK" = "" ] ; then
333 CCLINK="g++"
336 WITHOUT_GTK=1
337 else
338 echo "No"
340 else
341 echo "No"
345 # GTK
346 echo -n "Testing for GTK... "
348 if [ "$WITHOUT_GTK" = "1" ] ; then
349 echo "Disabled"
350 else
351 echo "#include <gtk/gtk.h>" > .tmp.c
352 echo "#include <gdk/gdkkeysyms.h>" >> .tmp.c
353 echo "int main(void) { gtk_main(); return 0; } " >> .tmp.c
355 # Try first GTK 2.0
356 TMP_CFLAGS=`sh -c 'pkg-config --cflags gtk+-2.0' 2>/dev/null`
357 TMP_LDFLAGS=`sh -c 'pkg-config --libs gtk+-2.0' 2>/dev/null`
359 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
360 if [ $? = 0 ] ; then
361 echo "#define CONFOPT_GTK 2" >> config.h
362 echo "$TMP_CFLAGS " >> config.cflags
363 echo "$TMP_LDFLAGS " >> config.ldflags
364 echo "OK (2.0)"
365 DRIVERS="gtk $DRIVERS"
366 DRV_OBJS="mpv_gtk.o $DRV_OBJS"
367 else
368 echo "No"
372 # msgfnt
373 echo -n "Testing for msgfmt... "
375 if which msgfmt > /dev/null 2>&1 ; then
376 echo "OK"
377 echo "BUILDMO=build-mo" >> makefile.opts
378 echo "INSTALLMO=install-mo" >> makefile.opts
379 echo "UNINSTALLMO=uninstall-mo" >> makefile.opts
380 else
381 echo "No"
382 echo "BUILDMO=" >> makefile.opts
383 echo "INSTALLMO=" >> makefile.opts
384 echo "UNINSTALLMO=" >> makefile.opts
387 if [ "$CCLINK" = "" ] ; then
388 CCLINK=$CC
391 echo >> config.h
393 grep DOCS $MPDM/makefile.opts >> makefile.opts
394 echo "VERSION=$VERSION" >> makefile.opts
395 echo "WINDRES=$WINDRES" >> makefile.opts
396 echo "PREFIX=\$(DESTDIR)$PREFIX" >> makefile.opts
397 echo "APPNAME=$APPNAME" >> makefile.opts
398 echo "DRV_OBJS=$DRV_OBJS" >> makefile.opts
399 echo "CCLINK=$CCLINK" >> makefile.opts
400 echo >> makefile.opts
402 cat makefile.opts makefile.in makefile.depend > Makefile
404 ##############################################
406 if [ "$DRIVERS" = "" ] ; then
408 echo
409 echo "*ERROR* No usable drivers (interfaces) found"
410 echo "See the README file for the available options."
412 exit 1
415 echo
416 echo "Configured drivers:" $DRIVERS
417 echo
418 echo "Type 'make' to build Minimum Profit."
420 # insert driver detection code into config.h
422 TRY_DRIVERS="#define TRY_DRIVERS() ("
423 echo >> config.h
424 for drv in $DRIVERS ; do
425 echo "int ${drv}_drv_detect(int * argc, char *** argv);" >> config.h
426 TRY_DRIVERS="$TRY_DRIVERS ${drv}_drv_detect(&argc, &argv) || "
427 done
429 echo >> config.h
430 echo $TRY_DRIVERS '0)' >> config.h
432 # cleanup
433 rm -f .tmp.c .tmp.cpp .tmp.o
435 exit 0