#!/bin/sh -efu
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright (C) 2007-2023  Alexey Gladkov <gladkov.alexey@gmail.com>

# shellcheck source=/bin/shell-quote
. shell-quote

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

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

cd "$dir"

for envname in $(print_environ_names); do
	case "$envname" in
		GLOBAL_*|MAKEFLAGS|MAKELEVEL|MFLAGS|PATH|PWD|SHELL|TERM|TMP|TMPDIR|USER)
			;;
		*)
			unset "$envname"
			;;
	esac
done

exec "$@"
