import sys, os, glob 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 != 'win32' : annotator_env.Replace( QT_UIC='/usr/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 != 'win32' : opts.Add( PathOption( 'clam_prefix', 'Prefix were CLAM was installed', '/usr') ) 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'] ) annotator_env.ParseConfig( 'pkg-config --cflags --libs clam_core clam_processing clam_audioio clam_vmqt' ) else : if annotator_env['release'] : annotator_env.Append( CPPFLAGS = ['-DWIN32'] ) annotator_env.Append( CCFLAGS = '/FD /GR /GX /MD /O2 /GL /W3 /Zm1000' ) annotator_env.Append( LINKFLAGS = ['/LTCG'] ) else : annotator_env.Append( CPPFLAGS = ['-DWIN32', '-D_DEBUG'] ) annotator_env.Append( CCFLAGS = '/D /FD /GR /GX /GZ /MDd /Od /W3 /ZI /Zm1000' ) 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) bin_main_object = annotator_env.Object('../src/main.cxx') bin_objects = [ annotator_env.Object(source) for source in sourcefiles ] annotator_env.Append(CPPPATH=source_dirs) if sys.platform != 'win32' : annotator_env.Append(CCFLAGS='-include CLAM/preinclude.hxx') annotator_env.Append(CPPFLAGS='-DRESOURCES_BASE="\\"/usr/share/annotator\\""') annotator_bin = annotator_env.Program( 'Annotator', bin_main_object + bin_objects, LINKFLAGS=['-rdynamic'] ) install_bin = annotator_env.Install( annotator_env['install_prefix']+'/bin', annotator_bin ) manpage = ['../resources/man/man9/Annotator.9'] install_manpage = annotator_env.Install( annotator_env['install_prefix']+'/share/man/man9', manpage ) sounds = ['../resources/sounds/click.mp3'] 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 : parse_pkg_config( annotator_env ) annotator_env.Append( LIBPATH = 'G:\projects\portmidi\lib' ) annotator_env.Append( LIBS = 'portmidi' ) annotator_env.Append( LIBS = 'porttime' ) annotator_env.Append( LIBS = 'winmm' ) annotator_env.Append( CCFLAGS = '/FICLAM/preinclude.hxx' ) annotator_env.Append( CCFLAGS = ['/EHsc'] ) annotator_env.Append( LINKFLAGS = ['/subsystem:console','/machine:x86'] ) annotator_bin = annotator_env.Program( 'Annotator', bin_main_object + bin_objects) install_bin = annotator_env.Install( annotator_env['install_prefix'], annotator_bin) manpage = ['../resources/man/man9/Annotator.9'] install_manpage = annotator_env.Install( annotator_env['install_prefix']+'/share/man/man9', manpage ) sounds = ['../resources/sounds/click.mp3'] 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] ) variantVCProj = 'Debug' if annotator_env['release'] : variantVCProj = 'Release' generate_vcproj = annotator_env.MSVSProject( target = 'Annotator' + annotator_env['MSVSPROJECTSUFFIX'], srcs = sourcefiles, buildtarget = annotator_bin, variant = variantVCProj ) vc_alias = annotator_env.Alias('visual_project', [generate_vcproj]) Default(annotator_bin)