about summary refs log tree commit diff
path: root/Completion/User/_make
blob: 5161e6689733cb778cc3416a39aecd3e7709c415 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#compdef make gmake pmake dmake

local prev="$words[CURRENT-1]" file expl tmp

(( $+_is_gnu )) || typeset -gA _is_gnu

if (( ! $+_is_gnu[$1] )); then
  if [[ $(_call version $1 -v -f /dev/null </dev/null 2>/dev/null) = *GNU* ]]
  then
    _is_gnu[$1]=yes
  else
    _is_gnu[$1]=
  fi
fi

if [[ "$prev" = -[CI] ]]; then
  _files -/
elif [[ "$prev" = -[foW] ]]; then
  _files
else
  file="$words[(I)-f]"
  if (( file )); then
    file="$words[file+1]"
  elif [[ -e Makefile ]]; then
    file=Makefile
  elif [[ -e makefile ]]; then
    file=makefile
  elif [[ -e GNUmakefile ]]; then
    file=GNUmakefile
  else
    file=''
  fi

  if [[ -n "$file" ]] && _wanted targets; then
    if [[ -n "$_is_gnu[$1]" ]]; then
      tmp=( $(make -nsp --no-print-directory -f "$file" .PHONY | awk '/^[a-zA-Z0-9][^\/\t=]+:/ {print $1}' FS=:) )
    else
      tmp=(
            $(awk '/^[a-zA-Z0-9][^\/\t=]+:/ {print $1}
 	      /^\.include  *<bsd\.port\.(subdir\.|pre\.)?mk>/ || /^\.include  *".*mk\/bsd\.pkg\.(subdir\.)?mk"/ {
 	        print "fetch fetch-list extract patch configure build install reinstall deinstall package describe checkpatch checksum makesum" }' \
 	     FS=: $file)
           )
    fi
    _all_labels targets expl 'make target' compadd "$tmp[@]" && return 0
  fi
  compset -P 1 '*='
  _files
fi