#!/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') ) options.Add(PathOption('external_dll_path', '(Windows only) The place where the NSIS packager takes the installed DLL from', '.')) if sys.platform=="linux2" : options.Add(BoolOption('crossmingw', 'Using MinGW crosscompiler mode', '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)] ) def unique(list) : return dict.fromkeys(list).keys() toolChain = 'default' if sys.platform == "win32": toolChain = 'mingw' env = Environment(ENV=os.environ, tools=[toolChain], options=options) options.Save('options.cache', env) Help(options.GenerateHelpText(env)) env.SConsignFile() # Single signature file crosscompiling = env.has_key("crossmingw") and env["crossmingw"] isWindowsPlatform = sys.platform=='win32' or crosscompiling isLinuxPlatform = sys.platform=='linux2' and not crosscompiling isDarwinPlatform = sys.platform=='darwin' 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]) if crosscompiling : env.Tool('crossmingw', toolpath=[clam_sconstoolspath]) sys.path.append(clam_sconstoolspath) import versionInfo version, fullVersion = versionInfo.versionFromLocalInfo("Voice2MIDI") print "Version: ", version print "Package version: ", fullVersion versionInfo.generateVersionSources(os.path.join('src','Voice2MIDIVersion'), "Voice2MIDI", fullVersion) 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['SHCXXCOMSTR'] = '== Compiling shared $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', 'Qt3Support', ], debug=False, crosscompiling=crosscompiling, ) #env.Append(CPPFLAGS=['-DQT3_SUPPORT']) mainSources = { 'Voice2MIDI' : os.path.join('src','main.cxx'), } blacklist = [ ] sourcePaths = [ os.path.join('src'), os.path.join('src','Analysis'), os.path.join('src','AudioIO'), os.path.join('src','Controller'), os.path.join('src','GUI'), os.path.join('src','GUI','MainWindow'), os.path.join('src','GUI','Widgets'), os.path.join('src','GUI','Widgets','Surfaces'), os.path.join('src','MIDIOut'), os.path.join('src','misc'), ] extraPaths = [] extraPaths += [ CLAMInstallDir+'/include', CLAMInstallDir+'/include/CLAM', # KLUDGE to keep old style includes ] 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 = unique(sources) for mainSource in mainSources.values() : sources.remove(mainSource) for blacksheep in blacklist : sources.remove( blacksheep ) qrcfiles = scanFiles("*.qrc", sourcePaths) if qrcfiles : sources += env.Qrc(source=qrcfiles) uifiles = scanFiles("*.ui", sourcePaths) if uifiles: env.Uic(source=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 ] # TODO: Create the rc file for Voice2MIDI """ if sys.platform=="win32" or crosscompiling : sources += env.RES(source=["resources/Voice2MIDI.rc"]) """ env.Append(CPPPATH=includePaths) if sys.platform=='darwin' : env.Append(CPPFLAGS='-DRESOURCES_BASE="\\"Voice2MIDI.app/Contents/Resources\\""') else : env.Append(CPPFLAGS='-DRESOURCES_BASE="\\"' + env['prefix'] + '/share/voice2midi\\""') if sys.platform=='win32' or crosscompiling : # TODO: This should not be hardcoded neither prefix (because package intall) env.Append(CPPFLAGS='-DDATA_EXAMPLES_PATH="\\"/usr/share/voice2midi/example-data\\""') env.Append(LIBS=['pthread']) 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? extralinkFlags = [] if sys.platform == 'darwin' : extralinkFlags=['-dynamic','-bind_at_load'] programs = [] for main in mainSources.items() : programs += [ env.Program(target=main[0], source = sources+[main[1]], LINKFLAGS=extralinkFlags) ] manpages = [ 'resources/man/man1/Voice2MIDI.1', ] # Manual step: lupdate-qt4 *xx *ui -ts Voice2MIDI_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 ['clamnetwork', 'pos', 'ui', 'wav', 'mp3', 'ogg']: examples += scanFiles('*.%s'%ext, ['example-data']) # the official one examples += scanFiles('*.%s'%ext, [os.path.join('resources','soundsamples')]) manualPages = scanFiles('*.htm', [os.path.join('resources','doc')]) manualImages = scanFiles('*.png', [os.path.join('resources','doc','pics')]) menuEntries = glob.glob('resources/*.desktop') mimeEntries = [] # 'resources/clam-network.xml' installation = { '/bin' : programs, '/share/applications': menuEntries, '/share/mime/packages': mimeEntries, '/share/man/man1' : manpages, '/share/voice2midi/i18n': translations, '/share/voice2midi/example-data': examples, '/share/doc/voice2midi/': manualPages, '/share/doc/voice2midi/pics': manualImages, } installTargets = [ env.Install( env['prefix']+path, files ) for path, files in installation.items() ] def absolutePosixPathToWine(dir) : return 'z:'+'\\\\'.join(dir.split('/')) if isWindowsPlatform : winqtdir=env['QTDIR'] if crosscompiling : env['NSIS_MAKENSIS'] = 'wine ~/.wine/dosdevices/c:/Program\ Files/NSIS/makensis' if crosscompiling : winqtdir = absolutePosixPathToWine(winqtdir) externalDllPath = env['external_dll_path'] if crosscompiling : externalDllPath = absolutePosixPathToWine(externalDllPath) winclampath = CLAMInstallDir if crosscompiling : winclampath = absolutePosixPathToWine(winclampath) if crosscompiling : env.AddPostAction(programs, env.Action(["i586-mingw32msvc-strip $TARGET"])) installTargets += [ env.Install( env['prefix']+"/bin", os.path.join(env['QTDIR'],'bin',"Qt"+dll+"4.dll") ) for dll in 'Core', 'Gui', 'OpenGL'] env.Append(NSIS_OPTIONS=['/DVERSION=%s' % fullVersion ]) env.Append(NSIS_OPTIONS=['/DQTDIR=%s'%winqtdir ]) env.Append(NSIS_OPTIONS=['/DEXTERNALDLLDIR=%s' % externalDllPath ]) env.Append(NSIS_OPTIONS=['/DCLAMINSTALLDIR=%s' % winclampath ]) # 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_voice2midi.nsi')] env.AddPreAction(win_packages, '%s\\changeExampleDataPath.py . ..' % clam_sconstoolspath) env.Alias('package', win_packages) if sys.platform=='darwin' : #Resource installation in Mac application directory (binaries, xml metadata, icon, sound) installTargets = [ env.Install( 'Voice2MIDI.app/Contents/MacOS', programs ), env.Install( 'Voice2MIDI.app/Contents', 'resources/Info.plist'), env.Install( 'Voice2MIDI.app/Contents/Resources', 'resources/CLAM.icns'), ] mac_packages = env.Dmg('CLAM_Voice2MIDI-%s.dmg'%fullVersion, [env.Dir('Voice2MIDI.app/')]+installTargets ) env.Alias('package', mac_packages) env.Alias('install', installTargets ) env.Default(programs, translations)