bbdlib.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #! /usr/bin/env python
  2. import os, sys, imp
  3. from waflib import Context, Options, Configure, Utils, Logs
  4. def start(cwd, version, wafdir):
  5. # simple example, the file main.c is hard-coded
  6. try:
  7. os.stat(cwd + os.sep + 'bbit')
  8. except:
  9. print('call from a folder containing a file named "bbit"')
  10. sys.exit(1)
  11. Logs.init_log()
  12. Context.waf_dir = wafdir
  13. Context.top_dir = Context.run_dir = cwd
  14. Context.out_dir = os.path.join(cwd, 'build')
  15. Context.g_module = imp.new_module('wscript')
  16. Context.g_module.root_path = os.path.join(cwd, 'bbit')
  17. Context.Context.recurse = \
  18. lambda x, y: getattr(Context.g_module, x.cmd or x.fun, Utils.nada)(x)
  19. Context.g_module.configure = lambda ctx: ctx.load('g++')
  20. Context.g_module.build = lambda bld: bld.objects(source='main.c')
  21. Options.OptionsContext().execute()
  22. do_config = 'configure' in sys.argv
  23. try:
  24. os.stat(cwd + os.sep + 'build')
  25. except:
  26. do_config = True
  27. if do_config:
  28. Context.create_context('configure').execute()
  29. if 'clean' in sys.argv:
  30. Context.create_context('clean').execute()
  31. if 'build' in sys.argv:
  32. Context.create_context('build').execute()