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 5import os 6import functools 7from waflib import Context,Task,Utils,Options,Errors,Logs 8from waflib.TaskGen import taskgen_method,before_method,feature,extension 9from waflib.Configure import conf 10@taskgen_method 11def add_marshal_file(self,filename,prefix): 12 if not hasattr(self,'marshal_list'): 13 self.marshal_list=[] 14 self.meths.append('process_marshal') 15 self.marshal_list.append((filename,prefix)) 16@before_method('process_source') 17def process_marshal(self): 18 for f,prefix in getattr(self,'marshal_list',[]): 19 node=self.path.find_resource(f) 20 if not node: 21 raise Errors.WafError('file not found %r'%f) 22 h_node=node.change_ext('.h') 23 c_node=node.change_ext('.c') 24 task=self.create_task('glib_genmarshal',node,[h_node,c_node]) 25 task.env.GLIB_GENMARSHAL_PREFIX=prefix 26 self.source=self.to_nodes(getattr(self,'source',[])) 27 self.source.append(c_node) 28class glib_genmarshal(Task.Task): 29 vars=['GLIB_GENMARSHAL_PREFIX','GLIB_GENMARSHAL'] 30 color='BLUE' 31 ext_out=['.h'] 32 def run(self): 33 bld=self.generator.bld 34 get=self.env.get_flat 35 cmd1="%s %s --prefix=%s --header > %s"%(get('GLIB_GENMARSHAL'),self.inputs[0].srcpath(),get('GLIB_GENMARSHAL_PREFIX'),self.outputs[0].abspath()) 36 ret=bld.exec_command(cmd1) 37 if ret: 38 return ret 39 c='''#include "%s"\n'''%self.outputs[0].name 40 self.outputs[1].write(c) 41 cmd2="%s %s --prefix=%s --body >> %s"%(get('GLIB_GENMARSHAL'),self.inputs[0].srcpath(),get('GLIB_GENMARSHAL_PREFIX'),self.outputs[1].abspath()) 42 return bld.exec_command(cmd2) 43@taskgen_method 44def add_enums_from_template(self,source='',target='',template='',comments=''): 45 if not hasattr(self,'enums_list'): 46 self.enums_list=[] 47 self.meths.append('process_enums') 48 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}) 49@taskgen_method 50def add_enums(self,source='',target='',file_head='',file_prod='',file_tail='',enum_prod='',value_head='',value_prod='',value_tail='',comments=''): 51 if not hasattr(self,'enums_list'): 52 self.enums_list=[] 53 self.meths.append('process_enums') 54 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}) 55@before_method('process_source') 56def process_enums(self): 57 for enum in getattr(self,'enums_list',[]): 58 task=self.create_task('glib_mkenums') 59 env=task.env 60 inputs=[] 61 source_list=self.to_list(enum['source']) 62 if not source_list: 63 raise Errors.WafError('missing source '+str(enum)) 64 source_list=[self.path.find_resource(k)for k in source_list] 65 inputs+=source_list 66 env.GLIB_MKENUMS_SOURCE=[k.abspath()for k in source_list] 67 if not enum['target']: 68 raise Errors.WafError('missing target '+str(enum)) 69 tgt_node=self.path.find_or_declare(enum['target']) 70 if tgt_node.name.endswith('.c'): 71 self.source.append(tgt_node) 72 env.GLIB_MKENUMS_TARGET=tgt_node.abspath() 73 options=[] 74 if enum['template']: 75 template_node=self.path.find_resource(enum['template']) 76 options.append('--template %s'%(template_node.abspath())) 77 inputs.append(template_node) 78 params={'file-head':'--fhead','file-prod':'--fprod','file-tail':'--ftail','enum-prod':'--eprod','value-head':'--vhead','value-prod':'--vprod','value-tail':'--vtail','comments':'--comments'} 79 for param,option in params.items(): 80 if enum[param]: 81 options.append('%s %r'%(option,enum[param])) 82 env.GLIB_MKENUMS_OPTIONS=' '.join(options) 83 task.set_inputs(inputs) 84 task.set_outputs(tgt_node) 85class glib_mkenums(Task.Task): 86 run_str='${GLIB_MKENUMS} ${GLIB_MKENUMS_OPTIONS} ${GLIB_MKENUMS_SOURCE} > ${GLIB_MKENUMS_TARGET}' 87 color='PINK' 88 ext_out=['.h'] 89@taskgen_method 90def add_settings_schemas(self,filename_list): 91 if not hasattr(self,'settings_schema_files'): 92 self.settings_schema_files=[] 93 if not isinstance(filename_list,list): 94 filename_list=[filename_list] 95 self.settings_schema_files.extend(filename_list) 96@taskgen_method 97def add_settings_enums(self,namespace,filename_list): 98 if hasattr(self,'settings_enum_namespace'): 99 raise Errors.WafError("Tried to add gsettings enums to %r more than once"%self.name) 100 self.settings_enum_namespace=namespace 101 if not isinstance(filename_list,list): 102 filename_list=[filename_list] 103 self.settings_enum_files=filename_list 104@feature('glib2') 105def process_settings(self): 106 enums_tgt_node=[] 107 install_files=[] 108 settings_schema_files=getattr(self,'settings_schema_files',[]) 109 if settings_schema_files and not self.env.GLIB_COMPILE_SCHEMAS: 110 raise Errors.WafError("Unable to process GSettings schemas - glib-compile-schemas was not found during configure") 111 if hasattr(self,'settings_enum_files'): 112 enums_task=self.create_task('glib_mkenums') 113 source_list=self.settings_enum_files 114 source_list=[self.path.find_resource(k)for k in source_list] 115 enums_task.set_inputs(source_list) 116 enums_task.env.GLIB_MKENUMS_SOURCE=[k.abspath()for k in source_list] 117 target=self.settings_enum_namespace+'.enums.xml' 118 tgt_node=self.path.find_or_declare(target) 119 enums_task.set_outputs(tgt_node) 120 enums_task.env.GLIB_MKENUMS_TARGET=tgt_node.abspath() 121 enums_tgt_node=[tgt_node] 122 install_files.append(tgt_node) 123 options='--comments "<!-- @comment@ -->" --fhead "<schemalist>" --vhead " <@type@ id=\\"%s.@EnumName@\\">" --vprod " <value nick=\\"@valuenick@\\" value=\\"@valuenum@\\"/>" --vtail " </@type@>" --ftail "</schemalist>" '%(self.settings_enum_namespace) 124 enums_task.env.GLIB_MKENUMS_OPTIONS=options 125 for schema in settings_schema_files: 126 schema_task=self.create_task('glib_validate_schema') 127 schema_node=self.path.find_resource(schema) 128 if not schema_node: 129 raise Errors.WafError("Cannot find the schema file %r"%schema) 130 install_files.append(schema_node) 131 source_list=enums_tgt_node+[schema_node] 132 schema_task.set_inputs(source_list) 133 schema_task.env.GLIB_COMPILE_SCHEMAS_OPTIONS=[("--schema-file="+k.abspath())for k in source_list] 134 target_node=schema_node.change_ext('.xml.valid') 135 schema_task.set_outputs(target_node) 136 schema_task.env.GLIB_VALIDATE_SCHEMA_OUTPUT=target_node.abspath() 137 def compile_schemas_callback(bld): 138 if not bld.is_install: 139 return 140 compile_schemas=Utils.to_list(bld.env.GLIB_COMPILE_SCHEMAS) 141 destdir=Options.options.destdir 142 paths=bld._compile_schemas_registered 143 if destdir: 144 paths=(os.path.join(destdir,path.lstrip(os.sep))for path in paths) 145 for path in paths: 146 Logs.pprint('YELLOW','Updating GSettings schema cache %r'%path) 147 if self.bld.exec_command(compile_schemas+[path]): 148 Logs.warn('Could not update GSettings schema cache %r'%path) 149 if self.bld.is_install: 150 schemadir=self.env.GSETTINGSSCHEMADIR 151 if not schemadir: 152 raise Errors.WafError('GSETTINGSSCHEMADIR not defined (should have been set up automatically during configure)') 153 if install_files: 154 self.add_install_files(install_to=schemadir,install_from=install_files) 155 registered_schemas=getattr(self.bld,'_compile_schemas_registered',None) 156 if not registered_schemas: 157 registered_schemas=self.bld._compile_schemas_registered=set() 158 self.bld.add_post_fun(compile_schemas_callback) 159 registered_schemas.add(schemadir) 160class glib_validate_schema(Task.Task): 161 run_str='rm -f ${GLIB_VALIDATE_SCHEMA_OUTPUT} && ${GLIB_COMPILE_SCHEMAS} --dry-run ${GLIB_COMPILE_SCHEMAS_OPTIONS} && touch ${GLIB_VALIDATE_SCHEMA_OUTPUT}' 162 color='PINK' 163@extension('.gresource.xml') 164def process_gresource_source(self,node): 165 if not self.env.GLIB_COMPILE_RESOURCES: 166 raise Errors.WafError("Unable to process GResource file - glib-compile-resources was not found during configure") 167 if'gresource'in self.features: 168 return 169 h_node=node.change_ext('_xml.h') 170 c_node=node.change_ext('_xml.c') 171 self.create_task('glib_gresource_source',node,[h_node,c_node]) 172 self.source.append(c_node) 173@feature('gresource') 174def process_gresource_bundle(self): 175 for i in self.to_list(self.source): 176 node=self.path.find_resource(i) 177 task=self.create_task('glib_gresource_bundle',node,node.change_ext('')) 178 inst_to=getattr(self,'install_path',None) 179 if inst_to: 180 self.add_install_files(install_to=inst_to,install_from=task.outputs) 181class glib_gresource_base(Task.Task): 182 color='BLUE' 183 base_cmd='${GLIB_COMPILE_RESOURCES} --sourcedir=${SRC[0].parent.srcpath()} --sourcedir=${SRC[0].bld_dir()}' 184 def scan(self): 185 bld=self.generator.bld 186 kw={} 187 kw['cwd']=self.get_cwd() 188 kw['quiet']=Context.BOTH 189 cmd=Utils.subst_vars('${GLIB_COMPILE_RESOURCES} --sourcedir=%s --sourcedir=%s --generate-dependencies %s'%(self.inputs[0].parent.srcpath(),self.inputs[0].bld_dir(),self.inputs[0].bldpath()),self.env) 190 output=bld.cmd_and_log(cmd,**kw) 191 nodes=[] 192 names=[] 193 for dep in output.splitlines(): 194 if dep: 195 node=bld.bldnode.find_node(dep) 196 if node: 197 nodes.append(node) 198 else: 199 names.append(dep) 200 return(nodes,names) 201class glib_gresource_source(glib_gresource_base): 202 vars=['GLIB_COMPILE_RESOURCES'] 203 fun_h=Task.compile_fun_shell(glib_gresource_base.base_cmd+' --target=${TGT[0].abspath()} --generate-header ${SRC}') 204 fun_c=Task.compile_fun_shell(glib_gresource_base.base_cmd+' --target=${TGT[1].abspath()} --generate-source ${SRC}') 205 ext_out=['.h'] 206 def run(self): 207 return self.fun_h[0](self)or self.fun_c[0](self) 208class glib_gresource_bundle(glib_gresource_base): 209 run_str=glib_gresource_base.base_cmd+' --target=${TGT} ${SRC}' 210 shell=True 211@conf 212def find_glib_genmarshal(conf): 213 conf.find_program('glib-genmarshal',var='GLIB_GENMARSHAL') 214@conf 215def find_glib_mkenums(conf): 216 if not conf.env.PERL: 217 conf.find_program('perl',var='PERL') 218 conf.find_program('glib-mkenums',interpreter='PERL',var='GLIB_MKENUMS') 219@conf 220def find_glib_compile_schemas(conf): 221 conf.find_program('glib-compile-schemas',var='GLIB_COMPILE_SCHEMAS') 222 def getstr(varname): 223 return getattr(Options.options,varname,getattr(conf.env,varname,'')) 224 gsettingsschemadir=getstr('GSETTINGSSCHEMADIR') 225 if not gsettingsschemadir: 226 datadir=getstr('DATADIR') 227 if not datadir: 228 prefix=conf.env.PREFIX 229 datadir=os.path.join(prefix,'share') 230 gsettingsschemadir=os.path.join(datadir,'glib-2.0','schemas') 231 conf.env.GSETTINGSSCHEMADIR=gsettingsschemadir 232@conf 233def find_glib_compile_resources(conf): 234 conf.find_program('glib-compile-resources',var='GLIB_COMPILE_RESOURCES') 235def configure(conf): 236 conf.find_glib_genmarshal() 237 conf.find_glib_mkenums() 238 conf.find_glib_compile_schemas(mandatory=False) 239 conf.find_glib_compile_resources(mandatory=False) 240def options(opt): 241 gr=opt.add_option_group('Installation directories') 242 gr.add_option('--gsettingsschemadir',help='GSettings schema location [DATADIR/glib-2.0/schemas]',default='',dest='GSETTINGSSCHEMADIR') 243