]> git.ipfire.org Git - thirdparty/util-linux.git/blob - configure
e67be05a2e04291a48111aabe5261aab6bc516ba
[thirdparty/util-linux.git] / configure
1 #!/bin/sh
2 # Configure script for util-linux - aeb, 990205
3 #
4 # We need to find out the following things:
5 #
6 # Version of gcc
7 #
8 # Existence of header files:
9 # H1. For fdisksunlabel.c: is there a <scsi/scsi.h>?
10 # H2. For fdisk.c: is there a <linux/blkpg.h>?
11 # H3. For kbd_rate.c: does <linux/kd.h> exist?
12 # H4. For nls.h: do we have <locale.h>?
13 # H5. For cal.c: do we have <langinfo.h>?
14 # H6. For mkswap.c: do we have <sys/user.h> or <asm/page.h>?
15 # H7. For nfsmount.c: do we have <rpcsvc/nfs_prot.h>?
16 # H8. For nfsmount.h (nfsmount_xdr.c: int32_t): do we have <asm/types.h>?
17 # H9. For raw.c: do we have <linux/raw.h>?
18 #
19 # Existence of functions:
20 # F1. For nfsmount.c: is inet_aton() available?
21 # F2. For mkswap.c: is fsync() available?
22 # F3. For agetty.c: is getdomainname() available?
23 # F4. For hwclock/kd.c: do we have nanosleep()?
24 # F5. For mkswap.c: do we have personality()?
25 # F6. For agetty.c: is updwtmp() available?
26 # F7. For pg.c: are fseeko() and ftello() available?
27 # F8. For fsck.cramfs.c: is lchown() available?
28 #
29 # 1. For sys-utils/cytune.c: do we need <linux/tqueue.h>?
30 # 2. For cfdisk, setterm, more, ul: do we have ncurses? How installed?
31 # 3. For more: do we have libtermcap?
32 # 4. For chfn, chsh, login, newgrp, passwd: do we need -lcrypt?
33 # 5. For sln: does static compilation work?
34 # 6. For lib/nls.h: do we have <libintl.h> and gettext()?
35 # 7. For xgettext: does it take the option --foreign-user?
36 # 8. For err.c: do we have __progname?
37 # 9. For script.c: do we have <pty.h> and openpty()?
38 # 10. For lib/widechar.h: do we have wide character support?
39 # 11. For pivot_root.c: does <linux/unistd.h> define __NR_pivot_root?
40 # 12. For hwclock.c: does struct tm have a field tm_gmtoff?
41 # 13. For nfsmount: does the output of rpcgen compile?
42 # 14. For fsck.cramfs, mkfs.cramfs: do we have libz?
43
44 rm -f make_include defines.h
45
46 VERSION=`cat VERSION`
47 echo
48 echo configuring util-linux-$VERSION
49 echo
50 echo "VERSION=$VERSION" > make_include
51 echo '#define UTIL_LINUX_VERSION "'$VERSION'"' > defines.h
52 echo '#define util_linux_version "util-linux-'$VERSION'"' >> defines.h
53 echo >> defines.h
54
55 CC=${CC-cc}
56 CFLAGS=${CFLAGS-"-O"}
57 LDFLAGS=${LDFLAGS-"-s"}
58 echo CC=$CC >> make_include
59 echo CFLAGS=$CFLAGS >> make_include
60 echo LDFLAGS=$LDFLAGS >> make_include
61
62 DEFS=
63 LIBS=
64 compile='$CC $CFLAGS $DEFS conftest.c -o conftest $LIBS >/dev/null 2>&1'
65 compile_with_warnings='$CC $CFLAGS $DEFS conftest.c -o conftest $LIBS 2>&1'
66 static_compile='$CC -static $DEFS conftest.c -o conftest $LIBS >/dev/null 2>&1'
67 eval COMPILE='"'$compile'"'
68 export COMPILE
69
70 rm -f conftest.c conftest
71
72 #
73 # Old gcc wants options like -m486, but gcc 3.0 says
74 # `-m486' is deprecated. Use `-march=i486' or `-mcpu=i486' instead.
75 #
76 echo "
77 int main(){ exit(0); }
78 " > conftest.c
79 gccout=`$CC $CFLAGS -m386 conftest.c -o conftest 2>&1 | grep "march="`
80 if test -z "$gccout"; then
81 echo "HAVE_OLD_GCC=yes" >> make_include
82 fi
83 rm -f conftest conftest.c
84
85 #
86 # Find out about the existence of header files
87 #
88
89 #
90 # H1. For fdisk/fdisksunlabel.c: is <scsi/scsi.h> available?
91 # Some kernels have <scsi/scsi.h> that uses u_char
92 # But maybe there is already a typedef. Let us use a #define
93 #
94 echo "
95 #define u_char unsigned char
96 #include <scsi/scsi.h>
97 #undef u_char
98 int main(){ exit(0); }
99 " > conftest.c
100 eval $compile
101 if test -s conftest; then
102 echo "#define HAVE_scsi_h" >> defines.h
103 echo "You have <scsi/scsi.h>"
104 else
105 echo "You don't have <scsi/scsi.h>"
106 fi
107 rm -f conftest conftest.c
108
109 #
110 # H2. For fdisk/fdisk.c: is <linux/blkpg.h> available?
111 #
112 if ./testincl "linux/blkpg.h"; then
113 echo "#define HAVE_blkpg_h" >> defines.h
114 fi
115
116 #
117 # H3. Does <linux/kd.h> exist?
118 #
119 if ./testincl "linux/kd.h"; then
120 echo "#define HAVE_kd_h" >> defines.h
121 fi
122
123 #
124 # H4. For lib/nls.h: do we have <locale.h>?
125 #
126 if ./testincl "locale.h"; then
127 echo "#define HAVE_locale_h" >> defines.h
128 fi
129
130 #
131 # H5. For cal.c: do we have <langinfo.h>?
132 #
133 if ./testincl "langinfo.h"; then
134 echo "#define HAVE_langinfo_h" >> defines.h
135 fi
136
137 #
138 # H6. For mkswap.c: do we have <sys/user.h> or <asm/page.h>?
139 #
140 if ./testincl "sys/user.h"; then
141 echo "#define HAVE_sys_user_h" >> defines.h
142 else if ./testincl "asm/page.h"; then
143 echo "#define HAVE_asm_page_h" >> defines.h
144 fi fi
145
146 #
147 # H7. For nfsmount.c: do we have <rpcsvc/nfs_prot.h>?
148 #
149 if ./testincl "rpcsvc/nfs_prot.h"; then
150 echo "#define HAVE_rpcsvc_nfs_prot_h" >> defines.h
151 fi
152
153 #
154 # H8. For nfsmount.h: do we have <asm/types.h>?
155 #
156 if ./testincl "asm/types.h"; then
157 echo "#define HAVE_asm_types_h" >> defines.h
158 fi
159
160 #
161 # H9. For raw.c: do we have <linux/raw.h>?
162 #
163 if ./testincl "linux/raw.h"; then
164 echo "HAVE_RAW_H=yes" >> make_include
165 fi
166
167
168 #
169 # Find out about the existence of functions
170 #
171
172 #
173 # F1. For mount/nfsmount.c: is inet_aton() available?
174 #
175 echo "
176 #include <sys/socket.h>
177 #include <netinet/in.h>
178 #include <arpa/inet.h>
179 int main(int a, char **v){
180 if (a == -1) /* false */
181 inet_aton((const char *) 0, (struct in_addr *) 0);
182 exit(0);
183 }
184 " > conftest.c
185 eval $compile
186 if test -s conftest; then
187 echo "#define HAVE_inet_aton" >> defines.h
188 echo "You have inet_aton()"
189 else
190 echo "You don't have inet_aton()"
191 fi
192 rm -f conftest conftest.c
193
194 #
195 # F2. For mkswap.c: is fsync() available?
196 #
197 echo "
198 #include <unistd.h>
199 int main(int a, char **v){
200 if (a == -1) /* false */
201 fsync(0);
202 exit(0);
203 }
204 " > conftest.c
205 eval $compile
206 if test -s conftest; then
207 echo "#define HAVE_fsync" >> defines.h
208 echo "You have fsync()"
209 else
210 echo "You don't have fsync()"
211 fi
212 rm -f conftest conftest.c
213
214 #
215 # F3. For agetty.c: is getdomainname() available?
216 #
217 echo "
218 #include <unistd.h>
219 int main(int a, char **v){
220 char buf[1];
221 if (a == -1) /* false */
222 getdomainname(buf, sizeof buf);
223 exit(0);
224 }
225 " > conftest.c
226 eval $compile
227 if test -s conftest; then
228 echo "#define HAVE_getdomainname" >> defines.h
229 echo "You have getdomainname()"
230 else
231 echo "You don't have getdomainname()"
232 fi
233 rm -f conftest conftest.c
234
235 #
236 # F4. For hwclock/kd.c: do we have nanosleep?
237 #
238 echo "
239 #include <time.h>
240 int main () {
241 struct timespec sleep = { 0, 1 };
242 nanosleep( &sleep, NULL );
243 exit(0);
244 }
245 " > conftest.c
246 eval $compile
247 if test -s conftest; then
248 echo "#define HAVE_nanosleep" >> defines.h
249 echo "You have nanosleep()"
250 else
251 echo "You don't have nanosleep()"
252 fi
253 rm -f conftest conftest.c
254
255 #
256 # F5. For mkswap.c: do we have personality()?
257 #
258 echo "
259 int main () {
260 extern int personality(unsigned long);
261 personality(0);
262 exit(0);
263 }
264 " > conftest.c
265 eval $compile
266 if test -s conftest; then
267 echo "#define HAVE_personality" >> defines.h
268 echo "You have personality()"
269 else
270 echo "You don't have personality()"
271 fi
272 rm -f conftest conftest.c
273
274 #
275 # F6. For agetty.c: is updwtmp() available?
276 #
277 echo '
278 #include <string.h>
279 #include <utmp.h>
280 int main(int a, char **v){
281 struct utmp ut;
282 memset (&ut, 0, sizeof(ut));
283 if (a == -1) /* false */
284 updwtmp("/nowhere/wtmp", &ut);
285 exit(0);
286 }
287 ' > conftest.c
288 eval $compile
289 if test -s conftest; then
290 echo "#define HAVE_updwtmp" >> defines.h
291 echo "You have updwtmp()"
292 else
293 echo "You don't have updwtmp()"
294 fi
295 rm -f conftest conftest.c
296
297 #
298 # F7. For pg.c: are fseeko() and ftello() available?
299 #
300 echo '
301 #include <stdio.h>
302 int main(int a, char **v){
303 fseeko(stdout, 0, 0);
304 ftello(stdout);
305 exit(0);
306 }
307 ' > conftest.c
308 eval $compile
309 if test -s conftest; then
310 echo "#define HAVE_fseeko" >> defines.h
311 echo "You have fseeko()"
312 else
313 echo "You don't have fseeko()"
314 fi
315 rm -f conftest conftest.c
316
317 #
318 # F8. For fsck.cramfs.c: is lchown() available?
319 #
320 echo '
321 #include <sys/types.h>
322 #include <unistd.h>
323 int main(int a, char **v){
324 lchown("nowhere",0,0);
325 exit(0);
326 }
327 ' > conftest.c
328 gccout=`eval $compile_with_warnings | grep "lchown is not implemented"`
329 if test -s conftest -a -z "$gccout"; then
330 echo "#define HAVE_lchown" >> defines.h
331 echo "You have lchown()"
332 else
333 echo "You don't have lchown()"
334 fi
335 rm -f conftest conftest.c
336
337 #
338 # 1. cytune.c may need struct tq_struct
339 #
340 echo "
341 #include <sys/types.h>
342 #include <linux/cyclades.h>
343 int main(){ exit(0); }
344 " > conftest.c
345 eval $compile
346 if test -s conftest; then
347 echo "You don't need <linux/tqueue.h>"
348 else
349 echo "#define NEED_tqueue_h" >> defines.h
350 echo "You need <linux/tqueue.h>"
351 fi
352 rm -f conftest conftest.c
353
354 #
355 # 2. How is [n]curses installed?
356 #
357 test_curses_h=0
358 have_ncurses=1
359 if ! ./testincl "term.h"; then
360 have_ncurses=0
361 elif ./testincl -q "ncurses/curses.h"; then
362 echo "HAVE_NCURSES=yes" >> make_include
363 echo "CURSESFLAGS=-I/usr/include/ncurses -DNCH=0" >> make_include
364 echo "You have ncurses. Using <ncurses/curses.h>."
365 elif ./testincl -q "ncurses.h"; then
366 echo "HAVE_NCURSES=yes" >> make_include
367 echo "CURSESFLAGS=-DNCH=1" >> make_include
368 echo "You have ncurses. Using <ncurses.h>."
369 elif [ -f /usr/local/include/ncurses.h ]; then
370 echo "HAVE_NCURSES=yes" >> make_include
371 echo "CURSESFLAGS=-I/usr/local/include -DNCH=1" >> make_include
372 echo "You have ncurses. Using /usr/local/include/ncurses.h."
373 elif ./testincl -q "curses.h"; then
374 test_curses_h=1
375 else
376 have_ncurses=0
377 fi
378 #
379 # If we found a curses.h, test whether it is ncurses
380 # (It should define __NCURSES_H and NCURSES_VERSION and NCURSES_CONST ...)
381 #
382 if [ $test_curses_h = 1 ]; then
383 echo "
384 #include <curses.h>
385 int main(){ char *c = NCURSES_VERSION; exit(0); }
386 " > conftest.c
387 eval $compile
388 if test -s conftest; then
389 echo "HAVE_NCURSES=yes" >> make_include
390 echo "CURSESFLAGS=-DNCH=0" >> make_include
391 echo "You have ncurses. Using <curses.h>."
392 else
393 have_ncurses=0
394 fi
395 rm -f conftest conftest.c
396 fi
397
398 if [ $have_ncurses = 0 ]; then
399 echo "HAVE_NCURSES=no" >> make_include
400 echo "You don't have ncurses - I will not make ul and setterm."
401 else
402 echo "LIBCURSES=-lncurses" >> make_include
403 fi
404
405 #
406 # 3. Some systems have /usr/lib/termcap.so -> /usr/lib/termcap.so.2
407 # where however the latter file does not exist. When termcap does
408 # not exist, we can try to compile more with curses instead.
409 #
410 echo '
411 #include <termcap.h>
412 int main(){ exit(0); tgetnum("li"); }
413 ' > conftest.c
414 LIBS=-ltermcap
415 eval $compile
416 LIBS=
417 if test -s conftest; then
418 echo "#define HAVE_termcap" >> defines.h
419 echo "HAVE_TERMCAP=yes" >> make_include
420 echo "LIBTERMCAP=-ltermcap" >> make_include
421 echo "You have termcap"
422 else
423 echo "HAVE_TERMCAP=no" >> make_include
424 if [ $have_ncurses = 0 ]; then
425 echo "You don't have termcap - I will not make more."
426 else
427 echo "You don't have termcap"
428 fi
429 fi
430 rm -f conftest conftest.c
431
432 #
433 # 4. Do we need -lcrypt?
434 #
435 echo '
436 #define _XOPEN_SOURCE
437 #include <unistd.h>
438 int main(){ char *c = crypt("abc","pw"); exit(0); }
439 ' > conftest.c
440 eval $compile
441 if test -s conftest; then
442 echo "NEED_LIBCRYPT=no" >> make_include
443 echo "You don't need -lcrypt"
444 else
445 echo "NEED_LIBCRYPT=yes" >> make_include
446 echo "You need -lcrypt"
447 fi
448 rm -f conftest conftest.c
449
450 #
451 # 5. Does static compilation work?
452 #
453 echo "
454 int main(){ return 0; }
455 " > conftest.c
456 eval $static_compile
457 if test -s conftest; then
458 : OK, nothing special
459 else
460 echo "CAN_DO_STATIC=no" >> make_include
461 echo "Strange... Static compilation fails here."
462 fi
463 rm -f conftest.c conftest
464
465 #
466 # 6. For lib/nls.h: do we have <libintl.h> and gettext() ?
467 #
468 echo '
469 #include <libintl.h>
470 int main(int a, char **v){
471 if (a == -1) /* false */
472 gettext("There is no gettext man page\n");
473 exit(0);
474 }
475 ' > conftest.c
476 eval $compile
477 if test -s conftest; then
478 echo '#define HAVE_libintl_h' >> defines.h
479 echo "You have <libintl.h> and gettext()"
480 echo '#define MAY_ENABLE_NLS' >> defines.h
481 MAY_ENABLE_NLS=yes
482 else
483 echo "You don't have native language support"
484 MAY_ENABLE_NLS=no
485 fi
486 rm -f conftest conftest.c
487
488
489 #
490 # 7. Does xgettext exist and take the option --foreign-user?
491 #
492 # We use the bash builtin "type" here.
493 # I don't see an easy way to avoid it.
494 # Many Linux systems do not have "which". Maybe "env" can be used.
495 # Writing /usr/bin/xgettext is no good: one may have xgettext elsewhere.
496 #
497 if (test $MAY_ENABLE_NLS = yes && type xgettext > /dev/null 2>&1); then
498 msg=`xgettext --foreign-user 2>&1 | grep unrecognized`
499 if test -n "$msg"; then
500 echo "FOREIGN = " >> make_include
501 else
502 echo "FOREIGN = --foreign-user" >> make_include
503 fi
504 echo "HAVE_XGETTEXT=yes" >> make_include
505 else
506 echo "HAVE_XGETTEXT=no" >> make_include
507 fi
508
509
510 #
511 # 8. For err.c: do we have __progname?
512 # [make sure gcc -O does not optimize the access away]
513 #
514 echo "
515 #include <stdio.h>
516 extern char *__progname;
517 int main(){ printf(__progname); exit(0); }
518 " > conftest.c
519 eval $compile
520 if test -s conftest; then
521 echo "#define HAVE_progname" >> defines.h
522 echo "You have __progname"
523 else
524 echo "You don't have __progname"
525 fi
526 rm -f conftest conftest.c
527
528 #
529 # 9. For script.c: do we have <pty.h> and openpty()?
530 #
531 echo "
532 #include <pty.h>
533 int main(){ exit(0); openpty(0, 0, 0, 0, 0); }
534 " > conftest.c
535 LIBS=-lutil
536 eval $compile
537 LIBS=
538 if test -s conftest; then
539 echo "HAVE_OPENPTY=yes" >> make_include
540 echo "#define HAVE_openpty" >> defines.h
541 echo "You have <pty.h> and openpty()"
542 else
543 echo "You don't have <pty.h> and openpty()"
544 fi
545 rm -f conftest conftest.c
546
547 #
548 # 10. For lib/widechar.h: do we have wide character support?
549 # [Do we have the headers <wchar.h>, <wctype.h>, the types wchar_t, wint_t
550 # and the fgetwc, fputwc, WEOF functions/macros?]
551 #
552 echo "
553 #include <wchar.h>
554 #include <wctype.h>
555 #include <stdio.h>
556 int main () {
557 wchar_t wc;
558 wint_t w;
559 w = fgetwc(stdin);
560 if (w == WEOF) exit(1);
561 wc = w;
562 fputwc(wc,stdout);
563 exit(0);
564 }
565 " > conftest.c
566 eval $compile
567 if test -s conftest && ./conftest < conftest.c > /dev/null 2>/dev/null; then
568 echo "#define ENABLE_WIDECHAR" >> defines.h
569 echo "You have wide character support"
570 else
571 echo "You don't have wide character support"
572 fi
573 rm -f conftest conftest.c
574
575 #
576 # 11. For pivot_root.c: does <linux/unistd.h> define __NR_pivot_root?
577 #
578 echo "
579 #include <linux/unistd.h>
580 int main(void)
581 {
582 return __NR_pivot_root;
583 }
584 " >conftest.c
585 eval $compile
586 if test -s conftest; then
587 echo "HAVE_PIVOT_ROOT=yes" >> make_include
588 echo "You have __NR_pivot_root"
589 else
590 echo "You don't have __NR_pivot_root"
591 fi
592 rm -f conftest conftest.c
593
594 #
595 # 12. For hwclock.c: does struct tm have a field tm_gmtoff?
596 #
597 echo "
598 #include <time.h>
599 #include <unistd.h>
600 int main(int a, char **v)
601 {
602 struct tm *tm = localtime(0);
603 if (a == -1) /* false */
604 sleep(tm->tm_gmtoff);
605 exit(0);
606 }
607 " >conftest.c
608 eval $compile
609 if test -s conftest; then
610 echo "#define HAVE_tm_gmtoff" >> defines.h
611 echo "You have a tm_gmtoff field in struct tm"
612 else
613 echo "You don't have a tm_gmtoff field in struct tm"
614 fi
615 rm -f conftest conftest.c
616
617 #
618 # 13. For nfsmount: does the output of rpcgen compile?
619 #
620 # On some systems the output of rpcgen compiles with warnings
621 # Here we conclude "Your rpcgen output does not compile"
622 # and use pregenerated files. If one wishes to use rpcgen anyway,
623 # just add the line "HAVE_GOOD_RPC=yes" to make_include.
624 #
625 rm -f conftest conftestx.c conftestl.c conftest.h conftest.x
626 rm -f conftestx.o conftestl.o
627 echo "
628 #ifdef RPC_CLNT
629 %#include <string.h> /* for memset() */
630 #endif
631 %#include <asm/types.h>
632 typedef opaque fhandle[1];
633 union fhstatus switch (unsigned fhs_status) {
634 case 0:
635 fhandle fhs_fhandle;
636 default:
637 void;
638 };
639 typedef string dirpath<1024>;
640 struct ppathcnf {
641 short pc_mask[2];
642 };
643
644 program MOUNTPROG {
645 version MOUNTVERS {
646 fhstatus
647 MOUNTPROC_MNT(dirpath) = 1;
648 } = 2;
649 } = 100005;
650 " > conftest.x
651 if rpcgen -h -o conftest.h conftest.x 2> conferrs && \
652 rpcgen -c -o conftestx.c conftest.x 2>> conferrs && \
653 rpcgen -l -o conftestl.c conftest.x 2>> conferrs && \
654 cc -c conftestx.c 2>> conferrs && cc -c conftestl.c 2>> conferrs && \
655 test ! -s conferrs
656 then
657 echo "HAVE_GOOD_RPC=yes" >> make_include
658 echo "Your rpcgen seems to work"
659 else
660 echo "Your rpcgen output does not compile - using pregenerated code"
661 fi
662 rm -f conftest conftestx.c conftestl.c conftest.h conftest.x conferrs
663 rm -f conftestx.o conftestl.o
664
665 #
666 # 14. For fsck.cramfs, mkfs.cramfs: do we have libz?
667 #
668 echo '
669 #include <zlib.h>
670 int main(){ exit(0); crc32(0, 0, 0); }
671 ' > conftest.c
672 LIBS=-lz
673 eval $compile
674 LIBS=
675 if test -s conftest; then
676 echo "HAVE_ZLIB=yes" >> make_include
677 echo "You have zlib"
678 else
679 echo "HAVE_ZLIB=no" >> make_include
680 echo "You don't have zlib"
681 fi
682 rm -f conftest conftest.c
683