kde4.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. # Thomas Nagy, 2006-2010 (ita)
  4. """
  5. Support for the KDE4 libraries and msgfmt
  6. """
  7. import os, re
  8. from waflib import Task, Utils
  9. from waflib.TaskGen import feature
  10. @feature('msgfmt')
  11. def apply_msgfmt(self):
  12. """
  13. Process all languages to create .mo files and to install them::
  14. def build(bld):
  15. bld(features='msgfmt', langs='es de fr', appname='myapp', install_path='${KDE4_LOCALE_INSTALL_DIR}')
  16. """
  17. for lang in self.to_list(self.langs):
  18. node = self.path.find_resource(lang+'.po')
  19. task = self.create_task('msgfmt', node, node.change_ext('.mo'))
  20. langname = lang.split('/')
  21. langname = langname[-1]
  22. inst = getattr(self, 'install_path', '${KDE4_LOCALE_INSTALL_DIR}')
  23. self.add_install_as(
  24. inst_to = inst + os.sep + langname + os.sep + 'LC_MESSAGES' + os.sep + getattr(self, 'appname', 'set_your_appname') + '.mo',
  25. inst_from = task.outputs[0],
  26. chmod = getattr(self, 'chmod', Utils.O644))
  27. class msgfmt(Task.Task):
  28. """
  29. Transform .po files into .mo files
  30. """
  31. color = 'BLUE'
  32. run_str = '${MSGFMT} ${SRC} -o ${TGT}'
  33. def configure(self):
  34. """
  35. Detect kde4-config and set various variables for the *use* system::
  36. def options(opt):
  37. opt.load('compiler_cxx kde4')
  38. def configure(conf):
  39. conf.load('compiler_cxx kde4')
  40. def build(bld):
  41. bld.program(source='main.c', target='app', use='KDECORE KIO KHTML')
  42. """
  43. kdeconfig = self.find_program('kde4-config')
  44. prefix = self.cmd_and_log(kdeconfig + ['--prefix']).strip()
  45. fname = '%s/share/apps/cmake/modules/KDELibsDependencies.cmake' % prefix
  46. try:
  47. os.stat(fname)
  48. except OSError:
  49. fname = '%s/share/kde4/apps/cmake/modules/KDELibsDependencies.cmake' % prefix
  50. try:
  51. os.stat(fname)
  52. except OSError:
  53. self.fatal('could not open %s' % fname)
  54. try:
  55. txt = Utils.readf(fname)
  56. except EnvironmentError:
  57. self.fatal('could not read %s' % fname)
  58. txt = txt.replace('\\\n', '\n')
  59. fu = re.compile('#(.*)\n')
  60. txt = fu.sub('', txt)
  61. setregexp = re.compile('([sS][eE][tT]\s*\()\s*([^\s]+)\s+\"([^"]+)\"\)')
  62. found = setregexp.findall(txt)
  63. for (_, key, val) in found:
  64. #print key, val
  65. self.env[key] = val
  66. # well well, i could just write an interpreter for cmake files
  67. self.env['LIB_KDECORE']= ['kdecore']
  68. self.env['LIB_KDEUI'] = ['kdeui']
  69. self.env['LIB_KIO'] = ['kio']
  70. self.env['LIB_KHTML'] = ['khtml']
  71. self.env['LIB_KPARTS'] = ['kparts']
  72. self.env['LIBPATH_KDECORE'] = [os.path.join(self.env.KDE4_LIB_INSTALL_DIR, 'kde4', 'devel'), self.env.KDE4_LIB_INSTALL_DIR]
  73. self.env['INCLUDES_KDECORE'] = [self.env['KDE4_INCLUDE_INSTALL_DIR']]
  74. self.env.append_value('INCLUDES_KDECORE', [self.env['KDE4_INCLUDE_INSTALL_DIR']+ os.sep + 'KDE'])
  75. self.find_program('msgfmt', var='MSGFMT')