OSDN Git Service

Update mksh to R43 (formal release, from tarball)
[android-x86/external-mksh.git] / src / Build.sh
index 6561cf6..31c559d 100644 (file)
@@ -1,7 +1,8 @@
 #!/bin/sh
-srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.488 2011/10/07 19:51:41 tg Exp $'
+srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.622 2013/02/19 18:45:15 tg Exp $'
 #-
-# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
+# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
+#              2011, 2012, 2013
 #      Thorsten Glaser <tg@mirbsd.org>
 #
 # Provided that these terms and disclaimer and all copyright notices
@@ -22,20 +23,26 @@ srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.488 2011/10/07 19:51:41 tg Exp $'
 # People analysing the output must whitelist conftest.c for any kind
 # of compiler warning checks (mirtoconf is by design not quiet).
 #
-# Environment used:    CC CFLAGS CPPFLAGS LDFLAGS LIBS NOWARN NROFF
-#                      TARGET_OS TARGET_OSREV
-# Feature selectors:   USE_PRINTF_BUILTIN
-# CPPFLAGS recognised: MKSH_ASSUME_UTF8 MKSH_BINSHREDUCED MKSH_CLS_STRING
-#                      MKSH_CONSERVATIVE_FDS MKSH_MIDNIGHTBSD01ASH_COMPAT
-#                      MKSH_NOPWNAM MKSH_NO_LIMITS MKSH_SMALL MKSH_S_NOVI
-#                      MKSH_UNEMPLOYED MKSH_DEFAULT_EXECSHELL MKSHRC_PATH
-#                      MKSH_DEFAULT_TMPDIR MKSH_CLRTOEOL_STRING MKSH_A4PB
-#                      MKSH_NO_DEPRECATED_WARNING MKSH_DONT_EMIT_IDSTRING
-#                      MKSH_NOPROSPECTOFWORK MKSH_NO_EXTERNAL_CAT
+# Used environment documentation is at the end of this file.
 
 LC_ALL=C
 export LC_ALL
 
+case $ZSH_VERSION:$VERSION in
+:zsh*) ZSH_VERSION=2 ;;
+esac
+
+if test -n "${ZSH_VERSION+x}" && (emulate sh) >/dev/null 2>&1; then
+       emulate sh
+       NULLCMD=:
+fi
+
+if test -d /usr/xpg4/bin/. >/dev/null 2>&1; then
+       # Solaris: some of the tools have weird behaviour, use portable ones
+       PATH=/usr/xpg4/bin:$PATH
+       export PATH
+fi
+
 v() {
        $e "$*"
        eval "$@"
@@ -55,24 +62,13 @@ vq() {
 
 rmf() {
        for _f in "$@"; do
-               case ${_f} in
-               mksh.1) ;;
-               *) rm -f "${_f}" ;;
+               case $_f in
+               Build.sh|check.pl|check.t|dot.mkshrc|*.c|*.h|mksh.1) ;;
+               *) rm -f "$_f" ;;
                esac
        done
 }
 
-if test -d /usr/xpg4/bin/. >/dev/null 2>&1; then
-       # Solaris: some of the tools have weird behaviour, use portable ones
-       PATH=/usr/xpg4/bin:$PATH
-       export PATH
-fi
-
-if test -n "${ZSH_VERSION+x}" && (emulate sh) >/dev/null 2>&1; then
-       emulate sh
-       NULLCMD=:
-fi
-
 allu=QWERTYUIOPASDFGHJKLZXCVBNM
 alll=qwertyuiopasdfghjklzxcvbnm
 alln=0123456789
@@ -156,14 +152,14 @@ ac_testinit() {
 }
 
 # pipe .c | ac_test[n] [!] label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput
-ac_testn() {
+ac_testnnd() {
        if test x"$1" = x"!"; then
                fr=1
                shift
        else
                fr=0
        fi
-       ac_testinit "$@" || return
+       ac_testinit "$@" || return 1
        cat >conftest.c
        vv ']' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN conftest.c $LIBS $ccpr"
        test $tcfn = no && test -f a.out && tcfn=a.out
@@ -182,6 +178,10 @@ ac_testn() {
                test $ct = sunpro && vscan='-e ignored -e turned.off'
        fi
        test -n "$vscan" && grep $vscan vv.out >/dev/null 2>&1 && fv=$fr
+       return 0
+}
+ac_testn() {
+       ac_testnnd "$@" || return
        rmf conftest.c conftest.o ${tcfn}* vv.out
        ac_testdone
 }
@@ -267,9 +267,24 @@ ac_header() {
        fi
        hf=$1; shift
        hv=`echo "$hf" | tr -d '\012\015' | tr -c $alll$allu$alln $alls`
+       echo "/* NeXTstep bug workaround */" >x
        for i
        do
-               echo "#include <$i>" >>x
+               case $i in
+               _time)
+                       echo '#if HAVE_BOTH_TIME_H' >>x
+                       echo '#include <sys/time.h>' >>x
+                       echo '#include <time.h>' >>x
+                       echo '#elif HAVE_SYS_TIME_H' >>x
+                       echo '#include <sys/time.h>' >>x
+                       echo '#elif HAVE_TIME_H' >>x
+                       echo '#include <time.h>' >>x
+                       echo '#endif' >>x
+                       ;;
+               *)
+                       echo "#include <$i>" >>x
+                       ;;
+               esac
        done
        echo "#include <$hf>" >>x
        echo 'int main(void) { return (0); }' >>x
@@ -279,6 +294,12 @@ ac_header() {
 }
 
 addsrcs() {
+       addsrcs_s=0
+       if test x"$1" = x"-s"; then
+               # optstatic
+               addsrcs_s=1
+               shift
+       fi
        if test x"$1" = x"!"; then
                fr=0
                shift
@@ -286,6 +307,13 @@ addsrcs() {
                fr=1
        fi
        eval i=\$$1
+       if test $addsrcs_s = 1; then
+               if test -f "$2" || test -f "$srcdir/$2"; then
+                       # always add $2, since it exists
+                       fr=1
+                       i=1
+               fi
+       fi
        test $fr = "$i" && case " $SRCS " in
        *\ $2\ *)       ;;
        *)              SRCS="$SRCS $2" ;;
@@ -293,16 +321,10 @@ addsrcs() {
 }
 
 
-if test -d mksh || test -d mksh.exe; then
-       echo "$me: Error: ./mksh is a directory!" >&2
-       exit 1
-fi
-rmf a.exe* a.out* conftest.c *core lft mksh* no *.bc *.ll *.o \
-    Rebuild.sh signames.inc test.sh x vv.out
-
-curdir=`pwd` srcdir=`dirname "$0"` check_categories=
-test -n "$srcdir" || srcdir=.
-dstversion=`sed -n '/define MKSH_VERSION/s/^.*"\(.*\)".*$/\1/p' $srcdir/sh.h`
+curdir=`pwd` srcdir=`dirname "$0" 2>/dev/null` check_categories=
+test -n "$srcdir" || srcdir=. # in case dirname does not exist
+dstversion=`sed -n '/define MKSH_VERSION/s/^.*"\([^"]*\)".*$/\1/p' $srcdir/sh.h`
+add_cppflags -DMKSH_BUILDSH
 
 e=echo
 r=0
@@ -311,6 +333,8 @@ pm=0
 cm=normal
 optflags=-std-compile-opts
 last=
+tfn=
+legacy=0
 
 for i
 do
@@ -327,6 +351,10 @@ do
                optflags=$i
                last=
                ;;
+       t:*)
+               tfn=$i
+               last=
+               ;;
        :-c)
                last=c
                ;;
@@ -338,6 +366,12 @@ do
        :-j)
                pm=1
                ;;
+       :-L)
+               legacy=1
+               ;;
+       :+L)
+               legacy=0
+               ;;
        :-M)
                cm=makefile
                ;;
@@ -353,6 +387,9 @@ do
        :-r)
                r=1
                ;;
+       :-t)
+               last=t
+               ;;
        :-v)
                echo "Build.sh $srcversion"
                echo "for mksh $dstversion"
@@ -373,17 +410,47 @@ if test -n "$last"; then
        exit 1
 fi
 
-SRCS="lalloc.c edit.c eval.c exec.c expr.c funcs.c histrap.c"
-SRCS="$SRCS jobs.c lex.c main.c misc.c shf.c syn.c tree.c var.c"
+test -z "$tfn" && if test $legacy = 0; then
+       tfn=mksh
+else
+       tfn=lksh
+fi
+if test -d $tfn || test -d $tfn.exe; then
+       echo "$me: Error: ./$tfn is a directory!" >&2
+       exit 1
+fi
+rmf a.exe* a.out* conftest.c *core core.* lft ${tfn}* no *.bc *.ll *.o \
+    Rebuild.sh signames.inc test.sh x vv.out
+
+SRCS="lalloc.c eval.c exec.c expr.c funcs.c histrap.c jobs.c"
+SRCS="$SRCS lex.c main.c misc.c shf.c syn.c tree.c var.c"
+
+if test $legacy = 0; then
+       SRCS="$SRCS edit.c"
+       check_categories="$check_categories shell:legacy-no int:32"
+else
+       check_categories="$check_categories shell:legacy-yes"
+       add_cppflags -DMKSH_LEGACY_MODE
+       HAVE_PERSISTENT_HISTORY=0
+       HAVE_ISSET_MKSH_CONSERVATIVE_FDS=1      # from sh.h
+fi
 
 if test x"$srcdir" = x"."; then
        CPPFLAGS="-I. $CPPFLAGS"
 else
        CPPFLAGS="-I. -I'$srcdir' $CPPFLAGS"
 fi
+test -n "$LDSTATIC" && if test -n "$LDFLAGS"; then
+       LDFLAGS="$LDFLAGS $LDSTATIC"
+else
+       LDFLAGS=$LDSTATIC
+fi
 
-test x"$TARGET_OS" = x"" && TARGET_OS=`uname -s 2>/dev/null || uname`
-if test x"$TARGET_OS" = x""; then
+if test -z "$TARGET_OS"; then
+       x=`uname -s 2>/dev/null || uname`
+       test x"$x" = x"`uname -n 2>/dev/null`" || TARGET_OS=$x
+fi
+if test -z "$TARGET_OS"; then
        echo "$me: Set TARGET_OS, your uname is broken!" >&2
        exit 1
 fi
@@ -391,7 +458,7 @@ oswarn=
 ccpc=-Wc,
 ccpl=-Wl,
 tsts=
-ccpr='|| for _f in ${tcfn}*; do test x"${_f}" = x"mksh.1" || rm -f "${_f}"; done'
+ccpr='|| for _f in ${tcfn}*; do case $_f in Build.sh|check.pl|check.t|dot.mkshrc|*.c|*.h|mksh.1) ;; *) rm -f "$_f" ;; esac; done'
 
 # Evil hack
 if test x"$TARGET_OS" = x"Android"; then
@@ -399,29 +466,105 @@ if test x"$TARGET_OS" = x"Android"; then
        TARGET_OS=Linux
 fi
 
+# Evil OS
+if test x"$TARGET_OS" = x"Minix"; then
+       echo >&2 "
+WARNING: additional checks before running Build.sh required!
+You can avoid these by calling Build.sh correctly, see below.
+"
+       cat >conftest.c <<'EOF'
+#include <sys/types.h>
+const char *
+#ifdef _NETBSD_SOURCE
+ct="Ninix3"
+#else
+ct="Minix3"
+#endif
+;
+EOF
+       ct=unknown
+       vv ']' "${CC-cc} -E $CFLAGS $CPPFLAGS $NOWARN conftest.c | grep ct= | tr -d \\\\015 >x"
+       sed 's/^/[ /' x
+       eval `cat x`
+       rmf x vv.out
+       case $ct in
+       Minix3|Ninix3)
+               echo >&2 "
+Warning: you set TARGET_OS to $TARGET_OS but that is ambiguous.
+Please set it to either Minix3 or Ninix3, whereas the latter is
+all versions of Minix with even partial NetBSD(R) userland. The
+value determined from your compiler for the current compilation
+(which may be wrong) is: $ct
+"
+               TARGET_OS=$ct
+               ;;
+       *)
+               echo >&2 "
+Warning: you set TARGET_OS to $TARGET_OS but that is ambiguous.
+Please set it to either Minix3 or Ninix3, whereas the latter is
+all versions of Minix with even partial NetBSD(R) userland. The
+proper value couldn't be determined, continue at your own risk.
+"
+               ;;
+       esac
+fi
+
 # Configuration depending on OS revision, on OSes that need them
 case $TARGET_OS in
-QNX)
+NEXTSTEP)
+       test x"$TARGET_OSREV" = x"" && TARGET_OSREV=`hostinfo 2>&1 | \
+           grep 'NeXT Mach [0-9][0-9.]*:' | \
+           sed 's/^.*NeXT Mach \([0-9][0-9.]*\):.*$/\1/'`
+       ;;
+QNX|SCO_SV)
        test x"$TARGET_OSREV" = x"" && TARGET_OSREV=`uname -r`
        ;;
 esac
 
 # Configuration depending on OS name
 case $TARGET_OS in
+386BSD)
+       : ${HAVE_CAN_OTWO=0}
+       add_cppflags -DMKSH_NO_SIGSETJMP
+       add_cppflags -DMKSH_TYPEDEF_SIG_ATOMIC_T=int
+       add_cppflags -DMKSH_CONSERVATIVE_FDS
+       ;;
 AIX)
        add_cppflags -D_ALL_SOURCE
        : ${HAVE_SETLOCALE_CTYPE=0}
        ;;
 BeOS)
-       oswarn=' and will currently not work'
+       case $KSH_VERSION in
+       *MIRBSD\ KSH*)
+               oswarn="; it has minor issues"
+               ;;
+       *)
+               oswarn="; you must recompile mksh with"
+               oswarn="$oswarn${nl}itself in a second stage"
+               ;;
+       esac
+       # BeOS has no real tty either
+       add_cppflags -DMKSH_UNEMPLOYED
+       add_cppflags -DMKSH_DISABLE_TTY_WARNING
+       # BeOS doesn't have different UIDs and GIDs
+       add_cppflags -DMKSH__NO_SETEUGID
        ;;
 BSD/OS)
        : ${HAVE_SETLOCALE_CTYPE=0}
        ;;
+Coherent)
+       oswarn="; it has major issues"
+       add_cppflags -DMKSH__NO_SYMLINK
+       check_categories="$check_categories nosymlink"
+       add_cppflags -DMKSH__NO_SETEUGID
+       add_cppflags -DMKSH_CONSERVATIVE_FDS
+       add_cppflags -DMKSH_DISABLE_TTY_WARNING
+       ;;
 CYGWIN*)
        : ${HAVE_SETLOCALE_CTYPE=0}
        ;;
 Darwin)
+       add_cppflags -D_DARWIN_C_SOURCE
        ;;
 DragonFly)
        ;;
@@ -430,6 +573,7 @@ FreeBSD)
 FreeMiNT)
        oswarn="; it has minor issues"
        add_cppflags -D_GNU_SOURCE
+       add_cppflags -DMKSH_CONSERVATIVE_FDS
        : ${HAVE_SETLOCALE_CTYPE=0}
        ;;
 GNU)
@@ -437,8 +581,8 @@ GNU)
        *tendracc*) ;;
        *) add_cppflags -D_GNU_SOURCE ;;
        esac
-       # define NO_PATH_MAX to use Hurd-only functions
-       add_cppflags -DNO_PATH_MAX
+       # define MKSH__NO_PATH_MAX to use Hurd-only functions
+       add_cppflags -DMKSH__NO_PATH_MAX
        ;;
 GNU/kFreeBSD)
        case $CC in
@@ -447,7 +591,7 @@ GNU/kFreeBSD)
        esac
        ;;
 Haiku)
-       add_cppflags -DMKSH_ASSUME_UTF8
+       add_cppflags -DMKSH_ASSUME_UTF8; HAVE_ISSET_MKSH_ASSUME_UTF8=1
        ;;
 HP-UX)
        ;;
@@ -469,9 +613,20 @@ Linux)
        add_cppflags -DSETUID_CAN_FAIL_WITH_EAGAIN
        : ${HAVE_REVOKE=0}
        ;;
+LynxOS)
+       oswarn="; it has minor issues"
+       ;;
 MidnightBSD)
        ;;
-Minix)
+Minix-vmd)
+       add_cppflags -DMKSH__NO_SETEUGID
+       add_cppflags -DMKSH_UNEMPLOYED
+       add_cppflags -DMKSH_CONSERVATIVE_FDS
+       add_cppflags -D_MINIX_SOURCE
+       oldish_ed=no-stderr-ed          # no /bin/ed, maybe see below
+       : ${HAVE_SETLOCALE_CTYPE=0}
+       ;;
+Minix3)
        add_cppflags -DMKSH_UNEMPLOYED
        add_cppflags -DMKSH_CONSERVATIVE_FDS
        add_cppflags -DMKSH_NO_LIMITS
@@ -482,11 +637,37 @@ Minix)
 MirBSD)
        ;;
 MSYS_*)
-       # probably same as CYGWIN* – need to test; from RT|Chatzilla
-       oswarn='but will probably work'
+       add_cppflags -DMKSH_ASSUME_UTF8=0; HAVE_ISSET_MKSH_ASSUME_UTF8=1
+       # almost same as CYGWIN* (from RT|Chatzilla)
+       : ${HAVE_SETLOCALE_CTYPE=0}
+       # broken on this OE (from ir0nh34d)
+       : ${HAVE_STDINT_H=0}
        ;;
 NetBSD)
        ;;
+NEXTSTEP)
+       add_cppflags -D_NEXT_SOURCE
+       add_cppflags -D_POSIX_SOURCE
+       : ${AWK=gawk} ${CC=cc -posix}
+       add_cppflags -DMKSH_NO_SIGSETJMP
+       # NeXTstep cannot get a controlling tty
+       add_cppflags -DMKSH_UNEMPLOYED
+       case $TARGET_OSREV in
+       4.2*)
+               # OpenStep 4.2 is broken by default
+               oswarn="; it needs libposix.a"
+               ;;
+       esac
+       add_cppflags -DMKSH_CONSERVATIVE_FDS
+       ;;
+Ninix3)
+       # similar to Minix3
+       add_cppflags -DMKSH_UNEMPLOYED
+       add_cppflags -DMKSH_CONSERVATIVE_FDS
+       add_cppflags -DMKSH_NO_LIMITS
+       # but no idea what else could be needed
+       oswarn="; it has unknown issues"
+       ;;
 OpenBSD)
        : ${HAVE_SETLOCALE_CTYPE=0}
        ;;
@@ -503,7 +684,8 @@ Plan9)
        add_cppflags -D_LIMITS_EXTENSION
        add_cppflags -D_BSD_EXTENSION
        add_cppflags -D_SUSV2_SOURCE
-       add_cppflags -DMKSH_ASSUME_UTF8
+       add_cppflags -DMKSH_ASSUME_UTF8; HAVE_ISSET_MKSH_ASSUME_UTF8=1
+       add_cppflags -DMKSH_NO_CMDLINE_EDITING
        oswarn=' and will currently not work'
        add_cppflags -DMKSH_UNEMPLOYED
        ;;
@@ -514,6 +696,7 @@ PW32*)
        ;;
 QNX)
        add_cppflags -D__NO_EXT_QNX
+       add_cppflags -D__EXT_UNIX_MISC
        case $TARGET_OSREV in
        [012345].*|6.[0123].*|6.4.[01])
                oldish_ed=no-stderr-ed          # oldish /bin/ed is broken
@@ -521,19 +704,46 @@ QNX)
        esac
        : ${HAVE_SETLOCALE_CTYPE=0}
        ;;
+SCO_SV)
+       case $TARGET_OSREV in
+       3.2*)
+               # SCO OpenServer 5
+               add_cppflags -DMKSH_UNEMPLOYED
+               ;;
+       5*)
+               # SCO OpenServer 6
+               ;;
+       *)
+               oswarn='; this is an unknown version of'
+               oswarn="$oswarn$nl$TARGET_OS ${TARGET_OSREV}, please tell me what to do"
+               ;;
+       esac
+       add_cppflags -DMKSH_CONSERVATIVE_FDS
+       : ${HAVE_SYS_SIGLIST=0} ${HAVE__SYS_SIGLIST=0}
+       ;;
+skyos)
+       oswarn="; it has minor issues"
+       ;;
 SunOS)
        add_cppflags -D_BSD_SOURCE
        add_cppflags -D__EXTENSIONS__
        ;;
 syllable)
        add_cppflags -D_GNU_SOURCE
+       add_cppflags -DMKSH_NO_SIGSUSPEND
        oswarn=' and will currently not work'
        ;;
 ULTRIX)
        : ${CC=cc -YPOSIX}
-       add_cppflags -Dssize_t=int
+       add_cppflags -DMKSH_TYPEDEF_SSIZE_T=int
+       add_cppflags -DMKSH_CONSERVATIVE_FDS
        : ${HAVE_SETLOCALE_CTYPE=0}
        ;;
+UnixWare|UNIX_SV)
+       # SCO UnixWare
+       add_cppflags -DMKSH_CONSERVATIVE_FDS
+       : ${HAVE_SYS_SIGLIST=0} ${HAVE__SYS_SIGLIST=0}
+       ;;
 UWIN*)
        ccpc='-Yc,'
        ccpl='-Yl,'
@@ -542,14 +752,21 @@ UWIN*)
        oswarn="$oswarn${nl}platform itself is very flakey/unreliable"
        : ${HAVE_SETLOCALE_CTYPE=0}
        ;;
+_svr4)
+       # generic target for SVR4 Unix with uname -s = uname -n
+       # this duplicates the * target below
+       oswarn='; it may or may not work'
+       test x"$TARGET_OSREV" = x"" && TARGET_OSREV=`uname -r`
+       ;;
 *)
        oswarn='; it may or may not work'
+       test x"$TARGET_OSREV" = x"" && TARGET_OSREV=`uname -r`
        ;;
 esac
 
 : ${HAVE_MKNOD=0}
 
-: ${CC=cc} ${NROFF=nroff}
+: ${AWK=awk} ${CC=cc} ${NROFF=nroff}
 test 0 = $r && echo | $NROFF -v 2>&1 | grep GNU >/dev/null 2>&1 && \
     NROFF="$NROFF -c"
 
@@ -572,6 +789,10 @@ OSF1)
        vv '|' "uname -a >&2"
        vv '|' "/usr/sbin/sizer -v >&2"
        ;;
+SCO_SV|UnixWare|UNIX_SV)
+       vv '|' "uname -a >&2"
+       vv '|' "uname -X >&2"
+       ;;
 *)
        vv '|' "uname -a >&2"
        ;;
@@ -582,7 +803,7 @@ operating system '$TARGET_OS'$oswarn. If you can provide
 a shell account to the developer, this may improve; please
 drop us a success or failure notice or even send in diffs.
 "
-$e "$bi$me: Building the MirBSD Korn Shell$ao $ui$dstversion$ao"
+$e "$bi$me: Building the MirBSD Korn Shell$ao $ui$dstversion$ao on $TARGET_OS ${TARGET_OSREV}..."
 
 #
 # Begin of mirtoconf checks
@@ -600,62 +821,77 @@ $e $bi$me: Scanning for functions... please ignore any errors.$ao
 CPP="$CC -E"
 $e ... which compiler seems to be used
 cat >conftest.c <<'EOF'
+const char *
 #if defined(__ICC) || defined(__INTEL_COMPILER)
-ct=icc
+ct="icc"
 #elif defined(__xlC__) || defined(__IBMC__)
-ct=xlc
+ct="xlc"
 #elif defined(__SUNPRO_C)
-ct=sunpro
+ct="sunpro"
 #elif defined(__ACK__)
-ct=ack
+ct="ack"
 #elif defined(__BORLANDC__)
-ct=bcc
+ct="bcc"
 #elif defined(__WATCOMC__)
-ct=watcom
+ct="watcom"
 #elif defined(__MWERKS__)
-ct=metrowerks
+ct="metrowerks"
 #elif defined(__HP_cc)
-ct=hpcc
+ct="hpcc"
 #elif defined(__DECC) || (defined(__osf__) && !defined(__GNUC__))
-ct=dec
+ct="dec"
 #elif defined(__PGI)
-ct=pgi
+ct="pgi"
 #elif defined(__DMC__)
-ct=dmc
+ct="dmc"
 #elif defined(_MSC_VER)
-ct=msc
+ct="msc"
 #elif defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__)
-ct=adsp
+ct="adsp"
 #elif defined(__IAR_SYSTEMS_ICC__)
-ct=iar
+ct="iar"
 #elif defined(SDCC)
-ct=sdcc
+ct="sdcc"
 #elif defined(__PCC__)
-ct=pcc
+ct="pcc"
 #elif defined(__TenDRA__)
-ct=tendra
+ct="tendra"
 #elif defined(__TINYC__)
-ct=tcc
+ct="tcc"
 #elif defined(__llvm__) && defined(__clang__)
-ct=clang
+ct="clang"
 #elif defined(__NWCC__)
-ct=nwcc
+ct="nwcc"
 #elif defined(__GNUC__)
-ct=gcc
+ct="gcc"
 #elif defined(_COMPILER_VERSION)
-ct=mipspro
+ct="mipspro"
 #elif defined(__sgi)
-ct=mipspro
+ct="mipspro"
 #elif defined(__hpux) || defined(__hpua)
-ct=hpcc
+ct="hpcc"
 #elif defined(__ultrix)
-ct=ucode
+ct="ucode"
+#elif defined(__USLC__)
+ct="uslc"
+#elif defined(__LCC__)
+ct="lcc"
+#else
+ct="unknown"
+#endif
+;
+const char *
+#if defined(__KLIBC__)
+et="klibc"
 #else
-ct=unknown
+et="unknown"
 #endif
+;
 EOF
-ct=unknown
-vv ']' "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c | grep ct= | tr -d \\\\015 >x"
+ct=untested
+et=untested
+vv ']' "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c | \
+    sed -n '/^ *[ce]t *= */s/^ *\([ce]t\) *= */\1=/p' | tr -d \\\\015 >x"
 sed 's/^/[ /' x
 eval `cat x`
 rmf x vv.out
@@ -679,8 +915,9 @@ bcc)
 clang)
        # does not work with current "ccc" compiler driver
        vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -version"
-       # this works, for now
+       # one of these two works, for now
        vv '|' "${CLANG-clang} -version"
+       vv '|' "${CLANG-clang} --version"
        # ensure compiler and linker are in sync unless overridden
        case $CCC_CC:$CCC_LD in
        :*)     ;;
@@ -715,6 +952,10 @@ iar)
 icc)
        vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V"
        ;;
+lcc)
+       vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS"
+       add_cppflags -D__inline__=__inline
+       ;;
 metrowerks)
        echo >&2 'Warning: Metrowerks C compiler detected. This has not yet
     been tested for compatibility with mksh. Continue at your
@@ -773,10 +1014,18 @@ ucode)
        vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V"
        vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -Wl,-V conftest.c $LIBS"
        ;;
+uslc)
+       case $TARGET_OS:$TARGET_OSREV in
+       SCO_SV:3.2*)
+               # SCO OpenServer 5
+               CFLAGS="$CFLAGS -g"
+               : ${HAVE_CAN_OTWO=0} ${HAVE_CAN_OPTIMISE=0}
+               ;;
+       esac
+       vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
+       ;;
 watcom)
-       echo >&2 'Warning: Watcom C Compiler detected. This compiler has not yet
-    been tested for compatibility with mksh. Continue at your
-    own risk, please report success/failure to the developers.'
+       vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS"
        ;;
 xlc)
        vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -qversion"
@@ -784,7 +1033,11 @@ xlc)
        vv '|' "ld -V"
        ;;
 *)
+       test x"$ct" = x"untested" && $e "!!! detecting preprocessor failed"
        ct=unknown
+       vv "$CC --version"
+       vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS"
+       vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
        ;;
 esac
 case $cm in
@@ -792,7 +1045,19 @@ dragonegg|llvm)
        vv '|' "llc -version"
        ;;
 esac
-$e "$bi==> which compiler seems to be used...$ao $ui$ct$ao"
+case $et in
+klibc)
+       add_cppflags -DMKSH_NO_LIMITS
+       ;;
+unknown)
+       # nothing special detected, don’t worry
+       unset et
+       ;;
+*)
+       # huh?
+       ;;
+esac
+$e "$bi==> which compiler seems to be used...$ao $ui$ct${et+ on $et}$ao"
 rmf conftest.c conftest.o conftest a.out* a.exe* vv.out
 
 #
@@ -831,6 +1096,7 @@ if ac_ifcpp 'ifdef __TINYC__' couldbe_tcc '!' compiler_known 0 \
     'if this could be tcc'; then
        ct=tcc
        CPP='cpp -D__TINYC__'
+       HAVE_COMPILER_KNOWN=1
 fi
 
 if test $ct = sunpro; then
@@ -864,6 +1130,9 @@ elif test $ct = tendra; then
 elif test $ct = ucode; then
        save_NOWARN=
        DOWARN=-w2
+elif test $ct = watcom; then
+       save_NOWARN=
+       DOWARN=-Wc,-we
 else
        test x"$save_NOWARN" = x"" && save_NOWARN=-Wno-error
        ac_flags 0 wnoerror "$save_NOWARN"
@@ -908,9 +1177,11 @@ i=0
 if test $ct = gcc; then
        # The following tests run with -Werror (gcc only) if possible
        NOWARN=$DOWARN; phase=u
+       ac_flags 0 wnooverflow -Wno-overflow
+       # mksh is not written in CFrustFrust!
+       ac_flags 1 no_eh_frame -fno-asynchronous-unwind-tables
        ac_flags 1 fnostrictaliasing -fno-strict-aliasing
        ac_flags 1 fstackprotectorall -fstack-protector-all
-       ac_flags 1 fwrapv -fwrapv
        test $cm = dragonegg && case " $CC $CFLAGS $LDFLAGS " in
        *\ -fplugin=*dragonegg*) ;;
        *) ac_flags 1 fplugin_dragonegg -fplugin=dragonegg ;;
@@ -960,13 +1231,12 @@ elif test $ct = icc; then
 elif test $ct = sunpro; then
        phase=u
        ac_flags 1 v -v
-       ac_flags 1 xc99 -xc99 'for support of ISO C99'
        ac_flags 1 ipo -xipo 'for cross-module optimisation'
        phase=x
 elif test $ct = hpcc; then
        phase=u
-       ac_flags 1 agcc -Agcc 'for support of GCC extensions'
-       ac_flags 1 ac99 -AC99 'for support of ISO C99'
+       # probably not needed
+       #ac_flags 1 agcc -Agcc 'for support of GCC extensions'
        phase=x
 elif test $ct = dec; then
        ac_flags 0 verb -verbose
@@ -977,7 +1247,6 @@ elif test $ct = dmc; then
 elif test $ct = bcc; then
        ac_flags 1 strpool "${ccpc}-d" 'if string pooling can be enabled'
 elif test $ct = mipspro; then
-       ac_flags 1 xc99 -c99 'for support of ISO C99'
        ac_flags 1 fullwarn -fullwarn 'for remark output support'
 elif test $ct = msc; then
        ac_flags 1 strpool "${ccpc}/GF" 'if string pooling can be enabled'
@@ -989,11 +1258,9 @@ elif test $ct = msc; then
        ac_flags 1 wall "${ccpc}/Wall" 'to enable all warnings'
        ac_flags 1 wp64 "${ccpc}/Wp64" 'to enable 64-bit warnings'
 elif test $ct = xlc; then
-       ac_flags 1 x99 -qlanglvl=extc99
-       test 1 = $HAVE_CAN_X99 || ac_flags 1 c99 -qlanglvl=stdc99
        ac_flags 1 rodata "-qro -qroconst -qroptr"
        ac_flags 1 rtcheck -qcheck=all
-       ac_flags 1 rtchkc -qextchk
+       #ac_flags 1 rtchkc -qextchk     # reported broken
        ac_flags 1 wformat "-qformat=all -qformat=nozln"
        #ac_flags 1 wp64 -qwarn64       # too verbose for now
 elif test $ct = tendra; then
@@ -1001,19 +1268,17 @@ elif test $ct = tendra; then
        test 1 = $HAVE_CAN_YSYSTEM && CPPFLAGS="-Ysystem $CPPFLAGS"
        ac_flags 1 extansi -Xa
 elif test $ct = tcc; then
-       ac_flags 1 boundschk -b
+       : #broken# ac_flags 1 boundschk -b
 elif test $ct = clang; then
        i=1
 elif test $ct = nwcc; then
        i=1
-       #broken# ac_flags 1 ssp -stackprotect
+       #broken# ac_flags 1 ssp -stackprotect
 fi
 # flags common to a subset of compilers (run with -Werror on gcc)
 if test 1 = $i; then
-       ac_flags 1 stdg99 -std=gnu99 'for support of ISO C99 + GCC extensions'
-       test 1 = $HAVE_CAN_STDG99 || \
-           ac_flags 1 stdc99 -std=c99 'for support of ISO C99'
        ac_flags 1 wall -Wall
+       ac_flags 1 fwrapv -fwrapv
 fi
 
 phase=x
@@ -1036,6 +1301,10 @@ ac_test attribute_bounded '' 'for __attribute__((__bounded__))' <<-'EOF'
            __attribute__((__bounded__ (__buffer__, 2, 3)));
        int main(int ac, char *av[]) { return (xcopy(av[0], av[--ac], 1)); }
        int xcopy(const void *s, void *d, size_t n) {
+               /*
+                * if memmove does not exist, we are not on a system
+                * with GCC with __bounded__ attribute either so poo
+                */
                memmove(d, s, n); return ((int)n);
        }
        #endif
@@ -1054,20 +1323,6 @@ ac_test attribute_format '' 'for __attribute__((__format__))' <<-'EOF'
        int main(int ac, char **av) { return (fprintf(stderr, "%s%d", *av, ac)); }
        #endif
 EOF
-ac_test attribute_nonnull '' 'for __attribute__((__nonnull__))' <<-'EOF'
-       #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
-       /* force a failure: TenDRA and gcc 1.42 have false positive here */
-       int main(void) { return (thiswillneverbedefinedIhope()); }
-       #else
-       int foo(char *s1, char *s2) __attribute__((__nonnull__));
-       int bar(char *s1, char *s2) __attribute__((__nonnull__ (1, 2)));
-       int baz(char *s) __attribute__((__nonnull__ (1)));
-       int foo(char *s1, char *s2) { return (bar(s2, s1)); }
-       int bar(char *s1, char *s2) { return (baz(s1) - baz(s2)); }
-       int baz(char *s) { return (*s); }
-       int main(int ac, char **av) { return (ac == foo(av[0], av[ac-1])); }
-       #endif
-EOF
 ac_test attribute_noreturn '' 'for __attribute__((__noreturn__))' <<-'EOF'
        #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
        /* force a failure: TenDRA and gcc 1.42 have false positive here */
@@ -1108,24 +1363,6 @@ phase=x
 #
 if ac_ifcpp 'ifdef MKSH_SMALL' isset_MKSH_SMALL '' \
     "if a reduced-feature mksh is requested"; then
-       #XXX this sucks; fix it for *all* compilers
-       case $ct in
-       clang|icc|nwcc)
-               ac_flags 1 fnoinline -fno-inline
-               ;;
-       gcc)
-               NOWARN=$DOWARN; phase=u
-               ac_flags 1 fnoinline -fno-inline
-               NOWARN=$save_NOWARN; phase=x
-               ;;
-       sunpro)
-               ac_flags 1 fnoinline -xinline=
-               ;;
-       xlc)
-               ac_flags 1 fnoinline -qnoinline
-               ;;
-       esac
-
        : ${HAVE_NICE=0}
        : ${HAVE_PERSISTENT_HISTORY=0}
        check_categories="$check_categories smksh"
@@ -1145,15 +1382,34 @@ ac_ifcpp 'ifdef MKSH_ASSUME_UTF8' isset_MKSH_ASSUME_UTF8 '' \
 ac_ifcpp 'ifdef MKSH_CONSERVATIVE_FDS' isset_MKSH_CONSERVATIVE_FDS '' \
     'if traditional/conservative fd use is requested' && \
     check_categories="$check_categories convfds"
+#ac_ifcpp 'ifdef MKSH_DISABLE_DEPRECATED' isset_MKSH_DISABLE_DEPRECATED '' \
+#    "if deprecated features are to be omitted" && \
+#    check_categories="$check_categories nodeprecated"
+#ac_ifcpp 'ifdef MKSH_DISABLE_EXPERIMENTAL' isset_MKSH_DISABLE_EXPERIMENTAL '' \
+#    "if experimental features are to be omitted" && \
+#    check_categories="$check_categories noexperimental"
+ac_ifcpp 'ifdef MKSH_MIDNIGHTBSD01ASH_COMPAT' isset_MKSH_MIDNIGHTBSD01ASH_COMPAT '' \
+    'if the MidnightBSD 0.1 ash compatibility mode is requested' && \
+    check_categories="$check_categories mnbsdash"
 
 #
 # Environment: headers
 #
+ac_header sys/time.h sys/types.h
+ac_header time.h sys/types.h
+test "11" = "$HAVE_SYS_TIME_H$HAVE_TIME_H" || HAVE_BOTH_TIME_H=0
+ac_test both_time_h '' 'whether <sys/time.h> and <time.h> can both be included' <<-'EOF'
+       #include <sys/types.h>
+       #include <sys/time.h>
+       #include <time.h>
+       int main(void) { struct tm tm; return ((int)sizeof(tm)); }
+EOF
 ac_header sys/bsdtypes.h
 ac_header sys/file.h sys/types.h
 ac_header sys/mkdev.h sys/types.h
 ac_header sys/mman.h sys/types.h
 ac_header sys/param.h
+ac_header sys/resource.h sys/types.h _time
 ac_header sys/select.h sys/types.h
 ac_header sys/sysmacros.h
 ac_header bstring.h
@@ -1164,55 +1420,11 @@ ac_header paths.h
 ac_header stdint.h stdarg.h
 # include strings.h only if compatible with string.h
 ac_header strings.h sys/types.h string.h
+ac_header termios.h
 ac_header ulimit.h sys/types.h
 ac_header values.h
 
 #
-# check whether whatever we use for the final link will succeed
-#
-if test $cm = makefile; then
-       : nothing to check
-else
-       HAVE_LINK_WORKS=x
-       ac_testinit link_works '' 'checking if the final link command may succeed'
-       fv=1
-       cat >conftest.c <<-'EOF'
-               #define EXTERN
-               #define MKSH_INCLUDES_ONLY
-               #include "sh.h"
-               __RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.488 2011/10/07 19:51:41 tg Exp $");
-               int main(void) { printf("Hello, World!\n"); return (0); }
-EOF
-       case $cm in
-       llvm)
-               v "$CC $CFLAGS $CPPFLAGS $NOWARN -emit-llvm -c conftest.c" || fv=0
-               rmf mksh.s
-               test $fv = 0 || v "llvm-link -o - conftest.o | opt $optflags | llc -o mksh.s" || fv=0
-               test $fv = 0 || v "$CC $CFLAGS $LDFLAGS -o $tcfn mksh.s $LIBS $ccpr"
-               ;;
-       dragonegg)
-               v "$CC $CFLAGS $CPPFLAGS $NOWARN -S -flto conftest.c" || fv=0
-               test $fv = 0 || v "mv conftest.s conftest.ll"
-               test $fv = 0 || v "llvm-as conftest.ll" || fv=0
-               rmf mksh.s
-               test $fv = 0 || v "llvm-link -o - conftest.bc | opt $optflags | llc -o mksh.s" || fv=0
-               test $fv = 0 || v "$CC $CFLAGS $LDFLAGS -o $tcfn mksh.s $LIBS $ccpr"
-               ;;
-       combine)
-               v "$CC $CFLAGS $CPPFLAGS $LDFLAGS -fwhole-program --combine $NOWARN -o $tcfn conftest.c $LIBS $ccpr"
-               ;;
-       lto|normal)
-               cm=normal
-               v "$CC $CFLAGS $CPPFLAGS $NOWARN -c conftest.c" || fv=0
-               test $fv = 0 || v "$CC $CFLAGS $LDFLAGS -o $tcfn conftest.o $LIBS $ccpr"
-               ;;
-       esac
-       test -f $tcfn || fv=0
-       ac_testdone
-       test $fv = 1 || exit 1
-fi
-
-#
 # Environment: definitions
 #
 echo '#include <sys/types.h>
@@ -1259,8 +1471,17 @@ EOF
 
 ac_test rlim_t <<-'EOF'
        #include <sys/types.h>
+       #if HAVE_BOTH_TIME_H
+       #include <sys/time.h>
+       #include <time.h>
+       #elif HAVE_SYS_TIME_H
        #include <sys/time.h>
+       #elif HAVE_TIME_H
+       #include <time.h>
+       #endif
+       #if HAVE_SYS_RESOURCE_H
        #include <sys/resource.h>
+       #endif
        #include <unistd.h>
        int main(void) { return ((int)(rlim_t)0); }
 EOF
@@ -1299,18 +1520,80 @@ test 1 = $HAVE_SIG_T || add_cppflags -Dsig_t=nosig_t
 ac_cppflags SIG_T
 
 #
-# Environment: signals
+# check whether whatever we use for the final link will succeed
+#
+if test $cm = makefile; then
+       : nothing to check
+else
+       HAVE_LINK_WORKS=x
+       ac_testinit link_works '' 'checking if the final link command may succeed'
+       fv=1
+       cat >conftest.c <<-'EOF'
+               #define EXTERN
+               #define MKSH_INCLUDES_ONLY
+               #include "sh.h"
+               __RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.622 2013/02/19 18:45:15 tg Exp $");
+               int main(void) { printf("Hello, World!\n"); return (0); }
+EOF
+       case $cm in
+       llvm)
+               v "$CC $CFLAGS $CPPFLAGS $NOWARN -emit-llvm -c conftest.c" || fv=0
+               rmf $tfn.s
+               test $fv = 0 || v "llvm-link -o - conftest.o | opt $optflags | llc -o $tfn.s" || fv=0
+               test $fv = 0 || v "$CC $CFLAGS $LDFLAGS -o $tcfn $tfn.s $LIBS $ccpr"
+               ;;
+       dragonegg)
+               v "$CC $CFLAGS $CPPFLAGS $NOWARN -S -flto conftest.c" || fv=0
+               test $fv = 0 || v "mv conftest.s conftest.ll"
+               test $fv = 0 || v "llvm-as conftest.ll" || fv=0
+               rmf $tfn.s
+               test $fv = 0 || v "llvm-link -o - conftest.bc | opt $optflags | llc -o $tfn.s" || fv=0
+               test $fv = 0 || v "$CC $CFLAGS $LDFLAGS -o $tcfn $tfn.s $LIBS $ccpr"
+               ;;
+       combine)
+               v "$CC $CFLAGS $CPPFLAGS $LDFLAGS -fwhole-program --combine $NOWARN -o $tcfn conftest.c $LIBS $ccpr"
+               ;;
+       lto|normal)
+               cm=normal
+               v "$CC $CFLAGS $CPPFLAGS $NOWARN -c conftest.c" || fv=0
+               test $fv = 0 || v "$CC $CFLAGS $LDFLAGS -o $tcfn conftest.o $LIBS $ccpr"
+               ;;
+       esac
+       test -f $tcfn || fv=0
+       ac_testdone
+       test $fv = 1 || exit 1
+fi
+
+#
+# Environment: errors and signals
 #
 test x"NetBSD" = x"$TARGET_OS" && $e Ignore the compatibility warning.
 
+ac_testn sys_errlist '' "the sys_errlist[] array and sys_nerr" <<-'EOF'
+       extern const int sys_nerr;
+       extern const char * const sys_errlist[];
+       int main(void) { return (*sys_errlist[sys_nerr - 1]); }
+EOF
+ac_testn _sys_errlist '!' sys_errlist 0 "the _sys_errlist[] array and _sys_nerr" <<-'EOF'
+       extern const int _sys_nerr;
+       extern const char * const _sys_errlist[];
+       int main(void) { return (*_sys_errlist[_sys_nerr - 1]); }
+EOF
+if test 1 = "$HAVE__SYS_ERRLIST"; then
+       add_cppflags -Dsys_nerr=_sys_nerr
+       add_cppflags -Dsys_errlist=_sys_errlist
+       HAVE_SYS_ERRLIST=1
+fi
+ac_cppflags SYS_ERRLIST
+
 for what in name list; do
        uwhat=`upper $what`
        ac_testn sys_sig$what '' "the sys_sig${what}[] array" <<-EOF
-               extern const char *const sys_sig${what}[];
+               extern const char * const sys_sig${what}[];
                int main(void) { return (sys_sig${what}[0][0]); }
        EOF
        ac_testn _sys_sig$what '!' sys_sig$what 0 "the _sys_sig${what}[] array" <<-EOF
-               extern const char *const _sys_sig${what}[];
+               extern const char * const _sys_sig${what}[];
                int main(void) { return (_sys_sig${what}[0][0]); }
        EOF
        eval uwhat_v=\$HAVE__SYS_SIG$uwhat
@@ -1321,28 +1604,27 @@ for what in name list; do
        ac_cppflags SYS_SIG$uwhat
 done
 
-ac_test strsignal '!' sys_siglist 0 <<-'EOF'
-       #include <string.h>
-       #include <signal.h>
-       int main(void) { return (strsignal(1)[0]); }
-EOF
-
 #
 # Environment: library functions
 #
-ac_testn flock_ex '' 'flock and mmap' <<-'EOF'
+ac_test flock <<-'EOF'
        #include <sys/types.h>
+       #include <fcntl.h>
+       #undef flock
        #if HAVE_SYS_FILE_H
        #include <sys/file.h>
        #endif
-       #if HAVE_SYS_MMAN_H
-       #include <sys/mman.h>
-       #endif
+       int main(void) { return (flock(0, LOCK_EX | LOCK_UN)); }
+EOF
+
+ac_test lock_fcntl '!' flock 1 'whether we can lock files with fcntl' <<-'EOF'
        #include <fcntl.h>
-       #include <stdlib.h>
-       int main(void) { return ((void *)mmap(NULL, (size_t)flock(0, LOCK_EX),
-           PROT_READ, MAP_PRIVATE, 0, (off_t)0) == (void *)NULL ? 1 :
-           munmap(NULL, 0)); }
+       #undef flock
+       int main(void) {
+               struct flock lks;
+               lks.l_type = F_WRLCK | F_UNLCK;
+               return (fcntl(0, F_SETLKW, &lks));
+       }
 EOF
 
 ac_test getrusage <<-'EOF'
@@ -1355,11 +1637,29 @@ ac_test getrusage <<-'EOF'
        }
 EOF
 
+ac_test gettimeofday <<-'EOF'
+       #define MKSH_INCLUDES_ONLY
+       #include "sh.h"
+       int main(void) { struct timeval tv; return (gettimeofday(&tv, NULL)); }
+EOF
+
 ac_test killpg <<-'EOF'
        #include <signal.h>
        int main(int ac, char *av[]) { return (av[0][killpg(123, ac)]); }
 EOF
 
+ac_test memmove <<-'EOF'
+       #include <sys/types.h>
+       #include <stddef.h>
+       #include <string.h>
+       #if HAVE_STRINGS_H
+       #include <strings.h>
+       #endif
+       int main(int ac, char *av[]) {
+               return (*(int *)(void *)memmove(av[0], av[1], ac));
+       }
+EOF
+
 ac_test mknod '' 'if to use mknod(), makedev() and friends' <<-'EOF'
        #define MKSH_INCLUDES_ONLY
        #include "sh.h"
@@ -1371,10 +1671,19 @@ ac_test mknod '' 'if to use mknod(), makedev() and friends' <<-'EOF'
        }
 EOF
 
-ac_test mkstemp <<-'EOF'
+ac_test mmap lock_fcntl 0 'for mmap and munmap' <<-'EOF'
+       #include <sys/types.h>
+       #if HAVE_SYS_FILE_H
+       #include <sys/file.h>
+       #endif
+       #if HAVE_SYS_MMAN_H
+       #include <sys/mman.h>
+       #endif
+       #include <stddef.h>
        #include <stdlib.h>
-       #include <unistd.h>
-       int main(void) { char tmpl[] = "X"; return (mkstemp(tmpl)); }
+       int main(void) { return ((void *)mmap(NULL, (size_t)0,
+           PROT_READ, MAP_PRIVATE, 0, (off_t)0) == (void *)NULL ? 1 :
+           munmap(NULL, 0)); }
 EOF
 
 ac_test nice <<-'EOF'
@@ -1405,7 +1714,14 @@ EOF
 
 ac_test select <<-'EOF'
        #include <sys/types.h>
+       #if HAVE_BOTH_TIME_H
+       #include <sys/time.h>
+       #include <time.h>
+       #elif HAVE_SYS_TIME_H
        #include <sys/time.h>
+       #elif HAVE_TIME_H
+       #include <time.h>
+       #endif
        #if HAVE_SYS_BSDTYPES_H
        #include <sys/bsdtypes.h>
        #endif
@@ -1444,16 +1760,47 @@ ac_test setgroups setresugid 0 <<-'EOF'
        int main(void) { gid_t gid = 0; return (setgroups(0, &gid)); }
 EOF
 
-ac_test strcasestr <<-'EOF'
-       #include <sys/types.h>
-       #include <stddef.h>
+if test x"$et" = x"klibc"; then
+
+       ac_testn __rt_sigsuspend '' 'whether klibc uses RT signals' <<-'EOF'
+               #define MKSH_INCLUDES_ONLY
+               #include "sh.h"
+               extern int __rt_sigsuspend(const sigset_t *, size_t);
+               int main(void) { return (__rt_sigsuspend(NULL, 0)); }
+EOF
+
+       # no? damn! legacy crap ahead!
+
+       ac_testn __sigsuspend_s '!' __rt_sigsuspend 1 \
+           'whether sigsuspend is usable (1/2)' <<-'EOF'
+               #define MKSH_INCLUDES_ONLY
+               #include "sh.h"
+               extern int __sigsuspend_s(sigset_t);
+               int main(void) { return (__sigsuspend_s(0)); }
+EOF
+       ac_testn __sigsuspend_xxs '!' __sigsuspend_s 1 \
+           'whether sigsuspend is usable (2/2)' <<-'EOF'
+               #define MKSH_INCLUDES_ONLY
+               #include "sh.h"
+               extern int __sigsuspend_xxs(int, int, sigset_t);
+               int main(void) { return (__sigsuspend_xxs(0, 0, 0)); }
+EOF
+
+       if test "000" = "$HAVE___RT_SIGSUSPEND$HAVE___SIGSUSPEND_S$HAVE___SIGSUSPEND_XXS"; then
+               # no usable sigsuspend(), use pause() *ugh*
+               add_cppflags -DMKSH_NO_SIGSUSPEND
+       fi
+fi
+
+ac_test strerror '!' sys_errlist 0 <<-'EOF'
+       extern char *strerror(int);
+       int main(int ac, char *av[]) { return (*strerror(*av[ac])); }
+EOF
+
+ac_test strsignal '!' sys_siglist 0 <<-'EOF'
        #include <string.h>
-       #if HAVE_STRINGS_H
-       #include <strings.h>
-       #endif
-       int main(int ac, char *av[]) {
-               return ((int)(ptrdiff_t)(void *)strcasestr(*av, av[ac]));
-       }
+       #include <signal.h>
+       int main(void) { return (strsignal(1)[0]); }
 EOF
 
 ac_test strlcpy <<-'EOF'
@@ -1465,36 +1812,215 @@ EOF
 #
 # check headers for declarations
 #
-save_CC=$CC; save_LDFLAGS=$LDFLAGS; save_LIBS=$LIBS
-CC="$CC -c -o $tcfn"; LDFLAGS=; LIBS=
-ac_test '!' flock_decl flock_ex 1 'if flock() does not need to be declared' <<-'EOF'
+ac_test flock_decl flock 1 'for declaration of flock()' <<-'EOF'
+       #define MKSH_INCLUDES_ONLY
+       #include "sh.h"
+       #if HAVE_SYS_FILE_H
+       #include <sys/file.h>
+       #endif
+       int main(void) { return ((flock)(0, 0)); }
+EOF
+ac_test revoke_decl revoke 1 'for declaration of revoke()' <<-'EOF'
        #define MKSH_INCLUDES_ONLY
        #include "sh.h"
-       long flock(void);               /* this clashes if defined before */
-       int main(void) { return ((int)flock()); }
+       int main(void) { return ((revoke)("")); }
 EOF
-ac_test '!' revoke_decl revoke 1 'if revoke() does not need to be declared' <<-'EOF'
+ac_test sys_errlist_decl sys_errlist 0 "for declaration of sys_errlist[] and sys_nerr" <<-'EOF'
        #define MKSH_INCLUDES_ONLY
        #include "sh.h"
-       long revoke(void);              /* this clashes if defined before */
-       int main(void) { return ((int)revoke()); }
+       int main(void) { return (*sys_errlist[sys_nerr - 1]); }
 EOF
-ac_test sys_siglist_decl sys_siglist 1 'if sys_siglist[] does not need to be declared' <<-'EOF'
+ac_test sys_siglist_decl sys_siglist 0 'for declaration of sys_siglist[]' <<-'EOF'
        #define MKSH_INCLUDES_ONLY
        #include "sh.h"
        int main(void) { return (sys_siglist[0][0]); }
 EOF
-CC=$save_CC; LDFLAGS=$save_LDFLAGS; LIBS=$save_LIBS
 
 #
 # other checks
 #
 fd='if to use persistent history'
-ac_cache PERSISTENT_HISTORY || test 0 = $HAVE_FLOCK_EX || fv=1
+ac_cache PERSISTENT_HISTORY || case $HAVE_MMAP$HAVE_FLOCK$HAVE_LOCK_FCNTL in
+11*|101) fv=1 ;;
+esac
 test 1 = $fv || check_categories="$check_categories no-histfile"
 ac_testdone
 ac_cppflags
 
+save_CFLAGS=$CFLAGS
+test x1 = x$HAVE_CAN_WNOOVERFLOW && CFLAGS="$CFLAGS -Wno-overflow"
+ac_testn compile_time_asserts_$$ '' 'whether compile-time assertions pass' <<-'EOF'
+       #define MKSH_INCLUDES_ONLY
+       #include "sh.h"
+       #ifndef CHAR_BIT
+       #define CHAR_BIT 8      /* defuse this test on really legacy systems */
+       #endif
+       struct ctasserts {
+       #define cta(name, assertion) char name[(assertion) ? 1 : -1]
+/* this one should be defined by the standard */
+cta(char_is_1_char, (sizeof(char) == 1) && (sizeof(signed char) == 1) &&
+    (sizeof(unsigned char) == 1));
+cta(char_is_8_bits, ((CHAR_BIT) == 8) && ((int)(unsigned char)0xFF == 0xFF) &&
+    ((int)(unsigned char)0x100 == 0) && ((int)(unsigned char)(int)-1 == 0xFF));
+/* the next assertion is probably not really needed */
+cta(short_is_2_char, sizeof(short) == 2);
+cta(short_size_no_matter_of_signedness, sizeof(short) == sizeof(unsigned short));
+/* the next assertion is probably not really needed */
+cta(int_is_4_char, sizeof(int) == 4);
+cta(int_size_no_matter_of_signedness, sizeof(int) == sizeof(unsigned int));
+
+cta(long_ge_int, sizeof(long) >= sizeof(int));
+cta(long_size_no_matter_of_signedness, sizeof(long) == sizeof(unsigned long));
+
+#ifndef MKSH_LEGACY_MODE
+/* the next assertion is probably not really needed */
+cta(ari_is_4_char, sizeof(mksh_ari_t) == 4);
+/* but the next two are; we REQUIRE signed integer wraparound */
+cta(ari_has_31_bit, 0 < (mksh_ari_t)(((((mksh_ari_t)1 << 15) << 15) - 1) * 2 + 1));
+#ifndef MKSH_GCC55009
+cta(ari_sign_32_bit_and_wrap,
+    (mksh_ari_t)(((((mksh_ari_t)1 << 15) << 15) - 1) * 2 + 1) >
+    (mksh_ari_t)(((((mksh_ari_t)1 << 15) << 15) - 1) * 2 + 2));
+#endif
+/* the next assertion is probably not really needed */
+cta(uari_is_4_char, sizeof(mksh_uari_t) == 4);
+/* but the next three are; we REQUIRE unsigned integer wraparound */
+cta(uari_has_31_bit, 0 < (mksh_uari_t)(((((mksh_uari_t)1 << 15) << 15) - 1) * 2 + 1));
+cta(uari_has_32_bit, 0 < (mksh_uari_t)(((((mksh_uari_t)1 << 15) << 15) - 1) * 4 + 3));
+cta(uari_wrap_32_bit,
+    (mksh_uari_t)(((((mksh_uari_t)1 << 15) << 15) - 1) * 4 + 3) >
+    (mksh_uari_t)(((((mksh_uari_t)1 << 15) << 15) - 1) * 4 + 4));
+#endif
+/* these are always required */
+cta(ari_is_signed, (mksh_ari_t)-1 < (mksh_ari_t)0);
+cta(uari_is_unsigned, (mksh_uari_t)-1 > (mksh_uari_t)0);
+
+cta(sizet_size_no_matter_of_signedness, sizeof(ssize_t) == sizeof(size_t));
+cta(ptrdifft_sizet_same_size, sizeof(ptrdiff_t) == sizeof(size_t));
+cta(ptrdifft_voidptr_same_size, sizeof(ptrdiff_t) == sizeof(void *));
+cta(ptrdifft_funcptr_same_size, sizeof(ptrdiff_t) == sizeof(void (*)(void)));
+/* our formatting routines assume this */
+cta(ptr_fits_in_long, sizeof(ptrdiff_t) <= sizeof(long));
+       };
+#ifndef MKSH_LEGACY_MODE
+#ifndef MKSH_GCC55009
+#define NUM 22
+#else
+#define NUM 21
+#endif
+#else
+#define NUM 15
+#endif
+char ctasserts_dblcheck[sizeof(struct ctasserts) == NUM ? 1 : -1];
+       int main(void) { return (sizeof(ctasserts_dblcheck)); }
+EOF
+CFLAGS=$save_CFLAGS
+eval test 1 = \$HAVE_COMPILE_TIME_ASSERTS_$$ || exit 1
+
+#
+# extra checks for legacy mksh
+#
+if test $legacy = 1; then
+       ac_test long_32bit '' 'whether long is 32 bit wide' <<-'EOF'
+               #define MKSH_INCLUDES_ONLY
+               #include "sh.h"
+               #ifndef CHAR_BIT
+               #define CHAR_BIT 0
+               #endif
+               struct ctasserts {
+               #define cta(name, assertion) char name[(assertion) ? 1 : -1]
+                       cta(char_is_8_bits, (CHAR_BIT) == 8);
+                       cta(long_is_32_bits, sizeof(long) == 4);
+               };
+               int main(void) { return (sizeof(struct ctasserts)); }
+EOF
+
+       ac_test long_64bit '!' long_32bit 0 'whether long is 64 bit wide' <<-'EOF'
+               #define MKSH_INCLUDES_ONLY
+               #include "sh.h"
+               #ifndef CHAR_BIT
+               #define CHAR_BIT 0
+               #endif
+               struct ctasserts {
+               #define cta(name, assertion) char name[(assertion) ? 1 : -1]
+                       cta(char_is_8_bits, (CHAR_BIT) == 8);
+                       cta(long_is_64_bits, sizeof(long) == 8);
+               };
+               int main(void) { return (sizeof(struct ctasserts)); }
+EOF
+
+       case $HAVE_LONG_32BIT$HAVE_LONG_64BIT in
+       10) check_categories="$check_categories int:32" ;;
+       01) check_categories="$check_categories int:64" ;;
+       *) check_categories="$check_categories int:u" ;;
+       esac
+fi
+
+#
+# runtime checks
+# once this is more than one, check if we can do runtime
+# checks (not cross-compiling) first to save on warnings
+#
+$e "${bi}run-time checks follow$ao, please ignore any weird errors"
+
+if ac_testnnd silent_idivwrapv '' '(run-time) whether signed integer division overflows wrap silently' <<-'EOF'
+       #define MKSH_INCLUDES_ONLY
+       #include "sh.h"
+       #if !defined(MKSH_LEGACY_MODE) || HAVE_LONG_32BIT
+       #define IDIVWRAPV_VL    (mksh_uari_t)0x80000000UL
+       #elif HAVE_LONG_64BIT
+       #define IDIVWRAPV_VL    (mksh_uari_t)0x8000000000000000UL
+       #else
+       # error "cannot check this"
+       #endif
+       #ifdef SIGFPE
+       static void fpe_catcher(int) MKSH_A_NORETURN;
+       #endif
+       int main(int ac, char **av) {
+               mksh_ari_t o1, o2, r1, r2;
+
+       #ifdef SIGFPE
+               signal(SIGFPE, fpe_catcher);
+       #endif
+               o1 = (mksh_ari_t)IDIVWRAPV_VL;
+               o2 = -ac;
+               r1 = o1 / o2;
+               r2 = o1 % o2;
+               if (r1 == o1 && r2 == 0) {
+                       printf("si");
+                       return (0);
+               }
+               printf("no %d %d %d %d %s", (int)o1, (int)o2, (int)r1,
+                   (int)r2, av[0]);
+               return (1);
+       }
+       #ifdef SIGFPE
+       static const char fpe_msg[] = "no, got SIGFPE, what were they smoking?";
+       #define fpe_msglen (sizeof(fpe_msg) - 1)
+       static void fpe_catcher(int sig MKSH_A_UNUSED) {
+               _exit(write(1, fpe_msg, fpe_msglen) == fpe_msglen ? 2 : 3);
+       }
+       #endif
+EOF
+then
+       if test $fv = 0; then
+               echo "| hrm, compiling this failed, but we will just failback"
+       else
+               echo "| running test programme; this will fail if cross-compiling"
+               echo "| in which case we will gracefully degrade to the default"
+               ./$tcfn >vv.out 2>&1
+               rv=$?
+               echo "| result: `cat vv.out`"
+               fv=0
+               test $rv = 0 && test x"`cat vv.out`" = x"si" && fv=1
+       fi
+       rmf conftest.c conftest.o ${tcfn}* vv.out
+       ac_testdone
+fi
+ac_cppflags
+
+$e "${bi}end of run-time checks$ao"
+
 #
 # Compiler: Praeprocessor (only if needed)
 #
@@ -1525,46 +2051,62 @@ if test 0 = $HAVE_SYS_SIGNAME; then
        else
                $e No list of signal names available via cpp. Falling back...
        fi
-       sigseen=:
+       sigseenone=:
+       sigseentwo=:
        echo '#include <signal.h>
 #ifndef NSIG
 #if defined(_NSIG)
 #define NSIG _NSIG
 #elif defined(SIGMAX)
 #define NSIG (SIGMAX+1)
+#elif defined(_SIGMAX)
+#define NSIG (_SIGMAX+1)
 #endif
 #endif
-mksh_cfg: NSIG' >conftest.c
+int
+mksh_cfg= NSIG
+;' >conftest.c
+       # GNU sed 2.03 segfaults when optimising this to sed -n
        NSIG=`vq "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c" | \
-           grep mksh_cfg: | sed 's/^mksh_cfg:[  ]*\([0-9x ()+-]*\).*$/\1/'`
+           grep '^ *mksh_cfg *=' | \
+           sed 's/^ *mksh_cfg *=[       ]*\([()0-9x+-][()0-9x+  -]*\).*$/\1/'`
        case $NSIG in
-       *[\ \(\)+-]*) NSIG=`awk "BEGIN { print $NSIG }"` ;;
+       *mksh_cfg*) $e "Error: NSIG='$NSIG'"; NSIG=0 ;;
+       *[\ \(\)+-]*) NSIG=`"$AWK" "BEGIN { print $NSIG }" </dev/null` ;;
        esac
        printf=printf
        (printf hallo) >/dev/null 2>&1 || printf=echo
+       test $printf = echo || test "`printf %d 42`" = 42 || printf=echo
        test $printf = echo || NSIG=`printf %d "$NSIG" 2>/dev/null`
        $printf "NSIG=$NSIG ... "
-       sigs="ABRT ALRM BUS CHLD CLD CONT DIL EMT FPE HUP ILL INFO INT IO IOT"
-       sigs="$sigs KILL LOST PIPE PROF PWR QUIT RESV SAK SEGV STOP SYS TERM"
+       sigs="INT SEGV ABRT KILL ALRM BUS CHLD CLD CONT DIL EMT FPE HUP ILL"
+       sigs="$sigs INFO IO IOT LOST PIPE PROF PWR QUIT RESV SAK STOP SYS TERM"
        sigs="$sigs TRAP TSTP TTIN TTOU URG USR1 USR2 VTALRM WINCH XCPU XFSZ"
        test 1 = $HAVE_CPP_DD && test $NSIG -gt 1 && sigs="$sigs "`vq \
            "$CPP $CFLAGS $CPPFLAGS $NOWARN -dD conftest.c" | \
-           grep '[      ]SIG[A-Z0-9]*[  ]' | \
-           sed 's/^\(.*[        ]SIG\)\([A-Z0-9]*\)\([  ].*\)$/\2/' | sort`
+           grep '[      ]SIG[A-Z0-9][A-Z0-9]*[  ]' | \
+           sed 's/^.*[  ]SIG\([A-Z0-9][A-Z0-9]*\)[      ].*$/\1/' | sort`
        test $NSIG -gt 1 || sigs=
        for name in $sigs; do
+               case $sigseenone in
+               *:$name:*) continue ;;
+               esac
+               sigseenone=$sigseenone$name:
                echo '#include <signal.h>' >conftest.c
-               echo mksh_cfg: SIG$name >>conftest.c
+               echo int >>conftest.c
+               echo mksh_cfg= SIG$name >>conftest.c
+               echo ';' >>conftest.c
+               # GNU sed 2.03 croaks on optimising this, too
                vq "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c" | \
-                   grep mksh_cfg: | \
-                   sed 's/^mksh_cfg:[   ]*\([0-9x]*\).*$/\1:'$name/
-       done | grep -v '^:' | sed 's/:/ /g' | while read nr name; do
+                   grep '^ *mksh_cfg *=' | \
+                   sed 's/^ *mksh_cfg *=[       ]*\([0-9][0-9x]*\).*$/:\1 '$name/
+       done | sed -n '/^:[^ ]/s/^://p' | while read nr name; do
                test $printf = echo || nr=`printf %d "$nr" 2>/dev/null`
                test $nr -gt 0 && test $nr -le $NSIG || continue
-               case $sigseen in
+               case $sigseentwo in
                *:$nr:*) ;;
                *)      echo "          { \"$name\", $nr },"
-                       sigseen=$sigseen$nr:
+                       sigseentwo=$sigseentwo$nr:
                        $printf "$name=$nr " >&2
                        ;;
                esac
@@ -1573,40 +2115,54 @@ mksh_cfg: NSIG' >conftest.c
        $e done.
 fi
 
-addsrcs '!' HAVE_STRLCPY strlcpy.c
+addsrcs -s '!' HAVE_STRLCPY strlcpy.c
 addsrcs USE_PRINTF_BUILTIN printf.c
 test 1 = "$USE_PRINTF_BUILTIN" && add_cppflags -DMKSH_PRINTF_BUILTIN
 test 1 = "$HAVE_CAN_VERB" && CFLAGS="$CFLAGS -verbose"
+test -n "$LDSTATIC" && add_cppflags -DMKSH_OPTSTATIC
+add_cppflags -DMKSH_BUILD_R=431
 
 $e $bi$me: Finished configuration testing, now producing output.$ao
 
 files=
 objs=
 sp=
+case $tcfn in
+a.exe) mkshexe=$tfn.exe ;;
+*)     mkshexe=$tfn ;;
+esac
 case $curdir in
-*\ *)  echo "#!./mksh" >test.sh ;;
-*)     echo "#!$curdir/mksh" >test.sh ;;
+*\ *)  mkshshebang="#!./$mkshexe" ;;
+*)     mkshshebang="#!$curdir/$mkshexe" ;;
 esac
-cat >>test.sh <<-EOF
+cat >test.sh <<-EOF
+       $mkshshebang
        LC_ALL=C PATH='$PATH'; export LC_ALL PATH
        test -n "\$KSH_VERSION" || exit 1
        set -A check_categories -- $check_categories
-       pflag='$curdir/mksh'
+       pflag='$curdir/$mkshexe'
        sflag='$srcdir/check.t'
-       usee=0 Pflag=0 uset=0 vflag=0 xflag=0
-       while getopts "C:e:Pp:s:t:v" ch; do case \$ch {
+       usee=0 Pflag=0 Sflag=0 uset=0 vflag=1 xflag=0
+       while getopts "C:e:fPp:QSs:t:v" ch; do case \$ch {
        (C)     check_categories[\${#check_categories[*]}]=\$OPTARG ;;
        (e)     usee=1; eflag=\$OPTARG ;;
+       (f)     check_categories[\${#check_categories[*]}]=fastbox ;;
        (P)     Pflag=1 ;;
+       (+P)    Pflag=0 ;;
        (p)     pflag=\$OPTARG ;;
+       (Q)     vflag=0 ;;
+       (+Q)    vflag=1 ;;
+       (S)     Sflag=1 ;;
+       (+S)    Sflag=0 ;;
        (s)     sflag=\$OPTARG ;;
        (t)     uset=1; tflag=\$OPTARG ;;
        (v)     vflag=1 ;;
+       (+v)    vflag=0 ;;
        (*)     xflag=1 ;;
        }
        done
        shift \$((OPTIND - 1))
-       set -A args -- '$srcdir/check.pl' -p "\$pflag" -s "\$sflag"
+       set -A args -- '$srcdir/check.pl' -p "\$pflag"
        x=
        for y in "\${check_categories[@]}"; do
                x=\$x,\$y
@@ -1627,19 +2183,40 @@ cat >>test.sh <<-EOF
        (( vflag )) && args[\${#args[*]}]=-v
        (( xflag )) && args[\${#args[*]}]=-x    # force usage by synerr
        print Testing mksh for conformance:
-       fgrep MirOS: '$srcdir/check.t'
-       fgrep MIRBSD '$srcdir/check.t'
+       fgrep -e MirOS: -e MIRBSD "\$sflag"
        print "This shell is actually:\\n\\t\$KSH_VERSION"
        print 'test.sh built for mksh $dstversion'
        cstr='\$os = defined \$^O ? \$^O : "unknown";'
        cstr="\$cstr"'print \$os . ", Perl version " . \$];'
        for perli in \$PERL perl5 perl no; do
-               [[ \$perli = no ]] && exit 1
-               perlos=\$(\$perli -e "\$cstr") 2>/dev/null || continue
-               print "Perl interpreter '\$perli' running on '\$perlos'"
-               [[ -n \$perlos ]] && break
+               if [[ \$perli = no ]]; then
+                       print Cannot find a working Perl interpreter, aborting.
+                       exit 1
+               fi
+               print "Trying Perl interpreter '\$perli'..."
+               perlos=\$(\$perli -e "\$cstr")
+               rv=\$?
+               print "Errorlevel \$rv, running on '\$perlos'"
+               if (( rv )); then
+                       print "=> not using"
+                       continue
+               fi
+               if [[ -n \$perlos ]]; then
+                       print "=> using it"
+                       break
+               fi
+       done
+       (( Sflag )) || echo + \$perli "\${args[@]}" -s "\$sflag" "\$@"
+       (( Sflag )) || exec \$perli "\${args[@]}" -s "\$sflag" "\$@"$tsts
+       # use of the -S option for check.t split into multiple chunks
+       rv=0
+       for s in "\$sflag".*; do
+               echo + \$perli "\${args[@]}" -s "\$s" "\$@"
+               \$perli "\${args[@]}" -s "\$s" "\$@"$tsts
+               rc=\$?
+               (( rv = rv ? rv : rc ))
        done
-       exec \$perli "\${args[@]}" "\$@"$tsts
+       exit \$rv
 EOF
 chmod 755 test.sh
 if test $cm = llvm; then
@@ -1649,7 +2226,8 @@ elif test $cm = dragonegg; then
 else
        emitbc=-c
 fi
-echo set -x >Rebuild.sh
+echo ": # work around NeXTstep bug" >Rebuild.sh
+echo set -x >>Rebuild.sh
 for file in $SRCS; do
        op=`echo x"$file" | sed 's/^x\(.*\)\.c$/\1./'`
        test -f $file || file=$srcdir/$file
@@ -1666,18 +2244,14 @@ for file in $SRCS; do
 done
 case $cm in
 dragonegg|llvm)
-       echo "rm -f mksh.s" >>Rebuild.sh
-       echo "llvm-link -o - $objs | opt $optflags | llc -o mksh.s" >>Rebuild.sh
-       lobjs=mksh.s
+       echo "rm -f $tfn.s" >>Rebuild.sh
+       echo "llvm-link -o - $objs | opt $optflags | llc -o $tfn.s" >>Rebuild.sh
+       lobjs=$tfn.s
        ;;
 *)
        lobjs=$objs
        ;;
 esac
-case $tcfn in
-a.exe) mkshexe=mksh.exe ;;
-*)     mkshexe=mksh ;;
-esac
 echo tcfn=$mkshexe >>Rebuild.sh
 echo "$CC $CFLAGS $LDFLAGS -o \$tcfn $lobjs $LIBS $ccpr" >>Rebuild.sh
 echo 'test -f $tcfn || exit 1; size $tcfn' >>Rebuild.sh
@@ -1711,9 +2285,10 @@ LIBS=            $LIBS
 #      \$(CC) \$(CFLAGS) \$(CPPFLAGS) -c \$<
 
 # for all make variants:
-#REGRESS_FLAGS=        -v
+#REGRESS_FLAGS=        -f
 #regress:
 #      ./test.sh \$(REGRESS_FLAGS)
+check_categories=$check_categories
 
 # for BSD make only:
 #.PATH: $srcdir
@@ -1751,33 +2326,111 @@ else
 fi
 case $cm in
 dragonegg|llvm)
-       rmf mksh.s
-       v "llvm-link -o - $objs | opt $optflags | llc -o mksh.s"
+       rmf $tfn.s
+       v "llvm-link -o - $objs | opt $optflags | llc -o $tfn.s"
        ;;
 esac
 tcfn=$mkshexe
 test $cm = combine || v "$CC $CFLAGS $LDFLAGS -o $tcfn $lobjs $LIBS $ccpr"
 test -f $tcfn || exit 1
-test 1 = $r || v "$NROFF -mdoc <'$srcdir/mksh.1' >mksh.cat1" || \
-    rmf mksh.cat1
+test 1 = $r || v "$NROFF -mdoc <'$srcdir/mksh.1' >$tfn.cat1" || \
+    rmf $tfn.cat1
 test 0 = $eq && v size $tcfn
 i=install
 test -f /usr/ucb/$i && i=/usr/ucb/$i
 test 1 = $eq && e=:
 $e
 $e Installing the shell:
-$e "# $i -c -s -o root -g bin -m 555 mksh /bin/mksh"
-$e "# grep -x /bin/mksh /etc/shells >/dev/null || echo /bin/mksh >>/etc/shells"
+$e "# $i -c -s -o root -g bin -m 555 $tfn /bin/$tfn"
+$e "# grep -x /bin/$tfn /etc/shells >/dev/null || echo /bin/$tfn >>/etc/shells"
 $e "# $i -c -o root -g bin -m 444 dot.mkshrc /usr/share/doc/mksh/examples/"
 $e
 $e Installing the manual:
-if test -f mksh.cat1; then
-       $e "# $i -c -o root -g bin -m 444 mksh.cat1" \
-           "/usr/share/man/cat1/mksh.0"
+if test -f $tfn.cat1; then
+       $e "# $i -c -o root -g bin -m 444 $tfn.cat1" \
+           "/usr/share/man/cat1/$tfn.0"
        $e or
 fi
-$e "# $i -c -o root -g bin -m 444 mksh.1 /usr/share/man/man1/mksh.1"
+$e "# $i -c -o root -g bin -m 444 mksh.1 /usr/share/man/man1/$tfn.1"
 $e
 $e Run the regression test suite: ./test.sh
 $e Please also read the sample file dot.mkshrc and the fine manual.
 exit 0
+
+: <<'EOD'
+
+=== Environment used ===
+
+==== build environment ====
+AWK                            default: awk
+CC                             default: cc
+CFLAGS                         if empty, defaults to -xO2 or +O2
+                               or -O3 -qstrict or -O2, per compiler
+CPPFLAGS                       default empty
+LDFLAGS                                default empty; added before sources
+LDSTATIC                       set this to '-static'; default unset
+LIBS                           default empty; added after sources
+                               [Interix] default: -lcrypt (XXX still needed?)
+NOWARN                         -Wno-error or similar
+NROFF                          default: nroff
+TARGET_OS                      default: $(uname -s || uname)
+TARGET_OSREV                   [QNX] default: $(uname -r)
+
+==== feature selectors ====
+USE_PRINTF_BUILTIN             1 to include (unsupported) printf(1) as builtin
+===== general format =====
+HAVE_STRLEN                    ac_test
+HAVE_STRING_H                  ac_header
+HAVE_CAN_FSTACKPROTECTORALL    ac_flags
+
+==== cpp definitions ====
+DEBUG                          dont use in production, wants gcc, implies:
+DEBUG_LEAKS                    enable freeing resources before exiting
+MKSHRC_PATH                    "~/.mkshrc" (do not change)
+MKSH_A4PB                      force use of arc4random_pushb
+MKSH_ASSUME_UTF8               (0=disabled, 1=enabled; default: unset)
+MKSH_BINSHREDUCED              if */sh or */-sh, enable set -o sh
+MKSH_CLRTOEOL_STRING           "\033[K"
+MKSH_CLS_STRING                        "\033[;H\033[J"
+MKSH_CONSERVATIVE_FDS          fd 0-9 for scripts, shell only up to 31
+MKSH_DEFAULT_EXECSHELL         "/bin/sh" (do not change)
+MKSH_DEFAULT_PROFILEDIR                "/etc" (do not change)
+MKSH_DEFAULT_TMPDIR            "/tmp" (do not change)
+MKSH_DISABLE_DEPRECATED                disable code paths scheduled for later removal
+MKSH_DISABLE_EXPERIMENTAL      disable code not yet comfy for (LTS) snapshots
+MKSH_DISABLE_TTY_WARNING       shut up warning about ctty if OS cant be fixed
+MKSH_DONT_EMIT_IDSTRING                omit RCS IDs from binary
+MKSH_GCC55009                  DANGER! see http://www.mirbsd.org/mksh.htm#p41
+MKSH_MIDNIGHTBSD01ASH_COMPAT   set -o sh: additional compatibility quirk
+MKSH_NOPROSPECTOFWORK          disable jobs, co-processes, etc. (do not use)
+MKSH_NOPWNAM                   skip PAM calls, for -static on eglibc, Solaris
+MKSH_NO_CMDLINE_EDITING                disable command line editing code entirely
+MKSH_NO_DEPRECATED_WARNING     omit warning when deprecated stuff is run
+MKSH_NO_EXTERNAL_CAT           omit hack to skip cat builtin when flags passed
+MKSH_NO_LIMITS                 omit ulimit code
+MKSH_NO_SIGSETJMP              define if sigsetjmp is broken or not available
+MKSH_NO_SIGSUSPEND             use sigprocmask+pause instead of sigsuspend
+MKSH_SMALL                     omit some code, optimise hard for size (slower)
+MKSH_SMALL_BUT_FAST            disable some hard-for-size optim. (modern sys.)
+MKSH_S_NOVI=1                  disable Vi editing mode (default if MKSH_SMALL)
+MKSH_TYPEDEF_SIG_ATOMIC_T      define to e.g. 'int' if sig_atomic_t is missing
+MKSH_TYPEDEF_SSIZE_T           define to e.g. 'long' if your OS has no ssize_t
+MKSH_UNEMPLOYED                        disable job control (but not jobs/co-processes)
+
+=== generic installation instructions ===
+
+Set CC and possibly CFLAGS, CPPFLAGS, LDFLAGS, LIBS. If cross-compiling,
+also set TARGET_OS. To disable tests, set e.g. HAVE_STRLCPY=0; to enable
+them, set to a value other than 0 or 1. Ensure /bin/ed is installed. For
+MKSH_SMALL but with Vi mode, add -DMKSH_S_NOVI=0 to CPPFLAGS as well.
+
+Normally, the following command is what you want to run, then:
+$ (sh Build.sh -r -c lto && ./test.sh -f) 2>&1 | tee log
+
+Copy dot.mkshrc to /etc/skel/.mkshrc; install mksh into $prefix/bin; or
+/bin; install the manpage, if omitting the -r flag a catmanpage is made
+using $NROFF. Consider using a forward script as /etc/skel/.mkshrc like
+https://www.mirbsd.org/cvs.cgi/contrib/hosted/tg/deb/mksh/debian/.mkshrc?rev=HEAD
+and put dot.mkshrc as /etc/mkshrc so users need not keep up their HOME.
+
+EOD