]>
Commit | Line | Data |
---|---|---|
ddf98968 | 1 | # |
77ffb593 | 2 | # Helper functions for wxWidgets bakefiles |
ddf98968 VS |
3 | # |
4 | # $Id$ | |
5 | # | |
6 | ||
7 | ||
cff5df9f VS |
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): | |
b778f9d6 VS |
14 | |
15 | try: | |
16 | # this fails in 0.1.4 and 0.1.5 has different subst.callbacks signature: | |
17 | utils.checkBakefileVersion('0.1.5') | |
18 | def __noopSubst(name, func, caller): | |
19 | return '$(%s)' % name | |
20 | except AttributeError: | |
21 | def __noopSubst(func, name): | |
22 | return '$(%s)' % name | |
cff5df9f | 23 | utils.addSubstituteCallback('CFG', __noopSubst) |
404d4609 | 24 | utils.addSubstituteCallback('LIBDIRNAME', __noopSubst) |
ee929bcf | 25 | utils.addSubstituteCallback('SETUPHDIR', __noopSubst) |
8004cb2b | 26 | utils.addSubstituteCallback('OBJS', __noopSubst) |
cff5df9f VS |
27 | |
28 | ||
ddf98968 | 29 | def mk_wxid(id): |
77ffb593 | 30 | """Creates wxWidgets library identifier from bakefile target ID that |
ddf98968 VS |
31 | follows this convention: DLLs end with 'dll', static libraries |
32 | end with 'lib'. If withPrefix=1, then _wxid is returned instead | |
33 | of wxid.""" | |
34 | if id.endswith('dll') or id.endswith('lib'): | |
35 | wxid = id[:-3] | |
36 | else: | |
37 | wxid = id | |
38 | return wxid | |
39 | ||
40 | ||
3560dc76 | 41 | # All libs that are part of the main library (i.e. non-contrib): |
83b9886f | 42 | MAIN_LIBS = ['mono', 'base', 'core', 'adv', 'html', 'xml', 'net', |
61639efb | 43 | 'media', 'odbc', 'qa', 'dbgrid', 'xrc'] |
ddf98968 | 44 | # List of library names/ids for categories with different names: |
83b9886f | 45 | LIBS_NOGUI = ['xml', 'net', 'odbc'] |
61639efb | 46 | LIBS_GUI = ['core', 'adv', 'html', 'gl', 'qa', 'dbgrid', 'xrc', 'media'] |
22cef566 VS |
47 | # Additional libraries that must be linked in: |
48 | EXTRALIBS = { | |
49 | 'gl' : '$(EXTRALIBS_OPENGL)', | |
50 | 'xml' : '$(EXTRALIBS_XML)', | |
c839485c | 51 | 'html' : '$(EXTRALIBS_HTML)', |
22cef566 | 52 | 'odbc' : '$(EXTRALIBS_ODBC)', |
c79241a2 | 53 | 'adv' : '$(PLUGIN_ADV_EXTRALIBS)', |
22cef566 | 54 | } |
ddf98968 VS |
55 | |
56 | def mkLibName(wxid): | |
57 | """Returns string that can be used as library name, including name | |
58 | suffixes, prefixes, version tags etc. This must be kept in sync | |
59 | with variables defined in common.bkl!""" | |
60 | if wxid == 'mono': | |
ea66c762 | 61 | return '$(WXNAMEPREFIXGUI)$(WXNAMESUFFIX)$(WXVERSIONTAG)$(HOST_SUFFIX)' |
e6978d5b | 62 | if wxid == 'base': |
ea66c762 | 63 | return '$(WXNAMEPREFIX)$(WXNAMESUFFIX)$(WXVERSIONTAG)$(HOST_SUFFIX)' |
e6978d5b | 64 | if wxid in LIBS_NOGUI: |
ea66c762 VS |
65 | return '$(WXNAMEPREFIX)$(WXNAMESUFFIX)_%s$(WXVERSIONTAG)$(HOST_SUFFIX)' % wxid |
66 | return '$(WXNAMEPREFIXGUI)$(WXNAMESUFFIX)_%s$(WXVERSIONTAG)$(HOST_SUFFIX)' % wxid | |
ddf98968 VS |
67 | |
68 | def mkDllName(wxid): | |
69 | """Returns string that can be used as DLL name, including name | |
70 | suffixes, prefixes, version tags etc. This must be kept in sync | |
71 | with variables defined in common.bkl!""" | |
72 | if wxid == 'mono': | |
4fc5f509 | 73 | return '$(WXDLLNAMEPREFIXGUI)$(WXNAMESUFFIX)$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG)' |
e6978d5b VS |
74 | if wxid == 'base': |
75 | return '$(WXDLLNAMEPREFIX)$(WXNAMESUFFIX)$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG)' | |
76 | if wxid in LIBS_NOGUI: | |
4fc5f509 VS |
77 | return '$(WXDLLNAMEPREFIX)$(WXNAMESUFFIX)_%s$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG)' % wxid |
78 | return '$(WXDLLNAMEPREFIXGUI)$(WXNAMESUFFIX)_%s$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG)' % wxid | |
ddf98968 VS |
79 | |
80 | ||
81 | def libToLink(wxlibname): | |
82 | """Returns string to pass to <sys-lib> when linking against 'wxlibname'. | |
3560dc76 VS |
83 | For one of main libraries, libToLink('foo') returns '$(WXLIB_FOO)' which |
84 | must be defined in common.bkl as either nothing (in monolithic build) or | |
85 | mkLibName('foo') (otherwise). | |
86 | For contrib libraries, it returns mkDllName(wxlibname). | |
87 | """ | |
88 | if wxlibname in MAIN_LIBS: | |
89 | return '$(WXLIB_%s)' % wxlibname.upper() | |
90 | else: | |
91 | return mkLibName(wxlibname) | |
ddf98968 | 92 | |
22cef566 VS |
93 | def extraLdflags(wxlibname): |
94 | if wxlibname in EXTRALIBS: | |
95 | return EXTRALIBS[wxlibname] | |
96 | else: | |
97 | return '' | |
ddf98968 VS |
98 | |
99 | wxVersion = None | |
100 | VERSION_FILE = '../../include/wx/version.h' | |
101 | ||
102 | def getVersion(): | |
77ffb593 | 103 | """Returns wxWidgets version as a tuple: (major,minor,release).""" |
ddf98968 VS |
104 | global wxVersion |
105 | if wxVersion == None: | |
106 | f = open(VERSION_FILE, 'rt') | |
107 | lines = f.readlines() | |
108 | f.close() | |
109 | major = minor = release = None | |
110 | for l in lines: | |
111 | if not l.startswith('#define'): continue | |
3103e8a9 JS |
112 | splitline = l.strip().split() |
113 | if splitline[0] != '#define': continue | |
114 | if len(splitline) < 3: continue | |
115 | name = splitline[1] | |
116 | value = splitline[2] | |
ddf98968 VS |
117 | if value == None: continue |
118 | if name == 'wxMAJOR_VERSION': major = int(value) | |
119 | if name == 'wxMINOR_VERSION': minor = int(value) | |
120 | if name == 'wxRELEASE_NUMBER': release = int(value) | |
121 | if major != None and minor != None and release != None: | |
122 | break | |
123 | wxVersion = (major, minor, release) | |
124 | return wxVersion | |
125 | ||
126 | def getVersionMajor(): | |
127 | return getVersion()[0] | |
128 | def getVersionMinor(): | |
129 | return getVersion()[1] | |
130 | def getVersionRelease(): | |
131 | return getVersion()[2] | |
390c0cfb VS |
132 | |
133 | ||
134 | def headersOnly(files): | |
135 | """Filters 'files' so that only headers are left. Used with | |
136 | <msvc-project-files> to add headers to VC++ projects but not files such | |
137 | as arrimpl.cpp.""" | |
138 | ||
139 | def callback(cond, sources): | |
140 | prf = suf = '' | |
5d38306b VS |
141 | if sources[0].isspace(): prf=' ' |
142 | if sources[-1].isspace(): suf=' ' | |
390c0cfb VS |
143 | retval = [] |
144 | for s in sources.split(): | |
145 | if s.endswith('.h'): | |
146 | retval.append(s) | |
147 | return '%s%s%s' % (prf, ' '.join(retval), suf) | |
148 | return utils.substitute2(files, callback) | |
dce0742b VS |
149 | |
150 | ||
151 | def makeDspDependency(lib): | |
152 | """Returns suitable entry for <depends-on-dsp> for main libs.""" | |
c79241a2 | 153 | return '%s:$(nativePaths(WXTOPDIR))build\\msw\\wx_%s.dsp' % (lib,lib) |
2edad6fc MW |
154 | |
155 | def makeContribDspDependency(lib): | |
156 | """Returns suitable entry for <depends-on-dsp> for contrib libs.""" | |
157 | return '%s:$(nativePaths(WXTOPDIR))contrib\\build\\%s\\%s.dsp' % (lib,lib,lib) |