Skip to content

Instantly share code, notes, and snippets.

@devzero2000
Created April 8, 2022 07:11
Show Gist options
  • Save devzero2000/cb887a6ba2764f7234191e560b64b7c8 to your computer and use it in GitHub Desktop.
Save devzero2000/cb887a6ba2764f7234191e560b64b7c8 to your computer and use it in GitHub Desktop.

Revisions

  1. devzero2000 created this gist Apr 8, 2022.
    50 changes: 50 additions & 0 deletions list_targets_makefile.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    #!/bin/bash
    #
    # Almost identical to this one
    # https://stackoverflow.com/questions/3063507/list-goals-targets-in-gnu-make-that-contain-variables-in-their-definition/9524878#9524878
    # but it also filters the program targets (.c, .h, ..)

    SCRIPT='
    /^# Make data base/,/^# Files/d # skip until files section
    /^# Not a target/,+1 d # following target isnt
    /^\.PHONY:/ d # special target
    /^\.SUFFIXES:/ d # special target
    /^\.DEFAULT:/ d # special target
    /^\.PRECIOUS:/ d # special target
    /^\.INTERMEDIATE:/ d # special target
    /^\.SECONDARY:/ d # special target
    /^\.SECONDEXPANSION/ d # special target
    /^\.DELETE_ON_ERROR:/ d # special target
    /^\.IGNORE:/ d # special target
    /^\.LOW_RESOLUTION_TIME:/ d # special target
    /^\.SILENT:/ d # special target
    /^\.EXPORT_ALL_VARIABLES:/ d # special target
    /^\.NOTPARALLEL:/ d # special target
    /^\.ONESHELL:/ d # special target
    /^\.POSIX:/ d # special target
    /^\.NOEXPORT:/ d # special target
    /^\.MAKE:/ d # special target
    # The stuff above here describes lines that are not
    # explicit targets or not targets other than special ones
    # The stuff below here decides whether an explicit target
    # should be output.
    /^[^#\t:=%]+:([^=]|$)/ { # found target block
    h # hold target
    d # delete line
    }
    /^# File is an intermediate prerequisite/ { # nope
    s/^.*$//;x # unhold target
    d # delete line
    }
    /^([^#]|$)/ { # end of target block
    s/^.*$//;x # unhold target
    s/:.*$//p # write current target
    d # hide any bugs
    }
    '

    make -npq .DEFAULT 2>/dev/null | sed -n -r "$SCRIPT" \
    | egrep -v '\.[a-z]*' | sort | uniq