import sys, os, glob version='0.2' def create_setup( target, source, env ) : os.system( "makensis clam_annotator.nsi" ) def create_setup_message( target, source, env ) : return "generating Annotator Installer" def create_dmg( target, source, env) : os.system( "mkdir DMG" ) os.system( "cp README.txt DMG" ) os.system( "cp -r Annotator.app DMG" ) os.system( "sudo hdiutil create -srcfolder DMG -volname CLAM_Annotator -uid 0 CLAM_Annotator-%s.dmg"%version ) os.system( "rm -rf DMG" ) def create_dmg_message( target, source, env): return "Creating DMG package" def parse_pkg_config( env ) : prefix = env['clam_prefix'] descriptor_path = prefix + "\\lib\\pkgconfig\\*.pc" descriptors = glob.glob( descriptor_path ) libpath = dict() libs = dict() cppflags = dict() cpppath = dict() ccflags = dict() for desc_file in descriptors : instream = open( desc_file ) for line in instream : tokens = line.strip().split(' ') if tokens[0] == 'Libs:' : for token in tokens[1:] : if "/LIBPATH:" in token : libpath[token.replace("/LIBPATH:", "")] = True else : libs[token] = True elif tokens[0] == 'Cflags:': foo = line.strip().split(' /') for token in foo[1:] : token = '/' + token # search for -X flags if(token.find(' -')!=-1): listOfRealTokens = token.split(' -') #print('new token to parse: ' + token) firstToken = listOfRealTokens[0] if "/I" in firstToken: cpppath[ firstToken.replace("/I","") ] = True elif "/D" in firstToken : cppflags[ firstToken ] = True else : ccflags[firstToken] = True for realToken in listOfRealTokens[1:]: #print('new token to parse: ' + realToken) ccflags['-'+realToken] = True else: #print('new token to parse: ' + token) if "/I" in token : cpppath[ token.replace("/I","") ] = True elif "/D" in token in token : cppflags[ token ] = True else : #print('token: ' + token ) ccflags[token] = True else : pass instream.close() print "Adding to evironment LIBPATH:" for elem in libpath.keys() : print elem, print env.Append( LIBPATH = libpath.keys() ) print "Adding to environment LIBS:" for elem in libs.keys() : print elem, print env.Append( LIBS = libs.keys() ) print "Adding to environment CPPFLAGS:" for elem in cppflags.keys() : print elem, print env.Append( CPPFLAGS = cppflags.keys() ) print "Adding to environment CCFLAGS:" for elem in ccflags.keys() : print elem, print env.Append( CCFLAGS = ccflags.keys() ) print "Adding to environment CPPPATH:" for elem in cpppath.keys() : print elem, print env.Append( CPPPATH = cpppath.keys() ) # builder for embedding images into a cxx file # def embed_images( target, source, env ) : output_file_str = str(target[0]) input_files = [ str(src_item) for src_item in source ] input_files_str = ' '.join( input_files ) cmd_str = '%s -embed %s %s -o %s'%(env['QT_UIC'], env['project'], input_files_str, output_file_str) os.system( cmd_str ) def embed_images_message( target, source, env ) : print "Embedding images into", str(target[0]) for item in source : print "\t", str(item), "..." bld = Builder( action = Action(embed_images, embed_images_message), suffix = '.cxx', src_suffix = '' ) annotator_env = Environment( tools=['default','qt'], ENV=os.environ) annotator_env.Append( BUILDERS = {'EmbedImages' : bld} ) if sys.platform == 'linux2' : annotator_env.Replace( QT_UIC='/usr/bin/uic' ) elif sys.platform == 'darwin' : annotator_env.Replace( QT_UIC='/Developer/qt/bin/uic' ) else: annotator_env.Replace( QT_UIC='G:\projects\qt/bin\uic' ) if sys.platform != 'win32' : annotator_env.Replace(QT_LIB='qt-mt') else : annotator_env.Replace(QT_LIB='qt-mt322') opts = Options('Annotator.conf') if sys.platform == 'linux2' : opts.Add( PathOption( 'clam_prefix', 'Prefix were CLAM was installed', '/usr') ) elif sys.platform == 'darwin' : opts.Add( PathOption( 'clam_prefix', 'Prefix were CLAM was installed', '/usr/local') ) else : opts.Add( PathOption( 'clam_prefix', 'Prefix were CLAM was installed', 'G:\projects\CLAM-bin' ) ) if sys.platform != 'win32' : opts.Add( PathOption( 'install_prefix', 'Prefix where Network editor is going to be installed', '/usr') ) else : opts.Add( PathOption( 'install_prefix', 'Prefix where Network editor is going to be installed', 'G:\projects\CLAM-bin\\bin') ) opts.Add( BoolOption( 'release', 'Build CLAM Annotator enabling compiler optimizations', 'no') ) opts.Update(annotator_env) opts.Save('Annotator.conf', annotator_env) Help(opts.GenerateHelpText(annotator_env)) annotator_env['project'] = 'Annotator' if sys.platform != 'win32' : if annotator_env['release'] : annotator_env.Append( CCFLAGS=['-O3','-fomit-frame-pointer','-Wall'] ) else : annotator_env.Append( CCFLAGS=['-g', '-Wall'] ) export_pkg_config = 'export PKG_CONFIG_PATH='+annotator_env['clam_prefix']+'/lib/pkgconfig' execute_pkg_config = 'pkg-config --cflags --libs clam_core clam_processing clam_audioio clam_vmqt' annotator_env.ParseConfig( export_pkg_config + ' && ' + execute_pkg_config ) else : if annotator_env['release'] : annotator_env.Append( CPPFLAGS = ['-DWIN32'] ) annotator_env.Append( CCFLAGS = '/FD /GR /GX /MD /O2 /Og /G7 /GL /W3 /Zm1000' ) annotator_env.Append( LINKFLAGS = ['/LTCG'] ) else : annotator_env.Append( CPPFLAGS = ['-DWIN32', '-D_DEBUG'] ) annotator_env.Append( LINKFLAGS = ['/OPT:NOREF', '/OPT:NOICF', '/DEBUG'] ) source_dirs = ['../src', '../src/AnnotatorBrowserGL', '../src/common', '../src/common/Clipboard' ] sourcefiles = [] for dir in source_dirs : sourcefiles += glob.glob(dir+'/*.cxx') sourcefiles += glob.glob(dir+'/*.ui') if sys.platform != 'win32' : sourcefiles.remove( '../src/main.cxx' ) sourcefiles.remove( '../src/Test.cxx' ) else : sourcefiles.remove( '../src\main.cxx' ) sourcefiles.remove( '../src\Test.cxx' ) image_dirs = ['../images'] image_files = [] for dir in image_dirs : image_files += glob.glob(dir+'/*.png') image_source = annotator_env.EmbedImages( 'image_collection.cxx', image_files ) sourcefiles.append(image_source) for source in sourcefiles : print source bin_objects = [ annotator_env.Object(source) for source in sourcefiles ] annotator_env.Append(CPPPATH=source_dirs) sounds = ['../resources/sounds/click.wav'] if sys.platform != 'win32' : bin_main_object = annotator_env.Object('../src/main.cxx') bin_test_object = annotator_env.Object('../src/Test.cxx') annotator_env.Append(CCFLAGS='-include CLAM/preinclude.hxx -DQT_THREAD_SUPPORT') if sys.platform == 'linux2': annotator_env.Append(CPPFLAGS='-DRESOURCES_BASE="\\"/usr/share/annotator\\""') annotator_bin = annotator_env.Program( 'Annotator', bin_objects + bin_main_object, LINKFLAGS=['-rdynamic'] ) sample_extractor_bin = annotator_env.Program( 'ClamExtractorExample', bin_test_object + bin_objects, LINKFLAGS=['-rdynamic'] ) install_bin = annotator_env.Install( annotator_env['install_prefix']+'/bin', [annotator_bin, sample_extractor_bin] ) manpage = ['../resources/man/man9/Annotator.9'] install_manpage = annotator_env.Install( annotator_env['install_prefix']+'/share/man/man9', manpage ) install_sounds = annotator_env.Install( annotator_env['install_prefix']+'/share/annotator/sounds', sounds ) annotator_env.AddPostAction( install_bin, 'chmod 755 $TARGET' ) install_alias = annotator_env.Alias( 'install', [install_bin,install_manpage, install_sounds] ) else: #MAC annotator_env.Append(CPPFLAGS='-DRESOURCES_BASE="\\"Annotator.app/Contents/Resources\\""') #Binaries: annotator + sample extractor annotator_bin_pre = annotator_env.Program( 'Annotator', bin_objects + bin_main_object, LINKFLAGS=['-dynamic','-bind_at_load'] ) sample_extractor_bin = annotator_env.Program( 'ClamExtractorExample', bin_test_object + bin_objects, LINKFLAGS=['-dynamic','-bind_at_load'] ) #Resource installation in Mac application directory (binaries, xml metadata, icon, sound) bundle_bin = annotator_env.Install( 'Annotator.app/Contents/MacOS', [annotator_bin_pre, sample_extractor_bin, 'runExtractor.sh'] ) bundle_data = annotator_env.Install( 'Annotator.app/Contents', 'resources/Info.plist') bundle_icon = annotator_env.Install( 'Annotator.app/Contents/Resources', 'resources/CLAM.icns') bundle_sounds = annotator_env.Install( 'Annotator.app/Contents/Resources/sounds', sounds ) annotator_bin = [ bundle_bin + bundle_sounds + bundle_data + bundle_icon ] #DMG creation process dmg_bld = Builder( action=Action(create_dmg, create_dmg_message )) annotator_env.Append( BUILDERS={'CreateDMG' : dmg_bld} ) dmg = annotator_env.CreateDMG('notused', annotator_bin ) annotator_env.Alias('dmg', [annotator_bin, dmg]) sample_app = annotator_env.Alias('ClamExtractorExample', sample_extractor_bin) else : bin_main_object = annotator_env.Object('../src\main.cxx') bin_test_object = annotator_env.Object('../src\Test.cxx') parse_pkg_config( annotator_env ) annotator_env.Append( CCFLAGS = '/FICLAM/preinclude.hxx -DQT_THREAD_SUPPORT' ) annotator_env.Append( CCFLAGS = ['/EHsc'] ) annotator_env.Append( LINKFLAGS = ['/machine:x86'] ) annotator_bin = annotator_env.Program( 'Annotator', bin_objects + bin_main_object) sample_extractor_bin = annotator_env.Program( 'ClamExtractorExample', bin_test_object + bin_objects) sample_app = annotator_env.Alias('ClamExtractorExample', sample_extractor_bin) install_bin = annotator_env.Install( annotator_env['install_prefix'], [annotator_bin, sample_extractor_bin] ) manpage = ['../resources/man/man9/Annotator.9'] install_manpage = annotator_env.Install( annotator_env['install_prefix']+'/share/man/man9', manpage ) install_sounds = annotator_env.Install( annotator_env['install_prefix']+'/share/annotator/sounds', sounds ) install_alias = annotator_env.Alias( 'install', [install_bin,install_sounds, install_manpage] ) setup_bld = Builder( action=Action(create_setup, create_setup_message )) annotator_env.Append( BUILDERS={'CreateSetup' : setup_bld} ) setup = annotator_env.CreateSetup('notused', annotator_bin) annotator_env.Alias('CreateSetup', [setup]) variantVCProj = 'Debug' if annotator_env['release'] : variantVCProj = 'Release' sourcefilesAnnotator = sourcefiles sourcefilesAnnotator += '..\src\main.cxx' generate_vcproj = annotator_env.MSVSProject( target = 'Annotator' + annotator_env['MSVSPROJECTSUFFIX'], srcs = sourcefilesAnnotator, buildtarget = annotator_bin, variant = variantVCProj ) vc_alias = annotator_env.Alias('visual_project', [generate_vcproj]) sourcefilesExtractor = sourcefiles sourcefilesExtractor += '..\src\Test.cxx' generate_vcproj_extractor = annotator_env.MSVSProject( target = 'ClamExtractorExample' + annotator_env['MSVSPROJECTSUFFIX'], srcs = sourcefilesExtractor, buildtarget = sample_extractor_bin, variant = variantVCProj ) vc_alias2 = annotator_env.Alias('visual_project_extractor', [generate_vcproj_extractor]) Default(annotator_bin)