Updated RELEASE_NOTES.
[mpdm.git] / config.sh
blob271bcb8af19daad8315f4d3e8f2f0564b805408a
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
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 else
135 echo "No"
139 # glob.h support
140 if [ "$WITHOUT_UNIX_GLOB" != 1 ] ; then
141 echo -n "Testing for unix-like glob.h... "
142 echo "#include <stdio.h>" > .tmp.c
143 echo "#include <glob.h>" >> .tmp.c
144 echo "int main(void) { glob_t g; g.gl_offs=1; glob(\"*\",GLOB_MARK,NULL,&g); return 0; }" >> .tmp.c
146 $CC .tmp.c -o .tmp.o 2>> .config.log
148 if [ $? = 0 ] ; then
149 echo "#define CONFOPT_GLOB_H 1" >> config.h
150 echo "OK"
151 else
152 echo "No; activating workaround"
156 # regex
157 echo -n "Testing for regular expressions... "
159 if [ "$WITH_PCRE" = 1 ] ; then
160 # try first the pcre library
161 TMP_CFLAGS="-I/usr/local/include"
162 TMP_LDFLAGS="-L/usr/local/lib -lpcre -lpcreposix"
163 echo "#include <pcreposix.h>" > .tmp.c
164 echo "int main(void) { regex_t r; regmatch_t m; regcomp(&r,\".*\",REG_EXTENDED|REG_ICASE); return 0; }" >> .tmp.c
166 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
168 if [ $? = 0 ] ; then
169 echo "OK (using pcre library)"
170 echo "#define CONFOPT_PCRE 1" >> config.h
171 echo "$TMP_CFLAGS " >> config.cflags
172 echo "$TMP_LDFLAGS " >> config.ldflags
173 REGEX_YET=1
177 if [ "$REGEX_YET" != 1 -a "$WITH_INCLUDED_REGEX" != 1 ] ; then
178 echo "#include <sys/types.h>" > .tmp.c
179 echo "#include <regex.h>" >> .tmp.c
180 echo "int main(void) { regex_t r; regmatch_t m; regcomp(&r,\".*\",REG_EXTENDED|REG_ICASE); return 0; }" >> .tmp.c
182 $CC .tmp.c -o .tmp.o 2>> .config.log
184 if [ $? = 0 ] ; then
185 echo "OK (using system one)"
186 echo "#define CONFOPT_SYSTEM_REGEX 1" >> config.h
187 REGEX_YET=1
191 if [ "$REGEX_YET" != 1 ] ; then
192 # if system libraries lack regex, try compiling the
193 # included gnu_regex.c
195 $CC -c -DSTD_HEADERS -DREGEX gnu_regex.c -o .tmp.o 2>> .config.log
197 if [ $? = 0 ] ; then
198 echo "OK (using included gnu_regex.c)"
199 echo "#define HAVE_STRING_H 1" >> config.h
200 echo "#define REGEX 1" >> config.h
201 echo "#define CONFOPT_INCLUDED_REGEX 1" >> config.h
202 else
203 echo "#define CONFOPT_NO_REGEX 1" >> config.h
204 echo "No (No usable regex library)"
205 exit 1
209 # unistd.h detection
210 echo -n "Testing for unistd.h... "
211 echo "#include <unistd.h>" > .tmp.c
212 echo "int main(void) { return(0); }" >> .tmp.c
214 $CC .tmp.c -o .tmp.o 2>> .config.log
216 if [ $? = 0 ] ; then
217 echo "#define CONFOPT_UNISTD_H 1" >> config.h
218 echo "OK"
219 else
220 echo "No"
223 # sys/types.h detection
224 echo -n "Testing for sys/types.h... "
225 echo "#include <sys/types.h>" > .tmp.c
226 echo "int main(void) { return(0); }" >> .tmp.c
228 $CC .tmp.c -o .tmp.o 2>> .config.log
230 if [ $? = 0 ] ; then
231 echo "#define CONFOPT_SYS_TYPES_H 1" >> config.h
232 echo "OK"
233 else
234 echo "No"
237 # sys/wait.h detection
238 echo -n "Testing for sys/wait.h... "
239 echo "#include <sys/wait.h>" > .tmp.c
240 echo "int main(void) { return(0); }" >> .tmp.c
242 $CC .tmp.c -o .tmp.o 2>> .config.log
244 if [ $? = 0 ] ; then
245 echo "#define CONFOPT_SYS_WAIT_H 1" >> config.h
246 echo "OK"
247 else
248 echo "No"
251 # sys/stat.h detection
252 echo -n "Testing for sys/stat.h... "
253 echo "#include <sys/stat.h>" > .tmp.c
254 echo "int main(void) { return(0); }" >> .tmp.c
256 $CC .tmp.c -o .tmp.o 2>> .config.log
258 if [ $? = 0 ] ; then
259 echo "#define CONFOPT_SYS_STAT_H 1" >> config.h
260 echo "OK"
261 else
262 echo "No"
265 # pwd.h detection
266 echo -n "Testing for pwd.h... "
267 echo "#include <pwd.h>" > .tmp.c
268 echo "int main(void) { return(0); }" >> .tmp.c
270 $CC .tmp.c -o .tmp.o 2>> .config.log
272 if [ $? = 0 ] ; then
273 echo "#define CONFOPT_PWD_H 1" >> config.h
274 echo "OK"
275 else
276 echo "No"
279 # chown() detection
280 echo -n "Testing for chown()... "
281 echo "#include <sys/types.h>" > .tmp.c
282 echo "#include <unistd.h>" >> .tmp.c
283 echo "int main(void) { chown(\"file\", 0, 0); }" >> .tmp.c
285 $CC .tmp.c -o .tmp.o 2>> .config.log
287 if [ $? = 0 ] ; then
288 echo "#define CONFOPT_CHOWN 1" >> config.h
289 echo "OK"
290 else
291 echo "No"
294 # gettext support
295 echo -n "Testing for gettext... "
297 if [ "$WITHOUT_GETTEXT" = "1" ] ; then
298 echo "Disabled by user"
299 else
300 echo "#include <libintl.h>" > .tmp.c
301 echo "#include <locale.h>" >> .tmp.c
302 echo "int main(void) { setlocale(LC_ALL, \"\"); gettext(\"hi\"); return 0; }" >> .tmp.c
304 # try first to compile without -lintl
305 $CC .tmp.c -o .tmp.o 2>> .config.log
307 if [ $? = 0 ] ; then
308 echo "OK"
309 echo "#define CONFOPT_GETTEXT 1" >> config.h
310 else
311 # try now with -lintl
312 TMP_LDFLAGS="-lintl"
314 $CC .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
316 if [ $? = 0 ] ; then
317 echo "OK (libintl needed)"
318 echo "#define CONFOPT_GETTEXT 1" >> config.h
319 echo "$TMP_LDFLAGS" >> config.ldflags
320 else
321 echo "No"
327 # iconv support
328 echo -n "Testing for iconv... "
330 if [ "$WITHOUT_ICONV" = "1" ] ; then
331 echo "Disabled by user"
332 else
333 echo "#include <iconv.h>" > .tmp.c
334 echo "#include <locale.h>" >> .tmp.c
335 echo "int main(void) { setlocale(LC_ALL, \"\"); iconv_open(\"WCHAR_T\", \"ISO-8859-1\"); return 0; }" >> .tmp.c
337 # try first to compile without -liconv
338 $CC .tmp.c -o .tmp.o 2>> .config.log
340 if [ $? = 0 ] ; then
341 echo "OK"
342 echo "#define CONFOPT_ICONV 1" >> config.h
343 else
344 # try now with -liconv
345 TMP_LDFLAGS="-liconv"
347 $CC .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
349 if [ $? = 0 ] ; then
350 echo "OK (libiconv needed)"
351 echo "#define CONFOPT_ICONV 1" >> config.h
352 echo "$TMP_LDFLAGS" >> config.ldflags
353 else
354 echo "No"
359 # wcwidth() existence
360 echo -n "Testing for wcwidth()... "
362 if [ "$WITHOUT_WCWIDTH" = "1" ] ; then
363 echo "Disabled by user (using Markus Kuhn's)"
364 else
365 echo "#include <wchar.h>" > .tmp.c
366 echo "int main(void) { wcwidth(L'a'); return 0; }" >> .tmp.c
368 $CC .tmp.c -o .tmp.o 2>> .config.log
370 if [ $? = 0 ] ; then
371 echo "OK"
372 echo "#define CONFOPT_WCWIDTH 1" >> config.h
373 else
374 echo "No; using Markus Kuhn's wcwidth()"
378 # canonicalize_file_name() detection
379 echo -n "Testing for file canonicalization... "
380 echo "#include <stdlib.h>" > .tmp.c
381 echo "int main(void) { canonicalize_file_name(\"file\"); return 0; }" >> .tmp.c
383 $CC .tmp.c -o .tmp.o 2>> .config.log
385 if [ $? = 0 ] ; then
386 echo "#define CONFOPT_CANONICALIZE_FILE_NAME 1" >> config.h
387 echo "canonicalize_file_name()"
388 else
389 # try now realpath
390 echo "#include <stdlib.h>" > .tmp.c
391 echo "int main(void) { char tmp[2048]; realpath(\"file\", tmp); return 0; }" >> .tmp.c
393 $CC .tmp.c -o .tmp.o 2>> .config.log
395 if [ $? = 0 ] ; then
396 echo "#define CONFOPT_REALPATH 1" >> config.h
397 echo "realpath()"
398 else
399 echo No
403 # test for Grutatxt
404 echo -n "Testing if Grutatxt is installed... "
406 DOCS="\$(ADD_DOCS)"
408 if which grutatxt > /dev/null ; then
409 echo "OK"
410 echo "GRUTATXT=yes" >> makefile.opts
411 DOCS="$DOCS \$(GRUTATXT_DOCS)"
412 else
413 echo "No"
414 echo "GRUTATXT=no" >> makefile.opts
417 # test for mp_doccer
418 echo -n "Testing if mp_doccer is installed... "
419 MP_DOCCER=$(which mp_doccer || which mp-doccer)
421 if [ $? = 0 ] ; then
423 if ${MP_DOCCER} --help | grep grutatxt > /dev/null ; then
425 echo "OK"
427 echo "MP_DOCCER=yes" >> makefile.opts
428 DOCS="$DOCS \$(MP_DOCCER_DOCS)"
430 grep GRUTATXT=yes makefile.opts > /dev/null && DOCS="$DOCS \$(G_AND_MP_DOCS)"
431 else
432 echo "Outdated (No)"
433 echo "MP_DOCCER=no" >> makefile.opts
435 else
436 echo "No"
437 echo "MP_DOCCER=no" >> makefile.opts
440 if [ "$WITH_NULL_HASH" = "1" ] ; then
441 echo "Selecting NULL hash function"
443 echo "#define CONFOPT_NULL_HASH 1" >> config.h
446 #########################################################
448 # final setup
450 echo "DOCS=$DOCS" >> makefile.opts
451 echo "VERSION=$VERSION" >> makefile.opts
452 echo "PREFIX=\$(DESTDIR)$PREFIX" >> makefile.opts
453 echo "DOCDIR=\$(DESTDIR)$DOCDIR" >> makefile.opts
454 echo >> makefile.opts
456 cat makefile.opts makefile.in makefile.depend > Makefile
458 #########################################################
460 # cleanup
462 rm -f .tmp.c .tmp.o
464 exit 0