import os, platform, readline, glob, multiprocessing from distutils import spawn ## ------------------------ ## -- Filename completer -- ## ------------------------ def complete( text, state ): return ( glob.glob( text + '*' ) + [ None ] )[ state ] # fed ## ----------------------- ## -- File decompressor -- ## ----------------------- def decompress( filename, outdir ): real_ext = None for ext in [ ".zip", ".tar", ".tar.gz", ".tar.bz2" ]: if filename[ len( filename ) - len( ext ) : ] == ext: real_ext = ext # fi # rof command = None if real_ext == ".zip": command = "unzip " + filename + " -d " + outdir elif real_ext == ".tar": command = "tar xf " + filename + " -C " + outdir + " --strip-components=1" elif real_ext == ".tar.gz": command = "tar xzf " + filename + " -C " + outdir + " --strip-components=1" elif real_ext == ".tar.bz2": command = "tar xjf " + filename + " -C " + outdir + " --strip-components=1" # fi if command <> None: print( "\tExtracting " + filename + "..." ) res = os.system( "mkdir -p " + outdir + " && " + command ) print( "\t\tdone." ) if res == 0: return True else: return False else: return False # fi # fed ## ------------------------- ## -- Find necessary data -- ## ------------------------- system_name = platform.system( ) process_count = multiprocessing.cpu_count( ) / 2 qmake_exec = spawn.find_executable( "qmake-qt4" ) cmake_exec = spawn.find_executable( "cmake" ) readline.set_completer_delims( ' \t\n;' ) readline.parse_and_bind( "tab: complete" ) readline.set_completer( complete ) install_prefix = os.path.abspath( raw_input( "Install prefix: " ) ) ## -------------------------------------------- ## -- Ask if new versions should be compiled -- ## -------------------------------------------- build_qmake = "y" if qmake_exec <> None: build_qmake = raw_input( "Qt4 was found in \"" + qmake_exec + "\", do you want to install a new Qt4 [y/n]? " ) # fi build_qmake.lower( ) build_cmake = "y" if cmake_exec <> None: build_cmake = raw_input( "CMake was found in \"" + cmake_exec + "\", do you want to install a new CMake [y/n]? " ) # fi build_cmake.lower( ) ## ----------------- ## -- Compile Qt4 -- ## ----------------- if build_qmake[ 0 ] == "y": print( "Compiling Qt4..." ) readline.set_completer_delims( ' \t\n;' ) readline.parse_and_bind( "tab: complete" ) readline.set_completer( complete ) qt4_file = os.path.abspath( raw_input( "\tCompressed file containing Qt4: " ) ) full = raw_input( "\tWould you like to perform a full build [y/n]? " ) full.lower( ) build_type = raw_input( "\tBuild type [release/debug]? " ) build_type.lower( ) if not decompress( qt4_file, "./qt4_source" ): print( "Unable to decompress Qt4." ) exit( 1 ) # fi qt4_source = os.path.abspath( "./qt4_source" ) os.system( "mkdir -p ./qt4_build" ) qt4_build = os.path.abspath( "./qt4_build" ) config_command = qt4_source + "/configure" config_command += " -prefix " + install_prefix config_command += " -" + build_type config_command += " -opensource -shared -fast -no-webkit -optimized-qmake -confirm-license" if full[ 0 ] == "n": config_command += " -no-phonon -no-phonon-backend -no-openvg -nomake demos -nomake examples" # fi ## MACOS: -no-framework ## Build and install res = os.system( "cd " + qt4_build + " && " + config_command ) if res <> 0: print( "Error configuring Qt4." ) exit( 1 ) # fi res = os.system( "cd " + qt4_build + " && make -j" + str( process_count ) ) if res <> 0: print( "Error compiling Qt4." ) exit( 1 ) # fi res = os.system( "cd " + qt4_build + " && make -j install" ) if res <> 0: print( "Error installing Qt4." ) exit( 1 ) # fi # fi ## eof - $RCSfile$