Skip to content

Instantly share code, notes, and snippets.

@Boldewyn
Last active December 17, 2015 07:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Boldewyn/5575397 to your computer and use it in GitHub Desktop.
Save Boldewyn/5575397 to your computer and use it in GitHub Desktop.
Search Makefiles recursively and run make(1) there, if one is found
#!/bin/bash
#
# Search Makefiles recursively and run make(1) there, if one is found
#
DEPTH=$(pwd | tr -c -d / | wc -c)
MOD=.
while [[ $DEPTH > 0 ]]
do
if [[ -f $MOD/Makefile ]]
then
if [[ $MOD == "." ]]; then
make "$@"
else
echo "make -C $MOD $@"
make -C $MOD "$@"
fi
exit 0
fi
MOD=$MOD/..
let DEPTH--
done
echo "No Makefile found." >&2
exit 1
@Boldewyn
Copy link
Author

What is missing is to detect another -C in the mk args and merge it with the -C of the detected Makefile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment