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