src/aubiopitch~.c: refix aubiopitch_tilde_del
[pd-aubio.git] / waflib / Options.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,tempfile,optparse,sys,re
6 from waflib import Logs,Utils,Context
7 cmds='distclean configure build install clean uninstall check dist distcheck'.split()
8 options={}
9 commands=[]
10 lockfile=os.environ.get('WAFLOCK','.lock-waf_%s_build'%sys.platform)
11 try:cache_global=os.path.abspath(os.environ['WAFCACHE'])
12 except KeyError:cache_global=''
13 platform=Utils.unversioned_sys_platform()
14 class opt_parser(optparse.OptionParser):
15         def __init__(self,ctx):
16                 optparse.OptionParser.__init__(self,conflict_handler="resolve",version='waf %s (%s)'%(Context.WAFVERSION,Context.WAFREVISION))
17                 self.formatter.width=Logs.get_term_cols()
18                 p=self.add_option
19                 self.ctx=ctx
20                 jobs=ctx.jobs()
21                 p('-j','--jobs',dest='jobs',default=jobs,type='int',help='amount of parallel jobs (%r)'%jobs)
22                 p('-k','--keep',dest='keep',default=0,action='count',help='keep running happily even if errors are found')
23                 p('-v','--verbose',dest='verbose',default=0,action='count',help='verbosity level -v -vv or -vvv [default: 0]')
24                 p('--nocache',dest='nocache',default=False,action='store_true',help='ignore the WAFCACHE (if set)')
25                 p('--zones',dest='zones',default='',action='store',help='debugging zones (task_gen, deps, tasks, etc)')
26                 gr=optparse.OptionGroup(self,'configure options')
27                 self.add_option_group(gr)
28                 gr.add_option('-o','--out',action='store',default='',help='build dir for the project',dest='out')
29                 gr.add_option('-t','--top',action='store',default='',help='src dir for the project',dest='top')
30                 default_prefix=os.environ.get('PREFIX')
31                 if not default_prefix:
32                         if platform=='win32':
33                                 d=tempfile.gettempdir()
34                                 default_prefix=d[0].upper()+d[1:]
35                         else:
36                                 default_prefix='/usr/local/'
37                 gr.add_option('--prefix',dest='prefix',default=default_prefix,help='installation prefix [default: %r]'%default_prefix)
38                 gr.add_option('--download',dest='download',default=False,action='store_true',help='try to download the tools if missing')
39                 gr=optparse.OptionGroup(self,'build and install options')
40                 self.add_option_group(gr)
41                 gr.add_option('-p','--progress',dest='progress_bar',default=0,action='count',help='-p: progress bar; -pp: ide output')
42                 gr.add_option('--targets',dest='targets',default='',action='store',help='task generators, e.g. "target1,target2"')
43                 gr=optparse.OptionGroup(self,'step options')
44                 self.add_option_group(gr)
45                 gr.add_option('--files',dest='files',default='',action='store',help='files to process, by regexp, e.g. "*/main.c,*/test/main.o"')
46                 default_destdir=os.environ.get('DESTDIR','')
47                 gr=optparse.OptionGroup(self,'install/uninstall options')
48                 self.add_option_group(gr)
49                 gr.add_option('--destdir',help='installation root [default: %r]'%default_destdir,default=default_destdir,dest='destdir')
50                 gr.add_option('-f','--force',dest='force',default=False,action='store_true',help='force file installation')
51                 gr.add_option('--distcheck-args',help='arguments to pass to distcheck',default=None,action='store')
52         def get_usage(self):
53                 cmds_str={}
54                 for cls in Context.classes:
55                         if not cls.cmd or cls.cmd=='options':
56                                 continue
57                         s=cls.__doc__ or''
58                         cmds_str[cls.cmd]=s
59                 if Context.g_module:
60                         for(k,v)in Context.g_module.__dict__.items():
61                                 if k in['options','init','shutdown']:
62                                         continue
63                                 if type(v)is type(Context.create_context):
64                                         if v.__doc__ and not k.startswith('_'):
65                                                 cmds_str[k]=v.__doc__
66                 just=0
67                 for k in cmds_str:
68                         just=max(just,len(k))
69                 lst=['  %s: %s'%(k.ljust(just),v)for(k,v)in cmds_str.items()]
70                 lst.sort()
71                 ret='\n'.join(lst)
72                 return'''waf [commands] [options]
73
74 Main commands (example: ./waf build -j4)
75 %s
76 '''%ret
77 class OptionsContext(Context.Context):
78         cmd='options'
79         fun='options'
80         def __init__(self,**kw):
81                 super(OptionsContext,self).__init__(**kw)
82                 self.parser=opt_parser(self)
83                 self.option_groups={}
84         def jobs(self):
85                 count=int(os.environ.get('JOBS',0))
86                 if count<1:
87                         if'NUMBER_OF_PROCESSORS'in os.environ:
88                                 count=int(os.environ.get('NUMBER_OF_PROCESSORS',1))
89                         else:
90                                 if hasattr(os,'sysconf_names'):
91                                         if'SC_NPROCESSORS_ONLN'in os.sysconf_names:
92                                                 count=int(os.sysconf('SC_NPROCESSORS_ONLN'))
93                                         elif'SC_NPROCESSORS_CONF'in os.sysconf_names:
94                                                 count=int(os.sysconf('SC_NPROCESSORS_CONF'))
95                                 if not count and os.name not in('nt','java'):
96                                         try:
97                                                 tmp=self.cmd_and_log(['sysctl','-n','hw.ncpu'],quiet=0)
98                                         except Exception:
99                                                 pass
100                                         else:
101                                                 if re.match('^[0-9]+$',tmp):
102                                                         count=int(tmp)
103                 if count<1:
104                         count=1
105                 elif count>1024:
106                         count=1024
107                 return count
108         def add_option(self,*k,**kw):
109                 return self.parser.add_option(*k,**kw)
110         def add_option_group(self,*k,**kw):
111                 try:
112                         gr=self.option_groups[k[0]]
113                 except KeyError:
114                         gr=self.parser.add_option_group(*k,**kw)
115                 self.option_groups[k[0]]=gr
116                 return gr
117         def get_option_group(self,opt_str):
118                 try:
119                         return self.option_groups[opt_str]
120                 except KeyError:
121                         for group in self.parser.option_groups:
122                                 if group.title==opt_str:
123                                         return group
124                         return None
125         def parse_args(self,_args=None):
126                 global options,commands
127                 (options,leftover_args)=self.parser.parse_args(args=_args)
128                 commands=leftover_args
129                 if options.destdir:
130                         options.destdir=os.path.abspath(os.path.expanduser(options.destdir))
131                 if options.verbose>=1:
132                         self.load('errcheck')
133         def execute(self):
134                 super(OptionsContext,self).execute()
135                 self.parse_args()