In mp.repeated_words, really add the first word to mp.word_color.
[mp-5.x.git] / config.sh
blob138c68337880c1c8e5851f9a3fab2e0725408153
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 # parse arguments
19 while [ $# -gt 0 ] ; do
21 case $1 in
22 --without-curses) WITHOUT_CURSES=1 ;;
23 --without-gtk) WITHOUT_GTK=1 ;;
24 --without-win32) WITHOUT_WIN32=1 ;;
25 --without-kde4) WITHOUT_KDE4=1 ;;
26 --help) CONFIG_HELP=1 ;;
28 --mingw32) CC=i586-mingw32msvc-cc
29 WINDRES=i586-mingw32msvc-windres
30 AR=i586-mingw32msvc-ar
31 CFLAGS="-O3 $CFLAGS"
34 --debian) BUILD_FOR_DEBIAN=1
35 PREFIX=/usr
36 APPNAME=mped
39 --prefix) PREFIX=$2 ; shift ;;
40 --prefix=*) PREFIX=`echo $1 | sed -e 's/--prefix=//'` ;;
41 esac
43 shift
44 done
46 if [ "$CONFIG_HELP" = "1" ] ; then
48 echo "Available options:"
49 echo "--prefix=PREFIX Installation prefix ($PREFIX)."
50 echo "--without-curses Disable curses (text) interface detection."
51 echo "--without-gtk Disable GTK interface detection."
52 echo "--without-win32 Disable win32 interface detection."
53 echo "--without-kde4 Disable KDE4 interface detection."
54 echo "--without-unix-glob Disable glob.h usage (use workaround)."
55 echo "--with-included-regex Use included regex code (gnu_regex.c)."
56 echo "--with-pcre Enable PCRE library detection."
57 echo "--without-gettext Disable gettext usage."
58 echo "--without-iconv Disable iconv usage."
59 echo "--without-wcwidth Disable system wcwidth() (use workaround)."
60 echo "--with-null-hash Tell MPDM to use a NULL hashing function."
61 echo "--mingw32 Build using the mingw32 compiler."
62 echo "--debian Build for Debian ('make deb')."
64 echo
65 echo "Environment variables:"
66 echo "CC C Compiler."
67 echo "AR Library Archiver."
68 echo "CFLAGS Compile flags (i.e., -O3)."
69 echo "WINDRES MS Windows resource compiler."
71 exit 1
74 echo "Configuring..."
76 echo "/* automatically created by config.sh - do not modify */" > config.h
77 echo "# automatically created by config.sh - do not modify" > makefile.opts
78 > config.ldflags
79 > config.cflags
80 > .config.log
82 # set compiler
83 if [ "$CC" = "" ] ; then
84 CC=cc
85 # if CC is unset, try if gcc is available
86 which gcc > /dev/null && CC=gcc
89 if [ "$CPP" = "" ] ; then
90 CPP=c++
91 # if CC is unset, try if gcc is available
92 which g++ > /dev/null && CPP=g++
95 MOC="moc"
96 which moc-qt4 > /dev/null && MOC=moc-qt4
98 echo "CC=$CC" >> makefile.opts
99 echo "CPP=$CPP" >> makefile.opts
100 echo "MOC=$MOC" >> makefile.opts
102 # set cflags
103 if [ "$CFLAGS" = "" -a "$CC" = "gcc" ] ; then
104 CFLAGS="-g -Wall"
107 echo "CFLAGS=$CFLAGS" >> makefile.opts
109 # Add CFLAGS to CC
110 CC="$CC $CFLAGS"
112 # add version
113 cat VERSION >> config.h
115 # add installation prefix and application name
116 echo "#define CONFOPT_PREFIX \"$PREFIX\"" >> config.h
117 echo "#define CONFOPT_APPNAME \"$APPNAME\"" >> config.h
119 ################################################################
121 # MPDM
122 echo -n "Looking for MPDM... "
124 for MPDM in ./mpdm ../mpdm NOTFOUND ; do
125 if [ -d $MPDM ] && [ -f $MPDM/mpdm.h ] ; then
126 break
128 done
130 if [ "$MPDM" != "NOTFOUND" ] ; then
131 echo "-I$MPDM" >> config.cflags
132 echo "-L$MPDM -lmpdm" >> config.ldflags
133 echo "OK ($MPDM)"
134 else
135 echo "No"
136 exit 1
139 # If MPDM is not configured, do it
140 if [ ! -f $MPDM/Makefile ] ; then
141 ( echo ; cd $MPDM ; ./config.sh --prefix=$PREFIX --docdir=$PREFIX/share/doc/$APPNAME $CONF_ARGS ; echo )
144 cat $MPDM/config.ldflags >> config.ldflags
145 echo "MPDM=$MPDM" >> makefile.opts
147 # MPSL
148 echo -n "Looking for MPSL... "
150 for MPSL in ./mpsl ../mpsl NOTFOUND ; do
151 if [ -d $MPSL ] && [ -f $MPSL/mpsl.h ] ; then
152 break
154 done
156 if [ "$MPSL" != "NOTFOUND" ] ; then
157 echo "-I$MPSL" >> config.cflags
158 echo "-L$MPSL -lmpsl" >> config.ldflags
159 echo "OK ($MPSL)"
160 else
161 echo "No"
162 exit 1
165 # If MPSL is not configured, do it
166 if [ ! -f $MPSL/Makefile ] ; then
167 ( echo ; cd $MPSL ; ./config.sh --prefix=$PREFIX --docdir=$PREFIX/share/doc/$APPNAME $CONF_ARGS ; echo )
170 cat $MPSL/config.ldflags >> config.ldflags
171 echo "MPSL=$MPSL" >> makefile.opts
173 # Win32
175 echo -n "Testing for win32... "
176 if [ "$WITHOUT_WIN32" = "1" ] ; then
177 echo "Disabled"
178 else
179 grep CONFOPT_WIN32 ${MPDM}/config.h >/dev/null
181 if [ $? = 0 ] ; then
182 echo "-mwindows -lcomctl32" >> config.ldflags
183 echo "#define CONFOPT_WIN32 1" >> config.h
184 echo "OK"
185 DRIVERS="win32 $DRIVERS"
186 DRV_OBJS="mpv_win32.o $DRV_OBJS"
187 WITHOUT_UNIX_GLOB=1
188 WITHOUT_KDE4=1
189 WITHOUT_GTK=1
190 WITHOUT_CURSES=1
191 APPNAME=wmp.exe
192 else
193 echo "No"
197 # test for curses / ncurses library
198 echo -n "Testing for ncursesw... "
200 if [ "$WITHOUT_CURSES" = "1" ] ; then
201 echo "Disabled"
202 else
203 echo "#include <curses.h>" > .tmp.c
204 echo "int main(void) { initscr(); endwin(); return 0; }" >> .tmp.c
206 TMP_CFLAGS="-I/usr/local/include"
207 TMP_LDFLAGS="-L/usr/local/lib -lncursesw"
209 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
210 if [ $? = 0 ] ; then
211 echo "#define CONFOPT_CURSES 1" >> config.h
212 echo $TMP_CFLAGS >> config.cflags
213 echo $TMP_LDFLAGS >> config.ldflags
214 echo "OK (ncursesw)"
215 DRIVERS="ncursesw $DRIVERS"
216 DRV_OBJS="mpv_curses.o $DRV_OBJS"
217 else
218 echo "No"
219 WITHOUT_CURSES=1
223 if [ "$WITHOUT_CURSES" != "1" ] ; then
224 # test for transparent colors in curses
225 echo -n "Testing for transparency support in curses... "
227 echo "#include <curses.h>" > .tmp.c
228 echo "int main(void) { initscr(); use_default_colors(); endwin(); return 0; }" >> .tmp.c
230 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
231 if [ $? = 0 ] ; then
232 echo "#define CONFOPT_TRANSPARENCY 1" >> config.h
233 echo "OK"
234 else
235 echo "No"
238 # test now for wget_wch() existence
239 echo -n "Testing for wget_wch()... "
241 echo "#include <wchar.h>" > .tmp.c
242 echo "#include <curses.h>" >> .tmp.c
243 echo "int main(void) { wchar_t c[2]; initscr(); wget_wch(stdscr, c); endwin(); return 0; }" >> .tmp.c
245 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
246 if [ $? = 0 ] ; then
247 echo "#define CONFOPT_WGET_WCH 1" >> config.h
248 echo "OK"
249 else
250 echo "No"
254 # KDE4
256 echo -n "Testing for KDE4... "
257 if [ "$WITHOUT_KDE4" = "1" ] ; then
258 echo "Disabled"
259 else
260 if which kde4-config > /dev/null
261 then
262 TMP_CFLAGS=$(pkg-config --cflags QtCore)
263 TMP_CFLAGS="$TMP_CFLAGS -I`kde4-config --install include`KDE"
265 TMP_LDFLAGS=$(pkg-config --libs QtCore)
266 TMP_LDFLAGS="$TMP_LDFLAGS -L`kde4-config --install lib` -lkfile -lkdeui -lkdecore"
268 echo "#include <KApplication>" > .tmp.cpp
269 echo "int main(void) { new KApplication() ; return 0; } " >> .tmp.cpp
271 echo "$CPP $TMP_CFLAGS .tmp.cpp $TMP_LDFLAGS -o .tmp.o" >> .config.log
272 $CPP $TMP_CFLAGS .tmp.cpp $TMP_LDFLAGS -o .tmp.o 2>> .config.log
274 if [ $? = 0 ] ; then
275 echo $TMP_CFLAGS >> config.cflags
276 echo $TMP_LDFLAGS >> config.ldflags
278 echo "#define CONFOPT_KDE4 1" >> config.h
279 echo "OK"
281 DRIVERS="kde4 $DRIVERS"
282 DRV_OBJS="mpv_kde4.o $DRV_OBJS"
283 if [ "$CCLINK" = "" ] ; then
284 CCLINK="g++"
287 WITHOUT_GTK=1
288 else
289 echo "No"
291 else
292 echo "No"
296 # GTK
297 echo -n "Testing for GTK... "
299 if [ "$WITHOUT_GTK" = "1" ] ; then
300 echo "Disabled"
301 else
302 echo "#include <gtk/gtk.h>" > .tmp.c
303 echo "#include <gdk/gdkkeysyms.h>" >> .tmp.c
304 echo "int main(void) { gtk_main(); return 0; } " >> .tmp.c
306 # Try first GTK 2.0
307 TMP_CFLAGS=`sh -c 'pkg-config --cflags gtk+-2.0' 2>/dev/null`
308 TMP_LDFLAGS=`sh -c 'pkg-config --libs gtk+-2.0' 2>/dev/null`
310 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
311 if [ $? = 0 ] ; then
312 echo "#define CONFOPT_GTK 2" >> config.h
313 echo "$TMP_CFLAGS " >> config.cflags
314 echo "$TMP_LDFLAGS " >> config.ldflags
315 echo "OK (2.0)"
316 DRIVERS="gtk $DRIVERS"
317 DRV_OBJS="mpv_gtk.o $DRV_OBJS"
318 else
319 echo "No"
323 if [ "$CCLINK" = "" ] ; then
324 CCLINK=$CC
327 echo >> config.h
329 grep DOCS $MPDM/makefile.opts >> makefile.opts
330 echo "VERSION=$VERSION" >> makefile.opts
331 echo "WINDRES=$WINDRES" >> makefile.opts
332 echo "PREFIX=\$(DESTDIR)$PREFIX" >> makefile.opts
333 echo "APPNAME=$APPNAME" >> makefile.opts
334 echo "DRV_OBJS=$DRV_OBJS" >> makefile.opts
335 echo "CCLINK=$CCLINK" >> makefile.opts
336 echo >> makefile.opts
338 cat makefile.opts makefile.in makefile.depend > Makefile
340 ##############################################
342 if [ "$DRIVERS" = "" ] ; then
344 echo
345 echo "*ERROR* No usable drivers (interfaces) found"
346 echo "See the README file for the available options."
348 exit 1
351 echo
352 echo "Configured drivers:" $DRIVERS
353 echo
354 echo "Type 'make' to build Minimum Profit."
356 # insert driver detection code into config.h
358 TRY_DRIVERS="#define TRY_DRIVERS() ("
359 echo >> config.h
360 for drv in $DRIVERS ; do
361 echo "int ${drv}_drv_detect(int * argc, char *** argv);" >> config.h
362 TRY_DRIVERS="$TRY_DRIVERS ${drv}_drv_detect(&argc, &argv) || "
363 done
365 echo >> config.h
366 echo $TRY_DRIVERS '0)' >> config.h
368 # cleanup
369 rm -f .tmp.c .tmp.cpp .tmp.o
371 exit 0