note *
note * This build script is in an extended Make Abstract Machine (MAM)
note * language. Documentation is at: src/cmd/INIT/README-mamake.md
note *

setv MAMAKE_STRICT 4
setv INSTALLROOT ../../..
setv CC cc
setv AR %{mam_cc_AR} %{mam_cc_AR_ARFLAGS}
setv mam_cc_FLAGS %{mam_cc_TARGET} %{mam_cc_DLL} %{-debug-symbols?1?%{mam_cc_DEBUG} -D_BLD_DEBUG?%{mam_cc_OPTIMIZE}?}
setv CCFLAGS
setv CCLDFLAGS %{-strip-symbols?1?%{mam_cc_LD_STRIP}??}
setv IFFEFLAGS
setv LDFLAGS
setv SH_DICT \"libshell\"
setv DYLIB_PRE %{mam_cc_SUFFIX_DYNAMIC?*?%{mam_cc_PREFIX_DYNAMIC}?%{mam_cc_PREFIX_SHARED}?}
setv DYLIB_SUF %{mam_cc_SUFFIX_DYNAMIC-%{mam_cc_SUFFIX_SHARED}}
setv DYLIB_VERSION 2.0

make install virtual
	note *
	note * Library dependencies
	note *

	bind -ldll
	bind -lcmd
	bind -last
	bind -lm dontcare
	bind -lnsl dontcare

	make shell.req
		makp %{INSTALLROOT}/bin/mkreq
		exec - mkreq %{CC} %{mam_cc_FLAGS} %{CCFLAGS} %{mam_cc_NOSTRICTALIASING} : %{LDFLAGS} : \
		exec -		shell dll cmd ast m jobs i socket nsl secdb network
	done

	note *
	note * Feature tests
	note *

	setv iffe_run iffe %{IFFEFLAGS} -v -c '%{CC} %{mam_cc_FLAGS} %{CCFLAGS} %{mam_cc_NOSTRICTALIASING} %{LDFLAGS}' ref -I%{INCLUDE_AST} -I%{INSTALLROOT}/include %{mam_libdll} %{mam_libcmd} %{mam_libast} %{mam_libm} %{mam_libnsl} : run

	make FEATURE/time
		make features/time
			prev %{INCLUDE_AST}/times.h
		done
		exec - %{iffe_run} %{<}
	done

	make FEATURE/dynamic
		make features/dynamic
			prev %{INCLUDE_AST}/dlldefs.h
		done
		exec - %{iffe_run} %{<}
	done

	loop F options externs sigfeatures locale cmds poll rlimits
		make FEATURE/%{F}
			makp features/%{F}
			exec - %{iffe_run} %{<}
		done
	done

	make FEATURE/math
		make features/math.sh
			prev %{INCLUDE_AST}/ast_float.h
			makp data/math.tab
		done
		exec - %{iffe_run} %{<} data/math.tab
	done

	note *
	note * Generate a shopt.h compile-time options header from SHOPT.sh and probe results.
	note *

	make shopt.h notrace
		prev FEATURE/options
		makp SHOPT.sh
		makp Mamfile
		note *
		note * the SHOPT.sh file calls the SHOPT function once for each option
		note *
		exec -	writedef()
		exec -	{
		exec -		echo "${3:-#ifndef SHOPT_$1}"
		exec -		echo "#   define SHOPT_$1	$2"
		exec -		echo "#endif"
		exec -		echo
		exec -	}
		exec -
		exec -	SHOPT()
		exec -	{
		exec -		n=${1%%=*}	# name
		exec -		v=${1#*=}	# value
		exec -		# probe certain options if they don't have a value configured
		exec -		case $1 in
		exec -		'MULTIBYTE=')
		exec -			# by default, SHOPT_MULTIBYTE is the opposite of AST_NOMULTIBYE
		exec -			writedef MULTIBYTE 1 '#if !defined(SHOPT_MULTIBYTE) && !AST_NOMULTIBYTE' ;;
		exec -		'DEVFD=')
		exec -			# if /dev/fd/n exposes file descriptor n, make SHOPT_DEVFD use this for
		exec -			# process substitutions instead of FIFOs, which are not as secure
		exec -			# WARNING: do not use 'test -e' for this test (too many shells break it
		exec -			# by failing to test for the physical existence of /dev/fd/9 in the FS)
		exec -			ls -d /dev/fd/9 9<&0 >/dev/null 2>&1 && writedef DEVFD 1 ;;
		exec -		'TEST_L=')
		exec -			# if external 'test' supports lowercase -l as equivalent to -L, enable
		exec -			# SHOPT_TEST_L so ksh supports it for compatibility with local scripts
		exec -			ln -s /dev/null "$EXECROOT/link$$"
		exec -			if	env test -l "$EXECROOT/link$$" && env test ! -l .
		exec -			then	writedef TEST_L 1
		exec -			fi 2>/dev/null
		exec -			rm -f "$EXECROOT/link$$" ;;
		exec -		'PRINTF_LEGACY=')
		exec -			# if external 'printf' allows POSIX-ignorant syntax (i.e., a format operand
		exec -			# starting with '-' without prior '--'), enable code for backward compat
		exec -			case $(env printf '-zut%s\n' alors 2>/dev/null) in
		exec -			-zutalors)
		exec -				writedef PRINTF_LEGACY 1 ;;
		exec -			esac ;;
		exec -		'SYSRC=')
		exec -			# if one of these exists, make SHOPT_SYSRC load /etc/ksh.kshrc by default
		exec -			if	test -f /etc/ksh.kshrc || test -f /etc/bash.bashrc
		exec -			then	writedef SYSRC 1
		exec -			fi ;;
		exec -		# some other SHOPTs may be probed for using feature tests in features/options
		exec -		*=?*)
		exec -			writedef "$n" "$v" ;;
		exec -		esac
		exec -		echo "* SHOPT_$n = ${v:-(probe)}" >&2  # show in make.out
		exec -	}
		exec -
		exec -	exec > %{@}
		exec -	echo '/* Generated from ksh93/SHOPT.sh by ksh93/Mamfile */'
		exec -	echo
		exec -	. "$PACKAGEROOT/src/cmd/ksh93/SHOPT.sh"
		exec -	cat <<-EOF
		exec -		#include "FEATURE/options"
		exec -
		exec -		/* overrides */
		exec -		#if SHOPT_SCRIPTONLY
		exec -		#   undef SHOPT_ACCT
		exec -		#   undef SHOPT_AUDIT
		exec -		#   undef SHOPT_ESH
		exec -		#   undef SHOPT_HISTEXPAND
		exec -		#   undef SHOPT_SYSRC
		exec -		#   undef SHOPT_VSH
		exec -		#endif
		exec -		#if !_sys_acct
		exec -		#   undef SHOPT_ACCT
		exec -		#endif
		exec -	EOF
	done shopt.h

	note *
	note * ksh93 C header (*.h) dependencies
	note *

	make include/fault.h
		prev FEATURE/sigfeatures
		prev %{INCLUDE_AST}/sfio.h
		prev %{INCLUDE_AST}/error.h
		prev %{INCLUDE_AST}/sig.h
	done

	make include/history.h
		prev %{INCLUDE_AST}/ast.h
	done

	make include/nval.h
		prev %{INCLUDE_AST}/option.h
		prev %{INCLUDE_AST}/cdt.h
		prev %{INCLUDE_AST}/ast.h
	done

	make include/name.h
		prev include/nval.h
		prev %{INCLUDE_AST}/cdt.h
		prev %{INCLUDE_AST}/ast.h
	done

	make include/shell.h
		prev include/fault.h
		prev %{INCLUDE_AST}/stk.h
		prev include/history.h
		prev %{INCLUDE_AST}/cmd.h
		prev %{INCLUDE_AST}/shcmd.h
		prev include/nval.h
		prev include/name.h
		prev %{INCLUDE_AST}/cdt.h
		prev %{INCLUDE_AST}/ast.h
	done

	make include/shtable.h
	done

	make include/builtins.h
		prev include/shtable.h
		prev FEATURE/dynamic
		prev %{INCLUDE_AST}/option.h
	done

	make include/regress.h
	done

	make include/argnod.h
	done

	make include/defs.h
		prev include/regress.h
		prev include/shtable.h
		prev include/shell.h
		prev %{INCLUDE_AST}/endian.h
		prev include/name.h
		prev include/argnod.h
		prev %{INCLUDE_AST}/cdt.h
		prev FEATURE/externs
		prev %{INCLUDE_AST}/error.h
		prev %{INCLUDE_AST}/sfio.h
		prev %{INCLUDE_AST}/ast.h
	done

	make include/test.h
		prev include/shtable.h
		prev include/defs.h
	done

	make include/path.h
		prev include/defs.h
		prev include/nval.h
	done

	make include/variables.h
		prev FEATURE/dynamic
		prev %{INCLUDE_AST}/option.h
		prev include/nval.h
	done

	make include/shnodes.h
		prev include/argnod.h
		prev %{INCLUDE_AST}/ast.h
	done

	make include/national.h
	done

	make include/terminal.h
		prev %{INCLUDE_AST}/ast_tty.h
	done

	make include/edit.h
		prev include/national.h
		prev include/terminal.h
		prev %{INCLUDE_AST}/sig.h
		prev FEATURE/locale
		prev FEATURE/cmds
	done

	make include/io.h
		prev %{INCLUDE_AST}/sfio.h
		prev %{INCLUDE_AST}/ast.h
	done

	make include/jobs.h
		prev include/terminal.h
		prev %{INCLUDE_AST}/aso.h
		prev %{INCLUDE_AST}/sfio.h
		prev %{INCLUDE_AST}/ast.h
	done

	make include/streval.h
		prev %{INCLUDE_AST}/ast_float.h
		prev include/defs.h
		prev %{INCLUDE_AST}/ast.h
	done

	make include/lexstates.h
		prev %{INCLUDE_AST}/wctype.h
		prev %{INCLUDE_AST}/wchar.h
		prev FEATURE/locale
	done

	make include/ulimit.h
		prev FEATURE/rlimits
		prev FEATURE/time
	done

	make include/shlex.h
		prev include/lexstates.h
		prev include/shtable.h
		prev include/shnodes.h
		prev %{INCLUDE_AST}/cdt.h
	done

	make include/fcin.h
		prev %{INCLUDE_AST}/sfio.h
	done

	make include/version.h
		prev %{INCLUDE_AST}/releaseflags.h
	done

	make include/timeout.h
	done

	note *
	note * ksh93 C source (*.c) dependencies
	note *

	make sh/pmain.c
		prev FEATURE/externs
		prev include/shell.h
		prev shopt.h
	done

	make bltins/cd_pwd.c
		prev include/test.h
		prev %{INCLUDE_AST}/ls.h
		prev include/builtins.h
		prev include/name.h
		prev include/path.h
		prev include/variables.h
		prev %{INCLUDE_AST}/error.h
		prev include/defs.h
		prev shopt.h
	done

	make bltins/cflow.c
		prev include/builtins.h
		prev include/shnodes.h
		prev %{INCLUDE_AST}/error.h
		prev %{INCLUDE_AST}/ast.h
		prev include/defs.h
		prev shopt.h
	done

	make bltins/enum.c
		prev include/defs.h
		prev shopt.h
	done

	make bltins/getopts.c
		prev include/builtins.h
		prev include/nval.h
		prev %{INCLUDE_AST}/error.h
		prev include/variables.h
		prev include/defs.h
		prev shopt.h
	done

	make bltins/hist.c
		prev include/edit.h
		prev include/builtins.h
		prev include/history.h
		prev include/name.h
		prev include/io.h
		prev include/variables.h
		prev %{INCLUDE_AST}/error.h
		prev %{INCLUDE_AST}/ls.h
		prev include/defs.h
		prev shopt.h
	done

	make bltins/misc.c
		prev %{INCLUDE_AST}/times.h
		prev FEATURE/time
		prev FEATURE/locale
		prev include/jobs.h
		prev include/builtins.h
		prev include/history.h
		prev include/name.h
		prev include/io.h
		prev include/path.h
		prev include/shnodes.h
		prev include/variables.h
		prev include/defs.h
		prev shopt.h
	done

	make bltins/mkservice.c
		prev %{INCLUDE_AST}/cmd.h
		prev %{INCLUDE_AST}/error.h
		prev include/nval.h
		prev include/defs.h
		prev shopt.h
	done

	make bltins/print.c
		prev %{INCLUDE_AST}/ccode.h
		prev %{INCLUDE_AST}/tmx.h
		prev include/streval.h
		prev include/builtins.h
		prev include/history.h
		prev include/name.h
		prev include/io.h
		prev %{INCLUDE_AST}/error.h
		prev include/defs.h
		prev shopt.h
	done

	make bltins/read.c
		prev include/edit.h
		prev include/terminal.h
		prev include/history.h
		prev include/builtins.h
		prev include/name.h
		prev include/io.h
		prev include/lexstates.h
		prev include/variables.h
		prev include/defs.h
		prev %{INCLUDE_AST}/error.h
		prev %{INCLUDE_AST}/ast.h
		prev shopt.h
	done

	make bltins/sleep.c
		prev FEATURE/poll
		prev FEATURE/time
		prev include/builtins.h
		prev %{INCLUDE_AST}/tmx.h
		prev %{INCLUDE_AST}/error.h
		prev include/defs.h
		prev shopt.h
	done

	make bltins/trap.c
		prev include/builtins.h
		prev include/jobs.h
		prev include/defs.h
		prev shopt.h
	done

	make bltins/test.c
		prev %{INCLUDE_AST}/tmx.h
		prev FEATURE/poll
		prev FEATURE/externs
		prev include/builtins.h
		prev include/test.h
		prev include/terminal.h
		prev include/io.h
		prev %{INCLUDE_AST}/regex.h
		prev %{INCLUDE_AST}/ls.h
		prev %{INCLUDE_AST}/error.h
		prev include/defs.h
		prev shopt.h
	done

	make bltins/typeset.c
		prev FEATURE/dynamic
		prev include/variables.h
		prev include/builtins.h
		prev include/history.h
		prev include/name.h
		prev include/path.h
		prev %{INCLUDE_AST}/error.h
		prev include/defs.h
		prev shopt.h
	done

	make bltins/ulimit.c
		prev include/ulimit.h
		prev include/name.h
		prev include/builtins.h
		prev include/defs.h
		prev %{INCLUDE_AST}/error.h
		prev %{INCLUDE_AST}/sfio.h
		prev %{INCLUDE_AST}/ast.h
		prev shopt.h
	done

	make bltins/umask.c
		prev include/builtins.h
		prev include/shell.h
		prev %{INCLUDE_AST}/ls.h
		prev %{INCLUDE_AST}/error.h
		prev %{INCLUDE_AST}/sfio.h
		prev %{INCLUDE_AST}/ast.h
		prev shopt.h
	done

	make bltins/whence.c
		prev include/builtins.h
		prev include/shlex.h
		prev include/path.h
		prev include/name.h
		prev include/shtable.h
		prev %{INCLUDE_AST}/error.h
		prev include/defs.h
		prev shopt.h
	done

	make sh/main.c
		prev FEATURE/externs
		prev FEATURE/time
		prev include/timeout.h
		prev include/history.h
		prev include/shnodes.h
		prev include/shlex.h
		prev include/jobs.h
		prev include/io.h
		prev include/path.h
		prev include/variables.h
		prev include/defs.h
		prev include/fcin.h
		prev %{INCLUDE_AST}/ls.h
		prev %{INCLUDE_AST}/sfio.h
		prev %{INCLUDE_AST}/ast.h
		prev shopt.h
	done

	make sh/nvdisc.c
		prev include/shlex.h
		prev include/io.h
		prev include/path.h
		prev include/builtins.h
		prev include/variables.h
		prev include/defs.h
		prev shopt.h
	done

	make sh/nvtype.c
		prev include/builtins.h
		prev include/variables.h
		prev include/io.h
		prev include/defs.h
		prev shopt.h
	done

	make sh/arith.c
		prev include/builtins.h
		prev include/variables.h
		prev include/streval.h
		prev include/name.h
		prev include/lexstates.h
		prev include/defs.h
		prev shopt.h
	done

	make sh/args.c
		prev include/io.h
		prev include/shlex.h
		prev FEATURE/poll
		prev include/edit.h
		prev include/terminal.h
		prev include/builtins.h
		prev include/jobs.h
		prev include/path.h
		prev include/defs.h
		prev shopt.h
	done

	make sh/array.c
		prev include/name.h
		prev include/defs.h
		prev shopt.h
	done

	make edit/completion.c
		prev include/history.h
		prev include/edit.h
		prev include/io.h
		prev include/path.h
		prev include/lexstates.h
		prev %{INCLUDE_AST}/ast_wchar.h
		prev include/defs.h
		prev shopt.h
	done

	make sh/defs.c
		prev include/timeout.h
		prev include/edit.h
		prev include/shlex.h
		prev include/jobs.h
		prev include/defs.h
		prev shopt.h
	done

	make edit/edit.c
		prev include/shlex.h
		prev include/edit.h
		prev include/history.h
		prev include/terminal.h
		prev include/io.h
		prev include/variables.h
		prev include/defs.h
		prev %{INCLUDE_AST}/ls.h
		prev FEATURE/time
		prev include/fault.h
		prev %{INCLUDE_AST}/ccode.h
		prev %{INCLUDE_AST}/ast.h
		prev shopt.h
	done

	make sh/expand.c
		prev include/path.h
		prev include/io.h
		prev %{INCLUDE_AST}/ast_dir.h
		prev %{INCLUDE_AST}/ls.h
		prev %{INCLUDE_AST}/glob.h
		prev %{INCLUDE_AST}/ast.h
		prev include/test.h
		prev include/variables.h
		prev include/defs.h
		prev shopt.h
	done

	make bltins/regress.c
		prev %{INCLUDE_AST}/tmx.h
		prev include/builtins.h
		prev include/io.h
		prev %{INCLUDE_AST}/ls.h
		prev %{INCLUDE_AST}/error.h
		prev include/defs.h
		prev shopt.h
	done

	make sh/fault.c
		prev include/ulimit.h
		prev include/builtins.h
		prev include/path.h
		prev include/jobs.h
		prev include/variables.h
		prev include/shlex.h
		prev include/history.h
		prev include/io.h
		prev include/fcin.h
		prev include/defs.h
		prev shopt.h
	done

	make sh/fcin.c
		prev include/fcin.h
		prev %{INCLUDE_AST}/error.h
		prev %{INCLUDE_AST}/sfio.h
		prev %{INCLUDE_AST}/ast.h
		prev shopt.h
	done

	make edit/history.c
		prev %{INCLUDE_AST}/stdio.h
		prev include/history.h
		prev include/io.h
		prev include/builtins.h
		prev include/path.h
		prev include/variables.h
		prev include/defs.h
		prev %{INCLUDE_AST}/ls.h
		prev %{INCLUDE_AST}/error.h
		prev FEATURE/time
		prev %{INCLUDE_AST}/sfio.h
		prev %{INCLUDE_AST}/ast.h
		prev shopt.h
	done

	make sh/init.c
		prev %{INCLUDE_AST}/wctype.h
		prev %{INCLUDE_AST}/ast_wchar.h
		prev include/version.h
		prev include/lexstates.h
		prev FEATURE/externs
		prev FEATURE/dynamic
		prev FEATURE/time
		prev include/builtins.h
		prev include/shlex.h
		prev include/io.h
		prev include/jobs.h
		prev include/edit.h
		prev include/name.h
		prev include/fault.h
		prev include/path.h
		prev include/variables.h
		prev %{INCLUDE_AST}/regex.h
		prev %{INCLUDE_AST}/tmx.h
		prev %{INCLUDE_AST}/ccode.h
		prev include/defs.h
		prev shopt.h
	done

	make sh/io.c
		prev %{INCLUDE_AST}/endian.h
		prev FEATURE/poll
		prev FEATURE/dynamic
		prev FEATURE/externs
		prev include/timeout.h
		prev include/edit.h
		prev include/history.h
		prev include/shnodes.h
		prev include/shlex.h
		prev include/jobs.h
		prev include/io.h
		prev include/path.h
		prev include/variables.h
		prev %{INCLUDE_AST}/regex.h
		prev %{INCLUDE_AST}/ls.h
		prev include/fcin.h
		prev include/defs.h
		prev shopt.h
	done

	make sh/jobs.c
		prev include/history.h
		prev include/jobs.h
		prev include/io.h
		prev %{INCLUDE_AST}/wait.h
		prev include/defs.h
		prev shopt.h
	done

	make sh/lex.c
		prev include/shlex.h
		prev include/io.h
		prev include/lexstates.h
		prev include/test.h
		prev include/argnod.h
		prev include/shell.h
		prev include/defs.h
		prev include/nval.h
		prev include/fcin.h
		prev %{INCLUDE_AST}/releaseflags.h
		prev %{INCLUDE_AST}/ast.h
		prev shopt.h
	done

	make sh/macro.c
		prev include/streval.h
		prev include/national.h
		prev include/path.h
		prev include/shnodes.h
		prev include/jobs.h
		prev include/io.h
		prev include/shlex.h
		prev include/variables.h
		prev include/name.h
		prev %{INCLUDE_AST}/regex.h
		prev include/fcin.h
		prev include/defs.h
		prev shopt.h
	done

	make sh/name.c
		prev include/builtins.h
		prev include/shnodes.h
		prev include/streval.h
		prev FEATURE/externs
		prev include/timeout.h
		prev include/lexstates.h
		prev include/path.h
		prev include/variables.h
		prev include/defs.h
		prev shopt.h
	done

	make sh/nvtree.c
		prev include/lexstates.h
		prev include/argnod.h
		prev include/name.h
		prev include/defs.h
		prev shopt.h
	done

	make sh/parse.c
		prev include/path.h
		prev include/test.h
		prev include/builtins.h
		prev include/history.h
		prev include/shlex.h
		prev %{INCLUDE_AST}/error.h
		prev include/fcin.h
		prev include/shell.h
		prev include/defs.h
		prev include/version.h
		prev shopt.h
	done

	make sh/path.c
		prev FEATURE/time
		prev %{INCLUDE_AST}/endian.h
		prev FEATURE/dynamic
		prev include/test.h
		prev include/history.h
		prev include/jobs.h
		prev include/io.h
		prev include/path.h
		prev include/variables.h
		prev include/nval.h
		prev %{INCLUDE_AST}/ls.h
		prev include/fcin.h
		prev include/defs.h
		prev shopt.h
	done

	make sh/string.c
		prev %{INCLUDE_AST}/wctype.h
		prev include/national.h
		prev include/lexstates.h
		prev include/shtable.h
		prev %{INCLUDE_AST}/ccode.h
		prev include/defs.h
		prev %{INCLUDE_AST}/lc.h
		prev %{INCLUDE_AST}/ast_wchar.h
		prev %{INCLUDE_AST}/ast.h
		prev shopt.h
	done

	make sh/streval.c
		prev FEATURE/externs
		prev %{INCLUDE_AST}/error.h
		prev include/streval.h
		prev shopt.h
	done

	make sh/subshell.c
		prev include/path.h
		prev include/variables.h
		prev include/jobs.h
		prev include/shlex.h
		prev include/shnodes.h
		prev include/fault.h
		prev include/io.h
		prev %{INCLUDE_AST}/ls.h
		prev include/defs.h
		prev shopt.h
	done

	make sh/tdump.c
		prev %{INCLUDE_AST}/ccode.h
		prev include/io.h
		prev include/path.h
		prev include/shnodes.h
		prev include/defs.h
		prev shopt.h
	done

	make sh/timers.c
		prev FEATURE/time
		prev FEATURE/sigfeatures
		prev include/defs.h
		prev include/fault.h
		prev %{INCLUDE_AST}/error.h
		prev %{INCLUDE_AST}/sig.h
		prev %{INCLUDE_AST}/ast.h
		prev shopt.h
	done

	make sh/trestore.c
		prev %{INCLUDE_AST}/ccode.h
		prev include/io.h
		prev include/path.h
		prev include/shnodes.h
		prev include/defs.h
		prev shopt.h
	done

	make sh/waitevent.c
		prev include/defs.h
		prev shopt.h
	done

	make sh/xec.c
		prev include/streval.h
		prev FEATURE/locale
		prev FEATURE/externs
		prev FEATURE/time
		prev include/builtins.h
		prev include/test.h
		prev include/jobs.h
		prev include/shnodes.h
		prev include/io.h
		prev include/name.h
		prev include/path.h
		prev include/variables.h
		prev include/fcin.h
		prev include/defs.h
		prev shopt.h
	done

	make data/limits.c
		prev include/ulimit.h
		prev %{INCLUDE_AST}/ast.h
		prev shopt.h
	done

	make data/msg.c
		prev include/edit.h
		prev include/jobs.h
		prev include/builtins.h
		prev include/history.h
		prev include/timeout.h
		prev include/shlex.h
		prev include/io.h
		prev include/path.h
		prev include/defs.h
		prev %{INCLUDE_AST}/ast.h
		prev shopt.h
	done

	make data/strdata.c
		prev FEATURE/math
		prev include/streval.h
		prev %{INCLUDE_AST}/ast_standards.h
		prev shopt.h
	done

	make data/testops.c
		prev include/test.h
		prev include/defs.h
		prev %{INCLUDE_AST}/ast.h
		prev shopt.h
	done

	make data/keywords.c
		prev include/shlex.h
		prev include/shell.h
		prev shopt.h
	done

	make data/options.c
		prev include/shtable.h
		prev include/name.h
		prev include/defs.h
		prev shopt.h
	done

	make data/signals.c
		prev include/jobs.h
		prev include/defs.h
		prev shopt.h
	done

	make data/aliases.c
		prev FEATURE/dynamic
		prev include/defs.h
		prev shopt.h
	done

	make data/builtins.c
		prev FEATURE/poll
		prev FEATURE/cmds
		prev include/jobs.h
		prev include/builtins.h
		prev include/version.h
		prev include/name.h
		prev include/ulimit.h
		prev include/shtable.h
		prev include/defs.h
		prev shopt.h
	done

	make data/variables.c
		prev include/builtins.h
		prev include/variables.h
		prev include/defs.h
		prev include/name.h
		prev include/shtable.h
		prev include/shell.h
		prev FEATURE/dynamic
		prev %{INCLUDE_AST}/ast.h
		prev shopt.h
	done

	make data/lexstates.c
		prev include/lexstates.h
		prev %{INCLUDE_AST}/ast.h
		prev shopt.h
	done

	make edit/emacs.c
		prev include/terminal.h
		prev include/edit.h
		prev include/history.h
		prev include/io.h
		prev include/defs.h
		prev %{INCLUDE_AST}/releaseflags.h
		prev %{INCLUDE_AST}/ast.h
		prev shopt.h
	done

	make edit/vi.c
		prev include/lexstates.h
		prev FEATURE/time
		prev include/terminal.h
		prev include/edit.h
		prev include/history.h
		prev include/io.h
		prev %{INCLUDE_AST}/ast.h
		prev include/defs.h
		prev shopt.h
	done

	make edit/hexpand.c
		prev include/edit.h
		prev include/defs.h
		prev shopt.h
	done

	make sh/shcomp.c
		prev include/terminal.h
		prev include/shnodes.h
		prev include/path.h
		prev include/defs.h
		prev include/shell.h
		prev include/version.h
		prev shopt.h
	done

	note *
	note * Set common compiler invocation arguments
	note *

	setv compile %{CC} %{mam_cc_FLAGS} %{CCFLAGS} %{mam_cc_NOSTRICTALIASING} %{DEBUG+-DDEBUG=%{DEBUG}} -DSH_DICT=%{SH_DICT} %{SH_CMDLIB_DIR+-DSH_CMDLIB_DIR=%{SH_CMDLIB_DIR}} -I. -Iinclude -I%{INCLUDE_AST} -D_API_ast=20100309 -DERROR_CONTEXT_T=Error_context_t -c

	note *
	note * Build the library
	note *

	make libshell.a
		loop OBJ args arith array defs expand fault fcin init io jobs lex macro main name nvdisc nvtree nvtype parse path streval string subshell tdump timers trestore waitevent xec
			make %{OBJ}.o
				prev sh/%{OBJ}.c
				exec - %{compile} %{<}
			done
		done

		loop OBJ cd_pwd cflow enum getopts hist misc mkservice print read regress sleep test trap typeset ulimit umask whence
			make %{OBJ}.o
				prev bltins/%{OBJ}.c
				exec - %{compile} %{<}
			done
		done

		loop OBJ completion edit emacs hexpand history vi
			make %{OBJ}.o
				prev edit/%{OBJ}.c
				exec - %{compile} %{<}
			done
		done

		loop OBJ aliases builtins keywords lexstates limits msg options signals strdata testops variables
			make %{OBJ}.o
				prev data/%{OBJ}.c
				exec - %{compile} %{<}
			done
		done

		note *
		note * Link the library
		note *
		exec - if	test -f %{@}
		exec - then	%{AR} rc %{@} %{?}  # add changed *.o
		exec - else	%{AR} rc %{@} %{^}  # add all *.o
		exec - fi || exit
		exec - ranlib %{@} >/dev/null 2>&1 || true

		note * save for dylink
		setv _libshell_object_files_ %{^}
	done libshell.a

	note *
	note * Pre-install public headers & dependency rules early (before 'bind -lshell')
	note *

	loop DIR bin include/ast lib/lib man/man1 man/man3 fun etc
		make %{INSTALLROOT}/%{DIR}
			exec - mkdir -p %{@}
		done
	done
	make %{INSTALLROOT}/lib/mam/shell
		loop HDR nval shell history
			make %{INCLUDE_AST}/%{HDR}.h
				prev include/%{HDR}.h
				exec - cp -f %{<} %{@}
			done
		done
		note * generate header dependency rules
		exec - mkdeps -lshell -last -ldll -lcmd %{^} > %{@}
		makp %{INSTALLROOT}/bin/mkdeps
		prev shell.req
	done %{INSTALLROOT}/lib/mam/shell

	note *
	note * Set the mam_libshell variable
	note *

	bind -lshell

	note *
	note * Link binaries
	note *

	shim - link_binary()
	shim - {
	shim -     %{CC} %{CCLDFLAGS} %{mam_cc_FLAGS} %{CCFLAGS} %{LDFLAGS} \
	shim -		-o "$@" %{mam_libshell} %{mam_libnsl} %{mam_libast} %{mam_libm}
	shim - }

	make ksh
		bind -lshell
		make pmain.o
			prev sh/pmain.c
			exec - %{compile} %{<}
		done
		exec - link_binary ksh pmain.o
	done ksh

	make shcomp
		bind -lshell
		make shcomp.o
			prev sh/shcomp.c
			exec - %{compile} %{<}
		done
		exec - link_binary shcomp shcomp.o
	done shcomp

	note *
	note * Dynamically linked version, if supported
	note *

	make %{INSTALLROOT}/dyn/lib/%{DYLIB_PRE}shell%{DYLIB_SUF} dontcare
		prev libshell.a
		prev shell.req
		exec - export LDFLAGS='%{LDFLAGS} %{CCLDFLAGS} %{mam_cc_LD_NOASNEEDED}'
		exec - dylink -m shell -v %{DYLIB_VERSION} -p '%{DYLIB_PRE}' -s '%{DYLIB_SUF}' $(sed 1d %{<}) %{_libshell_object_files_}
	done

	make %{INSTALLROOT}/dyn/bin/ksh dontcare
		prev ksh
		prev shell.req
		exec - export LDFLAGS='%{LDFLAGS} %{CCLDFLAGS} %{mam_cc_LD_NOASNEEDED} %{mam_cc_EXPORT_DYNAMIC}'
		exec - dylink -e ksh $(cat %{<}) %{mam_libnsl} %{mam_libm} pmain.o
	done

	make %{INSTALLROOT}/dyn/bin/shcomp dontcare
		prev shcomp
		prev shell.req
		exec - export LDFLAGS='%{LDFLAGS} %{CCLDFLAGS} %{mam_cc_LD_NOASNEEDED} %{mam_cc_EXPORT_DYNAMIC}'
		exec - dylink -e shcomp $(cat %{<}) %{mam_libnsl} %{mam_libm} shcomp.o
	done

	note *
	note * Pre-install the rest
	note *

	loop EXE ksh shcomp
		make %{INSTALLROOT}/bin/%{EXE}
			prev %{EXE}
			note * macOS throws code signature error if 'cp' overwrites Mach-O binary; must remove first
			exec - rm -f %{@} && cp %{<} %{@}
		done
	done
	make %{INSTALLROOT}/man/man1/sh.1
		makp sh.1
		exec - cp -f %{<} %{@}
	done
	make %{INSTALLROOT}/lib/libshell.a
		prev libshell.a
		exec - cp -f %{<} %{@} || exit
		exec - ranlib %{@} >/dev/null 2>&1 || true
	done
	loop MAN3PG shell nval
		make %{INSTALLROOT}/man/man3/%{MAN3PG}.3
			makp %{MAN3PG}.3
			exec - cp -f %{<} %{@}
		done
	done
	make %{INSTALLROOT}/lib/lib/shell
		prev shell.req
		exec - cp -f %{<} %{@}
	done
	loop FUN autocd cd dirs man mcd popd pushd
		make %{INSTALLROOT}/fun/%{FUN}
			makp fun/%{FUN}
			exec - cp -f %{<} %{@} && chmod ugo+x %{@}
		done
	done
	make %{INSTALLROOT}/etc/kshrc
		makp kshrc.sh
		exec - cp -f %{<} %{@}
	done
done install

note *
note * Run regression tests.
note *

make test dontcare virtual
	prev install
	make test.ksh virtual
		makp tests/shtests
		exec - cd "$PACKAGEROOT/src/cmd/ksh93/tests" && ./shtests
	done
done test
