cpplint: fixed import. The version on pypi is now up to date and works with Python3.
[waf.git] / build_system_kit / makefile_dumper / wscript
blob5e9b3f248ee6248949b3dc219a7a9f7bd3a13fa7
1 #! /usr/bin/env python
2 # encoding: utf-8
3 # Thomas Nagy, 2010 (ita)
5 """
6 Calling 'waf build' executes a normal build with Waf
7 Calling 'waf clean dump' will create a makefile corresponding to the build
8 The dependencies will be extracted too
9 """
11 VERSION='0.0.1'
12 APPNAME='cc_test'
14 top = '.'
16 def options(opt):
17 opt.load('compiler_c')
19 def configure(conf):
20 conf.load('compiler_c')
22 def build(bld):
23 bld.program(source='main.c', target='app', use='mylib', cflags=['-O2'])
24 bld.stlib(source='a.c', target='mylib')
26 # ---------------------------------------------------------------------------
28 from waflib import Build, Logs
29 class Dumper(Build.BuildContext):
30 fun = 'dump'
31 cmd = 'dump'
33 def dump(bld):
34 # call the build function as if a real build were performed
35 build(bld)
37 from waflib import Task
38 bld.commands = []
39 bld.targets = []
41 # store the command executed
42 old_exec = Task.TaskBase.exec_command
43 def exec_command(self, *k, **kw):
44 ret = old_exec(self, *k, **kw)
45 self.command_executed = k[0]
46 self.path = kw['cwd'] or self.generator.bld.cwd
47 return ret
48 Task.TaskBase.exec_command = exec_command
50 # perform a fake build, and accumulate the makefile bits
51 old_process = Task.TaskBase.process
52 def process(self):
53 old_process(self)
55 lst = []
56 for x in self.outputs:
57 lst.append(x.path_from(self.generator.bld.bldnode))
58 bld.targets.extend(lst)
59 lst.append(':')
60 for x in self.inputs + self.dep_nodes + self.generator.bld.node_deps.get(self.uid(), []):
61 lst.append(x.path_from(self.generator.bld.bldnode))
62 try:
63 if isinstance(self.command_executed, list):
64 self.command_executed = ' '.join(self.command_executed)
65 except Exception as e:
66 print(e)
67 else:
68 bld.commands.append(' '.join(lst))
69 bld.commands.append('\tcd %s && %s' % (self.path, self.command_executed))
70 Task.TaskBase.process = process
72 # write the makefile after the build is complete
73 def output_makefile(self):
74 self.commands.insert(0, "all: %s" % " ".join(self.targets))
75 node = self.bldnode.make_node('Makefile')
76 node.write("\n".join(self.commands))
77 Logs.warn('Wrote %s' % node.abspath())
78 bld.add_post_fun(output_makefile)