3 ## -------------------------------------------------------------------------
13 if [ "$cur_dir" == "/" ]; then
14 echo "$cur_dir`basename \"$1\"`"
16 echo "$cur_dir/`basename \"$1\"`"
22 ## -------------------------------------------------------------------------
23 function get_file_extension
25 valid_extensions=("zip" "tar" "tar.gz" "tar.bz2")
26 actual_file=`abspath $1`
28 for ext in ${valid_extensions[@]}; do
29 test_str=`dirname $actual_file`/`basename $actual_file $ext`
30 if [ $test_str != $actual_file ]; then
37 ## -------------------------------------------------------------------------
40 echo "Usage: `basename $0` -f=compressed_code -c=source_dir -b=build_dir [-p=instalation_prefix] [-q=qmake_executable]"
43 ## -------------------------------------------------------------------------
44 ## Analyze command-line arguments
49 prefix="${HOME}/local"
77 ## Check command line arguments
78 if [ "x$source_dir" == "x" ]; then
79 if [ "x$source_file" != "x" ]; then
80 base_path=`abspath $source_file`
81 base_ext=`get_file_extension $base_path`
82 base_dir=`dirname $base_path`
83 if [ "x$base_ext" != "x" ]; then
84 source_dir="$base_dir"/`basename $base_path .$base_ext`
86 echo "Error: Input compressed file extension not recognized."
94 if [ "x$build_dir" == "x" ]; then
95 if [ "x$source_dir" != "x" ]; then
97 if [ "${source_dir:$((${#str}-1)):1}" == "/" ]; then
98 base_dir=`echo $source_dir | rev | cut -c 2- | rev`
100 build_dir="$base_dir-build"
107 # Locate qmake executable
108 if [ "x$qmake_exec" == "x" ]; then
109 qmake_locations=("/usr/bin" "/usr/local/bin" "${HOME}/local/bin")
110 for loc in ${qmake_locations[@]}; do
111 qmake_file="$loc/qmake"
112 if [ -x $qmake_file ]; then
113 version=`$qmake_file --version | grep Using\ Qt\ version | cut -d ' ' -f 4`
114 if [ "${version:0:3}" == "4.8" ]; then
115 qmake_exec=$qmake_file
120 qmake_exec=`abspath $qmake_exec`
121 if [ -x $qmake_exec ]; then
122 qt_options="--qt-gui --qt-qmake=$qmake_exec"
124 qt_options="--no-qt-gui"
127 ## Other configuration variables
129 number_of_cores=`grep -c ^processor /proc/cpuinfo`
130 number_of_threads=`expr $number_of_cores / 2`
131 if [ "x$source_file" != "x" ]; then
132 source_file=`abspath $source_file`
134 source_dir=`abspath $source_dir`
135 build_dir=`abspath $build_dir`
137 echo "====================================================================="
138 echo "==> Source file : $source_file"
139 echo "==> Source dir : $source_dir"
140 echo "==> Build dir : $build_dir"
141 echo "==> Prefix : $prefix"
142 echo "==> qmake : $qmake_exec"
143 echo "==> Qt options : $qt_options"
144 echo "==> Platform : $platform"
145 echo "==> Number of cores : $number_of_cores"
146 echo "==> Number of threads : $number_of_threads"
147 echo "====================================================================="
148 read -n1 -r -p "Continue? [Y/N]... " key
150 if [ "$key" != 'Y' -a "$key" != 'y' ] ; then
155 if [ "x$source_file" != "x" ]; then
156 echo -n "==> Cleaning directories... "
160 echo -n "==> Creating directories... "
166 ## Extract source code
167 if [ "x$source_file" != "x" ]; then
168 echo -n "==> Extracting sources... "
169 base_path=`abspath $source_file`
170 base_ext=`get_file_extension $base_path`
171 if [ "$base_ext" == "zip" ]; then
172 echo unzip $base_path
173 elif [ "$base_ext" == "tar" ]; then
174 tar xf $base_path -C $source_dir --strip-components=1
175 elif [ "$base_ext" == "tar.gz" ]; then
176 tar xzf $base_path -C $source_dir --strip-components=1
177 elif [ "$base_ext" == "tar.bz2" ]; then
178 tar xjf $base_path -C $source_dir --strip-components=1
183 echo "==> Configuring sources... "
185 $source_dir/bootstrap --prefix=$prefix $qt_options
186 echo "==> Configuring sources... done."
188 echo "==> Compiling sources..."
190 make -j$number_of_threads
191 echo "==> Compiling sources... done."
193 echo "==> Installing package..."
196 echo "==> Installing package... done."