views:

83

answers:

2

I have a bunch of directories. I want to build an object for each directory. Suppose OBJS contains "build/dir1 build/dir2 build/dir3", and the pattern I'm matching is

build/%: %
    <do something here>

I'd like to add, for each object, dependencies for every file within that directory (recursively). I thought of doing something like

build/%: $(shell find %)
    <do something here>

But it seems like the second '%' is not expanded. How can I get this working?

(Weird thing that I noticed is that the '%' in '$(shell echo %)' is expanded.)

Thanks.

+2  A: 

I don't think you can invoke a process to compute the dependencies. The only way to run a process to create dependencies is by having a variable receive the output of a process and use that variable, but that won't solve your problem.

The common solution is to generate dependency files, and include them:

include build/*.depend

build/%: build/%.depend %
    ...

build/%.depend:
     command to generate explicit dependencies for build/% into build/%.depend
     possibly recursive make invocations

The first time you build, no dependency file will be generated, but the build outputs won't be there, either, so the build action will run, anyway. On subsequent make invocations, the include files are there, and considered by make.

Martin v. Löwis
A: 
You could try:
DIR := %
$(shell find $(DIR))
Aviral Dasgupta