]> git.saurik.com Git - wxWidgets.git/blob - build/bakefiles/wxwin.py
unicode compilation fix
[wxWidgets.git] / build / bakefiles / wxwin.py
1 #
2 # Helper functions for wxWindows bakefiles
3 #
4 # $Id$
5 #
6
7
8 import utils
9
10 # We use 'CFG' option in places where bakefile doesn't like it, so we must
11 # register a substitution function for it that provides additional knowledge
12 # about the option (in this case that it does not contain dir separators and
13 # so utils.nativePaths() doesn't have to do anything with it):
14 def __noopSubst(func, name):
15 return '$(%s)' % name
16 utils.addSubstituteCallback('CFG', __noopSubst)
17 utils.addSubstituteCallback('LIBDIRNAME', __noopSubst)
18 utils.addSubstituteCallback('OBJS', __noopSubst)
19
20
21 def mk_wxid(id):
22 """Creates wxWindows library identifier from bakefile target ID that
23 follows this convention: DLLs end with 'dll', static libraries
24 end with 'lib'. If withPrefix=1, then _wxid is returned instead
25 of wxid."""
26 if id.endswith('dll') or id.endswith('lib'):
27 wxid = id[:-3]
28 else:
29 wxid = id
30 return wxid
31
32
33 # All libs that are part of the main library (i.e. non-contrib):
34 MAIN_LIBS = ['mono', 'base', 'core', 'adv', 'html', 'xml', 'net',
35 'odbc', 'dbgrid']
36 # List of library names/ids for categories with different names:
37 LIBS_NOGUI = ['xml', 'net', 'odbc']
38 LIBS_GUI = ['core', 'adv', 'html', 'gl', 'dbgrid']
39
40 def mkLibName(wxid):
41 """Returns string that can be used as library name, including name
42 suffixes, prefixes, version tags etc. This must be kept in sync
43 with variables defined in common.bkl!"""
44 if wxid == 'mono':
45 return '$(WXNAMEPREFIXGUI)$(WXNAMESUFFIX)$(WXVERSIONTAG)$(HOST_SUFFIX)'
46 if wxid == 'base':
47 return '$(WXNAMEPREFIX)$(WXNAMESUFFIX)$(WXVERSIONTAG)$(HOST_SUFFIX)'
48 if wxid in LIBS_NOGUI:
49 return '$(WXNAMEPREFIX)$(WXNAMESUFFIX)_%s$(WXVERSIONTAG)$(HOST_SUFFIX)' % wxid
50 return '$(WXNAMEPREFIXGUI)$(WXNAMESUFFIX)_%s$(WXVERSIONTAG)$(HOST_SUFFIX)' % wxid
51
52 def mkDllName(wxid):
53 """Returns string that can be used as DLL name, including name
54 suffixes, prefixes, version tags etc. This must be kept in sync
55 with variables defined in common.bkl!"""
56 if wxid == 'mono':
57 return '$(WXDLLNAMEPREFIXGUI)$(WXNAMESUFFIX)$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG)'
58 if wxid == 'base':
59 return '$(WXDLLNAMEPREFIX)$(WXNAMESUFFIX)$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG)'
60 if wxid in LIBS_NOGUI:
61 return '$(WXDLLNAMEPREFIX)$(WXNAMESUFFIX)_%s$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG)' % wxid
62 return '$(WXDLLNAMEPREFIXGUI)$(WXNAMESUFFIX)_%s$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG)' % wxid
63
64
65 def libToLink(wxlibname):
66 """Returns string to pass to <sys-lib> when linking against 'wxlibname'.
67 For one of main libraries, libToLink('foo') returns '$(WXLIB_FOO)' which
68 must be defined in common.bkl as either nothing (in monolithic build) or
69 mkLibName('foo') (otherwise).
70 For contrib libraries, it returns mkDllName(wxlibname).
71 """
72 if wxlibname in MAIN_LIBS:
73 return '$(WXLIB_%s)' % wxlibname.upper()
74 else:
75 return mkLibName(wxlibname)
76
77
78 wxVersion = None
79 VERSION_FILE = '../../include/wx/version.h'
80
81 def getVersion():
82 """Returns wxWindows version as a tuple: (major,minor,release)."""
83 global wxVersion
84 if wxVersion == None:
85 f = open(VERSION_FILE, 'rt')
86 lines = f.readlines()
87 f.close()
88 major = minor = release = None
89 for l in lines:
90 if not l.startswith('#define'): continue
91 splitted = l.strip().split()
92 if splitted[0] != '#define': continue
93 if len(splitted) < 3: continue
94 name = splitted[1]
95 value = splitted[2]
96 if value == None: continue
97 if name == 'wxMAJOR_VERSION': major = int(value)
98 if name == 'wxMINOR_VERSION': minor = int(value)
99 if name == 'wxRELEASE_NUMBER': release = int(value)
100 if major != None and minor != None and release != None:
101 break
102 wxVersion = (major, minor, release)
103 return wxVersion
104
105 def getVersionMajor():
106 return getVersion()[0]
107 def getVersionMinor():
108 return getVersion()[1]
109 def getVersionRelease():
110 return getVersion()[2]
111
112
113 def headersOnly(files):
114 """Filters 'files' so that only headers are left. Used with
115 <msvc-project-files> to add headers to VC++ projects but not files such
116 as arrimpl.cpp."""
117
118 def callback(cond, sources):
119 prf = suf = ''
120 if sources[0].isspace(): prefix=' '
121 if sources[-1].isspace(): suffix=' '
122 retval = []
123 for s in sources.split():
124 if s.endswith('.h'):
125 retval.append(s)
126 return '%s%s%s' % (prf, ' '.join(retval), suf)
127 return utils.substitute2(files, callback)
128
129
130 def makeDspDependency(lib):
131 """Returns suitable entry for <depends-on-dsp> for main libs."""
132
133 DEPS_TABLE = {
134 'core':'base',
135 'adv':'core',
136 'html':'core',
137 'xml':'base',
138 'net':'base',
139 'odbc':'base',
140 'dbgrid':'adv,odbc',
141 }
142 if lib in DEPS_TABLE:
143 deps = ':%s' % DEPS_TABLE[lib]
144 else:
145 deps = ''
146 return '%s:$(nativePaths(WXTOPDIR))build\msw\wx_%s.dsp%s' % (lib,lib,deps)