summaryrefslogtreecommitdiffstats
path: root/helpers/make-extract-targets.awk
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 01:03:18 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 01:03:18 +0000
commitf4acb49ea148cdd899f7f29f1591c7bc853c2135 (patch)
treeb62d60873864065d6428a84a119dd8a3c90f1397 /helpers/make-extract-targets.awk
parentAdding upstream version 1:2.11. (diff)
downloadbash-completion-f4acb49ea148cdd899f7f29f1591c7bc853c2135.tar.xz
bash-completion-f4acb49ea148cdd899f7f29f1591c7bc853c2135.zip
Adding upstream version 1:2.12.0.upstream/1%2.12.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'helpers/make-extract-targets.awk')
-rw-r--r--helpers/make-extract-targets.awk93
1 files changed, 93 insertions, 0 deletions
diff --git a/helpers/make-extract-targets.awk b/helpers/make-extract-targets.awk
new file mode 100644
index 0000000..b0ce10e
--- /dev/null
+++ b/helpers/make-extract-targets.awk
@@ -0,0 +1,93 @@
+# helper AWK script for GNU make -*- awk -*-
+
+# This AWK script is used by the function `_comp_cmd_make__extract_targets` in
+# `completions/make`. This script receives the output of `make -npq' as the
+# input file or stdin and outputs the list of targets matching the prefix.
+#
+# @env prefix Specifies the prefix to match.
+# @env prefix_replace Specifies the string that replaces the prefix in the
+# output. This is used when we want to omit the directory name in showing
+# the list of the completions.
+#
+
+BEGIN {
+ prefix = ENVIRON["prefix"];
+ prefix_replace = ENVIRON["prefix_replace"];
+ is_target_block = 0;
+ target = "";
+}
+
+function starts_with(str, prefix) {
+ return substr(str, 1, length(prefix)) == prefix;
+}
+
+# skip any makefile outputs
+NR == 1, /^# +Make data base/ { next; }
+/^# +Finished Make data base/,/^# +Make data base/ { next; }
+
+# skip until files section
+/^# +Variables/, /^# +Files/ { next; }
+
+# skip not-target blocks
+/^# +Not a target/, /^$/ { next; }
+
+# 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.
+
+# only process the targets the user wants.
+starts_with($0, prefix) { is_target_block = 1; }
+is_target_block == 0 { next; }
+
+/^# +File is an intermediate prerequisite/ { # cancel the block
+ is_target_block = 0;
+ target = "";
+ next;
+}
+
+# end of target block
+/^$/ {
+ is_target_block = 0;
+ if (target != "") {
+ print target;
+ target = "";
+ }
+ next;
+}
+
+# found target block
+/^[^#\t:%]+:/ {
+ # special targets
+ if (/^\.PHONY:/ ) next;
+ if (/^\.SUFFIXES:/ ) next;
+ if (/^\.DEFAULT:/ ) next;
+ if (/^\.PRECIOUS:/ ) next;
+ if (/^\.INTERMEDIATE:/ ) next;
+ if (/^\.SECONDARY:/ ) next;
+ if (/^\.SECONDEXPANSION:/ ) next;
+ if (/^\.DELETE_ON_ERROR:/ ) next;
+ if (/^\.IGNORE:/ ) next;
+ if (/^\.LOW_RESOLUTION_TIME:/ ) next;
+ if (/^\.SILENT:/ ) next;
+ if (/^\.EXPORT_ALL_VARIABLES:/) next;
+ if (/^\.NOTPARALLEL:/ ) next;
+ if (/^\.ONESHELL:/ ) next;
+ if (/^\.POSIX:/ ) next;
+ if (/^\.NOEXPORT:/ ) next;
+ if (/^\.MAKE:/ ) next;
+
+ # dont complete with hidden targets unless we are doing a partial completion
+ if (prefix == "" || prefix ~ /\/$/)
+ if (substr($0, length(prefix) + 1, 1) ~ /[^a-zA-Z0-9]/)
+ next;
+
+ target = $0;
+ sub(/:.*/, "", target);
+ if (prefix_replace != prefix)
+ target = prefix_replace substr(target, 1 + length(prefix));
+
+ next;
+}
+
+# ex: filetype=awk