~ubuntu-branches/ubuntu/saucy/xmms2/saucy-proposed

« back to all changes in this revision

Viewing changes to waflib/extras/boost.py

  • Committer: Package Import Robot
  • Author(s): Benjamin Drung
  • Date: 2012-02-07 17:18:39 UTC
  • mfrom: (38.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20120207171839-89fyv03s32fwoa3h
Tags: 0.8+dfsg-2
* Unpack waf binary (following http://wiki.debian.org/UnpackWaf)
  (Closes: #654512).
* Remove transitional xmms2-plugin-wma package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
 
2
# encoding: utf-8
 
3
# WARNING! Do not edit! http://waf.googlecode.com/svn/docs/wafbook/single.html#_obtaining_the_waf_file
 
4
 
 
5
import sys
 
6
if sys.hexversion < 0x020400f0: from sets import Set as set
 
7
'''
 
8
To add the boost tool to the waf file:
 
9
$ ./waf-light --tools=compat15,boost
 
10
        or, if you have waf >= 1.6.2
 
11
$ ./waf update --files=boost
 
12
 
 
13
The wscript will look like:
 
14
 
 
15
def options(opt):
 
16
        opt.load('compiler_cxx boost')
 
17
 
 
18
def configure(conf):
 
19
        conf.load('compiler_cxx boost')
 
20
        conf.check_boost(lib='system filesystem', mt=True, static=True)
 
21
 
 
22
def build(bld):
 
23
        bld(source='main.cpp', target='app', use='BOOST')
 
24
'''
 
25
import sys
 
26
import re
 
27
from waflib import Utils,Logs
 
28
from waflib.Configure import conf
 
29
BOOST_LIBS=('/usr/lib','/usr/local/lib','/opt/local/lib','/sw/lib','/lib')
 
30
BOOST_INCLUDES=('/usr/include','/usr/local/include','/opt/local/include','/sw/include')
 
31
BOOST_VERSION_FILE='boost/version.hpp'
 
32
BOOST_VERSION_CODE='''
 
33
#include <iostream>
 
34
#include <boost/version.hpp>
 
35
int main() { std::cout << BOOST_LIB_VERSION << std::endl; }
 
36
'''
 
37
PLATFORM=Utils.unversioned_sys_platform()
 
38
detect_intel=lambda env:(PLATFORM=='win32')and'iw'or'il'
 
39
detect_clang=lambda env:(PLATFORM=='darwin')and'clang-darwin'or'clang'
 
40
detect_mingw=lambda env:(re.search('MinGW',env.CXX[0]))and'mgw'or'gcc'
 
41
BOOST_TOOLSETS={'borland':'bcb','clang':detect_clang,'como':'como','cw':'cw','darwin':'xgcc','edg':'edg','g++':detect_mingw,'gcc':detect_mingw,'icpc':detect_intel,'intel':detect_intel,'kcc':'kcc','kylix':'bck','mipspro':'mp','mingw':'mgw','msvc':'vc','qcc':'qcc','sun':'sw','sunc++':'sw','tru64cxx':'tru','vacpp':'xlc'}
 
42
def options(opt):
 
43
        opt.add_option('--boost-includes',type='string',default='',dest='boost_includes',help='''path to the boost directory where the includes are
 
44
                                   e.g. /boost_1_45_0/include''')
 
45
        opt.add_option('--boost-libs',type='string',default='',dest='boost_libs',help='''path to the directory where the boost libs are
 
46
                                   e.g. /boost_1_45_0/stage/lib''')
 
47
        opt.add_option('--boost-static',action='store_true',default=False,dest='boost_static',help='link static libraries')
 
48
        opt.add_option('--boost-mt',action='store_true',default=False,dest='boost_mt',help='select multi-threaded libraries')
 
49
        opt.add_option('--boost-abi',type='string',default='',dest='boost_abi',help='''select libraries with tags (dgsyp, d for debug),
 
50
                                   see doc Boost, Getting Started, chapter 6.1''')
 
51
        opt.add_option('--boost-toolset',type='string',default='',dest='boost_toolset',help='force a toolset e.g. msvc, vc90, \
 
52
                                                gcc, mingw, mgw45 (default: auto)')
 
53
        py_version='%d%d'%(sys.version_info[0],sys.version_info[1])
 
54
        opt.add_option('--boost-python',type='string',default=py_version,dest='boost_python',help='select the lib python with this version \
 
55
                                                (default: %s)'%py_version)
 
56
def __boost_get_version_file(self,dir):
 
57
        try:
 
58
                return self.root.find_dir(dir).find_node(BOOST_VERSION_FILE)
 
59
        except:
 
60
                return None
 
61
def boost_get_version(self,dir):
 
62
        re_but=re.compile('^#define\\s+BOOST_LIB_VERSION\\s+"(.*)"$',re.M)
 
63
        try:
 
64
                val=re_but.search(self.__boost_get_version_file(dir).read()).group(1)
 
65
        except:
 
66
                val=self.check_cxx(fragment=BOOST_VERSION_CODE,includes=[dir],execute=True,define_ret=True)
 
67
        return val
 
68
def boost_get_includes(self,*k,**kw):
 
69
        includes=k and k[0]or kw.get('includes',None)
 
70
        if includes and self.__boost_get_version_file(includes):
 
71
                return includes
 
72
        for dir in BOOST_INCLUDES:
 
73
                if self.__boost_get_version_file(dir):
 
74
                        return dir
 
75
        if includes:
 
76
                self.fatal('headers not found in %s'%includes)
 
77
        else:
 
78
                self.fatal('headers not found, use --boost-includes=/path/to/boost')
 
79
def boost_get_toolset(self,cc):
 
80
        toolset=cc
 
81
        if not cc:
 
82
                build_platform=Utils.unversioned_sys_platform()
 
83
                if build_platform in BOOST_TOOLSETS:
 
84
                        cc=build_platform
 
85
                else:
 
86
                        cc=self.env.CXX_NAME
 
87
        if cc in BOOST_TOOLSETS:
 
88
                toolset=BOOST_TOOLSETS[cc]
 
89
        return isinstance(toolset,str)and toolset or toolset(self.env)
 
90
def __boost_get_libs_path(self,*k,**kw):
 
91
        ''' return the lib path and all the files in it '''
 
92
        if'files'in kw:
 
93
                return self.root.find_dir('.'),Utils.to_list(kw['files'])
 
94
        libs=k and k[0]or kw.get('libs',None)
 
95
        if libs:
 
96
                path=self.root.find_dir(libs)
 
97
                files=path.ant_glob('*boost_*')
 
98
        if not libs or not files:
 
99
                for dir in BOOST_LIBS:
 
100
                        try:
 
101
                                path=self.root.find_dir(dir)
 
102
                                files=path.ant_glob('*boost_*')
 
103
                                if files:
 
104
                                        break
 
105
                                path=self.root.find_dir(dir+'64')
 
106
                                files=path.ant_glob('*boost_*')
 
107
                                if files:
 
108
                                        break
 
109
                        except:
 
110
                                path=None
 
111
        if not path:
 
112
                if libs:
 
113
                        self.fatal('libs not found in %s'%libs)
 
114
                else:
 
115
                        self.fatal('libs not found, \
 
116
                                           use --boost-includes=/path/to/boost/lib')
 
117
        return path,files
 
118
def boost_get_libs(self,*k,**kw):
 
119
        '''
 
120
        return the lib path and the required libs
 
121
        according to the parameters
 
122
        '''
 
123
        path,files=self.__boost_get_libs_path(**kw)
 
124
        t=[]
 
125
        if kw.get('mt',False):
 
126
                t.append('mt')
 
127
        if kw.get('abi',None):
 
128
                t.append(kw['abi'])
 
129
        tags=t and'(-%s)+'%'-'.join(t)or''
 
130
        toolset='(-%s[0-9]{0,3})+'%self.boost_get_toolset(kw.get('toolset',''))
 
131
        version='(-%s)+'%self.env.BOOST_VERSION
 
132
        def find_lib(re_lib,files):
 
133
                for file in files:
 
134
                        if re_lib.search(file.name):
 
135
                                return file
 
136
                return None
 
137
        def format_lib_name(name):
 
138
                if name.startswith('lib'):
 
139
                        name=name[3:]
 
140
                return name.split('.')[0]
 
141
        libs=[]
 
142
        for lib in Utils.to_list(k and k[0]or kw.get('lib',None)):
 
143
                py=(lib=='python')and'(-py%s)+'%kw['python']or''
 
144
                for pattern in['boost_%s%s%s%s%s'%(lib,toolset,tags,py,version),'boost_%s%s%s%s'%(lib,tags,py,version),'boost_%s%s%s'%(lib,tags,version),'boost_%s%s%s%s'%(lib,toolset,tags,py),'boost_%s%s%s'%(lib,tags,py),'boost_%s%s'%(lib,tags)]:
 
145
                        file=find_lib(re.compile(pattern),files)
 
146
                        if file:
 
147
                                libs.append(format_lib_name(file.name))
 
148
                                break
 
149
                else:
 
150
                        self.fatal('lib %s not found in %s'%(lib,path))
 
151
        return path.abspath(),libs
 
152
def check_boost(self,*k,**kw):
 
153
        if not self.env['CXX']:
 
154
                self.fatal('load a c++ compiler first, conf.load("compiler_cxx")')
 
155
        params={'lib':k and k[0]or kw.get('lib',None)}
 
156
        for key,value in self.options.__dict__.items():
 
157
                if not key.startswith('boost_'):
 
158
                        continue
 
159
                key=key[len('boost_'):]
 
160
                params[key]=value and value or kw.get(key,'')
 
161
        var=kw.get('uselib_store','BOOST')
 
162
        self.start_msg('Checking boost includes')
 
163
        self.env['INCLUDES_%s'%var]=self.boost_get_includes(**params)
 
164
        self.env.BOOST_VERSION=self.boost_get_version(self.env['INCLUDES_%s'%var])
 
165
        self.end_msg(self.env.BOOST_VERSION)
 
166
        if Logs.verbose:
 
167
                Logs.pprint('CYAN','    path : %s'%self.env['INCLUDES_%s'%var])
 
168
        if not params['lib']:
 
169
                return
 
170
        self.start_msg('Checking boost libs')
 
171
        suffix=params.get('static','ST')or''
 
172
        path,libs=self.boost_get_libs(**params)
 
173
        self.env['%sLIBPATH_%s'%(suffix,var)]=[path]
 
174
        self.env['%sLIB_%s'%(suffix,var)]=libs
 
175
        self.end_msg('ok')
 
176
        if Logs.verbose:
 
177
                Logs.pprint('CYAN','    path : %s'%path)
 
178
                Logs.pprint('CYAN','    libs : %s'%libs)
 
179
 
 
180
conf(__boost_get_version_file)
 
181
conf(boost_get_version)
 
182
conf(boost_get_includes)
 
183
conf(boost_get_toolset)
 
184
conf(__boost_get_libs_path)
 
185
conf(boost_get_libs)
 
186
conf(check_boost)
 
 
b'\\ No newline at end of file'