source: waflib/Tools/c_tests.py @ 9e58e78

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 9e58e78 was 0fa325b, checked in by Paul Brossier <piem@piem.org>, 11 years ago

waf: unpack

  • Property mode set to 100644
File size: 4.2 KB
Line 
1#! /usr/bin/env python
2# encoding: utf-8
3# WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file
4
5from waflib import Task
6from waflib.Configure import conf
7from waflib.TaskGen import feature,before_method,after_method
8import sys
9LIB_CODE='''
10#ifdef _MSC_VER
11#define testEXPORT __declspec(dllexport)
12#else
13#define testEXPORT
14#endif
15testEXPORT int lib_func(void) { return 9; }
16'''
17MAIN_CODE='''
18#ifdef _MSC_VER
19#define testEXPORT __declspec(dllimport)
20#else
21#define testEXPORT
22#endif
23testEXPORT int lib_func(void);
24int main(int argc, char **argv) {
25        (void)argc; (void)argv;
26        return !(lib_func() == 9);
27}
28'''
29@feature('link_lib_test')
30@before_method('process_source')
31def link_lib_test_fun(self):
32        def write_test_file(task):
33                task.outputs[0].write(task.generator.code)
34        rpath=[]
35        if getattr(self,'add_rpath',False):
36                rpath=[self.bld.path.get_bld().abspath()]
37        mode=self.mode
38        m='%s %s'%(mode,mode)
39        ex=self.test_exec and'test_exec'or''
40        bld=self.bld
41        bld(rule=write_test_file,target='test.'+mode,code=LIB_CODE)
42        bld(rule=write_test_file,target='main.'+mode,code=MAIN_CODE)
43        bld(features='%sshlib'%m,source='test.'+mode,target='test')
44        bld(features='%sprogram %s'%(m,ex),source='main.'+mode,target='app',use='test',rpath=rpath)
45@conf
46def check_library(self,mode=None,test_exec=True):
47        if not mode:
48                mode='c'
49                if self.env.CXX:
50                        mode='cxx'
51        self.check(compile_filename=[],features='link_lib_test',msg='Checking for libraries',mode=mode,test_exec=test_exec,)
52INLINE_CODE='''
53typedef int foo_t;
54static %s foo_t static_foo () {return 0; }
55%s foo_t foo () {
56        return 0;
57}
58'''
59INLINE_VALUES=['inline','__inline__','__inline']
60@conf
61def check_inline(self,**kw):
62        self.start_msg('Checking for inline')
63        if not'define_name'in kw:
64                kw['define_name']='INLINE_MACRO'
65        if not'features'in kw:
66                if self.env.CXX:
67                        kw['features']=['cxx']
68                else:
69                        kw['features']=['c']
70        for x in INLINE_VALUES:
71                kw['fragment']=INLINE_CODE%(x,x)
72                try:
73                        self.check(**kw)
74                except self.errors.ConfigurationError:
75                        continue
76                else:
77                        self.end_msg(x)
78                        if x!='inline':
79                                self.define('inline',x,quote=False)
80                        return x
81        self.fatal('could not use inline functions')
82LARGE_FRAGMENT='''#include <unistd.h>
83int main(int argc, char **argv) {
84        (void)argc; (void)argv;
85        return !(sizeof(off_t) >= 8);
86}
87'''
88@conf
89def check_large_file(self,**kw):
90        if not'define_name'in kw:
91                kw['define_name']='HAVE_LARGEFILE'
92        if not'execute'in kw:
93                kw['execute']=True
94        if not'features'in kw:
95                if self.env.CXX:
96                        kw['features']=['cxx','cxxprogram']
97                else:
98                        kw['features']=['c','cprogram']
99        kw['fragment']=LARGE_FRAGMENT
100        kw['msg']='Checking for large file support'
101        ret=True
102        try:
103                if self.env.DEST_BINFMT!='pe':
104                        ret=self.check(**kw)
105        except self.errors.ConfigurationError:
106                pass
107        else:
108                if ret:
109                        return True
110        kw['msg']='Checking for -D_FILE_OFFSET_BITS=64'
111        kw['defines']=['_FILE_OFFSET_BITS=64']
112        try:
113                ret=self.check(**kw)
114        except self.errors.ConfigurationError:
115                pass
116        else:
117                self.define('_FILE_OFFSET_BITS',64)
118                return ret
119        self.fatal('There is no support for large files')
120ENDIAN_FRAGMENT='''
121short int ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
122short int ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
123int use_ascii (int i) {
124        return ascii_mm[i] + ascii_ii[i];
125}
126short int ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
127short int ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
128int use_ebcdic (int i) {
129        return ebcdic_mm[i] + ebcdic_ii[i];
130}
131extern int foo;
132'''
133class grep_for_endianness(Task.Task):
134        color='PINK'
135        def run(self):
136                txt=self.inputs[0].read(flags='rb').decode('iso8859-1')
137                if txt.find('LiTTleEnDian')>-1:
138                        self.generator.tmp.append('little')
139                elif txt.find('BIGenDianSyS')>-1:
140                        self.generator.tmp.append('big')
141                else:
142                        return-1
143@feature('grep_for_endianness')
144@after_method('process_source')
145def grep_for_endianness_fun(self):
146        self.create_task('grep_for_endianness',self.compiled_tasks[0].outputs[0])
147@conf
148def check_endianness(self):
149        tmp=[]
150        def check_msg(self):
151                return tmp[0]
152        self.check(fragment=ENDIAN_FRAGMENT,features='c grep_for_endianness',msg="Checking for endianness",define='ENDIANNESS',tmp=tmp,okmsg=check_msg)
153        return tmp[0]
Note: See TracBrowser for help on using the repository browser.