OSDN Git Service

am 53cd6a87: (-s ours) am aecd2790: am c3da3ea3: DO NOT MERGE
[android-x86/external-webkit.git] / Tools / wx / build / settings.py
1 # Copyright (C) 2009 Kevin Ollivier  All rights reserved.
2 #
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions
5 # are met:
6 # 1. Redistributions of source code must retain the above copyright
7 #    notice, this list of conditions and the following disclaimer.
8 # 2. Redistributions in binary form must reproduce the above copyright
9 #    notice, this list of conditions and the following disclaimer in the
10 #    documentation and/or other materials provided with the distribution.
11 #
12 # THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
13 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
15 # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
16 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
17 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
18 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
19 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
20 # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
23 #
24 # Common elements of the waf build system shared by all projects.
25
26 import commands
27 import os
28 import platform
29 import re
30 import sys
31
32 import Options
33
34 from build_utils import *
35 from waf_extensions import *
36
37 # to be moved to wx when it supports more configs
38 from wxpresets import *
39
40 wk_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../..'))
41
42 if sys.platform.startswith('win'):
43     if not 'WXWIN' in os.environ:
44         print "Please set WXWIN to the directory containing wxWidgets."
45         sys.exit(1)
46
47     wx_root = os.environ['WXWIN']
48 else:
49     wx_root = commands.getoutput('wx-config --prefix')
50
51 jscore_dir = os.path.join(wk_root, 'JavaScriptCore')
52 webcore_dir = os.path.join(wk_root, 'WebCore')
53 wklibs_dir = os.path.join(wk_root, 'WebKitLibraries')
54
55 common_defines = []
56 common_cxxflags = []
57 common_includes = []
58 common_libs = []
59 common_libpaths = []
60 common_frameworks = []
61
62 ports = [
63     'Brew',
64     'Chromium',
65     'Gtk', 
66     'Haiku',
67     'Mac', 
68     'None',
69     'Qt',
70     'Safari',
71     'Win', 
72     'Wince',
73     'wx',
74 ]
75
76 port_uses = {
77     'wx': ['CURL', 'WXGC'],
78 }
79
80 jscore_dirs = [
81     'API',
82     'bytecode',
83     'bytecompiler',
84     'debugger',
85     'DerivedSources',
86     'interpreter',
87     'jit',
88     'parser',
89     'pcre',
90     'profiler',
91     'runtime',
92     'wtf',
93     'wtf/text',
94     'wtf/unicode',
95     'wtf/unicode/icu',
96     'yarr',
97 ]
98
99 webcore_dirs = [
100     'WebCore/accessibility',
101     'WebCore/bindings',
102     'WebCore/bindings/cpp',
103     'WebCore/bindings/generic',
104     'WebCore/bindings/js',
105     'WebCore/bindings/js/specialization',
106     'WebCore/bridge', 
107     'WebCore/bridge/c',
108     'WebCore/bridge/jsc',
109     'WebCore/css',
110     'WebCore/DerivedSources',
111     'WebCore/dom',
112     'WebCore/dom/default',
113     'WebCore/editing',
114     'WebCore/fileapi',
115     'WebCore/history',
116     'WebCore/html',
117     'WebCore/html/canvas',
118     'WebCore/html/parser',
119     'WebCore/inspector', 
120     'WebCore/loader', 
121     'WebCore/loader/appcache',
122     'WebCore/loader/archive',
123     'WebCore/loader/cache',
124     'WebCore/loader/icon',
125     'WebCore/notifications',
126     'WebCore/page',
127     'WebCore/page/animation', 
128     'WebCore/platform', 
129     'WebCore/platform/animation', 
130     'WebCore/platform/graphics',
131     'WebCore/platform/graphics/filters',
132     'WebCore/platform/graphics/transforms',
133     'WebCore/platform/image-decoders',
134     'WebCore/platform/image-decoders/bmp', 
135     'WebCore/platform/image-decoders/gif', 
136     'WebCore/platform/image-decoders/ico', 
137     'WebCore/platform/image-decoders/jpeg', 
138     'WebCore/platform/image-decoders/png',
139     'WebCore/platform/image-decoders/webp',
140     'WebCore/platform/mock',
141     'WebCore/platform/network', 
142     'WebCore/platform/sql', 
143     'WebCore/platform/text',
144     'WebCore/platform/text/transcoder',
145     'WebCore/plugins', 
146     'WebCore/rendering', 
147     'WebCore/rendering/style',
148     'WebCore/rendering/svg',
149     'WebCore/storage',
150     'WebCore/svg',
151     'WebCore/svg/animation',
152     'WebCore/svg/graphics',
153     'WebCore/svg/graphics/filters',
154     'WebCore/svg/properties',
155     'WebCore/websockets', 
156     'WebCore/xml'
157 ]
158
159 config = get_config(wk_root)
160 config_dir = config + git_branch_name()
161
162 output_dir = os.path.join(wk_root, 'WebKitBuild', config_dir)
163
164 build_port = "wx"
165 building_on_win32 = sys.platform.startswith('win')
166
167 def get_config():
168     waf_configname = config.upper().strip()
169     if building_on_win32:
170         isReleaseCRT = (config == 'Release')
171         if build_port == 'wx':
172             if Options.options.wxpython:
173                 isReleaseCRT = True
174         
175         if isReleaseCRT:
176             waf_configname = waf_configname + ' CRT_MULTITHREADED_DLL'
177         else:
178             waf_configname = waf_configname + ' CRT_MULTITHREADED_DLL_DBG'
179
180     return waf_configname
181
182 create_hash_table = wk_root + "/JavaScriptCore/create_hash_table"
183 if building_on_win32:
184     create_hash_table = get_output('cygpath --unix "%s"' % create_hash_table)
185 os.environ['CREATE_HASH_TABLE'] = create_hash_table
186
187 feature_defines = ['ENABLE_DATABASE', 'ENABLE_XSLT', 'ENABLE_JAVASCRIPT_DEBUGGER',
188                     'ENABLE_SVG', 'ENABLE_SVG_USE', 'ENABLE_FILTERS', 'ENABLE_SVG_FONTS',
189                     'ENABLE_SVG_ANIMATION', 'ENABLE_SVG_AS_IMAGE', 'ENABLE_SVG_FOREIGN_OBJECT',
190                     'ENABLE_JIT', 'BUILDING_%s' % build_port.upper()]
191
192 msvc_version = 'msvc2008'
193
194 msvclibs_dir = os.path.join(wklibs_dir, msvc_version, 'win')
195
196 def get_path_to_wxconfig():
197     if 'WX_CONFIG' in os.environ:
198         return os.environ['WX_CONFIG']
199     else:
200         return 'wx-config'
201
202 def common_set_options(opt):
203     """
204     Initialize common options provided to the user.
205     """
206     opt.tool_options('compiler_cxx')
207     opt.tool_options('compiler_cc')
208     opt.tool_options('python')
209     
210     opt.add_option('--wxpython', action='store_true', default=False, help='Create the wxPython bindings.')
211     opt.add_option('--wx-compiler-prefix', action='store', default='vc',
212                    help='Specify a different compiler prefix (do this if you used COMPILER_PREFIX when building wx itself)')
213     opt.add_option('--macosx-version', action='store', default='', help="Version of OS X to build for.")
214     opt.add_option('--msvc-version', action='store', default='', help="MSVC version to use to build. Use 8 for 2005, 9 for 2008")
215
216 def common_configure(conf):
217     """
218     Configuration used by all targets, called from the target's configure() step.
219     """
220     
221     conf.env['MSVC_TARGETS'] = ['x86']
222     
223     if Options.options.msvc_version and Options.options.msvc_version != '':
224         print "msvc version = %s" % Options.options.msvc_version
225         conf.env['MSVC_VERSIONS'] = ['msvc %s.0' % Options.options.msvc_version]
226     else:
227         print "msvc not set!"
228         conf.env['MSVC_VERSIONS'] = ['msvc 9.0', 'msvc 8.0']
229     
230     if sys.platform.startswith('cygwin'):
231         print "ERROR: You must use the Win32 Python from python.org, not Cygwin Python, when building on Windows."
232         sys.exit(1)
233     
234     if sys.platform.startswith('darwin') and build_port == 'wx':
235         import platform
236         if platform.release().startswith('10'): # Snow Leopard
237             # wx currently only supports 32-bit compilation, so we want gcc-4.0 instead of 4.2 on Snow Leopard
238             # unless the user has explicitly set a different compiler.
239             if not "CC" in os.environ:
240                 conf.env['CC'] = 'gcc-4.0'
241             if not "CXX" in os.environ:
242                 conf.env['CXX'] = 'g++-4.0'
243     conf.check_tool('compiler_cxx')
244     conf.check_tool('compiler_cc')
245     if Options.options.wxpython:
246         conf.check_tool('python')
247         conf.check_python_headers()
248     
249     if sys.platform.startswith('darwin'):
250         conf.check_tool('osx')
251     
252     global msvc_version
253     global msvclibs_dir
254     
255     libprefix = ''
256
257     if building_on_win32:
258         libprefix = 'lib'
259
260         found = conf.get_msvc_versions()
261         found_versions = []
262         for version in found:
263             found_versions.append(version[0])
264             
265         if 'msvc 9.0' in conf.env['MSVC_VERSIONS'] and 'msvc 9.0' in found_versions:
266             msvc_version = 'msvc2008'
267         elif 'msvc 8.0' in conf.env['MSVC_VERSIONS'] and 'msvc 8.0' in found_versions:
268             msvc_version = 'msvc2005'
269         
270         msvclibs_dir = os.path.join(wklibs_dir, msvc_version, 'win')
271
272         # Disable several warnings which occur many times during the build.
273         # Some of them are harmless (4099, 4344, 4396, 4800) and working around
274         # them in WebKit code is probably just not worth it. We can simply do
275         # nothing about the others (4503). A couple are possibly valid but
276         # there are just too many of them in the code so fixing them is
277         # impossible in practice and just results in tons of distracting output
278         # (4244, 4291). Finally 4996 is actively harmful as it is given for
279         # just about any use of standard C/C++ library facilities.
280         conf.env.append_value('CXXFLAGS', [
281             '/wd4099',  # type name first seen using 'struct' now seen using 'class'
282             '/wd4244',  # conversion from 'xxx' to 'yyy', possible loss of data:
283             '/wd4291',  # no matching operator delete found (for placement new)
284             '/wd4344',  # behaviour change in template deduction
285             '/wd4396',  # inline can't be used in friend declaration
286             '/wd4503',  # decorated name length exceeded, name was truncated
287             '/wd4800',  # forcing value to bool 'true' or 'false'
288             '/wd4996',  # deprecated function
289         ])
290
291         # This one also occurs in C code, so disable it there as well.
292         conf.env.append_value('CCFLAGS', ['/wd4996'])
293
294     if build_port == "wx":
295         update_wx_deps(conf, wk_root, msvc_version)
296     
297         conf.env.append_value('CXXDEFINES', ['BUILDING_WX__=1', 'JS_NO_EXPORT'])
298
299         if building_on_win32:
300             conf.env.append_value('LIBPATH', os.path.join(msvclibs_dir, 'lib'))
301             # wx settings
302             global config
303             is_debug = (config == 'Debug')
304             wxdefines, wxincludes, wxlibs, wxlibpaths = get_wxmsw_settings(wx_root, shared=True, unicode=True, debug=is_debug, wxPython=Options.options.wxpython)
305             conf.env['CXXDEFINES_WX'] = wxdefines
306             conf.env['CPPPATH_WX'] = wxincludes
307             conf.env['LIB_WX'] = wxlibs
308             conf.env['LIBPATH_WX'] = wxlibpaths
309
310     if sys.platform.startswith('darwin'):
311         conf.env['LIB_ICU'] = ['icucore']
312     
313         conf.env.append_value('CPPPATH', wklibs_dir)
314         conf.env.append_value('LIBPATH', wklibs_dir)
315         
316         min_version = None
317         
318         mac_target = 'MACOSX_DEPLOYMENT_TARGET'
319         if Options.options.macosx_version != '':
320             min_version = Options.options.macosx_version
321         
322         # WebKit only supports 10.4+, but ppc systems often set this to earlier systems
323         if not min_version:
324             min_version = commands.getoutput('sw_vers -productVersion')[:4]
325             if min_version in ['10.1','10.2','10.3']:
326                 min_version = '10.4'
327
328         os.environ[mac_target] = conf.env[mac_target] = min_version        
329
330         sdk_version = min_version
331         if min_version == "10.4":
332             sdk_version += "u"
333             conf.env.append_value('LIB_WKINTERFACE', ['WebKitSystemInterfaceTiger'])
334         else:
335             # NOTE: There is a WebKitSystemInterfaceSnowLeopard, but when we use that
336             # on 10.6, we get a strange missing symbol error, and this library seems to
337             # work fine for wx's purposes.
338             conf.env.append_value('LIB_WKINTERFACE', ['WebKitSystemInterfaceLeopard'])
339         
340         sdkroot = '/Developer/SDKs/MacOSX%s.sdk' % sdk_version
341         sdkflags = ['-arch', 'i386', '-isysroot', sdkroot]
342         
343         conf.env.append_value('CPPFLAGS', sdkflags)
344         conf.env.append_value('LINKFLAGS', sdkflags)
345         
346         conf.env.append_value('CPPPATH_SQLITE3', [os.path.join(wklibs_dir, 'WebCoreSQLite3')])
347         conf.env.append_value('LIB_SQLITE3', ['WebCoreSQLite3'])
348     
349     conf.env.append_value('CXXDEFINES', feature_defines)
350     if config == 'Release':
351         conf.env.append_value('CPPDEFINES', 'NDEBUG')
352         
353     if building_on_win32:
354         conf.env.append_value('CPPPATH', [
355             os.path.join(jscore_dir, 'os-win32'),
356             os.path.join(msvclibs_dir, 'include'),
357             os.path.join(msvclibs_dir, 'include', 'pthreads'),
358             os.path.join(msvclibs_dir, 'lib'),
359             ])
360             
361         conf.env.append_value('LIB', ['libpng', 'libjpeg', 'pthreadVC2'])
362         # common win libs
363         conf.env.append_value('LIB', [
364             'kernel32', 'user32','gdi32','comdlg32','winspool','winmm',
365             'shell32', 'shlwapi', 'comctl32', 'ole32', 'oleaut32', 'uuid', 'advapi32', 
366             'wsock32', 'gdiplus', 'usp10','version'])
367
368         conf.env['LIB_ICU'] = ['icudt', 'icule', 'iculx', 'icuuc', 'icuin', 'icuio', 'icutu']
369         
370         #curl
371         conf.env['LIB_CURL'] = ['libcurl']
372         
373         #sqlite3
374         conf.env['CPPPATH_SQLITE3'] = [os.path.join(msvclibs_dir, 'include', 'SQLite')]
375         conf.env['LIB_SQLITE3'] = ['sqlite3']
376         
377         #libxml2
378         conf.env['LIB_XML'] = ['libxml2']
379         
380         #libxslt
381         conf.env['LIB_XSLT'] = ['libxslt']
382     else:    
383         if build_port == 'wx':
384             port_uses['wx'].append('PTHREADS')
385             conf.env.append_value('LIB', ['jpeg', 'png', 'pthread'])
386             conf.env.append_value('LIBPATH', os.path.join(wklibs_dir, 'unix', 'lib'))
387             conf.env.append_value('CPPPATH', os.path.join(wklibs_dir, 'unix', 'include'))
388             conf.env.append_value('CXXFLAGS', ['-fPIC', '-DPIC'])
389             
390             conf.check_cfg(path=get_path_to_wxconfig(), args='--cxxflags --libs', package='', uselib_store='WX', mandatory=True)
391             
392         conf.check_cfg(msg='Checking for libxslt', path='xslt-config', args='--cflags --libs', package='', uselib_store='XSLT', mandatory=True)
393         conf.check_cfg(path='xml2-config', args='--cflags --libs', package='', uselib_store='XML', mandatory=True)
394         if sys.platform.startswith('darwin') and min_version and min_version == '10.4':
395             conf.check_cfg(path=os.path.join(wklibs_dir, 'unix', 'bin', 'curl-config'), args='--cflags --libs', package='', uselib_store='CURL', mandatory=True)
396         else:
397             conf.check_cfg(path='curl-config', args='--cflags --libs', package='', uselib_store='CURL', mandatory=True)
398         
399         if not sys.platform.startswith('darwin'):
400             conf.check_cfg(package='cairo', args='--cflags --libs', uselib_store='WX', mandatory=True)
401             conf.check_cfg(package='pango', args='--cflags --libs', uselib_store='WX', mandatory=True)
402             conf.check_cfg(package='gtk+-2.0', args='--cflags --libs', uselib_store='WX', mandatory=True)
403             conf.check_cfg(package='sqlite3', args='--cflags --libs', uselib_store='SQLITE3', mandatory=True)
404             conf.check_cfg(path='icu-config', args='--cflags --ldflags', package='', uselib_store='ICU', mandatory=True)
405
406     for use in port_uses[build_port]:
407        conf.env.append_value('CXXDEFINES', ['WTF_USE_%s' % use])