-
Notifications
You must be signed in to change notification settings - Fork 374
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1069 from akinomyoga/use-awk-for-make
refactor(make): Use awk to extract target names
- Loading branch information
Showing
11 changed files
with
137 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
helpersdir = $(datadir)/$(PACKAGE)/helpers | ||
helpers_DATA = perl python | ||
helpers_DATA = perl python make-extract-targets.awk | ||
|
||
EXTRA_DIST = $(helpers_DATA) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters