wscript 2.1 KB

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