google / kati

An experimental GNU make clone

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ninja file generated by Kati depends on irrelevant variables

asmundak opened this issue · comments

Kati converts the following makefile (when invoked with with --gen_all_targets option):

first: foo
foo:
	@echo foo

second: bar
bar:
	@echo bar

into

build first: phony foo
rule rule0
 description = build $out
 command = /bin/sh -c "echo foo"
build foo: rule0
build second: phony bar
rule rule1
 description = build $out
 command = /bin/sh -c "echo bar"
build bar: rule1

default first

However, adding a variable assignment second:= in front:

second := 
first: foo
foo:
	@echo foo

second: bar
bar:
	@echo bar

results in the output with the build statement for the top-level target second before the build statement for the first:

build second: phony bar
rule rule0
 description = build $out
 command = /bin/sh -c "echo bar"
build bar: rule0
build first: phony foo
rule rule1
 description = build $out
 command = /bin/sh -c "echo foo"
build foo: rule1

default first

The reason is that Kati generates build statements by iterating over the list of the top-level targets in the order their identifiers were added to the symbol table. As the symbol table contains the variable names, too, second makes it into the symbol table before first for the latter makefile