简体   繁体   中英

Bash completion for make with generic targets in a Makefile

I have a Makefile where most of my targets are created generically through a canned sequence. It seems that bash completion only suggests completions for normal targets, eg

target_name:
        #$@

and not for generic targets. Is there any way to make bash completion complete all the targets, even though they are not made explicit as the example above? To be more spesific, lets say I define a list of target names, and do something like this:

list=target1 target2
$(list):
        #$@

Is there some way to make these targets available for bash completion? Or, even more advanced, say I have two lists and I want the targets to be made of all possible combinations of the elements of the two lists. Can I also have these targets available for bash completion?

$ make -qp | grep '^[^.#].*: '
all: bin1 bin2 bin3
bin1: obj1.o obj2.o obj3.o
obj1.o: obj1.c obj1.h
...
$ make -qp | sed -n -e 's/^\([^.#[:space:]][^:[:space:]]*\): .*/\1/p'
all
bin1
obj1.o
...

The -q prevents Make from actually running anything, and the -p asks it to dump its database.

Then all you need to do is write and register a completion function ( example ).

There is no working solution, AFAIK.

This command:

make -qsp 2>/dev/null | egrep '^[^#%\.=]*:[^=]' | awk -F ': ' '{ print $2}'

will expand your makefile targets.

You may try to add it into your /etc/bash_competion , but I think it will need further debugging to cope with more complex situations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM