wxpresets.py revision 2daae5fd11344eaa88a0d92b0f6d65f8d2255c00
10bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# Copyright (C) 2009 Kevin Ollivier All rights reserved. 20bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# 30bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# Redistribution and use in source and binary forms, with or without 40bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# modification, are permitted provided that the following conditions 50bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# are met: 60bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# 1. Redistributions of source code must retain the above copyright 70bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# notice, this list of conditions and the following disclaimer. 80bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# 2. Redistributions in binary form must reproduce the above copyright 90bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# notice, this list of conditions and the following disclaimer in the 100bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# documentation and/or other materials provided with the distribution. 110bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# 120bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 130bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 140bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 150bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 160bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 170bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 180bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 190bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 200bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 210bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 220bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 230bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# 240bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# Library for functions to determine wx settings based on configuration 250bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch 260bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdochimport os 27231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockimport re 28231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 29231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockimport Options 30231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 31231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockdef parse_build_cfg(filename): 32231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block cfg_file = open(filename, 'r') 33231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block cfg = {} 34231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block for cfg_line in cfg_file.readlines(): 35231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block key = None 36231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block value = None 37231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block parts = cfg_line.split('=') 38231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block if len(parts) >= 1: 39231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block key = parts[0].strip() 40231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 41231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block if len(parts) >= 2: 42231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block value = parts[1].strip() 43231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block if value.isdigit(): 44231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block value = int(value) 45231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 46231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block if key: 47231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block cfg[key] = value 48231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 49231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block return cfg 50231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 51231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockdef get_wx_version(wx_root): 52231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block versionText = open(os.path.join(wx_root, "include", "wx", "version.h"), "r").read() 53231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 54231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block majorVersion = re.search("#define\swxMAJOR_VERSION\s+(\d+)", versionText).group(1) 55231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block minorVersion = re.search("#define\swxMINOR_VERSION\s+(\d+)", versionText).group(1) 562daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch releaseVersion = re.search("#define\swxRELEASE_NUMBER\s+(\d+)", versionText).group(1) 57231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 582daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch release = [majorVersion, minorVersion] 592daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch if int(minorVersion) % 2 == 1: 602daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch release.append(releaseVersion) 612daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch return release 620bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch 630bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdochdef get_wxmsw_settings(wx_root, shared = False, unicode = False, debug = False, wxPython=False): 640bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch if not os.path.exists(wx_root): 650bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch print "Directory %s does not exist." % wx_root 660bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch sys.exit(1) 670bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch 680bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch defines = ['__WXMSW__'] 690bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch includes = [os.path.join(wx_root, 'include')] 700bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch cxxflags = [] 710bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch libs = [] 720bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch libpaths = [] 730bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch 740bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch libdir = os.path.join(wx_root, 'lib') 750bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch ext = '' 760bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch postfix = 'vc' 770bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch 782daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch version_str_nodot = ''.join(get_wx_version(wx_root)[0:2]) 79231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 800bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch if shared: 810bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch defines.append('WXUSINGDLL') 82231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block libdir = os.path.join(libdir, Options.options.wx_compiler_prefix + '_dll') 830bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch else: 84231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block libdir = os.path.join(libdir, Options.options.wx_compiler_prefix + '_lib') 850bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch 860bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch if unicode: 870bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch defines.append('_UNICODE') 880bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch ext += 'u' 890bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch 900bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch depext = '' 912daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch if wxPython and not version_str_nodot.startswith('29'): 920bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch ext += 'h' 930bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch depext += 'h' 940bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch elif debug: 950bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch ext += 'd' 960bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch depext += 'd' 970bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch 980bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch configdir = os.path.join(libdir, 'msw' + ext) 99231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 100231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block monolithic = False 101231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block cfg_file = os.path.join(configdir, 'build.cfg') 102231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block if os.path.exists(cfg_file): 103231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block cfg = parse_build_cfg(cfg_file) 104231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block if "MONOLITHIC" in cfg: 105231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block monolithic = cfg["MONOLITHIC"] 1060bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch libpaths.append(libdir) 1070bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch includes.append(configdir) 1080bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch 1090bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch def get_wxlib_name(name): 1100bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch if name == 'base': 111231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block return 'wxbase%s%s' % (version_str_nodot, ext) 1120bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch 113231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block return "wxmsw%s%s_%s" % (version_str_nodot, ext, name) 1140bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch 1150bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch libs.extend(['wxzlib' + depext, 'wxjpeg' + depext, 'wxpng' + depext, 'wxexpat' + depext]) 116231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block if monolithic: 117231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block libs.extend(["wxmsw%s%s" % (version_str_nodot, ext)]) 118231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block else: 119231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block libs.extend([get_wxlib_name('base'), get_wxlib_name('core')]) 1200bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch 1210bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch if wxPython or debug: 1220bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch defines.append('__WXDEBUG__') 1230bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch 1240bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch return (defines, includes, libs, libpaths) 125