src/aubiopitch~.c: refix aubiopitch_tilde_del
[pd-aubio.git] / waflib / Configure.py
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,shlex,sys,time
6 from waflib import ConfigSet,Utils,Options,Logs,Context,Build,Errors
7 try:
8         from urllib import request
9 except ImportError:
10         from urllib import urlopen
11 else:
12         urlopen=request.urlopen
13 BREAK='break'
14 CONTINUE='continue'
15 WAF_CONFIG_LOG='config.log'
16 autoconfig=False
17 conf_template='''# project %(app)s configured on %(now)s by
18 # waf %(wafver)s (abi %(abi)s, python %(pyver)x on %(systype)s)
19 # using %(args)s
20 #'''
21 def download_check(node):
22         pass
23 def download_tool(tool,force=False,ctx=None):
24         for x in Utils.to_list(Context.remote_repo):
25                 for sub in Utils.to_list(Context.remote_locs):
26                         url='/'.join((x,sub,tool+'.py'))
27                         try:
28                                 web=urlopen(url)
29                                 try:
30                                         if web.getcode()!=200:
31                                                 continue
32                                 except AttributeError:
33                                         pass
34                         except Exception:
35                                 continue
36                         else:
37                                 tmp=ctx.root.make_node(os.sep.join((Context.waf_dir,'waflib','extras',tool+'.py')))
38                                 tmp.write(web.read(),'wb')
39                                 Logs.warn('Downloaded %s from %s'%(tool,url))
40                                 download_check(tmp)
41                                 try:
42                                         module=Context.load_tool(tool)
43                                 except Exception:
44                                         Logs.warn('The tool %s from %s is unusable'%(tool,url))
45                                         try:
46                                                 tmp.delete()
47                                         except Exception:
48                                                 pass
49                                         continue
50                                 return module
51         raise Errors.WafError('Could not load the Waf tool')
52 class ConfigurationContext(Context.Context):
53         '''configures the project'''
54         cmd='configure'
55         error_handlers=[]
56         def __init__(self,**kw):
57                 super(ConfigurationContext,self).__init__(**kw)
58                 self.environ=dict(os.environ)
59                 self.all_envs={}
60                 self.top_dir=None
61                 self.out_dir=None
62                 self.tools=[]
63                 self.hash=0
64                 self.files=[]
65                 self.tool_cache=[]
66                 self.setenv('')
67         def setenv(self,name,env=None):
68                 if name not in self.all_envs or env:
69                         if not env:
70                                 env=ConfigSet.ConfigSet()
71                                 self.prepare_env(env)
72                         else:
73                                 env=env.derive()
74                         self.all_envs[name]=env
75                 self.variant=name
76         def get_env(self):
77                 return self.all_envs[self.variant]
78         def set_env(self,val):
79                 self.all_envs[self.variant]=val
80         env=property(get_env,set_env)
81         def init_dirs(self):
82                 top=self.top_dir
83                 if not top:
84                         top=Options.options.top
85                 if not top:
86                         top=getattr(Context.g_module,Context.TOP,None)
87                 if not top:
88                         top=self.path.abspath()
89                 top=os.path.abspath(top)
90                 self.srcnode=(os.path.isabs(top)and self.root or self.path).find_dir(top)
91                 assert(self.srcnode)
92                 out=self.out_dir
93                 if not out:
94                         out=Options.options.out
95                 if not out:
96                         out=getattr(Context.g_module,Context.OUT,None)
97                 if not out:
98                         out=Options.lockfile.replace('.lock-waf_%s_'%sys.platform,'').replace('.lock-waf','')
99                 self.bldnode=(os.path.isabs(out)and self.root or self.path).make_node(out)
100                 self.bldnode.mkdir()
101                 if not os.path.isdir(self.bldnode.abspath()):
102                         conf.fatal('Could not create the build directory %s'%self.bldnode.abspath())
103         def execute(self):
104                 self.init_dirs()
105                 self.cachedir=self.bldnode.make_node(Build.CACHE_DIR)
106                 self.cachedir.mkdir()
107                 path=os.path.join(self.bldnode.abspath(),WAF_CONFIG_LOG)
108                 self.logger=Logs.make_logger(path,'cfg')
109                 app=getattr(Context.g_module,'APPNAME','')
110                 if app:
111                         ver=getattr(Context.g_module,'VERSION','')
112                         if ver:
113                                 app="%s (%s)"%(app,ver)
114                 now=time.ctime()
115                 pyver=sys.hexversion
116                 systype=sys.platform
117                 args=" ".join(sys.argv)
118                 wafver=Context.WAFVERSION
119                 abi=Context.ABI
120                 self.to_log(conf_template%vars())
121                 self.msg('Setting top to',self.srcnode.abspath())
122                 self.msg('Setting out to',self.bldnode.abspath())
123                 if id(self.srcnode)==id(self.bldnode):
124                         Logs.warn('Setting top == out (remember to use "update_outputs")')
125                 elif id(self.path)!=id(self.srcnode):
126                         if self.srcnode.is_child_of(self.path):
127                                 Logs.warn('Are you certain that you do not want to set top="." ?')
128                 super(ConfigurationContext,self).execute()
129                 self.store()
130                 Context.top_dir=self.srcnode.abspath()
131                 Context.out_dir=self.bldnode.abspath()
132                 env=ConfigSet.ConfigSet()
133                 env['argv']=sys.argv
134                 env['options']=Options.options.__dict__
135                 env.run_dir=Context.run_dir
136                 env.top_dir=Context.top_dir
137                 env.out_dir=Context.out_dir
138                 env['hash']=self.hash
139                 env['files']=self.files
140                 env['environ']=dict(self.environ)
141                 if not self.env.NO_LOCK_IN_RUN:
142                         env.store(Context.run_dir+os.sep+Options.lockfile)
143                 if not self.env.NO_LOCK_IN_TOP:
144                         env.store(Context.top_dir+os.sep+Options.lockfile)
145                 if not self.env.NO_LOCK_IN_OUT:
146                         env.store(Context.out_dir+os.sep+Options.lockfile)
147         def prepare_env(self,env):
148                 if not env.PREFIX:
149                         if Options.options.prefix or Utils.is_win32:
150                                 env.PREFIX=os.path.abspath(os.path.expanduser(Options.options.prefix))
151                         else:
152                                 env.PREFIX=''
153                 if not env.BINDIR:
154                         env.BINDIR=Utils.subst_vars('${PREFIX}/bin',env)
155                 if not env.LIBDIR:
156                         env.LIBDIR=Utils.subst_vars('${PREFIX}/lib',env)
157         def store(self):
158                 n=self.cachedir.make_node('build.config.py')
159                 n.write('version = 0x%x\ntools = %r\n'%(Context.HEXVERSION,self.tools))
160                 if not self.all_envs:
161                         self.fatal('nothing to store in the configuration context!')
162                 for key in self.all_envs:
163                         tmpenv=self.all_envs[key]
164                         tmpenv.store(os.path.join(self.cachedir.abspath(),key+Build.CACHE_SUFFIX))
165         def load(self,input,tooldir=None,funs=None,download=True):
166                 tools=Utils.to_list(input)
167                 if tooldir:tooldir=Utils.to_list(tooldir)
168                 for tool in tools:
169                         mag=(tool,id(self.env),funs)
170                         if mag in self.tool_cache:
171                                 self.to_log('(tool %s is already loaded, skipping)'%tool)
172                                 continue
173                         self.tool_cache.append(mag)
174                         module=None
175                         try:
176                                 module=Context.load_tool(tool,tooldir)
177                         except ImportError ,e:
178                                 if Options.options.download:
179                                         module=download_tool(tool,ctx=self)
180                                         if not module:
181                                                 self.fatal('Could not load the Waf tool %r or download a suitable replacement from the repository (sys.path %r)\n%s'%(tool,sys.path,e))
182                                 else:
183                                         self.fatal('Could not load the Waf tool %r from %r (try the --download option?):\n%s'%(tool,sys.path,e))
184                         except Exception ,e:
185                                 self.to_log('imp %r (%r & %r)'%(tool,tooldir,funs))
186                                 self.to_log(Utils.ex_stack())
187                                 raise
188                         if funs is not None:
189                                 self.eval_rules(funs)
190                         else:
191                                 func=getattr(module,'configure',None)
192                                 if func:
193                                         if type(func)is type(Utils.readf):func(self)
194                                         else:self.eval_rules(func)
195                         self.tools.append({'tool':tool,'tooldir':tooldir,'funs':funs})
196         def post_recurse(self,node):
197                 super(ConfigurationContext,self).post_recurse(node)
198                 self.hash=hash((self.hash,node.read('rb')))
199                 self.files.append(node.abspath())
200         def eval_rules(self,rules):
201                 self.rules=Utils.to_list(rules)
202                 for x in self.rules:
203                         f=getattr(self,x)
204                         if not f:self.fatal("No such method '%s'."%x)
205                         try:
206                                 f()
207                         except Exception ,e:
208                                 ret=self.err_handler(x,e)
209                                 if ret==BREAK:
210                                         break
211                                 elif ret==CONTINUE:
212                                         continue
213                                 else:
214                                         raise
215         def err_handler(self,fun,error):
216                 pass
217 def conf(f):
218         def fun(*k,**kw):
219                 mandatory=True
220                 if'mandatory'in kw:
221                         mandatory=kw['mandatory']
222                         del kw['mandatory']
223                 try:
224                         return f(*k,**kw)
225                 except Errors.ConfigurationError:
226                         if mandatory:
227                                 raise
228         setattr(ConfigurationContext,f.__name__,fun)
229         setattr(Build.BuildContext,f.__name__,fun)
230         return f
231 @conf
232 def add_os_flags(self,var,dest=None):
233         try:self.env.append_value(dest or var,shlex.split(self.environ[var]))
234         except KeyError:pass
235 @conf
236 def cmd_to_list(self,cmd):
237         if isinstance(cmd,str)and cmd.find(' '):
238                 try:
239                         os.stat(cmd)
240                 except OSError:
241                         return shlex.split(cmd)
242                 else:
243                         return[cmd]
244         return cmd
245 @conf
246 def check_waf_version(self,mini='1.6.99',maxi='1.8.0'):
247         self.start_msg('Checking for waf version in %s-%s'%(str(mini),str(maxi)))
248         ver=Context.HEXVERSION
249         if Utils.num2ver(mini)>ver:
250                 self.fatal('waf version should be at least %r (%r found)'%(Utils.num2ver(mini),ver))
251         if Utils.num2ver(maxi)<ver:
252                 self.fatal('waf version should be at most %r (%r found)'%(Utils.num2ver(maxi),ver))
253         self.end_msg('ok')
254 @conf
255 def find_file(self,filename,path_list=[]):
256         for n in Utils.to_list(filename):
257                 for d in Utils.to_list(path_list):
258                         p=os.path.join(d,n)
259                         if os.path.exists(p):
260                                 return p
261         self.fatal('Could not find %r'%filename)
262 @conf
263 def find_program(self,filename,**kw):
264         exts=kw.get('exts',Utils.is_win32 and'.exe,.com,.bat,.cmd'or',.sh,.pl,.py')
265         environ=kw.get('environ',os.environ)
266         ret=''
267         filename=Utils.to_list(filename)
268         var=kw.get('var','')
269         if not var:
270                 var=filename[0].upper()
271         if self.env[var]:
272                 ret=self.env[var]
273         elif var in environ:
274                 ret=environ[var]
275         path_list=kw.get('path_list','')
276         if not ret:
277                 if path_list:
278                         path_list=Utils.to_list(path_list)
279                 else:
280                         path_list=environ.get('PATH','').split(os.pathsep)
281                 if not isinstance(filename,list):
282                         filename=[filename]
283                 for a in exts.split(','):
284                         if ret:
285                                 break
286                         for b in filename:
287                                 if ret:
288                                         break
289                                 for c in path_list:
290                                         if ret:
291                                                 break
292                                         x=os.path.expanduser(os.path.join(c,b+a))
293                                         if os.path.isfile(x):
294                                                 ret=x
295         if not ret and Utils.winreg:
296                 ret=Utils.get_registry_app_path(Utils.winreg.HKEY_CURRENT_USER,filename)
297         if not ret and Utils.winreg:
298                 ret=Utils.get_registry_app_path(Utils.winreg.HKEY_LOCAL_MACHINE,filename)
299         self.msg('Checking for program '+','.join(filename),ret or False)
300         self.to_log('find program=%r paths=%r var=%r -> %r'%(filename,path_list,var,ret))
301         if not ret:
302                 self.fatal(kw.get('errmsg','')or'Could not find the program %s'%','.join(filename))
303         if var:
304                 self.env[var]=ret
305         return ret
306 @conf
307 def find_perl_program(self,filename,path_list=[],var=None,environ=None,exts=''):
308         try:
309                 app=self.find_program(filename,path_list=path_list,var=var,environ=environ,exts=exts)
310         except Exception:
311                 self.find_program('perl',var='PERL')
312                 app=self.find_file(filename,os.environ['PATH'].split(os.pathsep))
313                 if not app:
314                         raise
315                 if var:
316                         self.env[var]=Utils.to_list(self.env['PERL'])+[app]
317         self.msg('Checking for %r'%filename,app)