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] [-m=cmake_executable] [-t=build_type[MinSizeRel/Debug/Release]]"
43 ## -------------------------------------------------------------------------
44 ## Analyze command-line arguments
49 prefix="${HOME}/local"
50 build_type="MinSizeRel"
86 ## Check command line arguments
87 if [ "x$source_dir" == "x" ]; then
88 if [ "x$source_file" != "x" ]; then
89 base_path=`abspath $source_file`
90 base_ext=`get_file_extension $base_path`
91 base_dir=`dirname $base_path`
92 if [ "x$base_ext" != "x" ]; then
93 source_dir="$base_dir"/`basename $base_path .$base_ext`
95 echo "Error: Input compressed file extension not recognized."
103 if [ "x$build_dir" == "x" ]; then
104 if [ "x$source_dir" != "x" ]; then
106 if [ "${source_dir:$((${#str}-1)):1}" == "/" ]; then
107 base_dir=`echo $source_dir | rev | cut -c 2- | rev`
109 build_dir="$base_dir-build"
116 ## Locate cmake executable
117 if [ "x$cmake_exec" == "x" ]; then
118 cmake_locations=("/usr/bin" "/usr/local/bin" "${HOME}/local/bin")
120 for loc in ${cmake_locations[@]}; do
121 cmake_file="$loc/cmake"
122 if [ -x $cmake_file ]; then
123 str=`$cmake_file --version | grep version`
125 if [ "$cmake_ver" \< "$version" ]; then
127 cmake_exec=$cmake_file
132 if [ ! -x $cmake_exec ]; then
133 echo "ERROR: no valid cmake found."
136 cmake_exec=`abspath $cmake_exec`
138 # Locate qmake executable
139 if [ "x$qmake_exec" == "x" ]; then
140 qmake_locations=("/usr/bin" "/usr/local/bin" "${HOME}/local/bin")
141 for loc in ${qmake_locations[@]}; do
142 qmake_file="$loc/qmake"
143 if [ -x $qmake_file ]; then
144 version=`$qmake_file --version | grep Using\ Qt\ version | cut -d ' ' -f 4`
145 if [ "${version:0:3}" == "4.8" ]; then
146 qmake_exec=$qmake_file
151 qmake_exec=`abspath $qmake_exec`
152 if [ -x $qmake_exec ]; then
158 ## Other configuration variables
160 number_of_cores=`grep -c ^processor /proc/cpuinfo`
161 number_of_threads=`expr $number_of_cores / 2`
162 if [ "x$source_file" != "x" ]; then
163 source_file=`abspath $source_file`
165 source_dir=`abspath $source_dir`
166 build_dir=`abspath $build_dir`
168 echo "====================================================================="
169 echo "==> Source file : $source_file"
170 echo "==> Source dir : $source_dir"
171 echo "==> Build dir : $build_dir"
172 echo "==> Build type : $build_type"
173 echo "==> Prefix : $prefix"
174 echo "==> cmake : $cmake_exec"
175 echo "==> qmake : $qmake_exec"
176 echo "==> Use Qt : $use_qt"
177 echo "==> Platform : $platform"
178 echo "==> Number of cores : $number_of_cores"
179 echo "==> Number of threads : $number_of_threads"
180 echo "====================================================================="
181 read -n1 -r -p "Continue? [Y/N]... " key
183 if [ "$key" != 'Y' -a "$key" != 'y' ] ; then
188 if [ "x$source_file" != "x" ]; then
189 echo -n "==> Cleaning directories... "
193 echo -n "==> Creating directories... "
199 ## Extract source code
200 if [ "x$source_file" != "x" ]; then
201 echo -n "==> Extracting sources... "
202 base_path=`abspath $source_file`
203 base_ext=`get_file_extension $base_path`
204 if [ "$base_ext" == "zip" ]; then
205 echo unzip $base_path
206 elif [ "$base_ext" == "tar" ]; then
207 tar xf $base_path -C $source_dir --strip-components=1
208 elif [ "$base_ext" == "tar.gz" ]; then
209 tar xzf $base_path -C $source_dir --strip-components=1
210 elif [ "$base_ext" == "tar.bz2" ]; then
211 tar xjf $base_path -C $source_dir --strip-components=1
216 echo "==> Configuring sources... "
218 if [ "$use_qt" == "1" ]; then
220 -DCMAKE_CXX_FLAGS:STRING=-std=c++11 \
221 -DBUILD_DOCUMENTATION:BOOL=OFF \
222 -DBUILD_EXAMPLES:BOOL=OFF \
223 -DBUILD_SHARED_LIBS:BOOL=ON \
224 -DBUILD_TESTING:BOOL=OFF \
225 -DQT_QMAKE_EXECUTABLE:PATH=$qmake_exec \
226 -DCMAKE_BUILD_TYPE:STRING=$build_type \
227 -DModule_vtkGUISupportQt:BOOL=ON \
228 -DModule_vtkGUISupportQtOpenGL:BOOL=ON \
229 -DModule_vtkGUISupportQtSQL:BOOL=OFF \
230 -DModule_vtkGUISupportQtWebkit:BOOL=OFF \
231 -DCMAKE_INSTALL_PREFIX:PATH=$prefix \
235 -DCMAKE_CXX_FLAGS:STRING=-std=c++11 \
236 -DBUILD_DOCUMENTATION:BOOL=OFF \
237 -DBUILD_EXAMPLES:BOOL=OFF \
238 -DBUILD_SHARED_LIBS:BOOL=ON \
239 -DBUILD_TESTING:BOOL=OFF \
240 -DCMAKE_BUILD_TYPE:STRING=$build_type \
241 -DCMAKE_INSTALL_PREFIX:PATH=$prefix \
244 echo "==> Configuring sources... done."
246 echo "==> Compiling sources..."
248 make -j$number_of_threads
249 echo "==> Compiling sources... done."
251 echo "==> Installing package..."
254 echo "==> Installing package... done."