Updated TODO.
[mpdm.git] / config.sh
blob3e89b417a95ec65cb4bd54885e61da42186fccb8
1 #!/bin/sh
3 # Configuration shell script
5 # gets program version
6 VERSION=`cut -f2 -d\" VERSION`
8 # default installation prefix
9 PREFIX=/usr/local
11 # installation directory for documents
12 DOCDIR=""
14 # parse arguments
15 while [ $# -gt 0 ] ; do
17 case $1 in
18 --without-win32) WITHOUT_WIN32=1 ;;
19 --without-unix-glob) WITHOUT_UNIX_GLOB=1 ;;
20 --with-included-regex) WITH_INCLUDED_REGEX=1 ;;
21 --with-pcre) WITH_PCRE=1 ;;
22 --without-gettext) WITHOUT_GETTEXT=1 ;;
23 --without-iconv) WITHOUT_ICONV=1 ;;
24 --without-wcwidth) WITHOUT_WCWIDTH=1 ;;
25 --help) CONFIG_HELP=1 ;;
27 --mingw32) CC=i586-mingw32msvc-cc
28 WINDRES=i586-mingw32msvc-windres
29 AR=i586-mingw32msvc-ar
32 --prefix) PREFIX=$2 ; shift ;;
33 --prefix=*) PREFIX=`echo $1 | sed -e 's/--prefix=//'` ;;
35 --docdir) DOCDIR=$2 ; shift ;;
36 --docdir=*) DOCDIR=`echo $1 | sed -e 's/--docdir=//'` ;;
38 esac
40 shift
41 done
43 if [ "$CONFIG_HELP" = "1" ] ; then
45 echo "Available options:"
46 echo "--prefix=PREFIX Installation prefix ($PREFIX)."
47 echo "--docdir=DOCDIR Instalation directory for documentation."
48 echo "--without-win32 Disable win32 interface detection."
49 echo "--without-unix-glob Disable glob.h usage (use workaround)."
50 echo "--with-included-regex Use included regex code (gnu_regex.c)."
51 echo "--with-pcre Enable PCRE library detection."
52 echo "--without-gettext Disable gettext usage."
53 echo "--without-iconv Disable iconv usage."
54 echo "--without-wcwidth Disable system wcwidth() (use Marcus Kuhn's)."
55 echo "--mingw32 Build using the mingw32 compiler."
57 echo
58 echo "Environment variables:"
59 echo "CC C Compiler."
60 echo "AR Library Archiver."
62 exit 1
65 if [ "$DOCDIR" = "" ] ; then
66 DOCDIR=$PREFIX/share/doc/mpdm
69 echo "Configuring MPDM..."
71 echo "/* automatically created by config.sh - do not modify */" > config.h
72 echo "# automatically created by config.sh - do not modify" > makefile.opts
73 > config.ldflags
74 > config.cflags
75 > .config.log
77 # set compiler
78 if [ "$CC" = "" ] ; then
79 CC=cc
80 # if CC is unset, try if gcc is available
81 which gcc > /dev/null 2>&1
83 if [ $? = 0 ] ; then
84 CC=gcc
88 echo "CC=$CC" >> makefile.opts
90 # set archiver
91 if [ "$AR" = "" ] ; then
92 AR=ar
95 echo "AR=$AR" >> makefile.opts
97 # add version
98 cat VERSION >> config.h
100 # add installation prefix
101 echo "#define CONFOPT_PREFIX \"$PREFIX\"" >> config.h
103 #########################################################
105 # configuration directives
107 # CFLAGS
108 if [ -z "$CFLAGS" ] ; then
109 CFLAGS="-g -Wall"
112 echo -n "Testing if C compiler supports ${CFLAGS}... "
113 echo "int main(int argc, char *argv[]) { return 0; }" > .tmp.c
115 $CC .tmp.c -o .tmp.o 2>> .config.log
117 if [ $? = 0 ] ; then
118 echo "OK"
119 else
120 echo "No; resetting to defaults"
121 CFLAGS=""
124 echo "CFLAGS=$CFLAGS" >> makefile.opts
126 # Add CFLAGS to CC
127 CC="$CC $CFLAGS"
129 # Win32
130 echo -n "Testing for win32... "
131 if [ "$WITHOUT_WIN32" = "1" ] ; then
132 echo "Disabled by user"
133 else
134 echo "#include <windows.h>" > .tmp.c
135 echo "#include <commctrl.h>" >> .tmp.c
136 echo "int STDCALL WinMain(HINSTANCE h, HINSTANCE p, LPSTR c, int m)" >> .tmp.c
137 echo "{ return 0; }" >> .tmp.c
139 TMP_LDFLAGS=""
140 $CC .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
142 if [ $? = 0 ] ; then
143 echo "#define CONFOPT_WIN32 1" >> config.h
144 echo "OK"
145 WITHOUT_UNIX_GLOB=1
146 WITH_WIN32=1
147 else
148 echo "No"
152 # glob.h support
153 if [ "$WITHOUT_UNIX_GLOB" != 1 ] ; then
154 echo -n "Testing for unix-like glob.h... "
155 echo "#include <stdio.h>" > .tmp.c
156 echo "#include <glob.h>" >> .tmp.c
157 echo "int main(void) { glob_t g; g.gl_offs=1; glob(\"*\",GLOB_MARK,NULL,&g); return 0; }" >> .tmp.c
159 $CC .tmp.c -o .tmp.o 2>> .config.log
161 if [ $? = 0 ] ; then
162 echo "#define CONFOPT_GLOB_H 1" >> config.h
163 echo "OK"
164 else
165 echo "No; activating workaround"
169 # regex
170 echo -n "Testing for regular expressions... "
172 if [ "$WITH_PCRE" = 1 ] ; then
173 # try first the pcre library
174 TMP_CFLAGS="-I/usr/local/include"
175 TMP_LDFLAGS="-L/usr/local/lib -lpcre -lpcreposix"
176 echo "#include <pcreposix.h>" > .tmp.c
177 echo "int main(void) { regex_t r; regmatch_t m; regcomp(&r,\".*\",REG_EXTENDED|REG_ICASE); return 0; }" >> .tmp.c
179 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
181 if [ $? = 0 ] ; then
182 echo "OK (using pcre library)"
183 echo "#define CONFOPT_PCRE 1" >> config.h
184 echo "$TMP_CFLAGS " >> config.cflags
185 echo "$TMP_LDFLAGS " >> config.ldflags
186 REGEX_YET=1
190 if [ "$REGEX_YET" != 1 -a "$WITH_INCLUDED_REGEX" != 1 ] ; then
191 echo "#include <sys/types.h>" > .tmp.c
192 echo "#include <regex.h>" >> .tmp.c
193 echo "int main(void) { regex_t r; regmatch_t m; regcomp(&r,\".*\",REG_EXTENDED|REG_ICASE); return 0; }" >> .tmp.c
195 $CC .tmp.c -o .tmp.o 2>> .config.log
197 if [ $? = 0 ] ; then
198 echo "OK (using system one)"
199 echo "#define CONFOPT_SYSTEM_REGEX 1" >> config.h
200 REGEX_YET=1
204 if [ "$REGEX_YET" != 1 ] ; then
205 # if system libraries lack regex, try compiling the
206 # included gnu_regex.c
208 $CC -c -DSTD_HEADERS -DREGEX gnu_regex.c -o .tmp.o 2>> .config.log
210 if [ $? = 0 ] ; then
211 echo "OK (using included gnu_regex.c)"
212 echo "#define HAVE_STRING_H 1" >> config.h
213 echo "#define REGEX 1" >> config.h
214 echo "#define CONFOPT_INCLUDED_REGEX 1" >> config.h
215 else
216 echo "#define CONFOPT_NO_REGEX 1" >> config.h
217 echo "No (No usable regex library)"
218 exit 1
222 # unistd.h detection
223 echo -n "Testing for unistd.h... "
224 echo "#include <unistd.h>" > .tmp.c
225 echo "int main(void) { return(0); }" >> .tmp.c
227 $CC .tmp.c -o .tmp.o 2>> .config.log
229 if [ $? = 0 ] ; then
230 echo "#define CONFOPT_UNISTD_H 1" >> config.h
231 echo "OK"
232 else
233 echo "No"
236 # sys/types.h detection
237 echo -n "Testing for sys/types.h... "
238 echo "#include <sys/types.h>" > .tmp.c
239 echo "int main(void) { return(0); }" >> .tmp.c
241 $CC .tmp.c -o .tmp.o 2>> .config.log
243 if [ $? = 0 ] ; then
244 echo "#define CONFOPT_SYS_TYPES_H 1" >> config.h
245 echo "OK"
246 else
247 echo "No"
250 # sys/wait.h detection
251 echo -n "Testing for sys/wait.h... "
252 echo "#include <sys/wait.h>" > .tmp.c
253 echo "int main(void) { return(0); }" >> .tmp.c
255 $CC .tmp.c -o .tmp.o 2>> .config.log
257 if [ $? = 0 ] ; then
258 echo "#define CONFOPT_SYS_WAIT_H 1" >> config.h
259 echo "OK"
260 else
261 echo "No"
264 # sys/stat.h detection
265 echo -n "Testing for sys/stat.h... "
266 echo "#include <sys/stat.h>" > .tmp.c
267 echo "int main(void) { return(0); }" >> .tmp.c
269 $CC .tmp.c -o .tmp.o 2>> .config.log
271 if [ $? = 0 ] ; then
272 echo "#define CONFOPT_SYS_STAT_H 1" >> config.h
273 echo "OK"
274 else
275 echo "No"
278 # pwd.h detection
279 echo -n "Testing for pwd.h... "
280 echo "#include <pwd.h>" > .tmp.c
281 echo "int main(void) { return(0); }" >> .tmp.c
283 $CC .tmp.c -o .tmp.o 2>> .config.log
285 if [ $? = 0 ] ; then
286 echo "#define CONFOPT_PWD_H 1" >> config.h
287 echo "OK"
288 else
289 echo "No"
292 # chown() detection
293 echo -n "Testing for chown()... "
294 echo "#include <sys/types.h>" > .tmp.c
295 echo "#include <unistd.h>" >> .tmp.c
296 echo "int main(void) { chown(\"file\", 0, 0); }" >> .tmp.c
298 $CC .tmp.c -o .tmp.o 2>> .config.log
300 if [ $? = 0 ] ; then
301 echo "#define CONFOPT_CHOWN 1" >> config.h
302 echo "OK"
303 else
304 echo "No"
307 # gettext support
308 echo -n "Testing for gettext... "
310 if [ "$WITHOUT_GETTEXT" = "1" ] ; then
311 echo "Disabled by user"
312 else
313 echo "#include <libintl.h>" > .tmp.c
314 echo "#include <locale.h>" >> .tmp.c
315 echo "int main(void) { setlocale(LC_ALL, \"\"); gettext(\"hi\"); return 0; }" >> .tmp.c
317 # try first to compile without -lintl
318 $CC .tmp.c -o .tmp.o 2>> .config.log
320 if [ $? = 0 ] ; then
321 echo "OK"
322 echo "#define CONFOPT_GETTEXT 1" >> config.h
323 else
324 # try now with -lintl
325 TMP_LDFLAGS="-lintl"
327 $CC .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
329 if [ $? = 0 ] ; then
330 echo "OK (libintl needed)"
331 echo "#define CONFOPT_GETTEXT 1" >> config.h
332 echo "$TMP_LDFLAGS" >> config.ldflags
333 else
334 echo "No"
340 # iconv support
341 echo -n "Testing for iconv... "
343 if [ "$WITHOUT_ICONV" = "1" ] ; then
344 echo "Disabled by user"
345 else
346 echo "#include <iconv.h>" > .tmp.c
347 echo "#include <locale.h>" >> .tmp.c
348 echo "int main(void) { setlocale(LC_ALL, \"\"); iconv_open(\"WCHAR_T\", \"ISO-8859-1\"); return 0; }" >> .tmp.c
350 # try first to compile without -liconv
351 $CC .tmp.c -o .tmp.o 2>> .config.log
353 if [ $? = 0 ] ; then
354 echo "OK"
355 echo "#define CONFOPT_ICONV 1" >> config.h
356 else
357 # try now with -liconv
358 TMP_LDFLAGS="-liconv"
360 $CC .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
362 if [ $? = 0 ] ; then
363 echo "OK (libiconv needed)"
364 echo "#define CONFOPT_ICONV 1" >> config.h
365 echo "$TMP_LDFLAGS" >> config.ldflags
366 else
367 echo "No"
372 # wcwidth() existence
373 echo -n "Testing for wcwidth()... "
375 if [ "$WITHOUT_WCWIDTH" = "1" ] ; then
376 echo "Disabled by user (using Markus Kuhn's)"
377 else
378 echo "#include <wchar.h>" > .tmp.c
379 echo "int main(void) { wcwidth(L'a'); return 0; }" >> .tmp.c
381 $CC .tmp.c -o .tmp.o 2>> .config.log
383 if [ $? = 0 ] ; then
384 echo "OK"
385 echo "#define CONFOPT_WCWIDTH 1" >> config.h
386 else
387 echo "No; using Markus Kuhn's wcwidth()"
391 # canonicalize_file_name() detection
392 echo -n "Testing for file canonicalization... "
393 echo "#include <stdlib.h>" > .tmp.c
394 echo "int main(void) { canonicalize_file_name(\"file\"); return 0; }" >> .tmp.c
396 $CC .tmp.c -o .tmp.o 2>> .config.log
398 if [ $? = 0 ] ; then
399 echo "#define CONFOPT_CANONICALIZE_FILE_NAME 1" >> config.h
400 echo "canonicalize_file_name()"
401 else
402 # try now realpath
403 echo "#include <stdlib.h>" > .tmp.c
404 echo "int main(void) { char tmp[2048]; realpath(\"file\", tmp); return 0; }" >> .tmp.c
406 $CC .tmp.c -o .tmp.o 2>> .config.log
408 if [ $? = 0 ] ; then
409 echo "#define CONFOPT_REALPATH 1" >> config.h
410 echo "realpath()"
411 else
412 # try now _fullpath
413 echo "#include <stdlib.h>" > .tmp.c
414 echo "int main(void) { char tmp[2048]; _fullpath(tmp, \"file\", _MAX_PATH); return 0; }" >> .tmp.c
416 $CC .tmp.c -o .tmp.o 2>> .config.log
418 if [ $? = 0 ] ; then
419 echo "#define CONFOPT_FULLPATH 1" >> config.h
420 echo "_fullpath()"
421 else
422 echo "No"
427 if [ "$WITH_WIN32" != 1 ] ; then
428 echo -n "Testing for nanosleep()... "
429 echo "#include <time.h>" > .tmp.c
430 echo "int main(void) { struct timespec ts; ts.tv_sec = 1; ts.tv_nsec = 0; nanosleep(&ts, NULL); return 0; }" >> .tmp.c
432 $CC .tmp.c -o .tmp.o 2>> .config.log
434 if [ $? = 0 ] ; then
435 echo "#define CONFOPT_NANOSLEEP 1" >> config.h
436 echo "OK"
437 else
438 echo "No"
442 if [ "$WITH_WIN32" != 1 ] ; then
443 echo -n "Testing for POSIX threads... "
444 echo "#include <pthread.h>" > .tmp.c
445 echo "void *f(void *p) { return p; } int main(void) { pthread_t t; pthread_create(&t, NULL, f, NULL); return 0; }" >> .tmp.c
447 TMP_LDFLAGS="-pthread"
448 $CC .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
450 if [ $? = 0 ] ; then
451 echo "#define CONFOPT_PTHREADS 1" >> config.h
452 echo $TMP_LDFLAGS >> config.ldflags
453 WITH_PTHREADS=1
454 echo "OK"
455 else
456 echo "No"
460 if [ "$WITH_WIN32" != 1 -a "$WITH_PTHREADS" = 1 ] ; then
461 echo -n "Testing for POSIX semaphores... "
462 echo "#include <semaphore.h>" > .tmp.c
463 echo "int main(void) { sem_t s; sem_init(&s, 0, 0); return 0; }" >> .tmp.c
465 TMP_LDFLAGS="-pthread"
466 $CC .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
468 if [ $? = 0 ] ; then
469 echo "#define CONFOPT_POSIXSEMS 1" >> config.h
470 echo "OK"
471 else
472 echo "No"
476 # test for Grutatxt
477 echo -n "Testing if Grutatxt is installed... "
479 DOCS="\$(ADD_DOCS)"
481 if which grutatxt > /dev/null 2>&1 ; then
482 echo "OK"
483 echo "GRUTATXT=yes" >> makefile.opts
484 DOCS="$DOCS \$(GRUTATXT_DOCS)"
485 else
486 echo "No"
487 echo "GRUTATXT=no" >> makefile.opts
490 # test for mp_doccer
491 echo -n "Testing if mp_doccer is installed... "
492 MP_DOCCER=$(which mp_doccer||which mp-doccer)
494 if [ $? = 0 ] ; then
496 if ${MP_DOCCER} --help | grep grutatxt > /dev/null ; then
498 echo "OK"
500 echo "MP_DOCCER=yes" >> makefile.opts
501 DOCS="$DOCS \$(MP_DOCCER_DOCS)"
503 grep GRUTATXT=yes makefile.opts > /dev/null && DOCS="$DOCS \$(G_AND_MP_DOCS)"
504 else
505 echo "Outdated (No)"
506 echo "MP_DOCCER=no" >> makefile.opts
508 else
509 echo "No"
510 echo "MP_DOCCER=no" >> makefile.opts
513 if [ "$WITH_NULL_HASH" = "1" ] ; then
514 echo "Selecting NULL hash function"
516 echo "#define CONFOPT_NULL_HASH 1" >> config.h
519 #########################################################
521 # final setup
523 echo "DOCS=$DOCS" >> makefile.opts
524 echo "VERSION=$VERSION" >> makefile.opts
525 echo "PREFIX=\$(DESTDIR)$PREFIX" >> makefile.opts
526 echo "DOCDIR=\$(DESTDIR)$DOCDIR" >> makefile.opts
527 echo >> makefile.opts
529 cat makefile.opts makefile.in makefile.depend > Makefile
531 #########################################################
533 # cleanup
535 rm -f .tmp.c .tmp.o
537 exit 0