#!/usr/bin/python import os import glob import sys options = Options('options.cache', ARGUMENTS) options.Add(PathOption('prefix', 'The prefix where the application will be installed', '')) options.Add(PathOption('clam_prefix', 'The prefix where CLAM was installed', '')) options.Add(BoolOption('release', 'Enabling compiler optimizations', 'no') ) options.Add(BoolOption('verbose', 'Display the full command line instead a short command description', 'no') ) def scanFiles(pattern, paths) : files = [] for path in paths : files+=glob.glob(os.path.join(path,pattern)) return files def recursiveDirs(root) : return filter( (lambda a : a.rfind(".svn")==-1 ), [ a[0] for a in os.walk(root)] ) toolChain = 'default' if sys.platform == "win32": toolChain = 'mingw' env = Environment(ENV=os.environ, tools=[toolChain,'qt'], options=options) options.Save('options.cache', env) Help(options.GenerateHelpText(env)) env.SConsignFile() # Single signature file if sys.platform in ["linux2","darwin"] : env['QT_LIB']='qt-mt' if sys.platform=="linux2": env.AppendUnique(LIBS=['GL']) elif sys.platform=="win32" : env['QT_LIB']='qt-mt322' CLAMInstallDir = env['clam_prefix'] clam_sconstoolspath = os.path.join(CLAMInstallDir,'share','clam','sconstools') #env.Tool('qt4', toolpath=[clam_sconstoolspath]) env.Tool('clam', toolpath=[clam_sconstoolspath]) env.Tool('nsis', toolpath=[clam_sconstoolspath]) if sys.platform=='darwin' : env.Tool('bundle', toolpath=[clam_sconstoolspath]) env.Tool('dmg', toolpath=[clam_sconstoolspath]) sys.path.append(clam_sconstoolspath) import versionInfo version, fullVersion = versionInfo.versionFromLocalInfo("SMSTools") print "Version: ", version print "Package version: ", fullVersion versionInfo.generateVersionSources(os.path.join('src','SMSToolsVersion'), "SMSTools", fullVersion) # KLUDGE!!!!!!!!!!!!!!!!!! #env['RCCOM'] = '$RC $_CPPDEFFLAGS $_CPPINCFLAGS $RCFLAGS /fo$TARGET $SOURCES' # the original one env['RCCOM'] = '$RC $_CPPDEFFLAGS $RCFLAGS /fo$TARGET $SOURCES' env['CXXFILESUFFIX'] = '.cxx' env['QT4_UICDECLSUFFIX'] = '.hxx' env['QT4_MOCHPREFIX'] = os.path.join('generated','moc_') env['QT4_UICDECLPREFIX'] = os.path.join('generated','ui_') env['QT4_QRCCXXPREFIX'] = os.path.join('generated','qrc_') if not env['verbose']: env['CXXCOMSTR'] = '== Compiling $SOURCE' env['LINKCOMSTR'] = '== Linking $TARGET' env['SHLINKCOMSTR'] = '== Linking library $TARGET' env['QT4_RCCCOMSTR'] = '== Embeding resources $SOURCE' env['QT4_UICCOMSTR'] = '== Compiling interface $SOURCE' env['QT4_LRELEASECOMSTR'] = '== Compiling translation $TARGET' env['QT4_MOCFROMHCOMSTR'] = '== Generating metaobjects for $SOURCE' env['QT4_MOCFROMCXXCOMSTR'] = '== Generating metaobjects for $SOURCE' env.EnableClamModules([ 'clam_core', 'clam_audioio', 'clam_processing', ] , CLAMInstallDir) #env.EnableQt4Modules([ # 'QtCore', # 'QtGui', # 'QtOpenGL', # 'QtSvg', # 'QtSql', # 'QtNetwork', # 'QtTest', # 'QtXml', # 'QtSvg', # 'Qt3Support', # ]) mainSources = { 'SMSTools' : os.path.join('src','QtImpl','main.cxx'), 'SMSBatch' : os.path.join('src','SMSBatch.cxx'), 'SMSConsole' : os.path.join('src','SMS.cxx'), } sourcePaths=recursiveDirs(os.path.join('src','QtImpl')) sourcePaths+=recursiveDirs(os.path.join('vmqt')) extraPaths = [] extraPaths += [ CLAMInstallDir+'/include', CLAMInstallDir+'/include/CLAM', # KLUDGE to keep old style includes 'src', os.path.join('src','GUI','ScoreEditor'), '/usr/include/qt3', # qt3 tools should add this '/opt/local/include/qt3', # mac port. ] includePaths = sourcePaths + extraPaths sources = scanFiles('*.cxx', sourcePaths) if sys.platform == "win32" : sources = filter( (lambda a : a.rfind( "Ladspa")==-1 ), sources ) sources = filter( (lambda a : a.rfind( "moc_")==-1 ), sources ) sources = filter( (lambda a : a.rfind( "qrc_")==-1 ), sources ) sources = filter( (lambda a : a.rfind( "uic_")==-1 ), sources ) sources = dict.fromkeys(sources).keys() sources.append(os.path.join('src','Progress.cxx')) sources.append(os.path.join('src','SMSBase.cxx')) sources.append(os.path.join('src','SMSToolsVersion.cxx')) sources.append(os.path.join('src','WaitMessage.cxx')) sources.append(os.path.join('src','SerializationController.cxx')) sources.append(os.path.join('src','SMSAnalysisSynthesisConfig.cxx')) sources.append(os.path.join('src','SDIFSerializer.cxx')) sources.append(os.path.join('src','XMLSerializer.cxx')) # for SMSBatch binary: sources.append(os.path.join('src','SMSBatch.cxx')) sources.append(os.path.join('src','StdOutWaitMessage.cxx')) sources.append(os.path.join('src','StdOutProgress.cxx')) #for SMSConsole binary sources.append(os.path.join('src','SMS.cxx')) for mainSource in mainSources.values() : sources.remove(mainSource) qrcfiles = scanFiles("*.qrc", sourcePaths) if qrcfiles : sources += env.Qrc(source=qrcfiles) uifiles = scanFiles("*.ui", sourcePaths) if uifiles: uis = [ env.Uic(source=uifile) for uifile in uifiles ] sources += [ os.path.join( os.path.dirname(uiccpp), 'uic_'+os.path.splitext(os.path.basename(uiccpp))[0]+'.cxx') for uiccpp in uifiles ] sources += [ os.path.join( os.path.dirname(uiccpp), 'moc_'+os.path.splitext(os.path.basename(uiccpp))[0]+'.cxx') for uiccpp in uifiles ] if sys.platform=="win32" : sources += env.RES(source=["resources/SMSTools.rc"]) env.AppendUnique(LIBS=['opengl32']) env.Append( CPPFLAGS=['-DQT_DLL', '-DQT_THREAD_SUPPORT', '-DVISUAL'] ) env.Append( LIBS=['advapi32', 'comctl32', 'comdlg32', 'gdi32', 'kernel32', 'ole32', 'oleaut32', 'shell32', 'user32', 'uuid', 'winspool','wsock32'] ) env.Append(CPPPATH=includePaths) if sys.platform=='darwin' : env.Append(CPPFLAGS='-DDATA_EXAMPLES_PATH="\\"@executable_path/../Resources/example-data\\""') env.AppendUnique(LINKFLAGS="-F/System/Library/Frameworks") env.Append(LINKFLAGS=['-framework', 'AGL']) # kludge to avoid quotes env.Append(LINKFLAGS=['-framework', 'OpenGL']) if sys.platform=='linux2' : env.Append(CPPFLAGS='-DDATA_EXAMPLES_PATH="\\"' + env['prefix'] + '/share/smstools/example-data\\""') if sys.platform=='win32' : env.Append(CPPFLAGS='-DDATA_EXAMPLES_PATH="\\"' + env['prefix'] + '/share/smstools/example-data\\""') if sys.platform=='linux2' : if env['release'] : env.Append( CCFLAGS=['-g','-O3','-fomit-frame-pointer','-Wall'] ) else : env.Append( CCFLAGS=['-g', '-Wall'] ) # env.Append( LINKFLAGS=['-rdynamic'] ) # TODO: Is it needed? if sys.platform=='win32': if env['release'] : env.Append( LINKFLAGS = ['/LTCG'] ) else: env.Append( LINKFLAGS = ['/OPT:NOREF', '/OPT:NOICF', '/DEBUG'] ) programs = [] for main in mainSources.items() : programs += [ env.Program(target=main[0], source = sources+[main[1]]) ] manpages = [ 'resources/man/man1/SMSTools.1', ] # Manual step: lupdate-qt4 *xx *ui -ts Annotator_ca.ts tsfiles = scanFiles("*.ts", ["src/i18n/"]) env.Precious(tsfiles) # TODO: this is not enough!! scan -c will delete ts files!!! translatableSources = scanFiles('*.cxx', sourcePaths); translatableSources+= scanFiles('*.hxx', sourcePaths); translatableSources+= scanFiles('*.ui', sourcePaths); translatableSources = filter( (lambda a : a.rfind( "generated/")==-1 ), translatableSources ) translations = [] if len(tsfiles) : # tsNodes = env.Ts(target=tsfiles, source = translatableSources) translations = env.Qm(source = tsfiles) examples = [] for ext in ['xml', 'wav', 'mp3', 'ogg']: examples += scanFiles('*.%s'%ext, ['example-data']) menuEntries = glob.glob('resources/*.desktop') installation = { '/bin' : programs, '/share/applications': menuEntries, '/share/man/man1' : manpages, '/share/smstools/i18n': translations, '/share/smstools/example-data': examples, } installTargets = [ env.Install( env['prefix']+path, files ) for path, files in installation.items() ] if sys.platform=='win32' : """ installTargets += [ env.Install( env['prefix']+"/bin", os.path.join(env['QTDIR'],'lib',"Qt"+dll+"4.dll") ) for dll in 'Core', 'Gui', 'OpenGL'] """ env.Append(NSIS_OPTIONS=['/DVERSION=%s' % fullVersion ]) env.Append(NSIS_OPTIONS=['/DQTDIR=$QTDIR']) externalsDllDir = os.environ['EXTERNALDLLDIR'] env.Append(NSIS_OPTIONS=['/DEXTERNALDLLDIR=%s' % externalsDllDir ]) # Get the visual studio runtimes path for vcRuntimeDir in os.environ['PATH'].split(";") : vcRuntimeDir = os.path.normpath(vcRuntimeDir) if os.access(os.path.join(vcRuntimeDir,"msvcr71.dll"),os.R_OK) : break env.Append(NSIS_OPTIONS=['/DVCRUNTIMEDIR=%s' % vcRuntimeDir ]) win_packages = [env.Nsis( source='resources\\clam_smstools.nsi')] env.AddPreAction(win_packages, '%s\\changeExampleDataPath.py . ..' % clam_sconstoolspath) env.Alias('package', win_packages) if sys.platform=='darwin' : env.AppendUnique( LINKFLAGS=['-dynamic','-bind_at_load']) env.AppendUnique(LIBPATH=['/opt/local/lib']) mac_bundle = env.Bundle( BUNDLE_NAME='SMSTools', BUNDLE_BINARIES=["SMSTools"], # BUNDLE_RESOURCEDIRS=["example-data"], BUNDLE_PLIST='resources/Info.plist', BUNDLE_ICON='resources/CLAM.icns', ) env.Alias('bundle', mac_bundle) arch = os.popen("uname -p").read().strip() mac_packages = env.Dmg('CLAM_SMSTools-%s-%s.dmg'% (fullVersion, arch), [ env.Dir('SMSTools.app/'), env.Dir('example-data'), ] ) env.Alias('package', mac_packages) installTargets = [] env.Alias('install', installTargets ) env.Default(programs, translations)