• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.763 2020/09/04 21:01:37 tg Exp $'
3#-
4# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
5#		2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019,
6#		2020
7#	mirabilos <m@mirbsd.org>
8#
9# Provided that these terms and disclaimer and all copyright notices
10# are retained or reproduced in an accompanying document, permission
11# is granted to deal in this work without restriction, including un-
12# limited rights to use, publicly perform, distribute, sell, modify,
13# merge, give away, or sublicence.
14#
15# This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
16# the utmost extent permitted by applicable law, neither express nor
17# implied; without malicious intent or gross negligence. In no event
18# may a licensor, author or contributor be held liable for indirect,
19# direct, other damage, loss, or other issues arising in any way out
20# of dealing in the work, even if advised of the possibility of such
21# damage or existence of a defect, except proven that it results out
22# of said person's immediate fault when using the work as intended.
23#-
24# People analysing the output must whitelist conftest.c for any kind
25# of compiler warning checks (mirtoconf is by design not quiet).
26#
27# Used environment documentation is at the end of this file.
28
29LC_ALL=C; LANGUAGE=C
30export LC_ALL; unset LANGUAGE
31
32case $ZSH_VERSION:$VERSION in
33:zsh*) ZSH_VERSION=2 ;;
34esac
35
36if test -n "${ZSH_VERSION+x}" && (emulate sh) >/dev/null 2>&1; then
37	emulate sh
38	NULLCMD=:
39fi
40
41if test -d /usr/xpg4/bin/. >/dev/null 2>&1; then
42	# Solaris: some of the tools have weird behaviour, use portable ones
43	PATH=/usr/xpg4/bin:$PATH
44	export PATH
45fi
46
47nl='
48'
49safeIFS='	'
50safeIFS=" $safeIFS$nl"
51IFS=$safeIFS
52allu=QWERTYUIOPASDFGHJKLZXCVBNM
53alll=qwertyuiopasdfghjklzxcvbnm
54alln=0123456789
55alls=______________________________________________________________
56
57test_n() {
58	test x"$1" = x"" || return 0
59	return 1
60}
61
62test_z() {
63	test x"$1" = x""
64}
65
66case `echo a | tr '\201' X` in
67X)
68	# EBCDIC build system
69	lfcr='\n\r'
70	;;
71*)
72	lfcr='\012\015'
73	;;
74esac
75
76genopt_die() {
77	if test_z "$1"; then
78		echo >&2 "E: invalid input in '$srcfile': '$line'"
79	else
80		echo >&2 "E: $*"
81		echo >&2 "N: in '$srcfile': '$line'"
82	fi
83	rm -f "$bn.gen"
84	exit 1
85}
86
87genopt_soptc() {
88	optc=`echo "$line" | sed 's/^[<>]\(.\).*$/\1/'`
89	test x"$optc" = x'|' && return
90	optclo=`echo "$optc" | tr $allu $alll`
91	if test x"$optc" = x"$optclo"; then
92		islo=1
93	else
94		islo=0
95	fi
96	sym=`echo "$line" | sed 's/^[<>]/|/'`
97	o_str=$o_str$nl"<$optclo$islo$sym"
98}
99
100genopt_scond() {
101	case x$cond in
102	x)
103		cond=
104		;;
105	x*' '*)
106		cond=`echo "$cond" | sed 's/^ //'`
107		cond="#if $cond"
108		;;
109	x'!'*)
110		cond=`echo "$cond" | sed 's/^!//'`
111		cond="#ifndef $cond"
112		;;
113	x*)
114		cond="#ifdef $cond"
115		;;
116	esac
117}
118
119do_genopt() {
120	srcfile=$1
121	test -f "$srcfile" || genopt_die Source file \$srcfile not set.
122	bn=`basename "$srcfile" | sed 's/.opt$//'`
123	o_hdr='/* +++ GENERATED FILE +++ DO NOT EDIT +++ */'
124	o_gen=
125	o_str=
126	o_sym=
127	ddefs=
128	state=0
129	exec <"$srcfile"
130	IFS=
131	while IFS= read line; do
132		IFS=$safeIFS
133		case $state:$line in
134		2:'|'*)
135			# end of input
136			o_sym=`echo "$line" | sed 's/^.//'`
137			o_gen=$o_gen$nl"#undef F0"
138			o_gen=$o_gen$nl"#undef FN"
139			o_gen=$o_gen$ddefs
140			state=3
141			;;
142		1:@@)
143			# start of data block
144			o_gen=$o_gen$nl"#endif"
145			o_gen=$o_gen$nl"#ifndef F0"
146			o_gen=$o_gen$nl"#define F0 FN"
147			o_gen=$o_gen$nl"#endif"
148			state=2
149			;;
150		*:@@*)
151			genopt_die ;;
152		0:/\*-|0:\ \**|0:)
153			o_hdr=$o_hdr$nl$line
154			;;
155		0:@*|1:@*)
156			# start of a definition block
157			sym=`echo "$line" | sed 's/^@//'`
158			if test $state = 0; then
159				o_gen=$o_gen$nl"#if defined($sym)"
160			else
161				o_gen=$o_gen$nl"#elif defined($sym)"
162			fi
163			ddefs="$ddefs$nl#undef $sym"
164			state=1
165			;;
166		0:*|3:*)
167			genopt_die ;;
168		1:*)
169			# definition line
170			o_gen=$o_gen$nl$line
171			;;
172		2:'<'*'|'*)
173			genopt_soptc
174			;;
175		2:'>'*'|'*)
176			genopt_soptc
177			cond=`echo "$line" | sed 's/^[^|]*|//'`
178			genopt_scond
179			case $optc in
180			'|') optc=0 ;;
181			*) optc=\'$optc\' ;;
182			esac
183			IFS= read line || genopt_die Unexpected EOF
184			IFS=$safeIFS
185			test_z "$cond" || o_gen=$o_gen$nl"$cond"
186			o_gen=$o_gen$nl"$line, $optc)"
187			test_z "$cond" || o_gen=$o_gen$nl"#endif"
188			;;
189		esac
190	done
191	case $state:$o_sym in
192	3:) genopt_die Expected optc sym at EOF ;;
193	3:*) ;;
194	*) genopt_die Missing EOF marker ;;
195	esac
196	echo "$o_str" | sort | while IFS='|' read x opts cond; do
197		IFS=$safeIFS
198		test_n "$x" || continue
199		genopt_scond
200		test_z "$cond" || echo "$cond"
201		echo "\"$opts\""
202		test_z "$cond" || echo "#endif"
203	done | {
204		echo "$o_hdr"
205		echo "#ifndef $o_sym$o_gen"
206		echo "#else"
207		cat
208		echo "#undef $o_sym"
209		echo "#endif"
210	} >"$bn.gen"
211	IFS=$safeIFS
212	return 0
213}
214
215if test x"$BUILDSH_RUN_GENOPT" = x"1"; then
216	set x -G "$srcfile"
217	shift
218fi
219if test x"$1" = x"-G"; then
220	do_genopt "$2"
221	exit $?
222fi
223
224echo "For the build logs, demonstrate that /dev/null and /dev/tty exist:"
225ls -l /dev/null /dev/tty
226
227v() {
228	$e "$*"
229	eval "$@"
230}
231
232vv() {
233	_c=$1
234	shift
235	$e "\$ $*" 2>&1
236	eval "$@" >vv.out 2>&1
237	sed "s^${_c} " <vv.out
238}
239
240vq() {
241	eval "$@"
242}
243
244rmf() {
245	for _f in "$@"; do
246		case $_f in
247		*.1|*.faq|*.ico) ;;
248		*) rm -f "$_f" ;;
249		esac
250	done
251}
252
253tcfn=no
254bi=
255ui=
256ao=
257fx=
258me=`basename "$0"`
259orig_CFLAGS=$CFLAGS
260phase=x
261oldish_ed=stdout-ed,no-stderr-ed
262
263if test -t 1; then
264	bi=''
265	ui=''
266	ao=''
267fi
268
269upper() {
270	echo :"$@" | sed 's/^://' | tr $alll $allu
271}
272
273# clean up after ac_testrun()
274ac_testdone() {
275	eval HAVE_$fu=$fv
276	fr=no
277	test 0 = $fv || fr=yes
278	$e "$bi==> $fd...$ao $ui$fr$ao$fx"
279	fx=
280}
281
282# ac_cache label: sets f, fu, fv?=0
283ac_cache() {
284	f=$1
285	fu=`upper $f`
286	eval fv=\$HAVE_$fu
287	case $fv in
288	0|1)
289		fx=' (cached)'
290		return 0
291		;;
292	esac
293	fv=0
294	return 1
295}
296
297# ac_testinit label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput
298# returns 1 if value was cached/implied, 0 otherwise: call ac_testdone
299ac_testinit() {
300	if ac_cache $1; then
301		test x"$2" = x"!" && shift
302		test x"$2" = x"" || shift
303		fd=${3-$f}
304		ac_testdone
305		return 1
306	fi
307	fc=0
308	if test x"$2" = x""; then
309		ft=1
310	else
311		if test x"$2" = x"!"; then
312			fc=1
313			shift
314		fi
315		eval ft=\$HAVE_`upper $2`
316		shift
317	fi
318	fd=${3-$f}
319	if test $fc = "$ft"; then
320		fv=$2
321		fx=' (implied)'
322		ac_testdone
323		return 1
324	fi
325	$e ... $fd
326	return 0
327}
328
329# pipe .c | ac_test[n] [!] label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput
330ac_testnnd() {
331	if test x"$1" = x"!"; then
332		fr=1
333		shift
334	else
335		fr=0
336	fi
337	ac_testinit "$@" || return 1
338	cat >conftest.c
339	vv ']' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN conftest.c $LIBS $ccpr"
340	test $tcfn = no && test -f a.out && tcfn=a.out
341	test $tcfn = no && test -f a.exe && tcfn=a.exe
342	test $tcfn = no && test -f conftest.exe && tcfn=conftest.exe
343	test $tcfn = no && test -f conftest && tcfn=conftest
344	if test -f $tcfn; then
345		test 1 = $fr || fv=1
346	else
347		test 0 = $fr || fv=1
348	fi
349	vscan=
350	if test $phase = u; then
351		test $ct = gcc && vscan='unrecogni[sz]ed'
352		test $ct = hpcc && vscan='unsupported'
353		test $ct = pcc && vscan='unsupported'
354		test $ct = sunpro && vscan='-e ignored -e turned.off'
355	fi
356	test_n "$vscan" && grep $vscan vv.out >/dev/null 2>&1 && fv=$fr
357	return 0
358}
359ac_testn() {
360	ac_testnnd "$@" || return
361	rmf conftest.c conftest.o ${tcfn}* vv.out
362	ac_testdone
363}
364
365# ac_ifcpp cppexpr [!] label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput
366ac_ifcpp() {
367	expr=$1; shift
368	ac_testn "$@" <<-EOF
369		#include <unistd.h>
370		extern int thiswillneverbedefinedIhope(void);
371		int main(void) { return (isatty(0) +
372		#$expr
373		    0
374		#else
375		/* force a failure: expr is false */
376		    thiswillneverbedefinedIhope()
377		#endif
378		    ); }
379EOF
380	test x"$1" = x"!" && shift
381	f=$1
382	fu=`upper $f`
383	eval fv=\$HAVE_$fu
384	test x"$fv" = x"1"
385}
386
387add_cppflags() {
388	CPPFLAGS="$CPPFLAGS $*"
389}
390
391ac_cppflags() {
392	test x"$1" = x"" || fu=$1
393	fv=$2
394	test x"$2" = x"" && eval fv=\$HAVE_$fu
395	add_cppflags -DHAVE_$fu=$fv
396}
397
398ac_test() {
399	ac_testn "$@"
400	ac_cppflags
401}
402
403# ac_flags [-] add varname cflags [text] [ldflags]
404ac_flags() {
405	if test x"$1" = x"-"; then
406		shift
407		hf=1
408	else
409		hf=0
410	fi
411	fa=$1
412	vn=$2
413	f=$3
414	ft=$4
415	fl=$5
416	test x"$ft" = x"" && ft="if $f can be used"
417	save_CFLAGS=$CFLAGS
418	CFLAGS="$CFLAGS $f"
419	save_LDFLAGS=$LDFLAGS
420	test_z "$fl" || LDFLAGS="$LDFLAGS $fl"
421	if test 1 = $hf; then
422		ac_testn can_$vn '' "$ft"
423	else
424		ac_testn can_$vn '' "$ft" <<-'EOF'
425			/* evil apo'stroph in comment test */
426			#include <unistd.h>
427			int main(void) { return (isatty(0)); }
428		EOF
429		#'
430	fi
431	eval fv=\$HAVE_CAN_`upper $vn`
432	test_z "$fl" || test 11 = $fa$fv || LDFLAGS=$save_LDFLAGS
433	test 11 = $fa$fv || CFLAGS=$save_CFLAGS
434}
435
436# ac_header [!] header [prereq ...]
437ac_header() {
438	if test x"$1" = x"!"; then
439		na=1
440		shift
441	else
442		na=0
443	fi
444	hf=$1; shift
445	hv=`echo "$hf" | tr -d "$lfcr" | tr -c $alll$allu$alln $alls`
446	echo "/* NeXTstep bug workaround */" >x
447	for i
448	do
449		case $i in
450		_time)
451			echo '#if HAVE_BOTH_TIME_H' >>x
452			echo '#include <sys/time.h>' >>x
453			echo '#include <time.h>' >>x
454			echo '#elif HAVE_SYS_TIME_H' >>x
455			echo '#include <sys/time.h>' >>x
456			echo '#elif HAVE_TIME_H' >>x
457			echo '#include <time.h>' >>x
458			echo '#endif' >>x
459			;;
460		*)
461			echo "#include <$i>" >>x
462			;;
463		esac
464	done
465	echo "#include <$hf>" >>x
466	echo '#include <unistd.h>' >>x
467	echo 'int main(void) { return (isatty(0)); }' >>x
468	ac_testn "$hv" "" "<$hf>" <x
469	rmf x
470	test 1 = $na || ac_cppflags
471}
472
473addsrcs() {
474	if test x"$1" = x"!"; then
475		fr=0
476		shift
477	else
478		fr=1
479	fi
480	eval i=\$$1
481	test $fr = "$i" && case " $SRCS " in
482	*\ $2\ *)	;;
483	*)		SRCS="$SRCS $2" ;;
484	esac
485}
486
487
488curdir=`pwd` srcdir=`dirname "$0" 2>/dev/null`
489case x$srcdir in
490x)
491	srcdir=.
492	;;
493*\ *|*"	"*|*"$nl"*)
494	echo >&2 Source directory should not contain space or tab or newline.
495	echo >&2 Errors may occur.
496	;;
497*"'"*)
498	echo Source directory must not contain single quotes.
499	exit 1
500	;;
501esac
502dstversion=`sed -n '/define MKSH_VERSION/s/^.*"\([^"]*\)".*$/\1/p' "$srcdir/sh.h"`
503add_cppflags -DMKSH_BUILDSH
504
505e=echo
506r=0
507eq=0
508pm=0
509cm=normal
510optflags=-std-compile-opts
511check_categories=
512last=
513tfn=
514legacy=0
515textmode=0
516ebcdic=false
517
518for i
519do
520	case $last:$i in
521	c:dragonegg|c:llvm)
522		cm=$i
523		last=
524		;;
525	c:*)
526		echo "$me: Unknown option -c '$i'!" >&2
527		exit 1
528		;;
529	o:*)
530		optflags=$i
531		last=
532		;;
533	:-c)
534		last=c
535		;;
536	:-E)
537		ebcdic=true
538		;;
539	:-G)
540		echo "$me: Do not call me with '-G'!" >&2
541		exit 1
542		;;
543	:-g)
544		# checker, debug, valgrind build
545		add_cppflags -DDEBUG
546		CFLAGS="$CFLAGS -g3 -fno-builtin"
547		;;
548	:-j)
549		pm=1
550		;;
551	:-L)
552		legacy=1
553		;;
554	:+L)
555		legacy=0
556		;;
557	:-M)
558		cm=makefile
559		;;
560	:-O)
561		optflags=-std-compile-opts
562		;;
563	:-o)
564		last=o
565		;;
566	:-Q)
567		eq=1
568		;;
569	:-r)
570		r=1
571		;;
572	:-T)
573		textmode=1
574		;;
575	:+T)
576		textmode=0
577		;;
578	:-v)
579		echo "Build.sh $srcversion"
580		echo "for mksh $dstversion"
581		exit 0
582		;;
583	:*)
584		echo "$me: Unknown option '$i'!" >&2
585		exit 1
586		;;
587	*)
588		echo "$me: Unknown option -'$last' '$i'!" >&2
589		exit 1
590		;;
591	esac
592done
593if test_n "$last"; then
594	echo "$me: Option -'$last' not followed by argument!" >&2
595	exit 1
596fi
597
598test_n "$tfn" || if test $legacy = 0; then
599	tfn=mksh
600else
601	tfn=lksh
602fi
603if test -d $tfn || test -d $tfn.exe; then
604	echo "$me: Error: ./$tfn is a directory!" >&2
605	exit 1
606fi
607rmf a.exe* a.out* conftest.c conftest.exe* *core core.* ${tfn}* *.bc *.dbg \
608    *.ll *.o *.gen *.cat1 Rebuild.sh lft no signames.inc test.sh x vv.out *.htm
609
610SRCS="lalloc.c edit.c eval.c exec.c expr.c funcs.c histrap.c jobs.c"
611SRCS="$SRCS lex.c main.c misc.c shf.c syn.c tree.c var.c"
612
613if test $legacy = 0; then
614	check_categories="$check_categories shell:legacy-no int:32"
615else
616	check_categories="$check_categories shell:legacy-yes"
617	add_cppflags -DMKSH_LEGACY_MODE
618fi
619
620if $ebcdic; then
621	add_cppflags -DMKSH_EBCDIC
622fi
623
624if test $textmode = 0; then
625	check_categories="$check_categories shell:textmode-no shell:binmode-yes"
626else
627	check_categories="$check_categories shell:textmode-yes shell:binmode-no"
628	add_cppflags -DMKSH_WITH_TEXTMODE
629fi
630
631if test x"$srcdir" = x"."; then
632	CPPFLAGS="-I. $CPPFLAGS"
633else
634	CPPFLAGS="-I. -I'$srcdir' $CPPFLAGS"
635fi
636test_z "$LDSTATIC" || if test_z "$LDFLAGS"; then
637	LDFLAGS=$LDSTATIC
638else
639	LDFLAGS="$LDFLAGS $LDSTATIC"
640fi
641
642if test_z "$TARGET_OS"; then
643	x=`uname -s 2>/dev/null || uname`
644	test x"$x" = x"`uname -n 2>/dev/null`" || TARGET_OS=$x
645fi
646if test_z "$TARGET_OS"; then
647	echo "$me: Set TARGET_OS, your uname is broken!" >&2
648	exit 1
649fi
650oswarn=
651ccpc=-Wc,
652ccpl=-Wl,
653tsts=
654ccpr='|| for _f in ${tcfn}*; do case $_f in *.1|*.faq|*.ico) ;; *) rm -f "$_f" ;; esac; done'
655
656# Evil hack
657if test x"$TARGET_OS" = x"Android"; then
658	check_categories="$check_categories android"
659	TARGET_OS=Linux
660fi
661
662# Evil OS
663if test x"$TARGET_OS" = x"Minix"; then
664	echo >&2 "
665WARNING: additional checks before running Build.sh required!
666You can avoid these by calling Build.sh correctly, see below.
667"
668	cat >conftest.c <<'EOF'
669#include <sys/types.h>
670const char *
671#ifdef _NETBSD_SOURCE
672ct="Ninix3"
673#else
674ct="Minix3"
675#endif
676;
677EOF
678	ct=unknown
679	vv ']' "${CC-cc} -E $CFLAGS $CPPFLAGS $NOWARN conftest.c | grep ct= | tr -d \\\\015 >x"
680	sed 's/^/[ /' x
681	eval `cat x`
682	rmf x vv.out
683	case $ct in
684	Minix3|Ninix3)
685		echo >&2 "
686Warning: you set TARGET_OS to $TARGET_OS but that is ambiguous.
687Please set it to either Minix3 or Ninix3, whereas the latter is
688all versions of Minix with even partial NetBSD(R) userland. The
689value determined from your compiler for the current compilation
690(which may be wrong) is: $ct
691"
692		TARGET_OS=$ct
693		;;
694	*)
695		echo >&2 "
696Warning: you set TARGET_OS to $TARGET_OS but that is ambiguous.
697Please set it to either Minix3 or Ninix3, whereas the latter is
698all versions of Minix with even partial NetBSD(R) userland. The
699proper value couldn't be determined, continue at your own risk.
700"
701		;;
702	esac
703fi
704
705# Configuration depending on OS revision, on OSes that need them
706case $TARGET_OS in
707NEXTSTEP)
708	test_n "$TARGET_OSREV" || TARGET_OSREV=`hostinfo 2>&1 | \
709	    grep 'NeXT Mach [0-9][0-9.]*:' | \
710	    sed 's/^.*NeXT Mach \([0-9][0-9.]*\):.*$/\1/'`
711	;;
712QNX|SCO_SV)
713	test_n "$TARGET_OSREV" || TARGET_OSREV=`uname -r`
714	;;
715esac
716
717# Configuration depending on OS name
718case $TARGET_OS in
719386BSD)
720	: "${HAVE_CAN_OTWO=0}"
721	add_cppflags -DMKSH_NO_SIGSETJMP
722	add_cppflags -DMKSH_TYPEDEF_SIG_ATOMIC_T=int
723	;;
724A/UX)
725	add_cppflags -D_POSIX_SOURCE
726	: "${CC=gcc}"
727	: "${LIBS=-lposix}"
728	# GCC defines AUX but cc nothing
729	add_cppflags -D__A_UX__
730	;;
731AIX)
732	add_cppflags -D_ALL_SOURCE
733	: "${HAVE_SETLOCALE_CTYPE=0}"
734	;;
735BeOS)
736	case $KSH_VERSION in
737	*MIRBSD\ KSH*)
738		oswarn="; it has minor issues"
739		;;
740	*)
741		oswarn="; you must recompile mksh with"
742		oswarn="$oswarn${nl}itself in a second stage"
743		;;
744	esac
745	# BeOS has no real tty either
746	add_cppflags -DMKSH_UNEMPLOYED
747	add_cppflags -DMKSH_DISABLE_TTY_WARNING
748	# BeOS doesn't have different UIDs and GIDs
749	add_cppflags -DMKSH__NO_SETEUGID
750	;;
751BSD/OS)
752	: "${HAVE_SETLOCALE_CTYPE=0}"
753	;;
754Coherent)
755	oswarn="; it has major issues"
756	add_cppflags -DMKSH__NO_SYMLINK
757	check_categories="$check_categories nosymlink"
758	add_cppflags -DMKSH__NO_SETEUGID
759	add_cppflags -DMKSH_DISABLE_TTY_WARNING
760	;;
761CYGWIN*)
762	: "${HAVE_SETLOCALE_CTYPE=0}"
763	;;
764Darwin)
765	add_cppflags -D_DARWIN_C_SOURCE
766	;;
767DragonFly)
768	;;
769FreeBSD)
770	;;
771FreeMiNT)
772	oswarn="; it has minor issues"
773	add_cppflags -D_GNU_SOURCE
774	: "${HAVE_SETLOCALE_CTYPE=0}"
775	;;
776GNU)
777	case $CC in
778	*tendracc*) ;;
779	*) add_cppflags -D_GNU_SOURCE ;;
780	esac
781	add_cppflags -DSETUID_CAN_FAIL_WITH_EAGAIN
782	# define MKSH__NO_PATH_MAX to use Hurd-only functions
783	add_cppflags -DMKSH__NO_PATH_MAX
784	;;
785GNU/kFreeBSD)
786	case $CC in
787	*tendracc*) ;;
788	*) add_cppflags -D_GNU_SOURCE ;;
789	esac
790	add_cppflags -DSETUID_CAN_FAIL_WITH_EAGAIN
791	;;
792Haiku)
793	add_cppflags -DMKSH_ASSUME_UTF8
794	HAVE_ISSET_MKSH_ASSUME_UTF8=1
795	HAVE_ISOFF_MKSH_ASSUME_UTF8=0
796	;;
797OpenHarmony)
798	add_cppflags -D_GNU_SOURCE
799	add_cppflags -DMKSH_NO_SIGSETJMP
800	add_cppflags -DMKSH_DISABLE_TTY_WARNING
801	: "${HAVE_STRLCPY=0}"
802	: "${HAVE_REVOKE=0}"
803	: "${HAVE_CAN_FSTACKPROTECTORSTRONG=1}"
804	: "${MKSH_SMALL=1}"
805	: "${MKSH_SMALL_BUT_FAST=0}"
806	: "${MKSH_ASSUME_UTF8=1}"
807	: "${MKSH_S_NOVI=1}"
808	: "${MKSH_UNLIMITED=1}"
809	;;
810Harvey)
811	add_cppflags -D_POSIX_SOURCE
812	add_cppflags -D_LIMITS_EXTENSION
813	add_cppflags -D_BSD_EXTENSION
814	add_cppflags -D_SUSV2_SOURCE
815	add_cppflags -D_GNU_SOURCE
816	add_cppflags -DMKSH_ASSUME_UTF8
817	HAVE_ISSET_MKSH_ASSUME_UTF8=1
818	HAVE_ISOFF_MKSH_ASSUME_UTF8=0
819	add_cppflags -DMKSH__NO_SYMLINK
820	check_categories="$check_categories nosymlink"
821	add_cppflags -DMKSH_NO_CMDLINE_EDITING
822	add_cppflags -DMKSH__NO_SETEUGID
823	oswarn=' and will currently not work'
824	add_cppflags -DMKSH_UNEMPLOYED
825	add_cppflags -DMKSH_NOPROSPECTOFWORK
826	# these taken from Harvey-OS github and need re-checking
827	add_cppflags -D_setjmp=setjmp -D_longjmp=longjmp
828	: "${HAVE_CAN_NO_EH_FRAME=0}"
829	: "${HAVE_CAN_FNOSTRICTALIASING=0}"
830	: "${HAVE_CAN_FSTACKPROTECTORSTRONG=0}"
831	;;
832HP-UX)
833	;;
834Interix)
835	ccpc='-X '
836	ccpl='-Y '
837	add_cppflags -D_ALL_SOURCE
838	: "${LIBS=-lcrypt}"
839	: "${HAVE_SETLOCALE_CTYPE=0}"
840	;;
841IRIX*)
842	: "${HAVE_SETLOCALE_CTYPE=0}"
843	;;
844Jehanne)
845	add_cppflags -DMKSH_ASSUME_UTF8
846	HAVE_ISSET_MKSH_ASSUME_UTF8=1
847	HAVE_ISOFF_MKSH_ASSUME_UTF8=0
848	add_cppflags -DMKSH__NO_SYMLINK
849	check_categories="$check_categories nosymlink"
850	add_cppflags -DMKSH_NO_CMDLINE_EDITING
851	add_cppflags -DMKSH_DISABLE_REVOKE_WARNING
852	add_cppflags '-D_PATH_DEFPATH=\"/cmd\"'
853	add_cppflags '-DMKSH_DEFAULT_EXECSHELL=\"/cmd/mksh\"'
854	add_cppflags '-DMKSH_DEFAULT_PROFILEDIR=\"/cfg/mksh\"'
855	add_cppflags '-DMKSH_ENVDIR=\"/env\"'
856	SRCS="$SRCS jehanne.c"
857	;;
858Linux)
859	case $CC in
860	*tendracc*) ;;
861	*) add_cppflags -D_GNU_SOURCE ;;
862	esac
863	add_cppflags -DSETUID_CAN_FAIL_WITH_EAGAIN
864	: "${HAVE_REVOKE=0}"
865	;;
866LynxOS)
867	oswarn="; it has minor issues"
868	;;
869midipix)
870	add_cppflags -D_GNU_SOURCE
871	# their Perl (currently…) identifies as os:linux ☹
872	check_categories="$check_categories os:midipix"
873	;;
874MidnightBSD)
875	;;
876Minix-vmd)
877	add_cppflags -DMKSH__NO_SETEUGID
878	add_cppflags -DMKSH_UNEMPLOYED
879	add_cppflags -D_MINIX_SOURCE
880	oldish_ed=no-stderr-ed		# no /bin/ed, maybe see below
881	: "${HAVE_SETLOCALE_CTYPE=0}"
882	;;
883Minix3)
884	add_cppflags -DMKSH_UNEMPLOYED
885	add_cppflags -D_POSIX_SOURCE -D_POSIX_1_SOURCE=2 -D_MINIX
886	oldish_ed=no-stderr-ed		# /usr/bin/ed(!) is broken
887	: "${HAVE_SETLOCALE_CTYPE=0}${MKSH_UNLIMITED=1}" #XXX recheck ulimit
888	;;
889MirBSD)
890	;;
891MSYS_*)
892	add_cppflags -DMKSH_ASSUME_UTF8=0
893	HAVE_ISSET_MKSH_ASSUME_UTF8=1
894	HAVE_ISOFF_MKSH_ASSUME_UTF8=1
895	# almost same as CYGWIN* (from RT|Chatzilla)
896	: "${HAVE_SETLOCALE_CTYPE=0}"
897	# broken on this OE (from ir0nh34d)
898	: "${HAVE_STDINT_H=0}"
899	;;
900NetBSD)
901	;;
902NEXTSTEP)
903	add_cppflags -D_NEXT_SOURCE
904	add_cppflags -D_POSIX_SOURCE
905	: "${AWK=gawk}"
906	: "${CC=cc -posix}"
907	add_cppflags -DMKSH_NO_SIGSETJMP
908	# NeXTstep cannot get a controlling tty
909	add_cppflags -DMKSH_UNEMPLOYED
910	case $TARGET_OSREV in
911	4.2*)
912		# OpenStep 4.2 is broken by default
913		oswarn="; it needs libposix.a"
914		;;
915	esac
916	;;
917Ninix3)
918	# similar to Minix3
919	add_cppflags -DMKSH_UNEMPLOYED
920	: "${MKSH_UNLIMITED=1}" #XXX recheck ulimit
921	# but no idea what else could be needed
922	oswarn="; it has unknown issues"
923	;;
924OpenBSD)
925	: "${HAVE_SETLOCALE_CTYPE=0}"
926	;;
927OS/2)
928	add_cppflags -DMKSH_ASSUME_UTF8=0
929	HAVE_ISSET_MKSH_ASSUME_UTF8=1
930	HAVE_ISOFF_MKSH_ASSUME_UTF8=1
931	HAVE_TERMIOS_H=0
932	HAVE_MKNOD=0	# setmode() incompatible
933	check_categories="$check_categories nosymlink"
934	: "${CC=gcc}"
935	: "${SIZE=: size}"
936	SRCS="$SRCS os2.c"
937	add_cppflags -DMKSH_UNEMPLOYED
938	add_cppflags -DMKSH_NOPROSPECTOFWORK
939	add_cppflags -DMKSH_DOSPATH
940	: "${MKSH_UNLIMITED=1}"
941	if test $textmode = 0; then
942		x='dis'
943		y='standard OS/2 tools'
944	else
945		x='en'
946		y='standard Unix mksh and other tools'
947	fi
948	echo >&2 "
949OS/2 Note: mksh can be built with or without 'textmode'.
950Without 'textmode' it will behave like a standard Unix utility,
951compatible to mksh on all other platforms, using only ASCII LF
952(0x0A) as line ending character. This is supported by the mksh
953upstream developer.
954With 'textmode', mksh will be modified to behave more like other
955OS/2 utilities, supporting ASCII CR+LF (0x0D 0x0A) as line ending
956at the cost of deviation from standard mksh. This is supported by
957the mksh-os2 porter.
958
959] You are currently compiling with textmode ${x}abled, introducing
960] incompatibilities with $y.
961"
962	;;
963OS/390)
964	add_cppflags -DMKSH_ASSUME_UTF8=0
965	HAVE_ISSET_MKSH_ASSUME_UTF8=1
966	HAVE_ISOFF_MKSH_ASSUME_UTF8=1
967	: "${CC=xlc}"
968	: "${SIZE=: size}"
969	add_cppflags -DMKSH_FOR_Z_OS
970	add_cppflags -D_ALL_SOURCE
971	oswarn='; EBCDIC support is incomplete'
972	;;
973OSF1)
974	HAVE_SIG_T=0	# incompatible
975	add_cppflags -D_OSF_SOURCE
976	add_cppflags -D_POSIX_C_SOURCE=200112L
977	add_cppflags -D_XOPEN_SOURCE=600
978	add_cppflags -D_XOPEN_SOURCE_EXTENDED
979	: "${HAVE_SETLOCALE_CTYPE=0}"
980	;;
981Plan9)
982	add_cppflags -D_POSIX_SOURCE
983	add_cppflags -D_LIMITS_EXTENSION
984	add_cppflags -D_BSD_EXTENSION
985	add_cppflags -D_SUSV2_SOURCE
986	add_cppflags -DMKSH_ASSUME_UTF8
987	HAVE_ISSET_MKSH_ASSUME_UTF8=1
988	HAVE_ISOFF_MKSH_ASSUME_UTF8=0
989	add_cppflags -DMKSH__NO_SYMLINK
990	check_categories="$check_categories nosymlink"
991	add_cppflags -DMKSH_NO_CMDLINE_EDITING
992	add_cppflags -DMKSH__NO_SETEUGID
993	oswarn=' and will currently not work'
994	add_cppflags -DMKSH_UNEMPLOYED
995	# this is for detecting kencc
996	add_cppflags -DMKSH_MAYBE_KENCC
997	;;
998PW32*)
999	HAVE_SIG_T=0	# incompatible
1000	oswarn=' and will currently not work'
1001	: "${HAVE_SETLOCALE_CTYPE=0}"
1002	;;
1003QNX)
1004	add_cppflags -D__NO_EXT_QNX
1005	add_cppflags -D__EXT_UNIX_MISC
1006	case $TARGET_OSREV in
1007	[012345].*|6.[0123].*|6.4.[01])
1008		oldish_ed=no-stderr-ed		# oldish /bin/ed is broken
1009		;;
1010	esac
1011	: "${HAVE_SETLOCALE_CTYPE=0}"
1012	;;
1013SCO_SV)
1014	case $TARGET_OSREV in
1015	3.2*)
1016		# SCO OpenServer 5
1017		add_cppflags -DMKSH_UNEMPLOYED
1018		;;
1019	5*)
1020		# SCO OpenServer 6
1021		;;
1022	*)
1023		oswarn='; this is an unknown version of'
1024		oswarn="$oswarn$nl$TARGET_OS ${TARGET_OSREV}, please tell me what to do"
1025		;;
1026	esac
1027	: "${HAVE_SYS_SIGLIST=0}${HAVE__SYS_SIGLIST=0}"
1028	;;
1029skyos)
1030	oswarn="; it has minor issues"
1031	;;
1032SunOS)
1033	add_cppflags -D_BSD_SOURCE
1034	add_cppflags -D__EXTENSIONS__
1035	;;
1036syllable)
1037	add_cppflags -D_GNU_SOURCE
1038	add_cppflags -DMKSH_NO_SIGSUSPEND
1039	oswarn=' and will currently not work'
1040	;;
1041ULTRIX)
1042	: "${CC=cc -YPOSIX}"
1043	add_cppflags -DMKSH_TYPEDEF_SSIZE_T=int
1044	: "${HAVE_SETLOCALE_CTYPE=0}"
1045	;;
1046UnixWare|UNIX_SV)
1047	# SCO UnixWare
1048	: "${HAVE_SYS_SIGLIST=0}${HAVE__SYS_SIGLIST=0}"
1049	;;
1050UWIN*)
1051	ccpc='-Yc,'
1052	ccpl='-Yl,'
1053	tsts=" 3<>/dev/tty"
1054	oswarn="; it will compile, but the target"
1055	oswarn="$oswarn${nl}platform itself is very flakey/unreliable"
1056	: "${HAVE_SETLOCALE_CTYPE=0}"
1057	;;
1058_svr4)
1059	# generic target for SVR4 Unix with uname -s = uname -n
1060	# this duplicates the * target below
1061	oswarn='; it may or may not work'
1062	test_n "$TARGET_OSREV" || TARGET_OSREV=`uname -r`
1063	;;
1064*)
1065	oswarn='; it may or may not work'
1066	test_n "$TARGET_OSREV" || TARGET_OSREV=`uname -r`
1067	;;
1068esac
1069
1070: "${HAVE_MKNOD=0}"
1071
1072: "${AWK=awk}${CC=cc}${NROFF=nroff}${SIZE=size}"
1073test 0 = $r && echo | $NROFF -v 2>&1 | grep GNU >/dev/null 2>&1 && \
1074    echo | $NROFF -c >/dev/null 2>&1 && NROFF="$NROFF -c"
1075
1076# this aids me in tracing FTBFSen without access to the buildd
1077$e "Hi from$ao $bi$srcversion$ao on:"
1078case $TARGET_OS in
1079AIX)
1080	vv '|' "oslevel >&2"
1081	vv '|' "uname -a >&2"
1082	;;
1083Darwin)
1084	vv '|' "hwprefs machine_type os_type os_class >&2"
1085	vv '|' "sw_vers >&2"
1086	vv '|' "system_profiler -detailLevel mini SPSoftwareDataType SPHardwareDataType >&2"
1087	vv '|' "/bin/sh --version >&2"
1088	vv '|' "xcodebuild -version >&2"
1089	vv '|' "uname -a >&2"
1090	vv '|' "sysctl kern.version hw.machine hw.model hw.memsize hw.availcpu hw.ncpu hw.cpufrequency hw.byteorder hw.cpu64bit_capable >&2"
1091	vv '|' "sysctl hw.cpufrequency hw.byteorder hw.cpu64bit_capable hw.ncpu >&2"
1092	;;
1093IRIX*)
1094	vv '|' "uname -a >&2"
1095	vv '|' "hinv -v >&2"
1096	;;
1097OSF1)
1098	vv '|' "uname -a >&2"
1099	vv '|' "/usr/sbin/sizer -v >&2"
1100	;;
1101SCO_SV|UnixWare|UNIX_SV)
1102	vv '|' "uname -a >&2"
1103	vv '|' "uname -X >&2"
1104	;;
1105*)
1106	vv '|' "uname -a >&2"
1107	;;
1108esac
1109test_z "$oswarn" || echo >&2 "
1110Warning: mksh has not yet been ported to or tested on your
1111operating system '$TARGET_OS'$oswarn. If you can provide
1112a shell account to the developer, this may improve; please
1113drop us a success or failure notice or even send in diffs,
1114at the very least, complete logs (Build.sh + test.sh) will help.
1115"
1116$e "$bi$me: Building the MirBSD Korn Shell$ao $ui$dstversion$ao on $TARGET_OS ${TARGET_OSREV}..."
1117
1118#
1119# Start of mirtoconf checks
1120#
1121$e $bi$me: Scanning for functions... please ignore any errors.$ao
1122
1123#
1124# Compiler: which one?
1125#
1126# notes:
1127# - ICC defines __GNUC__ too
1128# - GCC defines __hpux too
1129# - LLVM+clang defines __GNUC__ too
1130# - nwcc defines __GNUC__ too
1131CPP="$CC -E"
1132$e ... which compiler type seems to be used
1133cat >conftest.c <<'EOF'
1134const char *
1135#if defined(__ICC) || defined(__INTEL_COMPILER)
1136ct="icc"
1137#elif defined(__xlC__) || defined(__IBMC__)
1138ct="xlc"
1139#elif defined(__SUNPRO_C)
1140ct="sunpro"
1141#elif defined(__neatcc__)
1142ct="neatcc"
1143#elif defined(__lacc__)
1144ct="lacc"
1145#elif defined(__ACK__)
1146ct="ack"
1147#elif defined(__BORLANDC__)
1148ct="bcc"
1149#elif defined(__WATCOMC__)
1150ct="watcom"
1151#elif defined(__MWERKS__)
1152ct="metrowerks"
1153#elif defined(__HP_cc)
1154ct="hpcc"
1155#elif defined(__DECC) || (defined(__osf__) && !defined(__GNUC__))
1156ct="dec"
1157#elif defined(__PGI)
1158ct="pgi"
1159#elif defined(__DMC__)
1160ct="dmc"
1161#elif defined(_MSC_VER)
1162ct="msc"
1163#elif defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__)
1164ct="adsp"
1165#elif defined(__IAR_SYSTEMS_ICC__)
1166ct="iar"
1167#elif defined(SDCC)
1168ct="sdcc"
1169#elif defined(__PCC__)
1170ct="pcc"
1171#elif defined(__TenDRA__)
1172ct="tendra"
1173#elif defined(__TINYC__)
1174ct="tcc"
1175#elif defined(__llvm__) && defined(__clang__)
1176ct="clang"
1177#elif defined(__NWCC__)
1178ct="nwcc"
1179#elif defined(__GNUC__)
1180ct="gcc"
1181#elif defined(_COMPILER_VERSION)
1182ct="mipspro"
1183#elif defined(__sgi)
1184ct="mipspro"
1185#elif defined(__hpux) || defined(__hpua)
1186ct="hpcc"
1187#elif defined(__ultrix)
1188ct="ucode"
1189#elif defined(__USLC__)
1190ct="uslc"
1191#elif defined(__LCC__)
1192ct="lcc"
1193#elif defined(MKSH_MAYBE_KENCC)
1194/* and none of the above matches */
1195ct="kencc"
1196#else
1197ct="unknown"
1198#endif
1199;
1200const char *
1201#if defined(__KLIBC__) && !defined(__OS2__)
1202et="klibc"
1203#else
1204et="unknown"
1205#endif
1206;
1207EOF
1208ct=untested
1209et=untested
1210vv ']' "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c | \
1211    sed -n '/^ *[ce]t *= */s/^ *\([ce]t\) *= */\1=/p' | tr -d \\\\015 >x"
1212sed 's/^/[ /' x
1213eval `cat x`
1214rmf x vv.out
1215cat >conftest.c <<'EOF'
1216#include <unistd.h>
1217int main(void) { return (isatty(0)); }
1218EOF
1219case $ct in
1220ack)
1221	# work around "the famous ACK const bug"
1222	CPPFLAGS="-Dconst= $CPPFLAGS"
1223	;;
1224adsp)
1225	echo >&2 'Warning: Analog Devices C++ compiler for Blackfin, TigerSHARC
1226    and SHARC (21000) DSPs detected. This compiler has not yet
1227    been tested for compatibility with mksh. Continue at your
1228    own risk, please report success/failure to the developers.'
1229	;;
1230bcc)
1231	echo >&2 "Warning: Borland C++ Builder detected. This compiler might
1232    produce broken executables. Continue at your own risk,
1233    please report success/failure to the developers."
1234	;;
1235clang)
1236	# does not work with current "ccc" compiler driver
1237	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -version"
1238	# one of these two works, for now
1239	vv '|' "${CLANG-clang} -version"
1240	vv '|' "${CLANG-clang} --version"
1241	# ensure compiler and linker are in sync unless overridden
1242	case $CCC_CC:$CCC_LD in
1243	:*)	;;
1244	*:)	CCC_LD=$CCC_CC; export CCC_LD ;;
1245	esac
1246	: "${HAVE_STRING_POOLING=i1}"
1247	;;
1248dec)
1249	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V"
1250	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -Wl,-V conftest.c $LIBS"
1251	;;
1252dmc)
1253	echo >&2 "Warning: Digital Mars Compiler detected. When running under"
1254	echo >&2 "    UWIN, mksh tends to be unstable due to the limitations"
1255	echo >&2 "    of this platform. Continue at your own risk,"
1256	echo >&2 "    please report success/failure to the developers."
1257	;;
1258gcc)
1259	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS"
1260	vv '|' 'eval echo "\`$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -dumpmachine\`" \
1261		 "gcc\`$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -dumpversion\`"'
1262	: "${HAVE_STRING_POOLING=i2}"
1263	;;
1264hpcc)
1265	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
1266	;;
1267iar)
1268	echo >&2 'Warning: IAR Systems (http://www.iar.com) compiler for embedded
1269    systems detected. This unsupported compiler has not yet
1270    been tested for compatibility with mksh. Continue at your
1271    own risk, please report success/failure to the developers.'
1272	;;
1273icc)
1274	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V"
1275	;;
1276kencc)
1277	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS"
1278	;;
1279lacc)
1280	# no version information
1281	;;
1282lcc)
1283	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS"
1284	add_cppflags -D__inline__=__inline
1285	;;
1286metrowerks)
1287	echo >&2 'Warning: Metrowerks C compiler detected. This has not yet
1288    been tested for compatibility with mksh. Continue at your
1289    own risk, please report success/failure to the developers.'
1290	;;
1291mipspro)
1292	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -version"
1293	;;
1294msc)
1295	ccpr=		# errorlevels are not reliable
1296	case $TARGET_OS in
1297	Interix)
1298		if test_z "$C89_COMPILER"; then
1299			C89_COMPILER=CL.EXE
1300		else
1301			C89_COMPILER=`ntpath2posix -c "$C89_COMPILER"`
1302		fi
1303		if test_z "$C89_LINKER"; then
1304			C89_LINKER=LINK.EXE
1305		else
1306			C89_LINKER=`ntpath2posix -c "$C89_LINKER"`
1307		fi
1308		vv '|' "$C89_COMPILER /HELP >&2"
1309		vv '|' "$C89_LINKER /LINK >&2"
1310		;;
1311	esac
1312	;;
1313neatcc)
1314	add_cppflags -DMKSH_DONT_EMIT_IDSTRING
1315	add_cppflags -DMKSH_NO_SIGSETJMP
1316	add_cppflags -Dsig_atomic_t=int
1317	vv '|' "$CC"
1318	;;
1319nwcc)
1320	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -version"
1321	;;
1322pcc)
1323	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -v"
1324	;;
1325pgi)
1326	echo >&2 'Warning: PGI detected. This unknown compiler has not yet
1327    been tested for compatibility with mksh. Continue at your
1328    own risk, please report success/failure to the developers.'
1329	;;
1330sdcc)
1331	echo >&2 'Warning: sdcc (http://sdcc.sourceforge.net), the small devices
1332    C compiler for embedded systems detected. This has not yet
1333    been tested for compatibility with mksh. Continue at your
1334    own risk, please report success/failure to the developers.'
1335	;;
1336sunpro)
1337	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
1338	;;
1339tcc)
1340	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -v"
1341	;;
1342tendra)
1343	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V 2>&1 | \
1344	    grep -F -i -e version -e release"
1345	;;
1346ucode)
1347	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V"
1348	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -Wl,-V conftest.c $LIBS"
1349	;;
1350uslc)
1351	case $TARGET_OS:$TARGET_OSREV in
1352	SCO_SV:3.2*)
1353		# SCO OpenServer 5
1354		CFLAGS="$CFLAGS -g"
1355		: "${HAVE_CAN_OTWO=0}${HAVE_CAN_OPTIMISE=0}"
1356		;;
1357	esac
1358	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
1359	;;
1360watcom)
1361	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS"
1362	;;
1363xlc)
1364	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -qversion"
1365	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -qversion=verbose"
1366	vv '|' "ld -V"
1367	;;
1368*)
1369	test x"$ct" = x"untested" && $e "!!! detecting preprocessor failed"
1370	ct=unknown
1371	vv '|' "$CC --version"
1372	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS"
1373	vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
1374	;;
1375esac
1376case $cm in
1377dragonegg|llvm)
1378	vv '|' "llc -version"
1379	;;
1380esac
1381etd=" on $et"
1382case $et in
1383klibc)
1384	: "${MKSH_UNLIMITED=1}"
1385	;;
1386unknown)
1387	# nothing special detected, don’t worry
1388	etd=
1389	;;
1390*)
1391	# huh?
1392	;;
1393esac
1394$e "$bi==> which compiler type seems to be used...$ao $ui$ct$etd$ao"
1395rmf conftest.c conftest.o conftest a.out* a.exe* conftest.exe* vv.out
1396
1397#
1398# Compiler: works as-is, with -Wno-error and -Werror
1399#
1400save_NOWARN=$NOWARN
1401NOWARN=
1402DOWARN=
1403ac_flags 0 compiler_works '' 'if the compiler works'
1404test 1 = $HAVE_CAN_COMPILER_WORKS || exit 1
1405HAVE_COMPILER_KNOWN=0
1406test $ct = unknown || HAVE_COMPILER_KNOWN=1
1407if ac_ifcpp 'if 0' compiler_fails '' \
1408    'if the compiler does not fail correctly'; then
1409	save_CFLAGS=$CFLAGS
1410	: "${HAVE_CAN_DELEXE=x}"
1411	case $ct in
1412	dec)
1413		CFLAGS="$CFLAGS ${ccpl}-non_shared"
1414		ac_testn can_delexe compiler_fails 0 'for the -non_shared linker option' <<-'EOF'
1415			#include <unistd.h>
1416			int main(void) { return (isatty(0)); }
1417		EOF
1418		;;
1419	dmc)
1420		CFLAGS="$CFLAGS ${ccpl}/DELEXECUTABLE"
1421		ac_testn can_delexe compiler_fails 0 'for the /DELEXECUTABLE linker option' <<-'EOF'
1422			#include <unistd.h>
1423			int main(void) { return (isatty(0)); }
1424		EOF
1425		;;
1426	*)
1427		exit 1
1428		;;
1429	esac
1430	test 1 = $HAVE_CAN_DELEXE || CFLAGS=$save_CFLAGS
1431	ac_ifcpp 'if 0' compiler_still_fails \
1432	    'if the compiler still does not fail correctly' && exit 1
1433fi
1434if ac_ifcpp 'ifdef __TINYC__' couldbe_tcc '!' compiler_known 0 \
1435    'if this could be tcc'; then
1436	ct=tcc
1437	CPP='cpp -D__TINYC__'
1438	HAVE_COMPILER_KNOWN=1
1439fi
1440
1441case $ct in
1442bcc)
1443	save_NOWARN="${ccpc}-w"
1444	DOWARN="${ccpc}-w!"
1445	;;
1446dec)
1447	# -msg_* flags not used yet, or is -w2 correct?
1448	;;
1449dmc)
1450	save_NOWARN="${ccpc}-w"
1451	DOWARN="${ccpc}-wx"
1452	;;
1453hpcc)
1454	save_NOWARN=
1455	DOWARN=+We
1456	;;
1457kencc)
1458	save_NOWARN=
1459	DOWARN=
1460	;;
1461mipspro)
1462	save_NOWARN=
1463	DOWARN="-diag_error 1-10000"
1464	;;
1465msc)
1466	save_NOWARN="${ccpc}/w"
1467	DOWARN="${ccpc}/WX"
1468	;;
1469sunpro)
1470	test x"$save_NOWARN" = x"" && save_NOWARN='-errwarn=%none'
1471	ac_flags 0 errwarnnone "$save_NOWARN"
1472	test 1 = $HAVE_CAN_ERRWARNNONE || save_NOWARN=
1473	ac_flags 0 errwarnall "-errwarn=%all"
1474	test 1 = $HAVE_CAN_ERRWARNALL && DOWARN="-errwarn=%all"
1475	;;
1476tendra)
1477	save_NOWARN=-w
1478	;;
1479ucode)
1480	save_NOWARN=
1481	DOWARN=-w2
1482	;;
1483watcom)
1484	save_NOWARN=
1485	DOWARN=-Wc,-we
1486	;;
1487xlc)
1488	case $TARGET_OS in
1489	OS/390)
1490		save_NOWARN=-qflag=e
1491		DOWARN=-qflag=i
1492		;;
1493	*)
1494		save_NOWARN=-qflag=i:e
1495		DOWARN=-qflag=i:i
1496		;;
1497	esac
1498	;;
1499*)
1500	test x"$save_NOWARN" = x"" && save_NOWARN=-Wno-error
1501	ac_flags 0 wnoerror "$save_NOWARN"
1502	test 1 = $HAVE_CAN_WNOERROR || save_NOWARN=
1503	ac_flags 0 werror -Werror
1504	test 1 = $HAVE_CAN_WERROR && DOWARN=-Werror
1505	test $ct = icc && DOWARN="$DOWARN -wd1419"
1506	;;
1507esac
1508NOWARN=$save_NOWARN
1509
1510#
1511# Compiler: extra flags (-O2 -f* -W* etc.)
1512#
1513i=`echo :"$orig_CFLAGS" | sed 's/^://' | tr -c -d $alll$allu$alln`
1514# optimisation: only if orig_CFLAGS is empty
1515test_n "$i" || case $ct in
1516hpcc)
1517	phase=u
1518	ac_flags 1 otwo +O2
1519	phase=x
1520	;;
1521kencc|tcc|tendra)
1522	# no special optimisation
1523	;;
1524sunpro)
1525	cat >x <<-'EOF'
1526		#include <unistd.h>
1527		int main(void) { return (isatty(0)); }
1528		#define __IDSTRING_CONCAT(l,p)	__LINTED__ ## l ## _ ## p
1529		#define __IDSTRING_EXPAND(l,p)	__IDSTRING_CONCAT(l,p)
1530		#define pad			void __IDSTRING_EXPAND(__LINE__,x)(void) { }
1531	EOF
1532	yes pad | head -n 256 >>x
1533	ac_flags - 1 otwo -xO2 <x
1534	rmf x
1535	;;
1536xlc)
1537	ac_flags 1 othree "-O3 -qstrict"
1538	test 1 = $HAVE_CAN_OTHREE || ac_flags 1 otwo -O2
1539	;;
1540*)
1541	ac_flags 1 otwo -O2
1542	test 1 = $HAVE_CAN_OTWO || ac_flags 1 optimise -O
1543	;;
1544esac
1545# other flags: just add them if they are supported
1546i=0
1547case $ct in
1548bcc)
1549	ac_flags 1 strpool "${ccpc}-d" 'if string pooling can be enabled'
1550	;;
1551clang)
1552	i=1
1553	;;
1554dec)
1555	ac_flags 0 verb -verbose
1556	ac_flags 1 rodata -readonly_strings
1557	;;
1558dmc)
1559	ac_flags 1 decl "${ccpc}-r" 'for strict prototype checks'
1560	ac_flags 1 schk "${ccpc}-s" 'for stack overflow checking'
1561	;;
1562gcc)
1563	ac_flags 1 fnolto -fno-lto 'whether we can explicitly disable buggy GCC LTO' -fno-lto
1564	# The following tests run with -Werror (gcc only) if possible
1565	NOWARN=$DOWARN; phase=u
1566	ac_flags 1 wnodeprecateddecls -Wno-deprecated-declarations
1567	# mksh is not written in CFrustFrust!
1568	ac_flags 1 no_eh_frame -fno-asynchronous-unwind-tables
1569	ac_flags 1 fnostrictaliasing -fno-strict-aliasing
1570	ac_flags 1 fstackprotectorstrong -fstack-protector-strong
1571	test 1 = $HAVE_CAN_FSTACKPROTECTORSTRONG || \
1572	    ac_flags 1 fstackprotectorall -fstack-protector-all
1573	test $cm = dragonegg && case " $CC $CFLAGS $LDFLAGS " in
1574	*\ -fplugin=*dragonegg*) ;;
1575	*) ac_flags 1 fplugin_dragonegg -fplugin=dragonegg ;;
1576	esac
1577	case $cm in
1578	combine)
1579		fv=0
1580		checks='7 8'
1581		;;
1582	lto)
1583		fv=0
1584		checks='1 2 3 4 5 6 7 8'
1585		;;
1586	*)
1587		fv=1
1588		;;
1589	esac
1590	test $fv = 1 || for what in $checks; do
1591		test $fv = 1 && break
1592		case $what in
1593		1)	t_cflags='-flto=jobserver'
1594			t_ldflags='-fuse-linker-plugin'
1595			t_use=1 t_name=fltojs_lp ;;
1596		2)	t_cflags='-flto=jobserver' t_ldflags=''
1597			t_use=1 t_name=fltojs_nn ;;
1598		3)	t_cflags='-flto=jobserver'
1599			t_ldflags='-fno-use-linker-plugin -fwhole-program'
1600			t_use=1 t_name=fltojs_np ;;
1601		4)	t_cflags='-flto'
1602			t_ldflags='-fuse-linker-plugin'
1603			t_use=1 t_name=fltons_lp ;;
1604		5)	t_cflags='-flto' t_ldflags=''
1605			t_use=1 t_name=fltons_nn ;;
1606		6)	t_cflags='-flto'
1607			t_ldflags='-fno-use-linker-plugin -fwhole-program'
1608			t_use=1 t_name=fltons_np ;;
1609		7)	t_cflags='-fwhole-program --combine' t_ldflags=''
1610			t_use=0 t_name=combine cm=combine ;;
1611		8)	fv=1 cm=normal ;;
1612		esac
1613		test $fv = 1 && break
1614		ac_flags $t_use $t_name "$t_cflags" \
1615		    "if gcc supports $t_cflags $t_ldflags" "$t_ldflags"
1616	done
1617	ac_flags 1 data_abi_align -malign-data=abi
1618	i=1
1619	;;
1620hpcc)
1621	phase=u
1622	# probably not needed
1623	#ac_flags 1 agcc -Agcc 'for support of GCC extensions'
1624	phase=x
1625	;;
1626icc)
1627	ac_flags 1 fnobuiltinsetmode -fno-builtin-setmode
1628	ac_flags 1 fnostrictaliasing -fno-strict-aliasing
1629	ac_flags 1 fstacksecuritycheck -fstack-security-check
1630	i=1
1631	;;
1632mipspro)
1633	ac_flags 1 fullwarn -fullwarn 'for remark output support'
1634	;;
1635msc)
1636	ac_flags 1 strpool "${ccpc}/GF" 'if string pooling can be enabled'
1637	echo 'int main(void) { char test[64] = ""; return (*test); }' >x
1638	ac_flags - 1 stackon "${ccpc}/GZ" 'if stack checks can be enabled' <x
1639	ac_flags - 1 stckall "${ccpc}/Ge" 'stack checks for all functions' <x
1640	ac_flags - 1 secuchk "${ccpc}/GS" 'for compiler security checks' <x
1641	rmf x
1642	ac_flags 1 wall "${ccpc}/Wall" 'to enable all warnings'
1643	ac_flags 1 wp64 "${ccpc}/Wp64" 'to enable 64-bit warnings'
1644	;;
1645nwcc)
1646	#broken# ac_flags 1 ssp -stackprotect
1647	i=1
1648	;;
1649pcc)
1650	ac_flags 1 fstackprotectorall -fstack-protector-all
1651	i=1
1652	;;
1653sunpro)
1654	phase=u
1655	ac_flags 1 v -v
1656	ac_flags 1 ipo -xipo 'for cross-module optimisation'
1657	phase=x
1658	;;
1659tcc)
1660	: #broken# ac_flags 1 boundschk -b
1661	;;
1662tendra)
1663	ac_flags 0 ysystem -Ysystem
1664	test 1 = $HAVE_CAN_YSYSTEM && CPPFLAGS="-Ysystem $CPPFLAGS"
1665	ac_flags 1 extansi -Xa
1666	;;
1667xlc)
1668	case $TARGET_OS in
1669	OS/390)
1670		# On IBM z/OS, the following are warnings by default:
1671		# CCN3296: #include file <foo.h> not found.
1672		# CCN3944: Attribute "__foo__" is not supported and is ignored.
1673		# CCN3963: The attribute "foo" is not a valid variable attribute and is ignored.
1674		ac_flags 1 halton '-qhaltonmsg=CCN3296 -qhaltonmsg=CCN3944 -qhaltonmsg=CCN3963'
1675		# CCN3290: Unknown macro name FOO on #undef directive.
1676		# CCN4108: The use of keyword '__attribute__' is non-portable.
1677		ac_flags 1 supprss '-qsuppress=CCN3290 -qsuppress=CCN4108'
1678		;;
1679	*)
1680		ac_flags 1 rodata '-qro -qroconst -qroptr'
1681		ac_flags 1 rtcheck -qcheck=all
1682		#ac_flags 1 rtchkc -qextchk	# reported broken
1683		ac_flags 1 wformat '-qformat=all -qformat=nozln'
1684		;;
1685	esac
1686	#ac_flags 1 wp64 -qwarn64	# too verbose for now
1687	;;
1688esac
1689# flags common to a subset of compilers (run with -Werror on gcc)
1690if test 1 = $i; then
1691	ac_flags 1 wall -Wall
1692	ac_flags 1 fwrapv -fwrapv
1693fi
1694
1695# “on demand” means: GCC version >= 4
1696fd='if to rely on compiler for string pooling'
1697ac_cache string_pooling || case $HAVE_STRING_POOLING in
16982) fx=' (on demand, cached)' ;;
1699i1) fv=1 ;;
1700i2) fv=2; fx=' (on demand)' ;;
1701esac
1702ac_testdone
1703test x"$HAVE_STRING_POOLING" = x"0" || ac_cppflags
1704
1705phase=x
1706# The following tests run with -Werror or similar (all compilers) if possible
1707NOWARN=$DOWARN
1708test $ct = pcc && phase=u
1709
1710#
1711# Compiler: check for stuff that only generates warnings
1712#
1713ac_test attribute_bounded '' 'for __attribute__((__bounded__))' <<-'EOF'
1714	#if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
1715	extern int thiswillneverbedefinedIhope(void);
1716	/* force a failure: TenDRA and gcc 1.42 have false positive here */
1717	int main(void) { return (thiswillneverbedefinedIhope()); }
1718	#else
1719	#include <string.h>
1720	#undef __attribute__
1721	int xcopy(const void *, void *, size_t)
1722	    __attribute__((__bounded__(__buffer__, 1, 3)))
1723	    __attribute__((__bounded__(__buffer__, 2, 3)));
1724	int main(int ac, char *av[]) { return (xcopy(av[0], av[--ac], 1)); }
1725	int xcopy(const void *s, void *d, size_t n) {
1726		/*
1727		 * if memmove does not exist, we are not on a system
1728		 * with GCC with __bounded__ attribute either so poo
1729		 */
1730		memmove(d, s, n); return ((int)n);
1731	}
1732	#endif
1733EOF
1734ac_test attribute_format '' 'for __attribute__((__format__))' <<-'EOF'
1735	#if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
1736	extern int thiswillneverbedefinedIhope(void);
1737	/* force a failure: TenDRA and gcc 1.42 have false positive here */
1738	int main(void) { return (thiswillneverbedefinedIhope()); }
1739	#else
1740	#define fprintf printfoo
1741	#include <stdio.h>
1742	#undef __attribute__
1743	#undef fprintf
1744	extern int fprintf(FILE *, const char *format, ...)
1745	    __attribute__((__format__(__printf__, 2, 3)));
1746	int main(int ac, char *av[]) { return (fprintf(stderr, "%s%d", *av, ac)); }
1747	#endif
1748EOF
1749ac_test attribute_noreturn '' 'for __attribute__((__noreturn__))' <<-'EOF'
1750	#if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
1751	extern int thiswillneverbedefinedIhope(void);
1752	/* force a failure: TenDRA and gcc 1.42 have false positive here */
1753	int main(void) { return (thiswillneverbedefinedIhope()); }
1754	#else
1755	#include <stdlib.h>
1756	#undef __attribute__
1757	void fnord(void) __attribute__((__noreturn__));
1758	int main(void) { fnord(); }
1759	void fnord(void) { exit(0); }
1760	#endif
1761EOF
1762ac_test attribute_pure '' 'for __attribute__((__pure__))' <<-'EOF'
1763	#if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
1764	extern int thiswillneverbedefinedIhope(void);
1765	/* force a failure: TenDRA and gcc 1.42 have false positive here */
1766	int main(void) { return (thiswillneverbedefinedIhope()); }
1767	#else
1768	#include <unistd.h>
1769	#undef __attribute__
1770	int foo(const char *) __attribute__((__pure__));
1771	int main(int ac, char *av[]) { return (foo(av[ac - 1]) + isatty(0)); }
1772	int foo(const char *s) { return ((int)s[0]); }
1773	#endif
1774EOF
1775ac_test attribute_unused '' 'for __attribute__((__unused__))' <<-'EOF'
1776	#if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
1777	extern int thiswillneverbedefinedIhope(void);
1778	/* force a failure: TenDRA and gcc 1.42 have false positive here */
1779	int main(void) { return (thiswillneverbedefinedIhope()); }
1780	#else
1781	#include <unistd.h>
1782	#undef __attribute__
1783	int main(int ac __attribute__((__unused__)), char *av[]
1784	    __attribute__((__unused__))) { return (isatty(0)); }
1785	#endif
1786EOF
1787ac_test attribute_used '' 'for __attribute__((__used__))' <<-'EOF'
1788	#if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2))
1789	extern int thiswillneverbedefinedIhope(void);
1790	/* force a failure: TenDRA and gcc 1.42 have false positive here */
1791	int main(void) { return (thiswillneverbedefinedIhope()); }
1792	#else
1793	#include <unistd.h>
1794	#undef __attribute__
1795	static const char fnord[] __attribute__((__used__)) = "42";
1796	int main(void) { return (isatty(0)); }
1797	#endif
1798EOF
1799
1800# End of tests run with -Werror
1801NOWARN=$save_NOWARN
1802phase=x
1803
1804#
1805# mksh: flavours (full/small mksh, omit certain stuff)
1806#
1807if ac_ifcpp 'ifdef MKSH_SMALL' isset_MKSH_SMALL '' \
1808    "if a reduced-feature mksh is requested"; then
1809	: "${HAVE_NICE=0}"
1810	: "${HAVE_PERSISTENT_HISTORY=0}"
1811	check_categories="$check_categories smksh"
1812fi
1813ac_ifcpp 'if defined(MKSH_BINSHPOSIX) || defined(MKSH_BINSHREDUCED)' \
1814    isset_MKSH_BINSH '' 'if invoking as sh should be handled specially' && \
1815    check_categories="$check_categories binsh"
1816ac_ifcpp 'ifdef MKSH_UNEMPLOYED' isset_MKSH_UNEMPLOYED '' \
1817    "if mksh will be built without job control" && \
1818    check_categories="$check_categories arge"
1819ac_ifcpp 'ifdef MKSH_NOPROSPECTOFWORK' isset_MKSH_NOPROSPECTOFWORK '' \
1820    "if mksh will be built without job signals" && \
1821    check_categories="$check_categories arge nojsig"
1822ac_ifcpp 'ifdef MKSH_ASSUME_UTF8' isset_MKSH_ASSUME_UTF8 '' \
1823    'if the default UTF-8 mode is specified' && : "${HAVE_SETLOCALE_CTYPE=0}"
1824ac_ifcpp 'if !MKSH_ASSUME_UTF8' isoff_MKSH_ASSUME_UTF8 \
1825    isset_MKSH_ASSUME_UTF8 0 \
1826    'if the default UTF-8 mode is disabled' && \
1827    check_categories="$check_categories noutf8"
1828#ac_ifcpp 'ifdef MKSH_DISABLE_DEPRECATED' isset_MKSH_DISABLE_DEPRECATED '' \
1829#    "if deprecated features are to be omitted" && \
1830#    check_categories="$check_categories nodeprecated"
1831#ac_ifcpp 'ifdef MKSH_DISABLE_EXPERIMENTAL' isset_MKSH_DISABLE_EXPERIMENTAL '' \
1832#    "if experimental features are to be omitted" && \
1833#    check_categories="$check_categories noexperimental"
1834ac_ifcpp 'ifdef MKSH_MIDNIGHTBSD01ASH_COMPAT' isset_MKSH_MIDNIGHTBSD01ASH_COMPAT '' \
1835    'if the MidnightBSD 0.1 ash compatibility mode is requested' && \
1836    check_categories="$check_categories mnbsdash"
1837
1838#
1839# Environment: headers
1840#
1841ac_header sys/time.h sys/types.h
1842ac_header time.h sys/types.h
1843test "11" = "$HAVE_SYS_TIME_H$HAVE_TIME_H" || HAVE_BOTH_TIME_H=0
1844ac_test both_time_h '' 'whether <sys/time.h> and <time.h> can both be included' <<-'EOF'
1845	#include <sys/types.h>
1846	#include <sys/time.h>
1847	#include <time.h>
1848	#include <unistd.h>
1849	int main(void) { struct tm tm; return ((int)sizeof(tm) + isatty(0)); }
1850EOF
1851ac_header sys/bsdtypes.h
1852ac_header sys/file.h sys/types.h
1853ac_header sys/mkdev.h sys/types.h
1854ac_header sys/mman.h sys/types.h
1855ac_header sys/param.h
1856ac_header sys/resource.h sys/types.h _time
1857ac_header sys/select.h sys/types.h
1858ac_header sys/sysmacros.h
1859ac_header bstring.h
1860ac_header grp.h sys/types.h
1861ac_header io.h
1862ac_header libgen.h
1863ac_header libutil.h sys/types.h
1864ac_header paths.h
1865ac_header stdint.h stdarg.h
1866# include strings.h only if compatible with string.h
1867ac_header strings.h sys/types.h string.h
1868ac_header termios.h
1869ac_header ulimit.h sys/types.h
1870ac_header values.h
1871
1872#
1873# Environment: definitions
1874#
1875echo '#include <sys/types.h>
1876#include <unistd.h>
1877/* check that off_t can represent 2^63-1 correctly, thx FSF */
1878#define LARGE_OFF_T ((((off_t)1 << 31) << 31) - 1 + (((off_t)1 << 31) << 31))
1879int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 &&
1880    LARGE_OFF_T % 2147483647 == 1) ? 1 : -1];
1881int main(void) { return (isatty(0)); }' >lft.c
1882ac_testn can_lfs '' "for large file support" <lft.c
1883save_CPPFLAGS=$CPPFLAGS
1884add_cppflags -D_FILE_OFFSET_BITS=64
1885ac_testn can_lfs_sus '!' can_lfs 0 "... with -D_FILE_OFFSET_BITS=64" <lft.c
1886if test 0 = $HAVE_CAN_LFS_SUS; then
1887	CPPFLAGS=$save_CPPFLAGS
1888	add_cppflags -D_LARGE_FILES=1
1889	ac_testn can_lfs_aix '!' can_lfs 0 "... with -D_LARGE_FILES=1" <lft.c
1890	test 1 = $HAVE_CAN_LFS_AIX || CPPFLAGS=$save_CPPFLAGS
1891fi
1892rm -f lft.c
1893rmf lft*	# end of large file support test
1894
1895#
1896# Environment: types
1897#
1898ac_test can_inttypes '!' stdint_h 1 "for standard 32-bit integer types" <<-'EOF'
1899	#include <sys/types.h>
1900	#include <stddef.h>
1901	int main(int ac, char *av[]) { return ((uint32_t)(size_t)*av + (int32_t)ac); }
1902EOF
1903ac_test can_ucbints '!' can_inttypes 1 "for UCB 32-bit integer types" <<-'EOF'
1904	#include <sys/types.h>
1905	#include <stddef.h>
1906	int main(int ac, char *av[]) { return ((u_int32_t)(size_t)*av + (int32_t)ac); }
1907EOF
1908ac_test can_int8type '!' stdint_h 1 "for standard 8-bit integer type" <<-'EOF'
1909	#include <sys/types.h>
1910	#include <stddef.h>
1911	int main(int ac, char *av[]) { return ((uint8_t)(size_t)av[ac]); }
1912EOF
1913ac_test can_ucbint8 '!' can_int8type 1 "for UCB 8-bit integer type" <<-'EOF'
1914	#include <sys/types.h>
1915	#include <stddef.h>
1916	int main(int ac, char *av[]) { return ((u_int8_t)(size_t)av[ac]); }
1917EOF
1918
1919# only testn: added later below
1920ac_testn sig_t <<-'EOF'
1921	#include <sys/types.h>
1922	#include <signal.h>
1923	#include <stddef.h>
1924	volatile sig_t foo = (sig_t)0;
1925	int main(void) { return (foo == (sig_t)0); }
1926EOF
1927
1928ac_testn sighandler_t '!' sig_t 0 <<-'EOF'
1929	#include <sys/types.h>
1930	#include <signal.h>
1931	#include <stddef.h>
1932	volatile sighandler_t foo = (sighandler_t)0;
1933	int main(void) { return (foo == (sighandler_t)0); }
1934EOF
1935if test 1 = $HAVE_SIGHANDLER_T; then
1936	add_cppflags -Dsig_t=sighandler_t
1937	HAVE_SIG_T=1
1938fi
1939
1940ac_testn __sighandler_t '!' sig_t 0 <<-'EOF'
1941	#include <sys/types.h>
1942	#include <signal.h>
1943	#include <stddef.h>
1944	volatile __sighandler_t foo = (__sighandler_t)0;
1945	int main(void) { return (foo == (__sighandler_t)0); }
1946EOF
1947if test 1 = $HAVE___SIGHANDLER_T; then
1948	add_cppflags -Dsig_t=__sighandler_t
1949	HAVE_SIG_T=1
1950fi
1951
1952test 1 = $HAVE_SIG_T || add_cppflags -Dsig_t=nosig_t
1953ac_cppflags SIG_T
1954
1955#
1956# check whether whatever we use for the final link will succeed
1957#
1958if test $cm = makefile; then
1959	: nothing to check
1960else
1961	HAVE_LINK_WORKS=x
1962	ac_testinit link_works '' 'checking if the final link command may succeed'
1963	fv=1
1964	cat >conftest.c <<-EOF
1965		#define EXTERN
1966		#define MKSH_INCLUDES_ONLY
1967		#include "sh.h"
1968		__RCSID("$srcversion");
1969		int main(void) {
1970			struct timeval tv;
1971			printf("Hello, World!\\n");
1972			return (time(&tv.tv_sec));
1973		}
1974EOF
1975	case $cm in
1976	llvm)
1977		v "$CC $CFLAGS $CPPFLAGS $NOWARN -emit-llvm -c conftest.c" || fv=0
1978		rmf $tfn.s
1979		test $fv = 0 || v "llvm-link -o - conftest.o | opt $optflags | llc -o $tfn.s" || fv=0
1980		test $fv = 0 || v "$CC $CFLAGS $LDFLAGS -o $tcfn $tfn.s $LIBS $ccpr"
1981		;;
1982	dragonegg)
1983		v "$CC $CFLAGS $CPPFLAGS $NOWARN -S -flto conftest.c" || fv=0
1984		test $fv = 0 || v "mv conftest.s conftest.ll"
1985		test $fv = 0 || v "llvm-as conftest.ll" || fv=0
1986		rmf $tfn.s
1987		test $fv = 0 || v "llvm-link -o - conftest.bc | opt $optflags | llc -o $tfn.s" || fv=0
1988		test $fv = 0 || v "$CC $CFLAGS $LDFLAGS -o $tcfn $tfn.s $LIBS $ccpr"
1989		;;
1990	combine)
1991		v "$CC $CFLAGS $CPPFLAGS $LDFLAGS -fwhole-program --combine $NOWARN -o $tcfn conftest.c $LIBS $ccpr"
1992		;;
1993	lto|normal)
1994		cm=normal
1995		v "$CC $CFLAGS $CPPFLAGS $NOWARN -c conftest.c" || fv=0
1996		test $fv = 0 || v "$CC $CFLAGS $LDFLAGS -o $tcfn conftest.o $LIBS $ccpr"
1997		;;
1998	esac
1999	test -f $tcfn || fv=0
2000	ac_testdone
2001	test $fv = 1 || exit 1
2002fi
2003
2004#
2005# Environment: errors and signals
2006#
2007test x"NetBSD" = x"$TARGET_OS" && $e Ignore the compatibility warning.
2008
2009ac_testn sys_errlist '' "the sys_errlist[] array and sys_nerr" <<-'EOF'
2010	extern const int sys_nerr;
2011	extern const char * const sys_errlist[];
2012	extern int isatty(int);
2013	int main(void) { return (*sys_errlist[sys_nerr - 1] + isatty(0)); }
2014EOF
2015ac_testn _sys_errlist '!' sys_errlist 0 "the _sys_errlist[] array and _sys_nerr" <<-'EOF'
2016	extern const int _sys_nerr;
2017	extern const char * const _sys_errlist[];
2018	extern int isatty(int);
2019	int main(void) { return (*_sys_errlist[_sys_nerr - 1] + isatty(0)); }
2020EOF
2021if test 1 = "$HAVE__SYS_ERRLIST"; then
2022	add_cppflags -Dsys_nerr=_sys_nerr
2023	add_cppflags -Dsys_errlist=_sys_errlist
2024	HAVE_SYS_ERRLIST=1
2025fi
2026ac_cppflags SYS_ERRLIST
2027
2028for what in name list; do
2029	uwhat=`upper $what`
2030	ac_testn sys_sig$what '' "the sys_sig$what[] array" <<-EOF
2031		extern const char * const sys_sig$what[];
2032		extern int isatty(int);
2033		int main(void) { return (sys_sig$what[0][0] + isatty(0)); }
2034	EOF
2035	ac_testn _sys_sig$what '!' sys_sig$what 0 "the _sys_sig$what[] array" <<-EOF
2036		extern const char * const _sys_sig$what[];
2037		extern int isatty(int);
2038		int main(void) { return (_sys_sig$what[0][0] + isatty(0)); }
2039	EOF
2040	eval uwhat_v=\$HAVE__SYS_SIG$uwhat
2041	if test 1 = "$uwhat_v"; then
2042		add_cppflags -Dsys_sig$what=_sys_sig$what
2043		eval HAVE_SYS_SIG$uwhat=1
2044	fi
2045	ac_cppflags SYS_SIG$uwhat
2046done
2047
2048#
2049# Environment: library functions
2050#
2051ac_test flock <<-'EOF'
2052	#include <sys/types.h>
2053	#include <fcntl.h>
2054	#undef flock
2055	#if HAVE_SYS_FILE_H
2056	#include <sys/file.h>
2057	#endif
2058	int main(void) { return (flock(0, LOCK_EX | LOCK_UN)); }
2059EOF
2060
2061ac_test lock_fcntl '!' flock 1 'whether we can lock files with fcntl' <<-'EOF'
2062	#include <fcntl.h>
2063	#undef flock
2064	int main(void) {
2065		struct flock lks;
2066		lks.l_type = F_WRLCK | F_UNLCK;
2067		return (fcntl(0, F_SETLKW, &lks));
2068	}
2069EOF
2070
2071ac_test rlimit '' 'getrlimit and setrlimit' <<-'EOF'
2072	#define MKSH_INCLUDES_ONLY
2073	#include "sh.h"
2074	int main(void) {
2075		struct rlimit l;
2076		if (getrlimit(0, &l)) return 1;
2077		l.rlim_max = l.rlim_cur;
2078		l.rlim_cur = RLIM_INFINITY;
2079		return (setrlimit(0, &l));
2080	}
2081EOF
2082
2083ac_test rlim_t rlimit 0 <<-'EOF'
2084	#include <sys/types.h>
2085	#if HAVE_BOTH_TIME_H
2086	#include <sys/time.h>
2087	#include <time.h>
2088	#elif HAVE_SYS_TIME_H
2089	#include <sys/time.h>
2090	#elif HAVE_TIME_H
2091	#include <time.h>
2092	#endif
2093	#if HAVE_SYS_RESOURCE_H
2094	#include <sys/resource.h>
2095	#endif
2096	#include <unistd.h>
2097	int main(void) { return (((int)(rlim_t)0) + isatty(0)); }
2098EOF
2099
2100ac_test getrusage <<-'EOF'
2101	#define MKSH_INCLUDES_ONLY
2102	#include "sh.h"
2103	int main(void) {
2104		struct rusage ru;
2105		return (getrusage(RUSAGE_SELF, &ru) +
2106		    getrusage(RUSAGE_CHILDREN, &ru));
2107	}
2108EOF
2109
2110ac_test getsid <<-'EOF'
2111	#include <unistd.h>
2112	int main(void) { return ((int)getsid(0)); }
2113EOF
2114
2115ac_test gettimeofday <<-'EOF'
2116	#define MKSH_INCLUDES_ONLY
2117	#include "sh.h"
2118	int main(void) { struct timeval tv; return (gettimeofday(&tv, NULL)); }
2119EOF
2120
2121ac_test killpg <<-'EOF'
2122	#include <signal.h>
2123	int main(int ac, char *av[]) { return (av[0][killpg(123, ac)]); }
2124EOF
2125
2126ac_test memmove <<-'EOF'
2127	#include <sys/types.h>
2128	#include <stddef.h>
2129	#include <string.h>
2130	#if HAVE_STRINGS_H
2131	#include <strings.h>
2132	#endif
2133	int main(int ac, char *av[]) {
2134		return (*(int *)(void *)memmove(av[0], av[1], (size_t)ac));
2135	}
2136EOF
2137
2138ac_test mknod '' 'if to use mknod(), makedev() and friends' <<-'EOF'
2139	#define MKSH_INCLUDES_ONLY
2140	#include "sh.h"
2141	int main(int ac, char *av[]) {
2142		dev_t dv;
2143		dv = makedev((unsigned int)ac, (unsigned int)av[0][0]);
2144		return (mknod(av[0], (mode_t)0, dv) ? (int)major(dv) :
2145		    (int)minor(dv));
2146	}
2147EOF
2148
2149ac_test mmap lock_fcntl 0 'for mmap and munmap' <<-'EOF'
2150	#include <sys/types.h>
2151	#if HAVE_SYS_FILE_H
2152	#include <sys/file.h>
2153	#endif
2154	#if HAVE_SYS_MMAN_H
2155	#include <sys/mman.h>
2156	#endif
2157	#include <stddef.h>
2158	#include <stdlib.h>
2159	int main(void) { return ((void *)mmap(NULL, (size_t)0,
2160	    PROT_READ, MAP_PRIVATE, 0, (off_t)0) == (void *)NULL ? 1 :
2161	    munmap(NULL, 0)); }
2162EOF
2163
2164ac_test ftruncate mmap 0 'for ftruncate' <<-'EOF'
2165	#include <unistd.h>
2166	int main(void) { return (ftruncate(0, 0)); }
2167EOF
2168
2169ac_test nice <<-'EOF'
2170	#include <unistd.h>
2171	int main(void) { return (nice(4)); }
2172EOF
2173
2174ac_test revoke <<-'EOF'
2175	#include <sys/types.h>
2176	#if HAVE_LIBUTIL_H
2177	#include <libutil.h>
2178	#endif
2179	#include <unistd.h>
2180	int main(int ac, char *av[]) { return (ac + revoke(av[0])); }
2181EOF
2182
2183ac_test setlocale_ctype '' 'setlocale(LC_CTYPE, "")' <<-'EOF'
2184	#include <locale.h>
2185	#include <stddef.h>
2186	int main(void) { return ((int)(size_t)(void *)setlocale(LC_CTYPE, "")); }
2187EOF
2188
2189ac_test langinfo_codeset setlocale_ctype 0 'nl_langinfo(CODESET)' <<-'EOF'
2190	#include <langinfo.h>
2191	#include <stddef.h>
2192	int main(void) { return ((int)(size_t)(void *)nl_langinfo(CODESET)); }
2193EOF
2194
2195ac_test select <<-'EOF'
2196	#include <sys/types.h>
2197	#if HAVE_BOTH_TIME_H
2198	#include <sys/time.h>
2199	#include <time.h>
2200	#elif HAVE_SYS_TIME_H
2201	#include <sys/time.h>
2202	#elif HAVE_TIME_H
2203	#include <time.h>
2204	#endif
2205	#if HAVE_SYS_BSDTYPES_H
2206	#include <sys/bsdtypes.h>
2207	#endif
2208	#if HAVE_SYS_SELECT_H
2209	#include <sys/select.h>
2210	#endif
2211	#if HAVE_BSTRING_H
2212	#include <bstring.h>
2213	#endif
2214	#include <stddef.h>
2215	#include <stdlib.h>
2216	#include <string.h>
2217	#if HAVE_STRINGS_H
2218	#include <strings.h>
2219	#endif
2220	#include <unistd.h>
2221	int main(void) {
2222		struct timeval tv = { 1, 200000 };
2223		fd_set fds; FD_ZERO(&fds); FD_SET(0, &fds);
2224		return (select(FD_SETSIZE, &fds, NULL, NULL, &tv));
2225	}
2226EOF
2227
2228ac_test setresugid <<-'EOF'
2229	#include <sys/types.h>
2230	#include <unistd.h>
2231	int main(void) { return (setresuid(0,0,0) + setresgid(0,0,0)); }
2232EOF
2233
2234ac_test setgroups setresugid 0 <<-'EOF'
2235	#include <sys/types.h>
2236	#if HAVE_GRP_H
2237	#include <grp.h>
2238	#endif
2239	#include <unistd.h>
2240	int main(void) { gid_t gid = 0; return (setgroups(0, &gid)); }
2241EOF
2242
2243if test x"$et" = x"klibc"; then
2244
2245	ac_testn __rt_sigsuspend '' 'whether klibc uses RT signals' <<-'EOF'
2246		#define MKSH_INCLUDES_ONLY
2247		#include "sh.h"
2248		extern int __rt_sigsuspend(const sigset_t *, size_t);
2249		int main(void) { return (__rt_sigsuspend(NULL, 0)); }
2250EOF
2251
2252	# no? damn! legacy crap ahead!
2253
2254	ac_testn __sigsuspend_s '!' __rt_sigsuspend 1 \
2255	    'whether sigsuspend is usable (1/2)' <<-'EOF'
2256		#define MKSH_INCLUDES_ONLY
2257		#include "sh.h"
2258		extern int __sigsuspend_s(sigset_t);
2259		int main(void) { return (__sigsuspend_s(0)); }
2260EOF
2261	ac_testn __sigsuspend_xxs '!' __sigsuspend_s 1 \
2262	    'whether sigsuspend is usable (2/2)' <<-'EOF'
2263		#define MKSH_INCLUDES_ONLY
2264		#include "sh.h"
2265		extern int __sigsuspend_xxs(int, int, sigset_t);
2266		int main(void) { return (__sigsuspend_xxs(0, 0, 0)); }
2267EOF
2268
2269	if test "000" = "$HAVE___RT_SIGSUSPEND$HAVE___SIGSUSPEND_S$HAVE___SIGSUSPEND_XXS"; then
2270		# no usable sigsuspend(), use pause() *ugh*
2271		add_cppflags -DMKSH_NO_SIGSUSPEND
2272	fi
2273fi
2274
2275ac_test strerror '!' sys_errlist 0 <<-'EOF'
2276	extern char *strerror(int);
2277	int main(int ac, char *av[]) { return (*strerror(*av[ac])); }
2278EOF
2279
2280ac_test strsignal '!' sys_siglist 0 <<-'EOF'
2281	#include <string.h>
2282	#include <signal.h>
2283	int main(void) { return (strsignal(1)[0]); }
2284EOF
2285
2286ac_test strlcpy <<-'EOF'
2287	#include <string.h>
2288	int main(int ac, char *av[]) { return (strlcpy(*av, av[1],
2289	    (size_t)ac)); }
2290EOF
2291
2292#
2293# check headers for declarations
2294#
2295ac_test flock_decl flock 1 'for declaration of flock()' <<-'EOF'
2296	#define MKSH_INCLUDES_ONLY
2297	#include "sh.h"
2298	#if HAVE_SYS_FILE_H
2299	#include <sys/file.h>
2300	#endif
2301	int main(void) { return ((flock)(0, 0)); }
2302EOF
2303ac_test revoke_decl revoke 1 'for declaration of revoke()' <<-'EOF'
2304	#define MKSH_INCLUDES_ONLY
2305	#include "sh.h"
2306	int main(void) { return ((revoke)("")); }
2307EOF
2308ac_test sys_errlist_decl sys_errlist 0 "for declaration of sys_errlist[] and sys_nerr" <<-'EOF'
2309	#define MKSH_INCLUDES_ONLY
2310	#include "sh.h"
2311	int main(void) { return (*sys_errlist[sys_nerr - 1] + isatty(0)); }
2312EOF
2313ac_test sys_siglist_decl sys_siglist 0 'for declaration of sys_siglist[]' <<-'EOF'
2314	#define MKSH_INCLUDES_ONLY
2315	#include "sh.h"
2316	int main(void) { return (sys_siglist[0][0] + isatty(0)); }
2317EOF
2318
2319ac_test st_mtim '' 'for struct stat.st_mtim.tv_nsec' <<-'EOF'
2320	#define MKSH_INCLUDES_ONLY
2321	#include "sh.h"
2322	int main(void) { struct stat sb; return (sizeof(sb.st_mtim.tv_nsec)); }
2323EOF
2324ac_test st_mtimensec '!' st_mtim 0 'for struct stat.st_mtimensec' <<-'EOF'
2325	#define MKSH_INCLUDES_ONLY
2326	#include "sh.h"
2327	int main(void) { struct stat sb; return (sizeof(sb.st_mtimensec)); }
2328EOF
2329
2330#
2331# other checks
2332#
2333fd='if to use persistent history'
2334ac_cache PERSISTENT_HISTORY || case $HAVE_FTRUNCATE$HAVE_MMAP$HAVE_FLOCK$HAVE_LOCK_FCNTL in
2335111*|1101) fv=1 ;;
2336esac
2337test 1 = $fv || check_categories="$check_categories no-histfile"
2338ac_testdone
2339ac_cppflags
2340
2341#
2342# extra checks for legacy mksh
2343#
2344if test $legacy = 1; then
2345	ac_test long_32bit '' 'whether long is 32 bit wide' <<-'EOF'
2346		#define MKSH_INCLUDES_ONLY
2347		#include "sh.h"
2348		#ifndef CHAR_BIT
2349		#define CHAR_BIT 0
2350		#endif
2351		struct ctasserts {
2352		#define cta(name,assertion) char name[(assertion) ? 1 : -1]
2353			cta(char_is_8_bits, (CHAR_BIT) == 8);
2354			cta(long_is_32_bits, sizeof(long) == 4);
2355		};
2356		int main(void) { return (sizeof(struct ctasserts)); }
2357EOF
2358
2359	ac_test long_64bit '!' long_32bit 0 'whether long is 64 bit wide' <<-'EOF'
2360		#define MKSH_INCLUDES_ONLY
2361		#include "sh.h"
2362		#ifndef CHAR_BIT
2363		#define CHAR_BIT 0
2364		#endif
2365		struct ctasserts {
2366		#define cta(name,assertion) char name[(assertion) ? 1 : -1]
2367			cta(char_is_8_bits, (CHAR_BIT) == 8);
2368			cta(long_is_64_bits, sizeof(long) == 8);
2369		};
2370		int main(void) { return (sizeof(struct ctasserts)); }
2371EOF
2372
2373	case $HAVE_LONG_32BIT$HAVE_LONG_64BIT in
2374	10) check_categories="$check_categories int:32" ;;
2375	01) check_categories="$check_categories int:64" ;;
2376	*) check_categories="$check_categories int:u" ;;
2377	esac
2378fi
2379
2380#
2381# Compiler: Praeprocessor (only if needed)
2382#
2383test 0 = $HAVE_SYS_SIGNAME && if ac_testinit cpp_dd '' \
2384    'checking if the C Preprocessor supports -dD'; then
2385	echo '#define foo bar' >conftest.c
2386	vv ']' "$CPP $CFLAGS $CPPFLAGS $NOWARN -dD conftest.c >x"
2387	grep '#define foo bar' x >/dev/null 2>&1 && fv=1
2388	rmf conftest.c x vv.out
2389	ac_testdone
2390fi
2391
2392#
2393# End of mirtoconf checks
2394#
2395$e ... done.
2396
2397# Some operating systems have ancient versions of ed(1) writing
2398# the character count to standard output; cope for that
2399echo wq >x
2400ed x <x 2>/dev/null | grep 3 >/dev/null 2>&1 && \
2401    check_categories="$check_categories $oldish_ed"
2402rmf x vv.out
2403
2404if test 0 = $HAVE_SYS_SIGNAME; then
2405	if test 1 = $HAVE_CPP_DD; then
2406		$e Generating list of signal names...
2407	else
2408		$e No list of signal names available via cpp. Falling back...
2409	fi
2410	sigseenone=:
2411	sigseentwo=:
2412	echo '#include <signal.h>
2413#if defined(NSIG_MAX)
2414#define cfg_NSIG NSIG_MAX
2415#elif defined(NSIG)
2416#define cfg_NSIG NSIG
2417#elif defined(_NSIG)
2418#define cfg_NSIG _NSIG
2419#elif defined(SIGMAX)
2420#define cfg_NSIG (SIGMAX + 1)
2421#elif defined(_SIGMAX)
2422#define cfg_NSIG (_SIGMAX + 1)
2423#else
2424/*XXX better error out, see sh.h */
2425#define cfg_NSIG 64
2426#endif
2427int
2428mksh_cfg= cfg_NSIG
2429;' >conftest.c
2430	# GNU sed 2.03 segfaults when optimising this to sed -n
2431	NSIG=`vq "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c" | \
2432	    grep -v '^#' | \
2433	    sed '/mksh_cfg.*= *$/{
2434		N
2435		s/\n/ /
2436		}' | \
2437	    grep '^ *mksh_cfg *=' | \
2438	    sed 's/^ *mksh_cfg *=[	 ]*\([()0-9x+-][()0-9x+	 -]*\).*$/\1/'`
2439	case $NSIG in
2440	*mksh_cfg*) $e "Error: NSIG='$NSIG'"; NSIG=0 ;;
2441	*[\ \(\)+-]*) NSIG=`"$AWK" "BEGIN { print $NSIG }" </dev/null` ;;
2442	esac
2443	printf=printf
2444	(printf hallo) >/dev/null 2>&1 || printf=echo
2445	test $printf = echo || test "`printf %d 42`" = 42 || printf=echo
2446	test $printf = echo || NSIG=`printf %d "$NSIG" 2>/dev/null`
2447	$printf "NSIG=$NSIG ... "
2448	sigs="ABRT FPE ILL INT SEGV TERM ALRM BUS CHLD CONT HUP KILL PIPE QUIT"
2449	sigs="$sigs STOP TSTP TTIN TTOU USR1 USR2 POLL PROF SYS TRAP URG VTALRM"
2450	sigs="$sigs XCPU XFSZ INFO WINCH EMT IO DIL LOST PWR SAK CLD IOT STKFLT"
2451	sigs="$sigs ABND DCE DUMP IOERR TRACE DANGER THCONT THSTOP RESV UNUSED"
2452	test 1 = $HAVE_CPP_DD && test $NSIG -gt 1 && sigs="$sigs "`vq \
2453	    "$CPP $CFLAGS $CPPFLAGS $NOWARN -dD conftest.c" | \
2454	    grep '[	 ]SIG[A-Z0-9][A-Z0-9]*[	 ]' | \
2455	    sed 's/^.*[	 ]SIG\([A-Z0-9][A-Z0-9]*\)[	 ].*$/\1/' | sort`
2456	test $NSIG -gt 1 || sigs=
2457	for name in $sigs; do
2458		case $sigseenone in
2459		*:$name:*) continue ;;
2460		esac
2461		sigseenone=$sigseenone$name:
2462		echo '#include <signal.h>' >conftest.c
2463		echo int >>conftest.c
2464		echo mksh_cfg= SIG$name >>conftest.c
2465		echo ';' >>conftest.c
2466		# GNU sed 2.03 croaks on optimising this, too
2467		vq "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c" | \
2468		    grep -v '^#' | \
2469		    sed '/mksh_cfg.*= *$/{
2470			N
2471			s/\n/ /
2472			}' | \
2473		    grep '^ *mksh_cfg *=' | \
2474		    sed 's/^ *mksh_cfg *=[	 ]*\([0-9][0-9x]*\).*$/:\1 '$name/
2475	done | sed -n '/^:[^ ]/s/^://p' | while read nr name; do
2476		test $printf = echo || nr=`printf %d "$nr" 2>/dev/null`
2477		test $nr -gt 0 && test $nr -lt $NSIG || continue
2478		case $sigseentwo in
2479		*:$nr:*) ;;
2480		*)	echo "		{ \"$name\", $nr },"
2481			sigseentwo=$sigseentwo$nr:
2482			$printf "$name=$nr " >&2
2483			;;
2484		esac
2485	done 2>&1 >signames.inc
2486	rmf conftest.c
2487	$e done.
2488fi
2489
2490if test 1 = "$MKSH_UNLIMITED"; then
2491	add_cppflags -DMKSH_UNLIMITED
2492else
2493	MKSH_UNLIMITED=0
2494fi
2495
2496if test 1 = "$USE_PRINTF_BUILTIN"; then
2497	add_cppflags -DMKSH_PRINTF_BUILTIN
2498else
2499	USE_PRINTF_BUILTIN=0
2500fi
2501
2502addsrcs '!' HAVE_STRLCPY strlcpy.c
2503addsrcs USE_PRINTF_BUILTIN printf.c
2504addsrcs '!' MKSH_UNLIMITED ulimit.c
2505
2506test 1 = "$HAVE_CAN_VERB" && CFLAGS="$CFLAGS -verbose"
2507add_cppflags -DMKSH_BUILD_R=593
2508
2509$e $bi$me: Finished configuration testing, now producing output.$ao
2510
2511files=
2512objs=
2513sp=
2514case $tcfn in
2515a.exe|conftest.exe)
2516	mkshexe=$tfn.exe
2517	add_cppflags -DMKSH_EXE_EXT
2518	;;
2519*)
2520	mkshexe=$tfn
2521	;;
2522esac
2523case $curdir in
2524*\ *)	mkshshebang="#!./$mkshexe" ;;
2525*)	mkshshebang="#!$curdir/$mkshexe" ;;
2526esac
2527cat >test.sh <<-EOF
2528	$mkshshebang
2529	LC_ALL=C PATH='$PATH'; export LC_ALL PATH
2530	case \$KSH_VERSION in
2531	*MIRBSD*|*LEGACY*) ;;
2532	*) exit 1 ;;
2533	esac
2534	set -A check_categories -- $check_categories
2535	pflag='$curdir/$mkshexe'
2536	sflag='$srcdir/check.t'
2537	usee=0 useU=0 Pflag=0 Sflag=0 uset=0 vflag=1 xflag=0
2538	while getopts "C:e:fPp:QSs:t:U:v" ch; do case \$ch {
2539	(C)	check_categories[\${#check_categories[*]}]=\$OPTARG ;;
2540	(e)	usee=1; eflag=\$OPTARG ;;
2541	(f)	check_categories[\${#check_categories[*]}]=fastbox ;;
2542	(P)	Pflag=1 ;;
2543	(+P)	Pflag=0 ;;
2544	(p)	pflag=\$OPTARG ;;
2545	(Q)	vflag=0 ;;
2546	(+Q)	vflag=1 ;;
2547	(S)	Sflag=1 ;;
2548	(+S)	Sflag=0 ;;
2549	(s)	sflag=\$OPTARG ;;
2550	(t)	uset=1; tflag=\$OPTARG ;;
2551	(U)	useU=1; Uflag=\$OPTARG ;;
2552	(v)	vflag=1 ;;
2553	(+v)	vflag=0 ;;
2554	(*)	xflag=1 ;;
2555	}
2556	done
2557	shift \$((OPTIND - 1))
2558	set -A args -- '$srcdir/check.pl' -p "\$pflag"
2559	if $ebcdic; then
2560		args[\${#args[*]}]=-E
2561	fi
2562	x=
2563	for y in "\${check_categories[@]}"; do
2564		x=\$x,\$y
2565	done
2566	if [[ -n \$x ]]; then
2567		args[\${#args[*]}]=-C
2568		args[\${#args[*]}]=\${x#,}
2569	fi
2570	if (( usee )); then
2571		args[\${#args[*]}]=-e
2572		args[\${#args[*]}]=\$eflag
2573	fi
2574	(( Pflag )) && args[\${#args[*]}]=-P
2575	if (( uset )); then
2576		args[\${#args[*]}]=-t
2577		args[\${#args[*]}]=\$tflag
2578	fi
2579	if (( useU )); then
2580		args[\${#args[*]}]=-U
2581		args[\${#args[*]}]=\$Uflag
2582	fi
2583	(( vflag )) && args[\${#args[*]}]=-v
2584	(( xflag )) && args[\${#args[*]}]=-x	# force usage by synerr
2585	if [[ -n \$TMPDIR && -d \$TMPDIR/. ]]; then
2586		args[\${#args[*]}]=-T
2587		args[\${#args[*]}]=\$TMPDIR
2588	fi
2589	print Testing mksh for conformance:
2590	grep -F -e 'KSH R' -e Mir''OS: "\$sflag" | sed '/KSH/s/^./&           /'
2591	print "This shell is actually:\\n\\t\$KSH_VERSION"
2592	print 'test.sh built for mksh $dstversion'
2593	cstr='\$os = defined \$^O ? \$^O : "unknown";'
2594	cstr="\$cstr"'print \$os . ", Perl version " . \$];'
2595	for perli in \$PERL perl5 perl no; do
2596		if [[ \$perli = no ]]; then
2597			print Cannot find a working Perl interpreter, aborting.
2598			exit 1
2599		fi
2600		print "Trying Perl interpreter '\$perli'..."
2601		perlos=\$(\$perli -e "\$cstr")
2602		rv=\$?
2603		print "Errorlevel \$rv, running on '\$perlos'"
2604		if (( rv )); then
2605			print "=> not using"
2606			continue
2607		fi
2608		if [[ -n \$perlos ]]; then
2609			print "=> using it"
2610			break
2611		fi
2612	done
2613	(( Sflag )) || echo + \$perli "\${args[@]}" -s "\$sflag" "\$@"
2614	(( Sflag )) || exec \$perli "\${args[@]}" -s "\$sflag" "\$@"$tsts
2615	# use of the -S option for check.t split into multiple chunks
2616	rv=0
2617	for s in "\$sflag".*; do
2618		echo + \$perli "\${args[@]}" -s "\$s" "\$@"
2619		\$perli "\${args[@]}" -s "\$s" "\$@"$tsts
2620		rc=\$?
2621		(( rv = rv ? rv : rc ))
2622	done
2623	exit \$rv
2624EOF
2625chmod 755 test.sh
2626case $cm in
2627dragonegg)
2628	emitbc="-S -flto"
2629	;;
2630llvm)
2631	emitbc="-emit-llvm -c"
2632	;;
2633*)
2634	emitbc=-c
2635	;;
2636esac
2637echo ": # work around NeXTstep bug" >Rebuild.sh
2638cd "$srcdir"
2639optfiles=`echo *.opt`
2640cd "$curdir"
2641for file in $optfiles; do
2642	echo "echo + Running genopt on '$file'..."
2643	echo "(srcfile='$srcdir/$file'; BUILDSH_RUN_GENOPT=1; . '$srcdir/Build.sh')"
2644done >>Rebuild.sh
2645echo set -x >>Rebuild.sh
2646for file in $SRCS; do
2647	op=`echo x"$file" | sed 's/^x\(.*\)\.c$/\1./'`
2648	test -f $file || file=$srcdir/$file
2649	files="$files$sp$file"
2650	echo "$CC $CFLAGS $CPPFLAGS $emitbc $file || exit 1" >>Rebuild.sh
2651	if test $cm = dragonegg; then
2652		echo "mv ${op}s ${op}ll" >>Rebuild.sh
2653		echo "llvm-as ${op}ll || exit 1" >>Rebuild.sh
2654		objs="$objs$sp${op}bc"
2655	else
2656		objs="$objs$sp${op}o"
2657	fi
2658	sp=' '
2659done
2660case $cm in
2661dragonegg|llvm)
2662	echo "rm -f $tfn.s" >>Rebuild.sh
2663	echo "llvm-link -o - $objs | opt $optflags | llc -o $tfn.s" >>Rebuild.sh
2664	lobjs=$tfn.s
2665	;;
2666*)
2667	lobjs=$objs
2668	;;
2669esac
2670echo tcfn=$mkshexe >>Rebuild.sh
2671echo "$CC $CFLAGS $LDFLAGS -o \$tcfn $lobjs $LIBS $ccpr" >>Rebuild.sh
2672echo "test -f \$tcfn || exit 1; $SIZE \$tcfn" >>Rebuild.sh
2673if test $cm = makefile; then
2674	extras='emacsfn.h exprtok.h rlimits.opt sh.h sh_flags.opt ulimits.opt var_spec.h'
2675	test 0 = $HAVE_SYS_SIGNAME && extras="$extras signames.inc"
2676	gens= genq=
2677	for file in $optfiles; do
2678		genf=`basename "$file" | sed 's/.opt$/.gen/'`
2679		gens="$gens $genf"
2680		genq="$genq$nl$genf: $srcdir/Build.sh $srcdir/$file
2681			srcfile=$srcdir/$file; BUILDSH_RUN_GENOPT=1; . $srcdir/Build.sh"
2682	done
2683	cat >Makefrag.inc <<EOF
2684# Makefile fragment for building mksh $dstversion
2685
2686PROG=		$mkshexe
2687MAN=		mksh.1
2688SRCS=		$SRCS
2689SRCS_FP=	$files
2690OBJS_BP=	$objs
2691INDSRCS=	$extras
2692NONSRCS_INST=	dot.mkshrc \$(MAN)
2693NONSRCS_NOINST=	Build.sh Makefile Rebuild.sh check.pl check.t test.sh
2694CC=		$CC
2695CPPFLAGS=	$CPPFLAGS
2696CFLAGS=		$CFLAGS
2697LDFLAGS=	$LDFLAGS
2698LIBS=		$LIBS
2699
2700.depend \$(OBJS_BP):$gens$genq
2701
2702# not BSD make only:
2703#VPATH=		$srcdir
2704#all: \$(PROG)
2705#\$(PROG): \$(OBJS_BP)
2706#	\$(CC) \$(CFLAGS) \$(LDFLAGS) -o \$@ \$(OBJS_BP) \$(LIBS)
2707#\$(OBJS_BP): \$(SRCS_FP) \$(NONSRCS)
2708#.c.o:
2709#	\$(CC) \$(CFLAGS) \$(CPPFLAGS) -c \$<
2710
2711# for all make variants:
2712#REGRESS_FLAGS=	-f
2713#regress:
2714#	./test.sh \$(REGRESS_FLAGS)
2715check_categories=$check_categories
2716
2717# for BSD make only:
2718#.PATH: $srcdir
2719#.include <bsd.prog.mk>
2720EOF
2721	$e
2722	$e Generated Makefrag.inc successfully.
2723	exit 0
2724fi
2725for file in $optfiles; do
2726	$e "+ Running genopt on '$file'..."
2727	do_genopt "$srcdir/$file" || exit 1
2728done
2729if test $cm = combine; then
2730	objs="-o $mkshexe"
2731	for file in $SRCS; do
2732		test -f $file || file=$srcdir/$file
2733		objs="$objs $file"
2734	done
2735	emitbc="-fwhole-program --combine"
2736	v "$CC $CFLAGS $CPPFLAGS $LDFLAGS $emitbc $objs $LIBS $ccpr"
2737elif test 1 = $pm; then
2738	for file in $SRCS; do
2739		test -f $file || file=$srcdir/$file
2740		v "$CC $CFLAGS $CPPFLAGS $emitbc $file" &
2741	done
2742	wait
2743else
2744	for file in $SRCS; do
2745		test $cm = dragonegg && \
2746		    op=`echo x"$file" | sed 's/^x\(.*\)\.c$/\1./'`
2747		test -f $file || file=$srcdir/$file
2748		v "$CC $CFLAGS $CPPFLAGS $emitbc $file" || exit 1
2749		if test $cm = dragonegg; then
2750			v "mv ${op}s ${op}ll"
2751			v "llvm-as ${op}ll" || exit 1
2752		fi
2753	done
2754fi
2755case $cm in
2756dragonegg|llvm)
2757	rmf $tfn.s
2758	v "llvm-link -o - $objs | opt $optflags | llc -o $tfn.s"
2759	;;
2760esac
2761tcfn=$mkshexe
2762test $cm = combine || v "$CC $CFLAGS $LDFLAGS -o $tcfn $lobjs $LIBS $ccpr"
2763test -f $tcfn || exit 1
2764test 1 = $r || v "$NROFF -mdoc <'$srcdir/lksh.1' >lksh.cat1" || rmf lksh.cat1
2765test 1 = $r || v "$NROFF -mdoc <'$srcdir/mksh.1' >mksh.cat1" || rmf mksh.cat1
2766test 1 = $r || v "(set -- ''; . '$srcdir/FAQ2HTML.sh')" || rmf FAQ.htm
2767test 0 = $eq && v $SIZE $tcfn
2768i=install
2769test -f /usr/ucb/$i && i=/usr/ucb/$i
2770test 1 = $eq && e=:
2771$e
2772$e Installing the shell:
2773$e "# $i -c -s -o root -g bin -m 555 $tfn /bin/$tfn"
2774if test $legacy = 0; then
2775	$e "# grep -x /bin/$tfn /etc/shells >/dev/null || echo /bin/$tfn >>/etc/shells"
2776	$e "# $i -c -o root -g bin -m 444 dot.mkshrc /usr/share/doc/mksh/examples/"
2777fi
2778$e
2779$e Installing the manual:
2780if test -f FAQ.htm; then
2781	$e "# $i -c -o root -g bin -m 444 FAQ.htm /usr/share/doc/mksh/"
2782fi
2783if test -f mksh.cat1; then
2784	if test -f FAQ.htm; then
2785		$e plus either
2786	fi
2787	$e "# $i -c -o root -g bin -m 444 lksh.cat1" \
2788	    "/usr/share/man/cat1/lksh.0"
2789	$e "# $i -c -o root -g bin -m 444 mksh.cat1" \
2790	    "/usr/share/man/cat1/mksh.0"
2791	$e or
2792fi
2793$e "# $i -c -o root -g bin -m 444 lksh.1 mksh.1 /usr/share/man/man1/"
2794$e
2795$e Run the regression test suite: ./test.sh
2796$e Please also read the sample file dot.mkshrc and the fine manual.
2797test -f FAQ.htm || \
2798    $e Run FAQ2HTML.sh and place FAQ.htm into a suitable location as well.
2799exit 0
2800
2801: <<'EOD'
2802
2803=== Environment used ===
2804
2805==== build environment ====
2806AWK				default: awk
2807CC				default: cc
2808CFLAGS				if empty, defaults to -xO2 or +O2
2809				or -O3 -qstrict or -O2, per compiler
2810CPPFLAGS			default empty
2811LDFLAGS				default empty; added before sources
2812LDSTATIC			set this to '-static'; default unset
2813LIBS				default empty; added after sources
2814				[Interix] default: -lcrypt (XXX still needed?)
2815NOWARN				-Wno-error or similar
2816NROFF				default: nroff
2817TARGET_OS			default: $(uname -s || uname)
2818TARGET_OSREV			[QNX] default: $(uname -r)
2819
2820==== feature selectors ====
2821MKSH_UNLIMITED			1 to omit ulimit builtin completely
2822USE_PRINTF_BUILTIN		1 to include (unsupported) printf(1) as builtin
2823===== general format =====
2824HAVE_STRLEN			ac_test
2825HAVE_STRING_H			ac_header
2826HAVE_CAN_FSTACKPROTECTORALL	ac_flags
2827
2828==== cpp definitions ====
2829DEBUG				dont use in production, wants gcc, implies:
2830DEBUG_LEAKS			enable freeing resources before exiting
2831KSH_VERSIONNAME_VENDOR_EXT	when patching; space+plus+word (e.g. " +SuSE")
2832MKSHRC_PATH			"~/.mkshrc" (do not change)
2833MKSH_A4PB			force use of arc4random_pushb
2834MKSH_ASSUME_UTF8		(0=disabled, 1=enabled; default: unset)
2835MKSH_BINSHPOSIX			if */sh or */-sh, enable set -o posix
2836MKSH_BINSHREDUCED		if */sh or */-sh, enable set -o sh
2837MKSH_CLS_STRING			KSH_ESC_STRING "[;H" KSH_ESC_STRING "[J"
2838MKSH_DEFAULT_EXECSHELL		"/bin/sh" (do not change)
2839MKSH_DEFAULT_PROFILEDIR		"/etc" (do not change)
2840MKSH_DEFAULT_TMPDIR		"/tmp" (do not change)
2841MKSH_DISABLE_DEPRECATED		disable code paths scheduled for later removal
2842MKSH_DISABLE_EXPERIMENTAL	disable code not yet comfy for (LTS) snapshots
2843MKSH_DISABLE_TTY_WARNING	shut up warning about ctty if OS cant be fixed
2844MKSH_DONT_EMIT_IDSTRING		omit RCS IDs from binary
2845MKSH_EARLY_LOCALE_TRACKING	track utf8-mode from POSIX locale, for SuSE
2846MKSH_MIDNIGHTBSD01ASH_COMPAT	set -o sh: additional compatibility quirk
2847MKSH_NOPROSPECTOFWORK		disable jobs, co-processes, etc. (do not use)
2848MKSH_NOPWNAM			skip PAM calls, for -static on glibc or Solaris
2849MKSH_NO_CMDLINE_EDITING		disable command line editing code entirely
2850MKSH_NO_DEPRECATED_WARNING	omit warning when deprecated stuff is run
2851MKSH_NO_SIGSETJMP		define if sigsetjmp is broken or not available
2852MKSH_NO_SIGSUSPEND		use sigprocmask+pause instead of sigsuspend
2853MKSH_SMALL			omit some code, optimise hard for size (slower)
2854MKSH_SMALL_BUT_FAST		disable some hard-for-size optim. (modern sys.)
2855MKSH_S_NOVI=1			disable Vi editing mode (default if MKSH_SMALL)
2856MKSH_TYPEDEF_SIG_ATOMIC_T	define to e.g. 'int' if sig_atomic_t is missing
2857MKSH_TYPEDEF_SSIZE_T		define to e.g. 'long' if your OS has no ssize_t
2858MKSH_UNEMPLOYED			disable job control (but not jobs/co-processes)
2859USE_REALLOC_MALLOC		define as 0 to not use realloc as malloc
2860
2861=== generic installation instructions ===
2862
2863Set CC and possibly CFLAGS, CPPFLAGS, LDFLAGS, LIBS. If cross-compiling,
2864also set TARGET_OS. To disable tests, set e.g. HAVE_STRLCPY=0; to enable
2865them, set to a value other than 0 or 1. Ensure /bin/ed is installed. For
2866MKSH_SMALL but with Vi mode, add -DMKSH_S_NOVI=0 to CPPFLAGS as well.
2867
2868Normally, the following command is what you want to run, then:
2869$ (sh Build.sh -r && ./test.sh -f) 2>&1 | tee log
2870
2871Copy dot.mkshrc to /etc/skel/.mkshrc; install mksh into $prefix/bin; or
2872/bin; install the manpage, if omitting the -r flag a catmanpage is made
2873using $NROFF. Consider using a forward script as /etc/skel/.mkshrc like
2874https://evolvis.org/plugins/scmgit/cgi-bin/gitweb.cgi?p=alioth/mksh.git;a=blob;f=debian/.mkshrc
2875and put dot.mkshrc as /etc/mkshrc so users need not keep up their HOME.
2876
2877You may also want to install the lksh binary (also as /bin/sh) built by:
2878$ CPPFLAGS="$CPPFLAGS -DMKSH_BINSHPOSIX" sh Build.sh -L -r
2879
2880EOD
2881