wscript (1952B)
1 #! /usr/bin/env python 2 # encoding: utf-8 3 4 top = '.' 5 out = 'bin' 6 7 import os, re 8 from waflib import Utils 9 10 def configure(conf): 11 pass 12 13 def build(bld): 14 15 # the test.pc.in is a special case which is always handled 16 bld(source='test.pc.in', VERSION='1.1', LIBS='moo', XPM_LIBS='-lxpm', LIBICONV='-liconv', XPM_CFLAGS='-O3', INTVAR=12) 17 18 tg = bld( 19 features = 'subst', # the feature 'subst' overrides the source/target processing 20 source = 'foo.in', # list of string or nodes 21 target = 'foo.txt', # list of strings or nodes 22 encoding = 'ascii', # file encoding for python3, default is latin-1 23 install_path = '/tmp/uff/', # installation path, optional 24 chmod = Utils.O755, # installation mode, optional 25 PREFIX = bld.env.PREFIX, # variables to use in the substitution 26 re_m4 = re.compile('%%(\w+)%%', re.M), # custom substitution 27 BINDIR = bld.env.BINDIR) 28 29 # if you are using an external dict, here is to merge the key/values: 30 dct = {'BINDIR': '/opt'} 31 tg.__dict__.update(dct) 32 33 # if you want a file copy, pass "is_copy=True" 34 bld(features='subst', source='wscript', target='wscript', is_copy=True) 35 36 # same thing with a simple function 37 def fun(task, text): 38 return text 39 bld(features='subst', subst_fun=fun, source='wscript', target='wscript2') 40 41 def hlink(task): 42 try: 43 link = os.link 44 except AttributeError: 45 task.outputs[0].write(task.inputs[0].read('rb'), 'wb') 46 else: 47 for x, y in zip(task.inputs, task.outputs): 48 try: 49 os.remove(y.abspath()) 50 except OSError: 51 pass 52 os.link(x.abspath(), y.abspath()) 53 bld(features='subst', fun=hlink, source='wscript', target='wscript3') 54 55 # this one is just a reminder that simple files can be created (and a test too) 56 bld(rule='echo "การไฟ่" > ${TGT}', target='uni.txt') 57 58 # and this is an alternate syntax 59 #@bld.rule(source='wscript', target='wscript2') 60 #def _(tsk): 61 # tsk.outputs[0].write(tsk.inputs[0].read()) 62