Skip to content

Instantly share code, notes, and snippets.

@pvdb
Last active August 16, 2024 15:26

Revisions

  1. pvdb revised this gist Oct 6, 2015. 1 changed file with 4 additions and 5 deletions.
    9 changes: 4 additions & 5 deletions list_targets.sh
    Original file line number Diff line number Diff line change
    @@ -13,22 +13,21 @@
    #
    # (1) the sed expression is "scraping" the make output, and will hence break of the output format ever changes
    # (2) the "-r" option excludes the built-in rules, as these are typically not relevant, but isn't required
    # (3) to improve the readability of the output, "| egrep -v '^.PHONY:'" can be appended to the pipeline
    # (4) implementation as a shell alias or as a Makefile target left as an exercise to the reader :-)
    # (3) implementation as a shell alias or as a Makefile target left as an exercise to the reader :-)
    #

    #
    # in the directory containing your Makefile:
    #
    make -rpn | sed -n -e '/^$/ { n ; /^[^ ]*:/p ; }'
    make -rpn | sed -n -e '/^$/ { n ; /^[^ .#][^ ]*:/p ; }'

    #
    # ... or add a touch of color by highlighting the targets in the rules:
    #
    make -rpn | sed -n -e '/^$/ { n ; /^[^ ]*:/p ; }' | egrep --color '^[^ ]*:'
    make -rpn | sed -n -e '/^$/ { n ; /^[^ .#][^ ]*:/p ; }' | egrep --color '^[^ ]*:'

    #
    # ... or if you prefer just the list of targets, WITHOUT the dependencies:
    #
    make -rpn | sed -n -e '/^$/ { n ; /^[^ ]*:/ { s/:.*$// ; p ; } ; }'
    make -rpn | sed -n -e '/^$/ { n ; /^[^ .#][^ ]*:/ { s/:.*$// ; p ; } ; }'

  2. pvdb revised this gist Oct 6, 2015. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions list_targets.sh
    Original file line number Diff line number Diff line change
    @@ -26,3 +26,9 @@ make -rpn | sed -n -e '/^$/ { n ; /^[^ ]*:/p ; }'
    # ... or add a touch of color by highlighting the targets in the rules:
    #
    make -rpn | sed -n -e '/^$/ { n ; /^[^ ]*:/p ; }' | egrep --color '^[^ ]*:'

    #
    # ... or if you prefer just the list of targets, WITHOUT the dependencies:
    #
    make -rpn | sed -n -e '/^$/ { n ; /^[^ ]*:/ { s/:.*$// ; p ; } ; }'

  3. pvdb revised this gist Oct 6, 2015. 1 changed file with 0 additions and 0 deletions.
    Empty file modified list_targets.sh
    100644 → 100755
    Empty file.
  4. pvdb revised this gist Oct 6, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions list_targets.sh
    Original file line number Diff line number Diff line change
    @@ -20,9 +20,9 @@
    #
    # in the directory containing your Makefile:
    #
    make -rpn | sed -n -e '/^$/ { n ; /^[^ ]*:/p }'
    make -rpn | sed -n -e '/^$/ { n ; /^[^ ]*:/p ; }'

    #
    # ... or add a touch of color by highlighting the targets in the rules:
    #
    make -rpn | sed -n -e '/^$/ { n ; /^[^ ]*:/p }' | egrep --color '^[^ ]*:'
    make -rpn | sed -n -e '/^$/ { n ; /^[^ ]*:/p ; }' | egrep --color '^[^ ]*:'
  5. pvdb revised this gist Jan 13, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion list_targets.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #
    # this gist can be used to list all targets, or - more correctly - rules,
    # that are defined in a Makefile (and possibly other, included Makefiles)
    # that are defined in a Makefile (and possibly other included Makefiles)
    # and is inspired by Jack Kelly's reply to a StackOverflow question:
    #
    # http://stackoverflow.com/questions/3063507/list-goals-targets-in-gnu-make/3632592#3632592
  6. pvdb revised this gist Jan 13, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion list_targets.sh
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@
    #
    # Notes:
    #
    # (1) the sed expression is "scraping" the make output, and will hence break of the output format changes
    # (1) the sed expression is "scraping" the make output, and will hence break of the output format ever changes
    # (2) the "-r" option excludes the built-in rules, as these are typically not relevant, but isn't required
    # (3) to improve the readability of the output, "| egrep -v '^.PHONY:'" can be appended to the pipeline
    # (4) implementation as a shell alias or as a Makefile target left as an exercise to the reader :-)
  7. pvdb revised this gist Jan 13, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion list_targets.sh
    Original file line number Diff line number Diff line change
    @@ -25,4 +25,4 @@ make -rpn | sed -n -e '/^$/ { n ; /^[^ ]*:/p }'
    #
    # ... or add a touch of color by highlighting the targets in the rules:
    #
    make -rpn | sed -n -e '/^$/ { n ; /^[^ ]*:/p }' | egrep --color '^[^ ]*: '
    make -rpn | sed -n -e '/^$/ { n ; /^[^ ]*:/p }' | egrep --color '^[^ ]*:'
  8. pvdb created this gist Jan 13, 2011.
    28 changes: 28 additions & 0 deletions list_targets.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    #
    # this gist can be used to list all targets, or - more correctly - rules,
    # that are defined in a Makefile (and possibly other, included Makefiles)
    # and is inspired by Jack Kelly's reply to a StackOverflow question:
    #
    # http://stackoverflow.com/questions/3063507/list-goals-targets-in-gnu-make/3632592#3632592
    #
    # I also found this script - http://www.shelldorado.com/scripts/cmds/targets - which does
    # something similar using awk, but it extracts targets from the "static" rules from a single
    # Makefile, meaning it ignores any included Makefiles, as well as targets from "dynamic" rules
    #
    # Notes:
    #
    # (1) the sed expression is "scraping" the make output, and will hence break of the output format changes
    # (2) the "-r" option excludes the built-in rules, as these are typically not relevant, but isn't required
    # (3) to improve the readability of the output, "| egrep -v '^.PHONY:'" can be appended to the pipeline
    # (4) implementation as a shell alias or as a Makefile target left as an exercise to the reader :-)
    #

    #
    # in the directory containing your Makefile:
    #
    make -rpn | sed -n -e '/^$/ { n ; /^[^ ]*:/p }'

    #
    # ... or add a touch of color by highlighting the targets in the rules:
    #
    make -rpn | sed -n -e '/^$/ { n ; /^[^ ]*:/p }' | egrep --color '^[^ ]*: '