1 from os.path import isdir, exists
2 from lbuild.build import BuildEnvironment
3 from lbuild.scope import ScopeAccessor
5 def gen_source_file(subscope : ScopeAccessor):
6 items = " ".join(subscope.values())
7 return [f"BUILD_SRCS := {items}"]
9 def gen_header_file(subscope : ScopeAccessor):
11 for x in subscope.values():
13 print(f"warning: '{x}' does not exists, skipped")
22 f"BUILD_INC := {' '.join(inc)}",
23 f"BUILD_HDR := {' '.join(hdr)}",
26 def gen_ccflags(subscope : ScopeAccessor):
27 items = " ".join(subscope.values())
28 return [f"BUILD_CFLAGS := {items}"]
30 def gen_ldflags(subscope : ScopeAccessor):
31 items = " ".join(subscope.values())
32 return [f"BUILD_LDFLAGS := {items}"]
35 class BuildScriptGenerator:
36 def __init__(self, env: BuildEnvironment):
50 def __gen_lines(self, scope, subscope):
52 policy = self.__gen_policy.get(scope.name)
54 print( "warning: no associated policy with"
59 policy = policy.get(subscope.name)
61 print( "warning: no associated policy with "
62 f"'{scope.name}.{subscope.name}' "
66 return policy(subscope)
68 def generate(self, file):
71 for scope in self.__env.scopes.values():
72 for subscope in scope.accessors():
73 lines += self.__gen_lines(scope, subscope)
75 with open(file, 'w') as f:
76 f.write('\n'.join(lines))