1
# bash completion for GNU make
1
# bash completion for GNU make -*- shell-script -*-
3
have make || have gmake || have gnumake || have pmake || have colormake &&
6
local file makef makef_dir="." makef_inc cur prev i split=false
9
_get_comp_words_by_ref cur prev
11
_split_longopt && split=true
5
local cur prev words cword split
6
_init_completion -s || return
8
local file makef makef_dir="." makef_inc i
14
-f|-o|-W|--file|--makefile|--old-file|--new-file|--assume-old|--assume-new|--what-if)
11
-f|--file|--makefile|-o|--old-file|--assume-old|-W|--what-if|\
12
--new-file|--assume-new)
18
-I|-C|--directory|--include-dir)
16
-I|--include-dir|-C|--directory|-m)
21
COMPREPLY=( $( compgen -v -- "$cur" ) )
28
COMPREPLY=( $( compgen -W "{1..$(( $(_ncpus)*2 ))}" -- "$cur" ) )
26
35
if [[ "$cur" == -* ]]; then
27
COMPREPLY=( $( compgen -W '-b -m -B -C -d -e -f -h -i -I\
28
-j -l -k -n -o -p -q -r -R - s -S -t -v -w -W \
29
--always-make --directory --debug \
30
--environment-overrides --file --makefile --help \
31
--ignore-errors --include-dir --jobs --load-average \
32
--max-load --keep-going --just-print --dry-run \
33
--recon --old-file --assume-old --print-data-base \
34
--question --no-builtin-rules --no-builtin-variables \
35
--silent --quiet --no-keep-goind --stop --touch \
36
--version --print-directory --no-print-directory \
37
--what-if --new-file --assume-new \
38
--warn-undefined-variables' -- "$cur" ) )
36
local opts="$( _parse_help "$1" )"
37
[[ $opts ]] || opts="$( _parse_usage "$1" )"
38
COMPREPLY=( $( compgen -W "$opts" -- "$cur" ) )
39
[[ $COMPREPLY == *= ]] && compopt -o nospace
40
elif [[ $cur == *=* ]]; then
44
[[ ${prev,,} == *dir?(ectory) ]] && diropt=-d
40
47
# before we check for makefiles, see if a path was specified
41
48
# with -C/--directory
42
for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do
43
if [[ ${COMP_WORDS[i]} == -@(C|-directory) ]]; then
49
for (( i=0; i < ${#words[@]}; i++ )); do
50
if [[ ${words[i]} == -@(C|-directory) ]]; then
44
51
# eval for tilde expansion
45
eval makef_dir=${COMP_WORDS[i+1]}
52
eval makef_dir=${words[i+1]}
50
57
# before we scan for targets, see if a Makefile name was
51
58
# specified with -f/--file/--makefile
52
for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do
53
if [[ ${COMP_WORDS[i]} == -@(f|-?(make)file) ]]; then
59
for (( i=0; i < ${#words[@]}; i++ )); do
60
if [[ ${words[i]} == -@(f|-?(make)file) ]]; then
54
61
# eval for tilde expansion
55
eval makef=${COMP_WORDS[i+1]}
62
eval makef=${words[i+1]}
60
[ -n "$makef" ] && makef="-f ${makef}"
61
[ -n "$makef_dir" ] && makef_dir="-C ${makef_dir}"
67
[[ -n $makef ]] && makef="-f ${makef}"
68
[[ -n $makef_dir ]] && makef_dir="-C ${makef_dir}"
63
70
COMPREPLY=( $( compgen -W "$( make -qp $makef $makef_dir 2>/dev/null | \
64
71
awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ \