]> git.saurik.com Git - wxWidgets.git/blob - build/bakefiles/wxwin.py
78c0162b00d8652b462d285619cfd3770d9a13a2
[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
19
20 def 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
32 # All libs that are part of the main library (i.e. non-contrib):
33 MAIN_LIBS = ['mono', 'base', 'core', 'html', 'xml']
34 # List of library names/ids for categories with different names:
35 LIBS_NOGUI = ['xml']
36 LIBS_GUI = ['core', 'html', 'gl']
37
38 def 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':
43 return '$(WXNAMEPREFIXGUI)$(WXNAMESUFFIX)$(WXVERSIONTAG)$(HOST_SUFFIX)'
44 if wxid == 'base':
45 return '$(WXNAMEPREFIX)$(WXNAMESUFFIX)$(WXVERSIONTAG)$(HOST_SUFFIX)'
46 if wxid in LIBS_NOGUI:
47 return '$(WXNAMEPREFIX)$(WXNAMESUFFIX)_%s$(WXVERSIONTAG)$(HOST_SUFFIX)' % wxid
48 return '$(WXNAMEPREFIXGUI)$(WXNAMESUFFIX)_%s$(WXVERSIONTAG)$(HOST_SUFFIX)' % wxid
49
50 def 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':
55 return '$(WXDLLNAMEPREFIXGUI)$(WXNAMESUFFIX)$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG)'
56 if wxid == 'base':
57 return '$(WXDLLNAMEPREFIX)$(WXNAMESUFFIX)$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG)'
58 if wxid in LIBS_NOGUI:
59 return '$(WXDLLNAMEPREFIX)$(WXNAMESUFFIX)_%s$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG)' % wxid
60 return '$(WXDLLNAMEPREFIXGUI)$(WXNAMESUFFIX)_%s$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG)' % wxid
61
62
63 def libToLink(wxlibname):
64 """Returns string to pass to <sys-lib> when linking against 'wxlibname'.
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)
74
75
76 wxVersion = None
77 VERSION_FILE = '../../include/wx/version.h'
78
79 def 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
103 def getVersionMajor():
104 return getVersion()[0]
105 def getVersionMinor():
106 return getVersion()[1]
107 def getVersionRelease():
108 return getVersion()[2]
109
110
111 def 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)