2 srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.668 2014/10/03 17:32:07 tg Exp $'
4 # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
5 # 2011, 2012, 2013, 2014
6 # Thorsten Glaser <tg@mirbsd.org>
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.
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.
23 # People analysing the output must whitelist conftest.c for any kind
24 # of compiler warning checks (mirtoconf is by design not quiet).
26 # Used environment documentation is at the end of this file.
31 case $ZSH_VERSION:$VERSION in
32 :zsh*) ZSH_VERSION=2 ;;
35 if test -n "${ZSH_VERSION+x}" && (emulate sh) >/dev/null 2>&1; then
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
49 safeIFS=" $safeIFS$nl"
51 allu=QWERTYUIOPASDFGHJKLZXCVBNM
52 alll=qwertyuiopasdfghjklzxcvbnm
54 alls=______________________________________________________________
59 echo >&2 "E: in '$srcfile': '$line'"
61 echo >&2 "E: invalid input in '$srcfile': '$line'"
68 optc=`echo "$line" | sed 's/^[<>]\(.\).*$/\1/'`
69 test x"$optc" = x'|' && return
70 optclo=`echo "$optc" | tr $allu $alll`
71 if test x"$optc" = x"$optclo"; then
76 sym=`echo "$line" | sed 's/^[<>]/|/'`
77 o_str=$o_str$nl"<$optclo$islo$sym"
86 cond=`echo "$cond" | sed 's/^ //'`
90 cond=`echo "$cond" | sed 's/^!//'`
101 test -f "$srcfile" || genopt_die Source file \$srcfile not set.
102 bn=`basename "$srcfile" | sed 's/.opt$//'`
110 while IFS= read line; do
115 o_sym=`echo "$line" | sed 's/^.//'`
116 o_gen=$o_gen$nl"#undef F0"
117 o_gen=$o_gen$nl"#undef FN"
122 # begin of data block
123 o_gen=$o_gen$nl"#endif"
124 o_gen=$o_gen$nl"#ifndef F0"
125 o_gen=$o_gen$nl"#define F0 FN"
126 o_gen=$o_gen$nl"#endif"
132 # begin of a definition block
133 sym=`echo "$line" | sed 's/^@//'`
134 if test $state = 0; then
135 o_gen=$o_gen$nl"#if defined($sym)"
137 o_gen=$o_gen$nl"#elif defined($sym)"
139 ddefs="$ddefs$nl#undef $sym"
153 cond=`echo "$line" | sed 's/^[^|]*|//'`
159 IFS= read line || genopt_die Unexpected EOF
161 test -n "$cond" && o_gen=$o_gen$nl"$cond"
162 o_gen=$o_gen$nl"$line, $optc)"
163 test -n "$cond" && o_gen=$o_gen$nl"#endif"
167 case $state:$o_sym in
168 3:) genopt_die Expected optc sym at EOF ;;
170 *) genopt_die Missing EOF marker ;;
172 echo "$o_str" | sort | while IFS='|' read x opts cond; do
174 test -n "$x" || continue
176 test -n "$cond" && echo "$cond"
178 test -n "$cond" && echo "#endif"
180 echo "#ifndef $o_sym$o_gen"
190 if test x"$BUILDSH_RUN_GENOPT" = x"1"; then
194 if test x"$1" = x"-G"; then
199 echo "For the build logs, demonstrate that /dev/null and /dev/tty exist:"
200 ls -l /dev/null /dev/tty
211 eval "$@" >vv.out 2>&1
212 sed "s
\a^
\a${_c}
\a" <vv.out
222 Build.sh|check.pl|check.t|dot.mkshrc|*.1|*.c|*.h|*.ico|*.opt) ;;
236 oldish_ed=stdout-ed,no-stderr-ed
245 echo :"$@" | sed 's/^://' | tr $alll $allu
248 # clean up after ac_testrun()
252 test 0 = $fv || fr=yes
253 $e "$bi==> $fd...$ao $ui$fr$ao$fx"
257 # ac_cache label: sets f, fu, fv?=0
272 # ac_testinit label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput
273 # returns 1 if value was cached/implied, 0 otherwise: call ac_testdone
276 test x"$2" = x"!" && shift
277 test x"$2" = x"" || shift
283 if test x"$2" = x""; then
286 if test x"$2" = x"!"; then
290 eval ft=\$HAVE_`upper $2`
294 if test $fc = "$ft"; then
304 # pipe .c | ac_test[n] [!] label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput
306 if test x"$1" = x"!"; then
312 ac_testinit "$@" || return 1
314 vv ']' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN conftest.c $LIBS $ccpr"
315 test $tcfn = no && test -f a.out && tcfn=a.out
316 test $tcfn = no && test -f a.exe && tcfn=a.exe
317 test $tcfn = no && test -f conftest && tcfn=conftest
318 if test -f $tcfn; then
324 if test $phase = u; then
325 test $ct = gcc && vscan='unrecogni[sz]ed'
326 test $ct = hpcc && vscan='unsupported'
327 test $ct = pcc && vscan='unsupported'
328 test $ct = sunpro && vscan='-e ignored -e turned.off'
330 test -n "$vscan" && grep $vscan vv.out >/dev/null 2>&1 && fv=$fr
334 ac_testnnd "$@" || return
335 rmf conftest.c conftest.o ${tcfn}* vv.out
339 # ac_ifcpp cppexpr [!] label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput
344 extern int thiswillneverbedefinedIhope(void);
345 int main(void) { return (isatty(0) +
349 /* force a failure: expr is false */
350 thiswillneverbedefinedIhope()
354 test x"$1" = x"!" && shift
362 CPPFLAGS="$CPPFLAGS $*"
366 test x"$1" = x"" || fu=$1
368 test x"$2" = x"" && eval fv=\$HAVE_$fu
369 add_cppflags -DHAVE_$fu=$fv
377 # ac_flags [-] add varname cflags [text] [ldflags]
379 if test x"$1" = x"-"; then
390 test x"$ft" = x"" && ft="if $f can be used"
393 if test -n "$fl"; then
394 save_LDFLAGS=$LDFLAGS
395 LDFLAGS="$LDFLAGS $fl"
397 if test 1 = $hf; then
398 ac_testn can_$vn '' "$ft"
400 ac_testn can_$vn '' "$ft" <<-'EOF'
401 /* evil apo'stroph in comment test */
403 int main(void) { return (isatty(0)); }
406 eval fv=\$HAVE_CAN_`upper $vn`
407 if test -n "$fl"; then
408 test 11 = $fa$fv || LDFLAGS=$save_LDFLAGS
410 test 11 = $fa$fv || CFLAGS=$save_CFLAGS
413 # ac_header [!] header [prereq ...]
415 if test x"$1" = x"!"; then
422 hv=`echo "$hf" | tr -d '\012\015' | tr -c $alll$allu$alln $alls`
423 echo "/* NeXTstep bug workaround */" >x
428 echo '#if HAVE_BOTH_TIME_H' >>x
429 echo '#include <sys/time.h>' >>x
430 echo '#include <time.h>' >>x
431 echo '#elif HAVE_SYS_TIME_H' >>x
432 echo '#include <sys/time.h>' >>x
433 echo '#elif HAVE_TIME_H' >>x
434 echo '#include <time.h>' >>x
438 echo "#include <$i>" >>x
442 echo "#include <$hf>" >>x
443 echo '#include <unistd.h>' >>x
444 echo 'int main(void) { return (isatty(0)); }' >>x
445 ac_testn "$hv" "" "<$hf>" <x
447 test 1 = $na || ac_cppflags
451 if test x"$1" = x"!"; then
458 test $fr = "$i" && case " $SRCS " in
460 *) SRCS="$SRCS $2" ;;
465 curdir=`pwd` srcdir=`dirname "$0" 2>/dev/null`
471 echo >&2 Source directory should not contain space or tab or newline.
472 echo >&2 Errors may occur.
475 echo Source directory must not contain single quotes.
479 dstversion=`sed -n '/define MKSH_VERSION/s/^.*"\([^"]*\)".*$/\1/p' "$srcdir/sh.h"`
480 add_cppflags -DMKSH_BUILDSH
487 optflags=-std-compile-opts
496 c:combine|c:dragonegg|c:llvm|c:lto)
501 echo "$me: Unknown option -c '$i'!" >&2
516 echo "$me: Do not call me with '-G'!" >&2
520 # checker, debug, valgrind build
522 CFLAGS="$CFLAGS -g3 -fno-builtin"
537 optflags=-std-compile-opts
552 echo "Build.sh $srcversion"
553 echo "for mksh $dstversion"
557 echo "$me: Unknown option '$i'!" >&2
561 echo "$me: Unknown option -'$last' '$i'!" >&2
566 if test -n "$last"; then
567 echo "$me: Option -'$last' not followed by argument!" >&2
571 test -z "$tfn" && if test $legacy = 0; then
576 if test -d $tfn || test -d $tfn.exe; then
577 echo "$me: Error: ./$tfn is a directory!" >&2
580 rmf a.exe* a.out* conftest.c *core core.* lft ${tfn}* no *.bc *.ll *.o *.gen \
581 Rebuild.sh signames.inc test.sh x vv.out
583 SRCS="lalloc.c eval.c exec.c expr.c funcs.c histrap.c jobs.c"
584 SRCS="$SRCS lex.c main.c misc.c shf.c syn.c tree.c var.c"
586 if test $legacy = 0; then
588 check_categories="$check_categories shell:legacy-no int:32"
590 check_categories="$check_categories shell:legacy-yes"
591 add_cppflags -DMKSH_LEGACY_MODE
592 HAVE_PERSISTENT_HISTORY=0
593 HAVE_ISSET_MKSH_CONSERVATIVE_FDS=1 # from sh.h
596 if test x"$srcdir" = x"."; then
597 CPPFLAGS="-I. $CPPFLAGS"
599 CPPFLAGS="-I. -I'$srcdir' $CPPFLAGS"
601 test -n "$LDSTATIC" && if test -n "$LDFLAGS"; then
602 LDFLAGS="$LDFLAGS $LDSTATIC"
607 if test -z "$TARGET_OS"; then
608 x=`uname -s 2>/dev/null || uname`
609 test x"$x" = x"`uname -n 2>/dev/null`" || TARGET_OS=$x
611 if test -z "$TARGET_OS"; then
612 echo "$me: Set TARGET_OS, your uname is broken!" >&2
619 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'
622 if test x"$TARGET_OS" = x"Android"; then
623 check_categories="$check_categories android"
628 if test x"$TARGET_OS" = x"Minix"; then
630 WARNING: additional checks before running Build.sh required!
631 You can avoid these by calling Build.sh correctly, see below.
633 cat >conftest.c <<'EOF'
634 #include <sys/types.h>
636 #ifdef _NETBSD_SOURCE
644 vv ']' "${CC-cc} -E $CFLAGS $CPPFLAGS $NOWARN conftest.c | grep ct= | tr -d \\\\015 >x"
651 Warning: you set TARGET_OS to $TARGET_OS but that is ambiguous.
652 Please set it to either Minix3 or Ninix3, whereas the latter is
653 all versions of Minix with even partial NetBSD(R) userland. The
654 value determined from your compiler for the current compilation
655 (which may be wrong) is: $ct
661 Warning: you set TARGET_OS to $TARGET_OS but that is ambiguous.
662 Please set it to either Minix3 or Ninix3, whereas the latter is
663 all versions of Minix with even partial NetBSD(R) userland. The
664 proper value couldn't be determined, continue at your own risk.
670 # Configuration depending on OS revision, on OSes that need them
673 test x"$TARGET_OSREV" = x"" && TARGET_OSREV=`hostinfo 2>&1 | \
674 grep 'NeXT Mach [0-9][0-9.]*:' | \
675 sed 's/^.*NeXT Mach \([0-9][0-9.]*\):.*$/\1/'`
678 test x"$TARGET_OSREV" = x"" && TARGET_OSREV=`uname -r`
682 # Configuration depending on OS name
686 add_cppflags -DMKSH_NO_SIGSETJMP
687 add_cppflags -DMKSH_TYPEDEF_SIG_ATOMIC_T=int
688 add_cppflags -DMKSH_CONSERVATIVE_FDS
691 add_cppflags -D_ALL_SOURCE
692 : ${HAVE_SETLOCALE_CTYPE=0}
697 oswarn="; it has minor issues"
700 oswarn="; you must recompile mksh with"
701 oswarn="$oswarn${nl}itself in a second stage"
704 # BeOS has no real tty either
705 add_cppflags -DMKSH_UNEMPLOYED
706 add_cppflags -DMKSH_DISABLE_TTY_WARNING
707 # BeOS doesn't have different UIDs and GIDs
708 add_cppflags -DMKSH__NO_SETEUGID
711 : ${HAVE_SETLOCALE_CTYPE=0}
714 oswarn="; it has major issues"
715 add_cppflags -DMKSH__NO_SYMLINK
716 check_categories="$check_categories nosymlink"
717 add_cppflags -DMKSH__NO_SETEUGID
718 add_cppflags -DMKSH_CONSERVATIVE_FDS
719 add_cppflags -DMKSH_DISABLE_TTY_WARNING
722 : ${HAVE_SETLOCALE_CTYPE=0}
725 add_cppflags -D_DARWIN_C_SOURCE
732 oswarn="; it has minor issues"
733 add_cppflags -D_GNU_SOURCE
734 add_cppflags -DMKSH_CONSERVATIVE_FDS
735 : ${HAVE_SETLOCALE_CTYPE=0}
740 *) add_cppflags -D_GNU_SOURCE ;;
742 # define MKSH__NO_PATH_MAX to use Hurd-only functions
743 add_cppflags -DMKSH__NO_PATH_MAX
748 *) add_cppflags -D_GNU_SOURCE ;;
752 add_cppflags -DMKSH_ASSUME_UTF8; HAVE_ISSET_MKSH_ASSUME_UTF8=1
759 add_cppflags -D_ALL_SOURCE
761 : ${HAVE_SETLOCALE_CTYPE=0}
764 : ${HAVE_SETLOCALE_CTYPE=0}
769 *) add_cppflags -D_GNU_SOURCE ;;
771 add_cppflags -DSETUID_CAN_FAIL_WITH_EAGAIN
775 oswarn="; it has minor issues"
780 add_cppflags -DMKSH__NO_SETEUGID
781 add_cppflags -DMKSH_UNEMPLOYED
782 add_cppflags -DMKSH_CONSERVATIVE_FDS
783 add_cppflags -D_MINIX_SOURCE
784 oldish_ed=no-stderr-ed # no /bin/ed, maybe see below
785 : ${HAVE_SETLOCALE_CTYPE=0}
788 add_cppflags -DMKSH_UNEMPLOYED
789 add_cppflags -DMKSH_CONSERVATIVE_FDS
790 add_cppflags -DMKSH_NO_LIMITS
791 add_cppflags -D_POSIX_SOURCE -D_POSIX_1_SOURCE=2 -D_MINIX
792 oldish_ed=no-stderr-ed # /usr/bin/ed(!) is broken
793 : ${HAVE_SETLOCALE_CTYPE=0}
798 add_cppflags -DMKSH_ASSUME_UTF8=0; HAVE_ISSET_MKSH_ASSUME_UTF8=1
799 # almost same as CYGWIN* (from RT|Chatzilla)
800 : ${HAVE_SETLOCALE_CTYPE=0}
801 # broken on this OE (from ir0nh34d)
807 add_cppflags -D_NEXT_SOURCE
808 add_cppflags -D_POSIX_SOURCE
809 : ${AWK=gawk} ${CC=cc -posix}
810 add_cppflags -DMKSH_NO_SIGSETJMP
811 # NeXTstep cannot get a controlling tty
812 add_cppflags -DMKSH_UNEMPLOYED
813 case $TARGET_OSREV in
815 # OpenStep 4.2 is broken by default
816 oswarn="; it needs libposix.a"
819 add_cppflags -DMKSH_CONSERVATIVE_FDS
823 add_cppflags -DMKSH_UNEMPLOYED
824 add_cppflags -DMKSH_CONSERVATIVE_FDS
825 add_cppflags -DMKSH_NO_LIMITS
826 # but no idea what else could be needed
827 oswarn="; it has unknown issues"
830 : ${HAVE_SETLOCALE_CTYPE=0}
833 HAVE_SIG_T=0 # incompatible
834 add_cppflags -D_OSF_SOURCE
835 add_cppflags -D_POSIX_C_SOURCE=200112L
836 add_cppflags -D_XOPEN_SOURCE=600
837 add_cppflags -D_XOPEN_SOURCE_EXTENDED
838 : ${HAVE_SETLOCALE_CTYPE=0}
841 add_cppflags -D_POSIX_SOURCE
842 add_cppflags -D_LIMITS_EXTENSION
843 add_cppflags -D_BSD_EXTENSION
844 add_cppflags -D_SUSV2_SOURCE
845 add_cppflags -DMKSH_ASSUME_UTF8; HAVE_ISSET_MKSH_ASSUME_UTF8=1
846 add_cppflags -DMKSH_NO_CMDLINE_EDITING
847 add_cppflags -DMKSH__NO_SETEUGID
848 oswarn=' and will currently not work'
849 add_cppflags -DMKSH_UNEMPLOYED
850 # this is for detecting kencc
851 add_cppflags -DMKSH_MAYBE_KENCC
854 HAVE_SIG_T=0 # incompatible
855 oswarn=' and will currently not work'
856 : ${HAVE_SETLOCALE_CTYPE=0}
859 add_cppflags -D__NO_EXT_QNX
860 add_cppflags -D__EXT_UNIX_MISC
861 case $TARGET_OSREV in
862 [012345].*|6.[0123].*|6.4.[01])
863 oldish_ed=no-stderr-ed # oldish /bin/ed is broken
866 : ${HAVE_SETLOCALE_CTYPE=0}
869 case $TARGET_OSREV in
872 add_cppflags -DMKSH_UNEMPLOYED
878 oswarn='; this is an unknown version of'
879 oswarn="$oswarn$nl$TARGET_OS ${TARGET_OSREV}, please tell me what to do"
882 add_cppflags -DMKSH_CONSERVATIVE_FDS
883 : ${HAVE_SYS_SIGLIST=0} ${HAVE__SYS_SIGLIST=0}
886 oswarn="; it has minor issues"
889 add_cppflags -D_BSD_SOURCE
890 add_cppflags -D__EXTENSIONS__
893 add_cppflags -D_GNU_SOURCE
894 add_cppflags -DMKSH_NO_SIGSUSPEND
895 oswarn=' and will currently not work'
899 add_cppflags -DMKSH_TYPEDEF_SSIZE_T=int
900 add_cppflags -DMKSH_CONSERVATIVE_FDS
901 : ${HAVE_SETLOCALE_CTYPE=0}
905 add_cppflags -DMKSH_CONSERVATIVE_FDS
906 : ${HAVE_SYS_SIGLIST=0} ${HAVE__SYS_SIGLIST=0}
912 oswarn="; it will compile, but the target"
913 oswarn="$oswarn${nl}platform itself is very flakey/unreliable"
914 : ${HAVE_SETLOCALE_CTYPE=0}
917 # generic target for SVR4 Unix with uname -s = uname -n
918 # this duplicates the * target below
919 oswarn='; it may or may not work'
920 test x"$TARGET_OSREV" = x"" && TARGET_OSREV=`uname -r`
923 oswarn='; it may or may not work'
924 test x"$TARGET_OSREV" = x"" && TARGET_OSREV=`uname -r`
930 : ${AWK=awk} ${CC=cc} ${NROFF=nroff} ${SIZE=size}
931 test 0 = $r && echo | $NROFF -v 2>&1 | grep GNU >/dev/null 2>&1 && \
934 # this aids me in tracing FTBFSen without access to the buildd
935 $e "Hi from$ao $bi$srcversion$ao on:"
939 vv '|' "uname -a >&2"
942 vv '|' "hwprefs machine_type os_type os_class >&2"
944 vv '|' "system_profiler SPSoftwareDataType SPHardwareDataType >&2"
945 vv '|' "/bin/sh --version >&2"
946 vv '|' "xcodebuild -version >&2"
947 vv '|' "uname -a >&2"
948 vv '|' "sysctl kern.version hw.machine hw.model hw.memsize hw.availcpu hw.cpufrequency hw.byteorder hw.cpu64bit_capable >&2"
951 vv '|' "uname -a >&2"
955 vv '|' "uname -a >&2"
956 vv '|' "/usr/sbin/sizer -v >&2"
958 SCO_SV|UnixWare|UNIX_SV)
959 vv '|' "uname -a >&2"
960 vv '|' "uname -X >&2"
963 vv '|' "uname -a >&2"
966 test -z "$oswarn" || echo >&2 "
967 Warning: mksh has not yet been ported to or tested on your
968 operating system '$TARGET_OS'$oswarn. If you can provide
969 a shell account to the developer, this may improve; please
970 drop us a success or failure notice or even send in diffs.
972 $e "$bi$me: Building the MirBSD Korn Shell$ao $ui$dstversion$ao on $TARGET_OS ${TARGET_OSREV}..."
975 # Begin of mirtoconf checks
977 $e $bi$me: Scanning for functions... please ignore any errors.$ao
980 # Compiler: which one?
983 # - ICC defines __GNUC__ too
984 # - GCC defines __hpux too
985 # - LLVM+clang defines __GNUC__ too
986 # - nwcc defines __GNUC__ too
988 $e ... which compiler seems to be used
989 cat >conftest.c <<'EOF'
991 #if defined(__ICC) || defined(__INTEL_COMPILER)
993 #elif defined(__xlC__) || defined(__IBMC__)
995 #elif defined(__SUNPRO_C)
997 #elif defined(__ACK__)
999 #elif defined(__BORLANDC__)
1001 #elif defined(__WATCOMC__)
1003 #elif defined(__MWERKS__)
1005 #elif defined(__HP_cc)
1007 #elif defined(__DECC) || (defined(__osf__) && !defined(__GNUC__))
1009 #elif defined(__PGI)
1011 #elif defined(__DMC__)
1013 #elif defined(_MSC_VER)
1015 #elif defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__)
1017 #elif defined(__IAR_SYSTEMS_ICC__)
1021 #elif defined(__PCC__)
1023 #elif defined(__TenDRA__)
1025 #elif defined(__TINYC__)
1027 #elif defined(__llvm__) && defined(__clang__)
1029 #elif defined(__NWCC__)
1031 #elif defined(__GNUC__)
1033 #elif defined(_COMPILER_VERSION)
1035 #elif defined(__sgi)
1037 #elif defined(__hpux) || defined(__hpua)
1039 #elif defined(__ultrix)
1041 #elif defined(__USLC__)
1043 #elif defined(__LCC__)
1045 #elif defined(MKSH_MAYBE_KENCC)
1046 /* and none of the above matches */
1053 #if defined(__KLIBC__)
1062 vv ']' "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c | \
1063 sed -n '/^ *[ce]t *= */s/^ *\([ce]t\) *= */\1=/p' | tr -d \\\\015 >x"
1067 cat >conftest.c <<'EOF'
1069 int main(void) { return (isatty(0)); }
1073 # work around "the famous ACK const bug"
1074 CPPFLAGS="-Dconst= $CPPFLAGS"
1077 echo >&2 'Warning: Analog Devices C++ compiler for Blackfin, TigerSHARC
1078 and SHARC (21000) DSPs detected. This compiler has not yet
1079 been tested for compatibility with mksh. Continue at your
1080 own risk, please report success/failure to the developers.'
1083 echo >&2 "Warning: Borland C++ Builder detected. This compiler might
1084 produce broken executables. Continue at your own risk,
1085 please report success/failure to the developers."
1088 # does not work with current "ccc" compiler driver
1089 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -version"
1090 # one of these two works, for now
1091 vv '|' "${CLANG-clang} -version"
1092 vv '|' "${CLANG-clang} --version"
1093 # ensure compiler and linker are in sync unless overridden
1094 case $CCC_CC:$CCC_LD in
1096 *:) CCC_LD=$CCC_CC; export CCC_LD ;;
1100 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V"
1101 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -Wl,-V conftest.c $LIBS"
1104 echo >&2 "Warning: Digital Mars Compiler detected. When running under"
1105 echo >&2 " UWIN, mksh tends to be unstable due to the limitations"
1106 echo >&2 " of this platform. Continue at your own risk,"
1107 echo >&2 " please report success/failure to the developers."
1110 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS"
1111 vv '|' 'echo `$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS \
1112 -dumpmachine` gcc`$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN \
1113 $LIBS -dumpversion`'
1116 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
1119 echo >&2 'Warning: IAR Systems (http://www.iar.com) compiler for embedded
1120 systems detected. This unsupported compiler has not yet
1121 been tested for compatibility with mksh. Continue at your
1122 own risk, please report success/failure to the developers.'
1125 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V"
1128 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS"
1131 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS"
1132 add_cppflags -D__inline__=__inline
1135 echo >&2 'Warning: Metrowerks C compiler detected. This has not yet
1136 been tested for compatibility with mksh. Continue at your
1137 own risk, please report success/failure to the developers.'
1140 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -version"
1143 ccpr= # errorlevels are not reliable
1146 if [[ -n $C89_COMPILER ]]; then
1147 C89_COMPILER=`ntpath2posix -c "$C89_COMPILER"`
1151 if [[ -n $C89_LINKER ]]; then
1152 C89_LINKER=`ntpath2posix -c "$C89_LINKER"`
1156 vv '|' "$C89_COMPILER /HELP >&2"
1157 vv '|' "$C89_LINKER /LINK >&2"
1162 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -version"
1165 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -v"
1168 echo >&2 'Warning: PGI detected. This unknown compiler has not yet
1169 been tested for compatibility with mksh. Continue at your
1170 own risk, please report success/failure to the developers.'
1173 echo >&2 'Warning: sdcc (http://sdcc.sourceforge.net), the small devices
1174 C compiler for embedded systems detected. This has not yet
1175 been tested for compatibility with mksh. Continue at your
1176 own risk, please report success/failure to the developers.'
1179 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
1182 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -v"
1185 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V 2>&1 | \
1186 fgrep -i -e version -e release"
1189 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V"
1190 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -Wl,-V conftest.c $LIBS"
1193 case $TARGET_OS:$TARGET_OSREV in
1197 : ${HAVE_CAN_OTWO=0} ${HAVE_CAN_OPTIMISE=0}
1200 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
1203 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS"
1206 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -qversion"
1207 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -qversion=verbose"
1211 test x"$ct" = x"untested" && $e "!!! detecting preprocessor failed"
1214 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS"
1215 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
1220 vv '|' "llc -version"
1225 add_cppflags -DMKSH_NO_LIMITS
1228 # nothing special detected, don’t worry
1235 $e "$bi==> which compiler seems to be used...$ao $ui$ct${et+ on $et}$ao"
1236 rmf conftest.c conftest.o conftest a.out* a.exe* vv.out
1239 # Compiler: works as-is, with -Wno-error and -Werror
1244 ac_flags 0 compiler_works '' 'if the compiler works'
1245 test 1 = $HAVE_CAN_COMPILER_WORKS || exit 1
1246 HAVE_COMPILER_KNOWN=0
1247 test $ct = unknown || HAVE_COMPILER_KNOWN=1
1248 if ac_ifcpp 'if 0' compiler_fails '' \
1249 'if the compiler does not fail correctly'; then
1251 : ${HAVE_CAN_DELEXE=x}
1254 CFLAGS="$CFLAGS ${ccpl}-non_shared"
1255 ac_testn can_delexe compiler_fails 0 'for the -non_shared linker option' <<-EOF
1257 int main(void) { return (isatty(0)); }
1261 CFLAGS="$CFLAGS ${ccpl}/DELEXECUTABLE"
1262 ac_testn can_delexe compiler_fails 0 'for the /DELEXECUTABLE linker option' <<-EOF
1264 int main(void) { return (isatty(0)); }
1271 test 1 = $HAVE_CAN_DELEXE || CFLAGS=$save_CFLAGS
1272 ac_testn compiler_still_fails '' 'if the compiler still does not fail correctly' <<-EOF
1274 test 1 = $HAVE_COMPILER_STILL_FAILS && exit 1
1276 if ac_ifcpp 'ifdef __TINYC__' couldbe_tcc '!' compiler_known 0 \
1277 'if this could be tcc'; then
1279 CPP='cpp -D__TINYC__'
1280 HAVE_COMPILER_KNOWN=1
1285 save_NOWARN="${ccpc}-w"
1289 # -msg_* flags not used yet, or is -w2 correct?
1292 save_NOWARN="${ccpc}-w"
1305 DOWARN="-diag_error 1-10000"
1308 save_NOWARN="${ccpc}/w"
1312 test x"$save_NOWARN" = x"" && save_NOWARN='-errwarn=%none'
1313 ac_flags 0 errwarnnone "$save_NOWARN"
1314 test 1 = $HAVE_CAN_ERRWARNNONE || save_NOWARN=
1315 ac_flags 0 errwarnall "-errwarn=%all"
1316 test 1 = $HAVE_CAN_ERRWARNALL && DOWARN="-errwarn=%all"
1330 save_NOWARN=-qflag=i:e
1334 test x"$save_NOWARN" = x"" && save_NOWARN=-Wno-error
1335 ac_flags 0 wnoerror "$save_NOWARN"
1336 test 1 = $HAVE_CAN_WNOERROR || save_NOWARN=
1337 ac_flags 0 werror -Werror
1338 test 1 = $HAVE_CAN_WERROR && DOWARN=-Werror
1339 test $ct = icc && DOWARN="$DOWARN -wd1419"
1345 # Compiler: extra flags (-O2 -f* -W* etc.)
1347 i=`echo :"$orig_CFLAGS" | sed 's/^://' | tr -c -d $alll$allu$alln`
1348 # optimisation: only if orig_CFLAGS is empty
1349 test x"$i" = x"" && case $ct in
1356 # no special optimisation
1361 int main(void) { return (isatty(0)); }
1362 #define __IDSTRING_CONCAT(l,p) __LINTED__ ## l ## _ ## p
1363 #define __IDSTRING_EXPAND(l,p) __IDSTRING_CONCAT(l,p)
1364 #define pad void __IDSTRING_EXPAND(__LINE__,x)(void) { }
1366 yes pad | head -n 256 >>x
1367 ac_flags - 1 otwo -xO2 <x
1371 ac_flags 1 othree "-O3 -qstrict"
1372 test 1 = $HAVE_CAN_OTHREE || ac_flags 1 otwo -O2
1376 test 1 = $HAVE_CAN_OTWO || ac_flags 1 optimise -O
1379 # other flags: just add them if they are supported
1383 ac_flags 1 strpool "${ccpc}-d" 'if string pooling can be enabled'
1389 ac_flags 0 verb -verbose
1390 ac_flags 1 rodata -readonly_strings
1393 ac_flags 1 decl "${ccpc}-r" 'for strict prototype checks'
1394 ac_flags 1 schk "${ccpc}-s" 'for stack overflow checking'
1397 # The following tests run with -Werror (gcc only) if possible
1398 NOWARN=$DOWARN; phase=u
1399 ac_flags 1 wnodeprecateddecls -Wno-deprecated-declarations
1400 # mksh is not written in CFrustFrust!
1401 ac_flags 1 no_eh_frame -fno-asynchronous-unwind-tables
1402 ac_flags 1 fnostrictaliasing -fno-strict-aliasing
1403 ac_flags 1 fstackprotectorstrong -fstack-protector-strong
1404 test 1 = $HAVE_CAN_FSTACKPROTECTORSTRONG || \
1405 ac_flags 1 fstackprotectorall -fstack-protector-all
1406 test $cm = dragonegg && case " $CC $CFLAGS $LDFLAGS " in
1407 *\ -fplugin=*dragonegg*) ;;
1408 *) ac_flags 1 fplugin_dragonegg -fplugin=dragonegg ;;
1417 checks='1 2 3 4 5 6 7 8'
1423 test $fv = 1 || for what in $checks; do
1424 test $fv = 1 && break
1426 1) t_cflags='-flto=jobserver'
1427 t_ldflags='-fuse-linker-plugin'
1428 t_use=1 t_name=fltojs_lp ;;
1429 2) t_cflags='-flto=jobserver' t_ldflags=''
1430 t_use=1 t_name=fltojs_nn ;;
1431 3) t_cflags='-flto=jobserver'
1432 t_ldflags='-fno-use-linker-plugin -fwhole-program'
1433 t_use=1 t_name=fltojs_np ;;
1435 t_ldflags='-fuse-linker-plugin'
1436 t_use=1 t_name=fltons_lp ;;
1437 5) t_cflags='-flto' t_ldflags=''
1438 t_use=1 t_name=fltons_nn ;;
1440 t_ldflags='-fno-use-linker-plugin -fwhole-program'
1441 t_use=1 t_name=fltons_np ;;
1442 7) t_cflags='-fwhole-program --combine' t_ldflags=''
1443 t_use=0 t_name=combine cm=combine ;;
1444 8) fv=1 cm=normal ;;
1446 test $fv = 1 && break
1447 ac_flags $t_use $t_name "$t_cflags" \
1448 "if gcc supports $t_cflags $t_ldflags" "$t_ldflags"
1454 # probably not needed
1455 #ac_flags 1 agcc -Agcc 'for support of GCC extensions'
1459 ac_flags 1 fnobuiltinsetmode -fno-builtin-setmode
1460 ac_flags 1 fnostrictaliasing -fno-strict-aliasing
1461 ac_flags 1 fstacksecuritycheck -fstack-security-check
1465 ac_flags 1 fullwarn -fullwarn 'for remark output support'
1468 ac_flags 1 strpool "${ccpc}/GF" 'if string pooling can be enabled'
1469 echo 'int main(void) { char test[64] = ""; return (*test); }' >x
1470 ac_flags - 1 stackon "${ccpc}/GZ" 'if stack checks can be enabled' <x
1471 ac_flags - 1 stckall "${ccpc}/Ge" 'stack checks for all functions' <x
1472 ac_flags - 1 secuchk "${ccpc}/GS" 'for compiler security checks' <x
1474 ac_flags 1 wall "${ccpc}/Wall" 'to enable all warnings'
1475 ac_flags 1 wp64 "${ccpc}/Wp64" 'to enable 64-bit warnings'
1479 #broken# ac_flags 1 ssp -stackprotect
1484 ac_flags 1 ipo -xipo 'for cross-module optimisation'
1488 : #broken# ac_flags 1 boundschk -b
1491 ac_flags 0 ysystem -Ysystem
1492 test 1 = $HAVE_CAN_YSYSTEM && CPPFLAGS="-Ysystem $CPPFLAGS"
1493 ac_flags 1 extansi -Xa
1496 ac_flags 1 rodata "-qro -qroconst -qroptr"
1497 ac_flags 1 rtcheck -qcheck=all
1498 #ac_flags 1 rtchkc -qextchk # reported broken
1499 ac_flags 1 wformat "-qformat=all -qformat=nozln"
1500 #ac_flags 1 wp64 -qwarn64 # too verbose for now
1503 # flags common to a subset of compilers (run with -Werror on gcc)
1504 if test 1 = $i; then
1505 ac_flags 1 wall -Wall
1506 ac_flags 1 fwrapv -fwrapv
1510 # The following tests run with -Werror or similar (all compilers) if possible
1512 test $ct = pcc && phase=u
1515 # Compiler: check for stuff that only generates warnings
1517 ac_test attribute_bounded '' 'for __attribute__((__bounded__))' <<-'EOF'
1518 #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
1519 extern int thiswillneverbedefinedIhope(void);
1520 /* force a failure: TenDRA and gcc 1.42 have false positive here */
1521 int main(void) { return (thiswillneverbedefinedIhope()); }
1524 #undef __attribute__
1525 int xcopy(const void *, void *, size_t)
1526 __attribute__((__bounded__(__buffer__, 1, 3)))
1527 __attribute__((__bounded__(__buffer__, 2, 3)));
1528 int main(int ac, char *av[]) { return (xcopy(av[0], av[--ac], 1)); }
1529 int xcopy(const void *s, void *d, size_t n) {
1531 * if memmove does not exist, we are not on a system
1532 * with GCC with __bounded__ attribute either so poo
1534 memmove(d, s, n); return ((int)n);
1538 ac_test attribute_format '' 'for __attribute__((__format__))' <<-'EOF'
1539 #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
1540 extern int thiswillneverbedefinedIhope(void);
1541 /* force a failure: TenDRA and gcc 1.42 have false positive here */
1542 int main(void) { return (thiswillneverbedefinedIhope()); }
1544 #define fprintf printfoo
1546 #undef __attribute__
1548 extern int fprintf(FILE *, const char *format, ...)
1549 __attribute__((__format__(__printf__, 2, 3)));
1550 int main(int ac, char **av) { return (fprintf(stderr, "%s%d", *av, ac)); }
1553 ac_test attribute_noreturn '' 'for __attribute__((__noreturn__))' <<-'EOF'
1554 #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
1555 extern int thiswillneverbedefinedIhope(void);
1556 /* force a failure: TenDRA and gcc 1.42 have false positive here */
1557 int main(void) { return (thiswillneverbedefinedIhope()); }
1560 #undef __attribute__
1561 void fnord(void) __attribute__((__noreturn__));
1562 int main(void) { fnord(); }
1563 void fnord(void) { exit(0); }
1566 ac_test attribute_pure '' 'for __attribute__((__pure__))' <<-'EOF'
1567 #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
1568 extern int thiswillneverbedefinedIhope(void);
1569 /* force a failure: TenDRA and gcc 1.42 have false positive here */
1570 int main(void) { return (thiswillneverbedefinedIhope()); }
1573 #undef __attribute__
1574 int foo(const char *) __attribute__((__pure__));
1575 int main(int ac, char **av) { return (foo(av[ac - 1]) + isatty(0)); }
1576 int foo(const char *s) { return ((int)s[0]); }
1579 ac_test attribute_unused '' 'for __attribute__((__unused__))' <<-'EOF'
1580 #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
1581 extern int thiswillneverbedefinedIhope(void);
1582 /* force a failure: TenDRA and gcc 1.42 have false positive here */
1583 int main(void) { return (thiswillneverbedefinedIhope()); }
1586 #undef __attribute__
1587 int main(int ac __attribute__((__unused__)), char **av
1588 __attribute__((__unused__))) { return (isatty(0)); }
1591 ac_test attribute_used '' 'for __attribute__((__used__))' <<-'EOF'
1592 #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
1593 extern int thiswillneverbedefinedIhope(void);
1594 /* force a failure: TenDRA and gcc 1.42 have false positive here */
1595 int main(void) { return (thiswillneverbedefinedIhope()); }
1598 #undef __attribute__
1599 static const char fnord[] __attribute__((__used__)) = "42";
1600 int main(void) { return (isatty(0)); }
1604 # End of tests run with -Werror
1609 # mksh: flavours (full/small mksh, omit certain stuff)
1611 if ac_ifcpp 'ifdef MKSH_SMALL' isset_MKSH_SMALL '' \
1612 "if a reduced-feature mksh is requested"; then
1614 : ${HAVE_PERSISTENT_HISTORY=0}
1615 check_categories="$check_categories smksh"
1616 HAVE_ISSET_MKSH_CONSERVATIVE_FDS=1 # from sh.h
1618 ac_ifcpp 'if defined(MKSH_BINSHPOSIX) || defined(MKSH_BINSHREDUCED)' \
1619 isset_MKSH_BINSH '' 'if invoking as sh should be handled specially' && \
1620 check_categories="$check_categories binsh"
1621 ac_ifcpp 'ifdef MKSH_UNEMPLOYED' isset_MKSH_UNEMPLOYED '' \
1622 "if mksh will be built without job control" && \
1623 check_categories="$check_categories arge"
1624 ac_ifcpp 'ifdef MKSH_NOPROSPECTOFWORK' isset_MKSH_NOPROSPECTOFWORK '' \
1625 "if mksh will be built without job signals" && \
1626 check_categories="$check_categories arge nojsig"
1627 ac_ifcpp 'ifdef MKSH_ASSUME_UTF8' isset_MKSH_ASSUME_UTF8 '' \
1628 'if the default UTF-8 mode is specified' && : ${HAVE_SETLOCALE_CTYPE=0}
1629 ac_ifcpp 'ifdef MKSH_CONSERVATIVE_FDS' isset_MKSH_CONSERVATIVE_FDS '' \
1630 'if traditional/conservative fd use is requested' && \
1631 check_categories="$check_categories convfds"
1632 #ac_ifcpp 'ifdef MKSH_DISABLE_DEPRECATED' isset_MKSH_DISABLE_DEPRECATED '' \
1633 # "if deprecated features are to be omitted" && \
1634 # check_categories="$check_categories nodeprecated"
1635 #ac_ifcpp 'ifdef MKSH_DISABLE_EXPERIMENTAL' isset_MKSH_DISABLE_EXPERIMENTAL '' \
1636 # "if experimental features are to be omitted" && \
1637 # check_categories="$check_categories noexperimental"
1638 ac_ifcpp 'ifdef MKSH_MIDNIGHTBSD01ASH_COMPAT' isset_MKSH_MIDNIGHTBSD01ASH_COMPAT '' \
1639 'if the MidnightBSD 0.1 ash compatibility mode is requested' && \
1640 check_categories="$check_categories mnbsdash"
1643 # Environment: headers
1645 ac_header sys/time.h sys/types.h
1646 ac_header time.h sys/types.h
1647 test "11" = "$HAVE_SYS_TIME_H$HAVE_TIME_H" || HAVE_BOTH_TIME_H=0
1648 ac_test both_time_h '' 'whether <sys/time.h> and <time.h> can both be included' <<-'EOF'
1649 #include <sys/types.h>
1650 #include <sys/time.h>
1653 int main(void) { struct tm tm; return ((int)sizeof(tm) + isatty(0)); }
1655 ac_header sys/bsdtypes.h
1656 ac_header sys/file.h sys/types.h
1657 ac_header sys/mkdev.h sys/types.h
1658 ac_header sys/mman.h sys/types.h
1659 ac_header sys/param.h
1660 ac_header sys/resource.h sys/types.h _time
1661 ac_header sys/select.h sys/types.h
1662 ac_header sys/sysmacros.h
1664 ac_header grp.h sys/types.h
1666 ac_header libutil.h sys/types.h
1668 ac_header stdint.h stdarg.h
1669 # include strings.h only if compatible with string.h
1670 ac_header strings.h sys/types.h string.h
1672 ac_header ulimit.h sys/types.h
1676 # Environment: definitions
1678 echo '#include <sys/types.h>
1680 /* check that off_t can represent 2^63-1 correctly, thx FSF */
1681 #define LARGE_OFF_T ((((off_t)1 << 31) << 31) - 1 + (((off_t)1 << 31) << 31))
1682 int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 &&
1683 LARGE_OFF_T % 2147483647 == 1) ? 1 : -1];
1684 int main(void) { return (isatty(0)); }' >lft.c
1685 ac_testn can_lfs '' "for large file support" <lft.c
1686 save_CPPFLAGS=$CPPFLAGS
1687 add_cppflags -D_FILE_OFFSET_BITS=64
1688 ac_testn can_lfs_sus '!' can_lfs 0 "... with -D_FILE_OFFSET_BITS=64" <lft.c
1689 if test 0 = $HAVE_CAN_LFS_SUS; then
1690 CPPFLAGS=$save_CPPFLAGS
1691 add_cppflags -D_LARGE_FILES=1
1692 ac_testn can_lfs_aix '!' can_lfs 0 "... with -D_LARGE_FILES=1" <lft.c
1693 test 1 = $HAVE_CAN_LFS_AIX || CPPFLAGS=$save_CPPFLAGS
1695 rmf lft* # end of large file support test
1698 # Environment: types
1700 ac_test can_inttypes '!' stdint_h 1 "for standard 32-bit integer types" <<-'EOF'
1701 #include <sys/types.h>
1703 int main(int ac, char **av) { return ((uint32_t)(ptrdiff_t)*av + (int32_t)ac); }
1705 ac_test can_ucbints '!' can_inttypes 1 "for UCB 32-bit integer types" <<-'EOF'
1706 #include <sys/types.h>
1708 int main(int ac, char **av) { return ((u_int32_t)(ptrdiff_t)*av + (int32_t)ac); }
1710 ac_test can_int8type '!' stdint_h 1 "for standard 8-bit integer type" <<-'EOF'
1711 #include <sys/types.h>
1713 int main(int ac, char **av) { return ((uint8_t)(ptrdiff_t)av[ac]); }
1715 ac_test can_ucbint8 '!' can_int8type 1 "for UCB 8-bit integer type" <<-'EOF'
1716 #include <sys/types.h>
1718 int main(int ac, char **av) { return ((u_int8_t)(ptrdiff_t)av[ac]); }
1721 ac_test rlim_t <<-'EOF'
1722 #include <sys/types.h>
1723 #if HAVE_BOTH_TIME_H
1724 #include <sys/time.h>
1726 #elif HAVE_SYS_TIME_H
1727 #include <sys/time.h>
1731 #if HAVE_SYS_RESOURCE_H
1732 #include <sys/resource.h>
1735 int main(void) { return (((int)(rlim_t)0) + isatty(0)); }
1738 # only testn: added later below
1739 ac_testn sig_t <<-'EOF'
1740 #include <sys/types.h>
1743 volatile sig_t foo = (sig_t)0;
1744 int main(void) { return (foo == (sig_t)0); }
1747 ac_testn sighandler_t '!' sig_t 0 <<-'EOF'
1748 #include <sys/types.h>
1751 volatile sighandler_t foo = (sighandler_t)0;
1752 int main(void) { return (foo == (sighandler_t)0); }
1754 if test 1 = $HAVE_SIGHANDLER_T; then
1755 add_cppflags -Dsig_t=sighandler_t
1759 ac_testn __sighandler_t '!' sig_t 0 <<-'EOF'
1760 #include <sys/types.h>
1763 volatile __sighandler_t foo = (__sighandler_t)0;
1764 int main(void) { return (foo == (__sighandler_t)0); }
1766 if test 1 = $HAVE___SIGHANDLER_T; then
1767 add_cppflags -Dsig_t=__sighandler_t
1771 test 1 = $HAVE_SIG_T || add_cppflags -Dsig_t=nosig_t
1775 # check whether whatever we use for the final link will succeed
1777 if test $cm = makefile; then
1781 ac_testinit link_works '' 'checking if the final link command may succeed'
1783 cat >conftest.c <<-'EOF'
1785 #define MKSH_INCLUDES_ONLY
1787 __RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.668 2014/10/03 17:32:07 tg Exp $");
1788 int main(void) { printf("Hello, World!\n"); return (isatty(0)); }
1792 v "$CC $CFLAGS $CPPFLAGS $NOWARN -emit-llvm -c conftest.c" || fv=0
1794 test $fv = 0 || v "llvm-link -o - conftest.o | opt $optflags | llc -o $tfn.s" || fv=0
1795 test $fv = 0 || v "$CC $CFLAGS $LDFLAGS -o $tcfn $tfn.s $LIBS $ccpr"
1798 v "$CC $CFLAGS $CPPFLAGS $NOWARN -S -flto conftest.c" || fv=0
1799 test $fv = 0 || v "mv conftest.s conftest.ll"
1800 test $fv = 0 || v "llvm-as conftest.ll" || fv=0
1802 test $fv = 0 || v "llvm-link -o - conftest.bc | opt $optflags | llc -o $tfn.s" || fv=0
1803 test $fv = 0 || v "$CC $CFLAGS $LDFLAGS -o $tcfn $tfn.s $LIBS $ccpr"
1806 v "$CC $CFLAGS $CPPFLAGS $LDFLAGS -fwhole-program --combine $NOWARN -o $tcfn conftest.c $LIBS $ccpr"
1810 v "$CC $CFLAGS $CPPFLAGS $NOWARN -c conftest.c" || fv=0
1811 test $fv = 0 || v "$CC $CFLAGS $LDFLAGS -o $tcfn conftest.o $LIBS $ccpr"
1814 test -f $tcfn || fv=0
1816 test $fv = 1 || exit 1
1820 # Environment: errors and signals
1822 test x"NetBSD" = x"$TARGET_OS" && $e Ignore the compatibility warning.
1824 ac_testn sys_errlist '' "the sys_errlist[] array and sys_nerr" <<-'EOF'
1825 extern const int sys_nerr;
1826 extern const char * const sys_errlist[];
1827 extern int isatty(int);
1828 int main(void) { return (*sys_errlist[sys_nerr - 1] + isatty(0)); }
1830 ac_testn _sys_errlist '!' sys_errlist 0 "the _sys_errlist[] array and _sys_nerr" <<-'EOF'
1831 extern const int _sys_nerr;
1832 extern const char * const _sys_errlist[];
1833 extern int isatty(int);
1834 int main(void) { return (*_sys_errlist[_sys_nerr - 1] + isatty(0)); }
1836 if test 1 = "$HAVE__SYS_ERRLIST"; then
1837 add_cppflags -Dsys_nerr=_sys_nerr
1838 add_cppflags -Dsys_errlist=_sys_errlist
1841 ac_cppflags SYS_ERRLIST
1843 for what in name list; do
1845 ac_testn sys_sig$what '' "the sys_sig${what}[] array" <<-EOF
1846 extern const char * const sys_sig${what}[];
1847 extern int isatty(int);
1848 int main(void) { return (sys_sig${what}[0][0] + isatty(0)); }
1850 ac_testn _sys_sig$what '!' sys_sig$what 0 "the _sys_sig${what}[] array" <<-EOF
1851 extern const char * const _sys_sig${what}[];
1852 extern int isatty(int);
1853 int main(void) { return (_sys_sig${what}[0][0] + isatty(0)); }
1855 eval uwhat_v=\$HAVE__SYS_SIG$uwhat
1856 if test 1 = "$uwhat_v"; then
1857 add_cppflags -Dsys_sig$what=_sys_sig$what
1858 eval HAVE_SYS_SIG$uwhat=1
1860 ac_cppflags SYS_SIG$uwhat
1864 # Environment: library functions
1866 ac_test flock <<-'EOF'
1867 #include <sys/types.h>
1871 #include <sys/file.h>
1873 int main(void) { return (flock(0, LOCK_EX | LOCK_UN)); }
1876 ac_test lock_fcntl '!' flock 1 'whether we can lock files with fcntl' <<-'EOF'
1881 lks.l_type = F_WRLCK | F_UNLCK;
1882 return (fcntl(0, F_SETLKW, &lks));
1886 ac_test getrusage <<-'EOF'
1887 #define MKSH_INCLUDES_ONLY
1891 return (getrusage(RUSAGE_SELF, &ru) +
1892 getrusage(RUSAGE_CHILDREN, &ru));
1896 ac_test getsid <<-'EOF'
1898 int main(void) { return ((int)getsid(0)); }
1901 ac_test gettimeofday <<-'EOF'
1902 #define MKSH_INCLUDES_ONLY
1904 int main(void) { struct timeval tv; return (gettimeofday(&tv, NULL)); }
1907 ac_test issetugid <<-'EOF'
1909 int main(void) { return (issetugid()); }
1912 ac_test killpg <<-'EOF'
1914 int main(int ac, char *av[]) { return (av[0][killpg(123, ac)]); }
1917 ac_test memmove <<-'EOF'
1918 #include <sys/types.h>
1922 #include <strings.h>
1924 int main(int ac, char *av[]) {
1925 return (*(int *)(void *)memmove(av[0], av[1], (size_t)ac));
1929 ac_test mknod '' 'if to use mknod(), makedev() and friends' <<-'EOF'
1930 #define MKSH_INCLUDES_ONLY
1932 int main(int ac, char *av[]) {
1934 dv = makedev((unsigned int)ac, (unsigned int)av[0][0]);
1935 return (mknod(av[0], (mode_t)0, dv) ? (int)major(dv) :
1940 ac_test mmap lock_fcntl 0 'for mmap and munmap' <<-'EOF'
1941 #include <sys/types.h>
1943 #include <sys/file.h>
1946 #include <sys/mman.h>
1950 int main(void) { return ((void *)mmap(NULL, (size_t)0,
1951 PROT_READ, MAP_PRIVATE, 0, (off_t)0) == (void *)NULL ? 1 :
1955 ac_test nice <<-'EOF'
1957 int main(void) { return (nice(4)); }
1960 ac_test revoke <<-'EOF'
1961 #include <sys/types.h>
1963 #include <libutil.h>
1966 int main(int ac, char *av[]) { return (ac + revoke(av[0])); }
1969 ac_test setlocale_ctype '' 'setlocale(LC_CTYPE, "")' <<-'EOF'
1972 int main(void) { return ((int)(ptrdiff_t)(void *)setlocale(LC_CTYPE, "")); }
1975 ac_test langinfo_codeset setlocale_ctype 0 'nl_langinfo(CODESET)' <<-'EOF'
1976 #include <langinfo.h>
1978 int main(void) { return ((int)(ptrdiff_t)(void *)nl_langinfo(CODESET)); }
1981 ac_test select <<-'EOF'
1982 #include <sys/types.h>
1983 #if HAVE_BOTH_TIME_H
1984 #include <sys/time.h>
1986 #elif HAVE_SYS_TIME_H
1987 #include <sys/time.h>
1991 #if HAVE_SYS_BSDTYPES_H
1992 #include <sys/bsdtypes.h>
1994 #if HAVE_SYS_SELECT_H
1995 #include <sys/select.h>
1998 #include <bstring.h>
2004 #include <strings.h>
2008 struct timeval tv = { 1, 200000 };
2009 fd_set fds; FD_ZERO(&fds); FD_SET(0, &fds);
2010 return (select(FD_SETSIZE, &fds, NULL, NULL, &tv));
2014 ac_test setresugid <<-'EOF'
2015 #include <sys/types.h>
2017 int main(void) { return (setresuid(0,0,0) + setresgid(0,0,0)); }
2020 ac_test setgroups setresugid 0 <<-'EOF'
2021 #include <sys/types.h>
2026 int main(void) { gid_t gid = 0; return (setgroups(0, &gid)); }
2029 if test x"$et" = x"klibc"; then
2031 ac_testn __rt_sigsuspend '' 'whether klibc uses RT signals' <<-'EOF'
2032 #define MKSH_INCLUDES_ONLY
2034 extern int __rt_sigsuspend(const sigset_t *, size_t);
2035 int main(void) { return (__rt_sigsuspend(NULL, 0)); }
2038 # no? damn! legacy crap ahead!
2040 ac_testn __sigsuspend_s '!' __rt_sigsuspend 1 \
2041 'whether sigsuspend is usable (1/2)' <<-'EOF'
2042 #define MKSH_INCLUDES_ONLY
2044 extern int __sigsuspend_s(sigset_t);
2045 int main(void) { return (__sigsuspend_s(0)); }
2047 ac_testn __sigsuspend_xxs '!' __sigsuspend_s 1 \
2048 'whether sigsuspend is usable (2/2)' <<-'EOF'
2049 #define MKSH_INCLUDES_ONLY
2051 extern int __sigsuspend_xxs(int, int, sigset_t);
2052 int main(void) { return (__sigsuspend_xxs(0, 0, 0)); }
2055 if test "000" = "$HAVE___RT_SIGSUSPEND$HAVE___SIGSUSPEND_S$HAVE___SIGSUSPEND_XXS"; then
2056 # no usable sigsuspend(), use pause() *ugh*
2057 add_cppflags -DMKSH_NO_SIGSUSPEND
2061 ac_test strerror '!' sys_errlist 0 <<-'EOF'
2062 extern char *strerror(int);
2063 int main(int ac, char *av[]) { return (*strerror(*av[ac])); }
2066 ac_test strsignal '!' sys_siglist 0 <<-'EOF'
2069 int main(void) { return (strsignal(1)[0]); }
2072 ac_test strlcpy <<-'EOF'
2074 int main(int ac, char *av[]) { return (strlcpy(*av, av[1],
2079 # check headers for declarations
2081 ac_test flock_decl flock 1 'for declaration of flock()' <<-'EOF'
2082 #define MKSH_INCLUDES_ONLY
2085 #include <sys/file.h>
2087 int main(void) { return ((flock)(0, 0)); }
2089 ac_test revoke_decl revoke 1 'for declaration of revoke()' <<-'EOF'
2090 #define MKSH_INCLUDES_ONLY
2092 int main(void) { return ((revoke)("")); }
2094 ac_test sys_errlist_decl sys_errlist 0 "for declaration of sys_errlist[] and sys_nerr" <<-'EOF'
2095 #define MKSH_INCLUDES_ONLY
2097 int main(void) { return (*sys_errlist[sys_nerr - 1] + isatty(0)); }
2099 ac_test sys_siglist_decl sys_siglist 0 'for declaration of sys_siglist[]' <<-'EOF'
2100 #define MKSH_INCLUDES_ONLY
2102 int main(void) { return (sys_siglist[0][0] + isatty(0)); }
2108 fd='if to use persistent history'
2109 ac_cache PERSISTENT_HISTORY || case $HAVE_MMAP$HAVE_FLOCK$HAVE_LOCK_FCNTL in
2112 test 1 = $fv || check_categories="$check_categories no-histfile"
2117 ac_testn compile_time_asserts_$$ '' 'whether compile-time assertions pass' <<-'EOF'
2118 #define MKSH_INCLUDES_ONLY
2121 #define CHAR_BIT 8 /* defuse this test on really legacy systems */
2124 #define cta(name, assertion) char name[(assertion) ? 1 : -1]
2125 /* this one should be defined by the standard */
2126 cta(char_is_1_char, (sizeof(char) == 1) && (sizeof(signed char) == 1) &&
2127 (sizeof(unsigned char) == 1));
2128 cta(char_is_8_bits, ((CHAR_BIT) == 8) && ((int)(unsigned char)0xFF == 0xFF) &&
2129 ((int)(unsigned char)0x100 == 0) && ((int)(unsigned char)(int)-1 == 0xFF));
2130 /* the next assertion is probably not really needed */
2131 cta(short_is_2_char, sizeof(short) == 2);
2132 cta(short_size_no_matter_of_signedness, sizeof(short) == sizeof(unsigned short));
2133 /* the next assertion is probably not really needed */
2134 cta(int_is_4_char, sizeof(int) == 4);
2135 cta(int_size_no_matter_of_signedness, sizeof(int) == sizeof(unsigned int));
2137 cta(long_ge_int, sizeof(long) >= sizeof(int));
2138 cta(long_size_no_matter_of_signedness, sizeof(long) == sizeof(unsigned long));
2140 #ifndef MKSH_LEGACY_MODE
2141 /* the next assertion is probably not really needed */
2142 cta(ari_is_4_char, sizeof(mksh_ari_t) == 4);
2144 cta(ari_has_31_bit, 0 < (mksh_ari_t)(((((mksh_ari_t)1 << 15) << 15) - 1) * 2 + 1));
2145 /* the next assertion is probably not really needed */
2146 cta(uari_is_4_char, sizeof(mksh_uari_t) == 4);
2147 /* but the next three are; we REQUIRE unsigned integer wraparound */
2148 cta(uari_has_31_bit, 0 < (mksh_uari_t)(((((mksh_uari_t)1 << 15) << 15) - 1) * 2 + 1));
2149 cta(uari_has_32_bit, 0 < (mksh_uari_t)(((((mksh_uari_t)1 << 15) << 15) - 1) * 4 + 3));
2150 cta(uari_wrap_32_bit,
2151 (mksh_uari_t)(((((mksh_uari_t)1 << 15) << 15) - 1) * 4 + 3) >
2152 (mksh_uari_t)(((((mksh_uari_t)1 << 15) << 15) - 1) * 4 + 4));
2157 /* these are always required */
2158 cta(ari_is_signed, (mksh_ari_t)-1 < (mksh_ari_t)0);
2159 cta(uari_is_unsigned, (mksh_uari_t)-1 > (mksh_uari_t)0);
2160 /* we require these to have the precisely same size and assume 2s complement */
2161 cta(ari_size_no_matter_of_signedness, sizeof(mksh_ari_t) == sizeof(mksh_uari_t));
2163 cta(sizet_size_no_matter_of_signedness, sizeof(ssize_t) == sizeof(size_t));
2164 cta(ptrdifft_sizet_same_size, sizeof(ptrdiff_t) == sizeof(size_t));
2165 cta(ptrdifft_voidptr_same_size, sizeof(ptrdiff_t) == sizeof(void *));
2166 cta(ptrdifft_funcptr_same_size, sizeof(ptrdiff_t) == sizeof(void (*)(void)));
2167 /* our formatting routines assume this */
2168 cta(ptr_fits_in_long, sizeof(ptrdiff_t) <= sizeof(long));
2169 /* for struct alignment people */
2170 char padding[64 - NUM];
2172 char ctasserts_dblcheck[sizeof(struct ctasserts) == 64 ? 1 : -1];
2173 int main(void) { return (sizeof(ctasserts_dblcheck) + isatty(0)); }
2176 eval test 1 = \$HAVE_COMPILE_TIME_ASSERTS_$$ || exit 1
2179 # extra checks for legacy mksh
2181 if test $legacy = 1; then
2182 ac_test long_32bit '' 'whether long is 32 bit wide' <<-'EOF'
2183 #define MKSH_INCLUDES_ONLY
2189 #define cta(name, assertion) char name[(assertion) ? 1 : -1]
2190 cta(char_is_8_bits, (CHAR_BIT) == 8);
2191 cta(long_is_32_bits, sizeof(long) == 4);
2193 int main(void) { return (sizeof(struct ctasserts)); }
2196 ac_test long_64bit '!' long_32bit 0 'whether long is 64 bit wide' <<-'EOF'
2197 #define MKSH_INCLUDES_ONLY
2203 #define cta(name, assertion) char name[(assertion) ? 1 : -1]
2204 cta(char_is_8_bits, (CHAR_BIT) == 8);
2205 cta(long_is_64_bits, sizeof(long) == 8);
2207 int main(void) { return (sizeof(struct ctasserts)); }
2210 case $HAVE_LONG_32BIT$HAVE_LONG_64BIT in
2211 10) check_categories="$check_categories int:32" ;;
2212 01) check_categories="$check_categories int:64" ;;
2213 *) check_categories="$check_categories int:u" ;;
2218 # Compiler: Praeprocessor (only if needed)
2220 test 0 = $HAVE_SYS_SIGNAME && if ac_testinit cpp_dd '' \
2221 'checking if the C Preprocessor supports -dD'; then
2222 echo '#define foo bar' >conftest.c
2223 vv ']' "$CPP $CFLAGS $CPPFLAGS $NOWARN -dD conftest.c >x"
2224 grep '#define foo bar' x >/dev/null 2>&1 && fv=1
2225 rmf conftest.c x vv.out
2230 # End of mirtoconf checks
2234 # Some operating systems have ancient versions of ed(1) writing
2235 # the character count to standard output; cope for that
2237 ed x <x 2>/dev/null | grep 3 >/dev/null 2>&1 && \
2238 check_categories="$check_categories $oldish_ed"
2241 if test 0 = $HAVE_SYS_SIGNAME; then
2242 if test 1 = $HAVE_CPP_DD; then
2243 $e Generating list of signal names...
2245 $e No list of signal names available via cpp. Falling back...
2249 echo '#include <signal.h>
2253 #elif defined(SIGMAX)
2254 #define NSIG (SIGMAX+1)
2255 #elif defined(_SIGMAX)
2256 #define NSIG (_SIGMAX+1)
2258 /* XXX better error out, see sh.h */
2265 # GNU sed 2.03 segfaults when optimising this to sed -n
2266 NSIG=`vq "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c" | \
2267 grep '^ *mksh_cfg *=' | \
2268 sed 's/^ *mksh_cfg *=[ ]*\([()0-9x+-][()0-9x+ -]*\).*$/\1/'`
2270 *mksh_cfg*) $e "Error: NSIG='$NSIG'"; NSIG=0 ;;
2271 *[\ \(\)+-]*) NSIG=`"$AWK" "BEGIN { print $NSIG }" </dev/null` ;;
2274 (printf hallo) >/dev/null 2>&1 || printf=echo
2275 test $printf = echo || test "`printf %d 42`" = 42 || printf=echo
2276 test $printf = echo || NSIG=`printf %d "$NSIG" 2>/dev/null`
2277 $printf "NSIG=$NSIG ... "
2278 sigs="ABRT FPE ILL INT SEGV TERM ALRM BUS CHLD CONT HUP KILL PIPE QUIT"
2279 sigs="$sigs STOP TSTP TTIN TTOU USR1 USR2 POLL PROF SYS TRAP URG VTALRM"
2280 sigs="$sigs XCPU XFSZ INFO WINCH EMT IO DIL LOST PWR SAK CLD IOT RESV"
2281 sigs="$sigs STKFLT UNUSED"
2282 test 1 = $HAVE_CPP_DD && test $NSIG -gt 1 && sigs="$sigs "`vq \
2283 "$CPP $CFLAGS $CPPFLAGS $NOWARN -dD conftest.c" | \
2284 grep '[ ]SIG[A-Z0-9][A-Z0-9]*[ ]' | \
2285 sed 's/^.*[ ]SIG\([A-Z0-9][A-Z0-9]*\)[ ].*$/\1/' | sort`
2286 test $NSIG -gt 1 || sigs=
2287 for name in $sigs; do
2289 *:$name:*) continue ;;
2291 sigseenone=$sigseenone$name:
2292 echo '#include <signal.h>' >conftest.c
2293 echo int >>conftest.c
2294 echo mksh_cfg= SIG$name >>conftest.c
2295 echo ';' >>conftest.c
2296 # GNU sed 2.03 croaks on optimising this, too
2297 vq "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c" | \
2298 grep '^ *mksh_cfg *=' | \
2299 sed 's/^ *mksh_cfg *=[ ]*\([0-9][0-9x]*\).*$/:\1 '$name/
2300 done | sed -n '/^:[^ ]/s/^://p' | while read nr name; do
2301 test $printf = echo || nr=`printf %d "$nr" 2>/dev/null`
2302 test $nr -gt 0 && test $nr -le $NSIG || continue
2305 *) echo " { \"$name\", $nr },"
2306 sigseentwo=$sigseentwo$nr:
2307 $printf "$name=$nr " >&2
2310 done 2>&1 >signames.inc
2315 addsrcs '!' HAVE_STRLCPY strlcpy.c
2316 addsrcs USE_PRINTF_BUILTIN printf.c
2317 test 1 = "$USE_PRINTF_BUILTIN" && add_cppflags -DMKSH_PRINTF_BUILTIN
2318 test 1 = "$HAVE_CAN_VERB" && CFLAGS="$CFLAGS -verbose"
2319 add_cppflags -DMKSH_BUILD_R=503
2321 $e $bi$me: Finished configuration testing, now producing output.$ao
2327 a.exe) mkshexe=$tfn.exe ;;
2331 *\ *) mkshshebang="#!./$mkshexe" ;;
2332 *) mkshshebang="#!$curdir/$mkshexe" ;;
2336 LC_ALL=C PATH='$PATH'; export LC_ALL PATH
2337 test -n "\$KSH_VERSION" || exit 1
2338 set -A check_categories -- $check_categories
2339 pflag='$curdir/$mkshexe'
2340 sflag='$srcdir/check.t'
2341 usee=0 Pflag=0 Sflag=0 uset=0 vflag=1 xflag=0
2342 while getopts "C:e:fPp:QSs:t:v" ch; do case \$ch {
2343 (C) check_categories[\${#check_categories[*]}]=\$OPTARG ;;
2344 (e) usee=1; eflag=\$OPTARG ;;
2345 (f) check_categories[\${#check_categories[*]}]=fastbox ;;
2348 (p) pflag=\$OPTARG ;;
2353 (s) sflag=\$OPTARG ;;
2354 (t) uset=1; tflag=\$OPTARG ;;
2360 shift \$((OPTIND - 1))
2361 set -A args -- '$srcdir/check.pl' -p "\$pflag"
2363 for y in "\${check_categories[@]}"; do
2366 if [[ -n \$x ]]; then
2367 args[\${#args[*]}]=-C
2368 args[\${#args[*]}]=\${x#,}
2371 args[\${#args[*]}]=-e
2372 args[\${#args[*]}]=\$eflag
2374 (( Pflag )) && args[\${#args[*]}]=-P
2376 args[\${#args[*]}]=-t
2377 args[\${#args[*]}]=\$tflag
2379 (( vflag )) && args[\${#args[*]}]=-v
2380 (( xflag )) && args[\${#args[*]}]=-x # force usage by synerr
2381 if [[ -n \$TMPDIR && -d \$TMPDIR/. ]]; then
2382 args[\${#args[*]}]=-T
2383 args[\${#args[*]}]=\$TMPDIR
2385 print Testing mksh for conformance:
2386 fgrep -e MirOS: -e MIRBSD "\$sflag"
2387 print "This shell is actually:\\n\\t\$KSH_VERSION"
2388 print 'test.sh built for mksh $dstversion'
2389 cstr='\$os = defined \$^O ? \$^O : "unknown";'
2390 cstr="\$cstr"'print \$os . ", Perl version " . \$];'
2391 for perli in \$PERL perl5 perl no; do
2392 if [[ \$perli = no ]]; then
2393 print Cannot find a working Perl interpreter, aborting.
2396 print "Trying Perl interpreter '\$perli'..."
2397 perlos=\$(\$perli -e "\$cstr")
2399 print "Errorlevel \$rv, running on '\$perlos'"
2401 print "=> not using"
2404 if [[ -n \$perlos ]]; then
2409 (( Sflag )) || echo + \$perli "\${args[@]}" -s "\$sflag" "\$@"
2410 (( Sflag )) || exec \$perli "\${args[@]}" -s "\$sflag" "\$@"$tsts
2411 # use of the -S option for check.t split into multiple chunks
2413 for s in "\$sflag".*; do
2414 echo + \$perli "\${args[@]}" -s "\$s" "\$@"
2415 \$perli "\${args[@]}" -s "\$s" "\$@"$tsts
2417 (( rv = rv ? rv : rc ))
2427 emitbc="-emit-llvm -c"
2433 echo ": # work around NeXTstep bug" >Rebuild.sh
2434 for file in "$srcdir"/*.opt; do
2435 echo "echo + Running genopt on '$file'..."
2436 echo "(srcfile='$file'; BUILDSH_RUN_GENOPT=1; . '$srcdir/Build.sh')"
2438 echo set -x >>Rebuild.sh
2439 for file in $SRCS; do
2440 op=`echo x"$file" | sed 's/^x\(.*\)\.c$/\1./'`
2441 test -f $file || file=$srcdir/$file
2442 files="$files$sp$file"
2444 echo "$CC $CFLAGS $CPPFLAGS $emitbc $file || exit 1" >>Rebuild.sh
2445 if test $cm = dragonegg; then
2446 echo "mv ${op}s ${op}ll" >>Rebuild.sh
2447 echo "llvm-as ${op}ll || exit 1" >>Rebuild.sh
2448 objs="$objs$sp${op}bc"
2450 objs="$objs$sp${op}o"
2455 echo "rm -f $tfn.s" >>Rebuild.sh
2456 echo "llvm-link -o - $objs | opt $optflags | llc -o $tfn.s" >>Rebuild.sh
2463 echo tcfn=$mkshexe >>Rebuild.sh
2464 echo "$CC $CFLAGS $LDFLAGS -o \$tcfn $lobjs $LIBS $ccpr" >>Rebuild.sh
2465 echo "test -f \$tcfn || exit 1; $SIZE \$tcfn" >>Rebuild.sh
2466 if test $cm = makefile; then
2467 extras='emacsfn.h rlimits.opt sh.h sh_flags.opt var_spec.h'
2468 test 0 = $HAVE_SYS_SIGNAME && extras="$extras signames.inc"
2470 for file in "$srcdir"/*.opt; do
2471 genf=`basename "$file" | sed 's/.opt$/.gen/'`
2473 genq="$genq$nl$genf: $srcdir/Build.sh $file
2474 srcfile=$file; BUILDSH_RUN_GENOPT=1; . $srcdir/Build.sh"
2476 cat >Makefrag.inc <<EOF
2477 # Makefile fragment for building mksh $dstversion
2485 NONSRCS_INST= dot.mkshrc \$(MAN)
2486 NONSRCS_NOINST= Build.sh Makefile Rebuild.sh check.pl check.t test.sh
2493 .depend \$(OBJS_BP):$gens$genq
2495 # not BSD make only:
2498 #\$(PROG): \$(OBJS_BP)
2499 # \$(CC) \$(CFLAGS) \$(LDFLAGS) -o \$@ \$(OBJS_BP) \$(LIBS)
2500 #\$(OBJS_BP): \$(SRCS_FP) \$(NONSRCS)
2502 # \$(CC) \$(CFLAGS) \$(CPPFLAGS) -c \$<
2504 # for all make variants:
2507 # ./test.sh \$(REGRESS_FLAGS)
2508 check_categories=$check_categories
2510 # for BSD make only:
2512 #.include <bsd.prog.mk>
2515 $e Generated Makefrag.inc successfully.
2518 for file in "$srcdir"/*.opt; do
2519 $e "+ Running genopt on '$file'..."
2520 do_genopt "$file" || exit 1
2522 if test $cm = combine; then
2524 for file in $SRCS; do
2525 test -f $file || file=$srcdir/$file
2528 emitbc="-fwhole-program --combine"
2529 v "$CC $CFLAGS $CPPFLAGS $LDFLAGS $emitbc $objs $LIBS $ccpr"
2530 elif test 1 = $pm; then
2531 for file in $SRCS; do
2532 test -f $file || file=$srcdir/$file
2533 v "$CC $CFLAGS $CPPFLAGS $emitbc $file" &
2537 for file in $SRCS; do
2538 test $cm = dragonegg && \
2539 op=`echo x"$file" | sed 's/^x\(.*\)\.c$/\1./'`
2540 test -f $file || file=$srcdir/$file
2541 v "$CC $CFLAGS $CPPFLAGS $emitbc $file" || exit 1
2542 if test $cm = dragonegg; then
2543 v "mv ${op}s ${op}ll"
2544 v "llvm-as ${op}ll" || exit 1
2551 v "llvm-link -o - $objs | opt $optflags | llc -o $tfn.s"
2555 test $cm = combine || v "$CC $CFLAGS $LDFLAGS -o $tcfn $lobjs $LIBS $ccpr"
2556 test -f $tcfn || exit 1
2557 test 1 = $r || v "$NROFF -mdoc <'$srcdir/mksh.1' >$tfn.cat1" || \
2559 test 0 = $eq && v $SIZE $tcfn
2561 test -f /usr/ucb/$i && i=/usr/ucb/$i
2564 $e Installing the shell:
2565 $e "# $i -c -s -o root -g bin -m 555 $tfn /bin/$tfn"
2566 if test $legacy = 0; then
2567 $e "# grep -x /bin/$tfn /etc/shells >/dev/null || echo /bin/$tfn >>/etc/shells"
2568 $e "# $i -c -o root -g bin -m 444 dot.mkshrc /usr/share/doc/mksh/examples/"
2571 $e Installing the manual:
2572 if test -f $tfn.cat1; then
2573 $e "# $i -c -o root -g bin -m 444 $tfn.cat1" \
2574 "/usr/share/man/cat1/$tfn.0"
2577 $e "# $i -c -o root -g bin -m 444 $tfn.1 /usr/share/man/man1/$tfn.1"
2579 $e Run the regression test suite: ./test.sh
2580 $e Please also read the sample file dot.mkshrc and the fine manual.
2585 === Environment used ===
2587 ==== build environment ====
2590 CFLAGS if empty, defaults to -xO2 or +O2
2591 or -O3 -qstrict or -O2, per compiler
2592 CPPFLAGS default empty
2593 LDFLAGS default empty; added before sources
2594 LDSTATIC set this to '-static'; default unset
2595 LIBS default empty; added after sources
2596 [Interix] default: -lcrypt (XXX still needed?)
2597 NOWARN -Wno-error or similar
2598 NROFF default: nroff
2599 TARGET_OS default: $(uname -s || uname)
2600 TARGET_OSREV [QNX] default: $(uname -r)
2602 ==== feature selectors ====
2603 USE_PRINTF_BUILTIN 1 to include (unsupported) printf(1) as builtin
2604 ===== general format =====
2606 HAVE_STRING_H ac_header
2607 HAVE_CAN_FSTACKPROTECTORALL ac_flags
2609 ==== cpp definitions ====
2610 DEBUG dont use in production, wants gcc, implies:
2611 DEBUG_LEAKS enable freeing resources before exiting
2612 MKSHRC_PATH "~/.mkshrc" (do not change)
2613 MKSH_A4PB force use of arc4random_pushb
2614 MKSH_ASSUME_UTF8 (0=disabled, 1=enabled; default: unset)
2615 MKSH_BINSHPOSIX if */sh or */-sh, enable set -o posix
2616 MKSH_BINSHREDUCED if */sh or */-sh, enable set -o sh
2617 MKSH_CLRTOEOL_STRING "\033[K"
2618 MKSH_CLS_STRING "\033[;H\033[J"
2619 MKSH_CONSERVATIVE_FDS fd 0-9 for scripts, shell only up to 31
2620 MKSH_DEFAULT_EXECSHELL "/bin/sh" (do not change)
2621 MKSH_DEFAULT_PROFILEDIR "/etc" (do not change)
2622 MKSH_DEFAULT_TMPDIR "/tmp" (do not change)
2623 MKSH_DISABLE_DEPRECATED disable code paths scheduled for later removal
2624 MKSH_DISABLE_EXPERIMENTAL disable code not yet comfy for (LTS) snapshots
2625 MKSH_DISABLE_TTY_WARNING shut up warning about ctty if OS cant be fixed
2626 MKSH_DONT_EMIT_IDSTRING omit RCS IDs from binary
2627 MKSH_MIDNIGHTBSD01ASH_COMPAT set -o sh: additional compatibility quirk
2628 MKSH_NOPROSPECTOFWORK disable jobs, co-processes, etc. (do not use)
2629 MKSH_NOPWNAM skip PAM calls, for -static on glibc or Solaris
2630 MKSH_NO_CMDLINE_EDITING disable command line editing code entirely
2631 MKSH_NO_DEPRECATED_WARNING omit warning when deprecated stuff is run
2632 MKSH_NO_EXTERNAL_CAT omit hack to skip cat builtin when flags passed
2633 MKSH_NO_LIMITS omit ulimit code
2634 MKSH_NO_SIGSETJMP define if sigsetjmp is broken or not available
2635 MKSH_NO_SIGSUSPEND use sigprocmask+pause instead of sigsuspend
2636 MKSH_SMALL omit some code, optimise hard for size (slower)
2637 MKSH_SMALL_BUT_FAST disable some hard-for-size optim. (modern sys.)
2638 MKSH_S_NOVI=1 disable Vi editing mode (default if MKSH_SMALL)
2639 MKSH_TYPEDEF_SIG_ATOMIC_T define to e.g. 'int' if sig_atomic_t is missing
2640 MKSH_TYPEDEF_SSIZE_T define to e.g. 'long' if your OS has no ssize_t
2641 MKSH_UNEMPLOYED disable job control (but not jobs/co-processes)
2643 === generic installation instructions ===
2645 Set CC and possibly CFLAGS, CPPFLAGS, LDFLAGS, LIBS. If cross-compiling,
2646 also set TARGET_OS. To disable tests, set e.g. HAVE_STRLCPY=0; to enable
2647 them, set to a value other than 0 or 1. Ensure /bin/ed is installed. For
2648 MKSH_SMALL but with Vi mode, add -DMKSH_S_NOVI=0 to CPPFLAGS as well.
2650 Normally, the following command is what you want to run, then:
2651 $ (sh Build.sh -r -c lto && ./test.sh -f) 2>&1 | tee log
2653 Copy dot.mkshrc to /etc/skel/.mkshrc; install mksh into $prefix/bin; or
2654 /bin; install the manpage, if omitting the -r flag a catmanpage is made
2655 using $NROFF. Consider using a forward script as /etc/skel/.mkshrc like
2656 http://anonscm.debian.org/cgit/collab-maint/mksh.git/plain/debian/.mkshrc
2657 and put dot.mkshrc as /etc/mkshrc so users need not keep up their HOME.