-
Notifications
You must be signed in to change notification settings - Fork 0
/
genrule.mk
71 lines (54 loc) · 1.29 KB
/
genrule.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
define lua_init
local genrule = require "genrule"
Rule = genrule.rule
local function say(...)
print(string.format("[%.6f]", os.clock()), ...)
end
local function show(...)
local N = select('#', ...)
for i=1,N do
local name = select(i, ...)
say(name, make[name])
end
end
export("say", say)
export("show", show)
endef
$(lua $(lua_init))
# demonstrate unique names & tostring
$(info $(lua `tostring(Rule {"@echo ola"}) ))
$(info $(lua `tostring(Rule {"@echo ola"}) ))
# simple rule
define simple_rule
local r = Rule {
"@echo Hello from recipe for $$@"
}
eval(tostring(r))
return r.name
endef
simple := $(lua $(simple_rule))
$(info name of simple rule: $(simple))
test.genrule: $(simple)
# multi-line recipes and target-specific variables
define genrule
local r = Rule {
CC="clang",
CXX="clang++",
{
"$$(say This is a synthesized rule)",
"$$(show CC,CXX)",
"$$(say my target is: $$@)",
}
}
eval(tostring(r))
say("Generated rule", r.name)
return r.name
endef
# generate a few rules
# note the use of simple assignment - the whole kaboodle, including
# side-effects, would be re-evaluated of recursive assign (=) was used
gens := $(lua $(genrule)) $(lua $(genrule)) $(lua $(genrule)) $(lua $(genrule))
$(info generated: $(gens))
generated: $(gens)
$(say $@: $^)
test.genrule: generated