[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 |
---|
| 6 | from waflib import Task,Utils,Options,Errors,Logs |
---|
| 7 | from waflib.TaskGen import taskgen_method,before_method,after_method,feature |
---|
| 8 | @taskgen_method |
---|
| 9 | def add_marshal_file(self,filename,prefix): |
---|
| 10 | if not hasattr(self,'marshal_list'): |
---|
| 11 | self.marshal_list=[] |
---|
| 12 | self.meths.append('process_marshal') |
---|
| 13 | self.marshal_list.append((filename,prefix)) |
---|
| 14 | @before_method('process_source') |
---|
| 15 | def process_marshal(self): |
---|
| 16 | for f,prefix in getattr(self,'marshal_list',[]): |
---|
| 17 | node=self.path.find_resource(f) |
---|
| 18 | if not node: |
---|
| 19 | raise Errors.WafError('file not found %r'%f) |
---|
| 20 | h_node=node.change_ext('.h') |
---|
| 21 | c_node=node.change_ext('.c') |
---|
| 22 | task=self.create_task('glib_genmarshal',node,[h_node,c_node]) |
---|
| 23 | task.env.GLIB_GENMARSHAL_PREFIX=prefix |
---|
| 24 | self.source=self.to_nodes(getattr(self,'source',[])) |
---|
| 25 | self.source.append(c_node) |
---|
| 26 | class glib_genmarshal(Task.Task): |
---|
| 27 | def run(self): |
---|
| 28 | bld=self.inputs[0].__class__.ctx |
---|
| 29 | get=self.env.get_flat |
---|
| 30 | cmd1="%s %s --prefix=%s --header > %s"%(get('GLIB_GENMARSHAL'),self.inputs[0].srcpath(),get('GLIB_GENMARSHAL_PREFIX'),self.outputs[0].abspath()) |
---|
| 31 | ret=bld.exec_command(cmd1) |
---|
| 32 | if ret:return ret |
---|
| 33 | c='''#include "%s"\n'''%self.outputs[0].name |
---|
| 34 | self.outputs[1].write(c) |
---|
| 35 | cmd2="%s %s --prefix=%s --body >> %s"%(get('GLIB_GENMARSHAL'),self.inputs[0].srcpath(),get('GLIB_GENMARSHAL_PREFIX'),self.outputs[1].abspath()) |
---|
| 36 | return bld.exec_command(cmd2) |
---|
| 37 | vars=['GLIB_GENMARSHAL_PREFIX','GLIB_GENMARSHAL'] |
---|
| 38 | color='BLUE' |
---|
| 39 | ext_out=['.h'] |
---|
| 40 | @taskgen_method |
---|
| 41 | def add_enums_from_template(self,source='',target='',template='',comments=''): |
---|
| 42 | if not hasattr(self,'enums_list'): |
---|
| 43 | self.enums_list=[] |
---|
| 44 | self.meths.append('process_enums') |
---|
| 45 | self.enums_list.append({'source':source,'target':target,'template':template,'file-head':'','file-prod':'','file-tail':'','enum-prod':'','value-head':'','value-prod':'','value-tail':'','comments':comments}) |
---|
| 46 | @taskgen_method |
---|
| 47 | def add_enums(self,source='',target='',file_head='',file_prod='',file_tail='',enum_prod='',value_head='',value_prod='',value_tail='',comments=''): |
---|
| 48 | if not hasattr(self,'enums_list'): |
---|
| 49 | self.enums_list=[] |
---|
| 50 | self.meths.append('process_enums') |
---|
| 51 | self.enums_list.append({'source':source,'template':'','target':target,'file-head':file_head,'file-prod':file_prod,'file-tail':file_tail,'enum-prod':enum_prod,'value-head':value_head,'value-prod':value_prod,'value-tail':value_tail,'comments':comments}) |
---|
| 52 | @before_method('process_source') |
---|
| 53 | def process_enums(self): |
---|
| 54 | for enum in getattr(self,'enums_list',[]): |
---|
| 55 | task=self.create_task('glib_mkenums') |
---|
| 56 | env=task.env |
---|
| 57 | inputs=[] |
---|
| 58 | source_list=self.to_list(enum['source']) |
---|
| 59 | if not source_list: |
---|
| 60 | raise Errors.WafError('missing source '+str(enum)) |
---|
| 61 | source_list=[self.path.find_resource(k)for k in source_list] |
---|
| 62 | inputs+=source_list |
---|
| 63 | env['GLIB_MKENUMS_SOURCE']=[k.abspath()for k in source_list] |
---|
| 64 | if not enum['target']: |
---|
| 65 | raise Errors.WafError('missing target '+str(enum)) |
---|
| 66 | tgt_node=self.path.find_or_declare(enum['target']) |
---|
| 67 | if tgt_node.name.endswith('.c'): |
---|
| 68 | self.source.append(tgt_node) |
---|
| 69 | env['GLIB_MKENUMS_TARGET']=tgt_node.abspath() |
---|
| 70 | options=[] |
---|
| 71 | if enum['template']: |
---|
| 72 | template_node=self.path.find_resource(enum['template']) |
---|
| 73 | options.append('--template %s'%(template_node.abspath())) |
---|
| 74 | inputs.append(template_node) |
---|
| 75 | params={'file-head':'--fhead','file-prod':'--fprod','file-tail':'--ftail','enum-prod':'--eprod','value-head':'--vhead','value-prod':'--vprod','value-tail':'--vtail','comments':'--comments'} |
---|
| 76 | for param,option in params.items(): |
---|
| 77 | if enum[param]: |
---|
| 78 | options.append('%s %r'%(option,enum[param])) |
---|
| 79 | env['GLIB_MKENUMS_OPTIONS']=' '.join(options) |
---|
| 80 | task.set_inputs(inputs) |
---|
| 81 | task.set_outputs(tgt_node) |
---|
| 82 | class glib_mkenums(Task.Task): |
---|
| 83 | run_str='${GLIB_MKENUMS} ${GLIB_MKENUMS_OPTIONS} ${GLIB_MKENUMS_SOURCE} > ${GLIB_MKENUMS_TARGET}' |
---|
| 84 | color='PINK' |
---|
| 85 | ext_out=['.h'] |
---|
| 86 | @taskgen_method |
---|
| 87 | def add_settings_schemas(self,filename_list): |
---|
| 88 | if not hasattr(self,'settings_schema_files'): |
---|
| 89 | self.settings_schema_files=[] |
---|
| 90 | if not isinstance(filename_list,list): |
---|
| 91 | filename_list=[filename_list] |
---|
| 92 | self.settings_schema_files.extend(filename_list) |
---|
| 93 | @taskgen_method |
---|
| 94 | def add_settings_enums(self,namespace,filename_list): |
---|
| 95 | if hasattr(self,'settings_enum_namespace'): |
---|
| 96 | raise Errors.WafError("Tried to add gsettings enums to '%s' more than once"%self.name) |
---|
| 97 | self.settings_enum_namespace=namespace |
---|
| 98 | if type(filename_list)!='list': |
---|
| 99 | filename_list=[filename_list] |
---|
| 100 | self.settings_enum_files=filename_list |
---|
| 101 | def r_change_ext(self,ext): |
---|
| 102 | name=self.name |
---|
| 103 | k=name.rfind('.') |
---|
| 104 | if k>=0: |
---|
| 105 | name=name[:k]+ext |
---|
| 106 | else: |
---|
| 107 | name=name+ext |
---|
| 108 | return self.parent.find_or_declare([name]) |
---|
| 109 | @feature('glib2') |
---|
| 110 | def process_settings(self): |
---|
| 111 | enums_tgt_node=[] |
---|
| 112 | install_files=[] |
---|
| 113 | settings_schema_files=getattr(self,'settings_schema_files',[]) |
---|
| 114 | if settings_schema_files and not self.env['GLIB_COMPILE_SCHEMAS']: |
---|
| 115 | raise Errors.WafError("Unable to process GSettings schemas - glib-compile-schemas was not found during configure") |
---|
| 116 | if hasattr(self,'settings_enum_files'): |
---|
| 117 | enums_task=self.create_task('glib_mkenums') |
---|
| 118 | source_list=self.settings_enum_files |
---|
| 119 | source_list=[self.path.find_resource(k)for k in source_list] |
---|
| 120 | enums_task.set_inputs(source_list) |
---|
| 121 | enums_task.env['GLIB_MKENUMS_SOURCE']=[k.abspath()for k in source_list] |
---|
| 122 | target=self.settings_enum_namespace+'.enums.xml' |
---|
| 123 | tgt_node=self.path.find_or_declare(target) |
---|
| 124 | enums_task.set_outputs(tgt_node) |
---|
| 125 | enums_task.env['GLIB_MKENUMS_TARGET']=tgt_node.abspath() |
---|
| 126 | enums_tgt_node=[tgt_node] |
---|
| 127 | install_files.append(tgt_node) |
---|
| 128 | options='--comments "<!-- @comment@ -->" --fhead "<schemalist>" --vhead " <@type@ id=\\"%s.@EnumName@\\">" --vprod " <value nick=\\"@valuenick@\\" value=\\"@valuenum@\\"/>" --vtail " </@type@>" --ftail "</schemalist>" '%(self.settings_enum_namespace) |
---|
| 129 | enums_task.env['GLIB_MKENUMS_OPTIONS']=options |
---|
| 130 | for schema in settings_schema_files: |
---|
| 131 | schema_task=self.create_task('glib_validate_schema') |
---|
| 132 | schema_node=self.path.find_resource(schema) |
---|
| 133 | if not schema_node: |
---|
| 134 | raise Errors.WafError("Cannot find the schema file '%s'"%schema) |
---|
| 135 | install_files.append(schema_node) |
---|
| 136 | source_list=enums_tgt_node+[schema_node] |
---|
| 137 | schema_task.set_inputs(source_list) |
---|
| 138 | schema_task.env['GLIB_COMPILE_SCHEMAS_OPTIONS']=[("--schema-file="+k.abspath())for k in source_list] |
---|
| 139 | target_node=r_change_ext(schema_node,'.xml.valid') |
---|
| 140 | schema_task.set_outputs(target_node) |
---|
| 141 | schema_task.env['GLIB_VALIDATE_SCHEMA_OUTPUT']=target_node.abspath() |
---|
| 142 | def compile_schemas_callback(bld): |
---|
| 143 | if not bld.is_install:return |
---|
| 144 | Logs.pprint('YELLOW','Updating GSettings schema cache') |
---|
| 145 | command=Utils.subst_vars("${GLIB_COMPILE_SCHEMAS} ${GSETTINGSSCHEMADIR}",bld.env) |
---|
| 146 | ret=self.bld.exec_command(command) |
---|
| 147 | if self.bld.is_install: |
---|
| 148 | if not self.env['GSETTINGSSCHEMADIR']: |
---|
| 149 | raise Errors.WafError('GSETTINGSSCHEMADIR not defined (should have been set up automatically during configure)') |
---|
| 150 | if install_files: |
---|
| 151 | self.bld.install_files(self.env['GSETTINGSSCHEMADIR'],install_files) |
---|
| 152 | if not hasattr(self.bld,'_compile_schemas_registered'): |
---|
| 153 | self.bld.add_post_fun(compile_schemas_callback) |
---|
| 154 | self.bld._compile_schemas_registered=True |
---|
| 155 | class glib_validate_schema(Task.Task): |
---|
| 156 | run_str='rm -f ${GLIB_VALIDATE_SCHEMA_OUTPUT} && ${GLIB_COMPILE_SCHEMAS} --dry-run ${GLIB_COMPILE_SCHEMAS_OPTIONS} && touch ${GLIB_VALIDATE_SCHEMA_OUTPUT}' |
---|
| 157 | color='PINK' |
---|
| 158 | def configure(conf): |
---|
| 159 | conf.find_program('glib-genmarshal',var='GLIB_GENMARSHAL') |
---|
| 160 | conf.find_perl_program('glib-mkenums',var='GLIB_MKENUMS') |
---|
| 161 | conf.find_program('glib-compile-schemas',var='GLIB_COMPILE_SCHEMAS',mandatory=False) |
---|
| 162 | def getstr(varname): |
---|
| 163 | return getattr(Options.options,varname,getattr(conf.env,varname,'')) |
---|
| 164 | gsettingsschemadir=getstr('GSETTINGSSCHEMADIR') |
---|
| 165 | if not gsettingsschemadir: |
---|
| 166 | datadir=getstr('DATADIR') |
---|
| 167 | if not datadir: |
---|
| 168 | prefix=conf.env['PREFIX'] |
---|
| 169 | datadir=os.path.join(prefix,'share') |
---|
| 170 | gsettingsschemadir=os.path.join(datadir,'glib-2.0','schemas') |
---|
| 171 | conf.env['GSETTINGSSCHEMADIR']=gsettingsschemadir |
---|
| 172 | def options(opt): |
---|
| 173 | opt.add_option('--gsettingsschemadir',help='GSettings schema location [Default: ${datadir}/glib-2.0/schemas]',default='',dest='GSETTINGSSCHEMADIR') |
---|