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