wscript (5363B)
1 #! /usr/bin/env python 2 # encoding: utf-8 3 # Thomas Nagy, 2006-2012 (ita) 4 5 # the following two variables are used by the target "waf dist" 6 VERSION='0.0.1' 7 APPNAME='cc_test' 8 9 # if you want to cross-compile, use a different command line: 10 # CC=mingw-gcc AR=mingw-ar waf configure build 11 12 top = '.' 13 14 from waflib import Configure, Logs, Utils 15 #Configure.autoconfig = True # True/False/'clobber' 16 17 def options(opt): 18 opt.load('compiler_c gnu_dirs') 19 20 def configure(conf): 21 conf.load('compiler_c gnu_dirs') 22 23 # compile and link in the default mode, which is c++ if present 24 conf.check(fragment='int main() { return 0; }\n') 25 26 # just compile in c mode, and do not link 27 conf.check(fragment='int main() { return 0; }\n', features='c') 28 29 try: 30 conf.check(fragment="int main(int argc, char* argv[]) { return 0; }\n", execute=True) # 1 31 except conf.errors.WafError: 32 Logs.warn('You are probably using a cross-compiler (disabling specific configuration tests)') 33 conf.check_library(test_exec=False) 34 else: 35 conf.check(fragment="""#include<stdio.h>\nint main(){fprintf(stderr, "mu"); printf("%d", 22);return 0;}\n""", 36 msg='Checking for exec results', execute=True, define_name='HAVE_MU') 37 conf.check(fragment='int main(int argc, char* argv[]) { return argc - 2;}', 38 msg='Checking for test arguments', test_args=['--foo=bar'], execute=True) 39 conf.check_library(test_exec=True) 40 41 conf.check(lib='m', cflags='-Wall', defines=['var=foo', 'x=y'], uselib_store='M', mandatory=False) 42 conf.check_large_file(mandatory=False) 43 conf.check_inline() 44 45 endianness = conf.check_endianness() 46 conf.define_cond("BIG_ENDIAN", endianness == "big") 47 48 def test_build(ctx): 49 ctx(rule='echo hello', shell=True, always=True) 50 # Configuration tests may even be re-used: 51 #ctx.in_msg = True # suppress console outputs 52 #ctx.check_large_file(mandatory=False) 53 54 conf.multicheck( 55 # list of conf.check() arguments 56 {'header_name':'stdio.h', 'msg':'... stdio', 'uselib_store': 'STDIO'}, 57 {'header_name':'xyztabcd.h', 'msg':'... optional xyztabcd.h', 'mandatory': False}, 58 {'header_name':'stdlib.h', 'msg':'... stdlib', 'okmsg': 'aye', 'errmsg': 'nope'}, 59 {'func': test_build, 'msg':'... testing an arbitrary build function', 'okmsg':'ok'}, 60 61 # parallelism control with after_tests/before_tests 62 {'header_name':'malloc.h', 'msg':'... malloc', 'uselib_store':'MALLOC', 'id':'malloc_t', 'mandatory':False}, 63 {'header_name':'unistd.h', 'msg':'... unistd', 'uselib_store':'UNISTD', 'before_tests':['malloc_t'], 'mandatory':False}, 64 65 msg = 'Checking for headers in parallel', 66 #mandatory = False, # set to False to make all tests non-mandatory 67 #run_all_tests = False # set to False to stop at the first error 68 ) 69 70 conf.check(header_name='stdio.h', auto_add_header_name=True) 71 #conf.check(header_name='unistd.h') 72 conf.check(fragment='int main() {return 0;}\n') 73 conf.write_config_header('config.h') 74 75 # exclude system libraries, force a particular folder (see strictlib below) 76 #conf.check(features='c cprogram strictlib', lib = 'gif', libpath = ['/opt/lib']) 77 78 def build(bld): 79 bld.env.DEFINES=['WAF=1'] 80 81 bld.recurse('program stlib stlib-deps shlib') 82 #bld.install_files('/tmp/foo', 'wscript') 83 #bld.env.PREFIX='/tmp/foo' 84 bld.install_files('${PREFIX}/', 'program/a.h program/main.c', relative_trick=False) 85 bld.install_as('${PREFIX}/gnigni.txt', 'wscript') 86 bld.symlink_as('${PREFIX}/libfoo.so', 'wscript') 87 88 p = Utils.subst_vars('${PREFIX}/gnigni.txt', bld.env) 89 bld.symlink_as('${PREFIX}/share/gnigni-abs.txt', p, relative_trick=False) 90 bld.symlink_as('${PREFIX}/share/gnigni-rel.txt', p, relative_trick=True) 91 92 bld.env.FOO =['m', 'ncurses'] 93 bld.env.ST = '-L%s' 94 bld.env.A = 'aye' 95 bld.env.B = 'doh' 96 bld.env.SRCA = ['aaa'] 97 bld(rule='echo ${ST:FOO} ${ST:SRC} ${A}${B} ${ST:SRCA} ${ST:SRC[0].abspath()}', 98 always=True, source='wscript', shell=1, name='Shell') 99 if not Utils.is_win32: 100 bld(rule='echo ${ST:FOO} ${ST:SRC} ${A}${B} ${ST:SRCA} ${ST:SRC[0].abspath()}', 101 always=True, source='wscript', shell=0, 102 stdout=None, stderr=None, # disable synchronized outputs on this rule 103 cls_keyword=lambda x:'Trying again', name='NoShell') 104 105 # illustrate how to add a command 'foo' and to execute things in it 106 if bld.cmd == 'foo': 107 def bar(bld): 108 print('myprogram exit status is', 109 bld.exec_command(bld.get_tgen_by_name('myprogram').link_task.outputs[0].abspath())) 110 bld.add_post_fun(bar) 111 #bld(rule='echo ${SRC} ${tsk.generator.newsize}', newsize='256x256', source='wscript') 112 113 # command examples 114 115 from waflib.Build import BuildContext 116 class foo_class(BuildContext): 117 cmd = 'foo' 118 119 from waflib.Context import Context 120 class package_class(Context): 121 """just a test, try calling 'waf package' """ 122 cmd = 'package' 123 fun = 'package' 124 125 def package(ctx): 126 print('just a test', ctx.path.ant_glob('wscript')) 127 128 # and a task generator method example 129 130 from waflib import TaskGen 131 @TaskGen.feature('strictlib') 132 def check_lib_in_libpath(self): 133 #For use in a configuration check: raise an exception 134 #if the library file does not exist in the folders pointed by 'libpath' 135 pths = self.to_list(getattr(self, 'libpath', [])) 136 if pths: 137 for l in self.to_list(Utils.to_list(getattr(self, 'lib', []))): 138 for x in pths: 139 names = Utils.listdir(x) 140 lname = self.env.cshlib_PATTERN % l 141 if lname in names: 142 break 143 else: 144 self.bld.fatal('wrong path for the library %s' % l) 145