Debian Codegraph @

Build.sh

raw symbols SCIP
1 #!/bin/sh
2 srcversion='$MirOS: src/bin/pax/Build.sh,v 1.27 2024/08/17 23:33:49 tg Exp $'
3 set +evx
4 #-
5 # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
6 # 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019,
7 # 2020, 2021, 2023, 2024
8 # mirabilos <[email protected]>
9 # Copyright (c) 2018
10 # mirabilos <[email protected]>
11 #
12 # Provided that these terms and disclaimer and all copyright notices
13 # are retained or reproduced in an accompanying document, permission
14 # is granted to deal in this work without restriction, including un-
15 # limited rights to use, publicly perform, distribute, sell, modify,
16 # merge, give away, or sublicence.
17 #
18 # This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
19 # the utmost extent permitted by applicable law, neither express nor
20 # implied; without malicious intent or gross negligence. In no event
21 # may a licensor, author or contributor be held liable for indirect,
22 # direct, other damage, loss, or other issues arising in any way out
23 # of dealing in the work, even if advised of the possibility of such
24 # damage or existence of a defect, except proven that it results out
25 # of said person's immediate fault when using the work as intended.
26 #-
27 # People analysing the output must whitelist conftest.c for any kind
28 # of compiler warning checks (mirtoconf is by design not quiet).
29 #
30 # Used environment documentation is at the end of this file.
31
32 LC_ALL=C; LANGUAGE=C
33 export LC_ALL; unset LANGUAGE
34
35 use_ach=x; unset use_ach
36
37 case $ZSH_VERSION:$VERSION in
38 :zsh*) ZSH_VERSION=2 ;;
39 esac
40
41 if test -n "${ZSH_VERSION+x}" && (emulate sh) >/dev/null 2>&1; then
42 emulate sh
43 NULLCMD=:
44 fi
45
46 if test -d /usr/xpg4/bin/. >/dev/null 2>&1; then
47 # Solaris: some of the tools have weird behaviour, use portable ones
48 PATH=/usr/xpg4/bin:$PATH
49 export PATH
50 fi
51
52 test_tool() {
53 x=`echo $2 | $3`
54 y=$?
55
56 test x"$y" = x"0" && test x"$x" = x"$4" && return
57 echo >&2 "E: your $1 does not work correctly!"
58 echo >&2 "N: 'echo $2 | $3' exited $y and returned '$x'; expected '$4'"
59 echo >&2 'N: install a better one and prepend its location to $PATH'
60 exit 1
61 }
62 test_tool grep foobarbaz 'grep bar' foobarbaz
63 test_tool sed abc 'sed y/ac/AC/' AbC
64 test_tool tr abc 'tr ac AC' AbC
65
66 sp=' '
67 ht=' '
68 nl='
69 '
70 safeIFS="$sp$ht$nl"
71 IFS=$safeIFS
72 allu=QWERTYUIOPASDFGHJKLZXCVBNM
73 alll=qwertyuiopasdfghjklzxcvbnm
74 alln=0123456789
75 alls=______________________________________________________________
76
77 test_n() {
78 test x"$1" = x"" || return 0
79 return 1
80 }
81
82 test_z() {
83 test x"$1" = x""
84 }
85
86 case `echo a | tr '\201' X` in
87 X)
88 # EBCDIC build system
89 lfcr='\n\r'
90 ;;
91 *)
92 lfcr='\012\015'
93 ;;
94 esac
95
96 echo "For the build logs, demonstrate that /dev/null and /dev/tty exist:"
97 ls -l /dev/null /dev/tty
98 cat <<EOF
99 Flags on entry (plus HAVE_* which are not shown here):
100 - CC <$CC>
101 - CFLAGS <$CFLAGS>
102 - CPPFLAGS <$CPPFLAGS>
103 - LDFLAGS <$LDFLAGS>
104 - LIBS <$LIBS>
105 - LDSTATIC <$LDSTATIC>
106 - TARGET_OS <$TARGET_OS> TARGET_OSREV <$TARGET_OSREV>
107
108 EOF
109
110 v() {
111 $e "$*"
112 eval "$@"
113 }
114
115 vv() {
116 _c=$1
117 shift
118 $e "\$ $*" 2>&1
119 eval "$@" >vv.out 2>&1
120 sed "s^${_c} " <vv.out
121 }
122
123 vq() {
124 eval "$@"
125 }
126
127 rmf() {
128 for _f in "$@"; do
129 case $_f in
130 cpio.[1ch]|pax.[1ch]|tar.[1ch]) ;;
131 *) rm -f "$_f" ;;
132 esac
133 done
134 }
135
136 tcfn=no
137 bi=
138 ui=
139 ao=
140 fx=
141 me=`basename "$0"`
142 orig_CFLAGS=$CFLAGS
143 phase=x
144
145 if test -t 1; then
146 bi=''
147 ui=''
148 ao=''
149 fi
150
151 upper() {
152 echo :"$@" | sed 's/^://' | tr $alll $allu
153 }
154
155 # clean up after ac_testrun()
156 ac_testdone() {
157 eval HAVE_$fu=$fv
158 fr=no
159 test 0 = $fv || fr=yes
160 $e "$bi==> $fd...$ao $ui$fr$ao$fx"
161 fx=
162 }
163
164 # ac_cache label: sets f, fu, fv?=0
165 ac_cache() {
166 f=$1
167 fu=`upper $f`
168 eval fv=\$HAVE_$fu
169 case $fv in
170 0|1)
171 fx=' (cached)'
172 return 0
173 ;;
174 esac
175 fv=0
176 return 1
177 }
178
179 # ac_testinit label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput
180 # returns 1 if value was cached/implied, 0 otherwise: call ac_testdone
181 ac_testinit() {
182 if ac_cache $1; then
183 test x"$2" = x"!" && shift
184 test x"$2" = x"" || shift
185 fd=${3-$f}
186 ac_testdone
187 return 1
188 fi
189 fc=0
190 if test x"$2" = x""; then
191 ft=1
192 else
193 if test x"$2" = x"!"; then
194 fc=1
195 shift
196 fi
197 eval ft=\$HAVE_`upper $2`
198 if test_z "$ft"; then
199 echo >&2
200 echo >&2 "E: test $f depends on $2 which is not defined yet"
201 exit 255
202 fi
203 shift
204 fi
205 fd=${3-$f}
206 if test $fc = "$ft"; then
207 fv=$2
208 fx=' (implied)'
209 ac_testdone
210 return 1
211 fi
212 $e ... $fd
213 return 0
214 }
215
216 cat_h_blurb() {
217 echo '#ifdef MKSH_USE_AUTOCONF_H
218 /* things that “should” have been on the command line */
219 #include "autoconf.h"
220 #undef MKSH_USE_AUTOCONF_H
221 #endif
222
223 '
224 cat
225 }
226
227 # pipe .c | ac_test[n] [!] label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput
228 ac_testnndnd() {
229 if test x"$1" = x"!"; then
230 fr=1
231 shift
232 else
233 fr=0
234 fi
235 cat_h_blurb >conftest.c
236 ac_testinit "$@" || return 1
237 vv ']' "$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN conftest.c $LIBS $ccpr"
238 test $tcfn = no && test -f a.out && tcfn=a.out
239 test $tcfn = no && test -f a.exe && tcfn=a.exe
240 test $tcfn = no && test -f conftest.exe && tcfn=conftest.exe
241 test $tcfn = no && test -f conftest && tcfn=conftest
242 if test -f $tcfn; then
243 test 1 = $fr || fv=1
244 else
245 test 0 = $fr || fv=1
246 fi
247 vscan=
248 if test $phase = u; then
249 case $ct in
250 gcc*) vscan='unrecogni[sz]ed' ;;
251 hpcc) vscan='unsupported' ;;
252 pcc) vscan='unsupported' ;;
253 sunpro) vscan='-e ignored -e turned.off' ;;
254 esac
255 fi
256 test_n "$vscan" && grep $vscan vv.out >/dev/null 2>&1 && fv=$fr
257 return 0
258 }
259 ac_testn() {
260 if ac_testnndnd "$@"; then
261 rmf conftest.c conftest.o ${tcfn}* vv.out
262 ac_testdone
263 else
264 rm -f conftest.c
265 fi
266 }
267 ac_testnnd() {
268 if ac_testnndnd "$@"; then
269 ac_testdone
270 fi
271 }
272
273 # ac_ifcpp cppexpr [!] label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput
274 ac_ifcpp() {
275 expr=$1; shift
276 ac_testn "$@" <<-EOF
277 #include <unistd.h>
278 extern int thiswillneverbedefinedIhope(void);
279 int main(void) { return (isatty(0) +
280 #$expr
281 0
282 #else
283 /* force a failure: expr is false */
284 thiswillneverbedefinedIhope()
285 #endif
286 ); }
287 EOF
288 test x"$1" = x"!" && shift
289 f=$1
290 fu=`upper $f`
291 eval fv=\$HAVE_$fu
292 test x"$fv" = x"1"
293 }
294
295 addtoach() {
296 if echo "$1" >>autoconf.h; then
297 echo ">>> $1"
298 else
299 echo >&2 "E: could not write autoconf.h"
300 exit 255
301 fi
302 }
303
304 # simple only (is IFS-split by shell)
305 cpp_define() {
306 case $use_ach in
307 0)
308 add_cppflags "-D$1=$2"
309 ;;
310 1)
311 addtoach "#define $1 $2"
312 ;;
313 *)
314 echo >&2 "E: cpp_define() called too early!"
315 exit 255
316 ;;
317 esac
318 }
319
320 add_cppflags() {
321 CPPFLAGS="$CPPFLAGS $*"
322 }
323
324 ac_cppflags() {
325 test x"$1" = x"" || fu=$1
326 fv=$2
327 test x"$2" = x"" && eval fv=\$HAVE_$fu
328 cpp_define HAVE_$fu $fv
329 }
330
331 ac_test() {
332 ac_testn "$@"
333 ac_cppflags
334 }
335
336 # ac_flags [-] add varname cflags [text] [ldflags]
337 ac_flags() {
338 if test x"$1" = x"-"; then
339 shift
340 hf=1
341 else
342 hf=0
343 fi
344 fa=$1
345 vn=$2
346 f=$3
347 ft=$4
348 fl=$5
349 test x"$ft" = x"" && ft="if $f can be used"
350 save_CFLAGS=$CFLAGS
351 CFLAGS="$CFLAGS $f"
352 save_LDFLAGS=$LDFLAGS
353 test_z "$fl" || LDFLAGS="$LDFLAGS $fl"
354 if test 1 = $hf; then
355 ac_testn can_$vn '' "$ft"
356 else
357 ac_testn can_$vn '' "$ft" <<-'EOF'
358 /* evil apo'stroph in comment test */
359 #include <unistd.h>
360 int main(void) { int t[2]; return (isatty(pipe(t))); }
361 EOF
362 #'
363 fi
364 eval fv=\$HAVE_CAN_`upper $vn`
365 test_z "$fl" || test 11 = $fa$fv || LDFLAGS=$save_LDFLAGS
366 test 11 = $fa$fv || CFLAGS=$save_CFLAGS
367 }
368
369 # ac_header [!] header [prereq ...]
370 ac_header() {
371 if test x"$1" = x"!"; then
372 na=1
373 shift
374 else
375 na=0
376 fi
377 hf=$1; shift
378 hv=`echo "$hf" | tr -d "$lfcr" | tr -c $alll$allu$alln $alls`
379 echo "/* NeXTstep bug workaround */" >x
380 for i
381 do
382 case $i in
383 _time)
384 echo '#if HAVE_BOTH_TIME_H' >>x
385 echo '#include <sys/time.h>' >>x
386 echo '#include <time.h>' >>x
387 echo '#elif HAVE_SYS_TIME_H' >>x
388 echo '#include <sys/time.h>' >>x
389 echo '#elif HAVE_TIME_H' >>x
390 echo '#include <time.h>' >>x
391 echo '#endif' >>x
392 ;;
393 *)
394 echo "#include <$i>" >>x
395 ;;
396 esac
397 done
398 echo "#include <$hf>" >>x
399 echo '#include <unistd.h>' >>x
400 echo 'int main(void) { return (isatty(0)); }' >>x
401 ac_testn "$hv" "" "<$hf>" <x
402 rmf x
403 test 1 = $na || ac_cppflags
404 }
405
406 addsrcs() {
407 if test x"$1" = x"!"; then
408 fr=0
409 shift
410 else
411 fr=1
412 fi
413 eval i=\$$1
414 test $fr = "$i" && case "$sp$SRCS$sp" in
415 *"$sp$2$sp"*) ;;
416 *) SRCS="$SRCS$sp$2" ;;
417 esac
418 }
419
420 # --- main ---
421
422 curdir=`pwd` srcdir=`dirname "$0" 2>/dev/null`
423 curdisp=.
424 case x$curdir in
425 x)
426 curdir=.
427 ;;
428 *"$sp"*|*"$ht"*|*"$nl"*)
429 echo >&2 Current directory should not contain space or tab or newline.
430 echo >&2 Errors may occur.
431 ;;
432 *"'"*)
433 echo >&2 Current directory should not contain single quotes.
434 echo >&2 Errors may occur.
435 ;;
436 *)
437 curdisp=$curdir
438 ;;
439 esac
440 case x$srcdir in
441 x)
442 srcdir=.
443 ;;
444 *"$sp"*|*"$ht"*|*"$nl"*)
445 echo >&2 Source directory should not contain space or tab or newline.
446 echo >&2 Errors may occur.
447 ;;
448 *"'"*)
449 echo >&2 Source directory must not contain single quotes.
450 exit 1
451 ;;
452 esac
453 srcdisp=`cd "$srcdir" && pwd` || srcdisp=
454 test_n "$srcdisp" || srcdisp=$srcdir
455 if test x"$srcdisp" = x"$curdir"; then
456 srcdisp=
457 else
458 srcdisp=$srcdir/
459 fi
460 dstversion=`sed -n '/define MIRCPIO_VERSION/s/^.*"\([^"]*\)".*$/\1/p' "$srcdir/pax.h"`
461 whatlong='MirCPIO (paxmirabilis)'
462 whatshort=paxmirabilis
463
464 e=echo
465 r=0
466 eq=0
467 pm=0
468 cm=normal
469 Cg=
470 optflags=-std-compile-opts
471 last=
472 mans=0
473
474 for i
475 do
476 case $last:$i in
477 c:dragonegg|c:llvm)
478 cm=$i
479 last=
480 ;;
481 c:*)
482 echo "$me: Unknown option -c '$i'!" >&2
483 exit 1
484 ;;
485 o:*)
486 optflags=$i
487 last=
488 ;;
489 :-A)
490 rm -f autoconf.h
491 addtoach '/* work around NeXTstep bug */'
492 use_ach=1
493 add_cppflags -DMKSH_USE_AUTOCONF_H
494 ;;
495 :-c)
496 last=c
497 ;;
498 :-g)
499 # checker, debug, valgrind build
500 add_cppflags -DDEBUG
501 Cg=YES
502 ;;
503 :-j)
504 pm=1
505 ;;
506 :-M)
507 cm=makefile
508 ;;
509 :-O)
510 optflags=-std-compile-opts
511 ;;
512 :-o)
513 last=o
514 ;;
515 :-Q)
516 eq=1
517 ;;
518 :-r)
519 r=1
520 ;;
521 :-tmir)
522 mans=1
523 ;;
524 :-tpax)
525 mans=2
526 ;;
527 :-v)
528 echo "Build.sh $srcversion"
529 echo "for $whatlong $dstversion"
530 exit 0
531 ;;
532 :*)
533 echo "$me: Unknown option '$i'!" >&2
534 exit 1
535 ;;
536 *)
537 echo "$me: Unknown option -'$last' '$i'!" >&2
538 exit 1
539 ;;
540 esac
541 done
542 if test_n "$last"; then
543 echo "$me: Option -'$last' not followed by argument!" >&2
544 exit 1
545 fi
546
547 tfn=paxpax
548 case $mans in
549 0)
550 paxname=pax
551 cpioname=cpio
552 tarname=tar
553 ;;
554 1)
555 paxname=mirpax
556 cpioname=mircpio
557 tarname=mirtar
558 ;;
559 2)
560 paxname=pax
561 cpioname=paxcpio
562 tarname=paxtar
563 ;;
564 esac
565 if test -d $tfn || test -d $tfn.exe; then
566 echo "$me: Error: ./$tfn is a directory!" >&2
567 exit 1
568 fi
569 test x"$use_ach" = x"1" || use_ach=0
570 cpp_define MKSH_BUILDSH 1
571 rmf a.exe* a.out* conftest.* *core core.* ${tfn}* *.bc *.dbg *.ll *.o *.cat? \
572 *.gen Rebuild.sh Makefrag.inc lft no x vv.out
573 rm -rf mans
574
575 SRCS="ar.c ar_io.c ar_subs.c buf_subs.c compat.c cpio.c"
576 SRCS="$SRCS file_subs.c ftree.c gen_subs.c getoldopt.c options.c"
577 SRCS="$SRCS pat_rep.c pax.c sel_subs.c tables.c tar.c tty_subs.c"
578 add_cppflags -DMBSDPORT_H=\\\"compat.h\\\"
579
580 if test_z "$srcdisp"; then
581 CPPFLAGS="-I. $CPPFLAGS"
582 else
583 CPPFLAGS="-I. -I'$srcdir' $CPPFLAGS"
584 fi
585 test_z "$LDSTATIC" || if test_z "$LDFLAGS"; then
586 LDFLAGS=$LDSTATIC
587 else
588 LDFLAGS="$LDFLAGS $LDSTATIC"
589 fi
590
591 if test_z "$TARGET_OS"; then
592 x=`uname -s 2>/dev/null || uname`
593 case $x in
594 scosysv)
595 # SVR4 Unix with uname -s = uname -n, whitelist
596 TARGET_OS=$x
597 ;;
598 syllable)
599 # other OS with uname -s = uname = uname -n, whitelist
600 TARGET_OS=$x
601 ;;
602 *)
603 test x"$x" = x"`uname -n 2>/dev/null`" || TARGET_OS=$x
604 ;;
605 esac
606 fi
607 if test_z "$TARGET_OS"; then
608 echo "$me: Set TARGET_OS, your uname is broken!" >&2
609 exit 1
610 fi
611 osnote=
612 oswarn=
613 ccpc=-Wc,
614 ccpl=-Wl,
615 tsts=
616 ccpr='|| for _f in ${tcfn}*; do case $_f in cpio.[1ch]|pax.[1ch]|tar.[1ch]) ;; *) rm -f "$_f" ;; esac; done'
617
618 # Evil hack
619 if test x"$TARGET_OS" = x"Android"; then
620 TARGET_OS=Linux
621 fi
622
623 # Evil OS
624 if test x"$TARGET_OS" = x"Minix"; then
625 echo >&2 "
626 WARNING: additional checks before running Build.sh required!
627 You can avoid these by calling Build.sh correctly, see below.
628 "
629 cat_h_blurb >conftest.c <<'EOF'
630 #include <sys/types.h>
631 const char *
632 #ifdef _NETBSD_SOURCE
633 ct="Ninix3"
634 #else
635 ct="Minix3"
636 #endif
637 ;
638 EOF
639 ct=unknown
640 vv ']' "${CC-cc} -E $CFLAGS $Cg $CPPFLAGS $NOWARN conftest.c | grep ct= | tr -d \\\\015 >x"
641 sed 's/^/[ /' x
642 eval `cat x`
643 rmf x vv.out
644 case $ct in
645 Minix3|Ninix3)
646 echo >&2 "
647 Warning: you set TARGET_OS to $TARGET_OS but that is ambiguous.
648 Please set it to either Minix3 or Ninix3, whereas the latter is
649 all versions of Minix with even partial NetBSD(R) userland. The
650 value determined from your compiler for the current compilation
651 (which may be wrong) is: $ct
652 "
653 TARGET_OS=$ct
654 ;;
655 *)
656 echo >&2 "
657 Warning: you set TARGET_OS to $TARGET_OS but that is ambiguous.
658 Please set it to either Minix3 or Ninix3, whereas the latter is
659 all versions of Minix with even partial NetBSD(R) userland. The
660 proper value couldn't be determined, continue at your own risk.
661 "
662 ;;
663 esac
664 fi
665
666 # Configuration depending on OS revision, on OSes that need them
667 case $TARGET_OS in
668 NEXTSTEP)
669 test_n "$TARGET_OSREV" || TARGET_OSREV=`hostinfo 2>&1 | \
670 grep 'NeXT Mach [0-9][0-9.]*:' | \
671 sed 's/^.*NeXT Mach \([0-9][0-9.]*\):.*$/\1/'`
672 ;;
673 BeOS|HP-UX|QNX|SCO_SV)
674 test_n "$TARGET_OSREV" || TARGET_OSREV=`uname -r`
675 ;;
676 esac
677
678 # SVR4 (some) workaround
679 int_as_ssizet() {
680 cpp_define SSIZE_MIN INT_MIN
681 cpp_define SSIZE_MAX INT_MAX
682 cpp_define ssize_t int
683 }
684
685 cmplrflgs=
686
687 # Configuration depending on OS name
688 case $TARGET_OS in
689 386BSD)
690 osnote='; it is untested'
691 : "${HAVE_CAN_OTWO=0}"
692 ;;
693 4.4BSD)
694 osnote='; assuming BOW (BSD on Windows)'
695 ;;
696 A/UX)
697 oswarn='; it is untested'
698 add_cppflags -D_POSIX_SOURCE
699 : "${CC=gcc}"
700 : "${LIBS=-lposix}"
701 # GCC defines AUX but cc nothing
702 add_cppflags -D__A_UX__
703 ;;
704 AIX)
705 oswarn='; it is untested'
706 add_cppflags -D_ALL_SOURCE
707 ;;
708 BeOS)
709 oswarn='; it is untested'
710 : "${CC=gcc}"
711 ;;
712 BSD/OS)
713 osnote='; it is untested'
714 ;;
715 Coherent)
716 oswarn='; it is untested, possibly has major issues'
717 cpp_define MKSH__NO_SYMLINK 1
718 ;;
719 CYGWIN*)
720 # libc lacks dprintf but the headers declare it unless #define’d
721 cpp_define dprintf rpl_dprintf
722 ;;
723 Darwin)
724 osnote='; it is untested'
725 add_cppflags -D_DARWIN_C_SOURCE
726 ;;
727 DragonFly)
728 osnote='; it is untested'
729 ;;
730 FreeBSD)
731 osnote='; it is untested'
732 ;;
733 FreeMiNT)
734 oswarn='; it is untested'
735 add_cppflags -D_GNU_SOURCE
736 ;;
737 GNU)
738 osnote='; it is untested'
739 case $CC in
740 *tendracc*) ;;
741 *) add_cppflags -D_GNU_SOURCE ;;
742 esac
743 ;;
744 GNU/kFreeBSD)
745 osnote='; it is untested'
746 case $CC in
747 *tendracc*) ;;
748 *) add_cppflags -D_GNU_SOURCE ;;
749 esac
750 ;;
751 Haiku)
752 oswarn='; it is untested'
753 ;;
754 Harvey)
755 oswarn='; it is not ported'
756 add_cppflags -D_POSIX_SOURCE
757 add_cppflags -D_LIMITS_EXTENSION
758 add_cppflags -D_BSD_EXTENSION
759 add_cppflags -D_SUSV2_SOURCE
760 add_cppflags -D_GNU_SOURCE
761 cpp_define MKSH__NO_SYMLINK 1
762 ;;
763 HP-UX)
764 osnote='; it is untested'
765 case $TARGET_OSREV in
766 B.09.*)
767 : "${CC=c89}"
768 add_cppflags -D_HPUX_SOURCE
769 cpp_define MBSDINT_H_SMALL_SYSTEM 1
770 ;;
771 esac
772 ;;
773 Interix)
774 oswarn='; it is untested'
775 ccpc='-X '
776 ccpl='-Y '
777 add_cppflags -D_ALL_SOURCE
778 ;;
779 IRIX*)
780 osnote='; it is untested'
781 ;;
782 Jehanne)
783 oswarn='; it is not ported'
784 add_cppflags -D_POSIX_SOURCE
785 add_cppflags -D_LIMITS_EXTENSION
786 add_cppflags -D_BSD_EXTENSION
787 add_cppflags -D_SUSV2_SOURCE
788 add_cppflags -D_GNU_SOURCE
789 cpp_define MKSH__NO_SYMLINK 1
790 ;;
791 Linux)
792 case $CC in
793 *tendracc*) ;;
794 *) add_cppflags -D_GNU_SOURCE ;;
795 esac
796 ;;
797 LynxOS)
798 osnote='; it is untested'
799 ;;
800 midipix)
801 oswarn='; it is untested'
802 add_cppflags -D_GNU_SOURCE
803 ;;
804 MidnightBSD)
805 cpp_define _WITH_DPRINTF 1
806 cpp_define UT_NAMESIZE 32
807 ;;
808 Minix-vmd)
809 oswarn='; it is untested'
810 add_cppflags -D_MINIX_SOURCE
811 ;;
812 Minix3)
813 oswarn='; it is untested'
814 add_cppflags -D_POSIX_SOURCE -D_POSIX_1_SOURCE=2 -D_MINIX
815 ;;
816 Minoca)
817 oswarn='; it is untested'
818 : "${CC=gcc}"
819 ;;
820 MirBSD)
821 add_cppflags -D_ALL_SOURCE
822 ;;
823 MSYS_*)
824 osnote='; it is untested'
825 # broken on this OE (from ir0nh34d)
826 : "${HAVE_STDINT_H=0}"
827 ;;
828 NetBSD)
829 add_cppflags -D_NETBSD_SOURCE
830 add_cppflags -D_OPENBSD_SOURCE
831 ;;
832 NEXTSTEP)
833 oswarn='; it is untested'
834 add_cppflags -D_NEXT_SOURCE
835 add_cppflags -D_POSIX_SOURCE
836 : "${CC=cc -posix -traditional-cpp}"
837 ;;
838 Ninix3)
839 oswarn='; it is untested'
840 ;;
841 OpenBSD)
842 osnote='; it is untested'
843 ;;
844 OS/2)
845 oswarn='; it is not ported'
846 # cf. https://github.com/komh/pdksh-os2/commit/590f2b19b0ff92a9a373295bce914654f9f5bf22
847 HAVE_TERMIOS_H=0
848 : "${CC=gcc}"
849 : "${SIZE=: size}"
850 ;;
851 OS/390)
852 oswarn='; it is not ported'
853 osnote='; EBCDIC support missing'
854 : "${CC=xlc}"
855 : "${SIZE=: size}"
856 add_cppflags -D_ALL_SOURCE
857 ;;
858 OSF1)
859 oswarn='; it is untested'
860 add_cppflags -D_OSF_SOURCE
861 add_cppflags -D_POSIX_C_SOURCE=200112L
862 add_cppflags -D_XOPEN_SOURCE=600
863 add_cppflags -D_XOPEN_SOURCE_EXTENDED
864 ;;
865 Plan9)
866 oswarn='; it is not ported'
867 add_cppflags -D_POSIX_SOURCE
868 add_cppflags -D_LIMITS_EXTENSION
869 add_cppflags -D_BSD_EXTENSION
870 add_cppflags -D_SUSV2_SOURCE
871 cpp_define MKSH__NO_SYMLINK 1
872 # this is for detecting kencc
873 cmplrflgs=-DMKSH_MAYBE_KENCC
874 ;;
875 PW32*)
876 oswarn='; it is untested'
877 ;;
878 QNX)
879 oswarn='; it is untested'
880 add_cppflags -D__NO_EXT_QNX
881 add_cppflags -D__EXT_UNIX_MISC
882 ;;
883 scosysv)
884 oswarn='; it is untested'
885 cmplrflgs=-DMKSH_MAYBE_QUICK_C
886 int_as_ssizet
887 ;;
888 SCO_SV)
889 oswarn='; it is untested'
890 case $TARGET_OSREV in
891 3.2*)
892 # SCO OpenServer 5
893 ;;
894 5*)
895 # SCO OpenServer 6
896 ;;
897 *)
898 oswarn='; this is an unknown version of'
899 oswarn="$oswarn$nl$TARGET_OS ${TARGET_OSREV}, please tell me what to do"
900 ;;
901 esac
902 ;;
903 SerenityOS)
904 oswarn='; it is untested'
905 ;;
906 SINIX-Z)
907 : "${CC=cc -Xa}"
908 cmplrflgs=-DMKSH_MAYBE_SCDE
909 ;;
910 skyos)
911 oswarn='; it is untested'
912 ;;
913 SunOS)
914 oswarn='; it is untested'
915 add_cppflags -D_BSD_SOURCE
916 add_cppflags -D__EXTENSIONS__
917 ;;
918 syllable)
919 oswarn='; it is untested'
920 add_cppflags -D_GNU_SOURCE
921 ;;
922 ULTRIX)
923 oswarn='; it is untested'
924 : "${CC=cc -YPOSIX}"
925 int_as_ssizet
926 ;;
927 UnixWare|UNIX_SV)
928 # SCO UnixWare
929 oswarn='; it is untested'
930 ;;
931 UWIN*)
932 oswarn='; it is untested'
933 ccpc='-Yc,'
934 ccpl='-Yl,'
935 tsts=" 3<>/dev/tty"
936 ;;
937 XENIX)
938 oswarn='; it is untested'
939 # mostly when crosscompiling from scosysv
940 cmplrflgs=-DMKSH_MAYBE_QUICK_C
941 # this can barely do anything
942 int_as_ssizet
943 cpp_define MKSH__NO_SYMLINK 1
944 # these are broken
945 HAVE_TERMIOS_H=0
946 ;;
947 _svr4)
948 # generic target for SVR4 Unix with uname -s = uname -n
949 oswarn='; it may or may not work'
950 : "${CC=cc -Xa}"
951 cmplrflgs=-DMKSH_MAYBE_SCDE
952 int_as_ssizet #XXX maybe not for *all* _svr4? here for Dell UNIX
953 ;;
954 *)
955 oswarn='; it may or may not work'
956 ;;
957 esac
958 test_n "$TARGET_OSREV" || TARGET_OSREV=`uname -r`
959
960 : "${AWK=awk}${CC=cc}${NROFF=nroff}${SIZE=size}"
961 test 0 = $r && echo | $NROFF -v 2>&1 | grep GNU >/dev/null 2>&1 && \
962 echo | $NROFF -c >/dev/null 2>&1 && NROFF="$NROFF -c"
963
964 # this aids me in tracing FTBFSen without access to the buildd
965 $e "Hi from$ao $bi$srcversion$ao on:"
966 case $TARGET_OS in
967 AIX)
968 vv '|' "oslevel >&2"
969 vv '|' "uname -a >&2"
970 ;;
971 Darwin)
972 vv '|' "hwprefs machine_type os_type os_class >&2"
973 vv '|' "sw_vers >&2"
974 vv '|' "system_profiler -detailLevel mini SPSoftwareDataType SPHardwareDataType >&2"
975 vv '|' "/bin/sh --version >&2"
976 vv '|' "xcodebuild -version >&2"
977 vv '|' "uname -a >&2"
978 vv '|' "sysctl kern.version hw.machine hw.model hw.memsize hw.availcpu hw.ncpu hw.cpufrequency hw.byteorder hw.cpu64bit_capable >&2"
979 vv '|' "sysctl hw.cpufrequency hw.byteorder hw.cpu64bit_capable hw.ncpu >&2"
980 ;;
981 IRIX*)
982 vv '|' "uname -a >&2"
983 vv '|' "hinv -v >&2"
984 ;;
985 OSF1)
986 vv '|' "uname -a >&2"
987 vv '|' "/usr/sbin/sizer -v >&2"
988 ;;
989 scosysv|SCO_SV|UnixWare|UNIX_SV|XENIX)
990 vv '|' "uname -a >&2"
991 vv '|' "uname -X >&2"
992 ;;
993 *)
994 vv '|' "uname -a >&2"
995 ;;
996 esac
997 test_z "$oswarn" || echo >&2 "
998 Warning: $whatshort has not yet been ported to or tested on your
999 operating system '$TARGET_OS'$oswarn."
1000 test_z "$osnote" || echo >&2 "
1001 Note: $whatshort is not fully ported to or tested yet on your
1002 operating system '$TARGET_OS'$osnote."
1003 test_z "$osnote$oswarn" || echo >&2 "
1004 If you can provide a shell account to the developer, this
1005 may improve; please drop us a success or failure notice or
1006 even send patches for the remaining issues, or, at the very
1007 least, complete logs (Build.sh + test?) will help.
1008 "
1009 $e "$bi$me: Building $whatlong$ao $ui$dstversion$ao on $TARGET_OS ${TARGET_OSREV}..."
1010
1011 #
1012 # Start of mirtoconf checks
1013 #
1014 $e $bi$me: Scanning for functions... please ignore any errors.$ao
1015
1016 #
1017 # Compiler: which one?
1018 #
1019 # notes:
1020 # - ICC defines __GNUC__ too
1021 # - GCC defines __hpux too
1022 # - LLVM+clang defines __GNUC__ too
1023 # - nwcc defines __GNUC__ too
1024 CPP="$CC -E"
1025 $e ... which compiler type seems to be used
1026 cat_h_blurb >conftest.c <<'EOF'
1027 const char *
1028 #if defined(__ICC) || defined(__INTEL_COMPILER)
1029 ct="icc"
1030 #elif defined(__xlC__) || defined(__IBMC__)
1031 ct="xlc"
1032 #elif defined(__SUNPRO_C)
1033 ct="sunpro"
1034 #elif defined(__neatcc__)
1035 ct="neatcc"
1036 #elif defined(__lacc__)
1037 ct="lacc"
1038 #elif defined(__ACK__)
1039 ct="ack"
1040 #elif defined(__BORLANDC__)
1041 ct="bcc"
1042 #elif defined(__WATCOMC__)
1043 ct="watcom"
1044 #elif defined(__MWERKS__)
1045 ct="metrowerks"
1046 #elif defined(__HP_cc)
1047 ct="hpcc"
1048 #elif defined(__DECC) || (defined(__osf__) && !defined(__GNUC__))
1049 ct="dec"
1050 #elif defined(__PGI)
1051 ct="pgi"
1052 #elif defined(__DMC__)
1053 ct="dmc"
1054 #elif defined(_MSC_VER)
1055 ct="msc"
1056 #elif defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__)
1057 ct="adsp"
1058 #elif defined(__IAR_SYSTEMS_ICC__)
1059 ct="iar"
1060 #elif defined(SDCC)
1061 ct="sdcc"
1062 #elif defined(__PCC__)
1063 ct="pcc"
1064 #elif defined(__TenDRA__)
1065 ct="tendra"
1066 #elif defined(__TINYC__)
1067 ct="tcc"
1068 #elif defined(__llvm__) && defined(__clang__)
1069 ct="clang"
1070 #elif defined(__NWCC__)
1071 ct="nwcc"
1072 #elif defined(__GNUC__) && (__GNUC__ < 2)
1073 ct="gcc1"
1074 #elif defined(__GNUC__)
1075 ct="gcc"
1076 #elif defined(_COMPILER_VERSION)
1077 ct="mipspro"
1078 #elif defined(__sgi)
1079 ct="mipspro"
1080 #elif defined(__hpux) || defined(__hpua)
1081 ct="hpcc"
1082 #elif defined(__ultrix)
1083 ct="ucode"
1084 #elif defined(__USLC__)
1085 ct="uslc"
1086 #elif defined(__LCC__)
1087 ct="lcc"
1088 #elif defined(MKSH_MAYBE_QUICK_C) && defined(_M_BITFIELDS)
1089 ct="quickc"
1090 #elif defined(MKSH_MAYBE_KENCC)
1091 /* and none of the above matches */
1092 ct="kencc"
1093 #elif defined(MKSH_MAYBE_SCDE)
1094 ct="tryscde"
1095 #else
1096 ct="unknown"
1097 #endif
1098 ;
1099 const char *
1100 #if defined(__KLIBC__) && !defined(__OS2__)
1101 et="klibc"
1102 #elif defined(__dietlibc__)
1103 et="dietlibc"
1104 #else
1105 et="unknown"
1106 #endif
1107 ;
1108 EOF
1109 ct=untested
1110 et=untested
1111 vv ']' "$CPP $CFLAGS $CPPFLAGS $NOWARN $cmplrflgs conftest.c | \
1112 sed -n '/^ *[ce]t *= */s/^ *\([ce]t\) *= */\1=/p' | tr -d \\\\015 >x"
1113 sed 's/^/[ /' x
1114 eval `cat x`
1115 rmf x vv.out
1116 cat_h_blurb >conftest.c <<'EOF'
1117 #include <unistd.h>
1118 int main(void) { return (isatty(0)); }
1119 EOF
1120 test_z "$Cg" || Cg=-g # generic
1121 case $ct:$TARGET_OS in
1122 tryscde:*)
1123 case `LC_ALL=C; export LC_ALL; $CC -V 2>&1` in
1124 *'Standard C Development Environment'*)
1125 ct=scde ;;
1126 *)
1127 ct=unknown ;;
1128 esac
1129 ;;
1130 esac
1131 case $ct in
1132 ack)
1133 # work around "the famous ACK const bug"
1134 CPPFLAGS="-Dconst= $CPPFLAGS"
1135 : "${HAVE_ATTRIBUTE_EXTENSION=0}" # skip checking as we know it absent
1136 ;;
1137 adsp)
1138 echo >&2 'Warning: Analog Devices C++ compiler for Blackfin, TigerSHARC
1139 and SHARC (21000) DSPs detected. This compiler has not yet
1140 been tested for compatibility with this. Continue at your
1141 own risk, please report success/failure to the developers.'
1142 ;;
1143 bcc)
1144 echo >&2 "Warning: Borland C++ Builder detected. This compiler might
1145 produce broken executables. Continue at your own risk,
1146 please report success/failure to the developers."
1147 ;;
1148 clang)
1149 # does not work with current "ccc" compiler driver
1150 vv '|' "$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN $LIBS --version"
1151 # one of these two works, for now
1152 vv '|' "${CLANG-clang} -version"
1153 # ensure compiler and linker are in sync unless overridden
1154 case $CCC_CC:$CCC_LD in
1155 :*) ;;
1156 *:) CCC_LD=$CCC_CC; export CCC_LD ;;
1157 esac
1158 ;;
1159 dec)
1160 vv '|' "$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V"
1161 vv '|' "$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN -Wl,-V conftest.c $LIBS"
1162 : "${HAVE_ATTRIBUTE_EXTENSION=0}" # skip checking as we know it absent
1163 ;;
1164 dmc)
1165 echo >&2 "Warning: Digital Mars Compiler detected. When running under"
1166 echo >&2 " UWIN, mksh tends to be unstable due to the limitations"
1167 echo >&2 " of this platform. Continue at your own risk,"
1168 echo >&2 " please report success/failure to the developers."
1169 ;;
1170 gcc1)
1171 vv '|' "$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS"
1172 vv '|' 'eval echo "\`$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN $LIBS -dumpmachine\`" \
1173 "gcc\`$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN $LIBS -dumpversion\`"'
1174 : "${HAVE_ATTRIBUTE_EXTENSION=0}" # false positive
1175 ;;
1176 gcc)
1177 test_z "$Cg" || Cg='-g3 -fno-builtin'
1178 vv '|' "$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS"
1179 vv '|' 'eval echo "\`$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN $LIBS -dumpmachine\`" \
1180 "gcc\`$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN $LIBS -dumpversion\`"'
1181 ;;
1182 hpcc)
1183 vv '|' "$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
1184 case $TARGET_OS,$TARGET_OSREV in
1185 HP-UX,B.09.*)
1186 : "${HAVE_ATTRIBUTE_EXTENSION=0}"
1187 ;;
1188 esac
1189 ;;
1190 iar)
1191 echo >&2 'Warning: IAR Systems (http://www.iar.com) compiler for embedded
1192 systems detected. This unsupported compiler has not yet
1193 been tested for compatibility with this. Continue at your
1194 own risk, please report success/failure to the developers.'
1195 ;;
1196 icc)
1197 vv '|' "$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V"
1198 ;;
1199 kencc)
1200 vv '|' "$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS"
1201 : "${HAVE_ATTRIBUTE_EXTENSION=0}" # skip checking as we know it absent
1202 ;;
1203 lacc)
1204 # no version information
1205 ;;
1206 lcc)
1207 vv '|' "$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS"
1208 cpp_define __inline__ __inline
1209 : "${HAVE_ATTRIBUTE_EXTENSION=0}" # skip checking as we know it absent
1210 ;;
1211 metrowerks)
1212 echo >&2 'Warning: Metrowerks C compiler detected. This has not yet
1213 been tested for compatibility with this. Continue at your
1214 own risk, please report success/failure to the developers.'
1215 ;;
1216 mipspro)
1217 test_z "$Cg" || Cg='-g3'
1218 vv '|' "$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN $LIBS -version"
1219 : "${HAVE_STDINT_H=0}" # broken unless building with __c99
1220 : "${HAVE_ATTRIBUTE_EXTENSION=0}" # skip checking as we know it absent
1221 ;;
1222 msc)
1223 ccpr= # errorlevels are not reliable
1224 case $TARGET_OS in
1225 Interix)
1226 if test_z "$C89_COMPILER"; then
1227 C89_COMPILER=CL.EXE
1228 else
1229 C89_COMPILER=`ntpath2posix -c "$C89_COMPILER"`
1230 fi
1231 if test_z "$C89_LINKER"; then
1232 C89_LINKER=LINK.EXE
1233 else
1234 C89_LINKER=`ntpath2posix -c "$C89_LINKER"`
1235 fi
1236 vv '|' "$C89_COMPILER /HELP >&2"
1237 vv '|' "$C89_LINKER /LINK >&2"
1238 ;;
1239 esac
1240 ;;
1241 neatcc)
1242 cpp_define MKSH_DONT_EMIT_IDSTRING 1
1243 vv '|' "$CC"
1244 ;;
1245 nwcc)
1246 vv '|' "$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN $LIBS -version"
1247 ;;
1248 pcc)
1249 vv '|' "$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN $LIBS -v"
1250 ;;
1251 pgi)
1252 echo >&2 'Warning: PGI detected. This unknown compiler has not yet
1253 been tested for compatibility with this. Continue at your
1254 own risk, please report success/failure to the developers.'
1255 ;;
1256 quickc)
1257 # no version information
1258 : "${HAVE_ATTRIBUTE_EXTENSION=0}" # skip checking as we know it absent
1259 ;;
1260 scde)
1261 vv '|' "$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
1262 : "${HAVE_ATTRIBUTE_EXTENSION=0}" # skip checking as we know it absent
1263 ;;
1264 sdcc)
1265 echo >&2 'Warning: sdcc (http://sdcc.sourceforge.net), the small devices
1266 C compiler for embedded systems detected. This has not yet
1267 been tested for compatibility with this. Continue at your
1268 own risk, please report success/failure to the developers.'
1269 ;;
1270 sunpro)
1271 vv '|' "$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
1272 ;;
1273 tcc)
1274 vv '|' "$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN $LIBS -v"
1275 ;;
1276 tendra)
1277 vv '|' "$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V 2>&1 | \
1278 grep -i -e version -e release"
1279 : "${HAVE_ATTRIBUTE_EXTENSION=0}" # false positive
1280 ;;
1281 ucode)
1282 vv '|' "$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V"
1283 vv '|' "$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN -Wl,-V conftest.c $LIBS"
1284 : "${HAVE_ATTRIBUTE_EXTENSION=0}" # skip checking as we know it absent
1285 ;;
1286 uslc)
1287 case $TARGET_OS:$TARGET_OSREV in
1288 SCO_SV:3.2*)
1289 # SCO OpenServer 5
1290 CFLAGS="$CFLAGS -g"
1291 : "${HAVE_CAN_OTWO=0}${HAVE_CAN_OPTIMISE=0}"
1292 ;;
1293 esac
1294 vv '|' "$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
1295 : "${HAVE_ATTRIBUTE_EXTENSION=0}" # skip checking as we know it absent
1296 ;;
1297 watcom)
1298 vv '|' "$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS"
1299 ;;
1300 xlc)
1301 vv '|' "$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN $LIBS -qversion"
1302 vv '|' "$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN $LIBS -qversion=verbose"
1303 vv '|' "ld -V"
1304 ;;
1305 *)
1306 test x"$ct" = x"untested" && $e "!!! detecting preprocessor failed"
1307 ct=unknown
1308 vv '|' "$CC --version"
1309 vv '|' "$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS"
1310 vv '|' "$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
1311 ;;
1312 esac
1313 case $cm in
1314 dragonegg|llvm)
1315 vv '|' "llc -version"
1316 ;;
1317 esac
1318 etd=" on $et"
1319 # still imake style but… can’t be helped
1320 case $et in
1321 dietlibc)
1322 # live, BSD, live❣
1323 #add_cppflags -D_BSD_SOURCE
1324 # dietlibc has u_long as uint32_t in many versions, ouch,
1325 # but thankfully ifdef _BSD_SOURCE, so… ouch²…
1326 add_cppflags -U_BSD_SOURCE
1327 : "${HAVE_CAN_ULONG=0}"
1328 ;;
1329 klibc)
1330 ;;
1331 unknown)
1332 # nothing special detected, don’t worry
1333 etd=
1334 ;;
1335 *)
1336 # huh?
1337 ;;
1338 esac
1339 $e "$bi==> which compiler type seems to be used...$ao $ui$ct$etd$ao"
1340 rmf conftest.c conftest.o conftest a.out* a.exe* conftest.exe* vv.out
1341
1342 #
1343 # Compiler: works as-is, with -Wno-error and -Werror
1344 #
1345 save_NOWARN=$NOWARN
1346 NOWARN=
1347 DOWARN=
1348 ac_flags 0 compiler_works '' 'if the compiler works'
1349 test 1 = $HAVE_CAN_COMPILER_WORKS || exit 1
1350 HAVE_COMPILER_KNOWN=0
1351 test $ct = unknown || HAVE_COMPILER_KNOWN=1
1352 if ac_ifcpp 'if 0' compiler_fails '' \
1353 'if the compiler does not fail correctly'; then
1354 save_CFLAGS=$CFLAGS
1355 : "${HAVE_CAN_DELEXE=x}"
1356 case $ct in
1357 dec)
1358 CFLAGS="$CFLAGS ${ccpl}-non_shared"
1359 ac_testn can_delexe compiler_fails 0 'for the -non_shared linker option' <<-'EOF'
1360 #include <unistd.h>
1361 int main(void) { return (isatty(0)); }
1362 EOF
1363 ;;
1364 dmc)
1365 CFLAGS="$CFLAGS ${ccpl}/DELEXECUTABLE"
1366 ac_testn can_delexe compiler_fails 0 'for the /DELEXECUTABLE linker option' <<-'EOF'
1367 #include <unistd.h>
1368 int main(void) { return (isatty(0)); }
1369 EOF
1370 ;;
1371 *)
1372 exit 1
1373 ;;
1374 esac
1375 test 1 = $HAVE_CAN_DELEXE || CFLAGS=$save_CFLAGS
1376 ac_ifcpp 'if 0' compiler_still_fails \
1377 'if the compiler still does not fail correctly' && exit 1
1378 fi
1379 if ac_ifcpp 'ifdef __TINYC__' couldbe_tcc '!' compiler_known 0 \
1380 'if this could be tcc'; then
1381 ct=tcc
1382 CPP='cpp -D__TINYC__'
1383 HAVE_COMPILER_KNOWN=1
1384 fi
1385
1386 case $ct in
1387 bcc)
1388 save_NOWARN="${ccpc}-w"
1389 DOWARN="${ccpc}-w!"
1390 ;;
1391 dec)
1392 # -msg_* flags not used yet, or is -w2 correct?
1393 ;;
1394 dmc)
1395 save_NOWARN="${ccpc}-w"
1396 DOWARN="${ccpc}-wx"
1397 ;;
1398 hpcc)
1399 save_NOWARN=
1400 DOWARN=+We
1401 ;;
1402 kencc)
1403 save_NOWARN=
1404 DOWARN=
1405 ;;
1406 mipspro)
1407 save_NOWARN=
1408 DOWARN="-diag_error 1-10000"
1409 ;;
1410 msc)
1411 save_NOWARN="${ccpc}/w"
1412 DOWARN="${ccpc}/WX"
1413 ;;
1414 quickc)
1415 ;;
1416 scde)
1417 ;;
1418 sunpro)
1419 test x"$save_NOWARN" = x"" && save_NOWARN='-errwarn=%none'
1420 ac_flags 0 errwarnnone "$save_NOWARN"
1421 test 1 = $HAVE_CAN_ERRWARNNONE || save_NOWARN=
1422 ac_flags 0 errwarnall "-errwarn=%all"
1423 test 1 = $HAVE_CAN_ERRWARNALL && DOWARN="-errwarn=%all"
1424 ;;
1425 tendra)
1426 save_NOWARN=-w
1427 ;;
1428 ucode)
1429 save_NOWARN=
1430 DOWARN=-w2
1431 ;;
1432 watcom)
1433 save_NOWARN=
1434 DOWARN=-Wc,-we
1435 ;;
1436 xlc)
1437 case $TARGET_OS in
1438 OS/390)
1439 save_NOWARN=-qflag=e
1440 DOWARN=-qflag=i
1441 ;;
1442 *)
1443 save_NOWARN=-qflag=i:e
1444 DOWARN=-qflag=i:i
1445 ;;
1446 esac
1447 ;;
1448 *)
1449 test x"$save_NOWARN" = x"" && save_NOWARN=-Wno-error
1450 ac_flags 0 wnoerror "$save_NOWARN"
1451 test 1 = $HAVE_CAN_WNOERROR || save_NOWARN=
1452 ac_flags 0 werror -Werror
1453 test 1 = $HAVE_CAN_WERROR && DOWARN=-Werror
1454 test $ct = icc && DOWARN="$DOWARN -wd1419"
1455 ;;
1456 esac
1457 NOWARN=$save_NOWARN
1458
1459 #
1460 # Compiler: extra flags (-O2 -f* -W* etc.)
1461 #
1462 i=`echo :"$orig_CFLAGS" | sed 's/^://' | tr -c -d $alll$allu$alln`
1463 # optimisation: only if orig_CFLAGS is empty
1464 test_n "$i" || case $ct in
1465 hpcc)
1466 phase=u
1467 ac_flags 1 otwo +O2
1468 phase=x
1469 ;;
1470 kencc|quickc|scde|tcc|tendra)
1471 # no special optimisation
1472 ;;
1473 sunpro)
1474 cat >x <<-'EOF'
1475 #include <unistd.h>
1476 int main(void) { return (isatty(0)); }
1477 #define __IDSTRING_CONCAT(l,p) __LINTED__ ## l ## _ ## p
1478 #define __IDSTRING_EXPAND(l,p) __IDSTRING_CONCAT(l,p)
1479 #define pad void __IDSTRING_EXPAND(__LINE__,x)(void) { }
1480 EOF
1481 yes pad | head -n 256 >>x
1482 ac_flags - 1 otwo -xO2 <x
1483 rmf x
1484 ;;
1485 xlc)
1486 ac_flags 1 othree "-O3 -qstrict"
1487 test 1 = $HAVE_CAN_OTHREE || ac_flags 1 otwo -O2
1488 ;;
1489 *)
1490 if test_n "$Cg"; then
1491 ac_flags 1 ogee -Og
1492 if test 1 = $HAVE_CAN_OGEE; then
1493 HAVE_CAN_OTWO=1 # for below
1494 else
1495 ac_flags 1 otwo -O2
1496 fi
1497 else
1498 ac_flags 1 otwo -O2
1499 fi
1500 test 1 = $HAVE_CAN_OTWO || ac_flags 1 optimise -O
1501 ;;
1502 esac
1503 # other flags: just add them if they are supported
1504 i=0
1505 case $ct in
1506 bcc)
1507 ac_flags 1 strpool "${ccpc}-d" 'if string pooling can be enabled'
1508 ;;
1509 clang)
1510 i=1
1511 ;;
1512 dec)
1513 ac_flags 0 verb -verbose
1514 ac_flags 1 rodata -readonly_strings
1515 ;;
1516 dmc)
1517 ac_flags 1 decl "${ccpc}-r" 'for strict prototype checks'
1518 ac_flags 1 schk "${ccpc}-s" 'for stack overflow checking'
1519 ;;
1520 gcc1)
1521 # The following tests run with -Werror (gcc only) if possible
1522 NOWARN=$DOWARN; phase=u
1523 ac_flags 1 wnodeprecateddecls -Wno-deprecated-declarations
1524 # we do not even use CFrustFrust in MirBSD so don’t code in it…
1525 ac_flags 1 no_eh_frame -fno-asynchronous-unwind-tables
1526 ac_flags 1 fnostrictaliasing -fno-strict-aliasing
1527 ac_flags 1 data_abi_align -malign-data=abi
1528 i=1
1529 ;;
1530 gcc)
1531 ac_flags 1 fnolto -fno-lto 'whether we can explicitly disable buggy GCC LTO' -fno-lto
1532 # The following tests run with -Werror (gcc only) if possible
1533 NOWARN=$DOWARN; phase=u
1534 ac_flags 1 wnodeprecateddecls -Wno-deprecated-declarations
1535 # we do not even use CFrustFrust in MirBSD so don’t code in it…
1536 ac_flags 1 no_eh_frame -fno-asynchronous-unwind-tables
1537 ac_flags 1 fnostrictaliasing -fno-strict-aliasing
1538 ac_flags 1 fstackprotectorstrong -fstack-protector-strong
1539 test 1 = $HAVE_CAN_FSTACKPROTECTORSTRONG || \
1540 ac_flags 1 fstackprotectorall -fstack-protector-all
1541 test $cm = dragonegg && case " $CC $CFLAGS $Cg $LDFLAGS " in
1542 *\ -fplugin=*dragonegg*) ;;
1543 *) ac_flags 1 fplugin_dragonegg -fplugin=dragonegg ;;
1544 esac
1545 case $cm in
1546 combine)
1547 fv=0
1548 checks='7 8'
1549 ;;
1550 lto)
1551 fv=0
1552 checks='1 2 3 4 5 6 7 8'
1553 ;;
1554 *)
1555 fv=1
1556 ;;
1557 esac
1558 test $fv = 1 || for what in $checks; do
1559 test $fv = 1 && break
1560 case $what in
1561 1) t_cflags='-flto=jobserver'
1562 t_ldflags='-fuse-linker-plugin'
1563 t_use=1 t_name=fltojs_lp ;;
1564 2) t_cflags='-flto=jobserver' t_ldflags=''
1565 t_use=1 t_name=fltojs_nn ;;
1566 3) t_cflags='-flto=jobserver'
1567 t_ldflags='-fno-use-linker-plugin -fwhole-program'
1568 t_use=1 t_name=fltojs_np ;;
1569 4) t_cflags='-flto'
1570 t_ldflags='-fuse-linker-plugin'
1571 t_use=1 t_name=fltons_lp ;;
1572 5) t_cflags='-flto' t_ldflags=''
1573 t_use=1 t_name=fltons_nn ;;
1574 6) t_cflags='-flto'
1575 t_ldflags='-fno-use-linker-plugin -fwhole-program'
1576 t_use=1 t_name=fltons_np ;;
1577 7) t_cflags='-fwhole-program --combine' t_ldflags=''
1578 t_use=0 t_name=combine cm=combine ;;
1579 8) fv=1 cm=normal ;;
1580 esac
1581 test $fv = 1 && break
1582 ac_flags $t_use $t_name "$t_cflags" \
1583 "if gcc supports $t_cflags $t_ldflags" "$t_ldflags"
1584 done
1585 ac_flags 1 data_abi_align -malign-data=abi
1586 i=1
1587 ;;
1588 hpcc)
1589 phase=u
1590 # probably not needed
1591 #ac_flags 1 agcc -Agcc 'for support of GCC extensions'
1592 phase=x
1593 ;;
1594 icc)
1595 ac_flags 1 fnobuiltinsetmode -fno-builtin-setmode
1596 ac_flags 1 fnostrictaliasing -fno-strict-aliasing
1597 ac_flags 1 fstacksecuritycheck -fstack-security-check
1598 i=1
1599 ;;
1600 mipspro)
1601 ac_flags 1 fullwarn -fullwarn 'for remark output support'
1602 ;;
1603 msc)
1604 ac_flags 1 strpool "${ccpc}/GF" 'if string pooling can be enabled'
1605 echo 'int main(void) { char test[64] = ""; return (*test); }' >x
1606 ac_flags - 1 stackon "${ccpc}/GZ" 'if stack checks can be enabled' <x
1607 ac_flags - 1 stckall "${ccpc}/Ge" 'stack checks for all functions' <x
1608 ac_flags - 1 secuchk "${ccpc}/GS" 'for compiler security checks' <x
1609 rmf x
1610 ac_flags 1 wall "${ccpc}/Wall" 'to enable all warnings'
1611 ac_flags 1 wp64 "${ccpc}/Wp64" 'to enable 64-bit warnings'
1612 ;;
1613 nwcc)
1614 #broken# ac_flags 1 ssp -stackprotect
1615 i=1
1616 ;;
1617 pcc)
1618 ac_flags 1 fstackprotectorall -fstack-protector-all
1619 i=1
1620 ;;
1621 sunpro)
1622 phase=u
1623 ac_flags 1 v -v
1624 ac_flags 1 ipo -xipo 'for cross-module optimisation'
1625 phase=x
1626 ;;
1627 tcc)
1628 : #broken# ac_flags 1 boundschk -b
1629 ;;
1630 tendra)
1631 ac_flags 0 ysystem -Ysystem
1632 test 1 = $HAVE_CAN_YSYSTEM && CPPFLAGS="-Ysystem $CPPFLAGS"
1633 ac_flags 1 extansi -Xa
1634 ;;
1635 xlc)
1636 case $TARGET_OS in
1637 OS/390)
1638 # On IBM z/OS, the following are warnings by default:
1639 # CCN3296: #include file <foo.h> not found.
1640 # CCN3944: Attribute "__foo__" is not supported and is ignored.
1641 # CCN3963: The attribute "foo" is not a valid variable attribute and is ignored.
1642 ac_flags 1 halton '-qhaltonmsg=CCN3296 -qhaltonmsg=CCN3944 -qhaltonmsg=CCN3963'
1643 # CCN3290: Unknown macro name FOO on #undef directive.
1644 # CCN4108: The use of keyword '__attribute__' is non-portable.
1645 ac_flags 1 supprss '-qsuppress=CCN3290 -qsuppress=CCN4108'
1646 ;;
1647 *)
1648 ac_flags 1 rodata '-qro -qroconst -qroptr'
1649 ac_flags 1 rtcheck -qcheck=all
1650 #ac_flags 1 rtchkc -qextchk # reported broken
1651 ac_flags 1 wformat '-qformat=all -qformat=nozln'
1652 ;;
1653 esac
1654 #ac_flags 1 wp64 -qwarn64 # too verbose for now
1655 ;;
1656 esac
1657 # flags common to a subset of compilers (run with -Werror on gcc)
1658 if test 1 = $i; then
1659 ac_flags 1 wall -Wall
1660 ac_flags 1 fwrapv -fwrapv
1661 fi
1662
1663 phase=x
1664 # The following tests run with -Werror or similar (all compilers) if possible
1665 NOWARN=$DOWARN
1666 test $ct = pcc && phase=u
1667
1668 #
1669 # Compiler: check for stuff that only generates warnings
1670 #
1671 : "${HAVE_ATTRIBUTE_EXTENSION=1}" # not a separate test but a dependency
1672 ac_test attribute_bounded attribute_extension 0 'for __attribute__((__bounded__))' <<-'EOF'
1673 #include <string.h>
1674 #undef __attribute__
1675 int xcopy(const void *, void *, size_t)
1676 __attribute__((__bounded__(__buffer__, 1, 3)))
1677 __attribute__((__bounded__(__buffer__, 2, 3)));
1678 int main(int ac, char *av[]) { return (xcopy(av[0], av[--ac], 1)); }
1679 int xcopy(const void *s, void *d, size_t n) {
1680 /*
1681 * if memmove does not exist, we are not on a system
1682 * with GCC with __bounded__ attribute either so poo
1683 */
1684 memmove(d, s, n); return ((int)n);
1685 }
1686 EOF
1687 ac_test attribute_format attribute_extension 0 'for __attribute__((__format__))' <<-'EOF'
1688 #define fprintf printfoo
1689 #include <stdio.h>
1690 #undef __attribute__
1691 #undef fprintf
1692 extern int fprintf(FILE *, const char *format, ...)
1693 __attribute__((__format__(__printf__, 2, 3)));
1694 int main(int ac, char *av[]) { return (fprintf(stderr, "%s%d", *av, ac)); }
1695 EOF
1696 ac_test attribute_nonnull attribute_extension 0 'for __attribute__((__nonnull__))' <<-'EOF'
1697 #include <stdio.h>
1698 #undef __attribute__
1699 int fnord(const char *) __attribute__((__nonnull__(1)));
1700 int main(void) { return (fnord("x")); }
1701 int fnord(const char *x) { return (fputc(*x, stderr)); }
1702 EOF
1703 ac_test attribute_noreturn attribute_extension 0 'for __attribute__((__noreturn__))' <<-'EOF'
1704 #include <stdlib.h>
1705 #undef __attribute__
1706 void fnord(void) __attribute__((__noreturn__));
1707 int main(void) { fnord(); }
1708 void fnord(void) { exit(0); }
1709 EOF
1710 ac_test attribute_pure attribute_extension 0 'for __attribute__((__pure__))' <<-'EOF'
1711 #include <unistd.h>
1712 #undef __attribute__
1713 int foo(const char *) __attribute__((__pure__));
1714 int main(int ac, char *av[]) { return (foo(av[ac - 1]) + isatty(0)); }
1715 int foo(const char *s) { return ((int)s[0]); }
1716 EOF
1717 ac_test attribute_unused attribute_extension 0 'for __attribute__((__unused__))' <<-'EOF'
1718 #include <unistd.h>
1719 #undef __attribute__
1720 int main(int ac __attribute__((__unused__)), char *av[]
1721 __attribute__((__unused__))) { return (isatty(0)); }
1722 EOF
1723 ac_test attribute_used attribute_extension 0 'for __attribute__((__used__))' <<-'EOF'
1724 #include <unistd.h>
1725 #undef __attribute__
1726 static const char fnord[] __attribute__((__used__)) = "42";
1727 int main(void) { return (isatty(0)); }
1728 EOF
1729
1730 # End of tests run with -Werror
1731 NOWARN=$save_NOWARN
1732 phase=x
1733
1734 #
1735 # Environment: headers
1736 #
1737 ac_header sys/time.h sys/types.h
1738 ac_header time.h sys/types.h
1739 test "11" = "$HAVE_SYS_TIME_H$HAVE_TIME_H" || HAVE_BOTH_TIME_H=0
1740 ac_test both_time_h '' 'whether <sys/time.h> and <time.h> can both be included' <<-'EOF'
1741 #include <sys/types.h>
1742 #include <sys/time.h>
1743 #include <time.h>
1744 #include <unistd.h>
1745 int main(void) { struct tm tm; return ((int)sizeof(tm) + isatty(0)); }
1746 EOF
1747 ac_header sys/mkdev.h sys/types.h
1748 ac_header sys/mtio.h sys/types.h
1749 ac_header sys/resource.h sys/types.h _time
1750 ac_header sys/sysmacros.h
1751 ac_header grp.h sys/types.h
1752 ac_header paths.h
1753 ac_header stdint.h stdarg.h
1754 # include strings.h only if compatible with string.h
1755 ac_header strings.h sys/types.h string.h
1756 ac_header utime.h _time
1757 ac_header utmp.h _time
1758 ac_header utmpx.h _time
1759 ac_header vis.h stdlib.h
1760
1761 #
1762 # Environment: definitions
1763 #
1764 echo '#include <sys/types.h>
1765 #include <fts.h>
1766 #include <unistd.h>
1767 struct ctassert_offt {
1768 off_t min63bits:63;
1769 };
1770 int main(void) { return ((int)sizeof(struct ctassert_offt)); }' >lft.c
1771 ac_testn can_lfs '' "for large file support" <lft.c
1772 save_CPPFLAGS=$CPPFLAGS
1773 add_cppflags -D_FILE_OFFSET_BITS=64
1774 ac_testn can_lfs_sus '!' can_lfs 0 "... with -D_FILE_OFFSET_BITS=64" <lft.c
1775 if test 0 = $HAVE_CAN_LFS_SUS; then
1776 CPPFLAGS=$save_CPPFLAGS
1777 add_cppflags -D_LARGE_FILES=1
1778 ac_testn can_lfs_aix '!' can_lfs 0 "... with -D_LARGE_FILES=1" <lft.c
1779 test 1 = $HAVE_CAN_LFS_AIX || CPPFLAGS=$save_CPPFLAGS
1780 fi
1781 rm -f lft.c
1782 rmf lft* # end of large file support test
1783
1784 #
1785 # Environment: types
1786 #
1787 ac_test can_inttypes '!' stdint_h 1 "for standard 32-bit integer types" <<-'EOF'
1788 #include <sys/types.h>
1789 #include <stddef.h>
1790 int main(int ac, char *av[]) { return ((uint32_t)(size_t)*av + (int32_t)ac); }
1791 EOF
1792 ac_test can_ucbints '!' can_inttypes 1 "for UCB 32-bit integer types" <<-'EOF'
1793 #include <sys/types.h>
1794 #include <stddef.h>
1795 int main(int ac, char *av[]) { return ((u_int32_t)(size_t)*av + (int32_t)ac); }
1796 EOF
1797 ac_test can_ulong '' "for u_long" <<-'EOF'
1798 #include <sys/types.h>
1799 #include <stddef.h>
1800 int main(int ac, char *av[]) { return ((u_long)(size_t)av[ac]); }
1801 EOF
1802
1803 #
1804 # check whether whatever we use for the final link will succeed
1805 #
1806 if test $cm = makefile; then
1807 : nothing to check
1808 else
1809 HAVE_LINK_WORKS=x
1810 ac_testinit link_works '' 'if the final link command may succeed'
1811 fv=1
1812 cat >conftest.c <<-EOF
1813 #include <sys/types.h>
1814 #if HAVE_BOTH_TIME_H
1815 #include <sys/time.h>
1816 #include <time.h>
1817 #elif HAVE_SYS_TIME_H
1818 #include <sys/time.h>
1819 #elif HAVE_TIME_H
1820 #include <time.h>
1821 #endif
1822 #include <sys/ioctl.h>
1823 #if HAVE_SYS_MTIO_H
1824 #include <sys/mtio.h>
1825 #endif
1826 #if HAVE_SYS_RESOURCE_H
1827 #include <sys/resource.h>
1828 #endif
1829 #include <sys/stat.h>
1830 #include <sys/wait.h>
1831 #include <ctype.h>
1832 #include <err.h>
1833 #include <errno.h>
1834 #include <fcntl.h>
1835 #include <fts.h>
1836 #if HAVE_GRP_H
1837 #include <grp.h>
1838 #endif
1839 #include <limits.h>
1840 #if HAVE_PATHS_H
1841 #include <paths.h>
1842 #endif
1843 #include <pwd.h>
1844 #include <regex.h>
1845 #include <signal.h>
1846 #include <stdarg.h>
1847 #include <stdio.h>
1848 #include <stdlib.h>
1849 #include <string.h>
1850 #if HAVE_STRINGS_H
1851 #include <strings.h>
1852 #endif
1853 #include <unistd.h>
1854 #if HAVE_UTMP_H
1855 #include <utmp.h>
1856 #elif HAVE_UTMPX_H
1857 #include <utmpx.h>
1858 #endif
1859 #if HAVE_VIS_H
1860 #include <vis.h>
1861 #endif
1862 #define EXTERN
1863 #define MIRTOCONF_EARLY
1864 #include "pax.h"
1865 #include "ftimes.h"
1866 #include "ar.h"
1867 #include "cpio.h"
1868 #include "tar.h"
1869 #include "extern.h"
1870 __RCSID("$srcversion");
1871 int main(void) { printf("Hello, World!\\n"); return (isatty(0)); }
1872 EOF
1873 case $cm in
1874 llvm)
1875 v "$CC $CFLAGS $Cg $CPPFLAGS $NOWARN -emit-llvm -c conftest.c" || fv=0
1876 rmf $tfn.s
1877 test $fv = 0 || v "llvm-link -o - conftest.o | opt $optflags | llc -o $tfn.s" || fv=0
1878 test $fv = 0 || v "$CC $CFLAGS $Cg $LDFLAGS -o $tcfn $tfn.s $LIBS $ccpr"
1879 ;;
1880 dragonegg)
1881 v "$CC $CFLAGS $Cg $CPPFLAGS $NOWARN -S -flto conftest.c" || fv=0
1882 test $fv = 0 || v "mv conftest.s conftest.ll"
1883 test $fv = 0 || v "llvm-as conftest.ll" || fv=0
1884 rmf $tfn.s
1885 test $fv = 0 || v "llvm-link -o - conftest.bc | opt $optflags | llc -o $tfn.s" || fv=0
1886 test $fv = 0 || v "$CC $CFLAGS $Cg $LDFLAGS -o $tcfn $tfn.s $LIBS $ccpr"
1887 ;;
1888 combine)
1889 v "$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS -fwhole-program --combine $NOWARN -o $tcfn conftest.c $LIBS $ccpr"
1890 ;;
1891 lto|normal)
1892 cm=normal
1893 v "$CC $CFLAGS $Cg $CPPFLAGS $NOWARN -c conftest.c" || fv=0
1894 test $fv = 0 || v "$CC $CFLAGS $Cg $LDFLAGS -o $tcfn conftest.o $LIBS $ccpr"
1895 ;;
1896 esac
1897 test -f $tcfn || fv=0
1898 ac_testdone
1899 test $fv = 1 || exit 1
1900 fi
1901
1902 #
1903 # Environment: library functions
1904 #
1905 ac_test dprintf <<-'EOF'
1906 #include <stdio.h>
1907 int main(void) { return (dprintf(1, "hi\n")); }
1908 EOF
1909
1910 ac_test fchmodat <<-'EOF'
1911 #include <sys/types.h>
1912 #include <sys/stat.h>
1913 #include <fcntl.h>
1914 #include <unistd.h>
1915 int main(void) { return (fchmodat(AT_FDCWD, ".",
1916 0, AT_SYMLINK_NOFOLLOW)); }
1917 EOF
1918
1919 ac_test fchownat <<-'EOF'
1920 #include <fcntl.h>
1921 #include <unistd.h>
1922 int main(void) { return (fchownat(AT_FDCWD, ".",
1923 0, 0, AT_SYMLINK_NOFOLLOW)); }
1924 EOF
1925
1926 ac_test futimens <<-'EOF'
1927 #include <sys/types.h>
1928 #include <sys/stat.h>
1929 #include <fcntl.h>
1930 struct timespec ts[2] = {{0L, 0L}, {0L, UTIME_OMIT}};
1931 int main(void) { return (futimens(0, ts)); }
1932 EOF
1933
1934 ac_test lchmod '!' fchmodat 0 <<-'EOF'
1935 #include <sys/types.h>
1936 #include <sys/stat.h>
1937 int main(void) { return (lchmod(".", 0)); }
1938 EOF
1939
1940 ac_test lchown '!' fchownat 0 <<-'EOF'
1941 #include <sys/types.h>
1942 #include <unistd.h>
1943 int main(void) { return (lchown(".", 0, 0)); }
1944 EOF
1945
1946 ac_test linkat <<-'EOF'
1947 #include <fcntl.h>
1948 #include <unistd.h>
1949 int main(int ac, char *av[]) { return (linkat(AT_FDCWD, av[1],
1950 AT_FDCWD, av[2], ac)); }
1951 EOF
1952
1953 ac_test pledge <<-'EOF'
1954 #include <unistd.h>
1955 int main(void) { return (pledge("", "")); }
1956 EOF
1957
1958 ac_test reallocarray <<-'EOF'
1959 #include <stdlib.h>
1960 int main(void) { return ((void *)reallocarray(NULL, 3, 3) == (void *)0UL); }
1961 EOF
1962
1963 ac_test setpgent grp_h 0 'for setpassent and setgroupent' <<-'EOF'
1964 #include <sys/types.h>
1965 #include <grp.h>
1966 #include <pwd.h>
1967 int main(void) { return (setpassent(1) + setgroupent(1)); }
1968 EOF
1969
1970 ac_test strlcpy <<-'EOF'
1971 #include <string.h>
1972 int main(int ac, char *av[]) { return (strlcpy(*av, av[1], (size_t)ac)); }
1973 EOF
1974
1975 ac_test strlcat strlcpy 0 <<-'EOF'
1976 #include <string.h>
1977 int main(int ac, char *av[]) { return (strlcat(*av, av[1], (size_t)ac)); }
1978 EOF
1979
1980 ac_test strmode <<-'EOF'
1981 #include <string.h>
1982 #include <unistd.h>
1983 int main(int ac, char *av[]) { strmode(ac, av[0]); return (*av[0]); }
1984 EOF
1985
1986 ac_test strtonum <<-'EOF'
1987 #include <limits.h>
1988 #include <stdlib.h>
1989 int main(int ac, char *av[]) {
1990 return (ac == (int)strtonum(av[1], 0, 100, NULL));
1991 }
1992 EOF
1993
1994 ac_test ug_from_ugid grp_h 0 'for user_from_uid and group_from_gid' <<-'EOF'
1995 #include <sys/types.h>
1996 #include <grp.h>
1997 #include <pwd.h>
1998 int main(void) { return (*user_from_uid(0, 0) ^ *group_from_gid(0, 0)); }
1999 EOF
2000
2001 ac_test ugid_from_ug ug_from_ugid 0 'for uid_from_user and gid_from_group' <<-'EOF'
2002 #include <sys/types.h>
2003 #include <grp.h>
2004 #include <pwd.h>
2005 int main(void) {
2006 uid_t uid;
2007 gid_t gid;
2008 uid_from_user("nobody", &uid);
2009 gid_from_group("nobody", &gid);
2010 return (uid ^ gid);
2011 }
2012 EOF
2013
2014 ac_test utimensat <<-'EOF'
2015 #include <sys/types.h>
2016 #include <sys/stat.h>
2017 #include <fcntl.h>
2018 struct timespec ts[2] = {{0L, 0L}, {0L, UTIME_OMIT}};
2019 int main(void) { return (utimensat(AT_FDCWD, ".", ts,
2020 AT_SYMLINK_NOFOLLOW)); }
2021 EOF
2022
2023 ac_test utimes '!' utimensat 0 <<-'EOF'
2024 #include <sys/time.h>
2025 struct timeval tv[2] = {{0L, 0L}, {0L, 0L}};
2026 int main(void) { return (utimes(".", tv)); }
2027 EOF
2028
2029 ac_test lutimes '!' utimensat 0 <<-'EOF'
2030 #include <sys/time.h>
2031 struct timeval tv[2] = {{0L, 0L}, {0L, 0L}};
2032 int main(void) { return (lutimes(".", tv)); }
2033 EOF
2034
2035 ac_test futimes '!' futimens 0 <<-'EOF'
2036 #include <sys/time.h>
2037 struct timeval tv[2] = {{0L, 0L}, {0L, 0L}};
2038 int main(void) { return (futimes(0, tv)); }
2039 EOF
2040
2041 #
2042 # check headers for declarations
2043 #
2044
2045 #
2046 # other checks
2047 #
2048 ac_test offt_long '' 'whether off_t is as wide as long' <<-'EOF'
2049 #include <sys/types.h>
2050 #include <limits.h>
2051 #include <unistd.h>
2052 #ifndef CHAR_BIT
2053 #define CHAR_BIT 0
2054 #endif
2055 struct ctasserts {
2056 #define cta(name,assertion) char name[(assertion) ? 1 : -1]
2057 cta(char_is_8_bits, (CHAR_BIT) == 8);
2058 cta(off_t_is_long, sizeof(off_t) == sizeof(long));
2059 };
2060 int main(void) { return (sizeof(struct ctasserts)); }
2061 EOF
2062
2063 ac_testn offt_llong '!' offt_long 0 'whether off_t is as wide as long long' <<-'EOF'
2064 #include <sys/types.h>
2065 #include <limits.h>
2066 #include <unistd.h>
2067 #ifndef CHAR_BIT
2068 #define CHAR_BIT 0
2069 #endif
2070 struct ctasserts {
2071 #define cta(name,assertion) char name[(assertion) ? 1 : -1]
2072 cta(char_is_8_bits, (CHAR_BIT) == 8);
2073 cta(off_t_is_llong, sizeof(off_t) == sizeof(long long));
2074 };
2075 int main(void) { return (sizeof(struct ctasserts)); }
2076 EOF
2077
2078 case $HAVE_OFFT_LLONG$HAVE_OFFT_LONG in
2079 10|01) ;;
2080 *) echo Cannot determine width of off_t
2081 exit 1 ;;
2082 esac
2083
2084 ac_test timet_long '' 'whether time_t is as wide as long' <<-'EOF'
2085 #include <sys/types.h>
2086 #if HAVE_BOTH_TIME_H
2087 #include <sys/time.h>
2088 #include <time.h>
2089 #elif HAVE_SYS_TIME_H
2090 #include <sys/time.h>
2091 #elif HAVE_TIME_H
2092 #include <time.h>
2093 #endif
2094 #include <limits.h>
2095 #ifndef CHAR_BIT
2096 #define CHAR_BIT 0
2097 #endif
2098 struct ctasserts {
2099 #define cta(name,assertion) char name[(assertion) ? 1 : -1]
2100 cta(char_is_8_bits, (CHAR_BIT) == 8);
2101 cta(time_t_is_long, sizeof(time_t) == sizeof(long));
2102 };
2103 int main(void) { return (sizeof(struct ctasserts)); }
2104 EOF
2105
2106 ac_testn timet_llong '!' timet_long 0 'whether time_t is as wide as long long' <<-'EOF'
2107 #include <sys/types.h>
2108 #if HAVE_BOTH_TIME_H
2109 #include <sys/time.h>
2110 #include <time.h>
2111 #elif HAVE_SYS_TIME_H
2112 #include <sys/time.h>
2113 #elif HAVE_TIME_H
2114 #include <time.h>
2115 #endif
2116 #include <limits.h>
2117 #ifndef CHAR_BIT
2118 #define CHAR_BIT 0
2119 #endif
2120 struct ctasserts {
2121 #define cta(name,assertion) char name[(assertion) ? 1 : -1]
2122 cta(char_is_8_bits, (CHAR_BIT) == 8);
2123 cta(time_t_is_llong, sizeof(time_t) == sizeof(long long));
2124 };
2125 int main(void) { return (sizeof(struct ctasserts)); }
2126 EOF
2127
2128 case $HAVE_TIMET_LLONG$HAVE_TIMET_LONG in
2129 10|01) ;;
2130 *) echo Cannot determine width of time_t
2131 exit 1 ;;
2132 esac
2133
2134 ac_test timet_large '' 'whether time_t is wider than 32 bit' <<-'EOF'
2135 #include <sys/types.h>
2136 #if HAVE_BOTH_TIME_H
2137 #include <sys/time.h>
2138 #include <time.h>
2139 #elif HAVE_SYS_TIME_H
2140 #include <sys/time.h>
2141 #elif HAVE_TIME_H
2142 #include <time.h>
2143 #endif
2144 #include <limits.h>
2145 #ifndef CHAR_BIT
2146 #define CHAR_BIT 0
2147 #endif
2148 struct ctasserts {
2149 #define cta(name,assertion) char name[(assertion) ? 1 : -1]
2150 cta(char_is_8_bits, (CHAR_BIT) == 8);
2151 cta(time_t_is_large, sizeof(time_t) > 4);
2152 };
2153 int main(void) { return (sizeof(struct ctasserts)); }
2154 EOF
2155
2156 ac_testn st_mtimensec '' 'for struct stat.st_mtimensec' <<-'EOF'
2157 #include <sys/types.h>
2158 #if HAVE_BOTH_TIME_H
2159 #include <sys/time.h>
2160 #include <time.h>
2161 #elif HAVE_SYS_TIME_H
2162 #include <sys/time.h>
2163 #elif HAVE_TIME_H
2164 #include <time.h>
2165 #endif
2166 #include <sys/stat.h>
2167 int main(void) { struct stat sb; return (sizeof(sb.st_mtimensec)); }
2168 EOF
2169 ac_testn st_mtimespec '!' st_mtimensec 0 'for struct stat.st_mtimespec.tv_nsec' <<-'EOF'
2170 #include <sys/types.h>
2171 #if HAVE_BOTH_TIME_H
2172 #include <sys/time.h>
2173 #include <time.h>
2174 #elif HAVE_SYS_TIME_H
2175 #include <sys/time.h>
2176 #elif HAVE_TIME_H
2177 #include <time.h>
2178 #endif
2179 #include <sys/stat.h>
2180 int main(void) { struct stat sb; return (sizeof(sb.st_mtimespec.tv_nsec)); }
2181 EOF
2182 if test 1 = "$HAVE_ST_MTIMESPEC"; then
2183 cpp_define st_atimensec st_atimespec.tv_nsec
2184 cpp_define st_ctimensec st_ctimespec.tv_nsec
2185 cpp_define st_mtimensec st_mtimespec.tv_nsec
2186 HAVE_ST_MTIMENSEC=1
2187 fi
2188 ac_testn st_mtim '!' st_mtimensec 0 'for struct stat.st_mtim.tv_nsec' <<-'EOF'
2189 #include <sys/types.h>
2190 #if HAVE_BOTH_TIME_H
2191 #include <sys/time.h>
2192 #include <time.h>
2193 #elif HAVE_SYS_TIME_H
2194 #include <sys/time.h>
2195 #elif HAVE_TIME_H
2196 #include <time.h>
2197 #endif
2198 #include <sys/stat.h>
2199 int main(void) { struct stat sb; return (sizeof(sb.st_mtim.tv_nsec)); }
2200 EOF
2201 if test 1 = "$HAVE_ST_MTIM"; then
2202 cpp_define st_atimensec st_atim.tv_nsec
2203 cpp_define st_ctimensec st_ctim.tv_nsec
2204 cpp_define st_mtimensec st_mtim.tv_nsec
2205 HAVE_ST_MTIMENSEC=1
2206 fi
2207 ac_testn st_mtime_nsec '!' st_mtimensec 0 'for struct stat.st_mtime_nsec' <<-'EOF'
2208 #include <sys/types.h>
2209 #if HAVE_BOTH_TIME_H
2210 #include <sys/time.h>
2211 #include <time.h>
2212 #elif HAVE_SYS_TIME_H
2213 #include <sys/time.h>
2214 #elif HAVE_TIME_H
2215 #include <time.h>
2216 #endif
2217 #include <sys/stat.h>
2218 int main(void) { struct stat sb; return (sizeof(sb.st_mtime_nsec)); }
2219 EOF
2220 if test 1 = "$HAVE_ST_MTIME_NSEC"; then
2221 cpp_define st_atimensec st_atime_nsec
2222 cpp_define st_ctimensec st_ctime_nsec
2223 cpp_define st_mtimensec st_mtime_nsec
2224 HAVE_ST_MTIMENSEC=1
2225 fi
2226 ac_cppflags ST_MTIMENSEC
2227
2228
2229 #
2230 # Compiler: Praeprocessor (only if needed)
2231 #
2232
2233 #
2234 # End of mirtoconf checks
2235 #
2236 $e ... done.
2237 rmf vv.out
2238
2239 addsrcs '!' HAVE_UGID_FROM_UG cache.c
2240 addsrcs '!' HAVE_REALLOCARRAY reallocarray.c
2241 addsrcs '!' HAVE_STRMODE strmode.c
2242 addsrcs '!' HAVE_STRTONUM strtonum.c
2243
2244 test 1 = "$HAVE_CAN_VERB" && CFLAGS="$CFLAGS -verbose"
2245
2246 $e $bi$me: Finished configuration testing, now producing output.$ao
2247
2248 files=
2249 objs=
2250 fsp=
2251 case $tcfn in
2252 a.exe|conftest.exe)
2253 buildoutput=$tfn.exe
2254 paxexe=$paxname.exe
2255 cpioexe=$cpioname.exe
2256 tarexe=$tarname.exe
2257 cpp_define MKSH_EXE_EXT 1
2258 ;;
2259 *)
2260 buildoutput=$tfn
2261 paxexe=$paxname
2262 cpioexe=$cpioname
2263 tarexe=$tarname
2264 ;;
2265 esac
2266 case $cm in
2267 dragonegg)
2268 emitbc="-S -flto"
2269 ;;
2270 llvm)
2271 emitbc="-emit-llvm -c"
2272 ;;
2273 *)
2274 emitbc=-c
2275 ;;
2276 esac
2277 echo ": # work around NeXTstep bug" >Rebuild.sh
2278 echo set -x >>Rebuild.sh
2279 for file in $SRCS; do
2280 op=`echo x"$file" | sed 's/^x\(.*\)\.c$/\1./'`
2281 test -f $file || file=$srcdir/$file
2282 files="$files$fsp$file"
2283 echo "$CC $CFLAGS $Cg $CPPFLAGS $emitbc $file || exit 1" >>Rebuild.sh
2284 if test $cm = dragonegg; then
2285 echo "mv ${op}s ${op}ll" >>Rebuild.sh
2286 echo "llvm-as ${op}ll || exit 1" >>Rebuild.sh
2287 objs="$objs$fsp${op}bc"
2288 else
2289 objs="$objs$fsp${op}o"
2290 fi
2291 fsp=$sp
2292 done
2293 case $cm in
2294 dragonegg|llvm)
2295 echo "rm -f $tfn.s" >>Rebuild.sh
2296 echo "llvm-link -o - $objs | opt $optflags | llc -o $tfn.s" >>Rebuild.sh
2297 lobjs=$tfn.s
2298 ;;
2299 *)
2300 lobjs=$objs
2301 ;;
2302 esac
2303 echo tcfn=$buildoutput >>Rebuild.sh
2304 echo "$CC $CFLAGS $Cg $LDFLAGS -o \$tcfn $lobjs $LIBS $ccpr" >>Rebuild.sh
2305 echo "test -f \$tcfn || exit 1; $SIZE \$tcfn" >>Rebuild.sh
2306 echo "rm -f $paxexe $cpioexe $tarexe" >>Rebuild.sh
2307 echo "for x in $paxexe $cpioexe $tarexe; do" >>Rebuild.sh
2308 echo " ln \$tcfn \$x || cp -p \$tcfn \$x || exit 1" >>Rebuild.sh
2309 echo "done" >>Rebuild.sh
2310 if test $cm = makefile; then
2311 extras='.linked/reallocarray.inc .linked/strlfun.inc .linked/strmode.inc .linked/strtonum.inc ar.h compat.h cpio.h extern.h ftimes.h pax.h tar.h'
2312 cat >Makefrag.inc <<EOF
2313 # Makefile fragment for building $whatlong $dstversion
2314
2315 PROG= $buildoutput
2316 # install as $paxexe and $cpioexe and $tarexe though
2317 MAN= cpio.1 pax.1 tar.1
2318 SRCDIR= $srcdir
2319 MF_DIR= $curdisp
2320 SRCS= $SRCS
2321 SRCS_FP= $files
2322 OBJS_BP= $objs
2323 INDSRCS= $extras
2324 NONSRCS_INST= \$(MAN)
2325 NONSRCS_NOINST= Build.sh Makefile Rebuild.sh
2326 CC= $CC
2327 CPPFLAGS= $CPPFLAGS -I'\$(MF_DIR)'
2328 CFLAGS= $CFLAGS $Cg
2329 LDFLAGS= $LDFLAGS
2330 LIBS= $LIBS
2331
2332 # not BSD make only:
2333 #VPATH= \$(SRCDIR)
2334 #all: \$(PROG)
2335 #\$(PROG): \$(OBJS_BP)
2336 # \$(CC) \$(CFLAGS) \$(LDFLAGS) -o \$@ \$(OBJS_BP) \$(LIBS)
2337 #\$(OBJS_BP): \$(SRCS_FP) \$(NONSRCS)
2338 #.c.o:
2339 # \$(CC) \$(CFLAGS) \$(CPPFLAGS) -c \$<
2340
2341 # for BSD make only:
2342 #.PATH: \$(SRCDIR)
2343 #.include <bsd.prog.mk>
2344 EOF
2345 $e
2346 $e Generated Makefrag.inc successfully.
2347 exit 0
2348 fi
2349 if test $cm = combine; then
2350 objs="-o $buildoutput"
2351 for file in $SRCS; do
2352 test -f $file || file=$srcdir/$file
2353 objs="$objs $file"
2354 done
2355 emitbc="-fwhole-program --combine"
2356 v "$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $emitbc $objs $LIBS $ccpr"
2357 elif test 1 = $pm; then
2358 for file in $SRCS; do
2359 test -f $file || file=$srcdir/$file
2360 v "$CC $CFLAGS $Cg $CPPFLAGS $emitbc $file" &
2361 done
2362 wait
2363 else
2364 for file in $SRCS; do
2365 test $cm = dragonegg && \
2366 op=`echo x"$file" | sed 's/^x\(.*\)\.c$/\1./'`
2367 test -f $file || file=$srcdir/$file
2368 v "$CC $CFLAGS $Cg $CPPFLAGS $emitbc $file" || exit 1
2369 if test $cm = dragonegg; then
2370 v "mv ${op}s ${op}ll"
2371 v "llvm-as ${op}ll" || exit 1
2372 fi
2373 done
2374 fi
2375 case $cm in
2376 dragonegg|llvm)
2377 rmf $tfn.s
2378 v "llvm-link -o - $objs | opt $optflags | llc -o $tfn.s"
2379 ;;
2380 esac
2381 tcfn=$buildoutput
2382 case $cm in
2383 combine)
2384 ;;
2385 *)
2386 v "$CC $CFLAGS $Cg $LDFLAGS -o $tcfn $lobjs $LIBS $ccpr"
2387 ;;
2388 esac
2389 test -f $tcfn || exit 1
2390 rm -f $paxexe $cpioexe $tarexe
2391 for x in $paxexe $cpioexe $tarexe; do
2392 ln $tcfn $x || cp -p $tcfn $x || exit 1
2393 done
2394 rm -rf mans
2395 mkdir mans
2396 echo .nr g $mans | cat - "$srcdir/cpio.1" >mans/$cpioname.1
2397 echo .nr g $mans | cat - "$srcdir/pax.1" >mans/$paxname.1
2398 echo .nr g $mans | cat - "$srcdir/tar.1" >mans/$tarname.1
2399 test 1 = $r || v "$NROFF -mdoc <mans/$cpioname.1 >mans/$cpioname.cat1" || rmf mans/$cpioname.cat1
2400 test 1 = $r || v "$NROFF -mdoc <mans/$paxname.1 >mans/$paxname.cat1" || rmf mans/$paxname.cat1
2401 test 1 = $r || v "$NROFF -mdoc <mans/$tarname.1 >mans/$tarname.cat1" || rmf mans/$tarname.cat1
2402 test 0 = $eq && v $SIZE $tcfn
2403 i=install
2404 test -f /usr/ucb/$i && i=/usr/ucb/$i
2405 test 1 = $eq && e=:
2406 $e
2407 $e Installing the executable:
2408 $e "# $i -c -s -o root -g bin -m 555 $paxexe /bin/$paxexe"
2409 for x in $cpioexe $tarexe; do
2410 $e "# ln -f /bin/$paxexe /bin/$x || cp -fp /bin/$paxexe /bin/$x"
2411 done
2412 $e
2413 $e Installing the manual:
2414 if test -f mans/$paxname.cat1; then
2415 $e "# $i -c -o root -g bin -m 444 mans/$cpioname.cat1" \
2416 "/usr/share/man/cat1/$cpioname.0"
2417 $e "# $i -c -o root -g bin -m 444 mans/$paxname.cat1" \
2418 "/usr/share/man/cat1/$paxname.0"
2419 $e "# $i -c -o root -g bin -m 444 mans/$tarname.cat1" \
2420 "/usr/share/man/cat1/$tarname.0"
2421 $e or
2422 fi
2423 $e "# $i -c -o root -g bin -m 444 mans/$cpioname.1 mans/$paxname.1 mans/$tarname.1 /usr/share/man/man1/"
2424 $e
2425 $e Please also read the fine manual.
2426 exit 0
2427
2428 : <<'EOD'
2429
2430 === Environment used ===
2431
2432 ==== build environment ====
2433 CC default: cc
2434 CFLAGS if empty, defaults to -xO2 or +O2
2435 or -O3 -qstrict or -O2, per compiler
2436 CPPFLAGS default empty
2437 LDFLAGS default empty; added before sources
2438 LDSTATIC set this to '-static'; default unset
2439 LIBS default empty; added after sources
2440 NOWARN -Wno-error or similar
2441 NROFF default: nroff
2442 TARGET_OS default: `uname -s || uname`
2443 TARGET_OSREV default: `uname -r` [only needed on some OS]
2444
2445 ===== general format =====
2446 HAVE_STRLEN ac_test
2447 HAVE_STRING_H ac_header
2448 HAVE_CAN_FSTACKPROTECTORALL ac_flags
2449
2450 ==== cpp definitions ====
2451 DEBUG don’t use in production, wants gcc
2452 MKSH_DONT_EMIT_IDSTRING omit RCS IDs from binary
2453 PAX_SAFE_PATH subprocess PATH, default "/bin:/usr/bin"
2454 SMALL for the MirBSD installer/rescue system
2455
2456 === generic installation instructions ===
2457
2458 Set CC and possibly CFLAGS, CPPFLAGS, LDFLAGS, LIBS. If cross-compiling,
2459 also set TARGET_OS. To disable tests, set e.g. HAVE_STRLCPY=0; to enable
2460 them, set to a value other than 0 or 1 (e.g. to x).
2461
2462 Normally, the following command is what you want to run, then:
2463 $ sh Build.sh -r 2>&1 | tee log
2464
2465 Install as /bin/pax and hardlink to /bin/cpio and /bin/tar or install as
2466 $prefix/bin/mirpax and hardlink to $prefix/bin/mir{cpio,tar}; install the
2467 manpages, if omitting the -r flag catmanpages are made using $NROFF.
2468
2469 Add -tmir to install as mir{pax,cpio,tar} or -tpax for pax{,cpio,tar}.
2470
2471 EOD