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