#!/bin/sh
#
# Maketool - GTK-based front end for gmake
# Copyright (c) 1999-2003 Greg Banks
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#
# Wrapper for non-GNU make programs which emits gmake-style messages on
# entering and leaving directories, necessary for tracking which directory
# a file belongs to in a recursive build.
#
dnl The usual m4-around-sh trick for quotes is to use [] but
dnl here we need them for ksh array syntax, so use <>
changequote(<,>)

ME=base

if [ -z "$MAKELEVEL" ]; then
    MAKELEVEL=0
else
    MAKELEVEL=`expr $MAKELEVEL + 1`
fi
export MAKELEVEL

HERE=`/bin/pwd`
if [ $MAKELEVEL -gt 0 ]; then
    echo $ME"[$MAKELEVEL]: Entering directory \`$HERE'"
fi

define(<smake_hack>,ifelse(
    base-host_os,<smake-irix6.5>,<yes>,
    <no>))
ifelse(smake_hack,<yes>,<
# Bloody smake will only accept arguments in the order:
# options, variable-overrides, targets so we have to
# parse and rebuild the options to override $MAKE.
# Fortunately on IRIX we know /bin/sh is ksh so we can
# use ksh arrays to preserve whitespace.
set -A OPTS
set -A VOVER
set -A TARGS
while [ $# -gt 0 ]; do
    case "$1" in
    -J*|-n|-k|-q)
    	OPTS[${#OPTS[@]}]="$1"
	;;
    -p|-f)
    	OPTS[${#OPTS[@]}]="$1"
    	OPTS[${#OPTS[@]}]="$2"
    	<shift>
    	;;
    -*) echo "$ME: unknown option \"$1\" ignoring" ;;
    *=*) 
    	VOVER[${#VOVER[@]}]="$1"
	;;
    *)
    	TARGS[${#TARGS[@]}]="$1"
	;;
    esac
    <shift>
done
exe "${OPTS[@]}" "${VOVER[@]}" MAKE=$ME "${TARGS[@]}">,
<exe MAKE=$ME "$@">)
status=$?

if [ $MAKELEVEL -gt 0 ]; then
    echo $ME"[$MAKELEVEL]: Leaving directory \`$HERE'"
fi

exit $status


syntax highlighted by Code2HTML, v. 0.9.1