silene / remake

Remake, a build system that bridges the gap between make and redo
27 stars 3 forks source link

Scope of rule-specific variable assignments #3

Closed adrieng closed 11 years ago

adrieng commented 11 years ago

It seems that in Remake, rule-specific variable assignments do not affect dependencies. For example, the following (Re)Makefile builds a different file.txt when executed with GNU Make:

MSG = "Built with remake"

all: file.txt

file.txt: MSG = "Built with make"

%.txt: %_tmp.txt
    cp $< $@

file_tmp.txt:
    echo $(MSG) > $@

Make's behavior is useful since it enables things like easy per-executable compiler flags:

binary.out: CFLAGS += -L libblah -l blah
binary.out: foo.o bar.o baz.o

...

Would it be possible for Remake to adopt this part of GNU Make's semantics?

silene commented 11 years ago

Definitely. In fact, I am surprised that it does not work. I guess that Remake is being confused by the presence of both variable assignments. Indeed, if you remove the global one, you get the expected behavior. I will have to take a closer look.

silene commented 11 years ago

Sorry, forget what I just said, I misunderstood your example.

The current behavior is expected. It is due to the principle that Remake should not allow non-deterministic builds. With Make, the content of file.txt is different depending on the order of your targets on the command line:

make file.txt file_tmp.txt >>> Built with make
make file_tmp.txt file.txt >>> Built with remake

I want to avoid this kind of behavior in Remake. That is why propagation of environment variables along dependencies is not performed.

That said, I have already been submitted patches to that effect, so I may add it, protect it by a preprocessor definition, and disable it by default.

adrieng commented 11 years ago

Thanks for your answer.

silene commented 11 years ago

Since commit fd63920, one can add the following line to Remakefile to achieve this behavior

.OPTIONS = variable-propagation