1 import os, platform, readline, glob, multiprocessing
2 from distutils import spawn
4 ## ------------------------
5 ## -- Filename completer --
6 ## ------------------------
8 def complete( text, state ):
9 return ( glob.glob( text + '*' ) + [ None ] )[ state ]
12 ## -----------------------
13 ## -- File decompressor --
14 ## -----------------------
16 def decompress( filename, outdir ):
18 for ext in [ ".zip", ".tar", ".tar.gz", ".tar.bz2" ]:
19 if filename[ len( filename ) - len( ext ) : ] == ext:
24 if real_ext == ".zip":
25 command = "unzip " + filename + " -d " + outdir
26 elif real_ext == ".tar":
27 command = "tar xf " + filename + " -C " + outdir + " --strip-components=1"
28 elif real_ext == ".tar.gz":
29 command = "tar xzf " + filename + " -C " + outdir + " --strip-components=1"
30 elif real_ext == ".tar.bz2":
31 command = "tar xjf " + filename + " -C " + outdir + " --strip-components=1"
34 print( "\tExtracting " + filename + "..." )
35 res = os.system( "mkdir -p " + outdir + " && " + command )
46 ## -------------------------
47 ## -- Find necessary data --
48 ## -------------------------
50 system_name = platform.system( )
51 process_count = multiprocessing.cpu_count( ) / 2
52 qmake_exec = spawn.find_executable( "qmake-qt4" )
53 cmake_exec = spawn.find_executable( "cmake" )
54 readline.set_completer_delims( ' \t\n;' )
55 readline.parse_and_bind( "tab: complete" )
56 readline.set_completer( complete )
57 install_prefix = os.path.abspath( raw_input( "Install prefix: " ) )
59 ## --------------------------------------------
60 ## -- Ask if new versions should be compiled --
61 ## --------------------------------------------
64 if qmake_exec <> None:
65 build_qmake = raw_input( "Qt4 was found in \"" + qmake_exec + "\", do you want to install a new Qt4 [y/n]? " )
70 if cmake_exec <> None:
71 build_cmake = raw_input( "CMake was found in \"" + cmake_exec + "\", do you want to install a new CMake [y/n]? " )
79 if build_qmake[ 0 ] == "y":
80 print( "Compiling Qt4..." )
81 readline.set_completer_delims( ' \t\n;' )
82 readline.parse_and_bind( "tab: complete" )
83 readline.set_completer( complete )
84 qt4_file = os.path.abspath(
85 raw_input( "\tCompressed file containing Qt4: " )
87 full = raw_input( "\tWould you like to perform a full build [y/n]? " )
89 build_type = raw_input( "\tBuild type [release/debug]? " )
91 if not decompress( qt4_file, "./qt4_source" ):
92 print( "Unable to decompress Qt4." )
95 qt4_source = os.path.abspath( "./qt4_source" )
96 os.system( "mkdir -p ./qt4_build" )
97 qt4_build = os.path.abspath( "./qt4_build" )
99 config_command = qt4_source + "/configure"
100 config_command += " -prefix " + install_prefix
101 config_command += " -" + build_type
102 config_command += " -opensource -shared -fast -no-webkit -optimized-qmake -confirm-license"
104 config_command += " -no-phonon -no-phonon-backend -no-openvg -nomake demos -nomake examples"
106 ## MACOS: -no-framework
109 res = os.system( "cd " + qt4_build + " && " + config_command )
111 print( "Error configuring Qt4." )
114 res = os.system( "cd " + qt4_build + " && make -j" + str( process_count ) )
116 print( "Error compiling Qt4." )
119 res = os.system( "cd " + qt4_build + " && make -j install" )
121 print( "Error installing Qt4." )