OSDN Git Service

Merge "Upgrade to mksh R56b."
[android-x86/external-mksh.git] / src / Build.sh
1 #!/bin/sh
2 srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.727 2017/08/29 13:38:28 tg Exp $'
3 #-
4 # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
5 #               2011, 2012, 2013, 2014, 2015, 2016, 2017
6 #       mirabilos <m@mirbsd.org>
7 #
8 # Provided that these terms and disclaimer and all copyright notices
9 # are retained or reproduced in an accompanying document, permission
10 # is granted to deal in this work without restriction, including un-
11 # limited rights to use, publicly perform, distribute, sell, modify,
12 # merge, give away, or sublicence.
13 #
14 # This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
15 # the utmost extent permitted by applicable law, neither express nor
16 # implied; without malicious intent or gross negligence. In no event
17 # may a licensor, author or contributor be held liable for indirect,
18 # direct, other damage, loss, or other issues arising in any way out
19 # of dealing in the work, even if advised of the possibility of such
20 # damage or existence of a defect, except proven that it results out
21 # of said person's immediate fault when using the work as intended.
22 #-
23 # People analysing the output must whitelist conftest.c for any kind
24 # of compiler warning checks (mirtoconf is by design not quiet).
25 #
26 # Used environment documentation is at the end of this file.
27
28 LC_ALL=C
29 export LC_ALL
30
31 case $ZSH_VERSION:$VERSION in
32 :zsh*) ZSH_VERSION=2 ;;
33 esac
34
35 if test -n "${ZSH_VERSION+x}" && (emulate sh) >/dev/null 2>&1; then
36         emulate sh
37         NULLCMD=:
38 fi
39
40 if test -d /usr/xpg4/bin/. >/dev/null 2>&1; then
41         # Solaris: some of the tools have weird behaviour, use portable ones
42         PATH=/usr/xpg4/bin:$PATH
43         export PATH
44 fi
45
46 nl='
47 '
48 safeIFS='       '
49 safeIFS=" $safeIFS$nl"
50 IFS=$safeIFS
51 allu=QWERTYUIOPASDFGHJKLZXCVBNM
52 alll=qwertyuiopasdfghjklzxcvbnm
53 alln=0123456789
54 alls=______________________________________________________________
55
56 case `echo a | tr '\201' X` in
57 X)
58         # EBCDIC build system
59         lfcr='\n\r'
60         ;;
61 *)
62         lfcr='\012\015'
63         ;;
64 esac
65
66 genopt_die() {
67         if test -n "$1"; then
68                 echo >&2 "E: $*"
69                 echo >&2 "E: in '$srcfile': '$line'"
70         else
71                 echo >&2 "E: invalid input in '$srcfile': '$line'"
72         fi
73         rm -f "$bn.gen"
74         exit 1
75 }
76
77 genopt_soptc() {
78         optc=`echo "$line" | sed 's/^[<>]\(.\).*$/\1/'`
79         test x"$optc" = x'|' && return
80         optclo=`echo "$optc" | tr $allu $alll`
81         if test x"$optc" = x"$optclo"; then
82                 islo=1
83         else
84                 islo=0
85         fi
86         sym=`echo "$line" | sed 's/^[<>]/|/'`
87         o_str=$o_str$nl"<$optclo$islo$sym"
88 }
89
90 genopt_scond() {
91         case x$cond in
92         x)
93                 cond=
94                 ;;
95         x*' '*)
96                 cond=`echo "$cond" | sed 's/^ //'`
97                 cond="#if $cond"
98                 ;;
99         x'!'*)
100                 cond=`echo "$cond" | sed 's/^!//'`
101                 cond="#ifndef $cond"
102                 ;;
103         x*)
104                 cond="#ifdef $cond"
105                 ;;
106         esac
107 }
108
109 do_genopt() {
110         srcfile=$1
111         test -f "$srcfile" || genopt_die Source file \$srcfile not set.
112         bn=`basename "$srcfile" | sed 's/.opt$//'`
113         o_hdr='/* +++ GENERATED FILE +++ DO NOT EDIT +++ */'
114         o_gen=
115         o_str=
116         o_sym=
117         ddefs=
118         state=0
119         exec <"$srcfile"
120         IFS=
121         while IFS= read line; do
122                 IFS=$safeIFS
123                 case $state:$line in
124                 2:'|'*)
125                         # end of input
126                         o_sym=`echo "$line" | sed 's/^.//'`
127                         o_gen=$o_gen$nl"#undef F0"
128                         o_gen=$o_gen$nl"#undef FN"
129                         o_gen=$o_gen$ddefs
130                         state=3
131                         ;;
132                 1:@@)
133                         # start of data block
134                         o_gen=$o_gen$nl"#endif"
135                         o_gen=$o_gen$nl"#ifndef F0"
136                         o_gen=$o_gen$nl"#define F0 FN"
137                         o_gen=$o_gen$nl"#endif"
138                         state=2
139                         ;;
140                 *:@@*)
141                         genopt_die ;;
142                 0:/\*-|0:\ \**|0:)
143                         o_hdr=$o_hdr$nl$line
144                         ;;
145                 0:@*|1:@*)
146                         # start of a definition block
147                         sym=`echo "$line" | sed 's/^@//'`
148                         if test $state = 0; then
149                                 o_gen=$o_gen$nl"#if defined($sym)"
150                         else
151                                 o_gen=$o_gen$nl"#elif defined($sym)"
152                         fi
153                         ddefs="$ddefs$nl#undef $sym"
154                         state=1
155                         ;;
156                 0:*|3:*)
157                         genopt_die ;;
158                 1:*)
159                         # definition line
160                         o_gen=$o_gen$nl$line
161                         ;;
162                 2:'<'*'|'*)
163                         genopt_soptc
164                         ;;
165                 2:'>'*'|'*)
166                         genopt_soptc
167                         cond=`echo "$line" | sed 's/^[^|]*|//'`
168                         genopt_scond
169                         case $optc in
170                         '|') optc=0 ;;
171                         *) optc=\'$optc\' ;;
172                         esac
173                         IFS= read line || genopt_die Unexpected EOF
174                         IFS=$safeIFS
175                         test -n "$cond" && o_gen=$o_gen$nl"$cond"
176                         o_gen=$o_gen$nl"$line, $optc)"
177                         test -n "$cond" && o_gen=$o_gen$nl"#endif"
178                         ;;
179                 esac
180         done
181         case $state:$o_sym in
182         3:) genopt_die Expected optc sym at EOF ;;
183         3:*) ;;
184         *) genopt_die Missing EOF marker ;;
185         esac
186         echo "$o_str" | sort | while IFS='|' read x opts cond; do
187                 IFS=$safeIFS
188                 test -n "$x" || continue
189                 genopt_scond
190                 test -n "$cond" && echo "$cond"
191                 echo "\"$opts\""
192                 test -n "$cond" && echo "#endif"
193         done | {
194                 echo "$o_hdr"
195                 echo "#ifndef $o_sym$o_gen"
196                 echo "#else"
197                 cat
198                 echo "#undef $o_sym"
199                 echo "#endif"
200         } >"$bn.gen"
201         IFS=$safeIFS
202         return 0
203 }
204
205 if test x"$BUILDSH_RUN_GENOPT" = x"1"; then
206         set x -G "$srcfile"
207         shift
208 fi
209 if test x"$1" = x"-G"; then
210         do_genopt "$2"
211         exit $?
212 fi
213
214 echo "For the build logs, demonstrate that /dev/null and /dev/tty exist:"
215 ls -l /dev/null /dev/tty
216
217 v() {
218         $e "$*"
219         eval "$@"
220 }
221
222 vv() {
223         _c=$1
224         shift
225         $e "\$ $*" 2>&1
226         eval "$@" >vv.out 2>&1
227         sed "s\a^\a${_c} \a" <vv.out
228 }
229
230 vq() {
231         eval "$@"
232 }
233
234 rmf() {
235         for _f in "$@"; do
236                 case $_f in
237                 Build.sh|check.pl|check.t|dot.mkshrc|*.1|*.c|*.h|*.ico|*.opt) ;;
238                 *) rm -f "$_f" ;;
239                 esac
240         done
241 }
242
243 tcfn=no
244 bi=
245 ui=
246 ao=
247 fx=
248 me=`basename "$0"`
249 orig_CFLAGS=$CFLAGS
250 phase=x
251 oldish_ed=stdout-ed,no-stderr-ed
252
253 if test -t 1; then
254         bi='\e[1m'
255         ui='\e[4m'
256         ao='\e[0m'
257 fi
258
259 upper() {
260         echo :"$@" | sed 's/^://' | tr $alll $allu
261 }
262
263 # clean up after ac_testrun()
264 ac_testdone() {
265         eval HAVE_$fu=$fv
266         fr=no
267         test 0 = $fv || fr=yes
268         $e "$bi==> $fd...$ao $ui$fr$ao$fx"
269         fx=
270 }
271
272 # ac_cache label: sets f, fu, fv?=0
273 ac_cache() {
274         f=$1
275         fu=`upper $f`
276         eval fv=\$HAVE_$fu
277         case $fv in
278         0|1)
279                 fx=' (cached)'
280                 return 0
281                 ;;
282         esac
283         fv=0
284         return 1
285 }
286
287 # ac_testinit label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput
288 # returns 1 if value was cached/implied, 0 otherwise: call ac_testdone
289 ac_testinit() {
290         if ac_cache $1; then
291                 test x"$2" = x"!" && shift
292                 test x"$2" = x"" || shift
293                 fd=${3-$f}
294                 ac_testdone
295                 return 1
296         fi
297         fc=0
298         if test x"$2" = x""; then
299                 ft=1
300         else
301                 if test x"$2" = x"!"; then
302                         fc=1
303                         shift
304                 fi
305                 eval ft=\$HAVE_`upper $2`
306                 shift
307         fi
308         fd=${3-$f}
309         if test $fc = "$ft"; then
310                 fv=$2
311                 fx=' (implied)'
312                 ac_testdone
313                 return 1
314         fi
315         $e ... $fd
316         return 0
317 }
318
319 # pipe .c | ac_test[n] [!] label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput
320 ac_testnnd() {
321         if test x"$1" = x"!"; then
322                 fr=1
323                 shift
324         else
325                 fr=0
326         fi
327         ac_testinit "$@" || return 1
328         cat >conftest.c
329         vv ']' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN conftest.c $LIBS $ccpr"
330         test $tcfn = no && test -f a.out && tcfn=a.out
331         test $tcfn = no && test -f a.exe && tcfn=a.exe
332         test $tcfn = no && test -f conftest.exe && tcfn=conftest.exe
333         test $tcfn = no && test -f conftest && tcfn=conftest
334         if test -f $tcfn; then
335                 test 1 = $fr || fv=1
336         else
337                 test 0 = $fr || fv=1
338         fi
339         vscan=
340         if test $phase = u; then
341                 test $ct = gcc && vscan='unrecogni[sz]ed'
342                 test $ct = hpcc && vscan='unsupported'
343                 test $ct = pcc && vscan='unsupported'
344                 test $ct = sunpro && vscan='-e ignored -e turned.off'
345         fi
346         test -n "$vscan" && grep $vscan vv.out >/dev/null 2>&1 && fv=$fr
347         return 0
348 }
349 ac_testn() {
350         ac_testnnd "$@" || return
351         rmf conftest.c conftest.o ${tcfn}* vv.out
352         ac_testdone
353 }
354
355 # ac_ifcpp cppexpr [!] label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput
356 ac_ifcpp() {
357         expr=$1; shift
358         ac_testn "$@" <<-EOF
359                 #include <unistd.h>
360                 extern int thiswillneverbedefinedIhope(void);
361                 int main(void) { return (isatty(0) +
362                 #$expr
363                     0
364                 #else
365                 /* force a failure: expr is false */
366                     thiswillneverbedefinedIhope()
367                 #endif
368                     ); }
369 EOF
370         test x"$1" = x"!" && shift
371         f=$1
372         fu=`upper $f`
373         eval fv=\$HAVE_$fu
374         test x"$fv" = x"1"
375 }
376
377 add_cppflags() {
378         CPPFLAGS="$CPPFLAGS $*"
379 }
380
381 ac_cppflags() {
382         test x"$1" = x"" || fu=$1
383         fv=$2
384         test x"$2" = x"" && eval fv=\$HAVE_$fu
385         add_cppflags -DHAVE_$fu=$fv
386 }
387
388 ac_test() {
389         ac_testn "$@"
390         ac_cppflags
391 }
392
393 # ac_flags [-] add varname cflags [text] [ldflags]
394 ac_flags() {
395         if test x"$1" = x"-"; then
396                 shift
397                 hf=1
398         else
399                 hf=0
400         fi
401         fa=$1
402         vn=$2
403         f=$3
404         ft=$4
405         fl=$5
406         test x"$ft" = x"" && ft="if $f can be used"
407         save_CFLAGS=$CFLAGS
408         CFLAGS="$CFLAGS $f"
409         if test -n "$fl"; then
410                 save_LDFLAGS=$LDFLAGS
411                 LDFLAGS="$LDFLAGS $fl"
412         fi
413         if test 1 = $hf; then
414                 ac_testn can_$vn '' "$ft"
415         else
416                 ac_testn can_$vn '' "$ft" <<-'EOF'
417                         /* evil apo'stroph in comment test */
418                         #include <unistd.h>
419                         int main(void) { return (isatty(0)); }
420                 EOF
421         fi
422         eval fv=\$HAVE_CAN_`upper $vn`
423         if test -n "$fl"; then
424                 test 11 = $fa$fv || LDFLAGS=$save_LDFLAGS
425         fi
426         test 11 = $fa$fv || CFLAGS=$save_CFLAGS
427 }
428
429 # ac_header [!] header [prereq ...]
430 ac_header() {
431         if test x"$1" = x"!"; then
432                 na=1
433                 shift
434         else
435                 na=0
436         fi
437         hf=$1; shift
438         hv=`echo "$hf" | tr -d "$lfcr" | tr -c $alll$allu$alln $alls`
439         echo "/* NeXTstep bug workaround */" >x
440         for i
441         do
442                 case $i in
443                 _time)
444                         echo '#if HAVE_BOTH_TIME_H' >>x
445                         echo '#include <sys/time.h>' >>x
446                         echo '#include <time.h>' >>x
447                         echo '#elif HAVE_SYS_TIME_H' >>x
448                         echo '#include <sys/time.h>' >>x
449                         echo '#elif HAVE_TIME_H' >>x
450                         echo '#include <time.h>' >>x
451                         echo '#endif' >>x
452                         ;;
453                 *)
454                         echo "#include <$i>" >>x
455                         ;;
456                 esac
457         done
458         echo "#include <$hf>" >>x
459         echo '#include <unistd.h>' >>x
460         echo 'int main(void) { return (isatty(0)); }' >>x
461         ac_testn "$hv" "" "<$hf>" <x
462         rmf x
463         test 1 = $na || ac_cppflags
464 }
465
466 addsrcs() {
467         if test x"$1" = x"!"; then
468                 fr=0
469                 shift
470         else
471                 fr=1
472         fi
473         eval i=\$$1
474         test $fr = "$i" && case " $SRCS " in
475         *\ $2\ *)       ;;
476         *)              SRCS="$SRCS $2" ;;
477         esac
478 }
479
480
481 curdir=`pwd` srcdir=`dirname "$0" 2>/dev/null`
482 case x$srcdir in
483 x)
484         srcdir=.
485         ;;
486 *\ *|*" "*|*"$nl"*)
487         echo >&2 Source directory should not contain space or tab or newline.
488         echo >&2 Errors may occur.
489         ;;
490 *"'"*)
491         echo Source directory must not contain single quotes.
492         exit 1
493         ;;
494 esac
495 dstversion=`sed -n '/define MKSH_VERSION/s/^.*"\([^"]*\)".*$/\1/p' "$srcdir/sh.h"`
496 add_cppflags -DMKSH_BUILDSH
497
498 e=echo
499 r=0
500 eq=0
501 pm=0
502 cm=normal
503 optflags=-std-compile-opts
504 check_categories=
505 last=
506 tfn=
507 legacy=0
508 textmode=0
509 ebcdic=false
510
511 for i
512 do
513         case $last:$i in
514         c:combine|c:dragonegg|c:llvm|c:lto)
515                 cm=$i
516                 last=
517                 ;;
518         c:*)
519                 echo "$me: Unknown option -c '$i'!" >&2
520                 exit 1
521                 ;;
522         o:*)
523                 optflags=$i
524                 last=
525                 ;;
526         t:*)
527                 tfn=$i
528                 last=
529                 ;;
530         :-c)
531                 last=c
532                 ;;
533         :-E)
534                 ebcdic=true
535                 ;;
536         :-G)
537                 echo "$me: Do not call me with '-G'!" >&2
538                 exit 1
539                 ;;
540         :-g)
541                 # checker, debug, valgrind build
542                 add_cppflags -DDEBUG
543                 CFLAGS="$CFLAGS -g3 -fno-builtin"
544                 ;;
545         :-j)
546                 pm=1
547                 ;;
548         :-L)
549                 legacy=1
550                 ;;
551         :+L)
552                 legacy=0
553                 ;;
554         :-M)
555                 cm=makefile
556                 ;;
557         :-O)
558                 optflags=-std-compile-opts
559                 ;;
560         :-o)
561                 last=o
562                 ;;
563         :-Q)
564                 eq=1
565                 ;;
566         :-r)
567                 r=1
568                 ;;
569         :-T)
570                 textmode=1
571                 ;;
572         :+T)
573                 textmode=0
574                 ;;
575         :-t)
576                 last=t
577                 ;;
578         :-v)
579                 echo "Build.sh $srcversion"
580                 echo "for mksh $dstversion"
581                 exit 0
582                 ;;
583         :*)
584                 echo "$me: Unknown option '$i'!" >&2
585                 exit 1
586                 ;;
587         *)
588                 echo "$me: Unknown option -'$last' '$i'!" >&2
589                 exit 1
590                 ;;
591         esac
592 done
593 if test -n "$last"; then
594         echo "$me: Option -'$last' not followed by argument!" >&2
595         exit 1
596 fi
597
598 test -z "$tfn" && if test $legacy = 0; then
599         tfn=mksh
600 else
601         tfn=lksh
602 fi
603 if test -d $tfn || test -d $tfn.exe; then
604         echo "$me: Error: ./$tfn is a directory!" >&2
605         exit 1
606 fi
607 rmf a.exe* a.out* conftest.c conftest.exe* *core core.* ${tfn}* *.bc *.dbg \
608     *.ll *.o *.gen *.cat1 Rebuild.sh lft no signames.inc test.sh x vv.out
609
610 SRCS="lalloc.c edit.c eval.c exec.c expr.c funcs.c histrap.c jobs.c"
611 SRCS="$SRCS lex.c main.c misc.c shf.c syn.c tree.c var.c"
612
613 if test $legacy = 0; then
614         check_categories="$check_categories shell:legacy-no int:32"
615 else
616         check_categories="$check_categories shell:legacy-yes"
617         add_cppflags -DMKSH_LEGACY_MODE
618 fi
619
620 if $ebcdic; then
621         add_cppflags -DMKSH_EBCDIC
622 fi
623
624 if test $textmode = 0; then
625         check_categories="$check_categories shell:textmode-no shell:binmode-yes"
626 else
627         check_categories="$check_categories shell:textmode-yes shell:binmode-no"
628         add_cppflags -DMKSH_WITH_TEXTMODE
629 fi
630
631 if test x"$srcdir" = x"."; then
632         CPPFLAGS="-I. $CPPFLAGS"
633 else
634         CPPFLAGS="-I. -I'$srcdir' $CPPFLAGS"
635 fi
636 test -n "$LDSTATIC" && if test -n "$LDFLAGS"; then
637         LDFLAGS="$LDFLAGS $LDSTATIC"
638 else
639         LDFLAGS=$LDSTATIC
640 fi
641
642 if test -z "$TARGET_OS"; then
643         x=`uname -s 2>/dev/null || uname`
644         test x"$x" = x"`uname -n 2>/dev/null`" || TARGET_OS=$x
645 fi
646 if test -z "$TARGET_OS"; then
647         echo "$me: Set TARGET_OS, your uname is broken!" >&2
648         exit 1
649 fi
650 oswarn=
651 ccpc=-Wc,
652 ccpl=-Wl,
653 tsts=
654 ccpr='|| for _f in ${tcfn}*; do case $_f in Build.sh|check.pl|check.t|dot.mkshrc|*.1|*.c|*.h|*.ico|*.opt) ;; *) rm -f "$_f" ;; esac; done'
655
656 # Evil hack
657 if test x"$TARGET_OS" = x"Android"; then
658         check_categories="$check_categories android"
659         TARGET_OS=Linux
660 fi
661
662 # Evil OS
663 if test x"$TARGET_OS" = x"Minix"; then
664         echo >&2 "
665 WARNING: additional checks before running Build.sh required!
666 You can avoid these by calling Build.sh correctly, see below.
667 "
668         cat >conftest.c <<'EOF'
669 #include <sys/types.h>
670 const char *
671 #ifdef _NETBSD_SOURCE
672 ct="Ninix3"
673 #else
674 ct="Minix3"
675 #endif
676 ;
677 EOF
678         ct=unknown
679         vv ']' "${CC-cc} -E $CFLAGS $CPPFLAGS $NOWARN conftest.c | grep ct= | tr -d \\\\015 >x"
680         sed 's/^/[ /' x
681         eval `cat x`
682         rmf x vv.out
683         case $ct in
684         Minix3|Ninix3)
685                 echo >&2 "
686 Warning: you set TARGET_OS to $TARGET_OS but that is ambiguous.
687 Please set it to either Minix3 or Ninix3, whereas the latter is
688 all versions of Minix with even partial NetBSD(R) userland. The
689 value determined from your compiler for the current compilation
690 (which may be wrong) is: $ct
691 "
692                 TARGET_OS=$ct
693                 ;;
694         *)
695                 echo >&2 "
696 Warning: you set TARGET_OS to $TARGET_OS but that is ambiguous.
697 Please set it to either Minix3 or Ninix3, whereas the latter is
698 all versions of Minix with even partial NetBSD(R) userland. The
699 proper value couldn't be determined, continue at your own risk.
700 "
701                 ;;
702         esac
703 fi
704
705 # Configuration depending on OS revision, on OSes that need them
706 case $TARGET_OS in
707 NEXTSTEP)
708         test x"$TARGET_OSREV" = x"" && TARGET_OSREV=`hostinfo 2>&1 | \
709             grep 'NeXT Mach [0-9][0-9.]*:' | \
710             sed 's/^.*NeXT Mach \([0-9][0-9.]*\):.*$/\1/'`
711         ;;
712 QNX|SCO_SV)
713         test x"$TARGET_OSREV" = x"" && TARGET_OSREV=`uname -r`
714         ;;
715 esac
716
717 # Configuration depending on OS name
718 case $TARGET_OS in
719 386BSD)
720         : "${HAVE_CAN_OTWO=0}"
721         add_cppflags -DMKSH_NO_SIGSETJMP
722         add_cppflags -DMKSH_TYPEDEF_SIG_ATOMIC_T=int
723         ;;
724 AIX)
725         add_cppflags -D_ALL_SOURCE
726         : "${HAVE_SETLOCALE_CTYPE=0}"
727         ;;
728 BeOS)
729         case $KSH_VERSION in
730         *MIRBSD\ KSH*)
731                 oswarn="; it has minor issues"
732                 ;;
733         *)
734                 oswarn="; you must recompile mksh with"
735                 oswarn="$oswarn${nl}itself in a second stage"
736                 ;;
737         esac
738         # BeOS has no real tty either
739         add_cppflags -DMKSH_UNEMPLOYED
740         add_cppflags -DMKSH_DISABLE_TTY_WARNING
741         # BeOS doesn't have different UIDs and GIDs
742         add_cppflags -DMKSH__NO_SETEUGID
743         ;;
744 BSD/OS)
745         : "${HAVE_SETLOCALE_CTYPE=0}"
746         ;;
747 Coherent)
748         oswarn="; it has major issues"
749         add_cppflags -DMKSH__NO_SYMLINK
750         check_categories="$check_categories nosymlink"
751         add_cppflags -DMKSH__NO_SETEUGID
752         add_cppflags -DMKSH_DISABLE_TTY_WARNING
753         ;;
754 CYGWIN*)
755         : "${HAVE_SETLOCALE_CTYPE=0}"
756         ;;
757 Darwin)
758         add_cppflags -D_DARWIN_C_SOURCE
759         ;;
760 DragonFly)
761         ;;
762 FreeBSD)
763         ;;
764 FreeMiNT)
765         oswarn="; it has minor issues"
766         add_cppflags -D_GNU_SOURCE
767         : "${HAVE_SETLOCALE_CTYPE=0}"
768         ;;
769 GNU)
770         case $CC in
771         *tendracc*) ;;
772         *) add_cppflags -D_GNU_SOURCE ;;
773         esac
774         add_cppflags -DSETUID_CAN_FAIL_WITH_EAGAIN
775         # define MKSH__NO_PATH_MAX to use Hurd-only functions
776         add_cppflags -DMKSH__NO_PATH_MAX
777         ;;
778 GNU/kFreeBSD)
779         case $CC in
780         *tendracc*) ;;
781         *) add_cppflags -D_GNU_SOURCE ;;
782         esac
783         add_cppflags -DSETUID_CAN_FAIL_WITH_EAGAIN
784         ;;
785 Haiku)
786         add_cppflags -DMKSH_ASSUME_UTF8
787         HAVE_ISSET_MKSH_ASSUME_UTF8=1
788         HAVE_ISOFF_MKSH_ASSUME_UTF8=0
789         ;;
790 Harvey)
791         add_cppflags -D_POSIX_SOURCE
792         add_cppflags -D_LIMITS_EXTENSION
793         add_cppflags -D_BSD_EXTENSION
794         add_cppflags -D_SUSV2_SOURCE
795         add_cppflags -D_GNU_SOURCE
796         add_cppflags -DMKSH_ASSUME_UTF8
797         HAVE_ISSET_MKSH_ASSUME_UTF8=1
798         HAVE_ISOFF_MKSH_ASSUME_UTF8=0
799         add_cppflags -DMKSH_NO_CMDLINE_EDITING
800         add_cppflags -DMKSH__NO_SETEUGID
801         oswarn=' and will currently not work'
802         add_cppflags -DMKSH_UNEMPLOYED
803         add_cppflags -DMKSH_NOPROSPECTOFWORK
804         # these taken from Harvey-OS github and need re-checking
805         add_cppflags -D_setjmp=setjmp -D_longjmp=longjmp
806         : "${HAVE_CAN_NO_EH_FRAME=0}"
807         : "${HAVE_CAN_FNOSTRICTALIASING=0}"
808         : "${HAVE_CAN_FSTACKPROTECTORSTRONG=0}"
809         ;;
810 HP-UX)
811         ;;
812 Interix)
813         ccpc='-X '
814         ccpl='-Y '
815         add_cppflags -D_ALL_SOURCE
816         : "${LIBS=-lcrypt}"
817         : "${HAVE_SETLOCALE_CTYPE=0}"
818         ;;
819 IRIX*)
820         : "${HAVE_SETLOCALE_CTYPE=0}"
821         ;;
822 Linux)
823         case $CC in
824         *tendracc*) ;;
825         *) add_cppflags -D_GNU_SOURCE ;;
826         esac
827         add_cppflags -DSETUID_CAN_FAIL_WITH_EAGAIN
828         : "${HAVE_REVOKE=0}"
829         ;;
830 LynxOS)
831         oswarn="; it has minor issues"
832         ;;
833 MidnightBSD)
834         ;;
835 Minix-vmd)
836         add_cppflags -DMKSH__NO_SETEUGID
837         add_cppflags -DMKSH_UNEMPLOYED
838         add_cppflags -D_MINIX_SOURCE
839         oldish_ed=no-stderr-ed          # no /bin/ed, maybe see below
840         : "${HAVE_SETLOCALE_CTYPE=0}"
841         ;;
842 Minix3)
843         add_cppflags -DMKSH_UNEMPLOYED
844         add_cppflags -DMKSH_NO_LIMITS
845         add_cppflags -D_POSIX_SOURCE -D_POSIX_1_SOURCE=2 -D_MINIX
846         oldish_ed=no-stderr-ed          # /usr/bin/ed(!) is broken
847         : "${HAVE_SETLOCALE_CTYPE=0}"
848         ;;
849 MirBSD)
850         ;;
851 MSYS_*)
852         add_cppflags -DMKSH_ASSUME_UTF8=0
853         HAVE_ISSET_MKSH_ASSUME_UTF8=1
854         HAVE_ISOFF_MKSH_ASSUME_UTF8=1
855         # almost same as CYGWIN* (from RT|Chatzilla)
856         : "${HAVE_SETLOCALE_CTYPE=0}"
857         # broken on this OE (from ir0nh34d)
858         : "${HAVE_STDINT_H=0}"
859         ;;
860 NetBSD)
861         ;;
862 NEXTSTEP)
863         add_cppflags -D_NEXT_SOURCE
864         add_cppflags -D_POSIX_SOURCE
865         : "${AWK=gawk}"
866         : "${CC=cc -posix}"
867         add_cppflags -DMKSH_NO_SIGSETJMP
868         # NeXTstep cannot get a controlling tty
869         add_cppflags -DMKSH_UNEMPLOYED
870         case $TARGET_OSREV in
871         4.2*)
872                 # OpenStep 4.2 is broken by default
873                 oswarn="; it needs libposix.a"
874                 ;;
875         esac
876         ;;
877 Ninix3)
878         # similar to Minix3
879         add_cppflags -DMKSH_UNEMPLOYED
880         add_cppflags -DMKSH_NO_LIMITS
881         # but no idea what else could be needed
882         oswarn="; it has unknown issues"
883         ;;
884 OpenBSD)
885         : "${HAVE_SETLOCALE_CTYPE=0}"
886         ;;
887 OS/2)
888         add_cppflags -DMKSH_ASSUME_UTF8=0
889         HAVE_ISSET_MKSH_ASSUME_UTF8=1
890         HAVE_ISOFF_MKSH_ASSUME_UTF8=1
891         HAVE_TERMIOS_H=0
892         HAVE_MKNOD=0    # setmode() incompatible
893         oswarn="; it is being ported"
894         check_categories="$check_categories nosymlink"
895         : "${CC=gcc}"
896         : "${SIZE=: size}"
897         SRCS="$SRCS os2.c"
898         add_cppflags -DMKSH_UNEMPLOYED
899         add_cppflags -DMKSH_NOPROSPECTOFWORK
900         add_cppflags -DMKSH_NO_LIMITS
901         add_cppflags -DMKSH_DOSPATH
902         if test $textmode = 0; then
903                 x='dis'
904                 y='standard OS/2 tools'
905         else
906                 x='en'
907                 y='standard Unix mksh and other tools'
908         fi
909         echo >&2 "
910 OS/2 Note: mksh can be built with or without 'textmode'.
911 Without 'textmode' it will behave like a standard Unix utility,
912 compatible to mksh on all other platforms, using only ASCII LF
913 (0x0A) as line ending character. This is supported by the mksh
914 upstream developer.
915 With 'textmode', mksh will be modified to behave more like other
916 OS/2 utilities, supporting ASCII CR+LF (0x0D 0x0A) as line ending
917 at the cost of deviation from standard mksh. This is supported by
918 the mksh-os2 porter.
919
920 ] You are currently compiling with textmode ${x}abled, introducing
921 ] incompatibilities with $y.
922 "
923         ;;
924 OS/390)
925         add_cppflags -DMKSH_ASSUME_UTF8=0
926         HAVE_ISSET_MKSH_ASSUME_UTF8=1
927         HAVE_ISOFF_MKSH_ASSUME_UTF8=1
928         : "${CC=xlc}"
929         : "${SIZE=: size}"
930         add_cppflags -DMKSH_FOR_Z_OS
931         add_cppflags -D_ALL_SOURCE
932         oswarn='; EBCDIC support is incomplete'
933         ;;
934 OSF1)
935         HAVE_SIG_T=0    # incompatible
936         add_cppflags -D_OSF_SOURCE
937         add_cppflags -D_POSIX_C_SOURCE=200112L
938         add_cppflags -D_XOPEN_SOURCE=600
939         add_cppflags -D_XOPEN_SOURCE_EXTENDED
940         : "${HAVE_SETLOCALE_CTYPE=0}"
941         ;;
942 Plan9)
943         add_cppflags -D_POSIX_SOURCE
944         add_cppflags -D_LIMITS_EXTENSION
945         add_cppflags -D_BSD_EXTENSION
946         add_cppflags -D_SUSV2_SOURCE
947         add_cppflags -DMKSH_ASSUME_UTF8
948         HAVE_ISSET_MKSH_ASSUME_UTF8=1
949         HAVE_ISOFF_MKSH_ASSUME_UTF8=0
950         add_cppflags -DMKSH_NO_CMDLINE_EDITING
951         add_cppflags -DMKSH__NO_SETEUGID
952         oswarn=' and will currently not work'
953         add_cppflags -DMKSH_UNEMPLOYED
954         # this is for detecting kencc
955         add_cppflags -DMKSH_MAYBE_KENCC
956         ;;
957 PW32*)
958         HAVE_SIG_T=0    # incompatible
959         oswarn=' and will currently not work'
960         : "${HAVE_SETLOCALE_CTYPE=0}"
961         ;;
962 QNX)
963         add_cppflags -D__NO_EXT_QNX
964         add_cppflags -D__EXT_UNIX_MISC
965         case $TARGET_OSREV in
966         [012345].*|6.[0123].*|6.4.[01])
967                 oldish_ed=no-stderr-ed          # oldish /bin/ed is broken
968                 ;;
969         esac
970         : "${HAVE_SETLOCALE_CTYPE=0}"
971         ;;
972 SCO_SV)
973         case $TARGET_OSREV in
974         3.2*)
975                 # SCO OpenServer 5
976                 add_cppflags -DMKSH_UNEMPLOYED
977                 ;;
978         5*)
979                 # SCO OpenServer 6
980                 ;;
981         *)
982                 oswarn='; this is an unknown version of'
983                 oswarn="$oswarn$nl$TARGET_OS ${TARGET_OSREV}, please tell me what to do"
984                 ;;
985         esac
986         : "${HAVE_SYS_SIGLIST=0}${HAVE__SYS_SIGLIST=0}"
987         ;;
988 skyos)
989         oswarn="; it has minor issues"
990         ;;
991 SunOS)
992         add_cppflags -D_BSD_SOURCE
993         add_cppflags -D__EXTENSIONS__
994         ;;
995 syllable)
996         add_cppflags -D_GNU_SOURCE
997         add_cppflags -DMKSH_NO_SIGSUSPEND
998         oswarn=' and will currently not work'
999         ;;
1000 ULTRIX)
1001         : "${CC=cc -YPOSIX}"
1002         add_cppflags -DMKSH_TYPEDEF_SSIZE_T=int
1003         : "${HAVE_SETLOCALE_CTYPE=0}"
1004         ;;
1005 UnixWare|UNIX_SV)
1006         # SCO UnixWare
1007         : "${HAVE_SYS_SIGLIST=0}${HAVE__SYS_SIGLIST=0}"
1008         ;;
1009 UWIN*)
1010         ccpc='-Yc,'
1011         ccpl='-Yl,'
1012         tsts=" 3<>/dev/tty"
1013         oswarn="; it will compile, but the target"
1014         oswarn="$oswarn${nl}platform itself is very flakey/unreliable"
1015         : "${HAVE_SETLOCALE_CTYPE=0}"
1016         ;;
1017 _svr4)
1018         # generic target for SVR4 Unix with uname -s = uname -n
1019         # this duplicates the * target below
1020         oswarn='; it may or may not work'
1021         test x"$TARGET_OSREV" = x"" && TARGET_OSREV=`uname -r`
1022         ;;
1023 *)
1024         oswarn='; it may or may not work'
1025         test x"$TARGET_OSREV" = x"" && TARGET_OSREV=`uname -r`
1026         ;;
1027 esac
1028
1029 : "${HAVE_MKNOD=0}"
1030
1031 : "${AWK=awk}${CC=cc}${NROFF=nroff}${SIZE=size}"
1032 test 0 = $r && echo | $NROFF -v 2>&1 | grep GNU >/dev/null 2>&1 && \
1033     echo | $NROFF -c >/dev/null 2>&1 && NROFF="$NROFF -c"
1034
1035 # this aids me in tracing FTBFSen without access to the buildd
1036 $e "Hi from$ao $bi$srcversion$ao on:"
1037 case $TARGET_OS in
1038 AIX)
1039         vv '|' "oslevel >&2"
1040         vv '|' "uname -a >&2"
1041         ;;
1042 Darwin)
1043         vv '|' "hwprefs machine_type os_type os_class >&2"
1044         vv '|' "sw_vers >&2"
1045         vv '|' "system_profiler SPSoftwareDataType SPHardwareDataType >&2"
1046         vv '|' "/bin/sh --version >&2"
1047         vv '|' "xcodebuild -version >&2"
1048         vv '|' "uname -a >&2"
1049         vv '|' "sysctl kern.version hw.machine hw.model hw.memsize hw.availcpu hw.cpufrequency hw.byteorder hw.cpu64bit_capable >&2"
1050         ;;
1051 IRIX*)
1052         vv '|' "uname -a >&2"
1053         vv '|' "hinv -v >&2"
1054         ;;
1055 OSF1)
1056         vv '|' "uname -a >&2"
1057         vv '|' "/usr/sbin/sizer -v >&2"
1058         ;;
1059 SCO_SV|UnixWare|UNIX_SV)
1060         vv '|' "uname -a >&2"
1061         vv '|' "uname -X >&2"
1062         ;;
1063 *)
1064         vv '|' "uname -a >&2"
1065         ;;
1066 esac
1067 test -z "$oswarn" || echo >&2 "
1068 Warning: mksh has not yet been ported to or tested on your
1069 operating system '$TARGET_OS'$oswarn. If you can provide
1070 a shell account to the developer, this may improve; please
1071 drop us a success or failure notice or even send in diffs.
1072 "
1073 $e "$bi$me: Building the MirBSD Korn Shell$ao $ui$dstversion$ao on $TARGET_OS ${TARGET_OSREV}..."
1074
1075 #
1076 # Start of mirtoconf checks
1077 #
1078 $e $bi$me: Scanning for functions... please ignore any errors.$ao
1079
1080 #
1081 # Compiler: which one?
1082 #
1083 # notes:
1084 # - ICC defines __GNUC__ too
1085 # - GCC defines __hpux too
1086 # - LLVM+clang defines __GNUC__ too
1087 # - nwcc defines __GNUC__ too
1088 CPP="$CC -E"
1089 $e ... which compiler type seems to be used
1090 cat >conftest.c <<'EOF'
1091 const char *
1092 #if defined(__ICC) || defined(__INTEL_COMPILER)
1093 ct="icc"
1094 #elif defined(__xlC__) || defined(__IBMC__)
1095 ct="xlc"
1096 #elif defined(__SUNPRO_C)
1097 ct="sunpro"
1098 #elif defined(__ACK__)
1099 ct="ack"
1100 #elif defined(__BORLANDC__)
1101 ct="bcc"
1102 #elif defined(__WATCOMC__)
1103 ct="watcom"
1104 #elif defined(__MWERKS__)
1105 ct="metrowerks"
1106 #elif defined(__HP_cc)
1107 ct="hpcc"
1108 #elif defined(__DECC) || (defined(__osf__) && !defined(__GNUC__))
1109 ct="dec"
1110 #elif defined(__PGI)
1111 ct="pgi"
1112 #elif defined(__DMC__)
1113 ct="dmc"
1114 #elif defined(_MSC_VER)
1115 ct="msc"
1116 #elif defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__)
1117 ct="adsp"
1118 #elif defined(__IAR_SYSTEMS_ICC__)
1119 ct="iar"
1120 #elif defined(SDCC)
1121 ct="sdcc"
1122 #elif defined(__PCC__)
1123 ct="pcc"
1124 #elif defined(__TenDRA__)
1125 ct="tendra"
1126 #elif defined(__TINYC__)
1127 ct="tcc"
1128 #elif defined(__llvm__) && defined(__clang__)
1129 ct="clang"
1130 #elif defined(__NWCC__)
1131 ct="nwcc"
1132 #elif defined(__GNUC__)
1133 ct="gcc"
1134 #elif defined(_COMPILER_VERSION)
1135 ct="mipspro"
1136 #elif defined(__sgi)
1137 ct="mipspro"
1138 #elif defined(__hpux) || defined(__hpua)
1139 ct="hpcc"
1140 #elif defined(__ultrix)
1141 ct="ucode"
1142 #elif defined(__USLC__)
1143 ct="uslc"
1144 #elif defined(__LCC__)
1145 ct="lcc"
1146 #elif defined(MKSH_MAYBE_KENCC)
1147 /* and none of the above matches */
1148 ct="kencc"
1149 #else
1150 ct="unknown"
1151 #endif
1152 ;
1153 const char *
1154 #if defined(__KLIBC__) && !defined(__OS2__)
1155 et="klibc"
1156 #else
1157 et="unknown"
1158 #endif
1159 ;
1160 EOF
1161 ct=untested
1162 et=untested
1163 vv ']' "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c | \
1164     sed -n '/^ *[ce]t *= */s/^ *\([ce]t\) *= */\1=/p' | tr -d \\\\015 >x"
1165 sed 's/^/[ /' x
1166 eval `cat x`
1167 rmf x vv.out
1168 cat >conftest.c <<'EOF'
1169 #include <unistd.h>
1170 int main(void) { return (isatty(0)); }
1171 EOF
1172 case $ct in
1173 ack)
1174         # work around "the famous ACK const bug"
1175         CPPFLAGS="-Dconst= $CPPFLAGS"
1176         ;;
1177 adsp)
1178         echo >&2 'Warning: Analog Devices C++ compiler for Blackfin, TigerSHARC
1179     and SHARC (21000) DSPs detected. This compiler has not yet
1180     been tested for compatibility with mksh. Continue at your
1181     own risk, please report success/failure to the developers.'
1182         ;;
1183 bcc)
1184         echo >&2 "Warning: Borland C++ Builder detected. This compiler might
1185     produce broken executables. Continue at your own risk,
1186     please report success/failure to the developers."
1187         ;;
1188 clang)
1189         # does not work with current "ccc" compiler driver
1190         vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -version"
1191         # one of these two works, for now
1192         vv '|' "${CLANG-clang} -version"
1193         vv '|' "${CLANG-clang} --version"
1194         # ensure compiler and linker are in sync unless overridden
1195         case $CCC_CC:$CCC_LD in
1196         :*)     ;;
1197         *:)     CCC_LD=$CCC_CC; export CCC_LD ;;
1198         esac
1199         : "${HAVE_STRING_POOLING=i1}"
1200         ;;
1201 dec)
1202         vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V"
1203         vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -Wl,-V conftest.c $LIBS"
1204         ;;
1205 dmc)
1206         echo >&2 "Warning: Digital Mars Compiler detected. When running under"
1207         echo >&2 "    UWIN, mksh tends to be unstable due to the limitations"
1208         echo >&2 "    of this platform. Continue at your own risk,"
1209         echo >&2 "    please report success/failure to the developers."
1210         ;;
1211 gcc)
1212         vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS"
1213         vv '|' 'echo `$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS \
1214             -dumpmachine` gcc`$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN \
1215             $LIBS -dumpversion`'
1216         : "${HAVE_STRING_POOLING=i2}"
1217         ;;
1218 hpcc)
1219         vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
1220         ;;
1221 iar)
1222         echo >&2 'Warning: IAR Systems (http://www.iar.com) compiler for embedded
1223     systems detected. This unsupported compiler has not yet
1224     been tested for compatibility with mksh. Continue at your
1225     own risk, please report success/failure to the developers.'
1226         ;;
1227 icc)
1228         vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V"
1229         ;;
1230 kencc)
1231         vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS"
1232         ;;
1233 lcc)
1234         vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS"
1235         add_cppflags -D__inline__=__inline
1236         ;;
1237 metrowerks)
1238         echo >&2 'Warning: Metrowerks C compiler detected. This has not yet
1239     been tested for compatibility with mksh. Continue at your
1240     own risk, please report success/failure to the developers.'
1241         ;;
1242 mipspro)
1243         vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -version"
1244         ;;
1245 msc)
1246         ccpr=           # errorlevels are not reliable
1247         case $TARGET_OS in
1248         Interix)
1249                 if [[ -n $C89_COMPILER ]]; then
1250                         C89_COMPILER=`ntpath2posix -c "$C89_COMPILER"`
1251                 else
1252                         C89_COMPILER=CL.EXE
1253                 fi
1254                 if [[ -n $C89_LINKER ]]; then
1255                         C89_LINKER=`ntpath2posix -c "$C89_LINKER"`
1256                 else
1257                         C89_LINKER=LINK.EXE
1258                 fi
1259                 vv '|' "$C89_COMPILER /HELP >&2"
1260                 vv '|' "$C89_LINKER /LINK >&2"
1261                 ;;
1262         esac
1263         ;;
1264 nwcc)
1265         vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -version"
1266         ;;
1267 pcc)
1268         vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -v"
1269         ;;
1270 pgi)
1271         echo >&2 'Warning: PGI detected. This unknown compiler has not yet
1272     been tested for compatibility with mksh. Continue at your
1273     own risk, please report success/failure to the developers.'
1274         ;;
1275 sdcc)
1276         echo >&2 'Warning: sdcc (http://sdcc.sourceforge.net), the small devices
1277     C compiler for embedded systems detected. This has not yet
1278     been tested for compatibility with mksh. Continue at your
1279     own risk, please report success/failure to the developers.'
1280         ;;
1281 sunpro)
1282         vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
1283         ;;
1284 tcc)
1285         vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -v"
1286         ;;
1287 tendra)
1288         vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V 2>&1 | \
1289             grep -F -i -e version -e release"
1290         ;;
1291 ucode)
1292         vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V"
1293         vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -Wl,-V conftest.c $LIBS"
1294         ;;
1295 uslc)
1296         case $TARGET_OS:$TARGET_OSREV in
1297         SCO_SV:3.2*)
1298                 # SCO OpenServer 5
1299                 CFLAGS="$CFLAGS -g"
1300                 : "${HAVE_CAN_OTWO=0}${HAVE_CAN_OPTIMISE=0}"
1301                 ;;
1302         esac
1303         vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
1304         ;;
1305 watcom)
1306         vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS"
1307         ;;
1308 xlc)
1309         vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -qversion"
1310         vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -qversion=verbose"
1311         vv '|' "ld -V"
1312         ;;
1313 *)
1314         test x"$ct" = x"untested" && $e "!!! detecting preprocessor failed"
1315         ct=unknown
1316         vv "$CC --version"
1317         vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS"
1318         vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
1319         ;;
1320 esac
1321 case $cm in
1322 dragonegg|llvm)
1323         vv '|' "llc -version"
1324         ;;
1325 esac
1326 etd=" on $et"
1327 case $et in
1328 klibc)
1329         add_cppflags -DMKSH_NO_LIMITS
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_testn compiler_still_fails '' 'if the compiler still does not fail correctly' <<-EOF
1377         EOF
1378         test 1 = $HAVE_COMPILER_STILL_FAILS && exit 1
1379 fi
1380 if ac_ifcpp 'ifdef __TINYC__' couldbe_tcc '!' compiler_known 0 \
1381     'if this could be tcc'; then
1382         ct=tcc
1383         CPP='cpp -D__TINYC__'
1384         HAVE_COMPILER_KNOWN=1
1385 fi
1386
1387 case $ct in
1388 bcc)
1389         save_NOWARN="${ccpc}-w"
1390         DOWARN="${ccpc}-w!"
1391         ;;
1392 dec)
1393         # -msg_* flags not used yet, or is -w2 correct?
1394         ;;
1395 dmc)
1396         save_NOWARN="${ccpc}-w"
1397         DOWARN="${ccpc}-wx"
1398         ;;
1399 hpcc)
1400         save_NOWARN=
1401         DOWARN=+We
1402         ;;
1403 kencc)
1404         save_NOWARN=
1405         DOWARN=
1406         ;;
1407 mipspro)
1408         save_NOWARN=
1409         DOWARN="-diag_error 1-10000"
1410         ;;
1411 msc)
1412         save_NOWARN="${ccpc}/w"
1413         DOWARN="${ccpc}/WX"
1414         ;;
1415 sunpro)
1416         test x"$save_NOWARN" = x"" && save_NOWARN='-errwarn=%none'
1417         ac_flags 0 errwarnnone "$save_NOWARN"
1418         test 1 = $HAVE_CAN_ERRWARNNONE || save_NOWARN=
1419         ac_flags 0 errwarnall "-errwarn=%all"
1420         test 1 = $HAVE_CAN_ERRWARNALL && DOWARN="-errwarn=%all"
1421         ;;
1422 tendra)
1423         save_NOWARN=-w
1424         ;;
1425 ucode)
1426         save_NOWARN=
1427         DOWARN=-w2
1428         ;;
1429 watcom)
1430         save_NOWARN=
1431         DOWARN=-Wc,-we
1432         ;;
1433 xlc)
1434         case $TARGET_OS in
1435         OS/390)
1436                 save_NOWARN=-qflag=e
1437                 DOWARN=-qflag=i
1438                 ;;
1439         *)
1440                 save_NOWARN=-qflag=i:e
1441                 DOWARN=-qflag=i:i
1442                 ;;
1443         esac
1444         ;;
1445 *)
1446         test x"$save_NOWARN" = x"" && save_NOWARN=-Wno-error
1447         ac_flags 0 wnoerror "$save_NOWARN"
1448         test 1 = $HAVE_CAN_WNOERROR || save_NOWARN=
1449         ac_flags 0 werror -Werror
1450         test 1 = $HAVE_CAN_WERROR && DOWARN=-Werror
1451         test $ct = icc && DOWARN="$DOWARN -wd1419"
1452         ;;
1453 esac
1454 NOWARN=$save_NOWARN
1455
1456 #
1457 # Compiler: extra flags (-O2 -f* -W* etc.)
1458 #
1459 i=`echo :"$orig_CFLAGS" | sed 's/^://' | tr -c -d $alll$allu$alln`
1460 # optimisation: only if orig_CFLAGS is empty
1461 test x"$i" = x"" && case $ct in
1462 hpcc)
1463         phase=u
1464         ac_flags 1 otwo +O2
1465         phase=x
1466         ;;
1467 kencc|tcc|tendra)
1468         # no special optimisation
1469         ;;
1470 sunpro)
1471         cat >x <<-'EOF'
1472                 #include <unistd.h>
1473                 int main(void) { return (isatty(0)); }
1474                 #define __IDSTRING_CONCAT(l,p)  __LINTED__ ## l ## _ ## p
1475                 #define __IDSTRING_EXPAND(l,p)  __IDSTRING_CONCAT(l,p)
1476                 #define pad                     void __IDSTRING_EXPAND(__LINE__,x)(void) { }
1477         EOF
1478         yes pad | head -n 256 >>x
1479         ac_flags - 1 otwo -xO2 <x
1480         rmf x
1481         ;;
1482 xlc)
1483         ac_flags 1 othree "-O3 -qstrict"
1484         test 1 = $HAVE_CAN_OTHREE || ac_flags 1 otwo -O2
1485         ;;
1486 *)
1487         ac_flags 1 otwo -O2
1488         test 1 = $HAVE_CAN_OTWO || ac_flags 1 optimise -O
1489         ;;
1490 esac
1491 # other flags: just add them if they are supported
1492 i=0
1493 case $ct in
1494 bcc)
1495         ac_flags 1 strpool "${ccpc}-d" 'if string pooling can be enabled'
1496         ;;
1497 clang)
1498         i=1
1499         ;;
1500 dec)
1501         ac_flags 0 verb -verbose
1502         ac_flags 1 rodata -readonly_strings
1503         ;;
1504 dmc)
1505         ac_flags 1 decl "${ccpc}-r" 'for strict prototype checks'
1506         ac_flags 1 schk "${ccpc}-s" 'for stack overflow checking'
1507         ;;
1508 gcc)
1509         # The following tests run with -Werror (gcc only) if possible
1510         NOWARN=$DOWARN; phase=u
1511         ac_flags 1 wnodeprecateddecls -Wno-deprecated-declarations
1512         # mksh is not written in CFrustFrust!
1513         ac_flags 1 no_eh_frame -fno-asynchronous-unwind-tables
1514         ac_flags 1 fnostrictaliasing -fno-strict-aliasing
1515         ac_flags 1 fstackprotectorstrong -fstack-protector-strong
1516         test 1 = $HAVE_CAN_FSTACKPROTECTORSTRONG || \
1517             ac_flags 1 fstackprotectorall -fstack-protector-all
1518         test $cm = dragonegg && case " $CC $CFLAGS $LDFLAGS " in
1519         *\ -fplugin=*dragonegg*) ;;
1520         *) ac_flags 1 fplugin_dragonegg -fplugin=dragonegg ;;
1521         esac
1522         case $cm in
1523         combine)
1524                 fv=0
1525                 checks='7 8'
1526                 ;;
1527         lto)
1528                 fv=0
1529                 checks='1 2 3 4 5 6 7 8'
1530                 ;;
1531         *)
1532                 fv=1
1533                 ;;
1534         esac
1535         test $fv = 1 || for what in $checks; do
1536                 test $fv = 1 && break
1537                 case $what in
1538                 1)      t_cflags='-flto=jobserver'
1539                         t_ldflags='-fuse-linker-plugin'
1540                         t_use=1 t_name=fltojs_lp ;;
1541                 2)      t_cflags='-flto=jobserver' t_ldflags=''
1542                         t_use=1 t_name=fltojs_nn ;;
1543                 3)      t_cflags='-flto=jobserver'
1544                         t_ldflags='-fno-use-linker-plugin -fwhole-program'
1545                         t_use=1 t_name=fltojs_np ;;
1546                 4)      t_cflags='-flto'
1547                         t_ldflags='-fuse-linker-plugin'
1548                         t_use=1 t_name=fltons_lp ;;
1549                 5)      t_cflags='-flto' t_ldflags=''
1550                         t_use=1 t_name=fltons_nn ;;
1551                 6)      t_cflags='-flto'
1552                         t_ldflags='-fno-use-linker-plugin -fwhole-program'
1553                         t_use=1 t_name=fltons_np ;;
1554                 7)      t_cflags='-fwhole-program --combine' t_ldflags=''
1555                         t_use=0 t_name=combine cm=combine ;;
1556                 8)      fv=1 cm=normal ;;
1557                 esac
1558                 test $fv = 1 && break
1559                 ac_flags $t_use $t_name "$t_cflags" \
1560                     "if gcc supports $t_cflags $t_ldflags" "$t_ldflags"
1561         done
1562         ac_flags 1 data_abi_align -malign-data=abi
1563         i=1
1564         ;;
1565 hpcc)
1566         phase=u
1567         # probably not needed
1568         #ac_flags 1 agcc -Agcc 'for support of GCC extensions'
1569         phase=x
1570         ;;
1571 icc)
1572         ac_flags 1 fnobuiltinsetmode -fno-builtin-setmode
1573         ac_flags 1 fnostrictaliasing -fno-strict-aliasing
1574         ac_flags 1 fstacksecuritycheck -fstack-security-check
1575         i=1
1576         ;;
1577 mipspro)
1578         ac_flags 1 fullwarn -fullwarn 'for remark output support'
1579         ;;
1580 msc)
1581         ac_flags 1 strpool "${ccpc}/GF" 'if string pooling can be enabled'
1582         echo 'int main(void) { char test[64] = ""; return (*test); }' >x
1583         ac_flags - 1 stackon "${ccpc}/GZ" 'if stack checks can be enabled' <x
1584         ac_flags - 1 stckall "${ccpc}/Ge" 'stack checks for all functions' <x
1585         ac_flags - 1 secuchk "${ccpc}/GS" 'for compiler security checks' <x
1586         rmf x
1587         ac_flags 1 wall "${ccpc}/Wall" 'to enable all warnings'
1588         ac_flags 1 wp64 "${ccpc}/Wp64" 'to enable 64-bit warnings'
1589         ;;
1590 nwcc)
1591         #broken# ac_flags 1 ssp -stackprotect
1592         i=1
1593         ;;
1594 pcc)
1595         ac_flags 1 fstackprotectorall -fstack-protector-all
1596         i=1
1597         ;;
1598 sunpro)
1599         phase=u
1600         ac_flags 1 v -v
1601         ac_flags 1 ipo -xipo 'for cross-module optimisation'
1602         phase=x
1603         ;;
1604 tcc)
1605         : #broken# ac_flags 1 boundschk -b
1606         ;;
1607 tendra)
1608         ac_flags 0 ysystem -Ysystem
1609         test 1 = $HAVE_CAN_YSYSTEM && CPPFLAGS="-Ysystem $CPPFLAGS"
1610         ac_flags 1 extansi -Xa
1611         ;;
1612 xlc)
1613         case $TARGET_OS in
1614         OS/390)
1615                 # On IBM z/OS, the following are warnings by default:
1616                 # CCN3296: #include file <foo.h> not found.
1617                 # CCN3944: Attribute "__foo__" is not supported and is ignored.
1618                 # CCN3963: The attribute "foo" is not a valid variable attribute and is ignored.
1619                 ac_flags 1 halton '-qhaltonmsg=CCN3296 -qhaltonmsg=CCN3944 -qhaltonmsg=CCN3963'
1620                 # CCN3290: Unknown macro name FOO on #undef directive.
1621                 # CCN4108: The use of keyword '__attribute__' is non-portable.
1622                 ac_flags 1 supprss '-qsuppress=CCN3290 -qsuppress=CCN4108'
1623                 ;;
1624         *)
1625                 ac_flags 1 rodata '-qro -qroconst -qroptr'
1626                 ac_flags 1 rtcheck -qcheck=all
1627                 #ac_flags 1 rtchkc -qextchk     # reported broken
1628                 ac_flags 1 wformat '-qformat=all -qformat=nozln'
1629                 ;;
1630         esac
1631         #ac_flags 1 wp64 -qwarn64       # too verbose for now
1632         ;;
1633 esac
1634 # flags common to a subset of compilers (run with -Werror on gcc)
1635 if test 1 = $i; then
1636         ac_flags 1 wall -Wall
1637         ac_flags 1 fwrapv -fwrapv
1638 fi
1639
1640 # “on demand” means: GCC version >= 4
1641 fd='if to rely on compiler for string pooling'
1642 ac_cache string_pooling || case $HAVE_STRING_POOLING in
1643 2) fx=' (on demand, cached)' ;;
1644 i1) fv=1 ;;
1645 i2) fv=2; fx=' (on demand)' ;;
1646 esac
1647 ac_testdone
1648 test x"$HAVE_STRING_POOLING" = x"0" || ac_cppflags
1649
1650 phase=x
1651 # The following tests run with -Werror or similar (all compilers) if possible
1652 NOWARN=$DOWARN
1653 test $ct = pcc && phase=u
1654
1655 #
1656 # Compiler: check for stuff that only generates warnings
1657 #
1658 ac_test attribute_bounded '' 'for __attribute__((__bounded__))' <<-'EOF'
1659         #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
1660         extern int thiswillneverbedefinedIhope(void);
1661         /* force a failure: TenDRA and gcc 1.42 have false positive here */
1662         int main(void) { return (thiswillneverbedefinedIhope()); }
1663         #else
1664         #include <string.h>
1665         #undef __attribute__
1666         int xcopy(const void *, void *, size_t)
1667             __attribute__((__bounded__(__buffer__, 1, 3)))
1668             __attribute__((__bounded__(__buffer__, 2, 3)));
1669         int main(int ac, char *av[]) { return (xcopy(av[0], av[--ac], 1)); }
1670         int xcopy(const void *s, void *d, size_t n) {
1671                 /*
1672                  * if memmove does not exist, we are not on a system
1673                  * with GCC with __bounded__ attribute either so poo
1674                  */
1675                 memmove(d, s, n); return ((int)n);
1676         }
1677         #endif
1678 EOF
1679 ac_test attribute_format '' 'for __attribute__((__format__))' <<-'EOF'
1680         #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
1681         extern int thiswillneverbedefinedIhope(void);
1682         /* force a failure: TenDRA and gcc 1.42 have false positive here */
1683         int main(void) { return (thiswillneverbedefinedIhope()); }
1684         #else
1685         #define fprintf printfoo
1686         #include <stdio.h>
1687         #undef __attribute__
1688         #undef fprintf
1689         extern int fprintf(FILE *, const char *format, ...)
1690             __attribute__((__format__(__printf__, 2, 3)));
1691         int main(int ac, char **av) { return (fprintf(stderr, "%s%d", *av, ac)); }
1692         #endif
1693 EOF
1694 ac_test attribute_noreturn '' 'for __attribute__((__noreturn__))' <<-'EOF'
1695         #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
1696         extern int thiswillneverbedefinedIhope(void);
1697         /* force a failure: TenDRA and gcc 1.42 have false positive here */
1698         int main(void) { return (thiswillneverbedefinedIhope()); }
1699         #else
1700         #include <stdlib.h>
1701         #undef __attribute__
1702         void fnord(void) __attribute__((__noreturn__));
1703         int main(void) { fnord(); }
1704         void fnord(void) { exit(0); }
1705         #endif
1706 EOF
1707 ac_test attribute_pure '' 'for __attribute__((__pure__))' <<-'EOF'
1708         #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
1709         extern int thiswillneverbedefinedIhope(void);
1710         /* force a failure: TenDRA and gcc 1.42 have false positive here */
1711         int main(void) { return (thiswillneverbedefinedIhope()); }
1712         #else
1713         #include <unistd.h>
1714         #undef __attribute__
1715         int foo(const char *) __attribute__((__pure__));
1716         int main(int ac, char **av) { return (foo(av[ac - 1]) + isatty(0)); }
1717         int foo(const char *s) { return ((int)s[0]); }
1718         #endif
1719 EOF
1720 ac_test attribute_unused '' 'for __attribute__((__unused__))' <<-'EOF'
1721         #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
1722         extern int thiswillneverbedefinedIhope(void);
1723         /* force a failure: TenDRA and gcc 1.42 have false positive here */
1724         int main(void) { return (thiswillneverbedefinedIhope()); }
1725         #else
1726         #include <unistd.h>
1727         #undef __attribute__
1728         int main(int ac __attribute__((__unused__)), char **av
1729             __attribute__((__unused__))) { return (isatty(0)); }
1730         #endif
1731 EOF
1732 ac_test attribute_used '' 'for __attribute__((__used__))' <<-'EOF'
1733         #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
1734         extern int thiswillneverbedefinedIhope(void);
1735         /* force a failure: TenDRA and gcc 1.42 have false positive here */
1736         int main(void) { return (thiswillneverbedefinedIhope()); }
1737         #else
1738         #include <unistd.h>
1739         #undef __attribute__
1740         static const char fnord[] __attribute__((__used__)) = "42";
1741         int main(void) { return (isatty(0)); }
1742         #endif
1743 EOF
1744
1745 # End of tests run with -Werror
1746 NOWARN=$save_NOWARN
1747 phase=x
1748
1749 #
1750 # mksh: flavours (full/small mksh, omit certain stuff)
1751 #
1752 if ac_ifcpp 'ifdef MKSH_SMALL' isset_MKSH_SMALL '' \
1753     "if a reduced-feature mksh is requested"; then
1754         : "${HAVE_NICE=0}"
1755         : "${HAVE_PERSISTENT_HISTORY=0}"
1756         check_categories="$check_categories smksh"
1757 fi
1758 ac_ifcpp 'if defined(MKSH_BINSHPOSIX) || defined(MKSH_BINSHREDUCED)' \
1759     isset_MKSH_BINSH '' 'if invoking as sh should be handled specially' && \
1760     check_categories="$check_categories binsh"
1761 ac_ifcpp 'ifdef MKSH_UNEMPLOYED' isset_MKSH_UNEMPLOYED '' \
1762     "if mksh will be built without job control" && \
1763     check_categories="$check_categories arge"
1764 ac_ifcpp 'ifdef MKSH_NOPROSPECTOFWORK' isset_MKSH_NOPROSPECTOFWORK '' \
1765     "if mksh will be built without job signals" && \
1766     check_categories="$check_categories arge nojsig"
1767 ac_ifcpp 'ifdef MKSH_ASSUME_UTF8' isset_MKSH_ASSUME_UTF8 '' \
1768     'if the default UTF-8 mode is specified' && : "${HAVE_SETLOCALE_CTYPE=0}"
1769 ac_ifcpp 'if !MKSH_ASSUME_UTF8' isoff_MKSH_ASSUME_UTF8 \
1770     isset_MKSH_ASSUME_UTF8 0 \
1771     'if the default UTF-8 mode is disabled' && \
1772     check_categories="$check_categories noutf8"
1773 #ac_ifcpp 'ifdef MKSH_DISABLE_DEPRECATED' isset_MKSH_DISABLE_DEPRECATED '' \
1774 #    "if deprecated features are to be omitted" && \
1775 #    check_categories="$check_categories nodeprecated"
1776 #ac_ifcpp 'ifdef MKSH_DISABLE_EXPERIMENTAL' isset_MKSH_DISABLE_EXPERIMENTAL '' \
1777 #    "if experimental features are to be omitted" && \
1778 #    check_categories="$check_categories noexperimental"
1779 ac_ifcpp 'ifdef MKSH_MIDNIGHTBSD01ASH_COMPAT' isset_MKSH_MIDNIGHTBSD01ASH_COMPAT '' \
1780     'if the MidnightBSD 0.1 ash compatibility mode is requested' && \
1781     check_categories="$check_categories mnbsdash"
1782
1783 #
1784 # Environment: headers
1785 #
1786 ac_header sys/time.h sys/types.h
1787 ac_header time.h sys/types.h
1788 test "11" = "$HAVE_SYS_TIME_H$HAVE_TIME_H" || HAVE_BOTH_TIME_H=0
1789 ac_test both_time_h '' 'whether <sys/time.h> and <time.h> can both be included' <<-'EOF'
1790         #include <sys/types.h>
1791         #include <sys/time.h>
1792         #include <time.h>
1793         #include <unistd.h>
1794         int main(void) { struct tm tm; return ((int)sizeof(tm) + isatty(0)); }
1795 EOF
1796 ac_header sys/bsdtypes.h
1797 ac_header sys/file.h sys/types.h
1798 ac_header sys/mkdev.h sys/types.h
1799 ac_header sys/mman.h sys/types.h
1800 ac_header sys/param.h
1801 ac_header sys/resource.h sys/types.h _time
1802 ac_header sys/select.h sys/types.h
1803 ac_header sys/sysmacros.h
1804 ac_header bstring.h
1805 ac_header grp.h sys/types.h
1806 ac_header io.h
1807 ac_header libgen.h
1808 ac_header libutil.h sys/types.h
1809 ac_header paths.h
1810 ac_header stdint.h stdarg.h
1811 # include strings.h only if compatible with string.h
1812 ac_header strings.h sys/types.h string.h
1813 ac_header termios.h
1814 ac_header ulimit.h sys/types.h
1815 ac_header values.h
1816
1817 #
1818 # Environment: definitions
1819 #
1820 echo '#include <sys/types.h>
1821 #include <unistd.h>
1822 /* check that off_t can represent 2^63-1 correctly, thx FSF */
1823 #define LARGE_OFF_T ((((off_t)1 << 31) << 31) - 1 + (((off_t)1 << 31) << 31))
1824 int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 &&
1825     LARGE_OFF_T % 2147483647 == 1) ? 1 : -1];
1826 int main(void) { return (isatty(0)); }' >lft.c
1827 ac_testn can_lfs '' "for large file support" <lft.c
1828 save_CPPFLAGS=$CPPFLAGS
1829 add_cppflags -D_FILE_OFFSET_BITS=64
1830 ac_testn can_lfs_sus '!' can_lfs 0 "... with -D_FILE_OFFSET_BITS=64" <lft.c
1831 if test 0 = $HAVE_CAN_LFS_SUS; then
1832         CPPFLAGS=$save_CPPFLAGS
1833         add_cppflags -D_LARGE_FILES=1
1834         ac_testn can_lfs_aix '!' can_lfs 0 "... with -D_LARGE_FILES=1" <lft.c
1835         test 1 = $HAVE_CAN_LFS_AIX || CPPFLAGS=$save_CPPFLAGS
1836 fi
1837 rm -f lft.c
1838 rmf lft*        # end of large file support test
1839
1840 #
1841 # Environment: types
1842 #
1843 ac_test can_inttypes '!' stdint_h 1 "for standard 32-bit integer types" <<-'EOF'
1844         #include <sys/types.h>
1845         #include <stddef.h>
1846         int main(int ac, char **av) { return ((uint32_t)(size_t)*av + (int32_t)ac); }
1847 EOF
1848 ac_test can_ucbints '!' can_inttypes 1 "for UCB 32-bit integer types" <<-'EOF'
1849         #include <sys/types.h>
1850         #include <stddef.h>
1851         int main(int ac, char **av) { return ((u_int32_t)(size_t)*av + (int32_t)ac); }
1852 EOF
1853 ac_test can_int8type '!' stdint_h 1 "for standard 8-bit integer type" <<-'EOF'
1854         #include <sys/types.h>
1855         #include <stddef.h>
1856         int main(int ac, char **av) { return ((uint8_t)(size_t)av[ac]); }
1857 EOF
1858 ac_test can_ucbint8 '!' can_int8type 1 "for UCB 8-bit integer type" <<-'EOF'
1859         #include <sys/types.h>
1860         #include <stddef.h>
1861         int main(int ac, char **av) { return ((u_int8_t)(size_t)av[ac]); }
1862 EOF
1863
1864 ac_test rlim_t <<-'EOF'
1865         #include <sys/types.h>
1866         #if HAVE_BOTH_TIME_H
1867         #include <sys/time.h>
1868         #include <time.h>
1869         #elif HAVE_SYS_TIME_H
1870         #include <sys/time.h>
1871         #elif HAVE_TIME_H
1872         #include <time.h>
1873         #endif
1874         #if HAVE_SYS_RESOURCE_H
1875         #include <sys/resource.h>
1876         #endif
1877         #include <unistd.h>
1878         int main(void) { return (((int)(rlim_t)0) + isatty(0)); }
1879 EOF
1880
1881 # only testn: added later below
1882 ac_testn sig_t <<-'EOF'
1883         #include <sys/types.h>
1884         #include <signal.h>
1885         #include <stddef.h>
1886         volatile sig_t foo = (sig_t)0;
1887         int main(void) { return (foo == (sig_t)0); }
1888 EOF
1889
1890 ac_testn sighandler_t '!' sig_t 0 <<-'EOF'
1891         #include <sys/types.h>
1892         #include <signal.h>
1893         #include <stddef.h>
1894         volatile sighandler_t foo = (sighandler_t)0;
1895         int main(void) { return (foo == (sighandler_t)0); }
1896 EOF
1897 if test 1 = $HAVE_SIGHANDLER_T; then
1898         add_cppflags -Dsig_t=sighandler_t
1899         HAVE_SIG_T=1
1900 fi
1901
1902 ac_testn __sighandler_t '!' sig_t 0 <<-'EOF'
1903         #include <sys/types.h>
1904         #include <signal.h>
1905         #include <stddef.h>
1906         volatile __sighandler_t foo = (__sighandler_t)0;
1907         int main(void) { return (foo == (__sighandler_t)0); }
1908 EOF
1909 if test 1 = $HAVE___SIGHANDLER_T; then
1910         add_cppflags -Dsig_t=__sighandler_t
1911         HAVE_SIG_T=1
1912 fi
1913
1914 test 1 = $HAVE_SIG_T || add_cppflags -Dsig_t=nosig_t
1915 ac_cppflags SIG_T
1916
1917 #
1918 # check whether whatever we use for the final link will succeed
1919 #
1920 if test $cm = makefile; then
1921         : nothing to check
1922 else
1923         HAVE_LINK_WORKS=x
1924         ac_testinit link_works '' 'checking if the final link command may succeed'
1925         fv=1
1926         cat >conftest.c <<-EOF
1927                 #define EXTERN
1928                 #define MKSH_INCLUDES_ONLY
1929                 #include "sh.h"
1930                 __RCSID("$srcversion");
1931                 int main(void) { printf("Hello, World!\\n"); return (isatty(0)); }
1932 EOF
1933         case $cm in
1934         llvm)
1935                 v "$CC $CFLAGS $CPPFLAGS $NOWARN -emit-llvm -c conftest.c" || fv=0
1936                 rmf $tfn.s
1937                 test $fv = 0 || v "llvm-link -o - conftest.o | opt $optflags | llc -o $tfn.s" || fv=0
1938                 test $fv = 0 || v "$CC $CFLAGS $LDFLAGS -o $tcfn $tfn.s $LIBS $ccpr"
1939                 ;;
1940         dragonegg)
1941                 v "$CC $CFLAGS $CPPFLAGS $NOWARN -S -flto conftest.c" || fv=0
1942                 test $fv = 0 || v "mv conftest.s conftest.ll"
1943                 test $fv = 0 || v "llvm-as conftest.ll" || fv=0
1944                 rmf $tfn.s
1945                 test $fv = 0 || v "llvm-link -o - conftest.bc | opt $optflags | llc -o $tfn.s" || fv=0
1946                 test $fv = 0 || v "$CC $CFLAGS $LDFLAGS -o $tcfn $tfn.s $LIBS $ccpr"
1947                 ;;
1948         combine)
1949                 v "$CC $CFLAGS $CPPFLAGS $LDFLAGS -fwhole-program --combine $NOWARN -o $tcfn conftest.c $LIBS $ccpr"
1950                 ;;
1951         lto|normal)
1952                 cm=normal
1953                 v "$CC $CFLAGS $CPPFLAGS $NOWARN -c conftest.c" || fv=0
1954                 test $fv = 0 || v "$CC $CFLAGS $LDFLAGS -o $tcfn conftest.o $LIBS $ccpr"
1955                 ;;
1956         esac
1957         test -f $tcfn || fv=0
1958         ac_testdone
1959         test $fv = 1 || exit 1
1960 fi
1961
1962 #
1963 # Environment: errors and signals
1964 #
1965 test x"NetBSD" = x"$TARGET_OS" && $e Ignore the compatibility warning.
1966
1967 ac_testn sys_errlist '' "the sys_errlist[] array and sys_nerr" <<-'EOF'
1968         extern const int sys_nerr;
1969         extern const char * const sys_errlist[];
1970         extern int isatty(int);
1971         int main(void) { return (*sys_errlist[sys_nerr - 1] + isatty(0)); }
1972 EOF
1973 ac_testn _sys_errlist '!' sys_errlist 0 "the _sys_errlist[] array and _sys_nerr" <<-'EOF'
1974         extern const int _sys_nerr;
1975         extern const char * const _sys_errlist[];
1976         extern int isatty(int);
1977         int main(void) { return (*_sys_errlist[_sys_nerr - 1] + isatty(0)); }
1978 EOF
1979 if test 1 = "$HAVE__SYS_ERRLIST"; then
1980         add_cppflags -Dsys_nerr=_sys_nerr
1981         add_cppflags -Dsys_errlist=_sys_errlist
1982         HAVE_SYS_ERRLIST=1
1983 fi
1984 ac_cppflags SYS_ERRLIST
1985
1986 for what in name list; do
1987         uwhat=`upper $what`
1988         ac_testn sys_sig$what '' "the sys_sig${what}[] array" <<-EOF
1989                 extern const char * const sys_sig${what}[];
1990                 extern int isatty(int);
1991                 int main(void) { return (sys_sig${what}[0][0] + isatty(0)); }
1992         EOF
1993         ac_testn _sys_sig$what '!' sys_sig$what 0 "the _sys_sig${what}[] array" <<-EOF
1994                 extern const char * const _sys_sig${what}[];
1995                 extern int isatty(int);
1996                 int main(void) { return (_sys_sig${what}[0][0] + isatty(0)); }
1997         EOF
1998         eval uwhat_v=\$HAVE__SYS_SIG$uwhat
1999         if test 1 = "$uwhat_v"; then
2000                 add_cppflags -Dsys_sig$what=_sys_sig$what
2001                 eval HAVE_SYS_SIG$uwhat=1
2002         fi
2003         ac_cppflags SYS_SIG$uwhat
2004 done
2005
2006 #
2007 # Environment: library functions
2008 #
2009 ac_test flock <<-'EOF'
2010         #include <sys/types.h>
2011         #include <fcntl.h>
2012         #undef flock
2013         #if HAVE_SYS_FILE_H
2014         #include <sys/file.h>
2015         #endif
2016         int main(void) { return (flock(0, LOCK_EX | LOCK_UN)); }
2017 EOF
2018
2019 ac_test lock_fcntl '!' flock 1 'whether we can lock files with fcntl' <<-'EOF'
2020         #include <fcntl.h>
2021         #undef flock
2022         int main(void) {
2023                 struct flock lks;
2024                 lks.l_type = F_WRLCK | F_UNLCK;
2025                 return (fcntl(0, F_SETLKW, &lks));
2026         }
2027 EOF
2028
2029 ac_test getrusage <<-'EOF'
2030         #define MKSH_INCLUDES_ONLY
2031         #include "sh.h"
2032         int main(void) {
2033                 struct rusage ru;
2034                 return (getrusage(RUSAGE_SELF, &ru) +
2035                     getrusage(RUSAGE_CHILDREN, &ru));
2036         }
2037 EOF
2038
2039 ac_test getsid <<-'EOF'
2040         #include <unistd.h>
2041         int main(void) { return ((int)getsid(0)); }
2042 EOF
2043
2044 ac_test gettimeofday <<-'EOF'
2045         #define MKSH_INCLUDES_ONLY
2046         #include "sh.h"
2047         int main(void) { struct timeval tv; return (gettimeofday(&tv, NULL)); }
2048 EOF
2049
2050 ac_test killpg <<-'EOF'
2051         #include <signal.h>
2052         int main(int ac, char *av[]) { return (av[0][killpg(123, ac)]); }
2053 EOF
2054
2055 ac_test memmove <<-'EOF'
2056         #include <sys/types.h>
2057         #include <stddef.h>
2058         #include <string.h>
2059         #if HAVE_STRINGS_H
2060         #include <strings.h>
2061         #endif
2062         int main(int ac, char *av[]) {
2063                 return (*(int *)(void *)memmove(av[0], av[1], (size_t)ac));
2064         }
2065 EOF
2066
2067 ac_test mknod '' 'if to use mknod(), makedev() and friends' <<-'EOF'
2068         #define MKSH_INCLUDES_ONLY
2069         #include "sh.h"
2070         int main(int ac, char *av[]) {
2071                 dev_t dv;
2072                 dv = makedev((unsigned int)ac, (unsigned int)av[0][0]);
2073                 return (mknod(av[0], (mode_t)0, dv) ? (int)major(dv) :
2074                     (int)minor(dv));
2075         }
2076 EOF
2077
2078 ac_test mmap lock_fcntl 0 'for mmap and munmap' <<-'EOF'
2079         #include <sys/types.h>
2080         #if HAVE_SYS_FILE_H
2081         #include <sys/file.h>
2082         #endif
2083         #if HAVE_SYS_MMAN_H
2084         #include <sys/mman.h>
2085         #endif
2086         #include <stddef.h>
2087         #include <stdlib.h>
2088         int main(void) { return ((void *)mmap(NULL, (size_t)0,
2089             PROT_READ, MAP_PRIVATE, 0, (off_t)0) == (void *)NULL ? 1 :
2090             munmap(NULL, 0)); }
2091 EOF
2092
2093 ac_test ftruncate mmap 0 'for ftruncate' <<-'EOF'
2094         #include <unistd.h>
2095         int main(void) { return (ftruncate(0, 0)); }
2096 EOF
2097
2098 ac_test nice <<-'EOF'
2099         #include <unistd.h>
2100         int main(void) { return (nice(4)); }
2101 EOF
2102
2103 ac_test revoke <<-'EOF'
2104         #include <sys/types.h>
2105         #if HAVE_LIBUTIL_H
2106         #include <libutil.h>
2107         #endif
2108         #include <unistd.h>
2109         int main(int ac, char *av[]) { return (ac + revoke(av[0])); }
2110 EOF
2111
2112 ac_test setlocale_ctype '' 'setlocale(LC_CTYPE, "")' <<-'EOF'
2113         #include <locale.h>
2114         #include <stddef.h>
2115         int main(void) { return ((int)(size_t)(void *)setlocale(LC_CTYPE, "")); }
2116 EOF
2117
2118 ac_test langinfo_codeset setlocale_ctype 0 'nl_langinfo(CODESET)' <<-'EOF'
2119         #include <langinfo.h>
2120         #include <stddef.h>
2121         int main(void) { return ((int)(size_t)(void *)nl_langinfo(CODESET)); }
2122 EOF
2123
2124 ac_test select <<-'EOF'
2125         #include <sys/types.h>
2126         #if HAVE_BOTH_TIME_H
2127         #include <sys/time.h>
2128         #include <time.h>
2129         #elif HAVE_SYS_TIME_H
2130         #include <sys/time.h>
2131         #elif HAVE_TIME_H
2132         #include <time.h>
2133         #endif
2134         #if HAVE_SYS_BSDTYPES_H
2135         #include <sys/bsdtypes.h>
2136         #endif
2137         #if HAVE_SYS_SELECT_H
2138         #include <sys/select.h>
2139         #endif
2140         #if HAVE_BSTRING_H
2141         #include <bstring.h>
2142         #endif
2143         #include <stddef.h>
2144         #include <stdlib.h>
2145         #include <string.h>
2146         #if HAVE_STRINGS_H
2147         #include <strings.h>
2148         #endif
2149         #include <unistd.h>
2150         int main(void) {
2151                 struct timeval tv = { 1, 200000 };
2152                 fd_set fds; FD_ZERO(&fds); FD_SET(0, &fds);
2153                 return (select(FD_SETSIZE, &fds, NULL, NULL, &tv));
2154         }
2155 EOF
2156
2157 ac_test setresugid <<-'EOF'
2158         #include <sys/types.h>
2159         #include <unistd.h>
2160         int main(void) { return (setresuid(0,0,0) + setresgid(0,0,0)); }
2161 EOF
2162
2163 ac_test setgroups setresugid 0 <<-'EOF'
2164         #include <sys/types.h>
2165         #if HAVE_GRP_H
2166         #include <grp.h>
2167         #endif
2168         #include <unistd.h>
2169         int main(void) { gid_t gid = 0; return (setgroups(0, &gid)); }
2170 EOF
2171
2172 if test x"$et" = x"klibc"; then
2173
2174         ac_testn __rt_sigsuspend '' 'whether klibc uses RT signals' <<-'EOF'
2175                 #define MKSH_INCLUDES_ONLY
2176                 #include "sh.h"
2177                 extern int __rt_sigsuspend(const sigset_t *, size_t);
2178                 int main(void) { return (__rt_sigsuspend(NULL, 0)); }
2179 EOF
2180
2181         # no? damn! legacy crap ahead!
2182
2183         ac_testn __sigsuspend_s '!' __rt_sigsuspend 1 \
2184             'whether sigsuspend is usable (1/2)' <<-'EOF'
2185                 #define MKSH_INCLUDES_ONLY
2186                 #include "sh.h"
2187                 extern int __sigsuspend_s(sigset_t);
2188                 int main(void) { return (__sigsuspend_s(0)); }
2189 EOF
2190         ac_testn __sigsuspend_xxs '!' __sigsuspend_s 1 \
2191             'whether sigsuspend is usable (2/2)' <<-'EOF'
2192                 #define MKSH_INCLUDES_ONLY
2193                 #include "sh.h"
2194                 extern int __sigsuspend_xxs(int, int, sigset_t);
2195                 int main(void) { return (__sigsuspend_xxs(0, 0, 0)); }
2196 EOF
2197
2198         if test "000" = "$HAVE___RT_SIGSUSPEND$HAVE___SIGSUSPEND_S$HAVE___SIGSUSPEND_XXS"; then
2199                 # no usable sigsuspend(), use pause() *ugh*
2200                 add_cppflags -DMKSH_NO_SIGSUSPEND
2201         fi
2202 fi
2203
2204 ac_test strerror '!' sys_errlist 0 <<-'EOF'
2205         extern char *strerror(int);
2206         int main(int ac, char *av[]) { return (*strerror(*av[ac])); }
2207 EOF
2208
2209 ac_test strsignal '!' sys_siglist 0 <<-'EOF'
2210         #include <string.h>
2211         #include <signal.h>
2212         int main(void) { return (strsignal(1)[0]); }
2213 EOF
2214
2215 ac_test strlcpy <<-'EOF'
2216         #include <string.h>
2217         int main(int ac, char *av[]) { return (strlcpy(*av, av[1],
2218             (size_t)ac)); }
2219 EOF
2220
2221 #
2222 # check headers for declarations
2223 #
2224 ac_test flock_decl flock 1 'for declaration of flock()' <<-'EOF'
2225         #define MKSH_INCLUDES_ONLY
2226         #include "sh.h"
2227         #if HAVE_SYS_FILE_H
2228         #include <sys/file.h>
2229         #endif
2230         int main(void) { return ((flock)(0, 0)); }
2231 EOF
2232 ac_test revoke_decl revoke 1 'for declaration of revoke()' <<-'EOF'
2233         #define MKSH_INCLUDES_ONLY
2234         #include "sh.h"
2235         int main(void) { return ((revoke)("")); }
2236 EOF
2237 ac_test sys_errlist_decl sys_errlist 0 "for declaration of sys_errlist[] and sys_nerr" <<-'EOF'
2238         #define MKSH_INCLUDES_ONLY
2239         #include "sh.h"
2240         int main(void) { return (*sys_errlist[sys_nerr - 1] + isatty(0)); }
2241 EOF
2242 ac_test sys_siglist_decl sys_siglist 0 'for declaration of sys_siglist[]' <<-'EOF'
2243         #define MKSH_INCLUDES_ONLY
2244         #include "sh.h"
2245         int main(void) { return (sys_siglist[0][0] + isatty(0)); }
2246 EOF
2247
2248 #
2249 # other checks
2250 #
2251 fd='if to use persistent history'
2252 ac_cache PERSISTENT_HISTORY || case $HAVE_FTRUNCATE$HAVE_MMAP$HAVE_FLOCK$HAVE_LOCK_FCNTL in
2253 111*|1101) fv=1 ;;
2254 esac
2255 test 1 = $fv || check_categories="$check_categories no-histfile"
2256 ac_testdone
2257 ac_cppflags
2258
2259 #
2260 # extra checks for legacy mksh
2261 #
2262 if test $legacy = 1; then
2263         ac_test long_32bit '' 'whether long is 32 bit wide' <<-'EOF'
2264                 #define MKSH_INCLUDES_ONLY
2265                 #include "sh.h"
2266                 #ifndef CHAR_BIT
2267                 #define CHAR_BIT 0
2268                 #endif
2269                 struct ctasserts {
2270                 #define cta(name, assertion) char name[(assertion) ? 1 : -1]
2271                         cta(char_is_8_bits, (CHAR_BIT) == 8);
2272                         cta(long_is_32_bits, sizeof(long) == 4);
2273                 };
2274                 int main(void) { return (sizeof(struct ctasserts)); }
2275 EOF
2276
2277         ac_test long_64bit '!' long_32bit 0 'whether long is 64 bit wide' <<-'EOF'
2278                 #define MKSH_INCLUDES_ONLY
2279                 #include "sh.h"
2280                 #ifndef CHAR_BIT
2281                 #define CHAR_BIT 0
2282                 #endif
2283                 struct ctasserts {
2284                 #define cta(name, assertion) char name[(assertion) ? 1 : -1]
2285                         cta(char_is_8_bits, (CHAR_BIT) == 8);
2286                         cta(long_is_64_bits, sizeof(long) == 8);
2287                 };
2288                 int main(void) { return (sizeof(struct ctasserts)); }
2289 EOF
2290
2291         case $HAVE_LONG_32BIT$HAVE_LONG_64BIT in
2292         10) check_categories="$check_categories int:32" ;;
2293         01) check_categories="$check_categories int:64" ;;
2294         *) check_categories="$check_categories int:u" ;;
2295         esac
2296 fi
2297
2298 #
2299 # Compiler: Praeprocessor (only if needed)
2300 #
2301 test 0 = $HAVE_SYS_SIGNAME && if ac_testinit cpp_dd '' \
2302     'checking if the C Preprocessor supports -dD'; then
2303         echo '#define foo bar' >conftest.c
2304         vv ']' "$CPP $CFLAGS $CPPFLAGS $NOWARN -dD conftest.c >x"
2305         grep '#define foo bar' x >/dev/null 2>&1 && fv=1
2306         rmf conftest.c x vv.out
2307         ac_testdone
2308 fi
2309
2310 #
2311 # End of mirtoconf checks
2312 #
2313 $e ... done.
2314
2315 # Some operating systems have ancient versions of ed(1) writing
2316 # the character count to standard output; cope for that
2317 echo wq >x
2318 ed x <x 2>/dev/null | grep 3 >/dev/null 2>&1 && \
2319     check_categories="$check_categories $oldish_ed"
2320 rmf x vv.out
2321
2322 if test 0 = $HAVE_SYS_SIGNAME; then
2323         if test 1 = $HAVE_CPP_DD; then
2324                 $e Generating list of signal names...
2325         else
2326                 $e No list of signal names available via cpp. Falling back...
2327         fi
2328         sigseenone=:
2329         sigseentwo=:
2330         echo '#include <signal.h>
2331 #if defined(NSIG_MAX)
2332 #define cfg_NSIG NSIG_MAX
2333 #elif defined(NSIG)
2334 #define cfg_NSIG NSIG
2335 #elif defined(_NSIG)
2336 #define cfg_NSIG _NSIG
2337 #elif defined(SIGMAX)
2338 #define cfg_NSIG (SIGMAX + 1)
2339 #elif defined(_SIGMAX)
2340 #define cfg_NSIG (_SIGMAX + 1)
2341 #else
2342 /*XXX better error out, see sh.h */
2343 #define cfg_NSIG 64
2344 #endif
2345 int
2346 mksh_cfg= cfg_NSIG
2347 ;' >conftest.c
2348         # GNU sed 2.03 segfaults when optimising this to sed -n
2349         NSIG=`vq "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c" | \
2350             grep -v '^#' | \
2351             sed '/mksh_cfg.*= *$/{
2352                 N
2353                 s/\n/ /
2354                 }' | \
2355             grep '^ *mksh_cfg *=' | \
2356             sed 's/^ *mksh_cfg *=[       ]*\([()0-9x+-][()0-9x+  -]*\).*$/\1/'`
2357         case $NSIG in
2358         *mksh_cfg*) $e "Error: NSIG='$NSIG'"; NSIG=0 ;;
2359         *[\ \(\)+-]*) NSIG=`"$AWK" "BEGIN { print $NSIG }" </dev/null` ;;
2360         esac
2361         printf=printf
2362         (printf hallo) >/dev/null 2>&1 || printf=echo
2363         test $printf = echo || test "`printf %d 42`" = 42 || printf=echo
2364         test $printf = echo || NSIG=`printf %d "$NSIG" 2>/dev/null`
2365         $printf "NSIG=$NSIG ... "
2366         sigs="ABRT FPE ILL INT SEGV TERM ALRM BUS CHLD CONT HUP KILL PIPE QUIT"
2367         sigs="$sigs STOP TSTP TTIN TTOU USR1 USR2 POLL PROF SYS TRAP URG VTALRM"
2368         sigs="$sigs XCPU XFSZ INFO WINCH EMT IO DIL LOST PWR SAK CLD IOT STKFLT"
2369         sigs="$sigs ABND DCE DUMP IOERR TRACE DANGER THCONT THSTOP RESV UNUSED"
2370         test 1 = $HAVE_CPP_DD && test $NSIG -gt 1 && sigs="$sigs "`vq \
2371             "$CPP $CFLAGS $CPPFLAGS $NOWARN -dD conftest.c" | \
2372             grep '[      ]SIG[A-Z0-9][A-Z0-9]*[  ]' | \
2373             sed 's/^.*[  ]SIG\([A-Z0-9][A-Z0-9]*\)[      ].*$/\1/' | sort`
2374         test $NSIG -gt 1 || sigs=
2375         for name in $sigs; do
2376                 case $sigseenone in
2377                 *:$name:*) continue ;;
2378                 esac
2379                 sigseenone=$sigseenone$name:
2380                 echo '#include <signal.h>' >conftest.c
2381                 echo int >>conftest.c
2382                 echo mksh_cfg= SIG$name >>conftest.c
2383                 echo ';' >>conftest.c
2384                 # GNU sed 2.03 croaks on optimising this, too
2385                 vq "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c" | \
2386                     grep -v '^#' | \
2387                     sed '/mksh_cfg.*= *$/{
2388                         N
2389                         s/\n/ /
2390                         }' | \
2391                     grep '^ *mksh_cfg *=' | \
2392                     sed 's/^ *mksh_cfg *=[       ]*\([0-9][0-9x]*\).*$/:\1 '$name/
2393         done | sed -n '/^:[^ ]/s/^://p' | while read nr name; do
2394                 test $printf = echo || nr=`printf %d "$nr" 2>/dev/null`
2395                 test $nr -gt 0 && test $nr -lt $NSIG || continue
2396                 case $sigseentwo in
2397                 *:$nr:*) ;;
2398                 *)      echo "          { \"$name\", $nr },"
2399                         sigseentwo=$sigseentwo$nr:
2400                         $printf "$name=$nr " >&2
2401                         ;;
2402                 esac
2403         done 2>&1 >signames.inc
2404         rmf conftest.c
2405         $e done.
2406 fi
2407
2408 addsrcs '!' HAVE_STRLCPY strlcpy.c
2409 addsrcs USE_PRINTF_BUILTIN printf.c
2410 test 1 = "$USE_PRINTF_BUILTIN" && add_cppflags -DMKSH_PRINTF_BUILTIN
2411 test 1 = "$HAVE_CAN_VERB" && CFLAGS="$CFLAGS -verbose"
2412 add_cppflags -DMKSH_BUILD_R=562
2413
2414 $e $bi$me: Finished configuration testing, now producing output.$ao
2415
2416 files=
2417 objs=
2418 sp=
2419 case $tcfn in
2420 a.exe|conftest.exe)
2421         mkshexe=$tfn.exe
2422         add_cppflags -DMKSH_EXE_EXT
2423         ;;
2424 *)
2425         mkshexe=$tfn
2426         ;;
2427 esac
2428 case $curdir in
2429 *\ *)   mkshshebang="#!./$mkshexe" ;;
2430 *)      mkshshebang="#!$curdir/$mkshexe" ;;
2431 esac
2432 cat >test.sh <<-EOF
2433         $mkshshebang
2434         LC_ALL=C PATH='$PATH'; export LC_ALL PATH
2435         test -n "\$KSH_VERSION" || exit 1
2436         set -A check_categories -- $check_categories
2437         pflag='$curdir/$mkshexe'
2438         sflag='$srcdir/check.t'
2439         usee=0 useU=0 Pflag=0 Sflag=0 uset=0 vflag=1 xflag=0
2440         while getopts "C:e:fPp:QSs:t:U:v" ch; do case \$ch {
2441         (C)     check_categories[\${#check_categories[*]}]=\$OPTARG ;;
2442         (e)     usee=1; eflag=\$OPTARG ;;
2443         (f)     check_categories[\${#check_categories[*]}]=fastbox ;;
2444         (P)     Pflag=1 ;;
2445         (+P)    Pflag=0 ;;
2446         (p)     pflag=\$OPTARG ;;
2447         (Q)     vflag=0 ;;
2448         (+Q)    vflag=1 ;;
2449         (S)     Sflag=1 ;;
2450         (+S)    Sflag=0 ;;
2451         (s)     sflag=\$OPTARG ;;
2452         (t)     uset=1; tflag=\$OPTARG ;;
2453         (U)     useU=1; Uflag=\$OPTARG ;;
2454         (v)     vflag=1 ;;
2455         (+v)    vflag=0 ;;
2456         (*)     xflag=1 ;;
2457         }
2458         done
2459         shift \$((OPTIND - 1))
2460         set -A args -- '$srcdir/check.pl' -p "\$pflag"
2461         if $ebcdic; then
2462                 args[\${#args[*]}]=-E
2463         fi
2464         x=
2465         for y in "\${check_categories[@]}"; do
2466                 x=\$x,\$y
2467         done
2468         if [[ -n \$x ]]; then
2469                 args[\${#args[*]}]=-C
2470                 args[\${#args[*]}]=\${x#,}
2471         fi
2472         if (( usee )); then
2473                 args[\${#args[*]}]=-e
2474                 args[\${#args[*]}]=\$eflag
2475         fi
2476         (( Pflag )) && args[\${#args[*]}]=-P
2477         if (( uset )); then
2478                 args[\${#args[*]}]=-t
2479                 args[\${#args[*]}]=\$tflag
2480         fi
2481         if (( useU )); then
2482                 args[\${#args[*]}]=-U
2483                 args[\${#args[*]}]=\$Uflag
2484         fi
2485         (( vflag )) && args[\${#args[*]}]=-v
2486         (( xflag )) && args[\${#args[*]}]=-x    # force usage by synerr
2487         if [[ -n \$TMPDIR && -d \$TMPDIR/. ]]; then
2488                 args[\${#args[*]}]=-T
2489                 args[\${#args[*]}]=\$TMPDIR
2490         fi
2491         print Testing mksh for conformance:
2492         grep -F -e Mir''OS: -e MIRBSD "\$sflag"
2493         print "This shell is actually:\\n\\t\$KSH_VERSION"
2494         print 'test.sh built for mksh $dstversion'
2495         cstr='\$os = defined \$^O ? \$^O : "unknown";'
2496         cstr="\$cstr"'print \$os . ", Perl version " . \$];'
2497         for perli in \$PERL perl5 perl no; do
2498                 if [[ \$perli = no ]]; then
2499                         print Cannot find a working Perl interpreter, aborting.
2500                         exit 1
2501                 fi
2502                 print "Trying Perl interpreter '\$perli'..."
2503                 perlos=\$(\$perli -e "\$cstr")
2504                 rv=\$?
2505                 print "Errorlevel \$rv, running on '\$perlos'"
2506                 if (( rv )); then
2507                         print "=> not using"
2508                         continue
2509                 fi
2510                 if [[ -n \$perlos ]]; then
2511                         print "=> using it"
2512                         break
2513                 fi
2514         done
2515         (( Sflag )) || echo + \$perli "\${args[@]}" -s "\$sflag" "\$@"
2516         (( Sflag )) || exec \$perli "\${args[@]}" -s "\$sflag" "\$@"$tsts
2517         # use of the -S option for check.t split into multiple chunks
2518         rv=0
2519         for s in "\$sflag".*; do
2520                 echo + \$perli "\${args[@]}" -s "\$s" "\$@"
2521                 \$perli "\${args[@]}" -s "\$s" "\$@"$tsts
2522                 rc=\$?
2523                 (( rv = rv ? rv : rc ))
2524         done
2525         exit \$rv
2526 EOF
2527 chmod 755 test.sh
2528 case $cm in
2529 dragonegg)
2530         emitbc="-S -flto"
2531         ;;
2532 llvm)
2533         emitbc="-emit-llvm -c"
2534         ;;
2535 *)
2536         emitbc=-c
2537         ;;
2538 esac
2539 echo ": # work around NeXTstep bug" >Rebuild.sh
2540 cd "$srcdir"
2541 optfiles=`echo *.opt`
2542 cd "$curdir"
2543 for file in $optfiles; do
2544         echo "echo + Running genopt on '$file'..."
2545         echo "(srcfile='$srcdir/$file'; BUILDSH_RUN_GENOPT=1; . '$srcdir/Build.sh')"
2546 done >>Rebuild.sh
2547 echo set -x >>Rebuild.sh
2548 for file in $SRCS; do
2549         op=`echo x"$file" | sed 's/^x\(.*\)\.c$/\1./'`
2550         test -f $file || file=$srcdir/$file
2551         files="$files$sp$file"
2552         sp=' '
2553         echo "$CC $CFLAGS $CPPFLAGS $emitbc $file || exit 1" >>Rebuild.sh
2554         if test $cm = dragonegg; then
2555                 echo "mv ${op}s ${op}ll" >>Rebuild.sh
2556                 echo "llvm-as ${op}ll || exit 1" >>Rebuild.sh
2557                 objs="$objs$sp${op}bc"
2558         else
2559                 objs="$objs$sp${op}o"
2560         fi
2561 done
2562 case $cm in
2563 dragonegg|llvm)
2564         echo "rm -f $tfn.s" >>Rebuild.sh
2565         echo "llvm-link -o - $objs | opt $optflags | llc -o $tfn.s" >>Rebuild.sh
2566         lobjs=$tfn.s
2567         ;;
2568 *)
2569         lobjs=$objs
2570         ;;
2571 esac
2572 echo tcfn=$mkshexe >>Rebuild.sh
2573 echo "$CC $CFLAGS $LDFLAGS -o \$tcfn $lobjs $LIBS $ccpr" >>Rebuild.sh
2574 echo "test -f \$tcfn || exit 1; $SIZE \$tcfn" >>Rebuild.sh
2575 if test $cm = makefile; then
2576         extras='emacsfn.h exprtok.h rlimits.opt sh.h sh_flags.opt var_spec.h'
2577         test 0 = $HAVE_SYS_SIGNAME && extras="$extras signames.inc"
2578         gens= genq=
2579         for file in $optfiles; do
2580                 genf=`basename "$file" | sed 's/.opt$/.gen/'`
2581                 gens="$gens $genf"
2582                 genq="$genq$nl$genf: $srcdir/Build.sh $srcdir/$file
2583                         srcfile=$srcdir/$file; BUILDSH_RUN_GENOPT=1; . $srcdir/Build.sh"
2584         done
2585         cat >Makefrag.inc <<EOF
2586 # Makefile fragment for building mksh $dstversion
2587
2588 PROG=           $mkshexe
2589 MAN=            mksh.1
2590 SRCS=           $SRCS
2591 SRCS_FP=        $files
2592 OBJS_BP=        $objs
2593 INDSRCS=        $extras
2594 NONSRCS_INST=   dot.mkshrc \$(MAN)
2595 NONSRCS_NOINST= Build.sh Makefile Rebuild.sh check.pl check.t test.sh
2596 CC=             $CC
2597 CFLAGS=         $CFLAGS
2598 CPPFLAGS=       $CPPFLAGS
2599 LDFLAGS=        $LDFLAGS
2600 LIBS=           $LIBS
2601
2602 .depend \$(OBJS_BP):$gens$genq
2603
2604 # not BSD make only:
2605 #VPATH=         $srcdir
2606 #all: \$(PROG)
2607 #\$(PROG): \$(OBJS_BP)
2608 #       \$(CC) \$(CFLAGS) \$(LDFLAGS) -o \$@ \$(OBJS_BP) \$(LIBS)
2609 #\$(OBJS_BP): \$(SRCS_FP) \$(NONSRCS)
2610 #.c.o:
2611 #       \$(CC) \$(CFLAGS) \$(CPPFLAGS) -c \$<
2612
2613 # for all make variants:
2614 #REGRESS_FLAGS= -f
2615 #regress:
2616 #       ./test.sh \$(REGRESS_FLAGS)
2617 check_categories=$check_categories
2618
2619 # for BSD make only:
2620 #.PATH: $srcdir
2621 #.include <bsd.prog.mk>
2622 EOF
2623         $e
2624         $e Generated Makefrag.inc successfully.
2625         exit 0
2626 fi
2627 for file in $optfiles; do
2628         $e "+ Running genopt on '$file'..."
2629         do_genopt "$srcdir/$file" || exit 1
2630 done
2631 if test $cm = combine; then
2632         objs="-o $mkshexe"
2633         for file in $SRCS; do
2634                 test -f $file || file=$srcdir/$file
2635                 objs="$objs $file"
2636         done
2637         emitbc="-fwhole-program --combine"
2638         v "$CC $CFLAGS $CPPFLAGS $LDFLAGS $emitbc $objs $LIBS $ccpr"
2639 elif test 1 = $pm; then
2640         for file in $SRCS; do
2641                 test -f $file || file=$srcdir/$file
2642                 v "$CC $CFLAGS $CPPFLAGS $emitbc $file" &
2643         done
2644         wait
2645 else
2646         for file in $SRCS; do
2647                 test $cm = dragonegg && \
2648                     op=`echo x"$file" | sed 's/^x\(.*\)\.c$/\1./'`
2649                 test -f $file || file=$srcdir/$file
2650                 v "$CC $CFLAGS $CPPFLAGS $emitbc $file" || exit 1
2651                 if test $cm = dragonegg; then
2652                         v "mv ${op}s ${op}ll"
2653                         v "llvm-as ${op}ll" || exit 1
2654                 fi
2655         done
2656 fi
2657 case $cm in
2658 dragonegg|llvm)
2659         rmf $tfn.s
2660         v "llvm-link -o - $objs | opt $optflags | llc -o $tfn.s"
2661         ;;
2662 esac
2663 tcfn=$mkshexe
2664 test $cm = combine || v "$CC $CFLAGS $LDFLAGS -o $tcfn $lobjs $LIBS $ccpr"
2665 test -f $tcfn || exit 1
2666 test 1 = $r || v "$NROFF -mdoc <'$srcdir/lksh.1' >lksh.cat1" || rmf lksh.cat1
2667 test 1 = $r || v "$NROFF -mdoc <'$srcdir/mksh.1' >mksh.cat1" || rmf mksh.cat1
2668 test 0 = $eq && v $SIZE $tcfn
2669 i=install
2670 test -f /usr/ucb/$i && i=/usr/ucb/$i
2671 test 1 = $eq && e=:
2672 $e
2673 $e Installing the shell:
2674 $e "# $i -c -s -o root -g bin -m 555 $tfn /bin/$tfn"
2675 if test $legacy = 0; then
2676         $e "# grep -x /bin/$tfn /etc/shells >/dev/null || echo /bin/$tfn >>/etc/shells"
2677         $e "# $i -c -o root -g bin -m 444 dot.mkshrc /usr/share/doc/mksh/examples/"
2678 fi
2679 $e
2680 $e Installing the manual:
2681 if test -f mksh.cat1; then
2682         $e "# $i -c -o root -g bin -m 444 lksh.cat1" \
2683             "/usr/share/man/cat1/lksh.0"
2684         $e "# $i -c -o root -g bin -m 444 mksh.cat1" \
2685             "/usr/share/man/cat1/mksh.0"
2686         $e or
2687 fi
2688 $e "# $i -c -o root -g bin -m 444 lksh.1 mksh.1 /usr/share/man/man1/"
2689 $e
2690 $e Run the regression test suite: ./test.sh
2691 $e Please also read the sample file dot.mkshrc and the fine manual.
2692 exit 0
2693
2694 : <<'EOD'
2695
2696 === Environment used ===
2697
2698 ==== build environment ====
2699 AWK                             default: awk
2700 CC                              default: cc
2701 CFLAGS                          if empty, defaults to -xO2 or +O2
2702                                 or -O3 -qstrict or -O2, per compiler
2703 CPPFLAGS                        default empty
2704 LDFLAGS                         default empty; added before sources
2705 LDSTATIC                        set this to '-static'; default unset
2706 LIBS                            default empty; added after sources
2707                                 [Interix] default: -lcrypt (XXX still needed?)
2708 NOWARN                          -Wno-error or similar
2709 NROFF                           default: nroff
2710 TARGET_OS                       default: $(uname -s || uname)
2711 TARGET_OSREV                    [QNX] default: $(uname -r)
2712
2713 ==== feature selectors ====
2714 USE_PRINTF_BUILTIN              1 to include (unsupported) printf(1) as builtin
2715 ===== general format =====
2716 HAVE_STRLEN                     ac_test
2717 HAVE_STRING_H                   ac_header
2718 HAVE_CAN_FSTACKPROTECTORALL     ac_flags
2719
2720 ==== cpp definitions ====
2721 DEBUG                           dont use in production, wants gcc, implies:
2722 DEBUG_LEAKS                     enable freeing resources before exiting
2723 MKSHRC_PATH                     "~/.mkshrc" (do not change)
2724 MKSH_A4PB                       force use of arc4random_pushb
2725 MKSH_ASSUME_UTF8                (0=disabled, 1=enabled; default: unset)
2726 MKSH_BINSHPOSIX                 if */sh or */-sh, enable set -o posix
2727 MKSH_BINSHREDUCED               if */sh or */-sh, enable set -o sh
2728 MKSH_CLS_STRING                 KSH_ESC_STRING "[;H" KSH_ESC_STRING "[J"
2729 MKSH_DEFAULT_EXECSHELL          "/bin/sh" (do not change)
2730 MKSH_DEFAULT_PROFILEDIR         "/etc" (do not change)
2731 MKSH_DEFAULT_TMPDIR             "/tmp" (do not change)
2732 MKSH_DISABLE_DEPRECATED         disable code paths scheduled for later removal
2733 MKSH_DISABLE_EXPERIMENTAL       disable code not yet comfy for (LTS) snapshots
2734 MKSH_DISABLE_TTY_WARNING        shut up warning about ctty if OS cant be fixed
2735 MKSH_DONT_EMIT_IDSTRING         omit RCS IDs from binary
2736 MKSH_MIDNIGHTBSD01ASH_COMPAT    set -o sh: additional compatibility quirk
2737 MKSH_NOPROSPECTOFWORK           disable jobs, co-processes, etc. (do not use)
2738 MKSH_NOPWNAM                    skip PAM calls, for -static on glibc or Solaris
2739 MKSH_NO_CMDLINE_EDITING         disable command line editing code entirely
2740 MKSH_NO_DEPRECATED_WARNING      omit warning when deprecated stuff is run
2741 MKSH_NO_LIMITS                  omit ulimit code
2742 MKSH_NO_SIGSETJMP               define if sigsetjmp is broken or not available
2743 MKSH_NO_SIGSUSPEND              use sigprocmask+pause instead of sigsuspend
2744 MKSH_SMALL                      omit some code, optimise hard for size (slower)
2745 MKSH_SMALL_BUT_FAST             disable some hard-for-size optim. (modern sys.)
2746 MKSH_S_NOVI=1                   disable Vi editing mode (default if MKSH_SMALL)
2747 MKSH_TYPEDEF_SIG_ATOMIC_T       define to e.g. 'int' if sig_atomic_t is missing
2748 MKSH_TYPEDEF_SSIZE_T            define to e.g. 'long' if your OS has no ssize_t
2749 MKSH_UNEMPLOYED                 disable job control (but not jobs/co-processes)
2750
2751 === generic installation instructions ===
2752
2753 Set CC and possibly CFLAGS, CPPFLAGS, LDFLAGS, LIBS. If cross-compiling,
2754 also set TARGET_OS. To disable tests, set e.g. HAVE_STRLCPY=0; to enable
2755 them, set to a value other than 0 or 1. Ensure /bin/ed is installed. For
2756 MKSH_SMALL but with Vi mode, add -DMKSH_S_NOVI=0 to CPPFLAGS as well.
2757
2758 Normally, the following command is what you want to run, then:
2759 $ (sh Build.sh -r -c lto && ./test.sh -f) 2>&1 | tee log
2760
2761 Copy dot.mkshrc to /etc/skel/.mkshrc; install mksh into $prefix/bin; or
2762 /bin; install the manpage, if omitting the -r flag a catmanpage is made
2763 using $NROFF. Consider using a forward script as /etc/skel/.mkshrc like
2764 http://anonscm.debian.org/cgit/collab-maint/mksh.git/plain/debian/.mkshrc
2765 and put dot.mkshrc as /etc/mkshrc so users need not keep up their HOME.
2766
2767 You may also want to install the lksh binary (also as /bin/sh) built by:
2768 $ CPPFLAGS="$CPPFLAGS -DMKSH_BINSHPOSIX" sh Build.sh -L -r -c lto
2769
2770 EOD