#!/bin/bash

# Do "make", but redirect where installed programs go.

set -e
IFS=`printf '\n\t'`
t=`printf '\t'`

# Search for DESTDIR= option.  If there is one, set environment variable also.
for option ; do
  case "$option" in
    DESTDIR=*) export DESTDIR="${option#DESTDIR=}" ;;
  esac
done

newdir=`run-redir --print`

# Override makefile variables for many commands, because they may
# have absolute pathnames.  The variable mkdir_p is officially obsolete,
# but we want to make sure we catch it.

exec run-redir ${REALMAKE:-make} INSTALL="install${t}-p" CP="cp${t}-p" \
  MKDIR="mkdir" MKDIR_P="mkdir${t}-p" mkdir_p="mkdir${t}-p" LN="ln" \
  SHELL="$newdir/bogus-shell" MAKESHELL="$newdir/bogus-shell" "$@"

