Include waf as an extracted source directory, rather than as a one-in-a-file script.
[ira/wip.git] / buildtools / wafadmin / Tools / kde4.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3 # Thomas Nagy, 2006 (ita)
4
5 import os, sys, re
6 import Options, TaskGen, Task, Utils
7 from TaskGen import taskgen, feature, after
8
9 class msgfmt_taskgen(TaskGen.task_gen):
10         def __init__(self, *k, **kw):
11                 TaskGen.task_gen.__init__(self, *k, **kw)
12
13 @feature('msgfmt')
14 def init_msgfmt(self):
15         #langs = '' # for example "foo/fr foo/br"
16         self.default_install_path = '${KDE4_LOCALE_INSTALL_DIR}'
17
18 @feature('msgfmt')
19 @after('init_msgfmt')
20 def apply_msgfmt(self):
21         for lang in self.to_list(self.langs):
22                 node = self.path.find_resource(lang+'.po')
23                 task = self.create_task('msgfmt', node, node.change_ext('.mo'))
24
25                 if not self.bld.is_install: continue
26                 langname = lang.split('/')
27                 langname = langname[-1]
28                 task.install_path = self.install_path + os.sep + langname + os.sep + 'LC_MESSAGES'
29                 task.filename = getattr(self, 'appname', 'set_your_appname') + '.mo'
30                 task.chmod = self.chmod
31
32 def detect(conf):
33         kdeconfig = conf.find_program('kde4-config')
34         if not kdeconfig:
35                 conf.fatal('we need kde4-config')
36         prefix = Utils.cmd_output('%s --prefix' % kdeconfig, silent=True).strip()
37         file = '%s/share/apps/cmake/modules/KDELibsDependencies.cmake' % prefix
38         try: os.stat(file)
39         except OSError:
40                 file = '%s/share/kde4/apps/cmake/modules/KDELibsDependencies.cmake' % prefix
41                 try: os.stat(file)
42                 except OSError: conf.fatal('could not open %s' % file)
43
44         try:
45                 txt = Utils.readf(file)
46         except (OSError, IOError):
47                 conf.fatal('could not read %s' % file)
48
49         txt = txt.replace('\\\n', '\n')
50         fu = re.compile('#(.*)\n')
51         txt = fu.sub('', txt)
52
53         setregexp = re.compile('([sS][eE][tT]\s*\()\s*([^\s]+)\s+\"([^"]+)\"\)')
54         found = setregexp.findall(txt)
55
56         for (_, key, val) in found:
57                 #print key, val
58                 conf.env[key] = val
59
60         # well well, i could just write an interpreter for cmake files
61         conf.env['LIB_KDECORE']='kdecore'
62         conf.env['LIB_KDEUI']  ='kdeui'
63         conf.env['LIB_KIO']    ='kio'
64         conf.env['LIB_KHTML']  ='khtml'
65         conf.env['LIB_KPARTS'] ='kparts'
66
67         conf.env['LIBPATH_KDECORE'] = conf.env['KDE4_LIB_INSTALL_DIR']
68         conf.env['CPPPATH_KDECORE'] = conf.env['KDE4_INCLUDE_INSTALL_DIR']
69         conf.env.append_value('CPPPATH_KDECORE', conf.env['KDE4_INCLUDE_INSTALL_DIR']+"/KDE")
70
71         conf.env['MSGFMT'] = conf.find_program('msgfmt')
72
73 Task.simple_task_type('msgfmt', '${MSGFMT} ${SRC} -o ${TGT}', color='BLUE', shell=False)
74