wxwin.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #
  2. # Helper functions for wxWidgets bakefiles
  3. #
  4. #
  5. import utils
  6. # We use 'CFG' option in places where bakefile doesn't like it, so we must
  7. # register a substitution function for it that provides additional knowledge
  8. # about the option (in this case that it does not contain dir separators and
  9. # so utils.nativePaths() doesn't have to do anything with it):
  10. try:
  11. # this fails in 0.1.4 and 0.1.5 has different subst.callbacks signature:
  12. utils.checkBakefileVersion('0.1.5')
  13. def __noopSubst(name, func, caller):
  14. return '$(%s)' % name
  15. except AttributeError:
  16. def __noopSubst(func, name):
  17. return '$(%s)' % name
  18. utils.addSubstituteCallback('CFG', __noopSubst)
  19. utils.addSubstituteCallback('LIBDIRNAME', __noopSubst)
  20. utils.addSubstituteCallback('SETUPHDIR', __noopSubst)
  21. utils.addSubstituteCallback('OBJS', __noopSubst)
  22. def mk_wxid(id):
  23. """Creates wxWidgets 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. # All libs that are part of the main library:
  33. MAIN_LIBS = ['mono', 'base', 'core', 'adv', 'html', 'xml', 'net', 'webview',
  34. 'media', 'qa', 'xrc', 'aui', 'ribbon', 'propgrid', 'richtext', 'stc']
  35. # List of library names/ids for categories with different names:
  36. LIBS_NOGUI = ['xml', 'net']
  37. LIBS_GUI = ['core', 'adv', 'html', 'gl', 'qa', 'xrc', 'media',
  38. 'aui', 'propgrid', 'richtext', 'stc', 'ribbon', 'webview']
  39. # Additional libraries that must be linked in:
  40. EXTRALIBS = {
  41. 'gl' : '$(EXTRALIBS_OPENGL)',
  42. 'xml' : '$(EXTRALIBS_XML)',
  43. 'html' : '$(EXTRALIBS_HTML)',
  44. 'adv' : '$(PLUGIN_ADV_EXTRALIBS)',
  45. 'media' : '$(EXTRALIBS_MEDIA)',
  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. def mkDllName(wxid):
  59. """Returns string that can be used as DLL name, including name
  60. suffixes, prefixes, version tags etc. This must be kept in sync
  61. with variables defined in common.bkl!"""
  62. if wxid == 'mono':
  63. return '$(WXDLLNAMEPREFIXGUI)$(WXNAMESUFFIX)$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG)'
  64. if wxid == 'base':
  65. return '$(WXDLLNAMEPREFIX)$(WXNAMESUFFIX)$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG)'
  66. if wxid in LIBS_NOGUI:
  67. return '$(WXDLLNAMEPREFIX)$(WXNAMESUFFIX)_%s$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG)' % wxid
  68. return '$(WXDLLNAMEPREFIXGUI)$(WXNAMESUFFIX)_%s$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG)' % wxid
  69. def libToLink(wxlibname):
  70. """Returns string to pass to <sys-lib> when linking against 'wxlibname'.
  71. For one of main libraries, libToLink('foo') returns '$(WXLIB_FOO)' which
  72. must be defined in common.bkl as either nothing (in monolithic build) or
  73. mkLibName('foo') (otherwise).
  74. """
  75. if wxlibname in MAIN_LIBS:
  76. return '$(WXLIB_%s)' % wxlibname.upper()
  77. else:
  78. return mkLibName(wxlibname)
  79. def extraLdflags(wxlibname):
  80. if wxlibname in EXTRALIBS:
  81. return EXTRALIBS[wxlibname]
  82. else:
  83. return ''
  84. wxVersion = None
  85. VERSION_FILE = '../../include/wx/version.h'
  86. def getVersion():
  87. """Returns wxWidgets version as a tuple: (major,minor,release)."""
  88. global wxVersion
  89. if wxVersion == None:
  90. f = open(VERSION_FILE, 'rt')
  91. lines = f.readlines()
  92. f.close()
  93. major = minor = release = None
  94. for l in lines:
  95. if not l.startswith('#define'): continue
  96. splitline = l.strip().split()
  97. if splitline[0] != '#define': continue
  98. if len(splitline) < 3: continue
  99. name = splitline[1]
  100. value = splitline[2]
  101. if value == None: continue
  102. if name == 'wxMAJOR_VERSION': major = int(value)
  103. if name == 'wxMINOR_VERSION': minor = int(value)
  104. if name == 'wxRELEASE_NUMBER': release = int(value)
  105. if major != None and minor != None and release != None:
  106. break
  107. wxVersion = (major, minor, release)
  108. return wxVersion
  109. def getVersionMajor():
  110. return getVersion()[0]
  111. def getVersionMinor():
  112. return getVersion()[1]
  113. def getVersionRelease():
  114. return getVersion()[2]
  115. def headersOnly(files):
  116. """Filters 'files' so that only headers are left. Used with
  117. <msvc-project-files> to add headers to VC++ projects but not files such
  118. as arrimpl.cpp."""
  119. def callback(cond, sources):
  120. prf = suf = ''
  121. if sources[0].isspace(): prf=' '
  122. if sources[-1].isspace(): suf=' '
  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. def makeDspDependency(lib):
  130. """Returns suitable entry for <depends-on-dsp> for main libs."""
  131. return '%s:$(nativePaths(WXTOPDIR))build\\msw\\wx_%s.dsp' % (lib,lib)