1 # Adapted from https://gist.github.com/777954
5 # this gist can be used to list all targets, or - more correctly - rules,
6 # that are defined in a Makefile (and possibly other included Makefiles)
7 # and is inspired by Jack Kelly's reply to a StackOverflow question:
9 # http://stackoverflow.com/questions/3063507/list-goals-targets-in-gnu-make/3632592#3632592
11 # I also found this script - http://www.shelldorado.com/scripts/cmds/targets - which does
12 # something similar using awk, but it extracts targets from the "static" rules from a single
13 # Makefile, meaning it ignores any included Makefiles, as well as targets from "dynamic" rules
17 # (1) the sed expression is "scraping" the make output, and will hence break of the output format ever changes
18 # (2) the "-r" option excludes the built-in rules, as these are typically not relevant, but isn't required
19 # (3) to improve the readability of the output, "| egrep -v '^.PHONY:'" can be appended to the pipeline
20 # (4) implementation as a shell alias or as a Makefile target left as an exercise to the reader :-)
24 # in the directory containing your Makefile:
26 #make -rpn | sed -n -e '/^$/ { n ; /^[^ ]*:/p }'
29 # ... or add a touch of color by highlighting the targets in the rules:
31 make -rpn |
sed -n -e '/^$/ { n ; /^[^ ]*:/p }' |
egrep --color '^[^ ]*:'