diff --git a/Buildhelper.py b/Buildhelper.py index 31e04452a..d4c1a3a52 100644 --- a/Buildhelper.py +++ b/Buildhelper.py @@ -25,6 +25,9 @@ from fnmatch import fnmatch import os import sys import fnmatch +import re +import tarfile + # # Common Helper Functions @@ -69,3 +72,81 @@ def scanSrcSubtree(root): for p in SRCPATTERNS: for f in fnmatch.filter(files, p): yield os.path.join(dir,f) + + + + +def Tarball(env,location,dirs,suffix=''): + ''' Custom Command: create Tarball of some subdirs + location: where to create the tar (optionally incl. filename.tar.gz) + suffix: (optional) suffix to include in the tar name + dirs: directories to include in the tar + + This is a bit of a hack, because we want to be able to include arbitrary dirctories, + without creating new dependencies on those dirs. Esp. we want to tar the source tree + prior to compiling. Solution is + - use the Command-Builder, but pass all target specifications as custom build vars + - create a pseudo-target located in the parent directory (not built by default) + ''' + targetID = '../extern-tar%s' % suffix + versionID = env['VERSION'] + defaultName = 'cinelerra%s_%s' % (suffix, versionID) + nameprefix = 'cinelerra-%s/' % (versionID) + location = env.subst(location) + dirs = env.subst(dirs) + return env.Command(targetID,None, createTarball, + location=location, defaultName=defaultName, dirs=dirs, nameprefix=nameprefix) + + +def createTarball(target,source,env): + ''' helper, builds the tar using the python2.3 tarfil lib. + This allows us to prefix all paths, thus moving the tree + into a virtual subdirectory containing the Version number, + as needed by common packaging systems. + ''' + name = getTarName( location = env['location'] + , defaultName = env['defaultName']) + targetspec = env['dirs'] + nameprefix = env['nameprefix'] or '' + print 'Running: tar -czf %s %s ...' % (name,targetspec) + if os.path.isfile(name): + os.remove(name) + tar = tarfile.open(name,'w:gz') + for name in targetspec.split(): + tar.add(name,nameprefix+name) + tar.close() +# +# old version using shell command: +# +# cmd = 'tar -czf %s %s' % (name,targetspec) +# print 'running ', cmd, ' ... ' +# pipe = os.popen (cmd) +# return pipe.close () + + + + +def getTarName(location, defaultName): + ''' create a suitable name for the tarball. + - if location contains a name (*.tar.gz) then use this + - otherwise append the defaultName to the specified dir + ''' + spec = os.path.abspath(location) + (head,tail) = os.path.split(spec) + if not os.path.isdir(head): + print 'Target dir "%s" for Tar doesn\'t exist.' % head + Exit(1) + mat = re.match(r'([\w\.\-])\.((tar)|(tar\.gz)|(tgz))', tail) + if mat: + name = mat.group(1) + ext = '.'+mat.group(2) + else: + ext = '.tar.gz' + if os.path.isdir(spec): + head = spec + name = defaultName + else: + name = tail + return os.path.join(head,name+ext) + + diff --git a/SConstruct b/SConstruct index fc05fe595..a9609ce49 100644 --- a/SConstruct +++ b/SConstruct @@ -22,7 +22,6 @@ ##################################################################### import os -import re from Buildhelper import * @@ -44,21 +43,31 @@ def setupBasicEnvironment(): ''' define cmdline options, build type decisions ''' opts = defineCmdlineOptions() - - env = Environment( options=opts - , CPPDEFINES={'DEBUG': '${DEBUG}' - ,'USE_OPENGL': '${OPENGL}' - } - ) + + env = Environment(options=opts) env.Replace( VERSION=VERSION , SRCDIR=SRCDIR , BINDIR=BINDIR , CPPPATH=SRCDIR # used to find includes ) + appendCppDefine(env,'DEBUG','DEBUG') + appendCppDefine(env,'OPENGL','USE_OPENGL') + appendVal(env,'ARCHFLAGS', 'CPPFLAGS') # for both C and C++ + appendVal(env,'OPTIMIZE', 'CPPFLAGS', val=' -O3') + prepareOptionsHelp(opts,env) opts.Save(OPTIONSCACHEFILE, env) return env +def appendCppDefine(env,var,cppVar): + if env[var]: + env.Append(CPPDEFINES={cppVar: env[var]}) + +def appendVal(env,var,targetVar,val=None): + if env[var]: + env.Append(**{targetVar: val or env[var]}) + + def defineCmdlineOptions(): ''' current options will be persisted in a options cache file. @@ -74,26 +83,35 @@ def defineCmdlineOptions(): # ,EnumOption('DIST_TARGET', 'Build target architecture', 'auto', # allowed_values=('auto', 'i386', 'i686', 'x86_64' ), ignorecase=2) ,PathOption('DESTDIR', 'Installation dir prefix', '/usr/local') - ,PackageOption('TARSRC', 'Create source tarball prior to compiling', '.') - ,PackageOption('TARDOC', 'Create tarball with dev documentaion, wiki and uml model', '.') + ,PathOption('SRCTAR', 'Create source tarball prior to compiling', '..', PathOption.PathAccept) + ,PathOption('DOCTAR', 'Create tarball with dev documentaionl', '..', PathOption.PathAccept) ) return opts + def prepareOptionsHelp(opts,env): prelude = ''' -USAGE: scons [-c] [OPTS] [TARGETS] +USAGE: scons [-c] [OPTS] [key=val,...] [TARGETS] Build and optionally install Cinelerra. Without specifying any target, just the (re)build target will run. Add -c to the commandline to clean up anything a given target would produce +Special Targets: + build : just compile and link + install : install created artifacts at PREFIX + src.tar : create source tarball + doc.tar : create developer doc tarball + tar : create all tarballs + Configuration Options: ''' Help(prelude + opts.GenerateHelpText(env)) + def configurePlatform(env): ''' locate required libs. setup platform specific options. @@ -124,33 +142,16 @@ def definePackagingTargets(env, artifacts): ''' build operations and targets to be done /before/ compiling. things like creating a source tarball or preparing a version header. ''' - env.SetDefault(TARFLAGS = '-c -z', TARSUFFIX = '') - if env['TARSRC']: - # define the Tar as a target and make it default, - # i.e. buid it if scons is called without targets - t=env.Tar(getTarName(env['TARSRC']),SRCDIR) - env.Default(t) - if env['TARDOC']: - t=env.Tar(getTarName(env['TARDOC']), 'admin doc wiki uml tests') - env.Default(t) + t = Tarball(env,location='$SRCTAR',dirs='$SRCDIR') + artifacts['src.tar'] = t + env.Alias('src.tar', t) + env.Alias('tar', t) + + t = Tarball(env,location='$DOCTAR',suffix='-doc',dirs='admin doc wiki uml tests') + artifacts['doc.tar'] = t + env.Alias('doc.tar', t) + env.Alias('tar', t) -def getTarName(spec): - (head,tail) = os.path.split( os.path.abspath(spec)) - if not os.path.isdir(head): - print 'Target dir "%s" for Tar doesn\'t exist.' % head - Exit(1) - mat = re.match(r'([\w\.\-])\.((tar)|(tar\.gz)|(tgz))', tail) - if mat: - name = mat.group(1) - ext = '.'+mat.group(2) - else: - ext = '.tar.gz' - if os.path.isdir(tail): - name = 'cinelerra$VERSION' - else: - name = tail - return os.path.join(head,name+ext) - def defineBuildTargets(env, artifacts): @@ -183,7 +184,7 @@ def defineInstallTargets(env, artifacts): il = env.Alias('install-lib', '$DESTDIR/lib') env.Alias('install', [ib, il]) - env.Alias('build', '$DESTDIR') + env.Alias('build', '$BINDIR') env.Default('build') # additional files to be cleaned when cleaning 'build' env.Clean ('build', [ 'scache.conf', '.sconf_temp', '.sconsign.dblite', 'config.log']) @@ -212,7 +213,7 @@ artifacts = {} # 'plugins' : plugin shared lib # 'tools' : small tool applications (e.g mpegtoc) # 'src,tar' : source tree as tarball (without doc) -# 'devdoc.tar' : uml model, wiki, dev docu (no src) +# 'doc.tar' : uml model, wiki, dev docu (no src) definePackagingTargets(env, artifacts) defineBuildTargets(env, artifacts) diff --git a/src/tool/SConscript b/src/tool/SConscript index e4c744190..f3a3abf76 100644 --- a/src/tool/SConscript +++ b/src/tool/SConscript @@ -6,5 +6,5 @@ Import('env','artifacts') # build the ubiquitous Hello World application (note: C source) -artifacts['tools'] = env.Program('$BINDIR/hello-world','hello.c') +artifacts['tools'] = env.Program('#$BINDIR/hello-world','hello.c')