12 if [ "$cur_dir" == "/" ]; then
13 echo "$cur_dir`basename \"$1\"`"
15 echo "$cur_dir/`basename \"$1\"`"
21 function get_file_extension
23 valid_extensions=("zip" "tar" "tar.gz" "tar.bz2")
24 actual_file=`abspath $1`
26 for ext in ${valid_extensions[@]}; do
27 test_str=`dirname $actual_file`/`basename $actual_file $ext`
28 if [ $test_str != $actual_file ]; then
37 echo "Usage: `basename $0` -f=compressed_code -c=source_dir -b=build_dir [-p=instalation_prefix] [-q=qmake_executable]"
40 ## Analyze command-line arguments
45 prefix="${HOME}/local"
73 ## Check command line arguments
74 if [ "x$source_dir" == "x" ]; then
75 if [ "x$source_file" != "x" ]; then
76 base_path=`abspath $source_file`
77 base_ext=`get_file_extension $base_path`
78 base_dir=`dirname $base_path`
79 if [ "x$base_ext" != "x" ]; then
80 source_dir="$base_dir"/`basename $base_path .$base_ext`
82 echo "Error: Input compressed file extension not recognized."
90 if [ "x$build_dir" == "x" ]; then
91 if [ "x$source_dir" != "x" ]; then
93 if [ "${source_dir:$((${#str}-1)):1}" == "/" ]; then
94 base_dir=`echo $source_dir | rev | cut -c 2- | rev`
96 build_dir="$base_dir-build"
103 # Locate qmake executable
104 if [ "x$qmake_exec" == "x" ]; then
105 qmake_locations=("/usr/bin" "/usr/local/bin" "${HOME}/local/bin")
106 for loc in ${qmake_locations[@]}; do
107 qmake_file="$loc/qmake"
108 if [ -x $qmake_file ]; then
109 version=`$qmake_file --version | grep Using\ Qt\ version | cut -d ' ' -f 4`
110 if [ "${version:0:3}" == "4.8" ]; then
111 qmake_exec=$qmake_file
116 qmake_exec=`abspath $qmake_exec`
117 if [ -x $qmake_exec ]; then
118 qt_options="--qt-gui --qt-qmake=$qmake_exec"
120 qt_options="--no-qt-gui"
123 ## Other configuration variables
125 number_of_cores=`grep -c ^processor /proc/cpuinfo`
126 number_of_threads=`expr $number_of_cores / 2`
127 if [ "x$source_file" != "x" ]; then
128 source_file=`abspath $source_file`
130 source_dir=`abspath $source_dir`
131 build_dir=`abspath $build_dir`
133 echo "====================================================================="
134 echo "==> Source file : $source_file"
135 echo "==> Source dir : $source_dir"
136 echo "==> Build dir : $build_dir"
137 echo "==> Prefix : $prefix"
138 echo "==> qmake : $qmake_exec"
139 echo "==> Qt options : $qt_options"
140 echo "==> Platform : $platform"
141 echo "==> Number of cores : $number_of_cores"
142 echo "==> Number of threads : $number_of_threads"
143 echo "====================================================================="
144 read -n1 -r -p "Continue? [Y/N]... " key
146 if [ "$key" != 'Y' -a "$key" != 'y' ] ; then
151 if [ "x$source_file" != "x" ]; then
152 echo -n "==> Cleaning directories... "
156 echo -n "==> Creating directories... "
162 ## Extract source code
163 if [ "x$source_file" != "x" ]; then
164 echo -n "==> Extracting sources... "
165 base_path=`abspath $source_file`
166 base_ext=`get_file_extension $base_path`
167 if [ "$base_ext" == "zip" ]; then
168 echo unzip $base_path
169 elif [ "$base_ext" == "tar" ]; then
170 tar xf $base_path -C $source_dir --strip-components=1
171 elif [ "$base_ext" == "tar.gz" ]; then
172 tar xzf $base_path -C $source_dir --strip-components=1
173 elif [ "$base_ext" == "tar.bz2" ]; then
174 tar xjf $base_path -C $source_dir --strip-components=1
179 echo "==> Configuring sources... "
181 $source_dir/bootstrap --prefix=$prefix $qt_options
182 echo "==> Configuring sources... done."
184 echo "==> Compiling sources..."
186 make -j$number_of_threads
187 echo "==> Compiling sources... done."
189 echo "==> Installing package..."
192 echo "==> Installing package... done."