Skip to content

Instantly share code, notes, and snippets.

@calorie
Created October 15, 2013 09:03
Show Gist options
  • Save calorie/6988791 to your computer and use it in GitHub Desktop.
Save calorie/6988791 to your computer and use it in GitHub Desktop.
# http://qiita.com/ToQoz/items/848abdf90a0f40e70ce0
# http://stackoverflow.com/questions/3063507/list-goals-targets-in-gnu-make/9524878#9524878
_makefile_cache_updated_at() {
echo $(stat .make_targets -c%Y)
}
_makefile_updated_at() {
echo $(stat Makefile -c%Y)
}
_generate_makefile_cache() {
[ -f .make_targets ] && rm .make_targets
make -qp | awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ {split($1,A,/ /);for(i in A)print A[i]}' > .make_targets
}
_make() {
if [ -f Makefile ]; then
if [ ! -f .make_targets ] || \
[ "`cat .make_targets | wc -l`" = "0" ] || \
[ `_makefile_cache_updated_at` -lt `_makefile_updated_at` ] || \
[ -f Makefile -a `_makefile_cache_updated_at` -lt `_makefile_updated_at` ]; then
_generate_makefile_cache
fi
compadd `cat .make_targets`
fi
}
compdef _make make
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment