wscript (4746B)
1 #! /usr/bin/env python 2 # encoding: utf-8 3 4 from waflib.Logs import pprint 5 6 top = '.' 7 out = 'build' 8 9 def options(opt): 10 opt.load('compiler_c') 11 12 def configure(conf): 13 conf.load('compiler_c') 14 15 conf.failure = 0 16 def disp(color, result): 17 pprint(color, result) 18 if color == 'RED': 19 conf.failure=1 20 21 def test(*funs): 22 conf.env.stash() 23 conf.in_msg = 1 # suppress outputs 24 for f in funs: 25 ret = f() 26 if not ret: 27 color = "GREEN" 28 else: 29 color = "RED" 30 if ret: 31 ret = '\t\t' + ret 32 else: 33 ret = '' 34 disp(color, "%s%s" % (f.__doc__, ret)) 35 conf.env.revert() 36 conf.in_msg = 0 37 return None 38 39 @test 40 def fun1(): 41 "global_define=1 by default -> no DEFINES_X anywhere" 42 conf.check_cfg(package='libpng') 43 conf.check_cc(header_name='unistd.h') 44 for x in conf.env: 45 if x.startswith('DEFINES_') and x != 'DEFINES_ST': 46 return 'conf.env.%s = %r' % (x, conf.env[x]) 47 48 @test 49 def fun2(): 50 "global_define=1 -> no DEFINES_X anywhere" 51 conf.check_cfg(package='libpng', global_define=1) 52 conf.check_cc(header_name='unistd.h', global_define=1) 53 for x in conf.env: 54 if x.startswith('DEFINES_') and x != 'DEFINES_ST': 55 return 'conf.env.%s = %r' % (x, conf.env[x]) 56 57 @test 58 def fun3(): 59 "global_define=0 -> DEFINES=[]" 60 conf.check_cfg(package='libpng', global_define=0) 61 conf.check_cc(header_name='unistd.h', global_define=0) 62 if conf.env.DEFINES: 63 return 'conf.env.DEFINES = %r' % conf.env.DEFINES 64 65 @test 66 def fun4(): 67 "global_define=0 -> DEFINES_LIBPNG=['HAVE_LIBPNG=1']" 68 conf.check_cfg(package='libpng', global_define=0) 69 val = conf.env.DEFINES_LIBPNG 70 if not isinstance(val, list) or not "HAVE_LIBPNG=1" in val: 71 return 'conf.env.DEFINES_LIBPNG = %r' % val 72 73 @test 74 def fun5(): 75 "global_defines=0, uselib_store=UNISTD -> DEFINES_UNISTD=['HAVE_UNISTD_H=1']" 76 conf.check_cc(header_name='unistd.h', uselib_store='UNISTD', global_define=0) 77 val = conf.env.DEFINES_UNISTD 78 if not isinstance(val, list) or not 'HAVE_UNISTD_H=1' in val: 79 return 'conf.env.DEFINES_UNISTD = %r' % val 80 81 @test 82 def fun6(): 83 "global_defines=0, uselib_store=UNISTD, define_name=FOO -> DEFINES_UNISTD=['FOO=1']" 84 conf.check_cc(header_name='unistd.h', uselib_store='UNISTD', global_define=0, define_name='FOO') 85 val = conf.env.DEFINES_UNISTD 86 if not isinstance(val, list) or not 'FOO=1' in val: 87 return 'conf.env.DEFINES_UNISTD = %r' % val 88 89 @test 90 def fun7(): 91 "uselib_store=UNISTD -> HAVE_UNISTD=1" 92 conf.check_cc(header_name='unistd.h', uselib_store='UNISTD') 93 val = conf.env.HAVE_UNISTD 94 if val != 1: 95 return 'conf.env.HAVE_UNISTD = %r' % val 96 97 @test 98 def fun8(): 99 "global_defines=0, define_name=HAVE_FOO -> DEFINES_LIBPNG=['HAVE_FOO=1']" 100 conf.check_cfg(package='libpng', global_define=0, define_name='HAVE_FOO') 101 val = conf.env.DEFINES_LIBPNG 102 if not isinstance(val, list) or not "HAVE_FOO=1" in val: 103 return 'conf.env.DEFINES_LIBPNG = %r' % val 104 105 @test 106 def modversion1(): 107 "modversion=libpng -> DEFINES=['LIBPNG_VERSION=X']" 108 conf.check_cfg(modversion='libpng') 109 val = conf.env.DEFINES 110 # automatic uppercase 111 if not isinstance(val, list) or not val[0].startswith("LIBPNG_VERSION="): 112 return 'conf.env.DEFINES = %r' % val 113 114 @test 115 def modversion2(): 116 "modversion=libpng, uselib_store=foo -> DEFINES=['FOO_VERSION=X']" 117 conf.check_cfg(modversion='libpng', uselib_store='foo') 118 val = conf.env.DEFINES 119 # automatic uppercase 120 if not isinstance(val, list) or not val[0].startswith("FOO_VERSION="): 121 return 'conf.env.DEFINES = %r' % val 122 123 @test 124 def modversion3(): 125 "modversion=libpng, uselib_store=foo, define_name=bar -> DEFINES=['bar=X']" 126 conf.check_cfg(modversion='libpng', uselib_store='foo', define_name='bar') 127 val = conf.env.DEFINES 128 if not isinstance(val, list) or not val[0].startswith("bar="): 129 return 'conf.env.DEFINES = %r' % val 130 131 @test 132 def atleast_version1(): 133 "atleast_version=1.0, global_define=1 -> DEFINES=['HAVE_LIBPNG=1']" 134 # same in waf 1.8 and 1.9 135 conf.check_cfg(package='libpng', atleast_version='1.0', global_define=1, args='--libs --cflags') 136 val = conf.env.DEFINES 137 if not isinstance(val, list) or not 'HAVE_LIBPNG=1' in val: 138 return 'conf.env.DEFINES = %r' % val 139 if not conf.env.LIB_LIBPNG: 140 return 'expected conf.env.LIB_LIBPNG to be defined :-/' 141 142 @test 143 def atleast_version2(): 144 "atleast_version=1.0, uselib_store=foo -> DEFINES=['HAVE_FOO=1']" 145 conf.check_cfg(package='libpng', uselib_store='foo', atleast_version='1.0', args='--libs --cflags') 146 val = conf.env.DEFINES 147 if not isinstance(val, list) or not 'HAVE_FOO=1' in val: 148 return 'conf.env.DEFINES = %r' % val 149 if not conf.env.LIB_foo: 150 return 'expected conf.env.LIB_foo to be defined :-/' 151 152 153 if conf.failure: 154 conf.fatal('One or several test failed, check the outputs above') 155