1 | #! /usr/bin/env python |
---|
2 | # encoding: utf-8 |
---|
3 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file |
---|
4 | |
---|
5 | import os,re |
---|
6 | from waflib import Configure,Context,TaskGen,Task,Utils,Runner,Options,Build,Logs |
---|
7 | import waflib.Tools.ccroot |
---|
8 | from waflib.TaskGen import feature,before_method,taskgen_method |
---|
9 | from waflib.Logs import error |
---|
10 | from waflib.Configure import conf |
---|
11 | _style_flags={'ba':'-b','desktop':'-d','keys':'-k','quoted':'--quoted-style','quotedxml':'--quotedxml-style','rfc822deb':'-r','schemas':'-s','xml':'-x',} |
---|
12 | @taskgen_method |
---|
13 | def ensure_localedir(self): |
---|
14 | if not self.env.LOCALEDIR: |
---|
15 | if self.env.DATAROOTDIR: |
---|
16 | self.env.LOCALEDIR=os.path.join(self.env.DATAROOTDIR,'locale') |
---|
17 | else: |
---|
18 | self.env.LOCALEDIR=os.path.join(self.env.PREFIX,'share','locale') |
---|
19 | @before_method('process_source') |
---|
20 | @feature('intltool_in') |
---|
21 | def apply_intltool_in_f(self): |
---|
22 | try:self.meths.remove('process_source') |
---|
23 | except ValueError:pass |
---|
24 | self.ensure_localedir() |
---|
25 | podir=getattr(self,'podir','.') |
---|
26 | podirnode=self.path.find_dir(podir) |
---|
27 | if not podirnode: |
---|
28 | error("could not find the podir %r"%podir) |
---|
29 | return |
---|
30 | cache=getattr(self,'intlcache','.intlcache') |
---|
31 | self.env.INTLCACHE=[os.path.join(str(self.path.get_bld()),podir,cache)] |
---|
32 | self.env.INTLPODIR=podirnode.bldpath() |
---|
33 | self.env.append_value('INTLFLAGS',getattr(self,'flags',self.env.INTLFLAGS_DEFAULT)) |
---|
34 | if'-c'in self.env.INTLFLAGS: |
---|
35 | self.bld.fatal('Redundant -c flag in intltool task %r'%self) |
---|
36 | style=getattr(self,'style',None) |
---|
37 | if style: |
---|
38 | try: |
---|
39 | style_flag=_style_flags[style] |
---|
40 | except KeyError: |
---|
41 | self.bld.fatal('intltool_in style "%s" is not valid'%style) |
---|
42 | self.env.append_unique('INTLFLAGS',[style_flag]) |
---|
43 | for i in self.to_list(self.source): |
---|
44 | node=self.path.find_resource(i) |
---|
45 | task=self.create_task('intltool',node,node.change_ext('')) |
---|
46 | inst=getattr(self,'install_path',None) |
---|
47 | if inst: |
---|
48 | self.bld.install_files(inst,task.outputs) |
---|
49 | @feature('intltool_po') |
---|
50 | def apply_intltool_po(self): |
---|
51 | try:self.meths.remove('process_source') |
---|
52 | except ValueError:pass |
---|
53 | self.ensure_localedir() |
---|
54 | appname=getattr(self,'appname',getattr(Context.g_module,Context.APPNAME,'set_your_app_name')) |
---|
55 | podir=getattr(self,'podir','.') |
---|
56 | inst=getattr(self,'install_path','${LOCALEDIR}') |
---|
57 | linguas=self.path.find_node(os.path.join(podir,'LINGUAS')) |
---|
58 | if linguas: |
---|
59 | file=open(linguas.abspath()) |
---|
60 | langs=[] |
---|
61 | for line in file.readlines(): |
---|
62 | if not line.startswith('#'): |
---|
63 | langs+=line.split() |
---|
64 | file.close() |
---|
65 | re_linguas=re.compile('[-a-zA-Z_@.]+') |
---|
66 | for lang in langs: |
---|
67 | if re_linguas.match(lang): |
---|
68 | node=self.path.find_resource(os.path.join(podir,re_linguas.match(lang).group()+'.po')) |
---|
69 | task=self.create_task('po',node,node.change_ext('.mo')) |
---|
70 | if inst: |
---|
71 | filename=task.outputs[0].name |
---|
72 | (langname,ext)=os.path.splitext(filename) |
---|
73 | inst_file=inst+os.sep+langname+os.sep+'LC_MESSAGES'+os.sep+appname+'.mo' |
---|
74 | self.bld.install_as(inst_file,task.outputs[0],chmod=getattr(self,'chmod',Utils.O644),env=task.env) |
---|
75 | else: |
---|
76 | Logs.pprint('RED',"Error no LINGUAS file found in po directory") |
---|
77 | class po(Task.Task): |
---|
78 | run_str='${MSGFMT} -o ${TGT} ${SRC}' |
---|
79 | color='BLUE' |
---|
80 | class intltool(Task.Task): |
---|
81 | run_str='${INTLTOOL} ${INTLFLAGS} ${INTLCACHE_ST:INTLCACHE} ${INTLPODIR} ${SRC} ${TGT}' |
---|
82 | color='BLUE' |
---|
83 | @conf |
---|
84 | def find_msgfmt(conf): |
---|
85 | conf.find_program('msgfmt',var='MSGFMT') |
---|
86 | @conf |
---|
87 | def find_intltool_merge(conf): |
---|
88 | if not conf.env.PERL: |
---|
89 | conf.find_program('perl',var='PERL') |
---|
90 | conf.env.INTLCACHE_ST='--cache=%s' |
---|
91 | conf.env.INTLFLAGS_DEFAULT=['-q','-u'] |
---|
92 | conf.find_program('intltool-merge',interpreter='PERL',var='INTLTOOL') |
---|
93 | def configure(conf): |
---|
94 | conf.find_msgfmt() |
---|
95 | conf.find_intltool_merge() |
---|
96 | if conf.env.CC or conf.env.CXX: |
---|
97 | conf.check(header_name='locale.h') |
---|