2 srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.488 2011/10/07 19:51:41 tg Exp $'
4 # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
5 # Thorsten Glaser <tg@mirbsd.org>
7 # Provided that these terms and disclaimer and all copyright notices
8 # are retained or reproduced in an accompanying document, permission
9 # is granted to deal in this work without restriction, including un-
10 # limited rights to use, publicly perform, distribute, sell, modify,
11 # merge, give away, or sublicence.
13 # This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
14 # the utmost extent permitted by applicable law, neither express nor
15 # implied; without malicious intent or gross negligence. In no event
16 # may a licensor, author or contributor be held liable for indirect,
17 # direct, other damage, loss, or other issues arising in any way out
18 # of dealing in the work, even if advised of the possibility of such
19 # damage or existence of a defect, except proven that it results out
20 # of said person's immediate fault when using the work as intended.
22 # People analysing the output must whitelist conftest.c for any kind
23 # of compiler warning checks (mirtoconf is by design not quiet).
25 # Environment used: CC CFLAGS CPPFLAGS LDFLAGS LIBS NOWARN NROFF
26 # TARGET_OS TARGET_OSREV
27 # Feature selectors: USE_PRINTF_BUILTIN
28 # CPPFLAGS recognised: MKSH_ASSUME_UTF8 MKSH_BINSHREDUCED MKSH_CLS_STRING
29 # MKSH_CONSERVATIVE_FDS MKSH_MIDNIGHTBSD01ASH_COMPAT
30 # MKSH_NOPWNAM MKSH_NO_LIMITS MKSH_SMALL MKSH_S_NOVI
31 # MKSH_UNEMPLOYED MKSH_DEFAULT_EXECSHELL MKSHRC_PATH
32 # MKSH_DEFAULT_TMPDIR MKSH_CLRTOEOL_STRING MKSH_A4PB
33 # MKSH_NO_DEPRECATED_WARNING MKSH_DONT_EMIT_IDSTRING
34 # MKSH_NOPROSPECTOFWORK MKSH_NO_EXTERNAL_CAT
48 eval "$@" >vv.out 2>&1
49 sed "s
\a^
\a${_c}
\a" <vv.out
65 if test -d /usr/xpg4/bin/. >/dev/null 2>&1; then
66 # Solaris: some of the tools have weird behaviour, use portable ones
67 PATH=/usr/xpg4/bin:$PATH
71 if test -n "${ZSH_VERSION+x}" && (emulate sh) >/dev/null 2>&1; then
76 allu=QWERTYUIOPASDFGHJKLZXCVBNM
77 alll=qwertyuiopasdfghjklzxcvbnm
79 alls=______________________________________________________________
90 oldish_ed=stdout-ed,no-stderr-ed
99 echo :"$@" | sed 's/^://' | tr $alll $allu
102 # clean up after ac_testrun()
106 test 0 = $fv || fr=yes
107 $e "$bi==> $fd...$ao $ui$fr$ao$fx"
111 # ac_cache label: sets f, fu, fv?=0
126 # ac_testinit label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput
127 # returns 1 if value was cached/implied, 0 otherwise: call ac_testdone
130 test x"$2" = x"!" && shift
131 test x"$2" = x"" || shift
137 if test x"$2" = x""; then
140 if test x"$2" = x"!"; then
144 eval ft=\$HAVE_`upper $2`
148 if test $fc = "$ft"; then
158 # pipe .c | ac_test[n] [!] label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput
160 if test x"$1" = x"!"; then
166 ac_testinit "$@" || return
168 vv ']' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN conftest.c $LIBS $ccpr"
169 test $tcfn = no && test -f a.out && tcfn=a.out
170 test $tcfn = no && test -f a.exe && tcfn=a.exe
171 test $tcfn = no && test -f conftest && tcfn=conftest
172 if test -f $tcfn; then
178 if test $phase = u; then
179 test $ct = gcc && vscan='unrecogni[sz]ed'
180 test $ct = hpcc && vscan='unsupported'
181 test $ct = pcc && vscan='unsupported'
182 test $ct = sunpro && vscan='-e ignored -e turned.off'
184 test -n "$vscan" && grep $vscan vv.out >/dev/null 2>&1 && fv=$fr
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`
272 echo "#include <$i>" >>x
274 echo "#include <$hf>" >>x
275 echo 'int main(void) { return (0); }' >>x
276 ac_testn "$hv" "" "<$hf>" <x
278 test 1 = $na || ac_cppflags
282 if test x"$1" = x"!"; then
289 test $fr = "$i" && case " $SRCS " in
291 *) SRCS="$SRCS $2" ;;
296 if test -d mksh || test -d mksh.exe; then
297 echo "$me: Error: ./mksh is a directory!" >&2
300 rmf a.exe* a.out* conftest.c *core lft mksh* no *.bc *.ll *.o \
301 Rebuild.sh signames.inc test.sh x vv.out
303 curdir=`pwd` srcdir=`dirname "$0"` check_categories=
304 test -n "$srcdir" || srcdir=.
305 dstversion=`sed -n '/define MKSH_VERSION/s/^.*"\(.*\)".*$/\1/p' $srcdir/sh.h`
312 optflags=-std-compile-opts
318 c:combine|c:dragonegg|c:llvm|c:lto)
323 echo "$me: Unknown option -c '$i'!" >&2
334 # checker, debug, valgrind build
336 CFLAGS="$CFLAGS -g3 -fno-builtin"
345 optflags=-std-compile-opts
357 echo "Build.sh $srcversion"
358 echo "for mksh $dstversion"
362 echo "$me: Unknown option '$i'!" >&2
366 echo "$me: Unknown option -'$last' '$i'!" >&2
371 if test -n "$last"; then
372 echo "$me: Option -'$last' not followed by argument!" >&2
376 SRCS="lalloc.c edit.c eval.c exec.c expr.c funcs.c histrap.c"
377 SRCS="$SRCS jobs.c lex.c main.c misc.c shf.c syn.c tree.c var.c"
379 if test x"$srcdir" = x"."; then
380 CPPFLAGS="-I. $CPPFLAGS"
382 CPPFLAGS="-I. -I'$srcdir' $CPPFLAGS"
385 test x"$TARGET_OS" = x"" && TARGET_OS=`uname -s 2>/dev/null || uname`
386 if test x"$TARGET_OS" = x""; then
387 echo "$me: Set TARGET_OS, your uname is broken!" >&2
394 ccpr='|| for _f in ${tcfn}*; do test x"${_f}" = x"mksh.1" || rm -f "${_f}"; done'
397 if test x"$TARGET_OS" = x"Android"; then
398 check_categories="$check_categories android"
402 # Configuration depending on OS revision, on OSes that need them
405 test x"$TARGET_OSREV" = x"" && TARGET_OSREV=`uname -r`
409 # Configuration depending on OS name
412 add_cppflags -D_ALL_SOURCE
413 : ${HAVE_SETLOCALE_CTYPE=0}
416 oswarn=' and will currently not work'
419 : ${HAVE_SETLOCALE_CTYPE=0}
422 : ${HAVE_SETLOCALE_CTYPE=0}
431 oswarn="; it has minor issues"
432 add_cppflags -D_GNU_SOURCE
433 : ${HAVE_SETLOCALE_CTYPE=0}
438 *) add_cppflags -D_GNU_SOURCE ;;
440 # define NO_PATH_MAX to use Hurd-only functions
441 add_cppflags -DNO_PATH_MAX
446 *) add_cppflags -D_GNU_SOURCE ;;
450 add_cppflags -DMKSH_ASSUME_UTF8
457 add_cppflags -D_ALL_SOURCE
459 : ${HAVE_SETLOCALE_CTYPE=0}
462 : ${HAVE_SETLOCALE_CTYPE=0}
467 *) add_cppflags -D_GNU_SOURCE ;;
469 add_cppflags -DSETUID_CAN_FAIL_WITH_EAGAIN
475 add_cppflags -DMKSH_UNEMPLOYED
476 add_cppflags -DMKSH_CONSERVATIVE_FDS
477 add_cppflags -DMKSH_NO_LIMITS
478 add_cppflags -D_POSIX_SOURCE -D_POSIX_1_SOURCE=2 -D_MINIX
479 oldish_ed=no-stderr-ed # /usr/bin/ed(!) is broken
480 : ${HAVE_SETLOCALE_CTYPE=0}
485 # probably same as CYGWIN* – need to test; from RT|Chatzilla
486 oswarn='but will probably work'
491 : ${HAVE_SETLOCALE_CTYPE=0}
494 HAVE_SIG_T=0 # incompatible
495 add_cppflags -D_OSF_SOURCE
496 add_cppflags -D_POSIX_C_SOURCE=200112L
497 add_cppflags -D_XOPEN_SOURCE=600
498 add_cppflags -D_XOPEN_SOURCE_EXTENDED
499 : ${HAVE_SETLOCALE_CTYPE=0}
502 add_cppflags -D_POSIX_SOURCE
503 add_cppflags -D_LIMITS_EXTENSION
504 add_cppflags -D_BSD_EXTENSION
505 add_cppflags -D_SUSV2_SOURCE
506 add_cppflags -DMKSH_ASSUME_UTF8
507 oswarn=' and will currently not work'
508 add_cppflags -DMKSH_UNEMPLOYED
511 HAVE_SIG_T=0 # incompatible
512 oswarn=' and will currently not work'
513 : ${HAVE_SETLOCALE_CTYPE=0}
516 add_cppflags -D__NO_EXT_QNX
517 case $TARGET_OSREV in
518 [012345].*|6.[0123].*|6.4.[01])
519 oldish_ed=no-stderr-ed # oldish /bin/ed is broken
522 : ${HAVE_SETLOCALE_CTYPE=0}
525 add_cppflags -D_BSD_SOURCE
526 add_cppflags -D__EXTENSIONS__
529 add_cppflags -D_GNU_SOURCE
530 oswarn=' and will currently not work'
534 add_cppflags -Dssize_t=int
535 : ${HAVE_SETLOCALE_CTYPE=0}
541 oswarn="; it will compile, but the target"
542 oswarn="$oswarn${nl}platform itself is very flakey/unreliable"
543 : ${HAVE_SETLOCALE_CTYPE=0}
546 oswarn='; it may or may not work'
552 : ${CC=cc} ${NROFF=nroff}
553 test 0 = $r && echo | $NROFF -v 2>&1 | grep GNU >/dev/null 2>&1 && \
556 # this aids me in tracing FTBFSen without access to the buildd
557 $e "Hi from$ao $bi$srcversion$ao on:"
561 vv '|' "uname -a >&2"
564 vv '|' "hwprefs machine_type os_type os_class >&2"
565 vv '|' "uname -a >&2"
568 vv '|' "uname -a >&2"
572 vv '|' "uname -a >&2"
573 vv '|' "/usr/sbin/sizer -v >&2"
576 vv '|' "uname -a >&2"
579 test -z "$oswarn" || echo >&2 "
580 Warning: mksh has not yet been ported to or tested on your
581 operating system '$TARGET_OS'$oswarn. If you can provide
582 a shell account to the developer, this may improve; please
583 drop us a success or failure notice or even send in diffs.
585 $e "$bi$me: Building the MirBSD Korn Shell$ao $ui$dstversion$ao"
588 # Begin of mirtoconf checks
590 $e $bi$me: Scanning for functions... please ignore any errors.$ao
593 # Compiler: which one?
596 # - ICC defines __GNUC__ too
597 # - GCC defines __hpux too
598 # - LLVM+clang defines __GNUC__ too
599 # - nwcc defines __GNUC__ too
601 $e ... which compiler seems to be used
602 cat >conftest.c <<'EOF'
603 #if defined(__ICC) || defined(__INTEL_COMPILER)
605 #elif defined(__xlC__) || defined(__IBMC__)
607 #elif defined(__SUNPRO_C)
609 #elif defined(__ACK__)
611 #elif defined(__BORLANDC__)
613 #elif defined(__WATCOMC__)
615 #elif defined(__MWERKS__)
617 #elif defined(__HP_cc)
619 #elif defined(__DECC) || (defined(__osf__) && !defined(__GNUC__))
623 #elif defined(__DMC__)
625 #elif defined(_MSC_VER)
627 #elif defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__)
629 #elif defined(__IAR_SYSTEMS_ICC__)
633 #elif defined(__PCC__)
635 #elif defined(__TenDRA__)
637 #elif defined(__TINYC__)
639 #elif defined(__llvm__) && defined(__clang__)
641 #elif defined(__NWCC__)
643 #elif defined(__GNUC__)
645 #elif defined(_COMPILER_VERSION)
649 #elif defined(__hpux) || defined(__hpua)
651 #elif defined(__ultrix)
658 vv ']' "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c | grep ct= | tr -d \\\\015 >x"
662 echo 'int main(void) { return (0); }' >conftest.c
665 # work around "the famous ACK const bug"
666 CPPFLAGS="-Dconst= $CPPFLAGS"
669 echo >&2 'Warning: Analog Devices C++ compiler for Blackfin, TigerSHARC
670 and SHARC (21000) DSPs detected. This compiler has not yet
671 been tested for compatibility with mksh. Continue at your
672 own risk, please report success/failure to the developers.'
675 echo >&2 "Warning: Borland C++ Builder detected. This compiler might
676 produce broken executables. Continue at your own risk,
677 please report success/failure to the developers."
680 # does not work with current "ccc" compiler driver
681 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -version"
682 # this works, for now
683 vv '|' "${CLANG-clang} -version"
684 # ensure compiler and linker are in sync unless overridden
685 case $CCC_CC:$CCC_LD in
687 *:) CCC_LD=$CCC_CC; export CCC_LD ;;
691 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V"
692 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -Wl,-V conftest.c $LIBS"
695 echo >&2 "Warning: Digital Mars Compiler detected. When running under"
696 echo >&2 " UWIN, mksh tends to be unstable due to the limitations"
697 echo >&2 " of this platform. Continue at your own risk,"
698 echo >&2 " please report success/failure to the developers."
701 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS"
702 vv '|' 'echo `$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS \
703 -dumpmachine` gcc`$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN \
707 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
710 echo >&2 'Warning: IAR Systems (http://www.iar.com) compiler for embedded
711 systems detected. This unsupported compiler has not yet
712 been tested for compatibility with mksh. Continue at your
713 own risk, please report success/failure to the developers.'
716 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V"
719 echo >&2 'Warning: Metrowerks C compiler detected. This has not yet
720 been tested for compatibility with mksh. Continue at your
721 own risk, please report success/failure to the developers.'
724 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -version"
727 ccpr= # errorlevels are not reliable
730 if [[ -n $C89_COMPILER ]]; then
731 C89_COMPILER=`ntpath2posix -c "$C89_COMPILER"`
735 if [[ -n $C89_LINKER ]]; then
736 C89_LINKER=`ntpath2posix -c "$C89_LINKER"`
740 vv '|' "$C89_COMPILER /HELP >&2"
741 vv '|' "$C89_LINKER /LINK >&2"
746 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -version"
749 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -v"
752 echo >&2 'Warning: PGI detected. This unknown compiler has not yet
753 been tested for compatibility with mksh. Continue at your
754 own risk, please report success/failure to the developers.'
757 echo >&2 'Warning: sdcc (http://sdcc.sourceforge.net), the small devices
758 C compiler for embedded systems detected. This has not yet
759 been tested for compatibility with mksh. Continue at your
760 own risk, please report success/failure to the developers.'
763 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
766 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -v"
769 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V 2>&1 | \
770 fgrep -i -e version -e release"
773 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V"
774 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -Wl,-V conftest.c $LIBS"
777 echo >&2 'Warning: Watcom C Compiler detected. This compiler has not yet
778 been tested for compatibility with mksh. Continue at your
779 own risk, please report success/failure to the developers.'
782 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -qversion"
783 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -qversion=verbose"
792 vv '|' "llc -version"
795 $e "$bi==> which compiler seems to be used...$ao $ui$ct$ao"
796 rmf conftest.c conftest.o conftest a.out* a.exe* vv.out
799 # Compiler: works as-is, with -Wno-error and -Werror
804 ac_flags 0 compiler_works '' 'if the compiler works'
805 test 1 = $HAVE_CAN_COMPILER_WORKS || exit 1
806 HAVE_COMPILER_KNOWN=0
807 test $ct = unknown || HAVE_COMPILER_KNOWN=1
808 if ac_ifcpp 'if 0' compiler_fails '' \
809 'if the compiler does not fail correctly'; then
811 : ${HAVE_CAN_DELEXE=x}
812 if test $ct = dmc; then
813 CFLAGS="$CFLAGS ${ccpl}/DELEXECUTABLE"
814 ac_testn can_delexe compiler_fails 0 'for the /DELEXECUTABLE linker option' <<-EOF
815 int main(void) { return (0); }
817 elif test $ct = dec; then
818 CFLAGS="$CFLAGS ${ccpl}-non_shared"
819 ac_testn can_delexe compiler_fails 0 'for the -non_shared linker option' <<-EOF
820 int main(void) { return (0); }
825 test 1 = $HAVE_CAN_DELEXE || CFLAGS=$save_CFLAGS
826 ac_testn compiler_still_fails '' 'if the compiler still does not fail correctly' <<-EOF
828 test 1 = $HAVE_COMPILER_STILL_FAILS && exit 1
830 if ac_ifcpp 'ifdef __TINYC__' couldbe_tcc '!' compiler_known 0 \
831 'if this could be tcc'; then
833 CPP='cpp -D__TINYC__'
836 if test $ct = sunpro; then
837 test x"$save_NOWARN" = x"" && save_NOWARN='-errwarn=%none'
838 ac_flags 0 errwarnnone "$save_NOWARN"
839 test 1 = $HAVE_CAN_ERRWARNNONE || save_NOWARN=
840 ac_flags 0 errwarnall "-errwarn=%all"
841 test 1 = $HAVE_CAN_ERRWARNALL && DOWARN="-errwarn=%all"
842 elif test $ct = hpcc; then
845 elif test $ct = mipspro; then
847 DOWARN="-diag_error 1-10000"
848 elif test $ct = msc; then
849 save_NOWARN="${ccpc}/w"
851 elif test $ct = dmc; then
852 save_NOWARN="${ccpc}-w"
854 elif test $ct = bcc; then
855 save_NOWARN="${ccpc}-w"
857 elif test $ct = dec; then
858 : -msg_* flags not used yet, or is -w2 correct?
859 elif test $ct = xlc; then
860 save_NOWARN=-qflag=i:e
862 elif test $ct = tendra; then
864 elif test $ct = ucode; then
868 test x"$save_NOWARN" = x"" && save_NOWARN=-Wno-error
869 ac_flags 0 wnoerror "$save_NOWARN"
870 test 1 = $HAVE_CAN_WNOERROR || save_NOWARN=
871 ac_flags 0 werror -Werror
872 test 1 = $HAVE_CAN_WERROR && DOWARN=-Werror
875 test $ct = icc && DOWARN="$DOWARN -wd1419"
879 # Compiler: extra flags (-O2 -f* -W* etc.)
881 i=`echo :"$orig_CFLAGS" | sed 's/^://' | tr -c -d $alll$allu$alln`
882 # optimisation: only if orig_CFLAGS is empty
883 test x"$i" = x"" && if test $ct = sunpro; then
885 int main(void) { return (0); }
886 #define __IDSTRING_CONCAT(l,p) __LINTED__ ## l ## _ ## p
887 #define __IDSTRING_EXPAND(l,p) __IDSTRING_CONCAT(l,p)
888 #define pad void __IDSTRING_EXPAND(__LINE__,x)(void) { }
890 yes pad | head -n 256 >>x
891 ac_flags - 1 otwo -xO2 <x
893 elif test $ct = hpcc; then
897 elif test $ct = xlc; then
898 ac_flags 1 othree "-O3 -qstrict"
899 test 1 = $HAVE_CAN_OTHREE || ac_flags 1 otwo -O2
900 elif test $ct = tcc || test $ct = tendra; then
901 : no special optimisation
904 test 1 = $HAVE_CAN_OTWO || ac_flags 1 optimise -O
906 # other flags: just add them if they are supported
908 if test $ct = gcc; then
909 # The following tests run with -Werror (gcc only) if possible
910 NOWARN=$DOWARN; phase=u
911 ac_flags 1 fnostrictaliasing -fno-strict-aliasing
912 ac_flags 1 fstackprotectorall -fstack-protector-all
913 ac_flags 1 fwrapv -fwrapv
914 test $cm = dragonegg && case " $CC $CFLAGS $LDFLAGS " in
915 *\ -fplugin=*dragonegg*) ;;
916 *) ac_flags 1 fplugin_dragonegg -fplugin=dragonegg ;;
918 if test $cm = lto; then
920 checks='1 2 3 4 5 6 7 8'
921 elif test $cm = combine; then
927 test $fv = 1 || for what in $checks; do
928 test $fv = 1 && break
930 1) t_cflags='-flto=jobserver'
931 t_ldflags='-fuse-linker-plugin'
932 t_use=1 t_name=fltojs_lp ;;
933 2) t_cflags='-flto=jobserver' t_ldflags=''
934 t_use=1 t_name=fltojs_nn ;;
935 3) t_cflags='-flto=jobserver'
936 t_ldflags='-fno-use-linker-plugin -fwhole-program'
937 t_use=1 t_name=fltojs_np ;;
939 t_ldflags='-fuse-linker-plugin'
940 t_use=1 t_name=fltons_lp ;;
941 5) t_cflags='-flto' t_ldflags=''
942 t_use=1 t_name=fltons_nn ;;
944 t_ldflags='-fno-use-linker-plugin -fwhole-program'
945 t_use=1 t_name=fltons_np ;;
946 7) t_cflags='-fwhole-program --combine' t_ldflags=''
947 t_use=0 t_name=combine cm=combine ;;
950 test $fv = 1 && break
951 ac_flags $t_use $t_name "$t_cflags" \
952 "if gcc supports $t_cflags $t_ldflags" "$t_ldflags"
955 elif test $ct = icc; then
956 ac_flags 1 fnobuiltinsetmode -fno-builtin-setmode
957 ac_flags 1 fnostrictaliasing -fno-strict-aliasing
958 ac_flags 1 fstacksecuritycheck -fstack-security-check
960 elif test $ct = sunpro; then
963 ac_flags 1 xc99 -xc99 'for support of ISO C99'
964 ac_flags 1 ipo -xipo 'for cross-module optimisation'
966 elif test $ct = hpcc; then
968 ac_flags 1 agcc -Agcc 'for support of GCC extensions'
969 ac_flags 1 ac99 -AC99 'for support of ISO C99'
971 elif test $ct = dec; then
972 ac_flags 0 verb -verbose
973 ac_flags 1 rodata -readonly_strings
974 elif test $ct = dmc; then
975 ac_flags 1 decl "${ccpc}-r" 'for strict prototype checks'
976 ac_flags 1 schk "${ccpc}-s" 'for stack overflow checking'
977 elif test $ct = bcc; then
978 ac_flags 1 strpool "${ccpc}-d" 'if string pooling can be enabled'
979 elif test $ct = mipspro; then
980 ac_flags 1 xc99 -c99 'for support of ISO C99'
981 ac_flags 1 fullwarn -fullwarn 'for remark output support'
982 elif test $ct = msc; then
983 ac_flags 1 strpool "${ccpc}/GF" 'if string pooling can be enabled'
984 echo 'int main(void) { char test[64] = ""; return (*test); }' >x
985 ac_flags - 1 stackon "${ccpc}/GZ" 'if stack checks can be enabled' <x
986 ac_flags - 1 stckall "${ccpc}/Ge" 'stack checks for all functions' <x
987 ac_flags - 1 secuchk "${ccpc}/GS" 'for compiler security checks' <x
989 ac_flags 1 wall "${ccpc}/Wall" 'to enable all warnings'
990 ac_flags 1 wp64 "${ccpc}/Wp64" 'to enable 64-bit warnings'
991 elif test $ct = xlc; then
992 ac_flags 1 x99 -qlanglvl=extc99
993 test 1 = $HAVE_CAN_X99 || ac_flags 1 c99 -qlanglvl=stdc99
994 ac_flags 1 rodata "-qro -qroconst -qroptr"
995 ac_flags 1 rtcheck -qcheck=all
996 ac_flags 1 rtchkc -qextchk
997 ac_flags 1 wformat "-qformat=all -qformat=nozln"
998 #ac_flags 1 wp64 -qwarn64 # too verbose for now
999 elif test $ct = tendra; then
1000 ac_flags 0 ysystem -Ysystem
1001 test 1 = $HAVE_CAN_YSYSTEM && CPPFLAGS="-Ysystem $CPPFLAGS"
1002 ac_flags 1 extansi -Xa
1003 elif test $ct = tcc; then
1004 ac_flags 1 boundschk -b
1005 elif test $ct = clang; then
1007 elif test $ct = nwcc; then
1009 #broken# ac_flags 1 ssp -stackprotect
1011 # flags common to a subset of compilers (run with -Werror on gcc)
1012 if test 1 = $i; then
1013 ac_flags 1 stdg99 -std=gnu99 'for support of ISO C99 + GCC extensions'
1014 test 1 = $HAVE_CAN_STDG99 || \
1015 ac_flags 1 stdc99 -std=c99 'for support of ISO C99'
1016 ac_flags 1 wall -Wall
1020 # The following tests run with -Werror or similar (all compilers) if possible
1022 test $ct = pcc && phase=u
1025 # Compiler: check for stuff that only generates warnings
1027 ac_test attribute_bounded '' 'for __attribute__((__bounded__))' <<-'EOF'
1028 #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
1029 /* force a failure: TenDRA and gcc 1.42 have false positive here */
1030 int main(void) { return (thiswillneverbedefinedIhope()); }
1033 #undef __attribute__
1034 int xcopy(const void *, void *, size_t)
1035 __attribute__((__bounded__ (__buffer__, 1, 3)))
1036 __attribute__((__bounded__ (__buffer__, 2, 3)));
1037 int main(int ac, char *av[]) { return (xcopy(av[0], av[--ac], 1)); }
1038 int xcopy(const void *s, void *d, size_t n) {
1039 memmove(d, s, n); return ((int)n);
1043 ac_test attribute_format '' 'for __attribute__((__format__))' <<-'EOF'
1044 #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
1045 /* force a failure: TenDRA and gcc 1.42 have false positive here */
1046 int main(void) { return (thiswillneverbedefinedIhope()); }
1048 #define fprintf printfoo
1050 #undef __attribute__
1052 extern int fprintf(FILE *, const char *format, ...)
1053 __attribute__((__format__ (__printf__, 2, 3)));
1054 int main(int ac, char **av) { return (fprintf(stderr, "%s%d", *av, ac)); }
1057 ac_test attribute_nonnull '' 'for __attribute__((__nonnull__))' <<-'EOF'
1058 #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
1059 /* force a failure: TenDRA and gcc 1.42 have false positive here */
1060 int main(void) { return (thiswillneverbedefinedIhope()); }
1062 int foo(char *s1, char *s2) __attribute__((__nonnull__));
1063 int bar(char *s1, char *s2) __attribute__((__nonnull__ (1, 2)));
1064 int baz(char *s) __attribute__((__nonnull__ (1)));
1065 int foo(char *s1, char *s2) { return (bar(s2, s1)); }
1066 int bar(char *s1, char *s2) { return (baz(s1) - baz(s2)); }
1067 int baz(char *s) { return (*s); }
1068 int main(int ac, char **av) { return (ac == foo(av[0], av[ac-1])); }
1071 ac_test attribute_noreturn '' 'for __attribute__((__noreturn__))' <<-'EOF'
1072 #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
1073 /* force a failure: TenDRA and gcc 1.42 have false positive here */
1074 int main(void) { return (thiswillneverbedefinedIhope()); }
1077 #undef __attribute__
1078 void fnord(void) __attribute__((__noreturn__));
1079 int main(void) { fnord(); }
1080 void fnord(void) { exit(0); }
1083 ac_test attribute_unused '' 'for __attribute__((__unused__))' <<-'EOF'
1084 #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
1085 /* force a failure: TenDRA and gcc 1.42 have false positive here */
1086 int main(void) { return (thiswillneverbedefinedIhope()); }
1088 int main(int ac __attribute__((__unused__)), char **av
1089 __attribute__((__unused__))) { return (0); }
1092 ac_test attribute_used '' 'for __attribute__((__used__))' <<-'EOF'
1093 #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
1094 /* force a failure: TenDRA and gcc 1.42 have false positive here */
1095 int main(void) { return (thiswillneverbedefinedIhope()); }
1097 static const char fnord[] __attribute__((__used__)) = "42";
1098 int main(void) { return (0); }
1102 # End of tests run with -Werror
1107 # mksh: flavours (full/small mksh, omit certain stuff)
1109 if ac_ifcpp 'ifdef MKSH_SMALL' isset_MKSH_SMALL '' \
1110 "if a reduced-feature mksh is requested"; then
1111 #XXX this sucks; fix it for *all* compilers
1114 ac_flags 1 fnoinline -fno-inline
1117 NOWARN=$DOWARN; phase=u
1118 ac_flags 1 fnoinline -fno-inline
1119 NOWARN=$save_NOWARN; phase=x
1122 ac_flags 1 fnoinline -xinline=
1125 ac_flags 1 fnoinline -qnoinline
1130 : ${HAVE_PERSISTENT_HISTORY=0}
1131 check_categories="$check_categories smksh"
1132 HAVE_ISSET_MKSH_CONSERVATIVE_FDS=1 # from sh.h
1134 ac_ifcpp 'ifdef MKSH_BINSHREDUCED' isset_MKSH_BINSHREDUCED '' \
1135 "if a reduced-feature sh is requested" && \
1136 check_categories="$check_categories binsh"
1137 ac_ifcpp 'ifdef MKSH_UNEMPLOYED' isset_MKSH_UNEMPLOYED '' \
1138 "if mksh will be built without job control" && \
1139 check_categories="$check_categories arge"
1140 ac_ifcpp 'ifdef MKSH_NOPROSPECTOFWORK' isset_MKSH_NOPROSPECTOFWORK '' \
1141 "if mksh will be built without job signals" && \
1142 check_categories="$check_categories arge nojsig"
1143 ac_ifcpp 'ifdef MKSH_ASSUME_UTF8' isset_MKSH_ASSUME_UTF8 '' \
1144 'if the default UTF-8 mode is specified' && : ${HAVE_SETLOCALE_CTYPE=0}
1145 ac_ifcpp 'ifdef MKSH_CONSERVATIVE_FDS' isset_MKSH_CONSERVATIVE_FDS '' \
1146 'if traditional/conservative fd use is requested' && \
1147 check_categories="$check_categories convfds"
1150 # Environment: headers
1152 ac_header sys/bsdtypes.h
1153 ac_header sys/file.h sys/types.h
1154 ac_header sys/mkdev.h sys/types.h
1155 ac_header sys/mman.h sys/types.h
1156 ac_header sys/param.h
1157 ac_header sys/select.h sys/types.h
1158 ac_header sys/sysmacros.h
1160 ac_header grp.h sys/types.h
1162 ac_header libutil.h sys/types.h
1164 ac_header stdint.h stdarg.h
1165 # include strings.h only if compatible with string.h
1166 ac_header strings.h sys/types.h string.h
1167 ac_header ulimit.h sys/types.h
1171 # check whether whatever we use for the final link will succeed
1173 if test $cm = makefile; then
1177 ac_testinit link_works '' 'checking if the final link command may succeed'
1179 cat >conftest.c <<-'EOF'
1181 #define MKSH_INCLUDES_ONLY
1183 __RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.488 2011/10/07 19:51:41 tg Exp $");
1184 int main(void) { printf("Hello, World!\n"); return (0); }
1188 v "$CC $CFLAGS $CPPFLAGS $NOWARN -emit-llvm -c conftest.c" || fv=0
1190 test $fv = 0 || v "llvm-link -o - conftest.o | opt $optflags | llc -o mksh.s" || fv=0
1191 test $fv = 0 || v "$CC $CFLAGS $LDFLAGS -o $tcfn mksh.s $LIBS $ccpr"
1194 v "$CC $CFLAGS $CPPFLAGS $NOWARN -S -flto conftest.c" || fv=0
1195 test $fv = 0 || v "mv conftest.s conftest.ll"
1196 test $fv = 0 || v "llvm-as conftest.ll" || fv=0
1198 test $fv = 0 || v "llvm-link -o - conftest.bc | opt $optflags | llc -o mksh.s" || fv=0
1199 test $fv = 0 || v "$CC $CFLAGS $LDFLAGS -o $tcfn mksh.s $LIBS $ccpr"
1202 v "$CC $CFLAGS $CPPFLAGS $LDFLAGS -fwhole-program --combine $NOWARN -o $tcfn conftest.c $LIBS $ccpr"
1206 v "$CC $CFLAGS $CPPFLAGS $NOWARN -c conftest.c" || fv=0
1207 test $fv = 0 || v "$CC $CFLAGS $LDFLAGS -o $tcfn conftest.o $LIBS $ccpr"
1210 test -f $tcfn || fv=0
1212 test $fv = 1 || exit 1
1216 # Environment: definitions
1218 echo '#include <sys/types.h>
1219 /* check that off_t can represent 2^63-1 correctly, thx FSF */
1220 #define LARGE_OFF_T (((off_t)1 << 62) - 1 + ((off_t)1 << 62))
1221 int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 &&
1222 LARGE_OFF_T % 2147483647 == 1) ? 1 : -1];
1223 int main(void) { return (0); }' >lft.c
1224 ac_testn can_lfs '' "for large file support" <lft.c
1225 save_CPPFLAGS=$CPPFLAGS
1226 add_cppflags -D_FILE_OFFSET_BITS=64
1227 ac_testn can_lfs_sus '!' can_lfs 0 "... with -D_FILE_OFFSET_BITS=64" <lft.c
1228 if test 0 = $HAVE_CAN_LFS_SUS; then
1229 CPPFLAGS=$save_CPPFLAGS
1230 add_cppflags -D_LARGE_FILES=1
1231 ac_testn can_lfs_aix '!' can_lfs 0 "... with -D_LARGE_FILES=1" <lft.c
1232 test 1 = $HAVE_CAN_LFS_AIX || CPPFLAGS=$save_CPPFLAGS
1234 rmf lft* # end of large file support test
1237 # Environment: types
1239 ac_test can_inttypes '!' stdint_h 1 "for standard 32-bit integer types" <<-'EOF'
1240 #include <sys/types.h>
1242 int main(int ac, char **av) { return ((uint32_t)(ptrdiff_t)*av + (int32_t)ac); }
1244 ac_test can_ucbints '!' can_inttypes 1 "for UCB 32-bit integer types" <<-'EOF'
1245 #include <sys/types.h>
1247 int main(int ac, char **av) { return ((u_int32_t)(ptrdiff_t)*av + (int32_t)ac); }
1249 ac_test can_int8type '!' stdint_h 1 "for standard 8-bit integer type" <<-'EOF'
1250 #include <sys/types.h>
1252 int main(int ac, char **av) { return ((uint8_t)(ptrdiff_t)av[ac]); }
1254 ac_test can_ucbint8 '!' can_int8type 1 "for UCB 8-bit integer type" <<-'EOF'
1255 #include <sys/types.h>
1257 int main(int ac, char **av) { return ((u_int8_t)(ptrdiff_t)av[ac]); }
1260 ac_test rlim_t <<-'EOF'
1261 #include <sys/types.h>
1262 #include <sys/time.h>
1263 #include <sys/resource.h>
1265 int main(void) { return ((int)(rlim_t)0); }
1268 # only testn: added later below
1269 ac_testn sig_t <<-'EOF'
1270 #include <sys/types.h>
1273 int main(void) { return ((int)(ptrdiff_t)(sig_t)(ptrdiff_t)kill(0,0)); }
1276 ac_testn sighandler_t '!' sig_t 0 <<-'EOF'
1277 #include <sys/types.h>
1280 int main(void) { return ((int)(ptrdiff_t)(sighandler_t)(ptrdiff_t)kill(0,0)); }
1282 if test 1 = $HAVE_SIGHANDLER_T; then
1283 add_cppflags -Dsig_t=sighandler_t
1287 ac_testn __sighandler_t '!' sig_t 0 <<-'EOF'
1288 #include <sys/types.h>
1291 int main(void) { return ((int)(ptrdiff_t)(__sighandler_t)(ptrdiff_t)kill(0,0)); }
1293 if test 1 = $HAVE___SIGHANDLER_T; then
1294 add_cppflags -Dsig_t=__sighandler_t
1298 test 1 = $HAVE_SIG_T || add_cppflags -Dsig_t=nosig_t
1302 # Environment: signals
1304 test x"NetBSD" = x"$TARGET_OS" && $e Ignore the compatibility warning.
1306 for what in name list; do
1308 ac_testn sys_sig$what '' "the sys_sig${what}[] array" <<-EOF
1309 extern const char *const sys_sig${what}[];
1310 int main(void) { return (sys_sig${what}[0][0]); }
1312 ac_testn _sys_sig$what '!' sys_sig$what 0 "the _sys_sig${what}[] array" <<-EOF
1313 extern const char *const _sys_sig${what}[];
1314 int main(void) { return (_sys_sig${what}[0][0]); }
1316 eval uwhat_v=\$HAVE__SYS_SIG$uwhat
1317 if test 1 = "$uwhat_v"; then
1318 add_cppflags -Dsys_sig$what=_sys_sig$what
1319 eval HAVE_SYS_SIG$uwhat=1
1321 ac_cppflags SYS_SIG$uwhat
1324 ac_test strsignal '!' sys_siglist 0 <<-'EOF'
1327 int main(void) { return (strsignal(1)[0]); }
1331 # Environment: library functions
1333 ac_testn flock_ex '' 'flock and mmap' <<-'EOF'
1334 #include <sys/types.h>
1336 #include <sys/file.h>
1339 #include <sys/mman.h>
1343 int main(void) { return ((void *)mmap(NULL, (size_t)flock(0, LOCK_EX),
1344 PROT_READ, MAP_PRIVATE, 0, (off_t)0) == (void *)NULL ? 1 :
1348 ac_test getrusage <<-'EOF'
1349 #define MKSH_INCLUDES_ONLY
1353 return (getrusage(RUSAGE_SELF, &ru) +
1354 getrusage(RUSAGE_CHILDREN, &ru));
1358 ac_test killpg <<-'EOF'
1360 int main(int ac, char *av[]) { return (av[0][killpg(123, ac)]); }
1363 ac_test mknod '' 'if to use mknod(), makedev() and friends' <<-'EOF'
1364 #define MKSH_INCLUDES_ONLY
1366 int main(int ac, char *av[]) {
1368 dv = makedev((unsigned int)ac, (unsigned int)av[0][0]);
1369 return (mknod(av[0], (mode_t)0, dv) ? (int)major(dv) :
1374 ac_test mkstemp <<-'EOF'
1377 int main(void) { char tmpl[] = "X"; return (mkstemp(tmpl)); }
1380 ac_test nice <<-'EOF'
1382 int main(void) { return (nice(4)); }
1385 ac_test revoke <<-'EOF'
1386 #include <sys/types.h>
1388 #include <libutil.h>
1391 int main(int ac, char *av[]) { return (ac + revoke(av[0])); }
1394 ac_test setlocale_ctype '' 'setlocale(LC_CTYPE, "")' <<-'EOF'
1397 int main(void) { return ((int)(ptrdiff_t)(void *)setlocale(LC_CTYPE, "")); }
1400 ac_test langinfo_codeset setlocale_ctype 0 'nl_langinfo(CODESET)' <<-'EOF'
1401 #include <langinfo.h>
1403 int main(void) { return ((int)(ptrdiff_t)(void *)nl_langinfo(CODESET)); }
1406 ac_test select <<-'EOF'
1407 #include <sys/types.h>
1408 #include <sys/time.h>
1409 #if HAVE_SYS_BSDTYPES_H
1410 #include <sys/bsdtypes.h>
1412 #if HAVE_SYS_SELECT_H
1413 #include <sys/select.h>
1416 #include <bstring.h>
1422 #include <strings.h>
1426 struct timeval tv = { 1, 200000 };
1427 fd_set fds; FD_ZERO(&fds); FD_SET(0, &fds);
1428 return (select(FD_SETSIZE, &fds, NULL, NULL, &tv));
1432 ac_test setresugid <<-'EOF'
1433 #include <sys/types.h>
1435 int main(void) { setresuid(0,0,0); return (setresgid(0,0,0)); }
1438 ac_test setgroups setresugid 0 <<-'EOF'
1439 #include <sys/types.h>
1444 int main(void) { gid_t gid = 0; return (setgroups(0, &gid)); }
1447 ac_test strcasestr <<-'EOF'
1448 #include <sys/types.h>
1452 #include <strings.h>
1454 int main(int ac, char *av[]) {
1455 return ((int)(ptrdiff_t)(void *)strcasestr(*av, av[ac]));
1459 ac_test strlcpy <<-'EOF'
1461 int main(int ac, char *av[]) { return (strlcpy(*av, av[1],
1466 # check headers for declarations
1468 save_CC=$CC; save_LDFLAGS=$LDFLAGS; save_LIBS=$LIBS
1469 CC="$CC -c -o $tcfn"; LDFLAGS=; LIBS=
1470 ac_test '!' flock_decl flock_ex 1 'if flock() does not need to be declared' <<-'EOF'
1471 #define MKSH_INCLUDES_ONLY
1473 long flock(void); /* this clashes if defined before */
1474 int main(void) { return ((int)flock()); }
1476 ac_test '!' revoke_decl revoke 1 'if revoke() does not need to be declared' <<-'EOF'
1477 #define MKSH_INCLUDES_ONLY
1479 long revoke(void); /* this clashes if defined before */
1480 int main(void) { return ((int)revoke()); }
1482 ac_test sys_siglist_decl sys_siglist 1 'if sys_siglist[] does not need to be declared' <<-'EOF'
1483 #define MKSH_INCLUDES_ONLY
1485 int main(void) { return (sys_siglist[0][0]); }
1487 CC=$save_CC; LDFLAGS=$save_LDFLAGS; LIBS=$save_LIBS
1492 fd='if to use persistent history'
1493 ac_cache PERSISTENT_HISTORY || test 0 = $HAVE_FLOCK_EX || fv=1
1494 test 1 = $fv || check_categories="$check_categories no-histfile"
1499 # Compiler: Praeprocessor (only if needed)
1501 test 0 = $HAVE_SYS_SIGNAME && if ac_testinit cpp_dd '' \
1502 'checking if the C Preprocessor supports -dD'; then
1503 echo '#define foo bar' >conftest.c
1504 vv ']' "$CPP $CFLAGS $CPPFLAGS $NOWARN -dD conftest.c >x"
1505 grep '#define foo bar' x >/dev/null 2>&1 && fv=1
1506 rmf conftest.c x vv.out
1511 # End of mirtoconf checks
1515 # Some operating systems have ancient versions of ed(1) writing
1516 # the character count to standard output; cope for that
1518 ed x <x 2>/dev/null | grep 3 >/dev/null 2>&1 && \
1519 check_categories="$check_categories $oldish_ed"
1522 if test 0 = $HAVE_SYS_SIGNAME; then
1523 if test 1 = $HAVE_CPP_DD; then
1524 $e Generating list of signal names...
1526 $e No list of signal names available via cpp. Falling back...
1529 echo '#include <signal.h>
1533 #elif defined(SIGMAX)
1534 #define NSIG (SIGMAX+1)
1537 mksh_cfg: NSIG' >conftest.c
1538 NSIG=`vq "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c" | \
1539 grep mksh_cfg: | sed 's/^mksh_cfg:[ ]*\([0-9x ()+-]*\).*$/\1/'`
1541 *[\ \(\)+-]*) NSIG=`awk "BEGIN { print $NSIG }"` ;;
1544 (printf hallo) >/dev/null 2>&1 || printf=echo
1545 test $printf = echo || NSIG=`printf %d "$NSIG" 2>/dev/null`
1546 $printf "NSIG=$NSIG ... "
1547 sigs="ABRT ALRM BUS CHLD CLD CONT DIL EMT FPE HUP ILL INFO INT IO IOT"
1548 sigs="$sigs KILL LOST PIPE PROF PWR QUIT RESV SAK SEGV STOP SYS TERM"
1549 sigs="$sigs TRAP TSTP TTIN TTOU URG USR1 USR2 VTALRM WINCH XCPU XFSZ"
1550 test 1 = $HAVE_CPP_DD && test $NSIG -gt 1 && sigs="$sigs "`vq \
1551 "$CPP $CFLAGS $CPPFLAGS $NOWARN -dD conftest.c" | \
1552 grep '[ ]SIG[A-Z0-9]*[ ]' | \
1553 sed 's/^\(.*[ ]SIG\)\([A-Z0-9]*\)\([ ].*\)$/\2/' | sort`
1554 test $NSIG -gt 1 || sigs=
1555 for name in $sigs; do
1556 echo '#include <signal.h>' >conftest.c
1557 echo mksh_cfg: SIG$name >>conftest.c
1558 vq "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c" | \
1560 sed 's/^mksh_cfg:[ ]*\([0-9x]*\).*$/\1:'$name/
1561 done | grep -v '^:' | sed 's/:/ /g' | while read nr name; do
1562 test $printf = echo || nr=`printf %d "$nr" 2>/dev/null`
1563 test $nr -gt 0 && test $nr -le $NSIG || continue
1566 *) echo " { \"$name\", $nr },"
1567 sigseen=$sigseen$nr:
1568 $printf "$name=$nr " >&2
1571 done 2>&1 >signames.inc
1576 addsrcs '!' HAVE_STRLCPY strlcpy.c
1577 addsrcs USE_PRINTF_BUILTIN printf.c
1578 test 1 = "$USE_PRINTF_BUILTIN" && add_cppflags -DMKSH_PRINTF_BUILTIN
1579 test 1 = "$HAVE_CAN_VERB" && CFLAGS="$CFLAGS -verbose"
1581 $e $bi$me: Finished configuration testing, now producing output.$ao
1587 *\ *) echo "#!./mksh" >test.sh ;;
1588 *) echo "#!$curdir/mksh" >test.sh ;;
1590 cat >>test.sh <<-EOF
1591 LC_ALL=C PATH='$PATH'; export LC_ALL PATH
1592 test -n "\$KSH_VERSION" || exit 1
1593 set -A check_categories -- $check_categories
1594 pflag='$curdir/mksh'
1595 sflag='$srcdir/check.t'
1596 usee=0 Pflag=0 uset=0 vflag=0 xflag=0
1597 while getopts "C:e:Pp:s:t:v" ch; do case \$ch {
1598 (C) check_categories[\${#check_categories[*]}]=\$OPTARG ;;
1599 (e) usee=1; eflag=\$OPTARG ;;
1601 (p) pflag=\$OPTARG ;;
1602 (s) sflag=\$OPTARG ;;
1603 (t) uset=1; tflag=\$OPTARG ;;
1608 shift \$((OPTIND - 1))
1609 set -A args -- '$srcdir/check.pl' -p "\$pflag" -s "\$sflag"
1611 for y in "\${check_categories[@]}"; do
1614 if [[ -n \$x ]]; then
1615 args[\${#args[*]}]=-C
1616 args[\${#args[*]}]=\${x#,}
1619 args[\${#args[*]}]=-e
1620 args[\${#args[*]}]=\$eflag
1622 (( Pflag )) && args[\${#args[*]}]=-P
1624 args[\${#args[*]}]=-t
1625 args[\${#args[*]}]=\$tflag
1627 (( vflag )) && args[\${#args[*]}]=-v
1628 (( xflag )) && args[\${#args[*]}]=-x # force usage by synerr
1629 print Testing mksh for conformance:
1630 fgrep MirOS: '$srcdir/check.t'
1631 fgrep MIRBSD '$srcdir/check.t'
1632 print "This shell is actually:\\n\\t\$KSH_VERSION"
1633 print 'test.sh built for mksh $dstversion'
1634 cstr='\$os = defined \$^O ? \$^O : "unknown";'
1635 cstr="\$cstr"'print \$os . ", Perl version " . \$];'
1636 for perli in \$PERL perl5 perl no; do
1637 [[ \$perli = no ]] && exit 1
1638 perlos=\$(\$perli -e "\$cstr") 2>/dev/null || continue
1639 print "Perl interpreter '\$perli' running on '\$perlos'"
1640 [[ -n \$perlos ]] && break
1642 exec \$perli "\${args[@]}" "\$@"$tsts
1645 if test $cm = llvm; then
1646 emitbc="-emit-llvm -c"
1647 elif test $cm = dragonegg; then
1652 echo set -x >Rebuild.sh
1653 for file in $SRCS; do
1654 op=`echo x"$file" | sed 's/^x\(.*\)\.c$/\1./'`
1655 test -f $file || file=$srcdir/$file
1656 files="$files$sp$file"
1658 echo "$CC $CFLAGS $CPPFLAGS $emitbc $file || exit 1" >>Rebuild.sh
1659 if test $cm = dragonegg; then
1660 echo "mv ${op}s ${op}ll" >>Rebuild.sh
1661 echo "llvm-as ${op}ll || exit 1" >>Rebuild.sh
1662 objs="$objs$sp${op}bc"
1664 objs="$objs$sp${op}o"
1669 echo "rm -f mksh.s" >>Rebuild.sh
1670 echo "llvm-link -o - $objs | opt $optflags | llc -o mksh.s" >>Rebuild.sh
1678 a.exe) mkshexe=mksh.exe ;;
1681 echo tcfn=$mkshexe >>Rebuild.sh
1682 echo "$CC $CFLAGS $LDFLAGS -o \$tcfn $lobjs $LIBS $ccpr" >>Rebuild.sh
1683 echo 'test -f $tcfn || exit 1; size $tcfn' >>Rebuild.sh
1684 if test $cm = makefile; then
1685 extras='emacsfn.h sh.h sh_flags.h var_spec.h'
1686 test 0 = $HAVE_SYS_SIGNAME && extras="$extras signames.inc"
1687 cat >Makefrag.inc <<EOF
1688 # Makefile fragment for building mksh $dstversion
1696 NONSRCS_INST= dot.mkshrc \$(MAN)
1697 NONSRCS_NOINST= Build.sh Makefile Rebuild.sh check.pl check.t test.sh
1704 # not BSD make only:
1707 #\$(PROG): \$(OBJS_BP)
1708 # \$(CC) \$(CFLAGS) \$(LDFLAGS) -o \$@ \$(OBJS_BP) \$(LIBS)
1709 #\$(OBJS_BP): \$(SRCS_FP) \$(NONSRCS)
1711 # \$(CC) \$(CFLAGS) \$(CPPFLAGS) -c \$<
1713 # for all make variants:
1716 # ./test.sh \$(REGRESS_FLAGS)
1718 # for BSD make only:
1720 #.include <bsd.prog.mk>
1723 $e Generated Makefrag.inc successfully.
1726 if test $cm = combine; then
1728 for file in $SRCS; do
1729 test -f $file || file=$srcdir/$file
1732 emitbc="-fwhole-program --combine"
1733 v "$CC $CFLAGS $CPPFLAGS $LDFLAGS $emitbc $objs $LIBS $ccpr"
1734 elif test 1 = $pm; then
1735 for file in $SRCS; do
1736 test -f $file || file=$srcdir/$file
1737 v "$CC $CFLAGS $CPPFLAGS $emitbc $file" &
1741 for file in $SRCS; do
1742 test $cm = dragonegg && \
1743 op=`echo x"$file" | sed 's/^x\(.*\)\.c$/\1./'`
1744 test -f $file || file=$srcdir/$file
1745 v "$CC $CFLAGS $CPPFLAGS $emitbc $file" || exit 1
1746 if test $cm = dragonegg; then
1747 v "mv ${op}s ${op}ll"
1748 v "llvm-as ${op}ll" || exit 1
1755 v "llvm-link -o - $objs | opt $optflags | llc -o mksh.s"
1759 test $cm = combine || v "$CC $CFLAGS $LDFLAGS -o $tcfn $lobjs $LIBS $ccpr"
1760 test -f $tcfn || exit 1
1761 test 1 = $r || v "$NROFF -mdoc <'$srcdir/mksh.1' >mksh.cat1" || \
1763 test 0 = $eq && v size $tcfn
1765 test -f /usr/ucb/$i && i=/usr/ucb/$i
1768 $e Installing the shell:
1769 $e "# $i -c -s -o root -g bin -m 555 mksh /bin/mksh"
1770 $e "# grep -x /bin/mksh /etc/shells >/dev/null || echo /bin/mksh >>/etc/shells"
1771 $e "# $i -c -o root -g bin -m 444 dot.mkshrc /usr/share/doc/mksh/examples/"
1773 $e Installing the manual:
1774 if test -f mksh.cat1; then
1775 $e "# $i -c -o root -g bin -m 444 mksh.cat1" \
1776 "/usr/share/man/cat1/mksh.0"
1779 $e "# $i -c -o root -g bin -m 444 mksh.1 /usr/share/man/man1/mksh.1"
1781 $e Run the regression test suite: ./test.sh
1782 $e Please also read the sample file dot.mkshrc and the fine manual.