Skip to content

Instantly share code, notes, and snippets.

@ejmr
Created July 1, 2015 12:50
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ejmr/00baeff569624a23a676 to your computer and use it in GitHub Desktop.
Save ejmr/00baeff569624a23a676 to your computer and use it in GitHub Desktop.
List all targets of a Makefile from the terminal
#!/bin/sh
#
# Running this script in a directory with a Makefile will print the
# targets in that Makefile, e.g.
#
# $ list-makefile-targets
# all
# clean
# docs
# install
# install-docs
#
# The script uses Perl. Any remotely modern version should suffice.
make -pn | perl -F: -ane 'print "$F[0]\n" if /^\w+\s*:/' | sort | uniq
@ANAU-designs
Copy link

make -pn | perl -F: -ane 'print "$F[0]\n" if /^((?!Makefile)\w+\s*:[^=])/' | sort | uniq
Would be better (added ((?!Makefile) ...) and [^=] just after the s*:) in order to:

  1. remove the 'Makefile' entry which has no real sense and
  2. discard variable declaration with a 'immediate set' assignment (e.g. SERIAL_PORT := /dev/ttyUSBx)
    see https://www.gnu.org/software/make/manual/make.html#Reading-Makefiles

@artu-hnrq
Copy link

Here there's a good option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment