Skip to content

Instantly share code, notes, and snippets.

@YarekTyshchenko
Last active May 13, 2016 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YarekTyshchenko/2a0c2612339b32f5cf4f5df056a5e156 to your computer and use it in GitHub Desktop.
Save YarekTyshchenko/2a0c2612339b32f5cf4f5df056a5e156 to your computer and use it in GitHub Desktop.
Search for a makefile upwards recursively

Search Make

This is a script to recursively search for a Makefile deep in a project, and execute the first one that is found. Designed to be used in sublime_text build script:

{
    "shell_cmd": "~/search_make.sh rsync"
}

Can also be used directly from command line as a replacement for Make:

alias make='~/search_make.sh'

Installation

To install the latest verison of this script simply do:

curl -sL "https://gist.githubusercontent.com/YarekTyshchenko/2a0c2612339b32f5cf4f5df056a5e156/raw/search_make.sh" > ~/search_make.sh
chmod +x ~/search_make.sh
alias smake='~/search_make.sh'

Installation of Sublime Build system

I managed to squeese the script into actual ST build system file, This is relatively experimental, I would still recommend you use the search_make.sh invoked from the build system, but This is easier to distribute.

To install go to Tools > Build System > New Build System...

Paste the contents of dce.sublime-build from here into the editor, and save the file as dce.sublime-build.

Now you if you select that build system for any file in any DCE project and hit ⌘B for Rsync, and ⌘⇧B for a drop down selection of make build and make start

{
"shell_cmd": "x=\\$(pwd);levels=0; while ! [ -f \"\\$x/Makefile\" ]; do ((levels++)); if [ \\$levels -gt 16 ]; then echo \"Looked 16 levels up, Makefile not found\"; exit 1; fi; x=\\$(dirname \"\\$x\"); done; echo \"found Makefile at \\$levels levels : \\$x/Makefile\"; ( cd \\$x; make rsync )",
"variants": [
{
"name": "build",
"shell_cmd": "x=\\$(pwd);levels=0; while ! [ -f \"\\$x/Makefile\" ]; do ((levels++)); if [ \\$levels -gt 16 ]; then echo \"Looked 16 levels up, Makefile not found\"; exit 1; fi; x=\\$(dirname \"\\$x\"); done; echo \"found Makefile at \\$levels levels : \\$x/Makefile\"; ( cd \\$x; make build )",
},
{
"name": "start",
"shell_cmd": "x=\\$(pwd);levels=0; while ! [ -f \"\\$x/Makefile\" ]; do ((levels++)); if [ \\$levels -gt 16 ]; then echo \"Looked 16 levels up, Makefile not found\"; exit 1; fi; x=\\$(dirname \"\\$x\"); done; echo \"found Makefile at \\$levels levels : \\$x/Makefile\"; ( cd \\$x; make start )",
}
]
}
#!/bin/bash
x=$(pwd)
levels=0
while ! [ -f "$x/Makefile" ]
do
((levels++))
if [ $levels -gt 16 ]
then
echo "Looked 16 levels up, Makefile not found"
exit 1
fi
x=$(dirname "$x")
done
echo "found Makefile at $levels levels : $x/Makefile"
( cd $x; make -f "$x/Makefile" $@ )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment