Home | History | Annotate | Download | only in src
      1 #!/bin/sh
      2 srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.488 2011/10/07 19:51:41 tg Exp $'
      3 #-
      4 # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
      5 #	Thorsten Glaser <tg (at] mirbsd.org>
      6 #
      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.
     12 #
     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.
     21 #-
     22 # People analysing the output must whitelist conftest.c for any kind
     23 # of compiler warning checks (mirtoconf is by design not quiet).
     24 #
     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
     35 
     36 LC_ALL=C
     37 export LC_ALL
     38 
     39 v() {
     40 	$e "$*"
     41 	eval "$@"
     42 }
     43 
     44 vv() {
     45 	_c=$1
     46 	shift
     47 	$e "\$ $*" 2>&1
     48 	eval "$@" >vv.out 2>&1
     49 	sed "s^${_c} " <vv.out
     50 }
     51 
     52 vq() {
     53 	eval "$@"
     54 }
     55 
     56 rmf() {
     57 	for _f in "$@"; do
     58 		case ${_f} in
     59 		mksh.1) ;;
     60 		*) rm -f "${_f}" ;;
     61 		esac
     62 	done
     63 }
     64 
     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
     68 	export PATH
     69 fi
     70 
     71 if test -n "${ZSH_VERSION+x}" && (emulate sh) >/dev/null 2>&1; then
     72 	emulate sh
     73 	NULLCMD=:
     74 fi
     75 
     76 allu=QWERTYUIOPASDFGHJKLZXCVBNM
     77 alll=qwertyuiopasdfghjklzxcvbnm
     78 alln=0123456789
     79 alls=______________________________________________________________
     80 nl='
     81 '
     82 tcfn=no
     83 bi=
     84 ui=
     85 ao=
     86 fx=
     87 me=`basename "$0"`
     88 orig_CFLAGS=$CFLAGS
     89 phase=x
     90 oldish_ed=stdout-ed,no-stderr-ed
     91 
     92 if test -t 1; then
     93 	bi='[1m'
     94 	ui='[4m'
     95 	ao='[0m'
     96 fi
     97 
     98 upper() {
     99 	echo :"$@" | sed 's/^://' | tr $alll $allu
    100 }
    101 
    102 # clean up after ac_testrun()
    103 ac_testdone() {
    104 	eval HAVE_$fu=$fv
    105 	fr=no
    106 	test 0 = $fv || fr=yes
    107 	$e "$bi==> $fd...$ao $ui$fr$ao$fx"
    108 	fx=
    109 }
    110 
    111 # ac_cache label: sets f, fu, fv?=0
    112 ac_cache() {
    113 	f=$1
    114 	fu=`upper $f`
    115 	eval fv=\$HAVE_$fu
    116 	case $fv in
    117 	0|1)
    118 		fx=' (cached)'
    119 		return 0
    120 		;;
    121 	esac
    122 	fv=0
    123 	return 1
    124 }
    125 
    126 # ac_testinit label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput
    127 # returns 1 if value was cached/implied, 0 otherwise: call ac_testdone
    128 ac_testinit() {
    129 	if ac_cache $1; then
    130 		test x"$2" = x"!" && shift
    131 		test x"$2" = x"" || shift
    132 		fd=${3-$f}
    133 		ac_testdone
    134 		return 1
    135 	fi
    136 	fc=0
    137 	if test x"$2" = x""; then
    138 		ft=1
    139 	else
    140 		if test x"$2" = x"!"; then
    141 			fc=1
    142 			shift
    143 		fi
    144 		eval ft=\$HAVE_`upper $2`
    145 		shift
    146 	fi
    147 	fd=${3-$f}
    148 	if test $fc = "$ft"; then
    149 		fv=$2
    150 		fx=' (implied)'
    151 		ac_testdone
    152 		return 1
    153 	fi
    154 	$e ... $fd
    155 	return 0
    156 }
    157 
    158 # pipe .c | ac_test[n] [!] label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput
    159 ac_testn() {
    160 	if test x"$1" = x"!"; then
    161 		fr=1
    162 		shift
    163 	else
    164 		fr=0
    165 	fi
    166 	ac_testinit "$@" || return
    167 	cat >conftest.c
    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
    173 		test 1 = $fr || fv=1
    174 	else
    175 		test 0 = $fr || fv=1
    176 	fi
    177 	vscan=
    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'
    183 	fi
    184 	test -n "$vscan" && grep $vscan vv.out >/dev/null 2>&1 && fv=$fr
    185 	rmf conftest.c conftest.o ${tcfn}* vv.out
    186 	ac_testdone
    187 }
    188 
    189 # ac_ifcpp cppexpr [!] label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput
    190 ac_ifcpp() {
    191 	expr=$1; shift
    192 	ac_testn "$@" <<-EOF
    193 		int main(void) { return (
    194 		#$expr
    195 		    0
    196 		#else
    197 		/* force a failure: expr is false */
    198 		    thiswillneverbedefinedIhope()
    199 		#endif
    200 		    ); }
    201 EOF
    202 	test x"$1" = x"!" && shift
    203 	f=$1
    204 	fu=`upper $f`
    205 	eval fv=\$HAVE_$fu
    206 	test x"$fv" = x"1"
    207 }
    208 
    209 add_cppflags() {
    210 	CPPFLAGS="$CPPFLAGS $*"
    211 }
    212 
    213 ac_cppflags() {
    214 	test x"$1" = x"" || fu=$1
    215 	fv=$2
    216 	test x"$2" = x"" && eval fv=\$HAVE_$fu
    217 	add_cppflags -DHAVE_$fu=$fv
    218 }
    219 
    220 ac_test() {
    221 	ac_testn "$@"
    222 	ac_cppflags
    223 }
    224 
    225 # ac_flags [-] add varname cflags [text] [ldflags]
    226 ac_flags() {
    227 	if test x"$1" = x"-"; then
    228 		shift
    229 		hf=1
    230 	else
    231 		hf=0
    232 	fi
    233 	fa=$1
    234 	vn=$2
    235 	f=$3
    236 	ft=$4
    237 	fl=$5
    238 	test x"$ft" = x"" && ft="if $f can be used"
    239 	save_CFLAGS=$CFLAGS
    240 	CFLAGS="$CFLAGS $f"
    241 	if test -n "$fl"; then
    242 		save_LDFLAGS=$LDFLAGS
    243 		LDFLAGS="$LDFLAGS $fl"
    244 	fi
    245 	if test 1 = $hf; then
    246 		ac_testn can_$vn '' "$ft"
    247 	else
    248 		ac_testn can_$vn '' "$ft" <<-'EOF'
    249 			/* evil apo'stroph in comment test */
    250 			int main(void) { return (0); }
    251 		EOF
    252 	fi
    253 	eval fv=\$HAVE_CAN_`upper $vn`
    254 	if test -n "$fl"; then
    255 		test 11 = $fa$fv || LDFLAGS=$save_LDFLAGS
    256 	fi
    257 	test 11 = $fa$fv || CFLAGS=$save_CFLAGS
    258 }
    259 
    260 # ac_header [!] header [prereq ...]
    261 ac_header() {
    262 	if test x"$1" = x"!"; then
    263 		na=1
    264 		shift
    265 	else
    266 		na=0
    267 	fi
    268 	hf=$1; shift
    269 	hv=`echo "$hf" | tr -d '\012\015' | tr -c $alll$allu$alln $alls`
    270 	for i
    271 	do
    272 		echo "#include <$i>" >>x
    273 	done
    274 	echo "#include <$hf>" >>x
    275 	echo 'int main(void) { return (0); }' >>x
    276 	ac_testn "$hv" "" "<$hf>" <x
    277 	rmf x
    278 	test 1 = $na || ac_cppflags
    279 }
    280 
    281 addsrcs() {
    282 	if test x"$1" = x"!"; then
    283 		fr=0
    284 		shift
    285 	else
    286 		fr=1
    287 	fi
    288 	eval i=\$$1
    289 	test $fr = "$i" && case " $SRCS " in
    290 	*\ $2\ *)	;;
    291 	*)		SRCS="$SRCS $2" ;;
    292 	esac
    293 }
    294 
    295 
    296 if test -d mksh || test -d mksh.exe; then
    297 	echo "$me: Error: ./mksh is a directory!" >&2
    298 	exit 1
    299 fi
    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
    302 
    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`
    306 
    307 e=echo
    308 r=0
    309 eq=0
    310 pm=0
    311 cm=normal
    312 optflags=-std-compile-opts
    313 last=
    314 
    315 for i
    316 do
    317 	case $last:$i in
    318 	c:combine|c:dragonegg|c:llvm|c:lto)
    319 		cm=$i
    320 		last=
    321 		;;
    322 	c:*)
    323 		echo "$me: Unknown option -c '$i'!" >&2
    324 		exit 1
    325 		;;
    326 	o:*)
    327 		optflags=$i
    328 		last=
    329 		;;
    330 	:-c)
    331 		last=c
    332 		;;
    333 	:-g)
    334 		# checker, debug, valgrind build
    335 		add_cppflags -DDEBUG
    336 		CFLAGS="$CFLAGS -g3 -fno-builtin"
    337 		;;
    338 	:-j)
    339 		pm=1
    340 		;;
    341 	:-M)
    342 		cm=makefile
    343 		;;
    344 	:-O)
    345 		optflags=-std-compile-opts
    346 		;;
    347 	:-o)
    348 		last=o
    349 		;;
    350 	:-Q)
    351 		eq=1
    352 		;;
    353 	:-r)
    354 		r=1
    355 		;;
    356 	:-v)
    357 		echo "Build.sh $srcversion"
    358 		echo "for mksh $dstversion"
    359 		exit 0
    360 		;;
    361 	:*)
    362 		echo "$me: Unknown option '$i'!" >&2
    363 		exit 1
    364 		;;
    365 	*)
    366 		echo "$me: Unknown option -'$last' '$i'!" >&2
    367 		exit 1
    368 		;;
    369 	esac
    370 done
    371 if test -n "$last"; then
    372 	echo "$me: Option -'$last' not followed by argument!" >&2
    373 	exit 1
    374 fi
    375 
    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"
    378 
    379 if test x"$srcdir" = x"."; then
    380 	CPPFLAGS="-I. $CPPFLAGS"
    381 else
    382 	CPPFLAGS="-I. -I'$srcdir' $CPPFLAGS"
    383 fi
    384 
    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
    388 	exit 1
    389 fi
    390 oswarn=
    391 ccpc=-Wc,
    392 ccpl=-Wl,
    393 tsts=
    394 ccpr='|| for _f in ${tcfn}*; do test x"${_f}" = x"mksh.1" || rm -f "${_f}"; done'
    395 
    396 # Evil hack
    397 if test x"$TARGET_OS" = x"Android"; then
    398 	check_categories="$check_categories android"
    399 	TARGET_OS=Linux
    400 fi
    401 
    402 # Configuration depending on OS revision, on OSes that need them
    403 case $TARGET_OS in
    404 QNX)
    405 	test x"$TARGET_OSREV" = x"" && TARGET_OSREV=`uname -r`
    406 	;;
    407 esac
    408 
    409 # Configuration depending on OS name
    410 case $TARGET_OS in
    411 AIX)
    412 	add_cppflags -D_ALL_SOURCE
    413 	: ${HAVE_SETLOCALE_CTYPE=0}
    414 	;;
    415 BeOS)
    416 	oswarn=' and will currently not work'
    417 	;;
    418 BSD/OS)
    419 	: ${HAVE_SETLOCALE_CTYPE=0}
    420 	;;
    421 CYGWIN*)
    422 	: ${HAVE_SETLOCALE_CTYPE=0}
    423 	;;
    424 Darwin)
    425 	;;
    426 DragonFly)
    427 	;;
    428 FreeBSD)
    429 	;;
    430 FreeMiNT)
    431 	oswarn="; it has minor issues"
    432 	add_cppflags -D_GNU_SOURCE
    433 	: ${HAVE_SETLOCALE_CTYPE=0}
    434 	;;
    435 GNU)
    436 	case $CC in
    437 	*tendracc*) ;;
    438 	*) add_cppflags -D_GNU_SOURCE ;;
    439 	esac
    440 	# define NO_PATH_MAX to use Hurd-only functions
    441 	add_cppflags -DNO_PATH_MAX
    442 	;;
    443 GNU/kFreeBSD)
    444 	case $CC in
    445 	*tendracc*) ;;
    446 	*) add_cppflags -D_GNU_SOURCE ;;
    447 	esac
    448 	;;
    449 Haiku)
    450 	add_cppflags -DMKSH_ASSUME_UTF8
    451 	;;
    452 HP-UX)
    453 	;;
    454 Interix)
    455 	ccpc='-X '
    456 	ccpl='-Y '
    457 	add_cppflags -D_ALL_SOURCE
    458 	: ${LIBS='-lcrypt'}
    459 	: ${HAVE_SETLOCALE_CTYPE=0}
    460 	;;
    461 IRIX*)
    462 	: ${HAVE_SETLOCALE_CTYPE=0}
    463 	;;
    464 Linux)
    465 	case $CC in
    466 	*tendracc*) ;;
    467 	*) add_cppflags -D_GNU_SOURCE ;;
    468 	esac
    469 	add_cppflags -DSETUID_CAN_FAIL_WITH_EAGAIN
    470 	: ${HAVE_REVOKE=0}
    471 	;;
    472 MidnightBSD)
    473 	;;
    474 Minix)
    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}
    481 	;;
    482 MirBSD)
    483 	;;
    484 MSYS_*)
    485 	# probably same as CYGWIN*  need to test; from RT|Chatzilla
    486 	oswarn='but will probably work'
    487 	;;
    488 NetBSD)
    489 	;;
    490 OpenBSD)
    491 	: ${HAVE_SETLOCALE_CTYPE=0}
    492 	;;
    493 OSF1)
    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}
    500 	;;
    501 Plan9)
    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
    509 	;;
    510 PW32*)
    511 	HAVE_SIG_T=0	# incompatible
    512 	oswarn=' and will currently not work'
    513 	: ${HAVE_SETLOCALE_CTYPE=0}
    514 	;;
    515 QNX)
    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
    520 		;;
    521 	esac
    522 	: ${HAVE_SETLOCALE_CTYPE=0}
    523 	;;
    524 SunOS)
    525 	add_cppflags -D_BSD_SOURCE
    526 	add_cppflags -D__EXTENSIONS__
    527 	;;
    528 syllable)
    529 	add_cppflags -D_GNU_SOURCE
    530 	oswarn=' and will currently not work'
    531 	;;
    532 ULTRIX)
    533 	: ${CC=cc -YPOSIX}
    534 	add_cppflags -Dssize_t=int
    535 	: ${HAVE_SETLOCALE_CTYPE=0}
    536 	;;
    537 UWIN*)
    538 	ccpc='-Yc,'
    539 	ccpl='-Yl,'
    540 	tsts=" 3<>/dev/tty"
    541 	oswarn="; it will compile, but the target"
    542 	oswarn="$oswarn${nl}platform itself is very flakey/unreliable"
    543 	: ${HAVE_SETLOCALE_CTYPE=0}
    544 	;;
    545 *)
    546 	oswarn='; it may or may not work'
    547 	;;
    548 esac
    549 
    550 : ${HAVE_MKNOD=0}
    551 
    552 : ${CC=cc} ${NROFF=nroff}
    553 test 0 = $r && echo | $NROFF -v 2>&1 | grep GNU >/dev/null 2>&1 && \
    554     NROFF="$NROFF -c"
    555 
    556 # this aids me in tracing FTBFSen without access to the buildd
    557 $e "Hi from$ao $bi$srcversion$ao on:"
    558 case $TARGET_OS in
    559 AIX)
    560 	vv '|' "oslevel >&2"
    561 	vv '|' "uname -a >&2"
    562 	;;
    563 Darwin)
    564 	vv '|' "hwprefs machine_type os_type os_class >&2"
    565 	vv '|' "uname -a >&2"
    566 	;;
    567 IRIX*)
    568 	vv '|' "uname -a >&2"
    569 	vv '|' "hinv -v >&2"
    570 	;;
    571 OSF1)
    572 	vv '|' "uname -a >&2"
    573 	vv '|' "/usr/sbin/sizer -v >&2"
    574 	;;
    575 *)
    576 	vv '|' "uname -a >&2"
    577 	;;
    578 esac
    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.
    584 "
    585 $e "$bi$me: Building the MirBSD Korn Shell$ao $ui$dstversion$ao"
    586 
    587 #
    588 # Begin of mirtoconf checks
    589 #
    590 $e $bi$me: Scanning for functions... please ignore any errors.$ao
    591 
    592 #
    593 # Compiler: which one?
    594 #
    595 # notes:
    596 # - ICC defines __GNUC__ too
    597 # - GCC defines __hpux too
    598 # - LLVM+clang defines __GNUC__ too
    599 # - nwcc defines __GNUC__ too
    600 CPP="$CC -E"
    601 $e ... which compiler seems to be used
    602 cat >conftest.c <<'EOF'
    603 #if defined(__ICC) || defined(__INTEL_COMPILER)
    604 ct=icc
    605 #elif defined(__xlC__) || defined(__IBMC__)
    606 ct=xlc
    607 #elif defined(__SUNPRO_C)
    608 ct=sunpro
    609 #elif defined(__ACK__)
    610 ct=ack
    611 #elif defined(__BORLANDC__)
    612 ct=bcc
    613 #elif defined(__WATCOMC__)
    614 ct=watcom
    615 #elif defined(__MWERKS__)
    616 ct=metrowerks
    617 #elif defined(__HP_cc)
    618 ct=hpcc
    619 #elif defined(__DECC) || (defined(__osf__) && !defined(__GNUC__))
    620 ct=dec
    621 #elif defined(__PGI)
    622 ct=pgi
    623 #elif defined(__DMC__)
    624 ct=dmc
    625 #elif defined(_MSC_VER)
    626 ct=msc
    627 #elif defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__)
    628 ct=adsp
    629 #elif defined(__IAR_SYSTEMS_ICC__)
    630 ct=iar
    631 #elif defined(SDCC)
    632 ct=sdcc
    633 #elif defined(__PCC__)
    634 ct=pcc
    635 #elif defined(__TenDRA__)
    636 ct=tendra
    637 #elif defined(__TINYC__)
    638 ct=tcc
    639 #elif defined(__llvm__) && defined(__clang__)
    640 ct=clang
    641 #elif defined(__NWCC__)
    642 ct=nwcc
    643 #elif defined(__GNUC__)
    644 ct=gcc
    645 #elif defined(_COMPILER_VERSION)
    646 ct=mipspro
    647 #elif defined(__sgi)
    648 ct=mipspro
    649 #elif defined(__hpux) || defined(__hpua)
    650 ct=hpcc
    651 #elif defined(__ultrix)
    652 ct=ucode
    653 #else
    654 ct=unknown
    655 #endif
    656 EOF
    657 ct=unknown
    658 vv ']' "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c | grep ct= | tr -d \\\\015 >x"
    659 sed 's/^/[ /' x
    660 eval `cat x`
    661 rmf x vv.out
    662 echo 'int main(void) { return (0); }' >conftest.c
    663 case $ct in
    664 ack)
    665 	# work around "the famous ACK const bug"
    666 	CPPFLAGS="-Dconst= $CPPFLAGS"
    667 	;;
    668 adsp)
    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.'
    673 	;;
    674 bcc)
    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."
    678 	;;
    679 clang)
    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
    686 	:*)	;;
    687 	*:)	CCC_LD=$CCC_CC; export CCC_LD ;;
    688 	esac
    689 	;;
    690 dec)
    691 	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V"
    692 	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -Wl,-V conftest.c $LIBS"
    693 	;;
    694 dmc)
    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."
    699 	;;
    700 gcc)
    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 \
    704 	    $LIBS -dumpversion`'
    705 	;;
    706 hpcc)
    707 	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
    708 	;;
    709 iar)
    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.'
    714 	;;
    715 icc)
    716 	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V"
    717 	;;
    718 metrowerks)
    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.'
    722 	;;
    723 mipspro)
    724 	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -version"
    725 	;;
    726 msc)
    727 	ccpr=		# errorlevels are not reliable
    728 	case $TARGET_OS in
    729 	Interix)
    730 		if [[ -n $C89_COMPILER ]]; then
    731 			C89_COMPILER=`ntpath2posix -c "$C89_COMPILER"`
    732 		else
    733 			C89_COMPILER=CL.EXE
    734 		fi
    735 		if [[ -n $C89_LINKER ]]; then
    736 			C89_LINKER=`ntpath2posix -c "$C89_LINKER"`
    737 		else
    738 			C89_LINKER=LINK.EXE
    739 		fi
    740 		vv '|' "$C89_COMPILER /HELP >&2"
    741 		vv '|' "$C89_LINKER /LINK >&2"
    742 		;;
    743 	esac
    744 	;;
    745 nwcc)
    746 	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -version"
    747 	;;
    748 pcc)
    749 	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -v"
    750 	;;
    751 pgi)
    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.'
    755 	;;
    756 sdcc)
    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.'
    761 	;;
    762 sunpro)
    763 	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
    764 	;;
    765 tcc)
    766 	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -v"
    767 	;;
    768 tendra)
    769 	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V 2>&1 | \
    770 	    fgrep -i -e version -e release"
    771 	;;
    772 ucode)
    773 	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V"
    774 	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -Wl,-V conftest.c $LIBS"
    775 	;;
    776 watcom)
    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.'
    780 	;;
    781 xlc)
    782 	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -qversion"
    783 	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -qversion=verbose"
    784 	vv '|' "ld -V"
    785 	;;
    786 *)
    787 	ct=unknown
    788 	;;
    789 esac
    790 case $cm in
    791 dragonegg|llvm)
    792 	vv '|' "llc -version"
    793 	;;
    794 esac
    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
    797 
    798 #
    799 # Compiler: works as-is, with -Wno-error and -Werror
    800 #
    801 save_NOWARN=$NOWARN
    802 NOWARN=
    803 DOWARN=
    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
    810 	save_CFLAGS=$CFLAGS
    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); }
    816 		EOF
    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); }
    821 		EOF
    822 	else
    823 		exit 1
    824 	fi
    825 	test 1 = $HAVE_CAN_DELEXE || CFLAGS=$save_CFLAGS
    826 	ac_testn compiler_still_fails '' 'if the compiler still does not fail correctly' <<-EOF
    827 	EOF
    828 	test 1 = $HAVE_COMPILER_STILL_FAILS && exit 1
    829 fi
    830 if ac_ifcpp 'ifdef __TINYC__' couldbe_tcc '!' compiler_known 0 \
    831     'if this could be tcc'; then
    832 	ct=tcc
    833 	CPP='cpp -D__TINYC__'
    834 fi
    835 
    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
    843 	save_NOWARN=
    844 	DOWARN=+We
    845 elif test $ct = mipspro; then
    846 	save_NOWARN=
    847 	DOWARN="-diag_error 1-10000"
    848 elif test $ct = msc; then
    849 	save_NOWARN="${ccpc}/w"
    850 	DOWARN="${ccpc}/WX"
    851 elif test $ct = dmc; then
    852 	save_NOWARN="${ccpc}-w"
    853 	DOWARN="${ccpc}-wx"
    854 elif test $ct = bcc; then
    855 	save_NOWARN="${ccpc}-w"
    856 	DOWARN="${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
    861 	DOWARN=-qflag=i:i
    862 elif test $ct = tendra; then
    863 	save_NOWARN=-w
    864 elif test $ct = ucode; then
    865 	save_NOWARN=
    866 	DOWARN=-w2
    867 else
    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
    873 fi
    874 
    875 test $ct = icc && DOWARN="$DOWARN -wd1419"
    876 NOWARN=$save_NOWARN
    877 
    878 #
    879 # Compiler: extra flags (-O2 -f* -W* etc.)
    880 #
    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
    884 	cat >x <<-'EOF'
    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) { }
    889 	EOF
    890 	yes pad | head -n 256 >>x
    891 	ac_flags - 1 otwo -xO2 <x
    892 	rmf x
    893 elif test $ct = hpcc; then
    894 	phase=u
    895 	ac_flags 1 otwo +O2
    896 	phase=x
    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
    902 else
    903 	ac_flags 1 otwo -O2
    904 	test 1 = $HAVE_CAN_OTWO || ac_flags 1 optimise -O
    905 fi
    906 # other flags: just add them if they are supported
    907 i=0
    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 ;;
    917 	esac
    918 	if test $cm = lto; then
    919 		fv=0
    920 		checks='1 2 3 4 5 6 7 8'
    921 	elif test $cm = combine; then
    922 		fv=0
    923 		checks='7 8'
    924 	else
    925 		fv=1
    926 	fi
    927 	test $fv = 1 || for what in $checks; do
    928 		test $fv = 1 && break
    929 		case $what in
    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 ;;
    938 		4)	t_cflags='-flto'
    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 ;;
    943 		6)	t_cflags='-flto'
    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 ;;
    948 		8)	fv=1 cm=normal ;;
    949 		esac
    950 		test $fv = 1 && break
    951 		ac_flags $t_use $t_name "$t_cflags" \
    952 		    "if gcc supports $t_cflags $t_ldflags" "$t_ldflags"
    953 	done
    954 	i=1
    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
    959 	i=1
    960 elif test $ct = sunpro; then
    961 	phase=u
    962 	ac_flags 1 v -v
    963 	ac_flags 1 xc99 -xc99 'for support of ISO C99'
    964 	ac_flags 1 ipo -xipo 'for cross-module optimisation'
    965 	phase=x
    966 elif test $ct = hpcc; then
    967 	phase=u
    968 	ac_flags 1 agcc -Agcc 'for support of GCC extensions'
    969 	ac_flags 1 ac99 -AC99 'for support of ISO C99'
    970 	phase=x
    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
    988 	rmf 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
   1006 	i=1
   1007 elif test $ct = nwcc; then
   1008 	i=1
   1009 	#broken# ac_flags 1 ssp -stackprotect
   1010 fi
   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
   1017 fi
   1018 
   1019 phase=x
   1020 # The following tests run with -Werror or similar (all compilers) if possible
   1021 NOWARN=$DOWARN
   1022 test $ct = pcc && phase=u
   1023 
   1024 #
   1025 # Compiler: check for stuff that only generates warnings
   1026 #
   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()); }
   1031 	#else
   1032 	#include <string.h>
   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);
   1040 	}
   1041 	#endif
   1042 EOF
   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()); }
   1047 	#else
   1048 	#define fprintf printfoo
   1049 	#include <stdio.h>
   1050 	#undef __attribute__
   1051 	#undef fprintf
   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)); }
   1055 	#endif
   1056 EOF
   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()); }
   1061 	#else
   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])); }
   1069 	#endif
   1070 EOF
   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()); }
   1075 	#else
   1076 	#include <stdlib.h>
   1077 	#undef __attribute__
   1078 	void fnord(void) __attribute__((__noreturn__));
   1079 	int main(void) { fnord(); }
   1080 	void fnord(void) { exit(0); }
   1081 	#endif
   1082 EOF
   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()); }
   1087 	#else
   1088 	int main(int ac __attribute__((__unused__)), char **av
   1089 	    __attribute__((__unused__))) { return (0); }
   1090 	#endif
   1091 EOF
   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()); }
   1096 	#else
   1097 	static const char fnord[] __attribute__((__used__)) = "42";
   1098 	int main(void) { return (0); }
   1099 	#endif
   1100 EOF
   1101 
   1102 # End of tests run with -Werror
   1103 NOWARN=$save_NOWARN
   1104 phase=x
   1105 
   1106 #
   1107 # mksh: flavours (full/small mksh, omit certain stuff)
   1108 #
   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
   1112 	case $ct in
   1113 	clang|icc|nwcc)
   1114 		ac_flags 1 fnoinline -fno-inline
   1115 		;;
   1116 	gcc)
   1117 		NOWARN=$DOWARN; phase=u
   1118 		ac_flags 1 fnoinline -fno-inline
   1119 		NOWARN=$save_NOWARN; phase=x
   1120 		;;
   1121 	sunpro)
   1122 		ac_flags 1 fnoinline -xinline=
   1123 		;;
   1124 	xlc)
   1125 		ac_flags 1 fnoinline -qnoinline
   1126 		;;
   1127 	esac
   1128 
   1129 	: ${HAVE_NICE=0}
   1130 	: ${HAVE_PERSISTENT_HISTORY=0}
   1131 	check_categories="$check_categories smksh"
   1132 	HAVE_ISSET_MKSH_CONSERVATIVE_FDS=1	# from sh.h
   1133 fi
   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"
   1148 
   1149 #
   1150 # Environment: headers
   1151 #
   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
   1159 ac_header bstring.h
   1160 ac_header grp.h sys/types.h
   1161 ac_header libgen.h
   1162 ac_header libutil.h sys/types.h
   1163 ac_header paths.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
   1168 ac_header values.h
   1169 
   1170 #
   1171 # check whether whatever we use for the final link will succeed
   1172 #
   1173 if test $cm = makefile; then
   1174 	: nothing to check
   1175 else
   1176 	HAVE_LINK_WORKS=x
   1177 	ac_testinit link_works '' 'checking if the final link command may succeed'
   1178 	fv=1
   1179 	cat >conftest.c <<-'EOF'
   1180 		#define EXTERN
   1181 		#define MKSH_INCLUDES_ONLY
   1182 		#include "sh.h"
   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); }
   1185 EOF
   1186 	case $cm in
   1187 	llvm)
   1188 		v "$CC $CFLAGS $CPPFLAGS $NOWARN -emit-llvm -c conftest.c" || fv=0
   1189 		rmf mksh.s
   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"
   1192 		;;
   1193 	dragonegg)
   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
   1197 		rmf mksh.s
   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"
   1200 		;;
   1201 	combine)
   1202 		v "$CC $CFLAGS $CPPFLAGS $LDFLAGS -fwhole-program --combine $NOWARN -o $tcfn conftest.c $LIBS $ccpr"
   1203 		;;
   1204 	lto|normal)
   1205 		cm=normal
   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"
   1208 		;;
   1209 	esac
   1210 	test -f $tcfn || fv=0
   1211 	ac_testdone
   1212 	test $fv = 1 || exit 1
   1213 fi
   1214 
   1215 #
   1216 # Environment: definitions
   1217 #
   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
   1233 fi
   1234 rmf lft*	# end of large file support test
   1235 
   1236 #
   1237 # Environment: types
   1238 #
   1239 ac_test can_inttypes '!' stdint_h 1 "for standard 32-bit integer types" <<-'EOF'
   1240 	#include <sys/types.h>
   1241 	#include <stddef.h>
   1242 	int main(int ac, char **av) { return ((uint32_t)(ptrdiff_t)*av + (int32_t)ac); }
   1243 EOF
   1244 ac_test can_ucbints '!' can_inttypes 1 "for UCB 32-bit integer types" <<-'EOF'
   1245 	#include <sys/types.h>
   1246 	#include <stddef.h>
   1247 	int main(int ac, char **av) { return ((u_int32_t)(ptrdiff_t)*av + (int32_t)ac); }
   1248 EOF
   1249 ac_test can_int8type '!' stdint_h 1 "for standard 8-bit integer type" <<-'EOF'
   1250 	#include <sys/types.h>
   1251 	#include <stddef.h>
   1252 	int main(int ac, char **av) { return ((uint8_t)(ptrdiff_t)av[ac]); }
   1253 EOF
   1254 ac_test can_ucbint8 '!' can_int8type 1 "for UCB 8-bit integer type" <<-'EOF'
   1255 	#include <sys/types.h>
   1256 	#include <stddef.h>
   1257 	int main(int ac, char **av) { return ((u_int8_t)(ptrdiff_t)av[ac]); }
   1258 EOF
   1259 
   1260 ac_test rlim_t <<-'EOF'
   1261 	#include <sys/types.h>
   1262 	#include <sys/time.h>
   1263 	#include <sys/resource.h>
   1264 	#include <unistd.h>
   1265 	int main(void) { return ((int)(rlim_t)0); }
   1266 EOF
   1267 
   1268 # only testn: added later below
   1269 ac_testn sig_t <<-'EOF'
   1270 	#include <sys/types.h>
   1271 	#include <signal.h>
   1272 	#include <stddef.h>
   1273 	int main(void) { return ((int)(ptrdiff_t)(sig_t)(ptrdiff_t)kill(0,0)); }
   1274 EOF
   1275 
   1276 ac_testn sighandler_t '!' sig_t 0 <<-'EOF'
   1277 	#include <sys/types.h>
   1278 	#include <signal.h>
   1279 	#include <stddef.h>
   1280 	int main(void) { return ((int)(ptrdiff_t)(sighandler_t)(ptrdiff_t)kill(0,0)); }
   1281 EOF
   1282 if test 1 = $HAVE_SIGHANDLER_T; then
   1283 	add_cppflags -Dsig_t=sighandler_t
   1284 	HAVE_SIG_T=1
   1285 fi
   1286 
   1287 ac_testn __sighandler_t '!' sig_t 0 <<-'EOF'
   1288 	#include <sys/types.h>
   1289 	#include <signal.h>
   1290 	#include <stddef.h>
   1291 	int main(void) { return ((int)(ptrdiff_t)(__sighandler_t)(ptrdiff_t)kill(0,0)); }
   1292 EOF
   1293 if test 1 = $HAVE___SIGHANDLER_T; then
   1294 	add_cppflags -Dsig_t=__sighandler_t
   1295 	HAVE_SIG_T=1
   1296 fi
   1297 
   1298 test 1 = $HAVE_SIG_T || add_cppflags -Dsig_t=nosig_t
   1299 ac_cppflags SIG_T
   1300 
   1301 #
   1302 # Environment: signals
   1303 #
   1304 test x"NetBSD" = x"$TARGET_OS" && $e Ignore the compatibility warning.
   1305 
   1306 for what in name list; do
   1307 	uwhat=`upper $what`
   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]); }
   1311 	EOF
   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]); }
   1315 	EOF
   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
   1320 	fi
   1321 	ac_cppflags SYS_SIG$uwhat
   1322 done
   1323 
   1324 ac_test strsignal '!' sys_siglist 0 <<-'EOF'
   1325 	#include <string.h>
   1326 	#include <signal.h>
   1327 	int main(void) { return (strsignal(1)[0]); }
   1328 EOF
   1329 
   1330 #
   1331 # Environment: library functions
   1332 #
   1333 ac_testn flock_ex '' 'flock and mmap' <<-'EOF'
   1334 	#include <sys/types.h>
   1335 	#if HAVE_SYS_FILE_H
   1336 	#include <sys/file.h>
   1337 	#endif
   1338 	#if HAVE_SYS_MMAN_H
   1339 	#include <sys/mman.h>
   1340 	#endif
   1341 	#include <fcntl.h>
   1342 	#include <stdlib.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 :
   1345 	    munmap(NULL, 0)); }
   1346 EOF
   1347 
   1348 ac_test getrusage <<-'EOF'
   1349 	#define MKSH_INCLUDES_ONLY
   1350 	#include "sh.h"
   1351 	int main(void) {
   1352 		struct rusage ru;
   1353 		return (getrusage(RUSAGE_SELF, &ru) +
   1354 		    getrusage(RUSAGE_CHILDREN, &ru));
   1355 	}
   1356 EOF
   1357 
   1358 ac_test killpg <<-'EOF'
   1359 	#include <signal.h>
   1360 	int main(int ac, char *av[]) { return (av[0][killpg(123, ac)]); }
   1361 EOF
   1362 
   1363 ac_test mknod '' 'if to use mknod(), makedev() and friends' <<-'EOF'
   1364 	#define MKSH_INCLUDES_ONLY
   1365 	#include "sh.h"
   1366 	int main(int ac, char *av[]) {
   1367 		dev_t dv;
   1368 		dv = makedev((unsigned int)ac, (unsigned int)av[0][0]);
   1369 		return (mknod(av[0], (mode_t)0, dv) ? (int)major(dv) :
   1370 		    (int)minor(dv));
   1371 	}
   1372 EOF
   1373 
   1374 ac_test mkstemp <<-'EOF'
   1375 	#include <stdlib.h>
   1376 	#include <unistd.h>
   1377 	int main(void) { char tmpl[] = "X"; return (mkstemp(tmpl)); }
   1378 EOF
   1379 
   1380 ac_test nice <<-'EOF'
   1381 	#include <unistd.h>
   1382 	int main(void) { return (nice(4)); }
   1383 EOF
   1384 
   1385 ac_test revoke <<-'EOF'
   1386 	#include <sys/types.h>
   1387 	#if HAVE_LIBUTIL_H
   1388 	#include <libutil.h>
   1389 	#endif
   1390 	#include <unistd.h>
   1391 	int main(int ac, char *av[]) { return (ac + revoke(av[0])); }
   1392 EOF
   1393 
   1394 ac_test setlocale_ctype '' 'setlocale(LC_CTYPE, "")' <<-'EOF'
   1395 	#include <locale.h>
   1396 	#include <stddef.h>
   1397 	int main(void) { return ((int)(ptrdiff_t)(void *)setlocale(LC_CTYPE, "")); }
   1398 EOF
   1399 
   1400 ac_test langinfo_codeset setlocale_ctype 0 'nl_langinfo(CODESET)' <<-'EOF'
   1401 	#include <langinfo.h>
   1402 	#include <stddef.h>
   1403 	int main(void) { return ((int)(ptrdiff_t)(void *)nl_langinfo(CODESET)); }
   1404 EOF
   1405 
   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>
   1411 	#endif
   1412 	#if HAVE_SYS_SELECT_H
   1413 	#include <sys/select.h>
   1414 	#endif
   1415 	#if HAVE_BSTRING_H
   1416 	#include <bstring.h>
   1417 	#endif
   1418 	#include <stddef.h>
   1419 	#include <stdlib.h>
   1420 	#include <string.h>
   1421 	#if HAVE_STRINGS_H
   1422 	#include <strings.h>
   1423 	#endif
   1424 	#include <unistd.h>
   1425 	int main(void) {
   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));
   1429 	}
   1430 EOF
   1431 
   1432 ac_test setresugid <<-'EOF'
   1433 	#include <sys/types.h>
   1434 	#include <unistd.h>
   1435 	int main(void) { setresuid(0,0,0); return (setresgid(0,0,0)); }
   1436 EOF
   1437 
   1438 ac_test setgroups setresugid 0 <<-'EOF'
   1439 	#include <sys/types.h>
   1440 	#if HAVE_GRP_H
   1441 	#include <grp.h>
   1442 	#endif
   1443 	#include <unistd.h>
   1444 	int main(void) { gid_t gid = 0; return (setgroups(0, &gid)); }
   1445 EOF
   1446 
   1447 ac_test strcasestr <<-'EOF'
   1448 	#include <sys/types.h>
   1449 	#include <stddef.h>
   1450 	#include <string.h>
   1451 	#if HAVE_STRINGS_H
   1452 	#include <strings.h>
   1453 	#endif
   1454 	int main(int ac, char *av[]) {
   1455 		return ((int)(ptrdiff_t)(void *)strcasestr(*av, av[ac]));
   1456 	}
   1457 EOF
   1458 
   1459 ac_test strlcpy <<-'EOF'
   1460 	#include <string.h>
   1461 	int main(int ac, char *av[]) { return (strlcpy(*av, av[1],
   1462 	    (size_t)ac)); }
   1463 EOF
   1464 
   1465 #
   1466 # check headers for declarations
   1467 #
   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
   1472 	#include "sh.h"
   1473 	long flock(void);		/* this clashes if defined before */
   1474 	int main(void) { return ((int)flock()); }
   1475 EOF
   1476 ac_test '!' revoke_decl revoke 1 'if revoke() does not need to be declared' <<-'EOF'
   1477 	#define MKSH_INCLUDES_ONLY
   1478 	#include "sh.h"
   1479 	long revoke(void);		/* this clashes if defined before */
   1480 	int main(void) { return ((int)revoke()); }
   1481 EOF
   1482 ac_test sys_siglist_decl sys_siglist 1 'if sys_siglist[] does not need to be declared' <<-'EOF'
   1483 	#define MKSH_INCLUDES_ONLY
   1484 	#include "sh.h"
   1485 	int main(void) { return (sys_siglist[0][0]); }
   1486 EOF
   1487 CC=$save_CC; LDFLAGS=$save_LDFLAGS; LIBS=$save_LIBS
   1488 
   1489 #
   1490 # other checks
   1491 #
   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"
   1495 ac_testdone
   1496 ac_cppflags
   1497 
   1498 #
   1499 # Compiler: Praeprocessor (only if needed)
   1500 #
   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
   1507 	ac_testdone
   1508 fi
   1509 
   1510 #
   1511 # End of mirtoconf checks
   1512 #
   1513 $e ... done.
   1514 
   1515 # Some operating systems have ancient versions of ed(1) writing
   1516 # the character count to standard output; cope for that
   1517 echo wq >x
   1518 ed x <x 2>/dev/null | grep 3 >/dev/null 2>&1 && \
   1519     check_categories="$check_categories $oldish_ed"
   1520 rmf x vv.out
   1521 
   1522 if test 0 = $HAVE_SYS_SIGNAME; then
   1523 	if test 1 = $HAVE_CPP_DD; then
   1524 		$e Generating list of signal names...
   1525 	else
   1526 		$e No list of signal names available via cpp. Falling back...
   1527 	fi
   1528 	sigseen=:
   1529 	echo '#include <signal.h>
   1530 #ifndef NSIG
   1531 #if defined(_NSIG)
   1532 #define NSIG _NSIG
   1533 #elif defined(SIGMAX)
   1534 #define NSIG (SIGMAX+1)
   1535 #endif
   1536 #endif
   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/'`
   1540 	case $NSIG in
   1541 	*[\ \(\)+-]*) NSIG=`awk "BEGIN { print $NSIG }"` ;;
   1542 	esac
   1543 	printf=printf
   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" | \
   1559 		    grep mksh_cfg: | \
   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
   1564 		case $sigseen in
   1565 		*:$nr:*) ;;
   1566 		*)	echo "		{ \"$name\", $nr },"
   1567 			sigseen=$sigseen$nr:
   1568 			$printf "$name=$nr " >&2
   1569 			;;
   1570 		esac
   1571 	done 2>&1 >signames.inc
   1572 	rmf conftest.c
   1573 	$e done.
   1574 fi
   1575 
   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"
   1580 
   1581 $e $bi$me: Finished configuration testing, now producing output.$ao
   1582 
   1583 files=
   1584 objs=
   1585 sp=
   1586 case $curdir in
   1587 *\ *)	echo "#!./mksh" >test.sh ;;
   1588 *)	echo "#!$curdir/mksh" >test.sh ;;
   1589 esac
   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 ;;
   1600 	(P)	Pflag=1 ;;
   1601 	(p)	pflag=\$OPTARG ;;
   1602 	(s)	sflag=\$OPTARG ;;
   1603 	(t)	uset=1; tflag=\$OPTARG ;;
   1604 	(v)	vflag=1 ;;
   1605 	(*)	xflag=1 ;;
   1606 	}
   1607 	done
   1608 	shift \$((OPTIND - 1))
   1609 	set -A args -- '$srcdir/check.pl' -p "\$pflag" -s "\$sflag"
   1610 	x=
   1611 	for y in "\${check_categories[@]}"; do
   1612 		x=\$x,\$y
   1613 	done
   1614 	if [[ -n \$x ]]; then
   1615 		args[\${#args[*]}]=-C
   1616 		args[\${#args[*]}]=\${x#,}
   1617 	fi
   1618 	if (( usee )); then
   1619 		args[\${#args[*]}]=-e
   1620 		args[\${#args[*]}]=\$eflag
   1621 	fi
   1622 	(( Pflag )) && args[\${#args[*]}]=-P
   1623 	if (( uset )); then
   1624 		args[\${#args[*]}]=-t
   1625 		args[\${#args[*]}]=\$tflag
   1626 	fi
   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
   1641 	done
   1642 	exec \$perli "\${args[@]}" "\$@"$tsts
   1643 EOF
   1644 chmod 755 test.sh
   1645 if test $cm = llvm; then
   1646 	emitbc="-emit-llvm -c"
   1647 elif test $cm = dragonegg; then
   1648 	emitbc="-S -flto"
   1649 else
   1650 	emitbc=-c
   1651 fi
   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"
   1657 	sp=' '
   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"
   1663 	else
   1664 		objs="$objs$sp${op}o"
   1665 	fi
   1666 done
   1667 case $cm in
   1668 dragonegg|llvm)
   1669 	echo "rm -f mksh.s" >>Rebuild.sh
   1670 	echo "llvm-link -o - $objs | opt $optflags | llc -o mksh.s" >>Rebuild.sh
   1671 	lobjs=mksh.s
   1672 	;;
   1673 *)
   1674 	lobjs=$objs
   1675 	;;
   1676 esac
   1677 case $tcfn in
   1678 a.exe)	mkshexe=mksh.exe ;;
   1679 *)	mkshexe=mksh ;;
   1680 esac
   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
   1689 
   1690 PROG=		$mkshexe
   1691 MAN=		mksh.1
   1692 SRCS=		$SRCS
   1693 SRCS_FP=	$files
   1694 OBJS_BP=	$objs
   1695 INDSRCS=	$extras
   1696 NONSRCS_INST=	dot.mkshrc \$(MAN)
   1697 NONSRCS_NOINST=	Build.sh Makefile Rebuild.sh check.pl check.t test.sh
   1698 CC=		$CC
   1699 CFLAGS=		$CFLAGS
   1700 CPPFLAGS=	$CPPFLAGS
   1701 LDFLAGS=	$LDFLAGS
   1702 LIBS=		$LIBS
   1703 
   1704 # not BSD make only:
   1705 #VPATH=		$srcdir
   1706 #all: \$(PROG)
   1707 #\$(PROG): \$(OBJS_BP)
   1708 #	\$(CC) \$(CFLAGS) \$(LDFLAGS) -o \$@ \$(OBJS_BP) \$(LIBS)
   1709 #\$(OBJS_BP): \$(SRCS_FP) \$(NONSRCS)
   1710 #.c.o:
   1711 #	\$(CC) \$(CFLAGS) \$(CPPFLAGS) -c \$<
   1712 
   1713 # for all make variants:
   1714 #REGRESS_FLAGS=	-v
   1715 #regress:
   1716 #	./test.sh \$(REGRESS_FLAGS)
   1717 
   1718 # for BSD make only:
   1719 #.PATH: $srcdir
   1720 #.include <bsd.prog.mk>
   1721 EOF
   1722 	$e
   1723 	$e Generated Makefrag.inc successfully.
   1724 	exit 0
   1725 fi
   1726 if test $cm = combine; then
   1727 	objs="-o $mkshexe"
   1728 	for file in $SRCS; do
   1729 		test -f $file || file=$srcdir/$file
   1730 		objs="$objs $file"
   1731 	done
   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" &
   1738 	done
   1739 	wait
   1740 else
   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
   1749 		fi
   1750 	done
   1751 fi
   1752 case $cm in
   1753 dragonegg|llvm)
   1754 	rmf mksh.s
   1755 	v "llvm-link -o - $objs | opt $optflags | llc -o mksh.s"
   1756 	;;
   1757 esac
   1758 tcfn=$mkshexe
   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" || \
   1762     rmf mksh.cat1
   1763 test 0 = $eq && v size $tcfn
   1764 i=install
   1765 test -f /usr/ucb/$i && i=/usr/ucb/$i
   1766 test 1 = $eq && e=:
   1767 $e
   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/"
   1772 $e
   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"
   1777 	$e or
   1778 fi
   1779 $e "# $i -c -o root -g bin -m 444 mksh.1 /usr/share/man/man1/mksh.1"
   1780 $e
   1781 $e Run the regression test suite: ./test.sh
   1782 $e Please also read the sample file dot.mkshrc and the fine manual.
   1783 exit 0
   1784