_services: Split xinetd service completion into _xinetd_services.
[bash-completion/bash-completion.git] / completions / make
1 # bash completion for GNU make                             -*- shell-script -*-
2
3 _make()
4 {
5     local cur prev words cword split
6     _init_completion -s || return
7
8     local file makef makef_dir="." makef_inc i
9
10     case $prev in
11         -f|--file|--makefile|-o|--old-file|--assume-old|-W|--what-if|\
12         --new-file|--assume-new)
13             _filedir
14             return 0
15             ;;
16         -I|--include-dir|-C|--directory|-m)
17             _filedir -d
18             return 0
19             ;;
20         -E)
21             COMPREPLY=( $( compgen -v -- "$cur" ) )
22             return 0
23             ;;
24         --eval|-D|-V|-x)
25             return 0
26             ;;
27     esac
28
29     $split && return 0
30
31     if [[ "$cur" == -* ]]; then
32         local opts="$( _parse_help "$1" )"
33         [[ $opts ]] || opts="$( _parse_usage "$1" )"
34         COMPREPLY=( $( compgen -W "$opts" -- "$cur" ) )
35         [[ $COMPREPLY == *= ]] && compopt -o nospace
36     else
37         # before we check for makefiles, see if a path was specified
38         # with -C/--directory
39         for (( i=0; i < ${#words[@]}; i++ )); do
40             if [[ ${words[i]} == -@(C|-directory) ]]; then
41                 # eval for tilde expansion
42                 eval makef_dir=${words[i+1]}
43                 break
44             fi
45         done
46
47         # before we scan for targets, see if a Makefile name was
48         # specified with -f/--file/--makefile
49         for (( i=0; i < ${#words[@]}; i++ )); do
50             if [[ ${words[i]} == -@(f|-?(make)file) ]]; then
51                 # eval for tilde expansion
52                 eval makef=${words[i+1]}
53                 break
54             fi
55         done
56
57         [ -n "$makef" ] && makef="-f ${makef}"
58         [ -n "$makef_dir" ] && makef_dir="-C ${makef_dir}"
59
60         COMPREPLY=( $( compgen -W "$( make -qp $makef $makef_dir 2>/dev/null | \
61             awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ \
62             {split($1,A,/ /);for(i in A)print A[i]}' )" \
63             -- "$cur" ) )
64
65     fi
66 } &&
67 complete -F _make make gmake gnumake pmake
68
69 # ex: ts=4 sw=4 et filetype=sh