2 srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.622 2013/02/19 18:45:15 tg Exp $'
4 # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
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
55 eval "$@" >vv.out 2>&1
56 sed "s
\a^
\a${_c}
\a" <vv.out
66 Build.sh|check.pl|check.t|dot.mkshrc|*.c|*.h|mksh.1) ;;
72 allu=QWERTYUIOPASDFGHJKLZXCVBNM
73 alll=qwertyuiopasdfghjklzxcvbnm
75 alls=______________________________________________________________
86 oldish_ed=stdout-ed,no-stderr-ed
95 echo :"$@" | sed 's/^://' | tr $alll $allu
98 # clean up after ac_testrun()
102 test 0 = $fv || fr=yes
103 $e "$bi==> $fd...$ao $ui$fr$ao$fx"
107 # ac_cache label: sets f, fu, fv?=0
122 # ac_testinit label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput
123 # returns 1 if value was cached/implied, 0 otherwise: call ac_testdone
126 test x"$2" = x"!" && shift
127 test x"$2" = x"" || shift
133 if test x"$2" = x""; then
136 if test x"$2" = x"!"; then
140 eval ft=\$HAVE_`upper $2`
144 if test $fc = "$ft"; then
154 # pipe .c | ac_test[n] [!] label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput
156 if test x"$1" = x"!"; then
162 ac_testinit "$@" || return 1
164 vv ']' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN conftest.c $LIBS $ccpr"
165 test $tcfn = no && test -f a.out && tcfn=a.out
166 test $tcfn = no && test -f a.exe && tcfn=a.exe
167 test $tcfn = no && test -f conftest && tcfn=conftest
168 if test -f $tcfn; then
174 if test $phase = u; then
175 test $ct = gcc && vscan='unrecogni[sz]ed'
176 test $ct = hpcc && vscan='unsupported'
177 test $ct = pcc && vscan='unsupported'
178 test $ct = sunpro && vscan='-e ignored -e turned.off'
180 test -n "$vscan" && grep $vscan vv.out >/dev/null 2>&1 && fv=$fr
184 ac_testnnd "$@" || return
185 rmf conftest.c conftest.o ${tcfn}* vv.out
189 # ac_ifcpp cppexpr [!] label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput
193 int main(void) { return (
197 /* force a failure: expr is false */
198 thiswillneverbedefinedIhope()
202 test x"$1" = x"!" && shift
210 CPPFLAGS="$CPPFLAGS $*"
214 test x"$1" = x"" || fu=$1
216 test x"$2" = x"" && eval fv=\$HAVE_$fu
217 add_cppflags -DHAVE_$fu=$fv
225 # ac_flags [-] add varname cflags [text] [ldflags]
227 if test x"$1" = x"-"; then
238 test x"$ft" = x"" && ft="if $f can be used"
241 if test -n "$fl"; then
242 save_LDFLAGS=$LDFLAGS
243 LDFLAGS="$LDFLAGS $fl"
245 if test 1 = $hf; then
246 ac_testn can_$vn '' "$ft"
248 ac_testn can_$vn '' "$ft" <<-'EOF'
249 /* evil apo'stroph in comment test */
250 int main(void) { return (0); }
253 eval fv=\$HAVE_CAN_`upper $vn`
254 if test -n "$fl"; then
255 test 11 = $fa$fv || LDFLAGS=$save_LDFLAGS
257 test 11 = $fa$fv || CFLAGS=$save_CFLAGS
260 # ac_header [!] header [prereq ...]
262 if test x"$1" = x"!"; then
269 hv=`echo "$hf" | tr -d '\012\015' | tr -c $alll$allu$alln $alls`
270 echo "/* NeXTstep bug workaround */" >x
275 echo '#if HAVE_BOTH_TIME_H' >>x
276 echo '#include <sys/time.h>' >>x
277 echo '#include <time.h>' >>x
278 echo '#elif HAVE_SYS_TIME_H' >>x
279 echo '#include <sys/time.h>' >>x
280 echo '#elif HAVE_TIME_H' >>x
281 echo '#include <time.h>' >>x
285 echo "#include <$i>" >>x
289 echo "#include <$hf>" >>x
290 echo 'int main(void) { return (0); }' >>x
291 ac_testn "$hv" "" "<$hf>" <x
293 test 1 = $na || ac_cppflags
298 if test x"$1" = x"-s"; then
303 if test x"$1" = x"!"; then
310 if test $addsrcs_s = 1; then
311 if test -f "$2" || test -f "$srcdir/$2"; then
312 # always add $2, since it exists
317 test $fr = "$i" && case " $SRCS " in
319 *) SRCS="$SRCS $2" ;;
324 curdir=`pwd` srcdir=`dirname "$0" 2>/dev/null` check_categories=
325 test -n "$srcdir" || srcdir=. # in case dirname does not exist
326 dstversion=`sed -n '/define MKSH_VERSION/s/^.*"\([^"]*\)".*$/\1/p' $srcdir/sh.h`
327 add_cppflags -DMKSH_BUILDSH
334 optflags=-std-compile-opts
342 c:combine|c:dragonegg|c:llvm|c:lto)
347 echo "$me: Unknown option -c '$i'!" >&2
362 # checker, debug, valgrind build
364 CFLAGS="$CFLAGS -g3 -fno-builtin"
379 optflags=-std-compile-opts
394 echo "Build.sh $srcversion"
395 echo "for mksh $dstversion"
399 echo "$me: Unknown option '$i'!" >&2
403 echo "$me: Unknown option -'$last' '$i'!" >&2
408 if test -n "$last"; then
409 echo "$me: Option -'$last' not followed by argument!" >&2
413 test -z "$tfn" && if test $legacy = 0; then
418 if test -d $tfn || test -d $tfn.exe; then
419 echo "$me: Error: ./$tfn is a directory!" >&2
422 rmf a.exe* a.out* conftest.c *core core.* lft ${tfn}* no *.bc *.ll *.o \
423 Rebuild.sh signames.inc test.sh x vv.out
425 SRCS="lalloc.c eval.c exec.c expr.c funcs.c histrap.c jobs.c"
426 SRCS="$SRCS lex.c main.c misc.c shf.c syn.c tree.c var.c"
428 if test $legacy = 0; then
430 check_categories="$check_categories shell:legacy-no int:32"
432 check_categories="$check_categories shell:legacy-yes"
433 add_cppflags -DMKSH_LEGACY_MODE
434 HAVE_PERSISTENT_HISTORY=0
435 HAVE_ISSET_MKSH_CONSERVATIVE_FDS=1 # from sh.h
438 if test x"$srcdir" = x"."; then
439 CPPFLAGS="-I. $CPPFLAGS"
441 CPPFLAGS="-I. -I'$srcdir' $CPPFLAGS"
443 test -n "$LDSTATIC" && if test -n "$LDFLAGS"; then
444 LDFLAGS="$LDFLAGS $LDSTATIC"
449 if test -z "$TARGET_OS"; then
450 x=`uname -s 2>/dev/null || uname`
451 test x"$x" = x"`uname -n 2>/dev/null`" || TARGET_OS=$x
453 if test -z "$TARGET_OS"; then
454 echo "$me: Set TARGET_OS, your uname is broken!" >&2
461 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'
464 if test x"$TARGET_OS" = x"Android"; then
465 check_categories="$check_categories android"
470 if test x"$TARGET_OS" = x"Minix"; then
472 WARNING: additional checks before running Build.sh required!
473 You can avoid these by calling Build.sh correctly, see below.
475 cat >conftest.c <<'EOF'
476 #include <sys/types.h>
478 #ifdef _NETBSD_SOURCE
486 vv ']' "${CC-cc} -E $CFLAGS $CPPFLAGS $NOWARN conftest.c | grep ct= | tr -d \\\\015 >x"
493 Warning: you set TARGET_OS to $TARGET_OS but that is ambiguous.
494 Please set it to either Minix3 or Ninix3, whereas the latter is
495 all versions of Minix with even partial NetBSD(R) userland. The
496 value determined from your compiler for the current compilation
497 (which may be wrong) is: $ct
503 Warning: you set TARGET_OS to $TARGET_OS but that is ambiguous.
504 Please set it to either Minix3 or Ninix3, whereas the latter is
505 all versions of Minix with even partial NetBSD(R) userland. The
506 proper value couldn't be determined, continue at your own risk.
512 # Configuration depending on OS revision, on OSes that need them
515 test x"$TARGET_OSREV" = x"" && TARGET_OSREV=`hostinfo 2>&1 | \
516 grep 'NeXT Mach [0-9][0-9.]*:' | \
517 sed 's/^.*NeXT Mach \([0-9][0-9.]*\):.*$/\1/'`
520 test x"$TARGET_OSREV" = x"" && TARGET_OSREV=`uname -r`
524 # Configuration depending on OS name
528 add_cppflags -DMKSH_NO_SIGSETJMP
529 add_cppflags -DMKSH_TYPEDEF_SIG_ATOMIC_T=int
530 add_cppflags -DMKSH_CONSERVATIVE_FDS
533 add_cppflags -D_ALL_SOURCE
534 : ${HAVE_SETLOCALE_CTYPE=0}
539 oswarn="; it has minor issues"
542 oswarn="; you must recompile mksh with"
543 oswarn="$oswarn${nl}itself in a second stage"
546 # BeOS has no real tty either
547 add_cppflags -DMKSH_UNEMPLOYED
548 add_cppflags -DMKSH_DISABLE_TTY_WARNING
549 # BeOS doesn't have different UIDs and GIDs
550 add_cppflags -DMKSH__NO_SETEUGID
553 : ${HAVE_SETLOCALE_CTYPE=0}
556 oswarn="; it has major issues"
557 add_cppflags -DMKSH__NO_SYMLINK
558 check_categories="$check_categories nosymlink"
559 add_cppflags -DMKSH__NO_SETEUGID
560 add_cppflags -DMKSH_CONSERVATIVE_FDS
561 add_cppflags -DMKSH_DISABLE_TTY_WARNING
564 : ${HAVE_SETLOCALE_CTYPE=0}
567 add_cppflags -D_DARWIN_C_SOURCE
574 oswarn="; it has minor issues"
575 add_cppflags -D_GNU_SOURCE
576 add_cppflags -DMKSH_CONSERVATIVE_FDS
577 : ${HAVE_SETLOCALE_CTYPE=0}
582 *) add_cppflags -D_GNU_SOURCE ;;
584 # define MKSH__NO_PATH_MAX to use Hurd-only functions
585 add_cppflags -DMKSH__NO_PATH_MAX
590 *) add_cppflags -D_GNU_SOURCE ;;
594 add_cppflags -DMKSH_ASSUME_UTF8; HAVE_ISSET_MKSH_ASSUME_UTF8=1
601 add_cppflags -D_ALL_SOURCE
603 : ${HAVE_SETLOCALE_CTYPE=0}
606 : ${HAVE_SETLOCALE_CTYPE=0}
611 *) add_cppflags -D_GNU_SOURCE ;;
613 add_cppflags -DSETUID_CAN_FAIL_WITH_EAGAIN
617 oswarn="; it has minor issues"
622 add_cppflags -DMKSH__NO_SETEUGID
623 add_cppflags -DMKSH_UNEMPLOYED
624 add_cppflags -DMKSH_CONSERVATIVE_FDS
625 add_cppflags -D_MINIX_SOURCE
626 oldish_ed=no-stderr-ed # no /bin/ed, maybe see below
627 : ${HAVE_SETLOCALE_CTYPE=0}
630 add_cppflags -DMKSH_UNEMPLOYED
631 add_cppflags -DMKSH_CONSERVATIVE_FDS
632 add_cppflags -DMKSH_NO_LIMITS
633 add_cppflags -D_POSIX_SOURCE -D_POSIX_1_SOURCE=2 -D_MINIX
634 oldish_ed=no-stderr-ed # /usr/bin/ed(!) is broken
635 : ${HAVE_SETLOCALE_CTYPE=0}
640 add_cppflags -DMKSH_ASSUME_UTF8=0; HAVE_ISSET_MKSH_ASSUME_UTF8=1
641 # almost same as CYGWIN* (from RT|Chatzilla)
642 : ${HAVE_SETLOCALE_CTYPE=0}
643 # broken on this OE (from ir0nh34d)
649 add_cppflags -D_NEXT_SOURCE
650 add_cppflags -D_POSIX_SOURCE
651 : ${AWK=gawk} ${CC=cc -posix}
652 add_cppflags -DMKSH_NO_SIGSETJMP
653 # NeXTstep cannot get a controlling tty
654 add_cppflags -DMKSH_UNEMPLOYED
655 case $TARGET_OSREV in
657 # OpenStep 4.2 is broken by default
658 oswarn="; it needs libposix.a"
661 add_cppflags -DMKSH_CONSERVATIVE_FDS
665 add_cppflags -DMKSH_UNEMPLOYED
666 add_cppflags -DMKSH_CONSERVATIVE_FDS
667 add_cppflags -DMKSH_NO_LIMITS
668 # but no idea what else could be needed
669 oswarn="; it has unknown issues"
672 : ${HAVE_SETLOCALE_CTYPE=0}
675 HAVE_SIG_T=0 # incompatible
676 add_cppflags -D_OSF_SOURCE
677 add_cppflags -D_POSIX_C_SOURCE=200112L
678 add_cppflags -D_XOPEN_SOURCE=600
679 add_cppflags -D_XOPEN_SOURCE_EXTENDED
680 : ${HAVE_SETLOCALE_CTYPE=0}
683 add_cppflags -D_POSIX_SOURCE
684 add_cppflags -D_LIMITS_EXTENSION
685 add_cppflags -D_BSD_EXTENSION
686 add_cppflags -D_SUSV2_SOURCE
687 add_cppflags -DMKSH_ASSUME_UTF8; HAVE_ISSET_MKSH_ASSUME_UTF8=1
688 add_cppflags -DMKSH_NO_CMDLINE_EDITING
689 oswarn=' and will currently not work'
690 add_cppflags -DMKSH_UNEMPLOYED
693 HAVE_SIG_T=0 # incompatible
694 oswarn=' and will currently not work'
695 : ${HAVE_SETLOCALE_CTYPE=0}
698 add_cppflags -D__NO_EXT_QNX
699 add_cppflags -D__EXT_UNIX_MISC
700 case $TARGET_OSREV in
701 [012345].*|6.[0123].*|6.4.[01])
702 oldish_ed=no-stderr-ed # oldish /bin/ed is broken
705 : ${HAVE_SETLOCALE_CTYPE=0}
708 case $TARGET_OSREV in
711 add_cppflags -DMKSH_UNEMPLOYED
717 oswarn='; this is an unknown version of'
718 oswarn="$oswarn$nl$TARGET_OS ${TARGET_OSREV}, please tell me what to do"
721 add_cppflags -DMKSH_CONSERVATIVE_FDS
722 : ${HAVE_SYS_SIGLIST=0} ${HAVE__SYS_SIGLIST=0}
725 oswarn="; it has minor issues"
728 add_cppflags -D_BSD_SOURCE
729 add_cppflags -D__EXTENSIONS__
732 add_cppflags -D_GNU_SOURCE
733 add_cppflags -DMKSH_NO_SIGSUSPEND
734 oswarn=' and will currently not work'
738 add_cppflags -DMKSH_TYPEDEF_SSIZE_T=int
739 add_cppflags -DMKSH_CONSERVATIVE_FDS
740 : ${HAVE_SETLOCALE_CTYPE=0}
744 add_cppflags -DMKSH_CONSERVATIVE_FDS
745 : ${HAVE_SYS_SIGLIST=0} ${HAVE__SYS_SIGLIST=0}
751 oswarn="; it will compile, but the target"
752 oswarn="$oswarn${nl}platform itself is very flakey/unreliable"
753 : ${HAVE_SETLOCALE_CTYPE=0}
756 # generic target for SVR4 Unix with uname -s = uname -n
757 # this duplicates the * target below
758 oswarn='; it may or may not work'
759 test x"$TARGET_OSREV" = x"" && TARGET_OSREV=`uname -r`
762 oswarn='; it may or may not work'
763 test x"$TARGET_OSREV" = x"" && TARGET_OSREV=`uname -r`
769 : ${AWK=awk} ${CC=cc} ${NROFF=nroff}
770 test 0 = $r && echo | $NROFF -v 2>&1 | grep GNU >/dev/null 2>&1 && \
773 # this aids me in tracing FTBFSen without access to the buildd
774 $e "Hi from$ao $bi$srcversion$ao on:"
778 vv '|' "uname -a >&2"
781 vv '|' "hwprefs machine_type os_type os_class >&2"
782 vv '|' "uname -a >&2"
785 vv '|' "uname -a >&2"
789 vv '|' "uname -a >&2"
790 vv '|' "/usr/sbin/sizer -v >&2"
792 SCO_SV|UnixWare|UNIX_SV)
793 vv '|' "uname -a >&2"
794 vv '|' "uname -X >&2"
797 vv '|' "uname -a >&2"
800 test -z "$oswarn" || echo >&2 "
801 Warning: mksh has not yet been ported to or tested on your
802 operating system '$TARGET_OS'$oswarn. If you can provide
803 a shell account to the developer, this may improve; please
804 drop us a success or failure notice or even send in diffs.
806 $e "$bi$me: Building the MirBSD Korn Shell$ao $ui$dstversion$ao on $TARGET_OS ${TARGET_OSREV}..."
809 # Begin of mirtoconf checks
811 $e $bi$me: Scanning for functions... please ignore any errors.$ao
814 # Compiler: which one?
817 # - ICC defines __GNUC__ too
818 # - GCC defines __hpux too
819 # - LLVM+clang defines __GNUC__ too
820 # - nwcc defines __GNUC__ too
822 $e ... which compiler seems to be used
823 cat >conftest.c <<'EOF'
825 #if defined(__ICC) || defined(__INTEL_COMPILER)
827 #elif defined(__xlC__) || defined(__IBMC__)
829 #elif defined(__SUNPRO_C)
831 #elif defined(__ACK__)
833 #elif defined(__BORLANDC__)
835 #elif defined(__WATCOMC__)
837 #elif defined(__MWERKS__)
839 #elif defined(__HP_cc)
841 #elif defined(__DECC) || (defined(__osf__) && !defined(__GNUC__))
845 #elif defined(__DMC__)
847 #elif defined(_MSC_VER)
849 #elif defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__)
851 #elif defined(__IAR_SYSTEMS_ICC__)
855 #elif defined(__PCC__)
857 #elif defined(__TenDRA__)
859 #elif defined(__TINYC__)
861 #elif defined(__llvm__) && defined(__clang__)
863 #elif defined(__NWCC__)
865 #elif defined(__GNUC__)
867 #elif defined(_COMPILER_VERSION)
871 #elif defined(__hpux) || defined(__hpua)
873 #elif defined(__ultrix)
875 #elif defined(__USLC__)
877 #elif defined(__LCC__)
884 #if defined(__KLIBC__)
893 vv ']' "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c | \
894 sed -n '/^ *[ce]t *= */s/^ *\([ce]t\) *= */\1=/p' | tr -d \\\\015 >x"
898 echo 'int main(void) { return (0); }' >conftest.c
901 # work around "the famous ACK const bug"
902 CPPFLAGS="-Dconst= $CPPFLAGS"
905 echo >&2 'Warning: Analog Devices C++ compiler for Blackfin, TigerSHARC
906 and SHARC (21000) DSPs detected. This compiler has not yet
907 been tested for compatibility with mksh. Continue at your
908 own risk, please report success/failure to the developers.'
911 echo >&2 "Warning: Borland C++ Builder detected. This compiler might
912 produce broken executables. Continue at your own risk,
913 please report success/failure to the developers."
916 # does not work with current "ccc" compiler driver
917 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -version"
918 # one of these two works, for now
919 vv '|' "${CLANG-clang} -version"
920 vv '|' "${CLANG-clang} --version"
921 # ensure compiler and linker are in sync unless overridden
922 case $CCC_CC:$CCC_LD in
924 *:) CCC_LD=$CCC_CC; export CCC_LD ;;
928 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V"
929 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -Wl,-V conftest.c $LIBS"
932 echo >&2 "Warning: Digital Mars Compiler detected. When running under"
933 echo >&2 " UWIN, mksh tends to be unstable due to the limitations"
934 echo >&2 " of this platform. Continue at your own risk,"
935 echo >&2 " please report success/failure to the developers."
938 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS"
939 vv '|' 'echo `$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS \
940 -dumpmachine` gcc`$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN \
944 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
947 echo >&2 'Warning: IAR Systems (http://www.iar.com) compiler for embedded
948 systems detected. This unsupported compiler has not yet
949 been tested for compatibility with mksh. Continue at your
950 own risk, please report success/failure to the developers.'
953 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V"
956 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS"
957 add_cppflags -D__inline__=__inline
960 echo >&2 'Warning: Metrowerks C compiler detected. This has not yet
961 been tested for compatibility with mksh. Continue at your
962 own risk, please report success/failure to the developers.'
965 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -version"
968 ccpr= # errorlevels are not reliable
971 if [[ -n $C89_COMPILER ]]; then
972 C89_COMPILER=`ntpath2posix -c "$C89_COMPILER"`
976 if [[ -n $C89_LINKER ]]; then
977 C89_LINKER=`ntpath2posix -c "$C89_LINKER"`
981 vv '|' "$C89_COMPILER /HELP >&2"
982 vv '|' "$C89_LINKER /LINK >&2"
987 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -version"
990 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -v"
993 echo >&2 'Warning: PGI detected. This unknown compiler has not yet
994 been tested for compatibility with mksh. Continue at your
995 own risk, please report success/failure to the developers.'
998 echo >&2 'Warning: sdcc (http://sdcc.sourceforge.net), the small devices
999 C compiler for embedded systems detected. This has not yet
1000 been tested for compatibility with mksh. Continue at your
1001 own risk, please report success/failure to the developers.'
1004 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
1007 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -v"
1010 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V 2>&1 | \
1011 fgrep -i -e version -e release"
1014 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V"
1015 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -Wl,-V conftest.c $LIBS"
1018 case $TARGET_OS:$TARGET_OSREV in
1022 : ${HAVE_CAN_OTWO=0} ${HAVE_CAN_OPTIMISE=0}
1025 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
1028 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS"
1031 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -qversion"
1032 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -qversion=verbose"
1036 test x"$ct" = x"untested" && $e "!!! detecting preprocessor failed"
1039 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS"
1040 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
1045 vv '|' "llc -version"
1050 add_cppflags -DMKSH_NO_LIMITS
1053 # nothing special detected, don’t worry
1060 $e "$bi==> which compiler seems to be used...$ao $ui$ct${et+ on $et}$ao"
1061 rmf conftest.c conftest.o conftest a.out* a.exe* vv.out
1064 # Compiler: works as-is, with -Wno-error and -Werror
1069 ac_flags 0 compiler_works '' 'if the compiler works'
1070 test 1 = $HAVE_CAN_COMPILER_WORKS || exit 1
1071 HAVE_COMPILER_KNOWN=0
1072 test $ct = unknown || HAVE_COMPILER_KNOWN=1
1073 if ac_ifcpp 'if 0' compiler_fails '' \
1074 'if the compiler does not fail correctly'; then
1076 : ${HAVE_CAN_DELEXE=x}
1077 if test $ct = dmc; then
1078 CFLAGS="$CFLAGS ${ccpl}/DELEXECUTABLE"
1079 ac_testn can_delexe compiler_fails 0 'for the /DELEXECUTABLE linker option' <<-EOF
1080 int main(void) { return (0); }
1082 elif test $ct = dec; then
1083 CFLAGS="$CFLAGS ${ccpl}-non_shared"
1084 ac_testn can_delexe compiler_fails 0 'for the -non_shared linker option' <<-EOF
1085 int main(void) { return (0); }
1090 test 1 = $HAVE_CAN_DELEXE || CFLAGS=$save_CFLAGS
1091 ac_testn compiler_still_fails '' 'if the compiler still does not fail correctly' <<-EOF
1093 test 1 = $HAVE_COMPILER_STILL_FAILS && exit 1
1095 if ac_ifcpp 'ifdef __TINYC__' couldbe_tcc '!' compiler_known 0 \
1096 'if this could be tcc'; then
1098 CPP='cpp -D__TINYC__'
1099 HAVE_COMPILER_KNOWN=1
1102 if test $ct = sunpro; then
1103 test x"$save_NOWARN" = x"" && save_NOWARN='-errwarn=%none'
1104 ac_flags 0 errwarnnone "$save_NOWARN"
1105 test 1 = $HAVE_CAN_ERRWARNNONE || save_NOWARN=
1106 ac_flags 0 errwarnall "-errwarn=%all"
1107 test 1 = $HAVE_CAN_ERRWARNALL && DOWARN="-errwarn=%all"
1108 elif test $ct = hpcc; then
1111 elif test $ct = mipspro; then
1113 DOWARN="-diag_error 1-10000"
1114 elif test $ct = msc; then
1115 save_NOWARN="${ccpc}/w"
1117 elif test $ct = dmc; then
1118 save_NOWARN="${ccpc}-w"
1120 elif test $ct = bcc; then
1121 save_NOWARN="${ccpc}-w"
1123 elif test $ct = dec; then
1124 : -msg_* flags not used yet, or is -w2 correct?
1125 elif test $ct = xlc; then
1126 save_NOWARN=-qflag=i:e
1128 elif test $ct = tendra; then
1130 elif test $ct = ucode; then
1133 elif test $ct = watcom; then
1137 test x"$save_NOWARN" = x"" && save_NOWARN=-Wno-error
1138 ac_flags 0 wnoerror "$save_NOWARN"
1139 test 1 = $HAVE_CAN_WNOERROR || save_NOWARN=
1140 ac_flags 0 werror -Werror
1141 test 1 = $HAVE_CAN_WERROR && DOWARN=-Werror
1144 test $ct = icc && DOWARN="$DOWARN -wd1419"
1148 # Compiler: extra flags (-O2 -f* -W* etc.)
1150 i=`echo :"$orig_CFLAGS" | sed 's/^://' | tr -c -d $alll$allu$alln`
1151 # optimisation: only if orig_CFLAGS is empty
1152 test x"$i" = x"" && if test $ct = sunpro; then
1154 int main(void) { return (0); }
1155 #define __IDSTRING_CONCAT(l,p) __LINTED__ ## l ## _ ## p
1156 #define __IDSTRING_EXPAND(l,p) __IDSTRING_CONCAT(l,p)
1157 #define pad void __IDSTRING_EXPAND(__LINE__,x)(void) { }
1159 yes pad | head -n 256 >>x
1160 ac_flags - 1 otwo -xO2 <x
1162 elif test $ct = hpcc; then
1166 elif test $ct = xlc; then
1167 ac_flags 1 othree "-O3 -qstrict"
1168 test 1 = $HAVE_CAN_OTHREE || ac_flags 1 otwo -O2
1169 elif test $ct = tcc || test $ct = tendra; then
1170 : no special optimisation
1173 test 1 = $HAVE_CAN_OTWO || ac_flags 1 optimise -O
1175 # other flags: just add them if they are supported
1177 if test $ct = gcc; then
1178 # The following tests run with -Werror (gcc only) if possible
1179 NOWARN=$DOWARN; phase=u
1180 ac_flags 0 wnooverflow -Wno-overflow
1181 # mksh is not written in CFrustFrust!
1182 ac_flags 1 no_eh_frame -fno-asynchronous-unwind-tables
1183 ac_flags 1 fnostrictaliasing -fno-strict-aliasing
1184 ac_flags 1 fstackprotectorall -fstack-protector-all
1185 test $cm = dragonegg && case " $CC $CFLAGS $LDFLAGS " in
1186 *\ -fplugin=*dragonegg*) ;;
1187 *) ac_flags 1 fplugin_dragonegg -fplugin=dragonegg ;;
1189 if test $cm = lto; then
1191 checks='1 2 3 4 5 6 7 8'
1192 elif test $cm = combine; then
1198 test $fv = 1 || for what in $checks; do
1199 test $fv = 1 && break
1201 1) t_cflags='-flto=jobserver'
1202 t_ldflags='-fuse-linker-plugin'
1203 t_use=1 t_name=fltojs_lp ;;
1204 2) t_cflags='-flto=jobserver' t_ldflags=''
1205 t_use=1 t_name=fltojs_nn ;;
1206 3) t_cflags='-flto=jobserver'
1207 t_ldflags='-fno-use-linker-plugin -fwhole-program'
1208 t_use=1 t_name=fltojs_np ;;
1210 t_ldflags='-fuse-linker-plugin'
1211 t_use=1 t_name=fltons_lp ;;
1212 5) t_cflags='-flto' t_ldflags=''
1213 t_use=1 t_name=fltons_nn ;;
1215 t_ldflags='-fno-use-linker-plugin -fwhole-program'
1216 t_use=1 t_name=fltons_np ;;
1217 7) t_cflags='-fwhole-program --combine' t_ldflags=''
1218 t_use=0 t_name=combine cm=combine ;;
1219 8) fv=1 cm=normal ;;
1221 test $fv = 1 && break
1222 ac_flags $t_use $t_name "$t_cflags" \
1223 "if gcc supports $t_cflags $t_ldflags" "$t_ldflags"
1226 elif test $ct = icc; then
1227 ac_flags 1 fnobuiltinsetmode -fno-builtin-setmode
1228 ac_flags 1 fnostrictaliasing -fno-strict-aliasing
1229 ac_flags 1 fstacksecuritycheck -fstack-security-check
1231 elif test $ct = sunpro; then
1234 ac_flags 1 ipo -xipo 'for cross-module optimisation'
1236 elif test $ct = hpcc; then
1238 # probably not needed
1239 #ac_flags 1 agcc -Agcc 'for support of GCC extensions'
1241 elif test $ct = dec; then
1242 ac_flags 0 verb -verbose
1243 ac_flags 1 rodata -readonly_strings
1244 elif test $ct = dmc; then
1245 ac_flags 1 decl "${ccpc}-r" 'for strict prototype checks'
1246 ac_flags 1 schk "${ccpc}-s" 'for stack overflow checking'
1247 elif test $ct = bcc; then
1248 ac_flags 1 strpool "${ccpc}-d" 'if string pooling can be enabled'
1249 elif test $ct = mipspro; then
1250 ac_flags 1 fullwarn -fullwarn 'for remark output support'
1251 elif test $ct = msc; then
1252 ac_flags 1 strpool "${ccpc}/GF" 'if string pooling can be enabled'
1253 echo 'int main(void) { char test[64] = ""; return (*test); }' >x
1254 ac_flags - 1 stackon "${ccpc}/GZ" 'if stack checks can be enabled' <x
1255 ac_flags - 1 stckall "${ccpc}/Ge" 'stack checks for all functions' <x
1256 ac_flags - 1 secuchk "${ccpc}/GS" 'for compiler security checks' <x
1258 ac_flags 1 wall "${ccpc}/Wall" 'to enable all warnings'
1259 ac_flags 1 wp64 "${ccpc}/Wp64" 'to enable 64-bit warnings'
1260 elif test $ct = xlc; then
1261 ac_flags 1 rodata "-qro -qroconst -qroptr"
1262 ac_flags 1 rtcheck -qcheck=all
1263 #ac_flags 1 rtchkc -qextchk # reported broken
1264 ac_flags 1 wformat "-qformat=all -qformat=nozln"
1265 #ac_flags 1 wp64 -qwarn64 # too verbose for now
1266 elif test $ct = tendra; then
1267 ac_flags 0 ysystem -Ysystem
1268 test 1 = $HAVE_CAN_YSYSTEM && CPPFLAGS="-Ysystem $CPPFLAGS"
1269 ac_flags 1 extansi -Xa
1270 elif test $ct = tcc; then
1271 : #broken# ac_flags 1 boundschk -b
1272 elif test $ct = clang; then
1274 elif test $ct = nwcc; then
1276 : #broken# ac_flags 1 ssp -stackprotect
1278 # flags common to a subset of compilers (run with -Werror on gcc)
1279 if test 1 = $i; then
1280 ac_flags 1 wall -Wall
1281 ac_flags 1 fwrapv -fwrapv
1285 # The following tests run with -Werror or similar (all compilers) if possible
1287 test $ct = pcc && phase=u
1290 # Compiler: check for stuff that only generates warnings
1292 ac_test attribute_bounded '' 'for __attribute__((__bounded__))' <<-'EOF'
1293 #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
1294 /* force a failure: TenDRA and gcc 1.42 have false positive here */
1295 int main(void) { return (thiswillneverbedefinedIhope()); }
1298 #undef __attribute__
1299 int xcopy(const void *, void *, size_t)
1300 __attribute__((__bounded__ (__buffer__, 1, 3)))
1301 __attribute__((__bounded__ (__buffer__, 2, 3)));
1302 int main(int ac, char *av[]) { return (xcopy(av[0], av[--ac], 1)); }
1303 int xcopy(const void *s, void *d, size_t n) {
1305 * if memmove does not exist, we are not on a system
1306 * with GCC with __bounded__ attribute either so poo
1308 memmove(d, s, n); return ((int)n);
1312 ac_test attribute_format '' 'for __attribute__((__format__))' <<-'EOF'
1313 #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
1314 /* force a failure: TenDRA and gcc 1.42 have false positive here */
1315 int main(void) { return (thiswillneverbedefinedIhope()); }
1317 #define fprintf printfoo
1319 #undef __attribute__
1321 extern int fprintf(FILE *, const char *format, ...)
1322 __attribute__((__format__ (__printf__, 2, 3)));
1323 int main(int ac, char **av) { return (fprintf(stderr, "%s%d", *av, ac)); }
1326 ac_test attribute_noreturn '' 'for __attribute__((__noreturn__))' <<-'EOF'
1327 #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
1328 /* force a failure: TenDRA and gcc 1.42 have false positive here */
1329 int main(void) { return (thiswillneverbedefinedIhope()); }
1332 #undef __attribute__
1333 void fnord(void) __attribute__((__noreturn__));
1334 int main(void) { fnord(); }
1335 void fnord(void) { exit(0); }
1338 ac_test attribute_unused '' 'for __attribute__((__unused__))' <<-'EOF'
1339 #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
1340 /* force a failure: TenDRA and gcc 1.42 have false positive here */
1341 int main(void) { return (thiswillneverbedefinedIhope()); }
1343 int main(int ac __attribute__((__unused__)), char **av
1344 __attribute__((__unused__))) { return (0); }
1347 ac_test attribute_used '' 'for __attribute__((__used__))' <<-'EOF'
1348 #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
1349 /* force a failure: TenDRA and gcc 1.42 have false positive here */
1350 int main(void) { return (thiswillneverbedefinedIhope()); }
1352 static const char fnord[] __attribute__((__used__)) = "42";
1353 int main(void) { return (0); }
1357 # End of tests run with -Werror
1362 # mksh: flavours (full/small mksh, omit certain stuff)
1364 if ac_ifcpp 'ifdef MKSH_SMALL' isset_MKSH_SMALL '' \
1365 "if a reduced-feature mksh is requested"; then
1367 : ${HAVE_PERSISTENT_HISTORY=0}
1368 check_categories="$check_categories smksh"
1369 HAVE_ISSET_MKSH_CONSERVATIVE_FDS=1 # from sh.h
1371 ac_ifcpp 'ifdef MKSH_BINSHREDUCED' isset_MKSH_BINSHREDUCED '' \
1372 "if a reduced-feature sh is requested" && \
1373 check_categories="$check_categories binsh"
1374 ac_ifcpp 'ifdef MKSH_UNEMPLOYED' isset_MKSH_UNEMPLOYED '' \
1375 "if mksh will be built without job control" && \
1376 check_categories="$check_categories arge"
1377 ac_ifcpp 'ifdef MKSH_NOPROSPECTOFWORK' isset_MKSH_NOPROSPECTOFWORK '' \
1378 "if mksh will be built without job signals" && \
1379 check_categories="$check_categories arge nojsig"
1380 ac_ifcpp 'ifdef MKSH_ASSUME_UTF8' isset_MKSH_ASSUME_UTF8 '' \
1381 'if the default UTF-8 mode is specified' && : ${HAVE_SETLOCALE_CTYPE=0}
1382 ac_ifcpp 'ifdef MKSH_CONSERVATIVE_FDS' isset_MKSH_CONSERVATIVE_FDS '' \
1383 'if traditional/conservative fd use is requested' && \
1384 check_categories="$check_categories convfds"
1385 #ac_ifcpp 'ifdef MKSH_DISABLE_DEPRECATED' isset_MKSH_DISABLE_DEPRECATED '' \
1386 # "if deprecated features are to be omitted" && \
1387 # check_categories="$check_categories nodeprecated"
1388 #ac_ifcpp 'ifdef MKSH_DISABLE_EXPERIMENTAL' isset_MKSH_DISABLE_EXPERIMENTAL '' \
1389 # "if experimental features are to be omitted" && \
1390 # check_categories="$check_categories noexperimental"
1391 ac_ifcpp 'ifdef MKSH_MIDNIGHTBSD01ASH_COMPAT' isset_MKSH_MIDNIGHTBSD01ASH_COMPAT '' \
1392 'if the MidnightBSD 0.1 ash compatibility mode is requested' && \
1393 check_categories="$check_categories mnbsdash"
1396 # Environment: headers
1398 ac_header sys/time.h sys/types.h
1399 ac_header time.h sys/types.h
1400 test "11" = "$HAVE_SYS_TIME_H$HAVE_TIME_H" || HAVE_BOTH_TIME_H=0
1401 ac_test both_time_h '' 'whether <sys/time.h> and <time.h> can both be included' <<-'EOF'
1402 #include <sys/types.h>
1403 #include <sys/time.h>
1405 int main(void) { struct tm tm; return ((int)sizeof(tm)); }
1407 ac_header sys/bsdtypes.h
1408 ac_header sys/file.h sys/types.h
1409 ac_header sys/mkdev.h sys/types.h
1410 ac_header sys/mman.h sys/types.h
1411 ac_header sys/param.h
1412 ac_header sys/resource.h sys/types.h _time
1413 ac_header sys/select.h sys/types.h
1414 ac_header sys/sysmacros.h
1416 ac_header grp.h sys/types.h
1418 ac_header libutil.h sys/types.h
1420 ac_header stdint.h stdarg.h
1421 # include strings.h only if compatible with string.h
1422 ac_header strings.h sys/types.h string.h
1424 ac_header ulimit.h sys/types.h
1428 # Environment: definitions
1430 echo '#include <sys/types.h>
1431 /* check that off_t can represent 2^63-1 correctly, thx FSF */
1432 #define LARGE_OFF_T (((off_t)1 << 62) - 1 + ((off_t)1 << 62))
1433 int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 &&
1434 LARGE_OFF_T % 2147483647 == 1) ? 1 : -1];
1435 int main(void) { return (0); }' >lft.c
1436 ac_testn can_lfs '' "for large file support" <lft.c
1437 save_CPPFLAGS=$CPPFLAGS
1438 add_cppflags -D_FILE_OFFSET_BITS=64
1439 ac_testn can_lfs_sus '!' can_lfs 0 "... with -D_FILE_OFFSET_BITS=64" <lft.c
1440 if test 0 = $HAVE_CAN_LFS_SUS; then
1441 CPPFLAGS=$save_CPPFLAGS
1442 add_cppflags -D_LARGE_FILES=1
1443 ac_testn can_lfs_aix '!' can_lfs 0 "... with -D_LARGE_FILES=1" <lft.c
1444 test 1 = $HAVE_CAN_LFS_AIX || CPPFLAGS=$save_CPPFLAGS
1446 rmf lft* # end of large file support test
1449 # Environment: types
1451 ac_test can_inttypes '!' stdint_h 1 "for standard 32-bit integer types" <<-'EOF'
1452 #include <sys/types.h>
1454 int main(int ac, char **av) { return ((uint32_t)(ptrdiff_t)*av + (int32_t)ac); }
1456 ac_test can_ucbints '!' can_inttypes 1 "for UCB 32-bit integer types" <<-'EOF'
1457 #include <sys/types.h>
1459 int main(int ac, char **av) { return ((u_int32_t)(ptrdiff_t)*av + (int32_t)ac); }
1461 ac_test can_int8type '!' stdint_h 1 "for standard 8-bit integer type" <<-'EOF'
1462 #include <sys/types.h>
1464 int main(int ac, char **av) { return ((uint8_t)(ptrdiff_t)av[ac]); }
1466 ac_test can_ucbint8 '!' can_int8type 1 "for UCB 8-bit integer type" <<-'EOF'
1467 #include <sys/types.h>
1469 int main(int ac, char **av) { return ((u_int8_t)(ptrdiff_t)av[ac]); }
1472 ac_test rlim_t <<-'EOF'
1473 #include <sys/types.h>
1474 #if HAVE_BOTH_TIME_H
1475 #include <sys/time.h>
1477 #elif HAVE_SYS_TIME_H
1478 #include <sys/time.h>
1482 #if HAVE_SYS_RESOURCE_H
1483 #include <sys/resource.h>
1486 int main(void) { return ((int)(rlim_t)0); }
1489 # only testn: added later below
1490 ac_testn sig_t <<-'EOF'
1491 #include <sys/types.h>
1494 int main(void) { return ((int)(ptrdiff_t)(sig_t)(ptrdiff_t)kill(0,0)); }
1497 ac_testn sighandler_t '!' sig_t 0 <<-'EOF'
1498 #include <sys/types.h>
1501 int main(void) { return ((int)(ptrdiff_t)(sighandler_t)(ptrdiff_t)kill(0,0)); }
1503 if test 1 = $HAVE_SIGHANDLER_T; then
1504 add_cppflags -Dsig_t=sighandler_t
1508 ac_testn __sighandler_t '!' sig_t 0 <<-'EOF'
1509 #include <sys/types.h>
1512 int main(void) { return ((int)(ptrdiff_t)(__sighandler_t)(ptrdiff_t)kill(0,0)); }
1514 if test 1 = $HAVE___SIGHANDLER_T; then
1515 add_cppflags -Dsig_t=__sighandler_t
1519 test 1 = $HAVE_SIG_T || add_cppflags -Dsig_t=nosig_t
1523 # check whether whatever we use for the final link will succeed
1525 if test $cm = makefile; then
1529 ac_testinit link_works '' 'checking if the final link command may succeed'
1531 cat >conftest.c <<-'EOF'
1533 #define MKSH_INCLUDES_ONLY
1535 __RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.622 2013/02/19 18:45:15 tg Exp $");
1536 int main(void) { printf("Hello, World!\n"); return (0); }
1540 v "$CC $CFLAGS $CPPFLAGS $NOWARN -emit-llvm -c conftest.c" || fv=0
1542 test $fv = 0 || v "llvm-link -o - conftest.o | opt $optflags | llc -o $tfn.s" || fv=0
1543 test $fv = 0 || v "$CC $CFLAGS $LDFLAGS -o $tcfn $tfn.s $LIBS $ccpr"
1546 v "$CC $CFLAGS $CPPFLAGS $NOWARN -S -flto conftest.c" || fv=0
1547 test $fv = 0 || v "mv conftest.s conftest.ll"
1548 test $fv = 0 || v "llvm-as conftest.ll" || fv=0
1550 test $fv = 0 || v "llvm-link -o - conftest.bc | opt $optflags | llc -o $tfn.s" || fv=0
1551 test $fv = 0 || v "$CC $CFLAGS $LDFLAGS -o $tcfn $tfn.s $LIBS $ccpr"
1554 v "$CC $CFLAGS $CPPFLAGS $LDFLAGS -fwhole-program --combine $NOWARN -o $tcfn conftest.c $LIBS $ccpr"
1558 v "$CC $CFLAGS $CPPFLAGS $NOWARN -c conftest.c" || fv=0
1559 test $fv = 0 || v "$CC $CFLAGS $LDFLAGS -o $tcfn conftest.o $LIBS $ccpr"
1562 test -f $tcfn || fv=0
1564 test $fv = 1 || exit 1
1568 # Environment: errors and signals
1570 test x"NetBSD" = x"$TARGET_OS" && $e Ignore the compatibility warning.
1572 ac_testn sys_errlist '' "the sys_errlist[] array and sys_nerr" <<-'EOF'
1573 extern const int sys_nerr;
1574 extern const char * const sys_errlist[];
1575 int main(void) { return (*sys_errlist[sys_nerr - 1]); }
1577 ac_testn _sys_errlist '!' sys_errlist 0 "the _sys_errlist[] array and _sys_nerr" <<-'EOF'
1578 extern const int _sys_nerr;
1579 extern const char * const _sys_errlist[];
1580 int main(void) { return (*_sys_errlist[_sys_nerr - 1]); }
1582 if test 1 = "$HAVE__SYS_ERRLIST"; then
1583 add_cppflags -Dsys_nerr=_sys_nerr
1584 add_cppflags -Dsys_errlist=_sys_errlist
1587 ac_cppflags SYS_ERRLIST
1589 for what in name list; do
1591 ac_testn sys_sig$what '' "the sys_sig${what}[] array" <<-EOF
1592 extern const char * const sys_sig${what}[];
1593 int main(void) { return (sys_sig${what}[0][0]); }
1595 ac_testn _sys_sig$what '!' sys_sig$what 0 "the _sys_sig${what}[] array" <<-EOF
1596 extern const char * const _sys_sig${what}[];
1597 int main(void) { return (_sys_sig${what}[0][0]); }
1599 eval uwhat_v=\$HAVE__SYS_SIG$uwhat
1600 if test 1 = "$uwhat_v"; then
1601 add_cppflags -Dsys_sig$what=_sys_sig$what
1602 eval HAVE_SYS_SIG$uwhat=1
1604 ac_cppflags SYS_SIG$uwhat
1608 # Environment: library functions
1610 ac_test flock <<-'EOF'
1611 #include <sys/types.h>
1615 #include <sys/file.h>
1617 int main(void) { return (flock(0, LOCK_EX | LOCK_UN)); }
1620 ac_test lock_fcntl '!' flock 1 'whether we can lock files with fcntl' <<-'EOF'
1625 lks.l_type = F_WRLCK | F_UNLCK;
1626 return (fcntl(0, F_SETLKW, &lks));
1630 ac_test getrusage <<-'EOF'
1631 #define MKSH_INCLUDES_ONLY
1635 return (getrusage(RUSAGE_SELF, &ru) +
1636 getrusage(RUSAGE_CHILDREN, &ru));
1640 ac_test gettimeofday <<-'EOF'
1641 #define MKSH_INCLUDES_ONLY
1643 int main(void) { struct timeval tv; return (gettimeofday(&tv, NULL)); }
1646 ac_test killpg <<-'EOF'
1648 int main(int ac, char *av[]) { return (av[0][killpg(123, ac)]); }
1651 ac_test memmove <<-'EOF'
1652 #include <sys/types.h>
1656 #include <strings.h>
1658 int main(int ac, char *av[]) {
1659 return (*(int *)(void *)memmove(av[0], av[1], ac));
1663 ac_test mknod '' 'if to use mknod(), makedev() and friends' <<-'EOF'
1664 #define MKSH_INCLUDES_ONLY
1666 int main(int ac, char *av[]) {
1668 dv = makedev((unsigned int)ac, (unsigned int)av[0][0]);
1669 return (mknod(av[0], (mode_t)0, dv) ? (int)major(dv) :
1674 ac_test mmap lock_fcntl 0 'for mmap and munmap' <<-'EOF'
1675 #include <sys/types.h>
1677 #include <sys/file.h>
1680 #include <sys/mman.h>
1684 int main(void) { return ((void *)mmap(NULL, (size_t)0,
1685 PROT_READ, MAP_PRIVATE, 0, (off_t)0) == (void *)NULL ? 1 :
1689 ac_test nice <<-'EOF'
1691 int main(void) { return (nice(4)); }
1694 ac_test revoke <<-'EOF'
1695 #include <sys/types.h>
1697 #include <libutil.h>
1700 int main(int ac, char *av[]) { return (ac + revoke(av[0])); }
1703 ac_test setlocale_ctype '' 'setlocale(LC_CTYPE, "")' <<-'EOF'
1706 int main(void) { return ((int)(ptrdiff_t)(void *)setlocale(LC_CTYPE, "")); }
1709 ac_test langinfo_codeset setlocale_ctype 0 'nl_langinfo(CODESET)' <<-'EOF'
1710 #include <langinfo.h>
1712 int main(void) { return ((int)(ptrdiff_t)(void *)nl_langinfo(CODESET)); }
1715 ac_test select <<-'EOF'
1716 #include <sys/types.h>
1717 #if HAVE_BOTH_TIME_H
1718 #include <sys/time.h>
1720 #elif HAVE_SYS_TIME_H
1721 #include <sys/time.h>
1725 #if HAVE_SYS_BSDTYPES_H
1726 #include <sys/bsdtypes.h>
1728 #if HAVE_SYS_SELECT_H
1729 #include <sys/select.h>
1732 #include <bstring.h>
1738 #include <strings.h>
1742 struct timeval tv = { 1, 200000 };
1743 fd_set fds; FD_ZERO(&fds); FD_SET(0, &fds);
1744 return (select(FD_SETSIZE, &fds, NULL, NULL, &tv));
1748 ac_test setresugid <<-'EOF'
1749 #include <sys/types.h>
1751 int main(void) { setresuid(0,0,0); return (setresgid(0,0,0)); }
1754 ac_test setgroups setresugid 0 <<-'EOF'
1755 #include <sys/types.h>
1760 int main(void) { gid_t gid = 0; return (setgroups(0, &gid)); }
1763 if test x"$et" = x"klibc"; then
1765 ac_testn __rt_sigsuspend '' 'whether klibc uses RT signals' <<-'EOF'
1766 #define MKSH_INCLUDES_ONLY
1768 extern int __rt_sigsuspend(const sigset_t *, size_t);
1769 int main(void) { return (__rt_sigsuspend(NULL, 0)); }
1772 # no? damn! legacy crap ahead!
1774 ac_testn __sigsuspend_s '!' __rt_sigsuspend 1 \
1775 'whether sigsuspend is usable (1/2)' <<-'EOF'
1776 #define MKSH_INCLUDES_ONLY
1778 extern int __sigsuspend_s(sigset_t);
1779 int main(void) { return (__sigsuspend_s(0)); }
1781 ac_testn __sigsuspend_xxs '!' __sigsuspend_s 1 \
1782 'whether sigsuspend is usable (2/2)' <<-'EOF'
1783 #define MKSH_INCLUDES_ONLY
1785 extern int __sigsuspend_xxs(int, int, sigset_t);
1786 int main(void) { return (__sigsuspend_xxs(0, 0, 0)); }
1789 if test "000" = "$HAVE___RT_SIGSUSPEND$HAVE___SIGSUSPEND_S$HAVE___SIGSUSPEND_XXS"; then
1790 # no usable sigsuspend(), use pause() *ugh*
1791 add_cppflags -DMKSH_NO_SIGSUSPEND
1795 ac_test strerror '!' sys_errlist 0 <<-'EOF'
1796 extern char *strerror(int);
1797 int main(int ac, char *av[]) { return (*strerror(*av[ac])); }
1800 ac_test strsignal '!' sys_siglist 0 <<-'EOF'
1803 int main(void) { return (strsignal(1)[0]); }
1806 ac_test strlcpy <<-'EOF'
1808 int main(int ac, char *av[]) { return (strlcpy(*av, av[1],
1813 # check headers for declarations
1815 ac_test flock_decl flock 1 'for declaration of flock()' <<-'EOF'
1816 #define MKSH_INCLUDES_ONLY
1819 #include <sys/file.h>
1821 int main(void) { return ((flock)(0, 0)); }
1823 ac_test revoke_decl revoke 1 'for declaration of revoke()' <<-'EOF'
1824 #define MKSH_INCLUDES_ONLY
1826 int main(void) { return ((revoke)("")); }
1828 ac_test sys_errlist_decl sys_errlist 0 "for declaration of sys_errlist[] and sys_nerr" <<-'EOF'
1829 #define MKSH_INCLUDES_ONLY
1831 int main(void) { return (*sys_errlist[sys_nerr - 1]); }
1833 ac_test sys_siglist_decl sys_siglist 0 'for declaration of sys_siglist[]' <<-'EOF'
1834 #define MKSH_INCLUDES_ONLY
1836 int main(void) { return (sys_siglist[0][0]); }
1842 fd='if to use persistent history'
1843 ac_cache PERSISTENT_HISTORY || case $HAVE_MMAP$HAVE_FLOCK$HAVE_LOCK_FCNTL in
1846 test 1 = $fv || check_categories="$check_categories no-histfile"
1851 test x1 = x$HAVE_CAN_WNOOVERFLOW && CFLAGS="$CFLAGS -Wno-overflow"
1852 ac_testn compile_time_asserts_$$ '' 'whether compile-time assertions pass' <<-'EOF'
1853 #define MKSH_INCLUDES_ONLY
1856 #define CHAR_BIT 8 /* defuse this test on really legacy systems */
1859 #define cta(name, assertion) char name[(assertion) ? 1 : -1]
1860 /* this one should be defined by the standard */
1861 cta(char_is_1_char, (sizeof(char) == 1) && (sizeof(signed char) == 1) &&
1862 (sizeof(unsigned char) == 1));
1863 cta(char_is_8_bits, ((CHAR_BIT) == 8) && ((int)(unsigned char)0xFF == 0xFF) &&
1864 ((int)(unsigned char)0x100 == 0) && ((int)(unsigned char)(int)-1 == 0xFF));
1865 /* the next assertion is probably not really needed */
1866 cta(short_is_2_char, sizeof(short) == 2);
1867 cta(short_size_no_matter_of_signedness, sizeof(short) == sizeof(unsigned short));
1868 /* the next assertion is probably not really needed */
1869 cta(int_is_4_char, sizeof(int) == 4);
1870 cta(int_size_no_matter_of_signedness, sizeof(int) == sizeof(unsigned int));
1872 cta(long_ge_int, sizeof(long) >= sizeof(int));
1873 cta(long_size_no_matter_of_signedness, sizeof(long) == sizeof(unsigned long));
1875 #ifndef MKSH_LEGACY_MODE
1876 /* the next assertion is probably not really needed */
1877 cta(ari_is_4_char, sizeof(mksh_ari_t) == 4);
1878 /* but the next two are; we REQUIRE signed integer wraparound */
1879 cta(ari_has_31_bit, 0 < (mksh_ari_t)(((((mksh_ari_t)1 << 15) << 15) - 1) * 2 + 1));
1880 #ifndef MKSH_GCC55009
1881 cta(ari_sign_32_bit_and_wrap,
1882 (mksh_ari_t)(((((mksh_ari_t)1 << 15) << 15) - 1) * 2 + 1) >
1883 (mksh_ari_t)(((((mksh_ari_t)1 << 15) << 15) - 1) * 2 + 2));
1885 /* the next assertion is probably not really needed */
1886 cta(uari_is_4_char, sizeof(mksh_uari_t) == 4);
1887 /* but the next three are; we REQUIRE unsigned integer wraparound */
1888 cta(uari_has_31_bit, 0 < (mksh_uari_t)(((((mksh_uari_t)1 << 15) << 15) - 1) * 2 + 1));
1889 cta(uari_has_32_bit, 0 < (mksh_uari_t)(((((mksh_uari_t)1 << 15) << 15) - 1) * 4 + 3));
1890 cta(uari_wrap_32_bit,
1891 (mksh_uari_t)(((((mksh_uari_t)1 << 15) << 15) - 1) * 4 + 3) >
1892 (mksh_uari_t)(((((mksh_uari_t)1 << 15) << 15) - 1) * 4 + 4));
1894 /* these are always required */
1895 cta(ari_is_signed, (mksh_ari_t)-1 < (mksh_ari_t)0);
1896 cta(uari_is_unsigned, (mksh_uari_t)-1 > (mksh_uari_t)0);
1898 cta(sizet_size_no_matter_of_signedness, sizeof(ssize_t) == sizeof(size_t));
1899 cta(ptrdifft_sizet_same_size, sizeof(ptrdiff_t) == sizeof(size_t));
1900 cta(ptrdifft_voidptr_same_size, sizeof(ptrdiff_t) == sizeof(void *));
1901 cta(ptrdifft_funcptr_same_size, sizeof(ptrdiff_t) == sizeof(void (*)(void)));
1902 /* our formatting routines assume this */
1903 cta(ptr_fits_in_long, sizeof(ptrdiff_t) <= sizeof(long));
1905 #ifndef MKSH_LEGACY_MODE
1906 #ifndef MKSH_GCC55009
1914 char ctasserts_dblcheck[sizeof(struct ctasserts) == NUM ? 1 : -1];
1915 int main(void) { return (sizeof(ctasserts_dblcheck)); }
1918 eval test 1 = \$HAVE_COMPILE_TIME_ASSERTS_$$ || exit 1
1921 # extra checks for legacy mksh
1923 if test $legacy = 1; then
1924 ac_test long_32bit '' 'whether long is 32 bit wide' <<-'EOF'
1925 #define MKSH_INCLUDES_ONLY
1931 #define cta(name, assertion) char name[(assertion) ? 1 : -1]
1932 cta(char_is_8_bits, (CHAR_BIT) == 8);
1933 cta(long_is_32_bits, sizeof(long) == 4);
1935 int main(void) { return (sizeof(struct ctasserts)); }
1938 ac_test long_64bit '!' long_32bit 0 'whether long is 64 bit wide' <<-'EOF'
1939 #define MKSH_INCLUDES_ONLY
1945 #define cta(name, assertion) char name[(assertion) ? 1 : -1]
1946 cta(char_is_8_bits, (CHAR_BIT) == 8);
1947 cta(long_is_64_bits, sizeof(long) == 8);
1949 int main(void) { return (sizeof(struct ctasserts)); }
1952 case $HAVE_LONG_32BIT$HAVE_LONG_64BIT in
1953 10) check_categories="$check_categories int:32" ;;
1954 01) check_categories="$check_categories int:64" ;;
1955 *) check_categories="$check_categories int:u" ;;
1961 # once this is more than one, check if we can do runtime
1962 # checks (not cross-compiling) first to save on warnings
1964 $e "${bi}run-time checks follow$ao, please ignore any weird errors"
1966 if ac_testnnd silent_idivwrapv '' '(run-time) whether signed integer division overflows wrap silently' <<-'EOF'
1967 #define MKSH_INCLUDES_ONLY
1969 #if !defined(MKSH_LEGACY_MODE) || HAVE_LONG_32BIT
1970 #define IDIVWRAPV_VL (mksh_uari_t)0x80000000UL
1971 #elif HAVE_LONG_64BIT
1972 #define IDIVWRAPV_VL (mksh_uari_t)0x8000000000000000UL
1974 # error "cannot check this"
1977 static void fpe_catcher(int) MKSH_A_NORETURN;
1979 int main(int ac, char **av) {
1980 mksh_ari_t o1, o2, r1, r2;
1983 signal(SIGFPE, fpe_catcher);
1985 o1 = (mksh_ari_t)IDIVWRAPV_VL;
1989 if (r1 == o1 && r2 == 0) {
1993 printf("no %d %d %d %d %s", (int)o1, (int)o2, (int)r1,
1998 static const char fpe_msg[] = "no, got SIGFPE, what were they smoking?";
1999 #define fpe_msglen (sizeof(fpe_msg) - 1)
2000 static void fpe_catcher(int sig MKSH_A_UNUSED) {
2001 _exit(write(1, fpe_msg, fpe_msglen) == fpe_msglen ? 2 : 3);
2006 if test $fv = 0; then
2007 echo "| hrm, compiling this failed, but we will just failback"
2009 echo "| running test programme; this will fail if cross-compiling"
2010 echo "| in which case we will gracefully degrade to the default"
2011 ./$tcfn >vv.out 2>&1
2013 echo "| result: `cat vv.out`"
2015 test $rv = 0 && test x"`cat vv.out`" = x"si" && fv=1
2017 rmf conftest.c conftest.o ${tcfn}* vv.out
2022 $e "${bi}end of run-time checks$ao"
2025 # Compiler: Praeprocessor (only if needed)
2027 test 0 = $HAVE_SYS_SIGNAME && if ac_testinit cpp_dd '' \
2028 'checking if the C Preprocessor supports -dD'; then
2029 echo '#define foo bar' >conftest.c
2030 vv ']' "$CPP $CFLAGS $CPPFLAGS $NOWARN -dD conftest.c >x"
2031 grep '#define foo bar' x >/dev/null 2>&1 && fv=1
2032 rmf conftest.c x vv.out
2037 # End of mirtoconf checks
2041 # Some operating systems have ancient versions of ed(1) writing
2042 # the character count to standard output; cope for that
2044 ed x <x 2>/dev/null | grep 3 >/dev/null 2>&1 && \
2045 check_categories="$check_categories $oldish_ed"
2048 if test 0 = $HAVE_SYS_SIGNAME; then
2049 if test 1 = $HAVE_CPP_DD; then
2050 $e Generating list of signal names...
2052 $e No list of signal names available via cpp. Falling back...
2056 echo '#include <signal.h>
2060 #elif defined(SIGMAX)
2061 #define NSIG (SIGMAX+1)
2062 #elif defined(_SIGMAX)
2063 #define NSIG (_SIGMAX+1)
2069 # GNU sed 2.03 segfaults when optimising this to sed -n
2070 NSIG=`vq "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c" | \
2071 grep '^ *mksh_cfg *=' | \
2072 sed 's/^ *mksh_cfg *=[ ]*\([()0-9x+-][()0-9x+ -]*\).*$/\1/'`
2074 *mksh_cfg*) $e "Error: NSIG='$NSIG'"; NSIG=0 ;;
2075 *[\ \(\)+-]*) NSIG=`"$AWK" "BEGIN { print $NSIG }" </dev/null` ;;
2078 (printf hallo) >/dev/null 2>&1 || printf=echo
2079 test $printf = echo || test "`printf %d 42`" = 42 || printf=echo
2080 test $printf = echo || NSIG=`printf %d "$NSIG" 2>/dev/null`
2081 $printf "NSIG=$NSIG ... "
2082 sigs="INT SEGV ABRT KILL ALRM BUS CHLD CLD CONT DIL EMT FPE HUP ILL"
2083 sigs="$sigs INFO IO IOT LOST PIPE PROF PWR QUIT RESV SAK STOP SYS TERM"
2084 sigs="$sigs TRAP TSTP TTIN TTOU URG USR1 USR2 VTALRM WINCH XCPU XFSZ"
2085 test 1 = $HAVE_CPP_DD && test $NSIG -gt 1 && sigs="$sigs "`vq \
2086 "$CPP $CFLAGS $CPPFLAGS $NOWARN -dD conftest.c" | \
2087 grep '[ ]SIG[A-Z0-9][A-Z0-9]*[ ]' | \
2088 sed 's/^.*[ ]SIG\([A-Z0-9][A-Z0-9]*\)[ ].*$/\1/' | sort`
2089 test $NSIG -gt 1 || sigs=
2090 for name in $sigs; do
2092 *:$name:*) continue ;;
2094 sigseenone=$sigseenone$name:
2095 echo '#include <signal.h>' >conftest.c
2096 echo int >>conftest.c
2097 echo mksh_cfg= SIG$name >>conftest.c
2098 echo ';' >>conftest.c
2099 # GNU sed 2.03 croaks on optimising this, too
2100 vq "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c" | \
2101 grep '^ *mksh_cfg *=' | \
2102 sed 's/^ *mksh_cfg *=[ ]*\([0-9][0-9x]*\).*$/:\1 '$name/
2103 done | sed -n '/^:[^ ]/s/^://p' | while read nr name; do
2104 test $printf = echo || nr=`printf %d "$nr" 2>/dev/null`
2105 test $nr -gt 0 && test $nr -le $NSIG || continue
2108 *) echo " { \"$name\", $nr },"
2109 sigseentwo=$sigseentwo$nr:
2110 $printf "$name=$nr " >&2
2113 done 2>&1 >signames.inc
2118 addsrcs -s '!' HAVE_STRLCPY strlcpy.c
2119 addsrcs USE_PRINTF_BUILTIN printf.c
2120 test 1 = "$USE_PRINTF_BUILTIN" && add_cppflags -DMKSH_PRINTF_BUILTIN
2121 test 1 = "$HAVE_CAN_VERB" && CFLAGS="$CFLAGS -verbose"
2122 test -n "$LDSTATIC" && add_cppflags -DMKSH_OPTSTATIC
2123 add_cppflags -DMKSH_BUILD_R=431
2125 $e $bi$me: Finished configuration testing, now producing output.$ao
2131 a.exe) mkshexe=$tfn.exe ;;
2135 *\ *) mkshshebang="#!./$mkshexe" ;;
2136 *) mkshshebang="#!$curdir/$mkshexe" ;;
2140 LC_ALL=C PATH='$PATH'; export LC_ALL PATH
2141 test -n "\$KSH_VERSION" || exit 1
2142 set -A check_categories -- $check_categories
2143 pflag='$curdir/$mkshexe'
2144 sflag='$srcdir/check.t'
2145 usee=0 Pflag=0 Sflag=0 uset=0 vflag=1 xflag=0
2146 while getopts "C:e:fPp:QSs:t:v" ch; do case \$ch {
2147 (C) check_categories[\${#check_categories[*]}]=\$OPTARG ;;
2148 (e) usee=1; eflag=\$OPTARG ;;
2149 (f) check_categories[\${#check_categories[*]}]=fastbox ;;
2152 (p) pflag=\$OPTARG ;;
2157 (s) sflag=\$OPTARG ;;
2158 (t) uset=1; tflag=\$OPTARG ;;
2164 shift \$((OPTIND - 1))
2165 set -A args -- '$srcdir/check.pl' -p "\$pflag"
2167 for y in "\${check_categories[@]}"; do
2170 if [[ -n \$x ]]; then
2171 args[\${#args[*]}]=-C
2172 args[\${#args[*]}]=\${x#,}
2175 args[\${#args[*]}]=-e
2176 args[\${#args[*]}]=\$eflag
2178 (( Pflag )) && args[\${#args[*]}]=-P
2180 args[\${#args[*]}]=-t
2181 args[\${#args[*]}]=\$tflag
2183 (( vflag )) && args[\${#args[*]}]=-v
2184 (( xflag )) && args[\${#args[*]}]=-x # force usage by synerr
2185 print Testing mksh for conformance:
2186 fgrep -e MirOS: -e MIRBSD "\$sflag"
2187 print "This shell is actually:\\n\\t\$KSH_VERSION"
2188 print 'test.sh built for mksh $dstversion'
2189 cstr='\$os = defined \$^O ? \$^O : "unknown";'
2190 cstr="\$cstr"'print \$os . ", Perl version " . \$];'
2191 for perli in \$PERL perl5 perl no; do
2192 if [[ \$perli = no ]]; then
2193 print Cannot find a working Perl interpreter, aborting.
2196 print "Trying Perl interpreter '\$perli'..."
2197 perlos=\$(\$perli -e "\$cstr")
2199 print "Errorlevel \$rv, running on '\$perlos'"
2201 print "=> not using"
2204 if [[ -n \$perlos ]]; then
2209 (( Sflag )) || echo + \$perli "\${args[@]}" -s "\$sflag" "\$@"
2210 (( Sflag )) || exec \$perli "\${args[@]}" -s "\$sflag" "\$@"$tsts
2211 # use of the -S option for check.t split into multiple chunks
2213 for s in "\$sflag".*; do
2214 echo + \$perli "\${args[@]}" -s "\$s" "\$@"
2215 \$perli "\${args[@]}" -s "\$s" "\$@"$tsts
2217 (( rv = rv ? rv : rc ))
2222 if test $cm = llvm; then
2223 emitbc="-emit-llvm -c"
2224 elif test $cm = dragonegg; then
2229 echo ": # work around NeXTstep bug" >Rebuild.sh
2230 echo set -x >>Rebuild.sh
2231 for file in $SRCS; do
2232 op=`echo x"$file" | sed 's/^x\(.*\)\.c$/\1./'`
2233 test -f $file || file=$srcdir/$file
2234 files="$files$sp$file"
2236 echo "$CC $CFLAGS $CPPFLAGS $emitbc $file || exit 1" >>Rebuild.sh
2237 if test $cm = dragonegg; then
2238 echo "mv ${op}s ${op}ll" >>Rebuild.sh
2239 echo "llvm-as ${op}ll || exit 1" >>Rebuild.sh
2240 objs="$objs$sp${op}bc"
2242 objs="$objs$sp${op}o"
2247 echo "rm -f $tfn.s" >>Rebuild.sh
2248 echo "llvm-link -o - $objs | opt $optflags | llc -o $tfn.s" >>Rebuild.sh
2255 echo tcfn=$mkshexe >>Rebuild.sh
2256 echo "$CC $CFLAGS $LDFLAGS -o \$tcfn $lobjs $LIBS $ccpr" >>Rebuild.sh
2257 echo 'test -f $tcfn || exit 1; size $tcfn' >>Rebuild.sh
2258 if test $cm = makefile; then
2259 extras='emacsfn.h sh.h sh_flags.h var_spec.h'
2260 test 0 = $HAVE_SYS_SIGNAME && extras="$extras signames.inc"
2261 cat >Makefrag.inc <<EOF
2262 # Makefile fragment for building mksh $dstversion
2270 NONSRCS_INST= dot.mkshrc \$(MAN)
2271 NONSRCS_NOINST= Build.sh Makefile Rebuild.sh check.pl check.t test.sh
2278 # not BSD make only:
2281 #\$(PROG): \$(OBJS_BP)
2282 # \$(CC) \$(CFLAGS) \$(LDFLAGS) -o \$@ \$(OBJS_BP) \$(LIBS)
2283 #\$(OBJS_BP): \$(SRCS_FP) \$(NONSRCS)
2285 # \$(CC) \$(CFLAGS) \$(CPPFLAGS) -c \$<
2287 # for all make variants:
2290 # ./test.sh \$(REGRESS_FLAGS)
2291 check_categories=$check_categories
2293 # for BSD make only:
2295 #.include <bsd.prog.mk>
2298 $e Generated Makefrag.inc successfully.
2301 if test $cm = combine; then
2303 for file in $SRCS; do
2304 test -f $file || file=$srcdir/$file
2307 emitbc="-fwhole-program --combine"
2308 v "$CC $CFLAGS $CPPFLAGS $LDFLAGS $emitbc $objs $LIBS $ccpr"
2309 elif test 1 = $pm; then
2310 for file in $SRCS; do
2311 test -f $file || file=$srcdir/$file
2312 v "$CC $CFLAGS $CPPFLAGS $emitbc $file" &
2316 for file in $SRCS; do
2317 test $cm = dragonegg && \
2318 op=`echo x"$file" | sed 's/^x\(.*\)\.c$/\1./'`
2319 test -f $file || file=$srcdir/$file
2320 v "$CC $CFLAGS $CPPFLAGS $emitbc $file" || exit 1
2321 if test $cm = dragonegg; then
2322 v "mv ${op}s ${op}ll"
2323 v "llvm-as ${op}ll" || exit 1
2330 v "llvm-link -o - $objs | opt $optflags | llc -o $tfn.s"
2334 test $cm = combine || v "$CC $CFLAGS $LDFLAGS -o $tcfn $lobjs $LIBS $ccpr"
2335 test -f $tcfn || exit 1
2336 test 1 = $r || v "$NROFF -mdoc <'$srcdir/mksh.1' >$tfn.cat1" || \
2338 test 0 = $eq && v size $tcfn
2340 test -f /usr/ucb/$i && i=/usr/ucb/$i
2343 $e Installing the shell:
2344 $e "# $i -c -s -o root -g bin -m 555 $tfn /bin/$tfn"
2345 $e "# grep -x /bin/$tfn /etc/shells >/dev/null || echo /bin/$tfn >>/etc/shells"
2346 $e "# $i -c -o root -g bin -m 444 dot.mkshrc /usr/share/doc/mksh/examples/"
2348 $e Installing the manual:
2349 if test -f $tfn.cat1; then
2350 $e "# $i -c -o root -g bin -m 444 $tfn.cat1" \
2351 "/usr/share/man/cat1/$tfn.0"
2354 $e "# $i -c -o root -g bin -m 444 mksh.1 /usr/share/man/man1/$tfn.1"
2356 $e Run the regression test suite: ./test.sh
2357 $e Please also read the sample file dot.mkshrc and the fine manual.
2362 === Environment used ===
2364 ==== build environment ====
2367 CFLAGS if empty, defaults to -xO2 or +O2
2368 or -O3 -qstrict or -O2, per compiler
2369 CPPFLAGS default empty
2370 LDFLAGS default empty; added before sources
2371 LDSTATIC set this to '-static'; default unset
2372 LIBS default empty; added after sources
2373 [Interix] default: -lcrypt (XXX still needed?)
2374 NOWARN -Wno-error or similar
2375 NROFF default: nroff
2376 TARGET_OS default: $(uname -s || uname)
2377 TARGET_OSREV [QNX] default: $(uname -r)
2379 ==== feature selectors ====
2380 USE_PRINTF_BUILTIN 1 to include (unsupported) printf(1) as builtin
2381 ===== general format =====
2383 HAVE_STRING_H ac_header
2384 HAVE_CAN_FSTACKPROTECTORALL ac_flags
2386 ==== cpp definitions ====
2387 DEBUG dont use in production, wants gcc, implies:
2388 DEBUG_LEAKS enable freeing resources before exiting
2389 MKSHRC_PATH "~/.mkshrc" (do not change)
2390 MKSH_A4PB force use of arc4random_pushb
2391 MKSH_ASSUME_UTF8 (0=disabled, 1=enabled; default: unset)
2392 MKSH_BINSHREDUCED if */sh or */-sh, enable set -o sh
2393 MKSH_CLRTOEOL_STRING "\033[K"
2394 MKSH_CLS_STRING "\033[;H\033[J"
2395 MKSH_CONSERVATIVE_FDS fd 0-9 for scripts, shell only up to 31
2396 MKSH_DEFAULT_EXECSHELL "/bin/sh" (do not change)
2397 MKSH_DEFAULT_PROFILEDIR "/etc" (do not change)
2398 MKSH_DEFAULT_TMPDIR "/tmp" (do not change)
2399 MKSH_DISABLE_DEPRECATED disable code paths scheduled for later removal
2400 MKSH_DISABLE_EXPERIMENTAL disable code not yet comfy for (LTS) snapshots
2401 MKSH_DISABLE_TTY_WARNING shut up warning about ctty if OS cant be fixed
2402 MKSH_DONT_EMIT_IDSTRING omit RCS IDs from binary
2403 MKSH_GCC55009 DANGER! see http://www.mirbsd.org/mksh.htm#p41
2404 MKSH_MIDNIGHTBSD01ASH_COMPAT set -o sh: additional compatibility quirk
2405 MKSH_NOPROSPECTOFWORK disable jobs, co-processes, etc. (do not use)
2406 MKSH_NOPWNAM skip PAM calls, for -static on eglibc, Solaris
2407 MKSH_NO_CMDLINE_EDITING disable command line editing code entirely
2408 MKSH_NO_DEPRECATED_WARNING omit warning when deprecated stuff is run
2409 MKSH_NO_EXTERNAL_CAT omit hack to skip cat builtin when flags passed
2410 MKSH_NO_LIMITS omit ulimit code
2411 MKSH_NO_SIGSETJMP define if sigsetjmp is broken or not available
2412 MKSH_NO_SIGSUSPEND use sigprocmask+pause instead of sigsuspend
2413 MKSH_SMALL omit some code, optimise hard for size (slower)
2414 MKSH_SMALL_BUT_FAST disable some hard-for-size optim. (modern sys.)
2415 MKSH_S_NOVI=1 disable Vi editing mode (default if MKSH_SMALL)
2416 MKSH_TYPEDEF_SIG_ATOMIC_T define to e.g. 'int' if sig_atomic_t is missing
2417 MKSH_TYPEDEF_SSIZE_T define to e.g. 'long' if your OS has no ssize_t
2418 MKSH_UNEMPLOYED disable job control (but not jobs/co-processes)
2420 === generic installation instructions ===
2422 Set CC and possibly CFLAGS, CPPFLAGS, LDFLAGS, LIBS. If cross-compiling,
2423 also set TARGET_OS. To disable tests, set e.g. HAVE_STRLCPY=0; to enable
2424 them, set to a value other than 0 or 1. Ensure /bin/ed is installed. For
2425 MKSH_SMALL but with Vi mode, add -DMKSH_S_NOVI=0 to CPPFLAGS as well.
2427 Normally, the following command is what you want to run, then:
2428 $ (sh Build.sh -r -c lto && ./test.sh -f) 2>&1 | tee log
2430 Copy dot.mkshrc to /etc/skel/.mkshrc; install mksh into $prefix/bin; or
2431 /bin; install the manpage, if omitting the -r flag a catmanpage is made
2432 using $NROFF. Consider using a forward script as /etc/skel/.mkshrc like
2433 https://www.mirbsd.org/cvs.cgi/contrib/hosted/tg/deb/mksh/debian/.mkshrc?rev=HEAD
2434 and put dot.mkshrc as /etc/mkshrc so users need not keep up their HOME.