]> git.saurik.com Git - wxWidgets.git/blob - build/bakefiles/wxwin.py
better way of dealing with EXTRALIBS_xxx
[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('SETUPHDIR', __noopSubst)
19 utils.addSubstituteCallback('OBJS', __noopSubst)
20
21
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
34 # All libs that are part of the main library (i.e. non-contrib):
35 MAIN_LIBS = ['mono', 'base', 'core', 'adv', 'html', 'xml', 'net',
36 'odbc', 'dbgrid']
37 # List of library names/ids for categories with different names:
38 LIBS_NOGUI = ['xml', 'net', 'odbc']
39 LIBS_GUI = ['core', 'adv', 'html', 'gl', 'dbgrid']
40 # Additional libraries that must be linked in:
41 EXTRALIBS = {
42 'gl' : '$(EXTRALIBS_OPENGL)',
43 'xml' : '$(EXTRALIBS_XML)',
44 'odbc' : '$(EXTRALIBS_ODBC)',
45 }
46
47 def mkLibName(wxid):
48 """Returns string that can be used as library name, including name
49 suffixes, prefixes, version tags etc. This must be kept in sync
50 with variables defined in common.bkl!"""
51 if wxid == 'mono':
52 return '$(WXNAMEPREFIXGUI)$(WXNAMESUFFIX)$(WXVERSIONTAG)$(HOST_SUFFIX)'
53 if wxid == 'base':
54 return '$(WXNAMEPREFIX)$(WXNAMESUFFIX)$(WXVERSIONTAG)$(HOST_SUFFIX)'
55 if wxid in LIBS_NOGUI:
56 return '$(WXNAMEPREFIX)$(WXNAMESUFFIX)_%s$(WXVERSIONTAG)$(HOST_SUFFIX)' % wxid
57 return '$(WXNAMEPREFIXGUI)$(WXNAMESUFFIX)_%s$(WXVERSIONTAG)$(HOST_SUFFIX)' % wxid
58
59 def mkDllName(wxid):
60 """Returns string that can be used as DLL name, including name
61 suffixes, prefixes, version tags etc. This must be kept in sync
62 with variables defined in common.bkl!"""
63 if wxid == 'mono':
64 return '$(WXDLLNAMEPREFIXGUI)$(WXNAMESUFFIX)$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG)'
65 if wxid == 'base':
66 return '$(WXDLLNAMEPREFIX)$(WXNAMESUFFIX)$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG)'
67 if wxid in LIBS_NOGUI:
68 return '$(WXDLLNAMEPREFIX)$(WXNAMESUFFIX)_%s$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG)' % wxid
69 return '$(WXDLLNAMEPREFIXGUI)$(WXNAMESUFFIX)_%s$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG)' % wxid
70
71
72 def libToLink(wxlibname):
73 """Returns string to pass to <sys-lib> when linking against 'wxlibname'.
74 For one of main libraries, libToLink('foo') returns '$(WXLIB_FOO)' which
75 must be defined in common.bkl as either nothing (in monolithic build) or
76 mkLibName('foo') (otherwise).
77 For contrib libraries, it returns mkDllName(wxlibname).
78 """
79 if wxlibname in MAIN_LIBS:
80 return '$(WXLIB_%s)' % wxlibname.upper()
81 else:
82 return mkLibName(wxlibname)
83
84 def extraLdflags(wxlibname):
85 if wxlibname in EXTRALIBS:
86 return EXTRALIBS[wxlibname]
87 else:
88 return ''
89
90 wxVersion = None
91 VERSION_FILE = '../../include/wx/version.h'
92
93 def getVersion():
94 """Returns wxWindows version as a tuple: (major,minor,release)."""
95 global wxVersion
96 if wxVersion == None:
97 f = open(VERSION_FILE, 'rt')
98 lines = f.readlines()
99 f.close()
100 major = minor = release = None
101 for l in lines:
102 if not l.startswith('#define'): continue
103 splitted = l.strip().split()
104 if splitted[0] != '#define': continue
105 if len(splitted) < 3: continue
106 name = splitted[1]
107 value = splitted[2]
108 if value == None: continue
109 if name == 'wxMAJOR_VERSION': major = int(value)
110 if name == 'wxMINOR_VERSION': minor = int(value)
111 if name == 'wxRELEASE_NUMBER': release = int(value)
112 if major != None and minor != None and release != None:
113 break
114 wxVersion = (major, minor, release)
115 return wxVersion
116
117 def getVersionMajor():
118 return getVersion()[0]
119 def getVersionMinor():
120 return getVersion()[1]
121 def getVersionRelease():
122 return getVersion()[2]
123
124
125 def headersOnly(files):
126 """Filters 'files' so that only headers are left. Used with
127 <msvc-project-files> to add headers to VC++ projects but not files such
128 as arrimpl.cpp."""
129
130 def callback(cond, sources):
131 prf = suf = ''
132 if sources[0].isspace(): prefix=' '
133 if sources[-1].isspace(): suffix=' '
134 retval = []
135 for s in sources.split():
136 if s.endswith('.h'):
137 retval.append(s)
138 return '%s%s%s' % (prf, ' '.join(retval), suf)
139 return utils.substitute2(files, callback)
140
141
142 def makeDspDependency(lib):
143 """Returns suitable entry for <depends-on-dsp> for main libs."""
144
145 DEPS_TABLE = {
146 'core':'base',
147 'adv':'core',
148 'html':'core',
149 'xml':'base',
150 'net':'base',
151 'odbc':'base',
152 'dbgrid':'adv,odbc',
153 }
154 if lib in DEPS_TABLE:
155 deps = ':%s' % DEPS_TABLE[lib]
156 else:
157 deps = ''
158 return '%s:$(nativePaths(WXTOPDIR))build\msw\wx_%s.dsp%s' % (lib,lib,deps)