views:

531

answers:

2

Hello,

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, e.g.

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?

+1  A: 

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.

Quassnoi
+3  A: 
$ 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).

ephemient
With a few modifications to the sed substitution, your method works. I have therefore marked your answer as correct. Thanks :)
Karl Yngve Lervåg