diff options
Diffstat (limited to 'Completion/Unix/Command/_make')
-rw-r--r-- | Completion/Unix/Command/_make | 154 |
1 files changed, 81 insertions, 73 deletions
diff --git a/Completion/Unix/Command/_make b/Completion/Unix/Command/_make index e404d162d..53e2e1b3e 100644 --- a/Completion/Unix/Command/_make +++ b/Completion/Unix/Command/_make @@ -3,10 +3,7 @@ # TODO: Based on targets given on the command line, show only variables that # are used in those targets and their dependencies. -local prev="$words[CURRENT-1]" file expl tmp is_gnu dir incl match -local -A TARGETS VARIABLES - -expandVars() { +_make-expandVars() { local open close var val front ret tmp=$1 front=${tmp%%\$*} @@ -28,7 +25,7 @@ expandVars() { ;; (\$*) # Escaped $. - print -- "${front}\$$(expandVars ${tmp#\$})" + print -- "${front}\$$(_make-expandVars ${tmp#\$})" return ;; @@ -58,10 +55,10 @@ expandVars() { ;; esac - print -- "${front}$(expandVars ${ret})" + print -- "${front}$(_make-expandVars ${ret})" } -parseMakefile () { +_make-parseMakefile () { local input var val target dep TAB=$'\t' dir=$1 tmp while read input @@ -81,14 +78,14 @@ parseMakefile () { var=${input%%[ $TAB]#:=*} val=${input#*=} val=${val##[ $TAB]#} - val=$(expandVars $val) + val=$(_make-expandVars $val) VARIABLES[$var]=$val ;; # TARGET: dependencies # TARGET1 TARGET2 TARGET3: dependencies ([[:alnum:]][^$TAB:=]#:[^=]*) - input=$(expandVars $input) + input=$(_make-expandVars $input) target=${input%%:*} dep=${input#*:} dep=${(z)dep} @@ -107,7 +104,7 @@ parseMakefile () { f=${f#[\"<]} f=${f%[\">]} fi - f=$(expandVars $f) + f=$(_make-expandVars $f) case $f in (/*) ;; (*) f=$dir/$f ;; @@ -115,14 +112,14 @@ parseMakefile () { if [[ -r $f ]] then - parseMakefile ${f%%/[^/]##} < $f + _make-parseMakefile ${f%%/[^/]##} < $f fi ;; esac done } -findBasedir () { +_make-findBasedir () { local file index basedir basedir=$PWD for (( index=0; index < $#@; index++ )) @@ -148,75 +145,86 @@ findBasedir () { print -- $basedir } -_pick_variant -r is_gnu gnu=GNU unix -v -f - -if [[ $is_gnu == gnu ]] -then - incl="(-|)include" -else - incl=.include -fi - -if [[ "$prev" == -[CI] ]] -then - _files -W ${(q)$(findBasedir ${words[1,CURRENT-1]})} -/ -elif [[ "$prev" == -[foW] ]] -then - _files -W ${(q)$(findBasedir $words)} -else - file="$words[(I)-f]" - if (( file )) +_make() { + + local prev="$words[CURRENT-1]" file expl tmp is_gnu dir incl match + local -A TARGETS VARIABLES + local ret=1 + + _pick_variant -r is_gnu gnu=GNU unix -v -f + + if [[ $is_gnu == gnu ]] then - file=${~words[file+1]} - [[ $file == [^/]* ]] && file=${(q)$(findBasedir $words)}/$file - [[ -r $file ]] || file= + incl="(-|)include" else - local basedir - basedir=${(q)$(findBasedir $words)} - if [[ $is_gnu == gnu && -r $basedir/GNUmakefile ]] - then - file=$basedir/GNUmakefile - elif [[ -r $basedir/makefile ]] - then - file=$basedir/makefile - elif [[ -r $basedir/Makefile ]] + incl=.include + fi + + if [[ "$prev" == -[CI] ]] + then + _files -W ${(q)$(_make-findBasedir ${words[1,CURRENT-1]})} -/ && ret=0 + elif [[ "$prev" == -[foW] ]] + then + _files -W ${(q)$(_make-findBasedir $words)} && ret=0 + else + file="$words[(I)-f]" + if (( file )) then - file=$basedir/Makefile + file=${~words[file+1]} + [[ $file == [^/]* ]] && file=${(q)$(_make-findBasedir $words)}/$file + [[ -r $file ]] || file= else - file='' + local basedir + basedir=${$(_make-findBasedir $words)} + if [[ $is_gnu == gnu && -r $basedir/GNUmakefile ]] + then + file=$basedir/GNUmakefile + elif [[ -r $basedir/makefile ]] + then + file=$basedir/makefile + elif [[ -r $basedir/Makefile ]] + then + file=$basedir/Makefile + else + file='' + fi fi - fi - if [[ -n "$file" ]] - then - if [[ $is_gnu == gnu ]] && zstyle -t ":completion:${curcontext}:targets" call-command + if [[ -n "$file" ]] + then + if [[ $is_gnu == gnu ]] && zstyle -t ":completion:${curcontext}:targets" call-command + then + _make-parseMakefile $PWD < <(_call_program targets "$words[1]" -nsp --no-print-directory -f "$file" .PHONY 2> /dev/null) + else + case "$OSTYPE" in + freebsd*) + _make-parseMakefile $PWD < <(_call_program targets "$words[1]" -nsp -f "$file" .PHONY 2> /dev/null) + ;; + *) + _make-parseMakefile $PWD < $file + esac + fi + fi + + if [[ $PREFIX == *'='* ]] then - parseMakefile $PWD < <(_call_program targets "$words[1]" -nsp --no-print-directory -f "$file" .PHONY 2> /dev/null) + # Complete make variable as if shell variable + compstate[parameter]="${PREFIX%%\=*}" + compset -P 1 '*=' + _value "$@" && ret=0 else - case "$OSTYPE" in - freebsd*) - parseMakefile $PWD < <(_call_program targets "$words[1]" -nsp -f "$file" .PHONY 2> /dev/null) - ;; - *) - parseMakefile $PWD < $file - esac + _tags targets variables + while _tags + do + _requested targets expl 'make targets' \ + compadd -- ${(k)TARGETS} && ret=0 + _requested variables expl 'make variables' \ + compadd -S '=' -- ${(k)VARIABLES} && ret=0 + done fi fi - if [[ $PREFIX == *'='* ]] - then - # Complete make variable as if shell variable - compstate[parameter]="${PREFIX%%\=*}" - compset -P 1 '*=' - _value "$@" - else - _tags targets variables - while _tags - do - _requested targets expl 'make targets' \ - compadd -- ${(k)TARGETS} - _requested variables expl 'make variables' \ - compadd -S '=' -- ${(k)VARIABLES} - done - fi -fi + return ret +} + +_make "$@" |