From b94c199f29ba6223127dfb5c2becda9176e95c9c Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 5 Sep 2016 00:26:46 +1200 Subject: Add mftl(1df) --- .gitignore | 1 + Makefile | 6 ++++-- README.markdown | 1 + bin/mftl.awk | 38 ++++++++++++++++++++++++++++++++++++++ man/man1/mftl.1df | 30 ++++++++++++++++++++++++++++++ 5 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 bin/mftl.awk create mode 100644 man/man1/mftl.1df diff --git a/.gitignore b/.gitignore index a8e2f9bb..bab3eb65 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ bin/han bin/mean bin/med +bin/mftl bin/mode bin/rfct bin/rndi diff --git a/Makefile b/Makefile index 5fb1de75..98dd0baf 100644 --- a/Makefile +++ b/Makefile @@ -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 -- cgit v1.2.3