]> git.saurik.com Git - wxWidgets.git/blame - build/bakefiles/wxwin.py
reference to technote
[wxWidgets.git] / build / bakefiles / wxwin.py
CommitLineData
ddf98968
VS
1#
2# Helper functions for wxWindows bakefiles
3#
4# $Id$
5#
6
7
cff5df9f
VS
8import 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):
404d4609
VS
14def __noopSubst(func, name):
15 return '$(%s)' % name
cff5df9f 16utils.addSubstituteCallback('CFG', __noopSubst)
404d4609 17utils.addSubstituteCallback('LIBDIRNAME', __noopSubst)
cff5df9f
VS
18
19
ddf98968
VS
20def mk_wxid(id):
21 """Creates wxWindows library identifier from bakefile target ID that
22 follows this convention: DLLs end with 'dll', static libraries
23 end with 'lib'. If withPrefix=1, then _wxid is returned instead
24 of wxid."""
25 if id.endswith('dll') or id.endswith('lib'):
26 wxid = id[:-3]
27 else:
28 wxid = id
29 return wxid
30
31
3560dc76 32# All libs that are part of the main library (i.e. non-contrib):
7c4728f6 33MAIN_LIBS = ['mono', 'base', 'core', 'html', 'xml', 'net']
ddf98968 34# List of library names/ids for categories with different names:
7c4728f6 35LIBS_NOGUI = ['xml', 'net']
a69544bf 36LIBS_GUI = ['core', 'html', 'gl']
ddf98968
VS
37
38def mkLibName(wxid):
39 """Returns string that can be used as library name, including name
40 suffixes, prefixes, version tags etc. This must be kept in sync
41 with variables defined in common.bkl!"""
42 if wxid == 'mono':
ea66c762 43 return '$(WXNAMEPREFIXGUI)$(WXNAMESUFFIX)$(WXVERSIONTAG)$(HOST_SUFFIX)'
e6978d5b 44 if wxid == 'base':
ea66c762 45 return '$(WXNAMEPREFIX)$(WXNAMESUFFIX)$(WXVERSIONTAG)$(HOST_SUFFIX)'
e6978d5b 46 if wxid in LIBS_NOGUI:
ea66c762
VS
47 return '$(WXNAMEPREFIX)$(WXNAMESUFFIX)_%s$(WXVERSIONTAG)$(HOST_SUFFIX)' % wxid
48 return '$(WXNAMEPREFIXGUI)$(WXNAMESUFFIX)_%s$(WXVERSIONTAG)$(HOST_SUFFIX)' % wxid
ddf98968
VS
49
50def mkDllName(wxid):
51 """Returns string that can be used as DLL name, including name
52 suffixes, prefixes, version tags etc. This must be kept in sync
53 with variables defined in common.bkl!"""
54 if wxid == 'mono':
4fc5f509 55 return '$(WXDLLNAMEPREFIXGUI)$(WXNAMESUFFIX)$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG)'
e6978d5b
VS
56 if wxid == 'base':
57 return '$(WXDLLNAMEPREFIX)$(WXNAMESUFFIX)$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG)'
58 if wxid in LIBS_NOGUI:
4fc5f509
VS
59 return '$(WXDLLNAMEPREFIX)$(WXNAMESUFFIX)_%s$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG)' % wxid
60 return '$(WXDLLNAMEPREFIXGUI)$(WXNAMESUFFIX)_%s$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG)' % wxid
ddf98968
VS
61
62
63def libToLink(wxlibname):
64 """Returns string to pass to <sys-lib> when linking against 'wxlibname'.
3560dc76
VS
65 For one of main libraries, libToLink('foo') returns '$(WXLIB_FOO)' which
66 must be defined in common.bkl as either nothing (in monolithic build) or
67 mkLibName('foo') (otherwise).
68 For contrib libraries, it returns mkDllName(wxlibname).
69 """
70 if wxlibname in MAIN_LIBS:
71 return '$(WXLIB_%s)' % wxlibname.upper()
72 else:
73 return mkLibName(wxlibname)
ddf98968
VS
74
75
76wxVersion = None
77VERSION_FILE = '../../include/wx/version.h'
78
79def getVersion():
80 """Returns wxWindows version as a tuple: (major,minor,release)."""
81 global wxVersion
82 if wxVersion == None:
83 f = open(VERSION_FILE, 'rt')
84 lines = f.readlines()
85 f.close()
86 major = minor = release = None
87 for l in lines:
88 if not l.startswith('#define'): continue
89 splitted = l.strip().split()
90 if splitted[0] != '#define': continue
91 if len(splitted) < 3: continue
92 name = splitted[1]
93 value = splitted[2]
94 if value == None: continue
95 if name == 'wxMAJOR_VERSION': major = int(value)
96 if name == 'wxMINOR_VERSION': minor = int(value)
97 if name == 'wxRELEASE_NUMBER': release = int(value)
98 if major != None and minor != None and release != None:
99 break
100 wxVersion = (major, minor, release)
101 return wxVersion
102
103def getVersionMajor():
104 return getVersion()[0]
105def getVersionMinor():
106 return getVersion()[1]
107def getVersionRelease():
108 return getVersion()[2]
390c0cfb
VS
109
110
111def headersOnly(files):
112 """Filters 'files' so that only headers are left. Used with
113 <msvc-project-files> to add headers to VC++ projects but not files such
114 as arrimpl.cpp."""
115
116 def callback(cond, sources):
117 prf = suf = ''
118 if sources[0].isspace(): prefix=' '
119 if sources[-1].isspace(): suffix=' '
120 retval = []
121 for s in sources.split():
122 if s.endswith('.h'):
123 retval.append(s)
124 return '%s%s%s' % (prf, ' '.join(retval), suf)
125 return utils.substitute2(files, callback)