3 # Thomas Nagy, 2010 (ita)
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
17 opt
.load('compiler_c')
20 conf
.load('compiler_c')
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
):
34 # call the build function as if a real build were performed
37 from waflib
import Task
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
48 Task
.TaskBase
.exec_command
= exec_command
50 # perform a fake build, and accumulate the makefile bits
51 old_process
= Task
.TaskBase
.process
56 for x
in self
.outputs
:
57 lst
.append(x
.path_from(self
.generator
.bld
.bldnode
))
58 bld
.targets
.extend(lst
)
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
))
63 if isinstance(self
.command_executed
, list):
64 self
.command_executed
= ' '.join(self
.command_executed
)
65 except Exception as e
:
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
)