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 26import commands 27import os 28import platform 29import re 30import sys 31 32import Options 33 34from build_utils import * 35from waf_extensions import * 36 37# to be moved to wx when it supports more configs 38from wxpresets import * 39 40wk_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../..')) 41 42if 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'] 48else: 49 wx_root = commands.getoutput('wx-config --prefix') 50 51jscore_dir = os.path.join(wk_root, 'JavaScriptCore') 52webcore_dir = os.path.join(wk_root, 'WebCore') 53wklibs_dir = os.path.join(wk_root, 'WebKitLibraries') 54 55common_defines = [] 56common_cxxflags = [] 57common_includes = [] 58common_libs = [] 59common_libpaths = [] 60common_frameworks = [] 61 62ports = [ 63 'CF', 64 'Chromium', 65 'Gtk', 66 'Haiku', 67 'Mac', 68 'None', 69 'Qt', 70 'Safari', 71 'Win', 72 'Wince', 73 'wx', 74] 75 76port_uses = { 77 'wx': ['CURL', 'WXGC'], 78} 79 80jscore_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/unicode', 94 'wtf/unicode/icu', 95 'yarr', 96] 97 98webcore_dirs = [ 99 'accessibility', 100 'bindings', 101 'bindings/js', 102 'bridge', 103 'bridge/c', 104 'bridge/jsc', 105 'css', 106 'DerivedSources', 107 'dom', 108 'dom/default', 109 'editing', 110 'history', 111 'html', 112 'html/canvas', 113 'inspector', 114 'loader', 115 'loader/appcache', 116 'loader/archive', 117 'loader/icon', 118 'notifications', 119 'page', 120 'page/animation', 121 'platform', 122 'platform/animation', 123 'platform/graphics', 124 'platform/graphics/transforms', 125 'platform/image-decoders', 126 'platform/image-decoders/bmp', 127 'platform/image-decoders/gif', 128 'platform/image-decoders/ico', 129 'platform/image-decoders/jpeg', 130 'platform/image-decoders/png', 131 'platform/mock', 132 'platform/network', 133 'platform/sql', 134 'platform/text', 135 'plugins', 136 'rendering', 137 'rendering/style', 138 'storage', 139 'websockets', 140 'xml' 141] 142 143config = get_config(wk_root) 144config_dir = config + git_branch_name() 145 146output_dir = os.path.join(wk_root, 'WebKitBuild', config_dir) 147 148build_port = "wx" 149building_on_win32 = sys.platform.startswith('win') 150 151def get_config(): 152 waf_configname = config.upper().strip() 153 if building_on_win32: 154 isReleaseCRT = (config == 'Release') 155 if build_port == 'wx': 156 if Options.options.wxpython: 157 isReleaseCRT = True 158 159 if isReleaseCRT: 160 waf_configname = waf_configname + ' CRT_MULTITHREADED_DLL' 161 else: 162 waf_configname = waf_configname + ' CRT_MULTITHREADED_DLL_DBG' 163 164 return waf_configname 165 166create_hash_table = wk_root + "/JavaScriptCore/create_hash_table" 167if building_on_win32: 168 create_hash_table = get_output('cygpath --unix "%s"' % create_hash_table) 169os.environ['CREATE_HASH_TABLE'] = create_hash_table 170 171feature_defines = ['ENABLE_DATABASE', 'ENABLE_XSLT', 'ENABLE_JAVASCRIPT_DEBUGGER'] 172 173msvc_version = 'msvc2008' 174 175msvclibs_dir = os.path.join(wklibs_dir, msvc_version, 'win') 176 177def get_path_to_wxconfig(): 178 if 'WX_CONFIG' in os.environ: 179 return os.environ['WX_CONFIG'] 180 else: 181 return 'wx-config' 182 183def common_set_options(opt): 184 """ 185 Initialize common options provided to the user. 186 """ 187 opt.tool_options('compiler_cxx') 188 opt.tool_options('compiler_cc') 189 opt.tool_options('python') 190 191 opt.add_option('--wxpython', action='store_true', default=False, help='Create the wxPython bindings.') 192 opt.add_option('--wx-compiler-prefix', action='store', default='vc', 193 help='Specify a different compiler prefix (do this if you used COMPILER_PREFIX when building wx itself)') 194 opt.add_option('--macosx-version', action='store', default='', help="Version of OS X to build for.") 195 196def common_configure(conf): 197 """ 198 Configuration used by all targets, called from the target's configure() step. 199 """ 200 201 conf.env['MSVC_VERSIONS'] = ['msvc 9.0', 'msvc 8.0'] 202 conf.env['MSVC_TARGETS'] = ['x86'] 203 204 if sys.platform.startswith('cygwin'): 205 print "ERROR: You must use the Win32 Python from python.org, not Cygwin Python, when building on Windows." 206 sys.exit(1) 207 208 if sys.platform.startswith('darwin') and build_port == 'wx': 209 import platform 210 if platform.release().startswith('10'): # Snow Leopard 211 # wx currently only supports 32-bit compilation, so we want gcc-4.0 instead of 4.2 on Snow Leopard 212 # unless the user has explicitly set a different compiler. 213 if not "CC" in os.environ: 214 conf.env['CC'] = 'gcc-4.0' 215 if not "CXX" in os.environ: 216 conf.env['CXX'] = 'g++-4.0' 217 conf.check_tool('compiler_cxx') 218 conf.check_tool('compiler_cc') 219 if Options.options.wxpython: 220 conf.check_tool('python') 221 conf.check_python_headers() 222 223 if sys.platform.startswith('darwin'): 224 conf.check_tool('osx') 225 226 global msvc_version 227 global msvclibs_dir 228 229 if building_on_win32: 230 found_versions = conf.get_msvc_versions() 231 if found_versions[0][0] == 'msvc 9.0': 232 msvc_version = 'msvc2008' 233 elif found_versions[0][0] == 'msvc 8.0': 234 msvc_version = 'msvc2005' 235 236 msvclibs_dir = os.path.join(wklibs_dir, msvc_version, 'win') 237 238 # Disable several warnings which occur many times during the build. 239 # Some of them are harmless (4099, 4344, 4396, 4800) and working around 240 # them in WebKit code is probably just not worth it. We can simply do 241 # nothing about the others (4503). A couple are possibly valid but 242 # there are just too many of them in the code so fixing them is 243 # impossible in practice and just results in tons of distracting output 244 # (4244, 4291). Finally 4996 is actively harmful as it is given for 245 # just about any use of standard C/C++ library facilities. 246 conf.env.append_value('CXXFLAGS', [ 247 '/wd4099', # type name first seen using 'struct' now seen using 'class' 248 '/wd4244', # conversion from 'xxx' to 'yyy', possible loss of data: 249 '/wd4291', # no matching operator delete found (for placement new) 250 '/wd4344', # behaviour change in template deduction 251 '/wd4396', # inline can't be used in friend declaration 252 '/wd4503', # decorated name length exceeded, name was truncated 253 '/wd4800', # forcing value to bool 'true' or 'false' 254 '/wd4996', # deprecated function 255 ]) 256 257 # This one also occurs in C code, so disable it there as well. 258 conf.env.append_value('CCFLAGS', ['/wd4996']) 259 260 if build_port == "wx": 261 update_wx_deps(conf, wk_root, msvc_version) 262 263 conf.env.append_value('CXXDEFINES', ['BUILDING_WX__=1', 'JS_NO_EXPORT']) 264 265 if building_on_win32: 266 conf.env.append_value('LIBPATH', os.path.join(msvclibs_dir, 'lib')) 267 # wx settings 268 global config 269 is_debug = (config == 'Debug') 270 wxdefines, wxincludes, wxlibs, wxlibpaths = get_wxmsw_settings(wx_root, shared=True, unicode=True, debug=is_debug, wxPython=Options.options.wxpython) 271 conf.env['CXXDEFINES_WX'] = wxdefines 272 conf.env['CPPPATH_WX'] = wxincludes 273 conf.env['LIB_WX'] = wxlibs 274 conf.env['LIBPATH_WX'] = wxlibpaths 275 276 if sys.platform.startswith('darwin'): 277 conf.env['LIB_ICU'] = ['icucore'] 278 # Apple does not ship the ICU headers with Mac OS X, so WebKit includes a copy of 3.2 headers 279 conf.env.append_value('CPPPATH_JSCORE', os.path.join(jscore_dir, 'icu')) 280 281 conf.env.append_value('CPPPATH_WEBCORE', os.path.join(webcore_dir, 'icu')) 282 283 conf.env.append_value('CPPPATH', wklibs_dir) 284 conf.env.append_value('LIBPATH', wklibs_dir) 285 286 min_version = None 287 288 mac_target = 'MACOSX_DEPLOYMENT_TARGET' 289 if Options.options.macosx_version != '': 290 min_version = Options.options.macosx_version 291 292 # WebKit only supports 10.4+, but ppc systems often set this to earlier systems 293 if not min_version: 294 min_version = commands.getoutput('sw_vers -productVersion')[:4] 295 if min_version in ['10.1','10.2','10.3']: 296 min_version = '10.4' 297 298 os.environ[mac_target] = conf.env[mac_target] = min_version 299 300 sdk_version = min_version 301 if min_version == "10.4": 302 sdk_version += "u" 303 conf.env.append_value('LIB', ['WebKitSystemInterfaceTiger']) 304 305 sdkroot = '/Developer/SDKs/MacOSX%s.sdk' % sdk_version 306 sdkflags = ['-arch', 'i386', '-isysroot', sdkroot] 307 308 conf.env.append_value('CPPFLAGS', sdkflags) 309 conf.env.append_value('LINKFLAGS', sdkflags) 310 311 conf.env.append_value('CPPPATH_SQLITE3', [os.path.join(wklibs_dir, 'WebCoreSQLite3')]) 312 conf.env.append_value('LIB_SQLITE3', ['WebCoreSQLite3']) 313 314 libprefix = '' 315 if building_on_win32: 316 libprefix = 'lib' 317 318 conf.env['LIB_JSCORE'] = [libprefix + 'jscore'] 319 conf.env['LIB_WEBCORE'] = [libprefix + 'webcore'] 320 conf.env['LIB_WXWEBKIT'] = ['wxwebkit'] 321 conf.env['CXXDEFINES_WXWEBKIT'] = ['WXUSINGDLL_WEBKIT'] 322 323 conf.env.append_value('CXXDEFINES', feature_defines) 324 if config == 'Release': 325 conf.env.append_value('CPPDEFINES', 'NDEBUG') 326 327 if building_on_win32: 328 conf.env.append_value('CPPPATH', [ 329 os.path.join(jscore_dir, 'os-win32'), 330 os.path.join(msvclibs_dir, 'include'), 331 os.path.join(msvclibs_dir, 'include', 'pthreads'), 332 os.path.join(msvclibs_dir, 'lib'), 333 ]) 334 335 conf.env.append_value('LIB', ['libpng', 'libjpeg', 'pthreadVC2']) 336 # common win libs 337 conf.env.append_value('LIB', [ 338 'kernel32', 'user32','gdi32','comdlg32','winspool','winmm', 339 'shell32', 'shlwapi', 'comctl32', 'ole32', 'oleaut32', 'uuid', 'advapi32', 340 'wsock32', 'gdiplus', 'usp10','version']) 341 342 conf.env['LIB_ICU'] = ['icudt', 'icule', 'iculx', 'icuuc', 'icuin', 'icuio', 'icutu'] 343 344 #curl 345 conf.env['LIB_CURL'] = ['libcurl'] 346 347 #sqlite3 348 conf.env['CPPPATH_SQLITE3'] = [os.path.join(msvclibs_dir, 'include', 'SQLite')] 349 conf.env['LIB_SQLITE3'] = ['sqlite3'] 350 351 #libxml2 352 conf.env['LIB_XML'] = ['libxml2'] 353 354 #libxslt 355 conf.env['LIB_XSLT'] = ['libxslt'] 356 else: 357 if build_port == 'wx': 358 port_uses['wx'].append('PTHREADS') 359 conf.env.append_value('LIB', ['jpeg', 'png', 'pthread']) 360 conf.env.append_value('LIBPATH', os.path.join(wklibs_dir, 'unix', 'lib')) 361 conf.env.append_value('CPPPATH', os.path.join(wklibs_dir, 'unix', 'include')) 362 conf.env.append_value('CXXFLAGS', ['-fPIC', '-DPIC']) 363 364 conf.check_cfg(path=get_path_to_wxconfig(), args='--cxxflags --libs', package='', uselib_store='WX', mandatory=True) 365 366 conf.check_cfg(msg='Checking for libxslt', path='xslt-config', args='--cflags --libs', package='', uselib_store='XSLT', mandatory=True) 367 conf.check_cfg(path='xml2-config', args='--cflags --libs', package='', uselib_store='XML', mandatory=True) 368 if sys.platform.startswith('darwin') and min_version and min_version == '10.4': 369 conf.check_cfg(path=os.path.join(wklibs_dir, 'unix', 'bin', 'curl-config'), args='--cflags --libs', package='', uselib_store='CURL', mandatory=True) 370 else: 371 conf.check_cfg(path='curl-config', args='--cflags --libs', package='', uselib_store='CURL', mandatory=True) 372 373 if not sys.platform.startswith('darwin'): 374 conf.check_cfg(package='cairo', args='--cflags --libs', uselib_store='WX', mandatory=True) 375 conf.check_cfg(package='pango', args='--cflags --libs', uselib_store='WX', mandatory=True) 376 conf.check_cfg(package='gtk+-2.0', args='--cflags --libs', uselib_store='WX', mandatory=True) 377 conf.check_cfg(package='sqlite3', args='--cflags --libs', uselib_store='SQLITE3', mandatory=True) 378 conf.check_cfg(path='icu-config', args='--cflags --ldflags', package='', uselib_store='ICU', mandatory=True) 379 380 for use in port_uses[build_port]: 381 conf.env.append_value('CXXDEFINES', ['WTF_USE_%s' % use]) 382