vanjoe
vanjoe

Reputation: 439

make variables that depend on a target

I have a Variable in make that is dependant on a file that must be built before the variable can be set, is there a way to get this to work?

parsable_file: dependancies
    commands to make parsable_file
targets=$(shell parse_cmd parsable_file)
$(targets): parsable_file
    command to make targets
.phony: all
all:$(targets)

If I run $ make parsable_file && make all this will work (I get an error that parse_cmd cant find parsable_file but it works), but just make all will not work. Is there a Make idiom for this?

Upvotes: 1

Views: 123

Answers (1)

Etan Reisner
Etan Reisner

Reputation: 81052

Set the variable in a file that you include in the main makefile and include a rule in the main makefile for how to build it (the one you already have should be fine).

I believe that will do what you want.

See Including Other Makefiles and How Makefiles Are Remade (which is linked from the first section) for more details on this concept.

Also, unless parseable_file has a usage independent from that parse_cmd call, it should be possible to do the creation and the parsing at the same time and just have the resulting makefile contain the correct value for $(targets) in one step.

Upvotes: 1

Related Questions