waf

FORK: waf with some random patches
git clone https://git.neptards.moe/neptards/waf.git
Log | Files | Refs | README

cbdlib.py (1726B)


      1 #! /usr/bin/env python
      2 
      3 import os, sys, imp, re
      4 from waflib import Context, Options, Configure, Utils, Logs
      5 
      6 def options(opt):
      7 	opt.load('compiler_c')
      8 
      9 def configure(conf):
     10 	conf.options = Options.options
     11 	conf.load('compiler_c')
     12 
     13 
     14 re_com = re.compile("#.*$", re.M)
     15 def build(bld):
     16 	txt = bld.path.find_node('cbit').read()
     17 	txt = re_com.sub('', txt)
     18 
     19 	tg = None
     20 	for x in txt.splitlines():
     21 		if not x:
     22 			continue
     23 		elif x.startswith(('\t', ' ')):
     24 			tg.rule = x.lstrip()
     25 		else:
     26 			line = x.split(':')
     27 			tgt = line[0].lstrip()
     28 			src = line[1].lstrip()
     29 			tg = bld()
     30 			if src:
     31 				tg.source = src
     32 			if tgt:
     33 				tg.target = tgt
     34 
     35 def recurse_rep(x, y):
     36 	f = getattr(Context.g_module, x.cmd or x.fun, Utils.nada)
     37 	return f(x)
     38 
     39 def start(cwd, version, wafdir):
     40 	# simple example, the file main.c is hard-coded
     41 	try:
     42 		os.stat(cwd + os.sep + 'cbit')
     43 	except:
     44 		print('call from a folder containing a file named "cbit"')
     45 		sys.exit(1)
     46 
     47 	Logs.init_log()
     48 	Context.waf_dir = wafdir
     49 	Context.top_dir = Context.run_dir = cwd
     50 	Context.out_dir = os.path.join(cwd, 'build')
     51 	Context.g_module = imp.new_module('wscript')
     52 	Context.g_module.root_path = os.path.join(cwd, 'cbit')
     53 	Context.Context.recurse = recurse_rep
     54 
     55 	# this is a fake module, which looks like a standard wscript file
     56 	Context.g_module.options = options
     57 	Context.g_module.configure = configure
     58 	Context.g_module.build = build
     59 
     60 	Options.OptionsContext().execute()
     61 
     62 	do_config = 'configure' in sys.argv
     63 	try:
     64 		os.stat(cwd + os.sep + 'build')
     65 	except:
     66 		do_config = True
     67 	if do_config:
     68 		Context.create_context('configure').execute()
     69 
     70 	if 'clean' in sys.argv:
     71 		Context.create_context('clean').execute()
     72 	if 'build' in sys.argv:
     73 		Context.create_context('build').execute()