views:

66

answers:

2

Makefiles are really really useful. But, the syntax is somewhat complex and limited. For a project, I need to create targets 1 to n, and would really like to write something like this:

all : target1 ... target100

target%d : target%d.pre
    ./script.py %d

I would like to have make capture the variable (%d) and then use it throughout the rule. I could imagine that is is possible to do this with a complex use of patterns (%.xyz) and patsubsts, but this would be very clumsy and unreadable.

I'm thinking of using a template engine like Cheetah to write a template (which can contain loops) that would then be converted into a Makefile. Does anyone have a better idea, or experience with this?

A: 

You should definitely take a look at CMake, which can do all the makefile generation for you.

anon
A: 

As beta pointed out in a comment, the second part is actually solved by

target% : target%d.pre
    ./script.py %d

Given that, the first part can be solved by:

files := $(shell for i in `seq 1 100`; do echo target$$i; done)

all : $(files)
biocs