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 3
setv INSTALLROOT ../../..
setv PACKAGE_ast_INCLUDE ${INSTALLROOT}/include/ast
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_VERSION 2.0

make install virtual
	note *
	note * AST header dependencies
	note * TODO: verify and centralise
	note *

	make ${PACKAGE_ast_INCLUDE}/sfio.h implicit
		prev ${PACKAGE_ast_INCLUDE}/sfio_s.h implicit
		make ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
			prev ${PACKAGE_ast_INCLUDE}/ast_map.h implicit
			make ${PACKAGE_ast_INCLUDE}/endian.h implicit
				make ${PACKAGE_ast_INCLUDE}/bytesex.h implicit
					note * TODO * circular dependency
					note # prev ${PACKAGE_ast_INCLUDE}/ast_common.h
				done
			done
		done
		make ${PACKAGE_ast_INCLUDE}/ast_std.h implicit
			make ${PACKAGE_ast_INCLUDE}/regex.h implicit
				prev ${PACKAGE_ast_INCLUDE}/ast_api.h implicit
				make ${PACKAGE_ast_INCLUDE}/ast_wchar.h implicit
					make ${PACKAGE_ast_INCLUDE}/wctype.h implicit
						make ${PACKAGE_ast_INCLUDE}/ast_wctype.h implicit
							prev ${PACKAGE_ast_INCLUDE}/endian.h
							make ${PACKAGE_ast_INCLUDE}/wchar.h implicit
								note * TODO * circular dependency
								note # prev ${PACKAGE_ast_INCLUDE}/ast_wchar.h
							done
						done
					done
					make ${PACKAGE_ast_INCLUDE}/stdio.h implicit
						make ${PACKAGE_ast_INCLUDE}/ast_stdio.h implicit
							prev ${PACKAGE_ast_INCLUDE}/sfio_s.h
							note * TODO * circular dependency
							note # prev ${PACKAGE_ast_INCLUDE}/ast_std.h
						done
					done
					prev ${PACKAGE_ast_INCLUDE}/ast_common.h
				done
				prev ${PACKAGE_ast_INCLUDE}/ast_common.h
			done
			make ${PACKAGE_ast_INCLUDE}/getopt.h implicit
				prev ${PACKAGE_ast_INCLUDE}/ast_getopt.h implicit
			done
			prev ${PACKAGE_ast_INCLUDE}/ast_map.h
			prev ${PACKAGE_ast_INCLUDE}/ast_botch.h implicit
			prev ${PACKAGE_ast_INCLUDE}/ast_limits.h implicit
			make ${PACKAGE_ast_INCLUDE}/ast_fcntl.h implicit
				prev ${PACKAGE_ast_INCLUDE}/ast_fs.h implicit
			done
			prev ${PACKAGE_ast_INCLUDE}/ast_getopt.h
			make ${PACKAGE_ast_INCLUDE}/ast_sys.h implicit
				prev ${PACKAGE_ast_INCLUDE}/getopt.h
				prev ${PACKAGE_ast_INCLUDE}/endian.h
			done
			prev ${PACKAGE_ast_INCLUDE}/ast_lib.h implicit
			prev ${PACKAGE_ast_INCLUDE}/ast_common.h
		done
	done
	make ${PACKAGE_ast_INCLUDE}/error.h implicit
		make ${PACKAGE_ast_INCLUDE}/option.h implicit
			make ${PACKAGE_ast_INCLUDE}/ast.h implicit
				prev ${PACKAGE_ast_INCLUDE}/ast_api.h
				make ${PACKAGE_ast_INCLUDE}/vmalloc.h implicit
					prev ${PACKAGE_ast_INCLUDE}/ast_common.h
					prev ${PACKAGE_ast_INCLUDE}/ast_std.h
				done
				prev ${PACKAGE_ast_INCLUDE}/sfio.h
				prev ${PACKAGE_ast_INCLUDE}/ast_std.h
			done
		done
		prev ${PACKAGE_ast_INCLUDE}/ast.h
	done
	make ${PACKAGE_ast_INCLUDE}/stk.h implicit
		prev ${PACKAGE_ast_INCLUDE}/sfio.h
	done
	make ${PACKAGE_ast_INCLUDE}/cmd.h implicit
		prev ${PACKAGE_ast_INCLUDE}/dlldefs.h implicit
		make ${PACKAGE_ast_INCLUDE}/cmdext.h implicit
			prev ${PACKAGE_ast_INCLUDE}/shcmd.h implicit
		done
		prev ${PACKAGE_ast_INCLUDE}/shcmd.h
		prev ${PACKAGE_ast_INCLUDE}/stk.h
		prev ${PACKAGE_ast_INCLUDE}/error.h
		prev ${PACKAGE_ast_INCLUDE}/ast.h
	done
	make ${PACKAGE_ast_INCLUDE}/cdt.h implicit
		prev ${PACKAGE_ast_INCLUDE}/ast_common.h
		prev ${PACKAGE_ast_INCLUDE}/ast_std.h
	done
	make ${PACKAGE_ast_INCLUDE}/times.h implicit
		prev ${PACKAGE_ast_INCLUDE}/ast_time.h implicit
		prev ${PACKAGE_ast_INCLUDE}/ast.h
	done
	make ${PACKAGE_ast_INCLUDE}/ls.h implicit
		prev ${PACKAGE_ast_INCLUDE}/ast_mode.h implicit
		prev ${PACKAGE_ast_INCLUDE}/ast_fs.h
		prev ${PACKAGE_ast_INCLUDE}/ast_std.h
	done
	make ${PACKAGE_ast_INCLUDE}/aso.h implicit
		prev ${PACKAGE_ast_INCLUDE}/ast_common.h
	done
	make ${PACKAGE_ast_INCLUDE}/ccode.h implicit
		prev ${PACKAGE_ast_INCLUDE}/ast_ccode.h implicit
		prev ${PACKAGE_ast_INCLUDE}/ast_common.h
	done
	make ${PACKAGE_ast_INCLUDE}/tmx.h implicit
		make ${PACKAGE_ast_INCLUDE}/tv.h implicit
			prev ${PACKAGE_ast_INCLUDE}/ast.h
		done
		make ${PACKAGE_ast_INCLUDE}/tm.h implicit
			prev ${PACKAGE_ast_INCLUDE}/times.h
			prev ${PACKAGE_ast_INCLUDE}/ast.h
		done
	done
	make ${PACKAGE_ast_INCLUDE}/ast_float.h implicit
		prev ${PACKAGE_ast_INCLUDE}/endian.h
		prev ${PACKAGE_ast_INCLUDE}/ast_common.h
	done
	make ${PACKAGE_ast_INCLUDE}/ast_dir.h implicit
		make ${PACKAGE_ast_INCLUDE}/dirent.h implicit
			make ${PACKAGE_ast_INCLUDE}/ast_dirent.h implicit
				prev ${PACKAGE_ast_INCLUDE}/ast_std.h
			done
		done
		prev ${PACKAGE_ast_INCLUDE}/ast_lib.h
	done
	make ${PACKAGE_ast_INCLUDE}/wait.h implicit
		prev ${PACKAGE_ast_INCLUDE}/ast_wait.h implicit
		prev ${PACKAGE_ast_INCLUDE}/ast.h
	done
	prev ${PACKAGE_ast_INCLUDE}/ast_standards.h implicit
	prev ${PACKAGE_ast_INCLUDE}/sig.h implicit
	prev ${PACKAGE_ast_INCLUDE}/glob.h implicit
	prev ${PACKAGE_ast_INCLUDE}/releaseflags.h implicit
	make ${PACKAGE_ast_INCLUDE}/lc.h implicit
		prev ${PACKAGE_ast_INCLUDE}/ast.h
	done
	prev ${PACKAGE_ast_INCLUDE}/ast_tty.h implicit

	note *
	note * Library dependencies
	note *

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

	make shell.req
		prev ${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 ${mam_cc_L+-L.} ${mam_cc_L+-L${INSTALLROOT}/lib} -I${PACKAGE_ast_INCLUDE} -I${INSTALLROOT}/include ${mam_libdll} ${mam_libcmd} ${mam_libast} ${mam_libm} ${mam_libnsl} : run

	make features/time
		prev ${PACKAGE_ast_INCLUDE}/times.h
	done

	make features/dynamic
		prev ${PACKAGE_ast_INCLUDE}/dlldefs.h
	done

	loop F options externs sigfeatures time dynamic locale cmds poll rlimits
		make FEATURE/${F} implicit
			prev features/${F}
			exec - ${iffe_run} ${<}
		done
	done

	make FEATURE/math implicit
		make features/math.sh
			prev ${PACKAGE_ast_INCLUDE}/ast_float.h
			prev data/math.tab implicit
		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 implicit
		prev FEATURE/options
		prev SHOPT.sh
		prev 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 >shopt.h
		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 implicit
		prev FEATURE/sigfeatures
		prev ${PACKAGE_ast_INCLUDE}/sfio.h
		prev ${PACKAGE_ast_INCLUDE}/error.h
		prev ${PACKAGE_ast_INCLUDE}/sig.h
	done

	make include/history.h implicit
		prev ${PACKAGE_ast_INCLUDE}/ast.h
	done

	make include/nval.h implicit
		prev ${PACKAGE_ast_INCLUDE}/option.h
		prev ${PACKAGE_ast_INCLUDE}/cdt.h
		prev ${PACKAGE_ast_INCLUDE}/ast.h
	done

	make include/name.h implicit
		prev include/nval.h
		prev ${PACKAGE_ast_INCLUDE}/cdt.h
		prev ${PACKAGE_ast_INCLUDE}/ast.h
	done

	make include/shell.h implicit
		prev include/fault.h
		prev ${PACKAGE_ast_INCLUDE}/stk.h
		prev include/history.h
		prev ${PACKAGE_ast_INCLUDE}/cmd.h
		prev ${PACKAGE_ast_INCLUDE}/shcmd.h
		prev include/nval.h
		prev include/name.h
		prev ${PACKAGE_ast_INCLUDE}/cdt.h
		prev ${PACKAGE_ast_INCLUDE}/ast.h
	done

	make include/shtable.h implicit
	done

	make include/builtins.h implicit
		prev include/shtable.h
		prev FEATURE/dynamic
		prev ${PACKAGE_ast_INCLUDE}/option.h
	done

	make include/regress.h implicit
	done

	make include/argnod.h implicit
	done

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

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

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

	make include/variables.h implicit
		prev FEATURE/dynamic
		prev ${PACKAGE_ast_INCLUDE}/option.h
		prev include/nval.h
	done

	make include/shnodes.h implicit
		prev include/argnod.h
		prev ${PACKAGE_ast_INCLUDE}/ast.h
	done

	make include/national.h implicit
	done

	make include/terminal.h implicit
		prev ${PACKAGE_ast_INCLUDE}/ast_tty.h
	done

	make include/edit.h implicit
		prev include/national.h
		prev include/terminal.h
		prev ${PACKAGE_ast_INCLUDE}/sig.h
		prev FEATURE/locale
		prev FEATURE/cmds
	done

	make include/io.h implicit
		prev ${PACKAGE_ast_INCLUDE}/sfio.h
		prev ${PACKAGE_ast_INCLUDE}/ast.h
	done

	make include/jobs.h implicit
		prev ${PACKAGE_ast_INCLUDE}/vmalloc.h
		prev include/terminal.h
		prev ${PACKAGE_ast_INCLUDE}/aso.h
		prev ${PACKAGE_ast_INCLUDE}/sfio.h
		prev ${PACKAGE_ast_INCLUDE}/ast.h
	done

	make include/streval.h implicit
		prev ${PACKAGE_ast_INCLUDE}/ast_float.h
		prev include/defs.h
		prev ${PACKAGE_ast_INCLUDE}/ast.h
	done

	make include/lexstates.h implicit
		prev ${PACKAGE_ast_INCLUDE}/wctype.h
		prev ${PACKAGE_ast_INCLUDE}/wchar.h
		prev FEATURE/locale
	done

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

	make include/shlex.h implicit
		prev include/lexstates.h
		prev include/shtable.h
		prev include/shnodes.h
		prev ${PACKAGE_ast_INCLUDE}/cdt.h
	done

	make include/fcin.h implicit
		prev ${PACKAGE_ast_INCLUDE}/sfio.h
	done

	make include/version.h implicit
		prev ${PACKAGE_ast_INCLUDE}/releaseflags.h
	done

	make include/timeout.h implicit
	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 ${PACKAGE_ast_INCLUDE}/ls.h
		prev include/builtins.h
		prev include/name.h
		prev include/path.h
		prev include/variables.h
		prev ${PACKAGE_ast_INCLUDE}/error.h
		prev include/defs.h
		prev shopt.h
	done

	make bltins/cflow.c
		prev include/builtins.h
		prev include/shnodes.h
		prev ${PACKAGE_ast_INCLUDE}/error.h
		prev ${PACKAGE_ast_INCLUDE}/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 ${PACKAGE_ast_INCLUDE}/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 ${PACKAGE_ast_INCLUDE}/error.h
		prev ${PACKAGE_ast_INCLUDE}/ls.h
		prev include/defs.h
		prev shopt.h
	done

	make bltins/misc.c
		prev ${PACKAGE_ast_INCLUDE}/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 ${PACKAGE_ast_INCLUDE}/cmd.h
		prev ${PACKAGE_ast_INCLUDE}/error.h
		prev include/nval.h
		prev include/defs.h
		prev shopt.h
	done

	make bltins/print.c
		prev ${PACKAGE_ast_INCLUDE}/ccode.h
		prev ${PACKAGE_ast_INCLUDE}/tmx.h
		prev include/streval.h
		prev include/builtins.h
		prev include/history.h
		prev include/name.h
		prev include/io.h
		prev ${PACKAGE_ast_INCLUDE}/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 ${PACKAGE_ast_INCLUDE}/error.h
		prev ${PACKAGE_ast_INCLUDE}/ast.h
		prev shopt.h
	done

	make bltins/sleep.c
		prev FEATURE/poll
		prev FEATURE/time
		prev include/builtins.h
		prev ${PACKAGE_ast_INCLUDE}/tmx.h
		prev ${PACKAGE_ast_INCLUDE}/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 ${PACKAGE_ast_INCLUDE}/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 ${PACKAGE_ast_INCLUDE}/regex.h
		prev ${PACKAGE_ast_INCLUDE}/ls.h
		prev ${PACKAGE_ast_INCLUDE}/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 ${PACKAGE_ast_INCLUDE}/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 ${PACKAGE_ast_INCLUDE}/error.h
		prev ${PACKAGE_ast_INCLUDE}/sfio.h
		prev ${PACKAGE_ast_INCLUDE}/ast.h
		prev shopt.h
	done

	make bltins/umask.c
		prev include/builtins.h
		prev include/shell.h
		prev ${PACKAGE_ast_INCLUDE}/ls.h
		prev ${PACKAGE_ast_INCLUDE}/error.h
		prev ${PACKAGE_ast_INCLUDE}/sfio.h
		prev ${PACKAGE_ast_INCLUDE}/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 ${PACKAGE_ast_INCLUDE}/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 ${PACKAGE_ast_INCLUDE}/ls.h
		prev ${PACKAGE_ast_INCLUDE}/sfio.h
		prev ${PACKAGE_ast_INCLUDE}/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 ${PACKAGE_ast_INCLUDE}/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 ${PACKAGE_ast_INCLUDE}/ls.h
		prev FEATURE/time
		prev include/fault.h
		prev ${PACKAGE_ast_INCLUDE}/ccode.h
		prev ${PACKAGE_ast_INCLUDE}/ast.h
		prev shopt.h
	done

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

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

	make sh/fault.c
		prev ${PACKAGE_ast_INCLUDE}/vmalloc.h
		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 ${PACKAGE_ast_INCLUDE}/error.h
		prev ${PACKAGE_ast_INCLUDE}/sfio.h
		prev ${PACKAGE_ast_INCLUDE}/ast.h
		prev shopt.h
	done

	make edit/history.c
		prev ${PACKAGE_ast_INCLUDE}/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 ${PACKAGE_ast_INCLUDE}/ls.h
		prev ${PACKAGE_ast_INCLUDE}/error.h
		prev FEATURE/time
		prev ${PACKAGE_ast_INCLUDE}/sfio.h
		prev ${PACKAGE_ast_INCLUDE}/ast.h
		prev shopt.h
	done

	make sh/init.c
		prev ${PACKAGE_ast_INCLUDE}/wctype.h
		prev ${PACKAGE_ast_INCLUDE}/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 ${PACKAGE_ast_INCLUDE}/regex.h
		prev ${PACKAGE_ast_INCLUDE}/tmx.h
		prev ${PACKAGE_ast_INCLUDE}/ccode.h
		prev include/defs.h
		prev shopt.h
	done

	make sh/io.c
		prev ${PACKAGE_ast_INCLUDE}/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 ${PACKAGE_ast_INCLUDE}/regex.h
		prev ${PACKAGE_ast_INCLUDE}/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 ${PACKAGE_ast_INCLUDE}/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 ${PACKAGE_ast_INCLUDE}/releaseflags.h
		prev ${PACKAGE_ast_INCLUDE}/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 ${PACKAGE_ast_INCLUDE}/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 ${PACKAGE_ast_INCLUDE}/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 ${PACKAGE_ast_INCLUDE}/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 ${PACKAGE_ast_INCLUDE}/ls.h
		prev include/fcin.h
		prev include/defs.h
		prev shopt.h
	done

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

	make sh/streval.c
		prev FEATURE/externs
		prev ${PACKAGE_ast_INCLUDE}/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 ${PACKAGE_ast_INCLUDE}/ls.h
		prev include/defs.h
		prev shopt.h
	done

	make sh/tdump.c
		prev ${PACKAGE_ast_INCLUDE}/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 ${PACKAGE_ast_INCLUDE}/error.h
		prev ${PACKAGE_ast_INCLUDE}/sig.h
		prev ${PACKAGE_ast_INCLUDE}/ast.h
		prev shopt.h
	done

	make sh/trestore.c
		prev ${PACKAGE_ast_INCLUDE}/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 ${PACKAGE_ast_INCLUDE}/vmalloc.h
		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 ${PACKAGE_ast_INCLUDE}/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 ${PACKAGE_ast_INCLUDE}/ast.h
		prev shopt.h
	done

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

	make data/testops.c
		prev include/test.h
		prev include/defs.h
		prev ${PACKAGE_ast_INCLUDE}/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 ${PACKAGE_ast_INCLUDE}/ast.h
		prev shopt.h
	done

	make data/lexstates.c
		prev include/lexstates.h
		prev ${PACKAGE_ast_INCLUDE}/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 ${PACKAGE_ast_INCLUDE}/releaseflags.h
		prev ${PACKAGE_ast_INCLUDE}/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 ${PACKAGE_ast_INCLUDE}/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${PACKAGE_ast_INCLUDE} -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 * Set the mam_libshell variable
	bind -lshell

	shim - link_binary()
	shim - {
	shim -     ${CC} ${CCLDFLAGS} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS} \
	shim -		${mam_cc_L+-L.} ${mam_cc_L+-L${INSTALLROOT}/lib} \
	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/libshell${mam_cc_SUFFIX_SHARED} dontcare
		prev libshell.a
		prev shell.req
		exec - export LDFLAGS='${LDFLAGS} ${CCLDFLAGS} ${mam_cc_LD_NOASNEEDED}'
		exec - dylink -m shell -v ${DYLIB_VERSION} -s ${mam_cc_SUFFIX_SHARED} $(sed 1d shell.req) ${_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 shell.req) ${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 shell.req) ${mam_libnsl} ${mam_libm} shcomp.o
	done

	note *
	note * Pre-install
	note *

	loop DIR bin include/ast lib/lib man/man1 man/man3 fun etc
		make ${INSTALLROOT}/${DIR}
			exec - mkdir -p ${@}
		done
	done
	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
		prev 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
			prev ${MAN3PG}.3
			exec - cp -f ${<} ${@}
		done
	done
	make ${INSTALLROOT}/lib/lib/shell
		prev shell.req
		exec - cp -f ${<} ${@}
	done
	loop HDR nval shell history
		make ${PACKAGE_ast_INCLUDE}/${HDR}.h
			prev include/${HDR}.h
			exec - cp -f ${<} ${@}
		done
	done
	loop FUN autocd cd dirs man mcd popd pushd
		make ${INSTALLROOT}/fun/${FUN}
			prev fun/${FUN}
			exec - cp -f ${<} ${@} && chmod ugo+x ${@}
		done
	done
	make ${INSTALLROOT}/etc/kshrc
		prev kshrc.sh
		exec - cp -f ${<} ${@}
	done
done install

note *
note * Run regression tests.
note *

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