#!/bin/bash function findMakefile() { file="$2" command cd "$1" while ! test -f "./$file"; do command cd .. 2>/dev/null test "$PWD" == "/" && return done echo "$PWD" } function run() { # Check if it's cmake; if so, don't try to colorise the output test -d "$objdir/CMakeFiles" && progress=false INSIDE_SPECIAL_MAKE=true export INSIDE_SPECIAL_MAKE if $progress; then if type -p pmake >/dev/null; then exec pmake "$@" else echo >&2 "Warning: cannot locate pmake!" fi fi exec $MAKE "$@" } [ "$MAKE" == "$0" ] && unset MAKE MAKE=${MAKE-/usr/bin/make} export MAKE # Don't recurse test -n "$INSIDE_SPECIAL_MAKE" && \ exec $MAKE "$@" # safety check test -f $HOME/.bash_functions && . $HOME/.bash_functions test "`type -t updatedirs`" == function || $MAKE "$@" progress=true file=Makefile dir=. args=() # parse args while test $# -gt 0 ; do case "${1}" in -f*) file="${1#-f}" shift test -z "$file" && { file="${1}" shift } args=("${args[@]}" -f "$file") ;; -C*) dir="${1#-C}" shift test -z "$dir" && { dir="${1}" shift } ;; VERBOSE=1) progress=false args=("${args[@]}" "$1") shift ;; *) args=("${args[@]}" "$1") shift ;; esac done objdir=$(findMakefile "$dir" "$file") if [ -z "$objdir" ]; then # See if updatedirs can do something... objdir=$(command cd "$dir"; updatedirs; findMakefile "$objdir" "$file") fi run -C "$objdir" "${args[@]}" exit 255 # Old code: # Check if $dir exists if ! test -d "$dir"; then # Doesn't exist. Let make complain run -C "$dir" "${args[@]}" fi # Check if $dir is a source or object dir if test -f "$dir/file"; then # It's an object dir, since there's a Makefile there run -C "$dir" "${args[@]}" fi