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