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] [-m=cmake_executable] [-t=build_type[MinSizeRel/Debug/Release]]"
40 ## Analyze command-line arguments
45 prefix="${HOME}/local"
46 build_type="MinSizeRel"
82 ## Check command line arguments
83 if [ "x$source_dir" == "x" ]; then
84 if [ "x$source_file" != "x" ]; then
85 base_path=`abspath $source_file`
86 base_ext=`get_file_extension $base_path`
87 base_dir=`dirname $base_path`
88 if [ "x$base_ext" != "x" ]; then
89 source_dir="$base_dir"/`basename $base_path .$base_ext`
91 echo "Error: Input compressed file extension not recognized."
99 if [ "x$build_dir" == "x" ]; then
100 if [ "x$source_dir" != "x" ]; then
102 if [ "${source_dir:$((${#str}-1)):1}" == "/" ]; then
103 base_dir=`echo $source_dir | rev | cut -c 2- | rev`
105 build_dir="$base_dir-build"
112 ## Locate cmake executable
113 if [ "x$cmake_exec" == "x" ]; then
114 cmake_locations=("/usr/bin" "/usr/local/bin" "${HOME}/local/bin")
116 for loc in ${cmake_locations[@]}; do
117 cmake_file="$loc/cmake"
118 if [ -x $cmake_file ]; then
119 str=`$cmake_file --version | grep version`
121 if [ "$cmake_ver" \< "$version" ]; then
123 cmake_exec=$cmake_file
128 if [ ! -x $cmake_exec ]; then
129 echo "ERROR: no valid cmake found."
132 cmake_exec=`abspath $cmake_exec`
134 # Locate qmake executable
135 if [ "x$qmake_exec" == "x" ]; then
136 qmake_locations=("/usr/bin" "/usr/local/bin" "${HOME}/local/bin")
137 for loc in ${qmake_locations[@]}; do
138 qmake_file="$loc/qmake"
139 if [ -x $qmake_file ]; then
140 version=`$qmake_file --version | grep Using\ Qt\ version | cut -d ' ' -f 4`
141 if [ "${version:0:3}" == "4.8" ]; then
142 qmake_exec=$qmake_file
147 qmake_exec=`abspath $qmake_exec`
148 if [ -x $qmake_exec ]; then
154 ## Other configuration variables
156 number_of_cores=`grep -c ^processor /proc/cpuinfo`
157 number_of_threads=`expr $number_of_cores / 2`
158 if [ "x$source_file" != "x" ]; then
159 source_file=`abspath $source_file`
161 source_dir=`abspath $source_dir`
162 build_dir=`abspath $build_dir`
164 echo "====================================================================="
165 echo "==> Source file : $source_file"
166 echo "==> Source dir : $source_dir"
167 echo "==> Build dir : $build_dir"
168 echo "==> Build type : $build_type"
169 echo "==> Prefix : $prefix"
170 echo "==> cmake : $cmake_exec"
171 echo "==> qmake : $qmake_exec"
172 echo "==> Use Qt : $use_qt"
173 echo "==> Platform : $platform"
174 echo "==> Number of cores : $number_of_cores"
175 echo "==> Number of threads : $number_of_threads"
176 echo "====================================================================="
177 read -n1 -r -p "Continue? [Y/N]... " key
179 if [ "$key" != 'Y' -a "$key" != 'y' ] ; then
184 if [ "x$source_file" != "x" ]; then
185 echo -n "==> Cleaning directories... "
189 echo -n "==> Creating directories... "
195 ## Extract source code
196 if [ "x$source_file" != "x" ]; then
197 echo -n "==> Extracting sources... "
198 base_path=`abspath $source_file`
199 base_ext=`get_file_extension $base_path`
200 if [ "$base_ext" == "zip" ]; then
201 echo unzip $base_path
202 elif [ "$base_ext" == "tar" ]; then
203 tar xf $base_path -C $source_dir --strip-components=1
204 elif [ "$base_ext" == "tar.gz" ]; then
205 tar xzf $base_path -C $source_dir --strip-components=1
206 elif [ "$base_ext" == "tar.bz2" ]; then
207 tar xjf $base_path -C $source_dir --strip-components=1
212 echo "==> Configuring sources... "
214 if [ "$use_qt" == "1" ]; then
216 -DCMAKE_CXX_FLAGS:STRING=-std=c++11 \
217 -DBUILD_DOCUMENTATION:BOOL=OFF \
218 -DBUILD_EXAMPLES:BOOL=OFF \
219 -DBUILD_SHARED_LIBS:BOOL=ON \
220 -DBUILD_TESTING:BOOL=OFF \
221 -DQT_QMAKE_EXECUTABLE:PATH=$qmake_exec \
222 -DCMAKE_BUILD_TYPE:STRING=$build_type \
223 -DModule_vtkGUISupportQt:BOOL=ON \
224 -DModule_vtkGUISupportQtOpenGL:BOOL=ON \
225 -DModule_vtkGUISupportQtSQL:BOOL=OFF \
226 -DModule_vtkGUISupportQtWebkit:BOOL=OFF \
227 -DCMAKE_INSTALL_PREFIX:PATH=$prefix \
231 -DCMAKE_CXX_FLAGS:STRING=-std=c++11 \
232 -DBUILD_DOCUMENTATION:BOOL=OFF \
233 -DBUILD_EXAMPLES:BOOL=OFF \
234 -DBUILD_SHARED_LIBS:BOOL=ON \
235 -DBUILD_TESTING:BOOL=OFF \
236 -DCMAKE_BUILD_TYPE:STRING=$build_type \
237 -DCMAKE_INSTALL_PREFIX:PATH=$prefix \
240 echo "==> Configuring sources... done."
242 echo "==> Compiling sources..."
244 make -j$number_of_threads
245 echo "==> Compiling sources... done."
247 echo "==> Installing package..."
250 echo "==> Installing package... done."