1
1
#compdef make gmake pmake dmake
3
local prev="$words[CURRENT-1]" file expl tmp is_gnu dir incl
3
# TODO: Based on targets given on the command line, show only variables that
4
# are used in those targets and their dependencies.
6
local prev="$words[CURRENT-1]" file expl tmp is_gnu dir incl match
7
local -A TARGETS VARIABLES
6
local open close var val tmp=$2 ret=$2
12
if [[ $var != $tmp ]]; then
29
# avoid parsing second $ in $$
36
if [[ $open != '' ]]; then
43
val=$(expandVars $(($1 - 1)) $val)
44
ret=${ret//\$$open$var$close/$val}
48
print -- ${ret//\$\$/\$}
10
local open close var val front ret tmp=$1
14
(\(*) # Variable of the form $(foobar)
24
([[:alpha:]]*) # $foobar. This is exactly $(f)oobar.
31
print -- "${front}\$$(expandVars ${tmp#\$})"
35
(*) # Nothing left to substitute.
49
val=${VARIABLES[$var]}
50
ret=${ret//\$$open$var$close/$val}
54
# Improper variable name. No replacement.
55
# I'm not sure if this is desired behavior.
56
front+="\$$open$var$close"
57
ret=${ret/\$$open$var$close/}
61
print -- "${front}$(expandVars ${ret})"
54
# parseMakefile only runs inside $(...), so it doesn't matter that
55
# it pollutes the global namespace, setting zsh variables to
56
# make variables. The difficult case is where a make variable
57
# is special in zsh; we use local -h to hide those. This
58
# isn't a complete solution since it means variables defined in
59
# included Makefiles are undefined before returning to the parent.
61
local input var val TAB=$'\t' dir=$1
65
([[:alnum:]][[:alnum:]_]#[ $TAB]#=*)
66
var=${input%%[ $TAB]#=*}
69
[[ ${(tP)var} = *special ]] && local -h $var
72
([[:alnum:]][[:alnum:]_]#[ $TAB]#:=*)
73
var=${input%%[ $TAB]#:=*}
76
val=$(expandVars 10 $val)
77
[[ ${(tP)var} = *special ]] && local -h $var
80
([[:alnum:]][^$TAB:=]#:[^=]*)
82
print $(expandVars 10 $input)
85
local f=${input##${~incl} ##}
86
if [[ $incl = '.include' ]]; then
96
parseMakefile ${f%%/[^/]##} < $f
65
local input var val target dep TAB=$'\t' dir=$1 tmp
71
([[:alnum:]][[:alnum:]_]#[ $TAB]#=*)
72
var=${input%%[ $TAB]#=*}
79
# Evaluated immediately
80
([[:alnum:]][[:alnum:]_]#[ $TAB]#:=*)
81
var=${input%%[ $TAB]#:=*}
84
val=$(expandVars $val)
88
# TARGET: dependencies
89
# TARGET1 TARGET2 TARGET3: dependencies
90
([[:alnum:]][^$TAB:=]#:[^=]*)
91
input=$(expandVars $input)
96
for tmp in ${(z)target}
102
# Include another makefile
104
local f=${input##${~incl} ##}
105
if [[ $incl == '.include' ]]
118
parseMakefile ${f%%/[^/]##} < $f
104
126
local file index basedir
106
for ((index=0; index<$#@; index++)); do
107
if [[ $@[index] = -C ]]; then
128
for (( index=0; index < $#@; index++ ))
130
if [[ $@[index] == -C ]]
108
132
file=${~@[index+1]};
109
if [[ -z $file ]]; then
110
# make returns with an error if an empty arg is given
111
# even if the concatenated path is a valid directory
113
elif [[ $file = /* ]]; then
114
# Absolute path, replace base directory
135
# make returns with an error if an empty arg is given
136
# even if the concatenated path is a valid directory
138
elif [[ $file == /* ]]
140
# Absolute path, replace base directory
117
# Relative, concatenate path
118
basedir=$basedir/$file
143
# Relative, concatenate path
144
basedir=$basedir/$file
125
151
_pick_variant -r is_gnu gnu=GNU unix -v -f
127
if [[ $is_gnu = gnu ]]; then
153
if [[ $is_gnu == gnu ]]
132
if [[ "$prev" = -[CI] ]]; then
160
if [[ "$prev" == -[CI] ]]
133
162
_files -W ${(q)$(findBasedir ${words[1,CURRENT-1]})} -/
134
elif [[ "$prev" = -[foW] ]]; then
163
elif [[ "$prev" == -[foW] ]]
135
165
_files -W ${(q)$(findBasedir $words)}
137
167
file="$words[(I)-f]"
139
170
file=${~words[file+1]}
140
[[ $file = [^/]* ]] && file=${(q)$(findBasedir $words)}/$file
171
[[ $file == [^/]* ]] && file=${(q)$(findBasedir $words)}/$file
141
172
[[ -r $file ]] || file=
144
175
basedir=${(q)$(findBasedir $words)}
145
if [[ $is_gnu = gnu && -r $basedir/GNUmakefile ]]; then
176
if [[ $is_gnu == gnu && -r $basedir/GNUmakefile ]]
146
178
file=$basedir/GNUmakefile
147
elif [[ -r $basedir/makefile ]]; then
179
elif [[ -r $basedir/makefile ]]
148
181
file=$basedir/makefile
149
elif [[ -r $basedir/Makefile ]]; then
182
elif [[ -r $basedir/Makefile ]]
150
184
file=$basedir/Makefile
156
if [[ -n "$file" ]] && _tags targets; then
157
if [[ $is_gnu = gnu ]] &&
158
zstyle -t ":completion:${curcontext}:targets" call-command; then
159
tmp=( $(_call_program targets "$words[1]" -nsp --no-print-directory -f "$file" .PHONY 2> /dev/null | parseMakefile $PWD) )
192
if [[ $is_gnu == gnu ]] && zstyle -t ":completion:${curcontext}:targets" call-command
194
parseMakefile $PWD < <(_call_program targets "$words[1]" -nsp --no-print-directory -f "$file" .PHONY 2> /dev/null)
161
tmp=( $(parseMakefile $PWD < $file) )
198
parseMakefile $PWD < <(_call_program targets "$words[1]" -nsp -f "$file" .PHONY 2> /dev/null)
201
parseMakefile $PWD < $file
163
_wanted targets expl 'make target' compadd -a tmp && return 0
165
compstate[parameter]="${PREFIX%%\=*}"
206
if [[ $PREFIX == *'='* ]]
208
# Complete make variable as if shell variable
209
compstate[parameter]="${PREFIX%%\=*}"
213
_tags targets variables
216
_requested targets expl 'make targets' \
217
compadd -- ${(k)TARGETS}
218
_requested variables expl 'make variables' \
219
compadd -S '=' -- ${(k)VARIABLES}