initial import
[vuplus_webkit] / Tools / waf / build / wxpresets.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 # Library for functions to determine wx settings based on configuration
25
26 import os
27 import re
28 import sys
29
30 import Options
31
32
33 def parse_build_cfg(filename):
34     cfg_file = open(filename, 'r')
35     cfg = {}
36     for cfg_line in cfg_file.readlines():
37         key = None
38         value = None
39         parts = cfg_line.split('=')
40         if len(parts) >= 1:
41             key = parts[0].strip()
42
43         if len(parts) >= 2:
44             value = parts[1].strip()
45             if value.isdigit():
46                 value = int(value)
47
48         if key:
49             cfg[key] = value
50
51     return cfg
52
53
54 def get_wx_version(wx_root):
55     versionText = open(os.path.join(wx_root, "include", "wx", "version.h"), "r").read()
56
57     majorVersion = re.search("#define\swxMAJOR_VERSION\s+(\d+)", versionText).group(1)
58     minorVersion = re.search("#define\swxMINOR_VERSION\s+(\d+)", versionText).group(1)
59     releaseVersion = re.search("#define\swxRELEASE_NUMBER\s+(\d+)", versionText).group(1)
60
61     release = [majorVersion, minorVersion]
62     if int(minorVersion) % 2 == 1:
63         release.append(releaseVersion)
64     return release
65
66
67 def get_wxmsw_settings(wx_root, shared=False, unicode=False, debug=False, wxPython=False):
68     if not os.path.exists(wx_root):
69         print "Directory %s does not exist." % wx_root
70         sys.exit(1)
71
72     defines = ['__WXMSW__']
73     includes = [os.path.join(wx_root, 'include')]
74     cxxflags = []
75     libs = []
76     libpaths = []
77
78     libdir = os.path.join(wx_root, 'lib')
79     ext = ''
80     postfix = 'vc'
81
82     version_str_nodot = ''.join(get_wx_version(wx_root)[0:2])
83
84     if shared:
85         defines.append('WXUSINGDLL')
86         libdir = os.path.join(libdir, Options.options.wx_compiler_prefix + '_dll')
87     else:
88         libdir = os.path.join(libdir, Options.options.wx_compiler_prefix + '_lib')
89
90     if unicode:
91         defines.append('_UNICODE')
92         ext += 'u'
93
94     depext = ''
95     if wxPython and not version_str_nodot.startswith('29'):
96         ext += 'h'
97         depext += 'h'
98     elif debug and not version_str_nodot.startswith('29'):
99         ext += 'd'
100         depext += 'd'
101
102     configdir = os.path.join(libdir, 'msw' + ext)
103
104     monolithic = False
105     cfg_file = os.path.join(configdir, 'build.cfg')
106     if os.path.exists(cfg_file):
107         cfg = parse_build_cfg(cfg_file)
108         if "MONOLITHIC" in cfg:
109             monolithic = cfg["MONOLITHIC"]
110     libpaths.append(libdir)
111     includes.append(configdir)
112
113     def get_wxlib_name(name):
114         if name == 'base':
115             return 'wxbase%s%s' % (version_str_nodot, ext)
116
117         return "wxmsw%s%s_%s" % (version_str_nodot, ext, name)
118
119     libs.extend(['wxzlib' + depext, 'wxjpeg' + depext, 'wxpng' + depext, 'wxexpat' + depext])
120     if monolithic:
121         libs.extend(["wxmsw%s%s" % (version_str_nodot, ext)])
122     else:
123         libs.extend([get_wxlib_name('base'), get_wxlib_name('core')])
124
125     if wxPython or debug:
126         defines.append('__WXDEBUG__')
127
128     return (defines, includes, libs, libpaths)