Skip to content

Instantly share code, notes, and snippets.

@0x5742
Created September 5, 2015 13:35
Show Gist options
  • Select an option

  • Save 0x5742/744bf31b54ffb501ade8 to your computer and use it in GitHub Desktop.

Select an option

Save 0x5742/744bf31b54ffb501ade8 to your computer and use it in GitHub Desktop.
a wrapper for make that searches parent directories
#!/bin/sh
# I always felt 'make' ought to do this.
# Search parent directories until Makefile is found, and build there.
# All options are passed directly to make, with a possible -C if none exists.
# (If -C or -f are given on the command line, no searching is done.)
dir="."
findparents=true
for arg in "$@"; do
case "$arg" in
-C*|-f*) findparents=false ;;
esac
done
while $findparents; do
for fn in makefile Makefile; do
if [ -e "$dir/$fn" ]; then
#echo "==> $fn found in $dir"
test $dir = '.' || set -- -C "$dir" "$@"
break
fi
done
if [ "$dir" -ef "$dir/.." ]; then
break
else
dir="$dir/.."
fi
done
exec ${MAKE:-make} "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment