]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh | |
2 | ######################################################################### | |
3 | # | |
4 | # $Id: configure,v 1.5.2.2 2004/01/07 00:09:05 richard Exp $ | |
5 | # | |
6 | # ======================================================================= | |
7 | # | |
8 | # tdl - A console program for managing to-do lists | |
9 | # | |
10 | # Copyright (C) Richard P. Curnow 2003-2004 | |
11 | # | |
12 | # This program is free software; you can redistribute it and/or modify | |
13 | # it under the terms of version 2 of the GNU General Public License as | |
14 | # published by the Free Software Foundation. | |
15 | # | |
16 | # This program is distributed in the hope that it will be useful, but | |
17 | # WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 | # General Public License for more details. | |
20 | # | |
21 | # You should have received a copy of the GNU General Public License along | |
22 | # with this program; if not, write to the Free Software Foundation, Inc., | |
23 | # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA | |
24 | # | |
25 | # ======================================================================= | |
26 | ||
27 | if [ -f config.log ]; then rm -f config.log ; fi | |
28 | exec 5>config.log | |
29 | ||
30 | if [ "x${CC}" = "x" ]; then | |
31 | MYCC="gcc" | |
32 | else | |
33 | MYCC="${CC}" | |
34 | fi | |
35 | ||
36 | if [ "x${CFLAGS}" = "x" ]; then | |
37 | MYCFLAGS="-O2 -Wall" | |
38 | else | |
39 | MYCFLAGS="${CFLAGS}" | |
40 | fi | |
41 | ||
42 | # ======================================================================= | |
43 | # Functions | |
44 | ||
45 | #{{{ cleanup | |
46 | cleanup () { | |
47 | if [ -f docheck.c ]; then rm -f docheck.c ; fi | |
48 | if [ -f docheck.o ]; then rm -f docheck.o ; fi | |
49 | if [ -f docheck ]; then rm -f docheck ; fi | |
50 | rm -rf docheck.c docheck.o docheck | |
51 | } | |
52 | #}}} | |
53 | ||
54 | #{{{ test_cc : basic compiler sanity check | |
55 | test_cc () { | |
56 | printf "Testing whether your compiler \"$MYCC $MYCFLAGS\" works : " | |
57 | cat >docheck.c <<EOF; | |
58 | #include <stdio.h> | |
59 | int main (int argc, char **argv) | |
60 | { | |
61 | return 0; | |
62 | } | |
63 | EOF | |
64 | ${MYCC} ${MYCFLAGS} -o docheck docheck.c 1>&5 2>&5 | |
65 | if [ $? -eq 0 ] | |
66 | then | |
67 | printf "it works\n" | |
68 | else | |
69 | printf "it doesn't work\n" | |
70 | printf "Failed program was\n" 1>&5 | |
71 | cat docheck.c 1>&5 | |
72 | rm -f docheck.c docheck | |
73 | exit 1 | |
74 | fi | |
75 | cleanup | |
76 | } | |
77 | #}}} | |
78 | #{{{ test_readline_include | |
79 | test_readline_include () { | |
80 | # Objective : test whether we can compile and link a program using | |
81 | # readline, and if so how. | |
82 | ||
83 | # As for includes, is it <readline.h> or <readline/readline.h> | |
84 | ||
85 | # As for linking, do we need -ltermcap, -lncurses etc | |
86 | ||
87 | printf "Testing what to include for readline : " | |
88 | cat >docheck.c <<EOF; | |
89 | #include <stdio.h> | |
90 | #include <readline.h> | |
91 | int main (int argc, char **argv) { | |
92 | printf("%s\n", rl_library_version); | |
93 | return 0; | |
94 | } | |
95 | EOF | |
96 | ${MYCC} ${MYCFLAGS} ${readline_inc_arg} -c -o docheck.o docheck.c 1>&5 2>&5 | |
97 | if [ $? -eq 0 ]; then | |
98 | printf "<readline.h>\n" | |
99 | READLINE_DEFINE="-DBARE_READLINE_H=1" | |
100 | else | |
101 | rm -f docheck.c | |
102 | cat >docheck.c <<EOF; | |
103 | #include <stdio.h> | |
104 | #include <readline/readline.h> | |
105 | int main (int argc, char **argv) { | |
106 | printf("%s\n", rl_library_version); | |
107 | return 0; | |
108 | } | |
109 | EOF | |
110 | ${MYCC} ${MYCFLAGS} ${readline_inc_arg} -c -o docheck.o docheck.c 1>&5 2>&5 | |
111 | if [ $? -eq 0 ]; then | |
112 | printf "<readline/readline.h>\n" | |
113 | READLINE_DEFINE="-DBARE_READLINE_H=0" | |
114 | else | |
115 | printf "FAILED\n" | |
116 | printf "Can't include readline.h, giving up on readline" | |
117 | use_readline="no" | |
118 | fi | |
119 | fi | |
120 | ||
121 | cleanup | |
122 | return | |
123 | } | |
124 | ||
125 | #}}} | |
126 | #{{{ test_readline_lib | |
127 | test_readline_lib () { | |
128 | ||
129 | printf "Testing extra libraries to link with readline : " | |
130 | cat >docheck.c <<EOF; | |
131 | #include <stdio.h> | |
132 | #if BARE_READLINE_H | |
133 | #include <readline.h> | |
134 | #else | |
135 | #include <readline/readline.h> | |
136 | #endif | |
137 | ||
138 | int main (int argc, char **argv) { | |
139 | printf("%s\n", rl_library_version); | |
140 | return 0; | |
141 | } | |
142 | EOF | |
143 | ${MYCC} ${MYCFLAGS} ${readline_inc_arg} ${READLINE_DEFINE} -c -o docheck.o docheck.c 1>&5 2>&5 | |
144 | if [ $? -ne 0 ]; then | |
145 | printf "unexpected compile failure, giving up on readline\n" | |
146 | use_readline="no" | |
147 | cleanup | |
148 | return | |
149 | fi | |
150 | ||
151 | # Now try to link it | |
152 | ${MYCC} ${MYCFLAGS} -o docheck docheck.o ${readline_lib_arg} -lreadline 1>&5 2>&5 | |
153 | if [ $? -eq 0 ]; then | |
154 | extra_readline_libs="" | |
155 | printf "(none)\n" | |
156 | cleanup | |
157 | return | |
158 | fi | |
159 | ||
160 | ${MYCC} ${MYCFLAGS} -o docheck docheck.o ${readline_lib_arg} -lreadline -ltermcap 1>&5 2>&5 | |
161 | if [ $? -eq 0 ]; then | |
162 | extra_readline_libs="-ltermcap" | |
163 | printf -- "-ltermcap\n" | |
164 | cleanup | |
165 | return | |
166 | fi | |
167 | ||
168 | ${MYCC} ${MYCFLAGS} -o docheck docheck.o ${readline_lib_arg} -lreadline -lncurses 1>&5 2>&5 | |
169 | if [ $? -eq 0 ]; then | |
170 | extra_readline_libs="-lncurses" | |
171 | printf -- "-lncurses\n" | |
172 | cleanup | |
173 | return | |
174 | fi | |
175 | ||
176 | printf "can't link a readline program\n" | |
177 | use_readline="no" | |
178 | return | |
179 | ||
180 | } | |
181 | #}}} | |
182 | #{{{ test_completion_matches | |
183 | test_completion_matches () { | |
184 | # See if the readline library has completion_matches() | |
185 | ||
186 | printf "Testing for completion_matches in readline : " | |
187 | cat >docheck.c <<EOF; | |
188 | #include <stdio.h> | |
189 | #if BARE_READLINE_H | |
190 | #include <readline.h> | |
191 | #else | |
192 | #include <readline/readline.h> | |
193 | #endif | |
194 | ||
195 | int main (int argc, char **argv) { | |
196 | void *x = &completion_matches; | |
197 | printf("%p\n", x); | |
198 | return 0; | |
199 | } | |
200 | EOF | |
201 | ${MYCC} ${MYCFLAGS} ${readline_inc_arg} ${READLINE_DEFINE} -c -o docheck.o docheck.c 1>&5 2>&5 | |
202 | if [ $? -ne 0 ]; then | |
203 | printf "no\n"; | |
204 | has_completion_matches=no | |
205 | cleanup | |
206 | return | |
207 | fi | |
208 | ||
209 | ${MYCC} ${MYCFLAGS} -o docheck docheck.o ${readline_lib_arg} -lreadline ${extra_readline_libs} 1>&5 2>&5 | |
210 | if [ $? -eq 0 ]; then | |
211 | printf "yes\n" | |
212 | has_completion_matches=yes | |
213 | else | |
214 | printf "no\n" | |
215 | has_completion_matches=no | |
216 | fi | |
217 | cleanup | |
218 | } | |
219 | #}}} | |
220 | #{{{ test_rl_completion_matches | |
221 | test_rl_completion_matches () { | |
222 | # See if the readline library has completion_matches() | |
223 | ||
224 | printf "Testing for rl_completion_matches in readline : " | |
225 | cat >docheck.c <<EOF; | |
226 | #include <stdio.h> | |
227 | #if BARE_READLINE_H | |
228 | #include <readline.h> | |
229 | #else | |
230 | #include <readline/readline.h> | |
231 | #endif | |
232 | ||
233 | int main (int argc, char **argv) { | |
234 | void *x = &rl_completion_matches; | |
235 | printf("%p\n", x); | |
236 | return 0; | |
237 | } | |
238 | EOF | |
239 | ${MYCC} ${MYCFLAGS} ${readline_inc_arg} ${READLINE_DEFINE} -c -o docheck.o docheck.c 1>&5 2>&5 | |
240 | if [ $? -ne 0 ]; then | |
241 | printf "no\n" | |
242 | has_rl_completion_matches=no | |
243 | cleanup | |
244 | return | |
245 | fi | |
246 | ||
247 | ${MYCC} ${MYCFLAGS} -o docheck docheck.o ${readline_lib_arg} -lreadline ${extra_readline_libs} 1>&5 2>&5 | |
248 | if [ $? -eq 0 ]; then | |
249 | printf "yes\n" | |
250 | has_rl_completion_matches=yes | |
251 | else | |
252 | printf "no\n" | |
253 | has_rl_completion_matches=no | |
254 | fi | |
255 | cleanup | |
256 | } | |
257 | #}}} | |
258 | ||
259 | #{{{ usage | |
260 | usage () { | |
261 | cat <<EOF; | |
262 | \`configure' configures tdl to adapt to many kinds of systems. | |
263 | ||
264 | Usage: ./configure [OPTION]... | |
265 | ||
266 | Defaults for the options are specified in brackets. | |
267 | ||
268 | Configuration: | |
269 | -h, --help display this help and exit | |
270 | ||
271 | Installation directories: | |
272 | --prefix=PREFIX install architecture-independent files in PREFIX | |
273 | [/usr/local] | |
274 | ||
275 | By default, \`make install' will install all the files in | |
276 | \`/usr/local/bin', \`/usr/local/lib' etc. You can specify | |
277 | an installation prefix other than \`/usr/local' using \`--prefix', | |
278 | for instance \`--prefix=$HOME'. | |
279 | ||
280 | For better control, use the options below. | |
281 | --without-readline Don't try to use GNU readline | |
282 | --readline-dir=DIR Specify parent of readline include and lib directories | |
283 | --readline-inc-dir=DIR Specify where readline include directory is | |
284 | --readline-lib-dir=DIR Specify where readline lib directory is | |
285 | ||
286 | Fine tuning of the installation directories: | |
287 | --bindir=DIR user executables [EPREFIX/bin] | |
288 | --infodir=DIR info documentation [PREFIX/info] | |
289 | --mandir=DIR man documentation [PREFIX/man] | |
290 | ||
291 | Some influential environment variables: | |
292 | CC C compiler command | |
293 | CFLAGS C compiler flags | |
294 | LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a | |
295 | nonstandard directory <lib dir> | |
296 | ||
297 | Use these variables to override the choices made by \`configure' or to help | |
298 | it to find libraries and programs with nonstandard names/locations. | |
299 | ||
300 | Report bugs to <rc@rc0.org.uk>. | |
301 | EOF | |
302 | } | |
303 | #}}} | |
304 | # ======================================================================= | |
305 | ||
306 | # Defaults for variables | |
307 | PREFIX=/usr/local | |
308 | ||
309 | use_readline=yes | |
310 | bad_options=no | |
311 | use_dotlock=yes | |
312 | ||
313 | # Parse options to configure | |
314 | for option | |
315 | do | |
316 | case "$option" in | |
317 | ||
318 | --prefix=* | --install-prefix=* ) | |
319 | PREFIX=`echo $option | sed -e 's/[^=]*=//;'` | |
320 | ;; | |
321 | --bindir=* ) | |
322 | BINDIR=`echo $option | sed -e 's/[^=]*=//;'` | |
323 | ;; | |
324 | --mandir=* ) | |
325 | MANDIR=`echo $option | sed -e 's/[^=]*=//;'` | |
326 | ;; | |
327 | --infodir=* ) | |
328 | INFODIR=`echo $option | sed -e 's/[^=]*=//;'` | |
329 | ;; | |
330 | --without-readline ) | |
331 | use_readline=no | |
332 | ;; | |
333 | --readline-dir=* ) | |
334 | readline_dir=`echo $option | sed -e 's/[^=]*=//;'` | |
335 | ;; | |
336 | --readline-inc-dir=* ) | |
337 | readline_inc_dir=`echo $option | sed -e 's/[^=]*=//;'` | |
338 | ;; | |
339 | --readline-lib-dir=* ) | |
340 | readline_lib_dir=`echo $option | sed -e 's/[^=]*=//;'` | |
341 | ;; | |
342 | --disable-dotlock ) | |
343 | use_dotlock=no | |
344 | ;; | |
345 | -h | --help ) | |
346 | usage | |
347 | exit 1 | |
348 | ;; | |
349 | * ) | |
350 | printf "Unrecognized option : $option\n" | |
351 | bad_options=yes | |
352 | ;; | |
353 | esac | |
354 | done | |
355 | ||
356 | if [ ${bad_options} = yes ]; then | |
357 | exit 1 | |
358 | fi | |
359 | ||
360 | #{{{ process readline-related arguments | |
361 | if [ "$use_readline" = "yes" ]; then | |
362 | if [ "x$readline_dir" != "x" ]; then | |
363 | if [ "x$readline_inc_dir" = "x" ]; then | |
364 | readline_inc_dir="${readline_dir}/include" | |
365 | fi | |
366 | if [ "x$readline_lib_dir" = "x" ]; then | |
367 | readline_lib_dir="${readline_dir}/lib" | |
368 | fi | |
369 | fi | |
370 | ||
371 | if [ "x$readline_inc_dir" != "x" ]; then | |
372 | readline_inc_arg="-I${readline_inc_dir}" | |
373 | else | |
374 | readline_inc_arg="" | |
375 | fi | |
376 | ||
377 | if [ "x$readline_lib_dir" != "x" ]; then | |
378 | readline_lib_arg="-L${readline_lib_dir} -R${readline_lib_dir}" | |
379 | else | |
380 | readline_lib_arg="" | |
381 | fi | |
382 | fi | |
383 | #}}} | |
384 | ||
385 | test_cc | |
386 | if [ "${use_readline}" = "yes" ]; then test_readline_include ; fi | |
387 | if [ "${use_readline}" = "yes" ]; then test_readline_lib ; fi | |
388 | if [ "${use_readline}" = "yes" ]; then test_completion_matches ; fi | |
389 | if [ "${use_readline}" = "yes" ]; then test_rl_completion_matches ; fi | |
390 | ||
391 | case "${use_readline}-${has_rl_completion_matches}-${has_completion_matches}" in | |
392 | yes-yes-* ) | |
393 | READLINE_DEFINE="-DUSE_READLINE=1 ${READLINE_DEFINE} -DUSE_RL_COMPLETION_MATCHES=1" | |
394 | ;; | |
395 | yes-*-yes ) | |
396 | READLINE_DEFINE="-DUSE_READLINE=1 ${READLINE_DEFINE} -DUSE_RL_COMPLETION_MATCHES=0" | |
397 | ;; | |
398 | yes-* ) | |
399 | printf "Can't find a completion function in readline\n" | |
400 | exit 1 | |
401 | ;; | |
402 | no-* ) | |
403 | READLINE_DEFINE="-UUSE_READLINE" | |
404 | printf "Not using readline\n"; | |
405 | esac | |
406 | ||
407 | case "${use_dotlock}" in | |
408 | yes ) | |
409 | DOTLOCK_DEFINE="-DUSE_DOTLOCK=1" | |
410 | ;; | |
411 | no ) | |
412 | DOTLOCK_DEFINE="" | |
413 | ;; | |
414 | esac | |
415 | ||
416 | DEFINES=${DOTLOCK_DEFINE} | |
417 | ||
418 | if [ "x" = "x${BINDIR}" ]; then BINDIR=${PREFIX}/bin ; fi | |
419 | if [ "x" = "x${MANDIR}" ]; then MANDIR=${PREFIX}/man ; fi | |
420 | if [ "x" = "x${INFODIR}" ]; then INFODIR=${PREFIX}/info ; fi | |
421 | ||
422 | if [ "x${use_readline}" = "xno" ]; then | |
423 | lib_readline="" | |
424 | else | |
425 | lib_readline="${readline_lib_arg} -lreadline ${extra_readline_libs}" | |
426 | fi | |
427 | ||
428 | echo "Generating Makefile" | |
429 | ||
430 | rm -f Makefile | |
431 | sed -e "s%@cc@%${MYCC}%; \ | |
432 | s%@cflags@%${MYCFLAGS}%; \ | |
433 | s%@prefix@%${PREFIX}%; \ | |
434 | s%@bindir@%${BINDIR}%; \ | |
435 | s%@mandir@%${MANDIR}%; \ | |
436 | s%@infodir@%${INFODIR}%; \ | |
437 | s%@readline_define@%${READLINE_DEFINE}%; \ | |
438 | s%@defines@%${DEFINES}%; \ | |
439 | s%@inc_readline@%${readline_inc_arg}%; \ | |
440 | s%@lib_readline@%${lib_readline}%; \ | |
441 | " < Makefile.in > Makefile | |
442 | ||
443 | # ======================================================================= | |
444 | # vim:et:sw=2:ht=2:sts=2:fdm=marker:cms=#%s | |
445 |