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