Fixed file permissions.
[mpdm.git] / config.sh
blobbdd329d82df8b8a6f5ff753cf133f5da29eb698f
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 cflags
91 if [ "$CFLAGS" = "" -a "$CC" = "gcc" ] ; then
92 CFLAGS="-g -Wall"
95 echo "CFLAGS=$CFLAGS" >> makefile.opts
97 # Add CFLAGS to CC
98 CC="$CC $CFLAGS"
100 # set archiver
101 if [ "$AR" = "" ] ; then
102 AR=ar
105 echo "AR=$AR" >> makefile.opts
107 # add version
108 cat VERSION >> config.h
110 # add installation prefix
111 echo "#define CONFOPT_PREFIX \"$PREFIX\"" >> config.h
113 #########################################################
115 # configuration directives
117 # Win32
118 echo -n "Testing for win32... "
119 if [ "$WITHOUT_WIN32" = "1" ] ; then
120 echo "Disabled by user"
121 else
122 echo "#include <windows.h>" > .tmp.c
123 echo "#include <commctrl.h>" >> .tmp.c
124 echo "int STDCALL WinMain(HINSTANCE h, HINSTANCE p, LPSTR c, int m)" >> .tmp.c
125 echo "{ return 0; }" >> .tmp.c
127 TMP_LDFLAGS=""
128 $CC .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
130 if [ $? = 0 ] ; then
131 echo "#define CONFOPT_WIN32 1" >> config.h
132 echo "OK"
133 WITHOUT_UNIX_GLOB=1
134 WITH_WIN32=1
135 else
136 echo "No"
140 # glob.h support
141 if [ "$WITHOUT_UNIX_GLOB" != 1 ] ; then
142 echo -n "Testing for unix-like glob.h... "
143 echo "#include <stdio.h>" > .tmp.c
144 echo "#include <glob.h>" >> .tmp.c
145 echo "int main(void) { glob_t g; g.gl_offs=1; glob(\"*\",GLOB_MARK,NULL,&g); return 0; }" >> .tmp.c
147 $CC .tmp.c -o .tmp.o 2>> .config.log
149 if [ $? = 0 ] ; then
150 echo "#define CONFOPT_GLOB_H 1" >> config.h
151 echo "OK"
152 else
153 echo "No; activating workaround"
157 # regex
158 echo -n "Testing for regular expressions... "
160 if [ "$WITH_PCRE" = 1 ] ; then
161 # try first the pcre library
162 TMP_CFLAGS="-I/usr/local/include"
163 TMP_LDFLAGS="-L/usr/local/lib -lpcre -lpcreposix"
164 echo "#include <pcreposix.h>" > .tmp.c
165 echo "int main(void) { regex_t r; regmatch_t m; regcomp(&r,\".*\",REG_EXTENDED|REG_ICASE); return 0; }" >> .tmp.c
167 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
169 if [ $? = 0 ] ; then
170 echo "OK (using pcre library)"
171 echo "#define CONFOPT_PCRE 1" >> config.h
172 echo "$TMP_CFLAGS " >> config.cflags
173 echo "$TMP_LDFLAGS " >> config.ldflags
174 REGEX_YET=1
178 if [ "$REGEX_YET" != 1 -a "$WITH_INCLUDED_REGEX" != 1 ] ; then
179 echo "#include <sys/types.h>" > .tmp.c
180 echo "#include <regex.h>" >> .tmp.c
181 echo "int main(void) { regex_t r; regmatch_t m; regcomp(&r,\".*\",REG_EXTENDED|REG_ICASE); return 0; }" >> .tmp.c
183 $CC .tmp.c -o .tmp.o 2>> .config.log
185 if [ $? = 0 ] ; then
186 echo "OK (using system one)"
187 echo "#define CONFOPT_SYSTEM_REGEX 1" >> config.h
188 REGEX_YET=1
192 if [ "$REGEX_YET" != 1 ] ; then
193 # if system libraries lack regex, try compiling the
194 # included gnu_regex.c
196 $CC -c -DSTD_HEADERS -DREGEX gnu_regex.c -o .tmp.o 2>> .config.log
198 if [ $? = 0 ] ; then
199 echo "OK (using included gnu_regex.c)"
200 echo "#define HAVE_STRING_H 1" >> config.h
201 echo "#define REGEX 1" >> config.h
202 echo "#define CONFOPT_INCLUDED_REGEX 1" >> config.h
203 else
204 echo "#define CONFOPT_NO_REGEX 1" >> config.h
205 echo "No (No usable regex library)"
206 exit 1
210 # unistd.h detection
211 echo -n "Testing for unistd.h... "
212 echo "#include <unistd.h>" > .tmp.c
213 echo "int main(void) { return(0); }" >> .tmp.c
215 $CC .tmp.c -o .tmp.o 2>> .config.log
217 if [ $? = 0 ] ; then
218 echo "#define CONFOPT_UNISTD_H 1" >> config.h
219 echo "OK"
220 else
221 echo "No"
224 # sys/types.h detection
225 echo -n "Testing for sys/types.h... "
226 echo "#include <sys/types.h>" > .tmp.c
227 echo "int main(void) { return(0); }" >> .tmp.c
229 $CC .tmp.c -o .tmp.o 2>> .config.log
231 if [ $? = 0 ] ; then
232 echo "#define CONFOPT_SYS_TYPES_H 1" >> config.h
233 echo "OK"
234 else
235 echo "No"
238 # sys/wait.h detection
239 echo -n "Testing for sys/wait.h... "
240 echo "#include <sys/wait.h>" > .tmp.c
241 echo "int main(void) { return(0); }" >> .tmp.c
243 $CC .tmp.c -o .tmp.o 2>> .config.log
245 if [ $? = 0 ] ; then
246 echo "#define CONFOPT_SYS_WAIT_H 1" >> config.h
247 echo "OK"
248 else
249 echo "No"
252 # sys/stat.h detection
253 echo -n "Testing for sys/stat.h... "
254 echo "#include <sys/stat.h>" > .tmp.c
255 echo "int main(void) { return(0); }" >> .tmp.c
257 $CC .tmp.c -o .tmp.o 2>> .config.log
259 if [ $? = 0 ] ; then
260 echo "#define CONFOPT_SYS_STAT_H 1" >> config.h
261 echo "OK"
262 else
263 echo "No"
266 # pwd.h detection
267 echo -n "Testing for pwd.h... "
268 echo "#include <pwd.h>" > .tmp.c
269 echo "int main(void) { return(0); }" >> .tmp.c
271 $CC .tmp.c -o .tmp.o 2>> .config.log
273 if [ $? = 0 ] ; then
274 echo "#define CONFOPT_PWD_H 1" >> config.h
275 echo "OK"
276 else
277 echo "No"
280 # chown() detection
281 echo -n "Testing for chown()... "
282 echo "#include <sys/types.h>" > .tmp.c
283 echo "#include <unistd.h>" >> .tmp.c
284 echo "int main(void) { chown(\"file\", 0, 0); }" >> .tmp.c
286 $CC .tmp.c -o .tmp.o 2>> .config.log
288 if [ $? = 0 ] ; then
289 echo "#define CONFOPT_CHOWN 1" >> config.h
290 echo "OK"
291 else
292 echo "No"
295 # gettext support
296 echo -n "Testing for gettext... "
298 if [ "$WITHOUT_GETTEXT" = "1" ] ; then
299 echo "Disabled by user"
300 else
301 echo "#include <libintl.h>" > .tmp.c
302 echo "#include <locale.h>" >> .tmp.c
303 echo "int main(void) { setlocale(LC_ALL, \"\"); gettext(\"hi\"); return 0; }" >> .tmp.c
305 # try first to compile without -lintl
306 $CC .tmp.c -o .tmp.o 2>> .config.log
308 if [ $? = 0 ] ; then
309 echo "OK"
310 echo "#define CONFOPT_GETTEXT 1" >> config.h
311 else
312 # try now with -lintl
313 TMP_LDFLAGS="-lintl"
315 $CC .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
317 if [ $? = 0 ] ; then
318 echo "OK (libintl needed)"
319 echo "#define CONFOPT_GETTEXT 1" >> config.h
320 echo "$TMP_LDFLAGS" >> config.ldflags
321 else
322 echo "No"
328 # iconv support
329 echo -n "Testing for iconv... "
331 if [ "$WITHOUT_ICONV" = "1" ] ; then
332 echo "Disabled by user"
333 else
334 echo "#include <iconv.h>" > .tmp.c
335 echo "#include <locale.h>" >> .tmp.c
336 echo "int main(void) { setlocale(LC_ALL, \"\"); iconv_open(\"WCHAR_T\", \"ISO-8859-1\"); return 0; }" >> .tmp.c
338 # try first to compile without -liconv
339 $CC .tmp.c -o .tmp.o 2>> .config.log
341 if [ $? = 0 ] ; then
342 echo "OK"
343 echo "#define CONFOPT_ICONV 1" >> config.h
344 else
345 # try now with -liconv
346 TMP_LDFLAGS="-liconv"
348 $CC .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
350 if [ $? = 0 ] ; then
351 echo "OK (libiconv needed)"
352 echo "#define CONFOPT_ICONV 1" >> config.h
353 echo "$TMP_LDFLAGS" >> config.ldflags
354 else
355 echo "No"
360 # wcwidth() existence
361 echo -n "Testing for wcwidth()... "
363 if [ "$WITHOUT_WCWIDTH" = "1" ] ; then
364 echo "Disabled by user (using Markus Kuhn's)"
365 else
366 echo "#include <wchar.h>" > .tmp.c
367 echo "int main(void) { wcwidth(L'a'); return 0; }" >> .tmp.c
369 $CC .tmp.c -o .tmp.o 2>> .config.log
371 if [ $? = 0 ] ; then
372 echo "OK"
373 echo "#define CONFOPT_WCWIDTH 1" >> config.h
374 else
375 echo "No; using Markus Kuhn's wcwidth()"
379 # canonicalize_file_name() detection
380 echo -n "Testing for file canonicalization... "
381 echo "#include <stdlib.h>" > .tmp.c
382 echo "int main(void) { canonicalize_file_name(\"file\"); return 0; }" >> .tmp.c
384 $CC .tmp.c -o .tmp.o 2>> .config.log
386 if [ $? = 0 ] ; then
387 echo "#define CONFOPT_CANONICALIZE_FILE_NAME 1" >> config.h
388 echo "canonicalize_file_name()"
389 else
390 # try now realpath
391 echo "#include <stdlib.h>" > .tmp.c
392 echo "int main(void) { char tmp[2048]; realpath(\"file\", tmp); return 0; }" >> .tmp.c
394 $CC .tmp.c -o .tmp.o 2>> .config.log
396 if [ $? = 0 ] ; then
397 echo "#define CONFOPT_REALPATH 1" >> config.h
398 echo "realpath()"
399 else
400 # try now _fullpath
401 echo "#include <stdlib.h>" > .tmp.c
402 echo "int main(void) { char tmp[2048]; _fullpath(tmp, \"file\", _MAX_PATH); return 0; }" >> .tmp.c
404 $CC .tmp.c -o .tmp.o 2>> .config.log
406 if [ $? = 0 ] ; then
407 echo "#define CONFOPT_FULLPATH 1" >> config.h
408 echo "_fullpath()"
409 else
410 echo "No"
415 if [ "$WITH_WIN32" != 1 ] ; then
416 echo -n "Testing for nanosleep()... "
417 echo "#include <time.h>" > .tmp.c
418 echo "int main(void) { struct timespec ts; ts.tv_sec = 1; ts.tv_nsec = 0; nanosleep(&ts, NULL); return 0; }" >> .tmp.c
420 $CC .tmp.c -o .tmp.o 2>> .config.log
422 if [ $? = 0 ] ; then
423 echo "#define CONFOPT_NANOSLEEP 1" >> config.h
424 echo "OK"
425 else
426 echo "No"
430 if [ "$WITH_WIN32" != 1 ] ; then
431 echo -n "Testing for POSIX threads... "
432 echo "#include <pthread.h>" > .tmp.c
433 echo "int main(void) { pthread_t t; pthread_create(&t, NULL, NULL, NULL); return 0; }" >> .tmp.c
435 TMP_LDFLAGS="-pthread"
436 $CC .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
438 if [ $? = 0 ] ; then
439 echo "#define CONFOPT_PTHREADS 1" >> config.h
440 echo $TMP_LDFLAGS >> config.ldflags
441 WITH_PTHREADS=1
442 echo "OK"
443 else
444 echo "No"
448 if [ "$WITH_WIN32" != 1 -a "$WITH_PTHREADS" = 1 ] ; then
449 echo -n "Testing for POSIX semaphores... "
450 echo "#include <semaphore.h>" > .tmp.c
451 echo "int main(void) { sem_t s; sem_init(&s, 0, 0); return 0; }" >> .tmp.c
453 TMP_LDFLAGS="-pthread"
454 $CC .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
456 if [ $? = 0 ] ; then
457 echo "#define CONFOPT_POSIXSEMS 1" >> config.h
458 echo "OK"
459 else
460 echo "No"
464 # test for Grutatxt
465 echo -n "Testing if Grutatxt is installed... "
467 DOCS="\$(ADD_DOCS)"
469 if which grutatxt > /dev/null 2>&1 ; then
470 echo "OK"
471 echo "GRUTATXT=yes" >> makefile.opts
472 DOCS="$DOCS \$(GRUTATXT_DOCS)"
473 else
474 echo "No"
475 echo "GRUTATXT=no" >> makefile.opts
478 # test for mp_doccer
479 echo -n "Testing if mp_doccer is installed... "
480 MP_DOCCER=$(which mp_doccer||which mp-doccer)
482 if [ $? = 0 ] ; then
484 if ${MP_DOCCER} --help | grep grutatxt > /dev/null ; then
486 echo "OK"
488 echo "MP_DOCCER=yes" >> makefile.opts
489 DOCS="$DOCS \$(MP_DOCCER_DOCS)"
491 grep GRUTATXT=yes makefile.opts > /dev/null && DOCS="$DOCS \$(G_AND_MP_DOCS)"
492 else
493 echo "Outdated (No)"
494 echo "MP_DOCCER=no" >> makefile.opts
496 else
497 echo "No"
498 echo "MP_DOCCER=no" >> makefile.opts
501 if [ "$WITH_NULL_HASH" = "1" ] ; then
502 echo "Selecting NULL hash function"
504 echo "#define CONFOPT_NULL_HASH 1" >> config.h
507 #########################################################
509 # final setup
511 echo "DOCS=$DOCS" >> makefile.opts
512 echo "VERSION=$VERSION" >> makefile.opts
513 echo "PREFIX=\$(DESTDIR)$PREFIX" >> makefile.opts
514 echo "DOCDIR=\$(DESTDIR)$DOCDIR" >> makefile.opts
515 echo >> makefile.opts
517 cat makefile.opts makefile.in makefile.depend > Makefile
519 #########################################################
521 # cleanup
523 rm -f .tmp.c .tmp.o
525 exit 0