#!/bin/ash -efu
#
# mki-run-make
#
# This file is part of mkimage
# Copyright (C) 2007-2009  Alexey Gladkov <gladkov.alexey@gmail.com>
#
# This file is covered by the GNU General Public License,
# which should be included with mkimage as the file COPYING.
#

. shell-quote

include_without_workdir_check=1
. "${0%/*}"/mki-sh-functions

showenv() {
	local n v

	printenv |
		sed -ne 's/^\(GLOBAL_[^=]\+\)=/\1\t/p' |
	while read n v; do
		printf '%s="%s"\n' "$n" "$(quote_shell "$v")"
	done

	for n in MAKEFLAGS MAKELEVEL MFLAGS \
		PATH PWD SHELL TERM TMP TMPDIR USER;
	do
		eval v="\${$n:-}"

		[ -n "$v" ] || continue
		printf '%s="%s"\n' "${1:+$1 }$n" "$(quote_shell "$v")"
	done
}

dir="$1"; shift
if [ -z "$NO_REMOTES" ] && [ -z "${dir##*=*}" ]; then
	fatal 'remote build is no longer supported'
fi

cd "$dir"

eval exec env -i $(showenv) $(quote_shell "$@")
