[0fa325b] | 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,TaskGen,Task,Utils,Runner,Options,Build,Logs |
---|
| 7 | import waflib.Tools.ccroot |
---|
| 8 | from waflib.TaskGen import feature,before_method |
---|
| 9 | from waflib.Logs import error |
---|
| 10 | @before_method('process_source') |
---|
| 11 | @feature('intltool_in') |
---|
| 12 | def apply_intltool_in_f(self): |
---|
| 13 | try:self.meths.remove('process_source') |
---|
| 14 | except ValueError:pass |
---|
| 15 | if not self.env.LOCALEDIR: |
---|
| 16 | self.env.LOCALEDIR=self.env.PREFIX+'/share/locale' |
---|
| 17 | for i in self.to_list(self.source): |
---|
| 18 | node=self.path.find_resource(i) |
---|
| 19 | podir=getattr(self,'podir','po') |
---|
| 20 | podirnode=self.path.find_dir(podir) |
---|
| 21 | if not podirnode: |
---|
| 22 | error("could not find the podir %r"%podir) |
---|
| 23 | continue |
---|
| 24 | cache=getattr(self,'intlcache','.intlcache') |
---|
| 25 | self.env['INTLCACHE']=os.path.join(self.path.bldpath(),podir,cache) |
---|
| 26 | self.env['INTLPODIR']=podirnode.bldpath() |
---|
| 27 | self.env['INTLFLAGS']=getattr(self,'flags',['-q','-u','-c']) |
---|
| 28 | task=self.create_task('intltool',node,node.change_ext('')) |
---|
| 29 | inst=getattr(self,'install_path','${LOCALEDIR}') |
---|
| 30 | if inst: |
---|
| 31 | self.bld.install_files(inst,task.outputs) |
---|
| 32 | @feature('intltool_po') |
---|
| 33 | def apply_intltool_po(self): |
---|
| 34 | try:self.meths.remove('process_source') |
---|
| 35 | except ValueError:pass |
---|
| 36 | if not self.env.LOCALEDIR: |
---|
| 37 | self.env.LOCALEDIR=self.env.PREFIX+'/share/locale' |
---|
| 38 | appname=getattr(self,'appname','set_your_app_name') |
---|
| 39 | podir=getattr(self,'podir','') |
---|
| 40 | inst=getattr(self,'install_path','${LOCALEDIR}') |
---|
| 41 | linguas=self.path.find_node(os.path.join(podir,'LINGUAS')) |
---|
| 42 | if linguas: |
---|
| 43 | file=open(linguas.abspath()) |
---|
| 44 | langs=[] |
---|
| 45 | for line in file.readlines(): |
---|
| 46 | if not line.startswith('#'): |
---|
| 47 | langs+=line.split() |
---|
| 48 | file.close() |
---|
| 49 | re_linguas=re.compile('[-a-zA-Z_@.]+') |
---|
| 50 | for lang in langs: |
---|
| 51 | if re_linguas.match(lang): |
---|
| 52 | node=self.path.find_resource(os.path.join(podir,re_linguas.match(lang).group()+'.po')) |
---|
| 53 | task=self.create_task('po',node,node.change_ext('.mo')) |
---|
| 54 | if inst: |
---|
| 55 | filename=task.outputs[0].name |
---|
| 56 | (langname,ext)=os.path.splitext(filename) |
---|
| 57 | inst_file=inst+os.sep+langname+os.sep+'LC_MESSAGES'+os.sep+appname+'.mo' |
---|
| 58 | self.bld.install_as(inst_file,task.outputs[0],chmod=getattr(self,'chmod',Utils.O644),env=task.env) |
---|
| 59 | else: |
---|
| 60 | Logs.pprint('RED',"Error no LINGUAS file found in po directory") |
---|
| 61 | class po(Task.Task): |
---|
| 62 | run_str='${MSGFMT} -o ${TGT} ${SRC}' |
---|
| 63 | color='BLUE' |
---|
| 64 | class intltool(Task.Task): |
---|
| 65 | run_str='${INTLTOOL} ${INTLFLAGS} ${INTLCACHE} ${INTLPODIR} ${SRC} ${TGT}' |
---|
| 66 | color='BLUE' |
---|
| 67 | def configure(conf): |
---|
| 68 | conf.find_program('msgfmt',var='MSGFMT') |
---|
| 69 | conf.find_perl_program('intltool-merge',var='INTLTOOL') |
---|
| 70 | prefix=conf.env.PREFIX |
---|
| 71 | datadir=conf.env.DATADIR |
---|
| 72 | if not datadir: |
---|
| 73 | datadir=os.path.join(prefix,'share') |
---|
| 74 | conf.define('LOCALEDIR',os.path.join(datadir,'locale').replace('\\','\\\\')) |
---|
| 75 | conf.define('DATADIR',datadir.replace('\\','\\\\')) |
---|
| 76 | if conf.env.CC or conf.env.CXX: |
---|
| 77 | conf.check(header_name='locale.h') |
---|