1 # Copyright (C) 2009 Kevin Ollivier All rights reserved.
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions
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.
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.
24 # Common elements of the waf build system shared by all projects.
34 from build_utils import *
35 from waf_extensions import *
37 # to be moved to wx when it supports more configs
38 from wxpresets import *
40 wk_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../..'))
42 if sys.platform.startswith('win'):
43 if not 'WXWIN' in os.environ:
44 print "Please set WXWIN to the directory containing wxWidgets."
47 wx_root = os.environ['WXWIN']
49 wx_root = commands.getoutput('wx-config --prefix')
51 jscore_dir = os.path.join(wk_root, 'Source', 'JavaScriptCore')
52 webcore_dir = os.path.join(wk_root, 'Source', 'WebCore')
53 wklibs_dir = os.path.join(wk_root, 'WebKitLibraries')
60 common_frameworks = []
77 'wx': ['CURL', 'WXGC'],
100 webcore_dirs_common = [
101 'Source/WebCore/accessibility',
102 'Source/WebCore/bindings',
103 'Source/WebCore/bindings/cpp',
104 'Source/WebCore/bindings/generic',
105 'Source/WebCore/bindings/js',
106 'Source/WebCore/bridge',
107 'Source/WebCore/bridge/c',
108 'Source/WebCore/bridge/jsc',
109 'Source/WebCore/css',
110 'Source/WebCore/DerivedSources',
111 'Source/WebCore/dom',
112 'Source/WebCore/dom/default',
113 'Source/WebCore/editing',
114 'Source/WebCore/fileapi',
115 'Source/WebCore/history',
116 'Source/WebCore/html',
117 'Source/WebCore/html/canvas',
118 'Source/WebCore/html/parser',
119 'Source/WebCore/html/shadow',
120 'Source/WebCore/inspector',
121 'Source/WebCore/loader',
122 'Source/WebCore/loader/appcache',
123 'Source/WebCore/loader/archive',
124 'Source/WebCore/loader/cache',
125 'Source/WebCore/loader/icon',
126 'Source/WebCore/notifications',
127 'Source/WebCore/page',
128 'Source/WebCore/page/animation',
129 'Source/WebCore/platform',
130 'Source/WebCore/platform/animation',
131 'Source/WebCore/platform/graphics',
132 'Source/WebCore/platform/graphics/filters',
133 'Source/WebCore/platform/graphics/filters/arm',
134 'Source/WebCore/platform/graphics/transforms',
135 'Source/WebCore/platform/image-decoders',
136 'Source/WebCore/platform/image-decoders/bmp',
137 'Source/WebCore/platform/image-decoders/gif',
138 'Source/WebCore/platform/image-decoders/ico',
139 'Source/WebCore/platform/image-decoders/jpeg',
140 'Source/WebCore/platform/image-decoders/png',
141 'Source/WebCore/platform/image-decoders/webp',
142 'Source/WebCore/platform/mock',
143 'Source/WebCore/platform/network',
144 'Source/WebCore/platform/sql',
145 'Source/WebCore/platform/text',
146 'Source/WebCore/platform/text/transcoder',
147 'Source/WebCore/plugins',
148 'Source/WebCore/rendering',
149 'Source/WebCore/rendering/style',
150 'Source/WebCore/rendering/svg',
151 'Source/WebCore/storage',
152 'Source/WebCore/svg',
153 'Source/WebCore/svg/animation',
154 'Source/WebCore/svg/graphics',
155 'Source/WebCore/svg/graphics/filters',
156 'Source/WebCore/svg/properties',
157 'Source/WebCore/testing',
158 'Source/WebCore/websockets',
159 'Source/WebCore/xml',
160 'Source/WebCore/xml/parser',
163 config = get_config(wk_root)
164 arch = get_arch(wk_root)
167 output_dir = os.path.join(get_base_product_dir(wk_root), config_dir)
169 building_on_win32 = sys.platform.startswith('win')
172 if building_on_win32:
175 build_port = default_port
179 waf_configname = config.upper().strip()
180 if building_on_win32:
181 isReleaseCRT = (config == 'Release')
182 if build_port == 'wx':
183 if Options.options.wxpython:
187 waf_configname = waf_configname + ' CRT_MULTITHREADED_DLL'
189 waf_configname = waf_configname + ' CRT_MULTITHREADED_DLL_DBG'
191 return waf_configname
193 create_hash_table = wk_root + "/Source/JavaScriptCore/create_hash_table"
194 if building_on_win32:
195 create_hash_table = get_output('cygpath --unix "%s"' % create_hash_table)
196 os.environ['CREATE_HASH_TABLE'] = create_hash_table
200 msvc_version = 'msvc2008'
202 msvclibs_dir = os.path.join(wklibs_dir, msvc_version, 'win')
205 def get_path_to_wxconfig():
206 if 'WX_CONFIG' in os.environ:
207 return os.environ['WX_CONFIG']
212 def common_set_options(opt):
214 Initialize common options provided to the user.
216 opt.tool_options('compiler_cxx')
217 opt.tool_options('compiler_cc')
218 opt.tool_options('python')
220 opt.add_option('--port', action='store', default=default_port, help='Which WebKit port to build.')
221 opt.add_option('--wxpython', action='store_true', default=False, help='Create the wxPython bindings.')
222 opt.add_option('--wx-compiler-prefix', action='store', default='vc',
223 help='Specify a different compiler prefix (do this if you used COMPILER_PREFIX when building wx itself)')
224 opt.add_option('--macosx-version', action='store', default='', help="Version of OS X to build for.")
225 opt.add_option('--msvc-version', action='store', default='', help="MSVC version to use to build. Use 8 for 2005, 9 for 2008")
226 opt.add_option('--mac_universal_binary', action='store_true', default=False, help='Build Mac as universal (i386, x86_64, ppc) binary.')
227 opt.add_option('--mac_archs', action='store', default='', help='Comma separated list of architectures (i386, x86_64, ppc) to build on Mac.')
229 def common_configure(conf):
231 Configuration used by all targets, called from the target's configure() step.
234 conf.env['MSVC_TARGETS'] = ['x86']
236 build_port = Options.options.port
238 feature_defines = ['ENABLE_DATABASE', 'ENABLE_XSLT', 'ENABLE_JAVASCRIPT_DEBUGGER',
239 'ENABLE_SVG', 'ENABLE_SVG_USE', 'ENABLE_FILTERS', 'ENABLE_SVG_FONTS',
240 'ENABLE_SVG_ANIMATION', 'ENABLE_SVG_AS_IMAGE', 'ENABLE_SVG_FOREIGN_OBJECT',
241 'ENABLE_DOM_STORAGE', 'BUILDING_%s' % build_port.upper()]
243 conf.env["FEATURE_DEFINES"] = ' '.join(feature_defines)
245 if Options.options.msvc_version and Options.options.msvc_version != '':
246 conf.env['MSVC_VERSIONS'] = ['msvc %s.0' % Options.options.msvc_version]
248 conf.env['MSVC_VERSIONS'] = ['msvc 9.0', 'msvc 8.0']
250 if sys.platform.startswith('cygwin'):
251 print "ERROR: You must use the Win32 Python from python.org, not Cygwin Python, when building on Windows."
254 conf.check_tool('compiler_cxx')
255 conf.check_tool('compiler_cc')
257 if sys.platform.startswith('darwin'):
258 conf.check_tool('osx')
265 if building_on_win32:
268 found = conf.get_msvc_versions()
270 for version in found:
271 found_versions.append(version[0])
273 if 'msvc 9.0' in conf.env['MSVC_VERSIONS'] and 'msvc 9.0' in found_versions:
274 msvc_version = 'msvc2008'
275 elif 'msvc 8.0' in conf.env['MSVC_VERSIONS'] and 'msvc 8.0' in found_versions:
276 msvc_version = 'msvc2005'
278 msvclibs_dir = os.path.join(wklibs_dir, msvc_version, 'win')
280 # Disable several warnings which occur many times during the build.
281 # Some of them are harmless (4099, 4344, 4396, 4800) and working around
282 # them in WebKit code is probably just not worth it. We can simply do
283 # nothing about the others (4503). A couple are possibly valid but
284 # there are just too many of them in the code so fixing them is
285 # impossible in practice and just results in tons of distracting output
286 # (4244, 4291). Finally 4996 is actively harmful as it is given for
287 # just about any use of standard C/C++ library facilities.
288 conf.env.append_value('CXXFLAGS', [
289 '/wd4099', # type name first seen using 'struct' now seen using 'class'
290 '/wd4244', # conversion from 'xxx' to 'yyy', possible loss of data:
291 '/wd4291', # no matching operator delete found (for placement new)
292 '/wd4344', # behaviour change in template deduction
293 '/wd4396', # inline can't be used in friend declaration
294 '/wd4503', # decorated name length exceeded, name was truncated
295 '/wd4800', # forcing value to bool 'true' or 'false'
296 '/wd4996', # deprecated function
299 # This one also occurs in C code, so disable it there as well.
300 conf.env.append_value('CCFLAGS', ['/wd4996'])
302 if build_port == "wx":
303 update_wx_deps(conf, wk_root, msvc_version)
305 conf.env.append_value('CXXDEFINES', ['BUILDING_WX__=1', 'JS_NO_EXPORT'])
307 if building_on_win32:
308 conf.env.append_value('LIBPATH', os.path.join(msvclibs_dir, 'lib'))
311 is_debug = (config == 'Debug')
312 wxdefines, wxincludes, wxlibs, wxlibpaths = get_wxmsw_settings(wx_root, shared=True, unicode=True, debug=is_debug, wxPython=Options.options.wxpython)
313 conf.env['CXXDEFINES_WX'] = wxdefines
314 conf.env['CPPPATH_WX'] = wxincludes
315 conf.env['LIB_WX'] = wxlibs
316 conf.env['LIBPATH_WX'] = wxlibpaths
318 conf.check_cfg(path=get_path_to_wxconfig(), args='--cxxflags --libs', package='', uselib_store='WX', mandatory=True)
320 if sys.platform.startswith('darwin'):
321 conf.env['LIB_ICU'] = ['icucore']
323 conf.env.append_value('CPPPATH', wklibs_dir)
324 conf.env.append_value('LIBPATH', wklibs_dir)
328 mac_target = 'MACOSX_DEPLOYMENT_TARGET'
329 if Options.options.macosx_version != '':
330 min_version = Options.options.macosx_version
332 # WebKit only supports 10.4+, but ppc systems often set this to earlier systems
334 min_version = commands.getoutput('sw_vers -productVersion')[:4]
335 if min_version in ['10.1', '10.2', '10.3']:
338 sdk_version = min_version
339 if min_version == "10.4":
341 conf.env.append_value('LIB_WKINTERFACE', ['WebKitSystemInterfaceTiger'])
343 # NOTE: There is a WebKitSystemInterfaceSnowLeopard, but when we use that
344 # on 10.6, we get a strange missing symbol error, and this library seems to
345 # work fine for wx's purposes.
346 conf.env.append_value('LIB_WKINTERFACE', ['WebKitSystemInterfaceLeopard'])
348 # match WebKit Mac's default here unless we're building on platforms that won't support 64-bit.
351 if Options.options.mac_archs != '':
352 arch_list = Options.options.mac_archs.replace("'", '').replace('"', '').split(",")
353 for arch in arch_list:
354 if arch.strip() != '':
355 archs.append(arch.strip())
356 elif Options.options.mac_universal_binary:
357 archs = ['i386', 'x86_64', 'ppc']
359 is_cocoa = "__WXOSX_COCOA__" in conf.env["CXXDEFINES_WX"]
360 if min_version == "10.4" or not is_cocoa:
366 sdkroot = '/Developer/SDKs/MacOSX%s.sdk' % sdk_version
367 sdkflags = ['-isysroot', sdkroot]
369 sdkflags.extend(['-arch', arch])
371 conf.env.append_value('CPPFLAGS', sdkflags)
372 conf.env.append_value('LINKFLAGS', sdkflags)
374 conf.env.append_value('LINKFLAGS', ['-framework', 'Security'])
376 conf.env.append_value('CPPPATH_SQLITE3', [os.path.join(wklibs_dir, 'WebCoreSQLite3')])
377 conf.env.append_value('LIB_SQLITE3', ['WebCoreSQLite3'])
379 # NOTE: The order here is important, because python sets the MACOSX_DEPLOYMENT_TARGET to
380 # 10.3 even on intel. So we must first set the SDK and arch flags, then load Python's config,
381 # and finally override the value Python set for MACOSX_DEPLOYMENT_TARGET
382 if Options.options.wxpython:
383 conf.check_tool('python')
384 conf.check_python_headers()
386 if sys.platform.startswith('darwin'):
387 os.environ[mac_target] = conf.env[mac_target] = min_version
389 conf.env.append_value('CXXDEFINES', feature_defines)
390 if config == 'Release':
391 conf.env.append_value('CPPDEFINES', 'NDEBUG')
393 if building_on_win32:
394 conf.env.append_value('CPPPATH', [
395 os.path.join(jscore_dir, 'os-win32'),
396 os.path.join(msvclibs_dir, 'include'),
397 os.path.join(msvclibs_dir, 'include', 'pthreads'),
398 os.path.join(msvclibs_dir, 'lib'),
401 conf.env.append_value('LIB', ['libpng', 'libjpeg', 'pthreadVC2'])
403 conf.env.append_value('LIB', [
404 'kernel32', 'user32', 'gdi32', 'comdlg32', 'winspool', 'winmm',
405 'shell32', 'shlwapi', 'comctl32', 'ole32', 'oleaut32', 'uuid', 'advapi32',
406 'wsock32', 'gdiplus', 'usp10', 'version'])
408 conf.env['LIB_ICU'] = ['icudt', 'icule', 'iculx', 'icuuc', 'icuin', 'icuio', 'icutu']
411 conf.env['LIB_CURL'] = ['libcurl']
414 conf.env['CPPPATH_SQLITE3'] = [os.path.join(msvclibs_dir, 'include', 'SQLite')]
415 conf.env['LIB_SQLITE3'] = ['sqlite3']
418 conf.env['LIB_XML'] = ['libxml2']
421 conf.env['LIB_XSLT'] = ['libxslt']
423 if build_port == 'wx':
424 port_uses['wx'].append('PTHREADS')
425 conf.env.append_value('LIB', ['jpeg', 'png', 'pthread'])
426 conf.env.append_value('LIBPATH', os.path.join(wklibs_dir, 'unix', 'lib'))
427 conf.env.append_value('CPPPATH', os.path.join(wklibs_dir, 'unix', 'include'))
428 conf.env.append_value('CXXFLAGS', ['-fPIC', '-DPIC'])
430 conf.check_cfg(msg='Checking for libxslt', path='xslt-config', args='--cflags --libs', package='', uselib_store='XSLT', mandatory=True)
431 conf.check_cfg(path='xml2-config', args='--cflags --libs', package='', uselib_store='XML', mandatory=True)
432 if sys.platform.startswith('darwin') and min_version and min_version == '10.4':
433 conf.check_cfg(path=os.path.join(wklibs_dir, 'unix', 'bin', 'curl-config'), args='--cflags --libs', package='', uselib_store='CURL', mandatory=True)
435 conf.check_cfg(path='curl-config', args='--cflags --libs', package='', uselib_store='CURL', mandatory=True)
437 if not sys.platform.startswith('darwin'):
438 conf.check_cfg(package='cairo', args='--cflags --libs', uselib_store='WX', mandatory=True)
439 conf.check_cfg(package='pango', args='--cflags --libs', uselib_store='WX', mandatory=True)
440 conf.check_cfg(package='gtk+-2.0', args='--cflags --libs', uselib_store='WX', mandatory=True)
441 conf.check_cfg(package='sqlite3', args='--cflags --libs', uselib_store='SQLITE3', mandatory=True)
442 conf.check_cfg(path='icu-config', args='--cflags --ldflags', package='', uselib_store='ICU', mandatory=True)
444 if build_port in port_uses:
445 for use in port_uses[build_port]:
446 conf.env.append_value('CXXDEFINES', ['WTF_USE_%s' % use])