1 ###############################################################################
3 ## This script is coded for minimum version of Python 2.4 .
4 ## Pyhthon3 is incompatible.
8 ###############################################################################
19 from optparse import OptionGroup
20 from optparse import OptionGroup
21 from optparse import OptionParser
22 from sys import stderr
23 from sys import stdout
25 class AbortError( Exception ):
26 def __init__( self, format, *args ):
27 self.value = format % args
31 ###############################################################################
33 ## Main configure object.
35 ## dir = containing this configure script
36 ## cwd = current working dir at time of script launch
38 class Configure( object ):
43 def __init__( self, verbose ):
45 self._log_verbose = []
48 self.verbose = verbose
49 self.dir = os.path.dirname( sys.argv[0] )
50 self.cwd = os.getcwd()
54 ## compute src dir which is 2 dirs up from this script
55 self.src_dir = os.path.normpath( sys.argv[0] )
57 self.src_dir = os.path.dirname( self.src_dir )
58 if len( self.src_dir ) == 0:
59 self.src_dir = os.curdir
61 def _final_dir( self, chdir, dir ):
62 dir = os.path.normpath( dir )
63 if not os.path.isabs( dir ):
64 if os.path.isabs( chdir ):
65 dir = os.path.normpath( os.path.abspath(dir ))
67 dir = os.path.normpath( self.relpath( dir, chdir ))
71 def errln( self, format, *args ):
73 if re.match( '^.*[!?:;.]$', s ):
74 stderr.write( 'ERROR: %s configure stop.\n' % (s) )
76 stderr.write( 'ERROR: %s; configure stop.\n' % (s) )
79 def infof( self, format, *args ):
81 self._log_verbose.append( line )
82 if cfg.verbose >= Configure.OUT_INFO:
83 self._log_info.append( line )
85 def verbosef( self, format, *args ):
87 self._log_verbose.append( line )
88 if cfg.verbose >= Configure.OUT_VERBOSE:
91 ## doc is ready to be populated
92 def doc_ready( self ):
93 ## compute final paths as they are after chdir into build
94 self.build_final = os.curdir
95 self.src_final = self._final_dir( self.build_dir, self.src_dir )
96 self.prefix_final = self._final_dir( self.build_dir, self.prefix_dir )
98 cfg.infof( 'compute: makevar SRC/ = %s\n', self.src_final )
99 cfg.infof( 'compute: makevar BUILD/ = %s\n', self.build_final )
100 cfg.infof( 'compute: makevar PREFIX/ = %s\n', self.prefix_final )
102 ## xcode does a chdir so we need appropriate values
103 macosx = os.path.join( self.src_dir, 'macosx' )
104 self.xcode_x_src = self._final_dir( macosx, self.src_dir )
105 self.xcode_x_build = self._final_dir( macosx, self.build_dir )
106 self.xcode_x_prefix = self._final_dir( macosx, self.prefix_dir )
108 ## perform chdir and enable log recording
110 if os.path.abspath( self.build_dir ) == os.path.abspath( self.src_dir ):
111 cfg.errln( 'build (scratch) directory must not be the same as top-level source root!' )
113 if self.build_dir != os.curdir:
114 if os.path.exists( self.build_dir ):
115 if not options.force:
116 self.errln( 'build directory already exists: %s (use --force to overwrite)', self.build_dir )
118 self.mkdirs( self.build_dir )
119 self.infof( 'chdir: %s\n', self.build_dir )
120 os.chdir( self.build_dir )
125 def mkdirs( self, dir ):
126 if len(dir) and not os.path.exists( dir ):
127 self.infof( 'mkdir: %s\n', dir )
130 def open( self, *args ):
131 dir = os.path.dirname( args[0] )
132 if len(args) > 1 and args[1].find('w') != -1:
134 m = re.match( '^(.*)\.tmp$', args[0] )
136 self.infof( 'write: %s\n', m.group(1) )
138 self.infof( 'write: %s\n', args[0] )
143 cfg.errln( 'open failure: %s', x )
145 def record_log( self ):
149 self.verbose = Configure.OUT_QUIET
150 file = cfg.open( 'log/config.info.txt', 'w' )
151 for line in self._log_info:
154 file = cfg.open( 'log/config.verbose.txt', 'w' )
155 for line in self._log_verbose:
159 ## Find executable by searching path.
160 ## On success, returns full pathname of executable.
161 ## On fail, returns None.
162 def findExecutable( self, name ):
163 if len( os.path.split(name)[0] ):
164 if os.access( name, os.X_OK ):
168 if not os.environ.has_key( 'PATH' ) or os.environ[ 'PATH' ] == '':
171 path = os.environ['PATH']
173 for dir in path.split( os.pathsep ):
174 f = os.path.join( dir, name )
175 if os.access( f, os.X_OK ):
179 ## taken from python2.6 -- we need it
180 def relpath( self, path, start=os.curdir ):
181 """Return a relative version of a path"""
184 raise ValueError("no path specified")
186 start_list = os.path.abspath(start).split(os.sep)
187 path_list = os.path.abspath(path).split(os.sep)
189 # Work out how much of the filepath is shared by start and path.
190 i = len(os.path.commonprefix([start_list, path_list]))
192 rel_list = [os.pardir] * (len(start_list)-i) + path_list[i:]
195 return os.path.join(*rel_list)
197 ## update with parsed cli options
198 def update_cli( self, options ):
199 self.src_dir = os.path.normpath( options.src )
200 self.build_dir = os.path.normpath( options.build )
201 self.prefix_dir = os.path.normpath( options.prefix )
203 ## special case if src == build: add build subdir
204 if os.path.abspath( self.src_dir ) == os.path.abspath( self.build_dir ):
205 self.build_dir = os.path.join( self.build_dir, 'build' )
207 ###############################################################################
211 ## pretext = text which immediately follows 'probe:' output prefix
212 ## abort = if true configure will exit on probe fail
213 ## head = if true probe session is stripped of all but first line
214 ## session = output from command, including stderr
215 ## fail = true if probe failed
217 class Action( object ):
220 def __init__( self, category, pretext='unknown', abort=False, head=False ):
221 if self not in Action.actions:
222 Action.actions.append( self )
224 self.category = category
225 self.pretext = pretext
230 self.run_done = False
232 self.msg_fail = 'fail'
233 self.msg_pass = 'pass'
236 def _actionBegin( self ):
237 cfg.infof( '%s: %s...', self.category, self.pretext )
239 def _actionEnd( self ):
241 cfg.infof( '(%s) %s\n', self.msg_fail, self.msg_end )
243 self._dumpSession( cfg.infof )
244 cfg.errln( 'unable to continue' )
245 self._dumpSession( cfg.verbosef )
247 cfg.infof( '(%s) %s\n', self.msg_pass, self.msg_end )
248 self._dumpSession( cfg.verbosef )
250 def _dumpSession( self, printf ):
251 if self.session and len(self.session):
252 for line in self.session:
253 printf( ' : %s\n', line )
255 printf( ' : <NO-OUTPUT>\n' )
257 def _parseSession( self ):
270 ###############################################################################
272 ## base probe: anything which runs in shell.
274 ## pretext = text which immediately follows 'probe:' output prefix
275 ## command = full command and arguments to pipe
276 ## abort = if true configure will exit on probe fail
277 ## head = if true probe session is stripped of all but first line
278 ## session = output from command, including stderr
279 ## fail = true if probe failed
281 class ShellProbe( Action ):
282 def __init__( self, pretext, command, abort=False, head=False ):
283 super( ShellProbe, self ).__init__( 'probe', pretext, abort, head )
284 self.command = command
287 ## pipe and redirect stderr to stdout; effects communicate result
288 pipe = subprocess.Popen( self.command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
290 ## read data into memory buffers, only first element (stdout) data is used
291 data = pipe.communicate()
292 self.fail = pipe.returncode != 0
295 self.session = data[0].splitlines()
300 self.msg_end = 'code %d' % (pipe.returncode)
302 def _dumpSession( self, printf ):
303 printf( ' + %s\n', self.command )
304 super( ShellProbe, self )._dumpSession( printf )
306 ###############################################################################
308 ## GNU host tuple probe: determine canonical platform type
310 ## example results from various platforms:
312 ## i386-apple-darwin9.6.0 (Mac OS X 10.5.6 Intel)
313 ## powerpc-apple-darwin9.6.0 (Mac OS X 10.5.6 PPC)
314 ## i686-pc-cygwin (Cygwin, Microsoft Vista)
315 ## x86_64-unknown-linux-gnu (Linux, Fedora 10 x86_64)
317 class HostTupleProbe( ShellProbe, list ):
318 GNU_TUPLE_RX = '([^-]+)-([^-]+)-([^0-9-]+)([^-]*)-?([^-]*)'
320 def __init__( self ):
321 super( HostTupleProbe, self ).__init__( 'host tuple', '%s/config.guess' % (cfg.dir), abort=True, head=True )
323 def _parseSession( self ):
324 if len(self.session):
325 self.spec = self.session[0]
329 ## grok GNU host tuples
330 m = re.match( HostTupleProbe.GNU_TUPLE_RX, self.spec )
333 self.msg_end = 'invalid host tuple: %s' % (self.spec)
336 self.msg_end = self.spec
338 ## assign tuple from regex
342 self.machine = self[0]
343 self.vendor = self[1]
344 self.system = self[2]
345 self.release = self[3]
348 ## nice formal name for 'system'
349 self.systemf = platform.system()
351 if self.match( '*-*-cygwin*' ):
352 self.systemf = self[2][0].upper() + self[2][1:]
354 ## glob-match against spec
355 def match( self, *specs ):
357 if fnmatch.fnmatch( self.spec, spec ):
361 ###############################################################################
363 class BuildAction( Action, list ):
364 def __init__( self ):
365 super( BuildAction, self ).__init__( 'compute', 'build tuple', abort=True )
368 self.spec = arch.mode[arch.mode.mode]
370 ## grok GNU host tuples
371 m = re.match( HostTupleProbe.GNU_TUPLE_RX, self.spec )
373 self.msg_end = 'invalid host tuple: %s' % (self.spec)
376 self.msg_end = self.spec
378 ## assign tuple from regex
382 self.machine = self[0]
383 self.vendor = self[1]
384 self.system = self[2]
385 self.release = self[3]
387 self.systemf = host.systemf
391 ## glob-match against spec
392 def match( self, *specs ):
394 if fnmatch.fnmatch( self.spec, spec ):
398 ###############################################################################
400 ## value wrapper; value is accepted only if one of host specs matcheds
401 ## otherwise it is None (or a keyword-supplied val)
403 ## result is attribute 'value'
405 class IfHost( object ):
406 def __init__( self, value, *specs, **kwargs ):
407 self.value = kwargs.get('none',None)
409 if host.match( spec ):
413 def __nonzero__( self ):
414 return self.value != None
420 ###############################################################################
422 ## platform conditional value; loops through list of tuples comparing
423 ## to first host match and sets value accordingly; the first value is
426 class ForHost( object ):
427 def __init__( self, default, *tuples ):
430 if host.match( tuple[1] ):
431 self.value = tuple[0]
437 ###############################################################################
439 class ArchAction( Action ):
440 def __init__( self ):
441 super( ArchAction, self ).__init__( 'compute', 'available architectures', abort=True )
442 self.mode = SelectMode( 'architecture', (host.machine,host.spec) )
447 ## some match on system should be made here; otherwise we signal a warning.
448 if host.match( '*-*-cygwin*' ):
450 elif host.match( '*-*-darwin*' ):
451 self.mode['i386'] = 'i386-apple-darwin%s' % (host.release)
452 self.mode['x86_64'] = 'x86_64-apple-darwin%s' % (host.release)
453 self.mode['ppc'] = 'powerpc-apple-darwin%s' % (host.release)
454 self.mode['ppc64'] = 'powerpc64-apple-darwin%s' % (host.release)
456 ## special cases in that powerpc does not match gcc -arch value
457 ## which we like to use; so it has to be removed.
458 ## note: we don't know if apple will release Ssnow Leopad/ppc64 yet; just a guess.
459 if 'powerpc' in self.mode:
460 del self.mode['powerpc']
461 self.mode.mode = 'ppc'
462 elif 'powerpc64' in self.mode:
463 del self.mode['powerpc64']
464 self.mode.mode = 'ppc64'
465 elif host.match( '*-*-linux*' ):
468 self.msg_pass = 'WARNING'
470 self.msg_end = self.mode.toString()
472 ## glob-match against spec
473 def match( self, spec ):
474 return fnmatch.fnmatch( self.spec, spec )
476 ###############################################################################
478 class CoreProbe( Action ):
479 def __init__( self ):
480 super( CoreProbe, self ).__init__( 'probe', 'number of CPU cores' )
485 ## good for darwin9.6.0 and linux
487 self.count = os.sysconf( 'SC_NPROCESSORS_ONLN' )
497 self.count = int( os.environ['NUMBER_OF_PROCESSORS'] )
507 elif self.count > 32:
511 if options.launch_jobs == 0:
512 self.jobs = core.count
514 self.jobs = options.launch_jobs
516 self.jobs = core.count
518 self.msg_end = str(self.count)
520 ###############################################################################
522 class SelectMode( dict ):
523 def __init__( self, descr, *modes, **kwargs ):
524 super( SelectMode, self ).__init__( modes )
527 self.default = kwargs.get('default',modes[0][0])
528 self.mode = self.default
530 def cli_add_option( self, parser, option ):
531 parser.add_option( option, default=self.mode, metavar='MODE',
532 help='select %s mode: %s' % (self.descr,self.toString()),
533 action='callback', callback=self.cli_callback, type='str' )
535 def cli_callback( self, option, opt_str, value, parser, *args, **kwargs ):
536 if value not in self:
537 raise optparse.OptionValueError( 'invalid %s mode: %s (choose from %s)'
538 % (self.descr,value,self.toString( True )) )
541 def toString( self, nodefault=False ):
547 value = ' '.join( keys )
549 value = '%s [%s]' % (' '.join( keys ), self.mode )
552 ###############################################################################
554 ## Repository object.
555 ## Holds information gleaned from subversion working dir.
557 ## Builds are classed into one of the following types:
560 ## must be built from official svn with '/tags/' in the url
562 ## must be built from official svn but is not a release
566 class RepoProbe( ShellProbe ):
567 def __init__( self ):
568 super( RepoProbe, self ).__init__( 'svn info', 'svn info %s' % (cfg.src_dir) )
570 self.url = 'svn://nowhere.com/project/unknown'
571 self.root = 'svn://nowhere.com/project'
572 self.branch = 'unknown'
573 self.uuid = '00000000-0000-0000-0000-000000000000';
575 self.date = '0000-00-00 00:00:00 -0000'
577 self.type = 'unofficial'
579 def _parseSession( self ):
580 for line in self.session:
582 m = re.match( '([^:]+):\\s+(.+)', line )
586 (name,value) = m.groups()
589 elif name == 'Repository Root':
591 elif name == 'Repository UUID':
593 elif name == 'Revision':
594 self.rev = int( value )
595 elif name == 'Last Changed Date':
596 # strip chars in parens
597 if value.find( ' (' ):
598 self.date = value[0:value.find(' (')]
603 i = self.url.rfind( '/' )
604 if i != -1 and i < len(self.url)-1:
605 self.branch = self.url[i+1:]
607 # type-classification via repository UUID
608 if self.uuid == 'b64f7644-9d1e-0410-96f1-a4d463321fa5':
610 m = re.match( '([^:]+)://([^/]+)/(.+)', self.url )
611 if m and re.match( 'tags/', m.group( 3 )):
612 self.type = 'release'
614 self.type = 'developer'
616 self.msg_end = self.url
618 ###############################################################################
622 ## Contains manually updated version numbers consistent with HB releases
623 ## and other project metadata.
625 class Project( Action ):
626 def __init__( self ):
627 super( Project, self ).__init__( 'compute', 'project data' )
629 self.name = 'HandBrake'
630 self.acro_lower = 'hb'
631 self.acro_upper = 'HB'
632 self.url_website = 'http://handbrake.fr'
633 self.url_community = 'http://forum.handbrake.fr'
634 self.url_irc = 'irc://irc.freenode.net/handbrake'
636 self.name_lower = self.name.lower()
637 self.name_upper = self.name.upper()
644 appcastfmt = 'http://handbrake.fr/appcast%s.xml'
646 if repo.type == 'release':
647 self.version = '%d.%d.%d' % (self.vmajor,self.vminor,self.vpoint)
648 self.url_appcast = appcastfmt % ('')
649 self.build = time.strftime('%Y%m%d') + '00'
650 self.title = '%s %s (%s)' % (self.name,self.version,self.build)
651 elif repo.type == 'developer':
652 self.version = 'svn%d' % (repo.rev)
653 self.url_appcast = appcastfmt % ('_unstable')
654 self.build = time.strftime('%Y%m%d') + '01'
655 self.title = '%s svn%d (%s)' % (self.name,repo.rev,self.build)
657 self.version = 'svn%d' % (repo.rev)
658 self.url_appcast = appcastfmt % ('_unofficial')
659 self.build = time.strftime('%Y%m%d') + '99'
660 self.title = 'Unofficial svn%d (%s)' % (repo.rev,self.build)
662 self.msg_end = '%s (%s)' % (self.name,repo.type)
665 ###############################################################################
667 class ToolProbe( Action ):
670 def __init__( self, var, *names, **kwargs ):
671 super( ToolProbe, self ).__init__( 'find', abort=kwargs.get('abort',True) )
672 if not self in ToolProbe.tools:
673 ToolProbe.tools.append( self )
679 self.names.append( str(name) )
680 self.name = self.names[0]
681 self.pretext = self.name
682 self.pathname = self.names[0]
686 for i,name in enumerate(self.names):
687 self.session.append( 'name[%d] = %s' % (i,name) )
688 for name in self.names:
689 f = cfg.findExecutable( name )
696 self.msg_end = 'not found'
698 def cli_add_option( self, parser ):
699 parser.add_option( '--'+self.name, metavar='PROG',
700 help='[%s]' % (self.pathname),
701 action='callback', callback=self.cli_callback, type='str' )
703 def cli_callback( self, option, opt_str, value, parser, *args, **kwargs ):
704 self.__init__( self.var, value, **self.kwargs )
707 def doc_add( self, doc ):
708 doc.add( self.var, self.pathname )
710 ###############################################################################
712 class SelectTool( Action ):
715 def __init__( self, var, name, *pool, **kwargs ):
716 super( SelectTool, self ).__init__( 'select', abort=kwargs.get('abort',True) )
718 if not self in SelectTool.selects:
719 SelectTool.selects.append( self )
727 for i,(name,tool) in enumerate(self.pool):
728 self.session.append( 'tool[%d] = %s (%s)' % (i,name,tool.pathname) )
729 for (name,tool) in self.pool:
733 self.msg_end = '%s (%s)' % (name,tool.pathname)
736 self.msg_end = 'not found'
738 def cli_add_option( self, parser ):
739 parser.add_option( '--'+self.name, metavar='MODE',
740 help='select %s mode: %s' % (self.name,self.toString()),
741 action='callback', callback=self.cli_callback, type='str' )
743 def cli_callback( self, option, opt_str, value, parser, *args, **kwargs ):
745 for (name,tool) in self.pool:
748 self.__init__( self.var, self.name, [name,tool], **kwargs )
752 raise optparse.OptionValueError( 'invalid %s mode: %s (choose from %s)'
753 % (self.name,value,self.toString( True )) )
755 def doc_add( self, doc ):
756 doc.add( self.var, self.selected )
758 def toString( self, nodefault=False ):
759 if len(self.pool) == 1:
760 value = self.pool[0][0]
763 for key,value in self.pool:
768 value = '%s [%s]' % (s[1:], self.selected )
771 ###############################################################################
773 ## config object used to output gnu-make or gnu-m4 output.
775 ## - add() to add NAME/VALUE pairs suitable for both make/m4.
776 ## - addBlank() to add a linefeed for both make/m4.
777 ## - addMake() to add a make-specific line.
778 ## - addM4() to add a m4-specific line.
780 class ConfigDocument:
781 def __init__( self ):
784 def _outputMake( self, file, namelen, name, value, append ):
786 file.write( '%-*s += %s\n' % (namelen, name, value ))
788 file.write( '%-*s = %s\n' % (namelen, name, value ))
790 def _outputM4( self, file, namelen, name, value ):
792 name = '<<__%s>>,' % name.replace( '.', '_' )
793 file.write( 'define(%-*s <<%s>>)dnl\n' % (namelen, name, value ))
795 def add( self, name, value, append=False ):
796 self._elements.append( [name,value,append] )
798 def addBlank( self ):
799 self._elements.append( None )
801 def addComment( self, format, *args ):
802 self.addMake( '## ' + format % args )
803 self.addM4( 'dnl ' + format % args )
805 def addMake( self, line ):
806 self._elements.append( ('?make',line) )
808 def addM4( self, line ):
809 self._elements.append( ('?m4',line) )
811 def output( self, file, type ):
813 for item in self._elements:
814 if item == None or item[0].find( '?' ) == 0:
816 if len(item[0]) > namelen:
817 namelen = len(item[0])
818 for item in self._elements:
821 file.write( 'dnl\n' )
825 if item[0].find( '?' ) == 0:
826 if item[0].find( type, 1 ) == 1:
827 file.write( '%s\n' % (item[1]) )
831 self._outputM4( file, namelen, item[0], item[1] )
833 self._outputMake( file, namelen, item[0], item[1], item[2] )
835 def update( self, name, value ):
836 for item in self._elements:
842 raise ValueError( 'element not found: %s' % (name) )
844 def write( self, type ):
846 fname = 'GNUmakefile'
848 fname = os.path.join( 'project', project.name_lower + '.m4' )
850 raise ValueError, 'unknown file type: ' + type
852 ftmp = fname + '.tmp'
855 file = cfg.open( ftmp, 'w' )
856 self.output( file, type )
867 cfg.errln( 'failed writing to %s\n%s', ftmp, x )
870 os.rename( ftmp, fname )
872 cfg.errln( 'failed writing to %s\n%s', fname, x )
874 ###############################################################################
879 ## class to hook options and create CONF.args list
880 class Option( optparse.Option ):
883 def _conf_record( self, opt, value ):
884 ## skip conf,force,launch
885 if re.match( '^--(conf|force|launch).*$', opt ):
888 ## remove duplicates (last duplicate wins)
889 for i,arg in enumerate( Option.conf_args ):
891 del Option.conf_args[i]
895 Option.conf_args.append( [opt,'%s=%s' % (opt,value)] )
897 Option.conf_args.append( [opt,'%s' % (opt)] )
899 def take_action( self, action, dest, opt, value, values, parser ):
900 self._conf_record( opt, value )
901 return optparse.Option.take_action( self, action, dest, opt, value, values, parser )
904 cli = OptionParser( 'usage: %prog [OPTIONS...] [TARGETS...]' )
905 cli.option_class = Option
908 cli.description += 'Configure %s build system.' % (project.name)
910 ## add hidden options
911 cli.add_option( '--conf-method', default='terminal', action='store', help=optparse.SUPPRESS_HELP )
912 cli.add_option( '--force', default=False, action='store_true', help='overwrite existing build config' )
913 cli.add_option( '--verbose', default=False, action='store_true', help='increase verbosity' )
915 ## add install options
916 grp = OptionGroup( cli, 'Directory Locations' )
917 grp.add_option( '--src', default=cfg.src_dir, action='store', metavar='DIR',
918 help='specify top-level source dir [%s]' % (cfg.src_dir) )
919 grp.add_option( '--build', default=cfg.build_dir, action='store', metavar='DIR',
920 help='specify build scratch/output dir [%s]' % (cfg.build_dir) )
921 grp.add_option( '--prefix', default=cfg.prefix_dir, action='store', metavar='DIR',
922 help='specify install dir for products [%s]' % (cfg.prefix_dir) )
923 cli.add_option_group( grp )
925 ## add feature options
926 grp = OptionGroup( cli, 'Feature Options' )
928 h = IfHost( 'enable assembly code in non-contrib modules', 'NOMATCH*-*-darwin*', 'NOMATCH*-*-linux*', none=optparse.SUPPRESS_HELP ).value
929 grp.add_option( '--enable-asm', default=False, action='store_true', help=h )
931 h = IfHost( 'disable GTK GUI', '*-*-linux*', none=optparse.SUPPRESS_HELP ).value
932 grp.add_option( '--disable-gtk', default=False, action='store_true', help=h )
934 h = IfHost( 'disable Xcode', '*-*-darwin*', none=optparse.SUPPRESS_HELP ).value
935 grp.add_option( '--disable-xcode', default=False, action='store_true', help=h )
937 cli.add_option_group( grp )
939 ## add launch options
940 grp = OptionGroup( cli, 'Launch Options' )
941 grp.add_option( '--launch', default=False, action='store_true',
942 help='launch build, capture log and wait for completion' )
943 grp.add_option( '--launch-jobs', default=1, action='store', metavar='N', type='int',
944 help='allow N jobs at once; 0 to match CPU count [1]' )
945 grp.add_option( '--launch-args', default=None, action='store', metavar='ARGS',
946 help='specify additional ARGS for launch command' )
947 grp.add_option( '--launch-quiet', default=False, action='store_true',
948 help='do not echo build output while waiting' )
949 cli.add_option_group( grp )
951 ## add compile options
952 grp = OptionGroup( cli, 'Compiler Options' )
953 debugMode.cli_add_option( grp, '--debug' )
954 optimizeMode.cli_add_option( grp, '--optimize' )
955 arch.mode.cli_add_option( grp, '--arch' )
956 cli.add_option_group( grp )
958 ## add tool locations
959 grp = OptionGroup( cli, 'Tool Basenames and Locations' )
960 for tool in ToolProbe.tools:
961 tool.cli_add_option( grp )
962 cli.add_option_group( grp )
965 grp = OptionGroup( cli, 'Tool Options' )
966 for select in SelectTool.selects:
967 select.cli_add_option( grp )
968 cli.add_option_group( grp )
971 ###############################################################################
973 ## launcher - used for QuickStart method; launch; build and capture log.
976 def __init__( self, targets ):
978 self._file = cfg.open( 'log/build.txt', 'w' )
980 cmd = '%s -j%d' % (Tools.gmake.pathname,core.jobs)
981 if options.launch_args:
982 cmd += ' ' + options.launch_args
984 cmd += ' ' + ' '.join(targets)
987 timeBegin = time.time()
988 self.infof( 'time begin: %s\n', time.asctime() )
989 self.infof( 'launch: %s\n', cmd )
990 if options.launch_quiet:
991 stdout.write( 'building to %s ...\n' % (os.path.abspath( cfg.build_final )))
993 stdout.write( '%s\n' % ('-' * 79) )
997 pipe = subprocess.Popen( cmd, shell=True, bufsize=1, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
999 cfg.errln( 'launch failure: %s', x )
1000 for line in pipe.stdout:
1001 self.echof( '%s', line )
1005 timeEnd = time.time()
1006 elapsed = timeEnd - timeBegin
1009 result = 'FAILURE (code %d)' % pipe.returncode
1013 ## present duration in decent format
1015 hours = int(seconds / 3600)
1016 seconds -= hours * 3600
1017 minutes = int(seconds / 60)
1018 seconds -= minutes * 60
1024 segs.append( '%d hour' % hours )
1026 segs.append( '%d hours' % hours )
1028 if len(segs) or minutes == 1:
1029 segs.append( '%d minute' % minutes )
1030 elif len(segs) or minutes > 1:
1031 segs.append( '%d minutes' % minutes )
1034 segs.append( '%d second' % seconds )
1036 segs.append( '%d seconds' % seconds )
1038 if not options.launch_quiet:
1039 stdout.write( '%s\n' % ('-' * 79) )
1040 self.infof( 'time end: %s\n', time.asctime() )
1041 self.infof( 'duration: %s (%.2fs)\n', ', '.join(segs), elapsed )
1042 self.infof( 'result: %s\n', result )
1047 def echof( self, format, *args ):
1048 line = format % args
1049 self._file.write( line )
1050 if not options.launch_quiet:
1051 stdout.write( ' : %s' % line )
1054 def infof( self, format, *args ):
1055 line = format % args
1056 self._file.write( line )
1057 cfg.infof( '%s', line )
1059 ###############################################################################
1064 ## we need to pre-check argv for -h or --help or --verbose to deal with
1065 ## initializing Configure correctly.
1066 verbose = Configure.OUT_INFO
1067 for arg in sys.argv:
1068 if arg == '-h' or arg == '--help':
1069 verbose = Configure.OUT_QUIET
1071 if arg == '--verbose':
1072 verbose = Configure.OUT_VERBOSE
1074 ## create main objects; actions/probes run() is delayed.
1075 ## if any actions must be run earlier (eg: for configure --help purposes)
1076 ## then run() must be invoked earlier. subequent run() invocations
1078 cfg = Configure( verbose )
1079 host = HostTupleProbe(); host.run()
1081 cfg.prefix_dir = ForHost( '/usr/local', ['/Applications','*-*-darwin*'] ).value
1083 build = BuildAction()
1084 arch = ArchAction(); arch.run()
1086 ## create remaining main objects
1091 ## create tools in a scope
1093 ar = ToolProbe( 'AR.exe', 'ar' )
1094 cp = ToolProbe( 'CP.exe', 'cp' )
1095 curl = ToolProbe( 'CURL.exe', 'curl', abort=False )
1096 gcc = ToolProbe( 'GCC.gcc', 'gcc', IfHost( 'gcc-4', '*-*-cygwin*' ))
1098 if host.match( '*-*-darwin*' ):
1099 gmake = ToolProbe( 'GMAKE.exe', 'make', 'gmake' )
1101 gmake = ToolProbe( 'GMAKE.exe', 'gmake', 'make' )
1103 m4 = ToolProbe( 'M4.exe', 'm4' )
1104 mkdir = ToolProbe( 'MKDIR.exe', 'mkdir' )
1105 patch = ToolProbe( 'PATCH.exe', 'gpatch', 'patch' )
1106 rm = ToolProbe( 'RM.exe', 'rm' )
1107 tar = ToolProbe( 'TAR.exe', 'gtar', 'tar' )
1108 wget = ToolProbe( 'WGET.exe', 'wget', abort=False )
1109 yasm = ToolProbe( 'YASM.exe', 'yasm', abort=False )
1111 xcodebuild = ToolProbe( 'XCODEBUILD.exe', 'xcodebuild', abort=False )
1112 lipo = ToolProbe( 'LIPO.exe', 'lipo', abort=False )
1114 fetch = SelectTool( 'FETCH.select', 'fetch', ['wget',wget], ['curl',curl] )
1117 for tool in ToolProbe.tools:
1119 for select in SelectTool.selects:
1122 debugMode = SelectMode( 'debug', ('none','none'), ('min','min'), ('std','std'), ('max','max') )
1123 optimizeMode = SelectMode( 'optimize', ('none','none'), ('speed','speed'), ('size','size'), default='speed' )
1125 ## create CLI and parse
1127 (options,args) = cli.parse_args()
1129 ## update cfg with cli directory locations
1130 cfg.update_cli( options )
1132 ## prepare list of targets and NAME=VALUE args to pass to make
1135 rx_exports = re.compile( '([^=]+)=(.*)' )
1137 m = rx_exports.match( arg )
1139 exports.append( m.groups() )
1141 targets.append( arg )
1143 ## run delayed actions
1144 for action in Action.actions:
1147 ## cfg hook before doc prep
1150 ## create document object
1151 doc = ConfigDocument()
1152 doc.addComment( 'generated by configure on %s', time.strftime( '%c' ))
1154 ## add configure line for reconfigure purposes
1157 for arg in Option.conf_args:
1158 args.append( arg[1] )
1159 doc.add( 'CONF.args', ' '.join( args ))
1162 doc.add( 'HB.title', project.title )
1163 doc.add( 'HB.name', project.name )
1164 doc.add( 'HB.name.lower', project.name_lower )
1165 doc.add( 'HB.name.upper', project.name_upper )
1166 doc.add( 'HB.acro.lower', project.acro_lower )
1167 doc.add( 'HB.acro.upper', project.acro_upper )
1169 doc.add( 'HB.url.website', project.url_website )
1170 doc.add( 'HB.url.community', project.url_community )
1171 doc.add( 'HB.url.irc', project.url_irc )
1172 doc.add( 'HB.url.appcast', project.url_appcast )
1174 doc.add( 'HB.version.major', project.vmajor )
1175 doc.add( 'HB.version.minor', project.vminor )
1176 doc.add( 'HB.version.point', project.vpoint )
1177 doc.add( 'HB.version', project.version )
1178 doc.add( 'HB.version.hex', '%04x%02x%02x%08x' % (project.vmajor,project.vminor,project.vpoint,repo.rev) )
1180 doc.add( 'HB.build', project.build )
1182 doc.add( 'HB.repo.url', repo.url )
1183 doc.add( 'HB.repo.root', repo.root )
1184 doc.add( 'HB.repo.branch', repo.branch )
1185 doc.add( 'HB.repo.uuid', repo.uuid )
1186 doc.add( 'HB.repo.rev', repo.rev )
1187 doc.add( 'HB.repo.date', repo.date )
1188 doc.add( 'HB.repo.official', repo.official )
1189 doc.add( 'HB.repo.type', repo.type )
1192 doc.add( 'HOST.spec', host.spec )
1193 doc.add( 'HOST.machine', host.machine )
1194 doc.add( 'HOST.vendor', host.vendor )
1195 doc.add( 'HOST.system', host.system )
1196 doc.add( 'HOST.systemf', host.systemf )
1197 doc.add( 'HOST.release', host.release )
1198 doc.add( 'HOST.extra', host.extra )
1199 doc.add( 'HOST.title', '%s %s' % (host.systemf,arch.mode.default) )
1200 doc.add( 'HOST.ncpu', core.count )
1203 doc.add( 'BUILD.spec', build.spec )
1204 doc.add( 'BUILD.machine', build.machine )
1205 doc.add( 'BUILD.vendor', build.vendor )
1206 doc.add( 'BUILD.system', build.system )
1207 doc.add( 'BUILD.systemf', build.systemf )
1208 doc.add( 'BUILD.release', build.release )
1209 doc.add( 'BUILD.extra', build.extra )
1210 doc.add( 'BUILD.title', '%s %s' % (build.systemf,arch.mode.mode) )
1211 doc.add( 'BUILD.ncpu', core.count )
1212 doc.add( 'BUILD.jobs', core.jobs )
1214 doc.add( 'BUILD.cross', int(arch.mode.mode != arch.mode.default) )
1215 doc.add( 'BUILD.method', 'terminal' )
1216 doc.add( 'BUILD.date', time.strftime('%c') )
1217 doc.add( 'BUILD.arch', arch.mode.mode )
1220 doc.add( 'CONF.method', options.conf_method )
1223 doc.add( 'SRC', cfg.src_final )
1224 doc.add( 'SRC/', cfg.src_final + os.sep )
1225 doc.add( 'BUILD', cfg.build_final )
1226 doc.add( 'BUILD/', cfg.build_final + os.sep )
1227 doc.add( 'PREFIX', cfg.prefix_final )
1228 doc.add( 'PREFIX/', cfg.prefix_final + os.sep )
1231 doc.add( 'FEATURE.asm', 'disabled' )
1232 doc.add( 'FEATURE.gtk', int( not options.disable_gtk ))
1233 doc.add( 'FEATURE.xcode', int( not (Tools.xcodebuild.fail or options.disable_xcode) ))
1235 if not Tools.xcodebuild.fail and not options.disable_xcode:
1237 doc.add( 'XCODE.external.src', cfg.xcode_x_src )
1238 doc.add( 'XCODE.external.build', cfg.xcode_x_build )
1239 doc.add( 'XCODE.external.prefix', cfg.xcode_x_prefix )
1242 doc.addMake( '## include definitions' )
1243 doc.addMake( 'include $(SRC/)make/include/main.defs' )
1246 for tool in ToolProbe.tools:
1250 for select in SelectTool.selects:
1251 select.doc_add( doc )
1254 if arch.mode.mode != arch.mode.default:
1255 doc.add( 'GCC.archs', arch.mode.mode )
1257 doc.add( 'GCC.archs', '' )
1258 doc.add( 'GCC.g', debugMode.mode )
1259 doc.add( 'GCC.O', optimizeMode.mode )
1261 if options.enable_asm and not Tools.yasm.fail:
1263 if build.match( 'i?86-*' ):
1265 doc.add( 'LIBHB.GCC.D', 'HAVE_MMX', append=True )
1266 doc.add( 'LIBHB.YASM.D', 'ARCH_X86', append=True )
1267 if build.match( '*-*-darwin*' ):
1268 doc.add( 'LIBHB.YASM.f', 'macho32' )
1270 doc.add( 'LIBHB.YASM.f', 'elf32' )
1271 doc.add( 'LIBHB.YASM.m', 'x86' )
1272 elif build.match( 'x86_64-*' ):
1274 doc.add( 'LIBHB.GCC.D', 'HAVE_MMX ARCH_X86_64', append=True )
1275 if build.match( '*-*-darwin*' ):
1276 doc.add( 'LIBHB.YASM.D', 'ARCH_X86_64 PIC', append=True )
1277 doc.add( 'LIBHB.YASM.f', 'macho64' )
1279 doc.add( 'LIBHB.YASM.D', 'ARCH_X86_64', append=True )
1280 doc.add( 'LIBHB.YASM.f', 'elf64' )
1281 doc.add( 'LIBHB.YASM.m', 'amd64' )
1282 doc.update( 'FEATURE.asm', asm )
1284 ## add exports to make
1287 doc.addComment( 'overrides via VARIABLE=VALUE on command-line' )
1289 doc.add( nv[0], nv[1] )
1292 doc.addMake( '## include custom definitions' )
1293 doc.addMake( '-include $(SRC/)custom.defs' )
1294 doc.addMake( '-include $(BUILD/)GNUmakefile.custom.defs' )
1297 doc.addMake( '## include rules' )
1298 doc.addMake( 'include $(SRC/)make/include/main.rules' )
1299 doc.addMake( '-include $(SRC/)custom.rules' )
1300 doc.addMake( '-include $(BUILD/)GNUmakefile.custom.rules' )
1313 if os.path.normpath( cfg.build_dir ) == os.curdir:
1318 stdout.write( '%s\n' % ('-' * 79) )
1320 stdout.write( 'Build is finished!\n' )
1322 stdout.write( 'You may now examine the output.\n' )
1324 stdout.write( 'You may now cd into %s and examine the output.\n' % (cfg.build_dir) )
1326 stdout.write( 'Build is configured!\n' )
1328 stdout.write( 'You may now run make (%s).\n' % (Tools.gmake.pathname) )
1330 stdout.write( 'You may now cd into %s and run make (%s).\n' % (cfg.build_dir,Tools.gmake.pathname) )
1332 except AbortError, x:
1333 stderr.write( 'ERROR: %s\n' % (x) )