diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | README.markdown | 1 | ||||
-rw-r--r-- | bin/mftl.awk | 38 | ||||
-rw-r--r-- | man/man1/mftl.1df | 30 |
5 files changed, 74 insertions, 2 deletions
@@ -1,6 +1,7 @@ bin/han bin/mean bin/med +bin/mftl bin/mode bin/rfct bin/rndi @@ -69,6 +69,7 @@ SENDMAIL := msmtp all : bin/han \ bin/mean \ bin/med \ + bin/mftl \ bin/mode \ bin/rfct \ bin/rndi \ @@ -86,6 +87,7 @@ clean distclean : bin/han \ bin/mean \ bin/med \ + bin/mftl \ bin/mode \ bin/rfct \ bin/rndi \ @@ -177,8 +179,8 @@ install-bash-completion : install-bash install -pm 0644 -- bash/bash_completion "$(HOME)"/.config/bash_completion install -pm 0644 -- bash/bash_completion.d/* "$(HOME)"/.bash_completion.d -install-bin : bin/han bin/sd2u bin/su2d bin/mean bin/med bin/mode \ - bin/tot bin/unf check-bin install-bin-man +install-bin : bin/han bin/sd2u bin/su2d bin/mean bin/med bin/mftl \ + bin/mode bin/tot bin/unf check-bin install-bin-man install -m 0755 -d -- "$(HOME)"/.local/bin for name in bin/* ; do \ [ -x "$$name" ] || continue ; \ diff --git a/README.markdown b/README.markdown index 36d689cf..2bc94c08 100644 --- a/README.markdown +++ b/README.markdown @@ -433,6 +433,7 @@ Installed by the `install-bin` target: it exits with success or failure. Good for quick tests. * `mean(1df)` prints the mean of a list of integers. * `med(1df)` prints the median of a list of integers. +* `mftl(1df)` finds usable-looking targets in Makefiles. * `mode(1df)` prints the first encountered mode of a list of integers. * `mkcp(1df)` creates a directory and copies preceding arguments into it. * `mkmv(1df)` creates a directory and moves preceding arguments into it. diff --git a/bin/mftl.awk b/bin/mftl.awk new file mode 100644 index 00000000..c6d65409 --- /dev/null +++ b/bin/mftl.awk @@ -0,0 +1,38 @@ +# Try to find the targets in a Makefile that look like they're targets the user +# could be reasonably expected to call directly + +# Separators are space, tab, or colon +BEGIN { + FS = "[ \t:]" +} + +# Skip comments +/^#/ { next } + +# Join backslash-broken lines +/\\$/ { + sub(/\\$/, "") + line = line $0 + next +} +{ + $0 = line $0 + line = "" +} + +# Check lines matching expected "targets:dependencies" format +/^[a-zA-Z0-9][a-zA-Z0-9 \t_-]+:([^=]|$)/ { + + # Iterate through the targets that don't look like substitutions or + # inference rules and stack them up into an array's keys to keep them + # unique; this probably needs refinement + for (i=0; i<NF; i++) + if ($i ~ /^[a-zA-Z0-9][a-zA-Z0-9./_-]*$/) + ats[$i] +} + +# Print unique determined targets, sorted +END { + for (t in ats) + print t | "sort" +} diff --git a/man/man1/mftl.1df b/man/man1/mftl.1df new file mode 100644 index 00000000..efb2b486 --- /dev/null +++ b/man/man1/mftl.1df @@ -0,0 +1,30 @@ +.TH MFTL 1df "September 2016" "Manual page for mftl" +.SH NAME +.B mftl +\- find and list usable-looking targets in Makefiles +.SH SYNOPSIS +.B +mftl +Makefile +.br +.B +mftl +Makefile1 Makefile2 +.br +grep -v foo Makefile | +.B +mftl +.SH DESCRIPTION +.B mftl +searches for targets in a Makefile specified as either targets or dependencies. +Any targets it finds that are simple strings or filenames that look like they +should be referenced by the user, are printed uniquely sorted to stdout. +.P +This is not 100% accurate (and probably can't be); GNU Make's heresies make it +particularly complicated. For simple POSIX-ish Makefiles, it should work well. +The idea is to get an overview of what's accessible in a Makefile without +having to page through the whole thing. +.SH SEE ALSO +make(1) +.SH AUTHOR +Tom Ryder <tom@sanctum.geek.nz> |