Coding style changes.
[mpdm.git] / config.sh
blob7e25cdf31fc5a2fd864ddb8fdcbb3de8554e8b65
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 --prefix) PREFIX=$2 ; shift ;;
28 --prefix=*) PREFIX=`echo $1 | sed -e 's/--prefix=//'` ;;
30 --docdir) DOCDIR=$2 ; shift ;;
31 --docdir=*) DOCDIR=`echo $1 | sed -e 's/--docdir=//'` ;;
33 esac
35 shift
36 done
38 if [ "$CONFIG_HELP" = "1" ] ; then
40 echo "Available options:"
41 echo "--prefix=PREFIX Installation prefix ($PREFIX)."
42 echo "--docdir=DOCDIR Instalation directory for documentation."
43 echo "--without-win32 Disable win32 interface detection."
44 echo "--without-unix-glob Disable glob.h usage (use workaround)."
45 echo "--with-included-regex Use included regex code (gnu_regex.c)."
46 echo "--with-pcre Enable PCRE library detection."
47 echo "--without-gettext Disable gettext usage."
48 echo "--without-iconv Disable iconv usage."
49 echo "--without-wcwidth Disable system wcwidth() (use Marcus Kuhn's)."
51 echo
52 echo "Environment variables:"
53 echo "CC C Compiler."
54 echo "AR Library Archiver."
56 exit 1
59 if [ "$DOCDIR" = "" ] ; then
60 DOCDIR=$PREFIX/share/doc/mpdm
63 echo "Configuring MPDM..."
65 echo "/* automatically created by config.sh - do not modify */" > config.h
66 echo "# automatically created by config.sh - do not modify" > makefile.opts
67 > config.ldflags
68 > config.cflags
69 > .config.log
71 # set compiler
72 if [ "$CC" = "" ] ; then
73 CC=cc
74 # if CC is unset, try if gcc is available
75 which gcc > /dev/null
77 if [ $? = 0 ] ; then
78 CC=gcc
82 echo "CC=$CC" >> makefile.opts
84 # set cflags
85 if [ "$CFLAGS" = "" -a "$CC" = "gcc" ] ; then
86 CFLAGS="-g -Wall"
89 echo "CFLAGS=$CFLAGS" >> makefile.opts
91 # Add CFLAGS to CC
92 CC="$CC $CFLAGS"
94 # set archiver
95 if [ "$AR" = "" ] ; then
96 AR=ar
99 echo "AR=$AR" >> makefile.opts
101 # add version
102 cat VERSION >> config.h
104 # add installation prefix
105 echo "#define CONFOPT_PREFIX \"$PREFIX\"" >> config.h
107 #########################################################
109 # configuration directives
111 # Win32
112 echo -n "Testing for win32... "
113 if [ "$WITHOUT_WIN32" = "1" ] ; then
114 echo "Disabled by user"
115 else
116 echo "#include <windows.h>" > .tmp.c
117 echo "#include <commctrl.h>" >> .tmp.c
118 echo "int STDCALL WinMain(HINSTANCE h, HINSTANCE p, LPSTR c, int m)" >> .tmp.c
119 echo "{ return 0; }" >> .tmp.c
121 TMP_LDFLAGS="-mwindows -lcomctl32"
122 $CC .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
124 if [ $? = 0 ] ; then
125 echo "#define CONFOPT_WIN32 1" >> config.h
126 echo "$TMP_LDFLAGS " >> config.ldflags
127 echo "OK"
128 WITHOUT_UNIX_GLOB=1
129 else
130 echo "No"
134 # glob.h support
135 if [ "$WITHOUT_UNIX_GLOB" != 1 ] ; then
136 echo -n "Testing for unix-like glob.h... "
137 echo "#include <stdio.h>" > .tmp.c
138 echo "#include <glob.h>" >> .tmp.c
139 echo "int main(void) { glob_t g; g.gl_offs=1; glob(\"*\",GLOB_MARK,NULL,&g); return 0; }" >> .tmp.c
141 $CC .tmp.c -o .tmp.o 2>> .config.log
143 if [ $? = 0 ] ; then
144 echo "#define CONFOPT_GLOB_H 1" >> config.h
145 echo "OK"
146 else
147 echo "No; activating workaround"
151 # regex
152 echo -n "Testing for regular expressions... "
154 if [ "$WITH_PCRE" = 1 ] ; then
155 # try first the pcre library
156 TMP_CFLAGS="-I/usr/local/include"
157 TMP_LDFLAGS="-L/usr/local/lib -lpcre -lpcreposix"
158 echo "#include <pcreposix.h>" > .tmp.c
159 echo "int main(void) { regex_t r; regmatch_t m; regcomp(&r,\".*\",REG_EXTENDED|REG_ICASE); return 0; }" >> .tmp.c
161 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
163 if [ $? = 0 ] ; then
164 echo "OK (using pcre library)"
165 echo "#define CONFOPT_PCRE 1" >> config.h
166 echo "$TMP_CFLAGS " >> config.cflags
167 echo "$TMP_LDFLAGS " >> config.ldflags
168 REGEX_YET=1
172 if [ "$REGEX_YET" != 1 -a "$WITH_INCLUDED_REGEX" != 1 ] ; then
173 echo "#include <sys/types.h>" > .tmp.c
174 echo "#include <regex.h>" >> .tmp.c
175 echo "int main(void) { regex_t r; regmatch_t m; regcomp(&r,\".*\",REG_EXTENDED|REG_ICASE); return 0; }" >> .tmp.c
177 $CC .tmp.c -o .tmp.o 2>> .config.log
179 if [ $? = 0 ] ; then
180 echo "OK (using system one)"
181 echo "#define CONFOPT_SYSTEM_REGEX 1" >> config.h
182 REGEX_YET=1
186 if [ "$REGEX_YET" != 1 ] ; then
187 # if system libraries lack regex, try compiling the
188 # included gnu_regex.c
190 $CC -c -DSTD_HEADERS -DREGEX gnu_regex.c -o .tmp.o 2>> .config.log
192 if [ $? = 0 ] ; then
193 echo "OK (using included gnu_regex.c)"
194 echo "#define HAVE_STRING_H 1" >> config.h
195 echo "#define REGEX 1" >> config.h
196 echo "#define CONFOPT_INCLUDED_REGEX 1" >> config.h
197 else
198 echo "#define CONFOPT_NO_REGEX 1" >> config.h
199 echo "No (No usable regex library)"
200 exit 1
204 # unistd.h detection
205 echo -n "Testing for unistd.h... "
206 echo "#include <unistd.h>" > .tmp.c
207 echo "int main(void) { return(0); }" >> .tmp.c
209 $CC .tmp.c -o .tmp.o 2>> .config.log
211 if [ $? = 0 ] ; then
212 echo "#define CONFOPT_UNISTD_H 1" >> config.h
213 echo "OK"
214 else
215 echo "No"
218 # sys/types.h detection
219 echo -n "Testing for sys/types.h... "
220 echo "#include <sys/types.h>" > .tmp.c
221 echo "int main(void) { return(0); }" >> .tmp.c
223 $CC .tmp.c -o .tmp.o 2>> .config.log
225 if [ $? = 0 ] ; then
226 echo "#define CONFOPT_SYS_TYPES_H 1" >> config.h
227 echo "OK"
228 else
229 echo "No"
232 # sys/wait.h detection
233 echo -n "Testing for sys/wait.h... "
234 echo "#include <sys/wait.h>" > .tmp.c
235 echo "int main(void) { return(0); }" >> .tmp.c
237 $CC .tmp.c -o .tmp.o 2>> .config.log
239 if [ $? = 0 ] ; then
240 echo "#define CONFOPT_SYS_WAIT_H 1" >> config.h
241 echo "OK"
242 else
243 echo "No"
246 # sys/stat.h detection
247 echo -n "Testing for sys/stat.h... "
248 echo "#include <sys/stat.h>" > .tmp.c
249 echo "int main(void) { return(0); }" >> .tmp.c
251 $CC .tmp.c -o .tmp.o 2>> .config.log
253 if [ $? = 0 ] ; then
254 echo "#define CONFOPT_SYS_STAT_H 1" >> config.h
255 echo "OK"
256 else
257 echo "No"
260 # pwd.h detection
261 echo -n "Testing for pwd.h... "
262 echo "#include <pwd.h>" > .tmp.c
263 echo "int main(void) { return(0); }" >> .tmp.c
265 $CC .tmp.c -o .tmp.o 2>> .config.log
267 if [ $? = 0 ] ; then
268 echo "#define CONFOPT_PWD_H 1" >> config.h
269 echo "OK"
270 else
271 echo "No"
274 # chown() detection
275 echo -n "Testing for chown()... "
276 echo "#include <sys/types.h>" > .tmp.c
277 echo "#include <unistd.h>" >> .tmp.c
278 echo "int main(void) { chown(\"file\", 0, 0); }" >> .tmp.c
280 $CC .tmp.c -o .tmp.o 2>> .config.log
282 if [ $? = 0 ] ; then
283 echo "#define CONFOPT_CHOWN 1" >> config.h
284 echo "OK"
285 else
286 echo "No"
289 # gettext support
290 echo -n "Testing for gettext... "
292 if [ "$WITHOUT_GETTEXT" = "1" ] ; then
293 echo "Disabled by user"
294 else
295 echo "#include <libintl.h>" > .tmp.c
296 echo "#include <locale.h>" >> .tmp.c
297 echo "int main(void) { setlocale(LC_ALL, \"\"); gettext(\"hi\"); return 0; }" >> .tmp.c
299 # try first to compile without -lintl
300 $CC .tmp.c -o .tmp.o 2>> .config.log
302 if [ $? = 0 ] ; then
303 echo "OK"
304 echo "#define CONFOPT_GETTEXT 1" >> config.h
305 else
306 # try now with -lintl
307 TMP_LDFLAGS="-lintl"
309 $CC .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
311 if [ $? = 0 ] ; then
312 echo "OK (libintl needed)"
313 echo "#define CONFOPT_GETTEXT 1" >> config.h
314 echo "$TMP_LDFLAGS" >> config.ldflags
315 else
316 echo "No"
322 # iconv support
323 echo -n "Testing for iconv... "
325 if [ "$WITHOUT_ICONV" = "1" ] ; then
326 echo "Disabled by user"
327 else
328 echo "#include <iconv.h>" > .tmp.c
329 echo "#include <locale.h>" >> .tmp.c
330 echo "int main(void) { setlocale(LC_ALL, \"\"); iconv_open(\"WCHAR_T\", \"ISO-8859-1\"); return 0; }" >> .tmp.c
332 # try first to compile without -liconv
333 $CC .tmp.c -o .tmp.o 2>> .config.log
335 if [ $? = 0 ] ; then
336 echo "OK"
337 echo "#define CONFOPT_ICONV 1" >> config.h
338 else
339 # try now with -liconv
340 TMP_LDFLAGS="-liconv"
342 $CC .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
344 if [ $? = 0 ] ; then
345 echo "OK (libiconv needed)"
346 echo "#define CONFOPT_ICONV 1" >> config.h
347 echo "$TMP_LDFLAGS" >> config.ldflags
348 else
349 echo "No"
354 # wcwidth() existence
355 echo -n "Testing for wcwidth()... "
357 if [ "$WITHOUT_WCWIDTH" = "1" ] ; then
358 echo "Disabled by user (using Markus Kuhn's)"
359 else
360 echo "#include <wchar.h>" > .tmp.c
361 echo "int main(void) { wcwidth(L'a'); return 0; }" >> .tmp.c
363 $CC .tmp.c -o .tmp.o 2>> .config.log
365 if [ $? = 0 ] ; then
366 echo "OK"
367 echo "#define CONFOPT_WCWIDTH 1" >> config.h
368 else
369 echo "No; using Markus Kuhn's wcwidth()"
373 if [ "$WITH_NULL_HASH" = "1" ] ; then
374 echo "Selecting NULL hash function"
376 echo "#define CONFOPT_NULL_HASH 1" >> config.h
379 #########################################################
381 # final setup
383 echo "VERSION=$VERSION" >> makefile.opts
384 echo "PREFIX=\$(DESTDIR)$PREFIX" >> makefile.opts
385 echo "DOCDIR=\$(DESTDIR)$DOCDIR" >> makefile.opts
386 echo >> makefile.opts
388 cat makefile.opts makefile.in makefile.depend > Makefile
390 #########################################################
392 # cleanup
394 rm -f .tmp.c .tmp.o
396 exit 0