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] [-m=cmake_executable] [-t=build_type[MinSizeRel/Debug/Release]]"
43 ## -------------------------------------------------------------------------
44 ## Analyze command-line arguments
49 prefix="${HOME}/local"
50 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 ## Other configuration variables
136 number_of_cores=`grep -c ^processor /proc/cpuinfo`
137 number_of_threads=`expr $number_of_cores / 2`
138 if [ "x$source_file" != "x" ]; then
139 source_file=`abspath $source_file`
141 source_dir=`abspath $source_dir`
142 build_dir=`abspath $build_dir`
144 echo "====================================================================="
145 echo "==> Source file : $source_file"
146 echo "==> Source dir : $source_dir"
147 echo "==> Build dir : $build_dir"
148 echo "==> Build type : $build_type"
149 echo "==> Prefix : $prefix"
150 echo "==> cmake : $cmake_exec"
151 echo "==> Platform : $platform"
152 echo "==> Number of cores : $number_of_cores"
153 echo "==> Number of threads : $number_of_threads"
154 echo "====================================================================="
155 read -n1 -r -p "Continue? [Y/N]... " key
157 if [ "$key" != 'Y' -a "$key" != 'y' ] ; then
162 if [ "x$source_file" != "x" ]; then
163 echo -n "==> Cleaning directories... "
167 echo -n "==> Creating directories... "
173 ## Extract source code
174 if [ "x$source_file" != "x" ]; then
175 echo -n "==> Extracting sources... "
176 base_path=`abspath $source_file`
177 base_ext=`get_file_extension $base_path`
178 if [ "$base_ext" == "zip" ]; then
179 echo unzip $base_path
180 elif [ "$base_ext" == "tar" ]; then
181 tar xf $base_path -C $source_dir --strip-components=1
182 elif [ "$base_ext" == "tar.gz" ]; then
183 tar xzf $base_path -C $source_dir --strip-components=1
184 elif [ "$base_ext" == "tar.bz2" ]; then
185 tar xjf $base_path -C $source_dir --strip-components=1
190 echo "==> Configuring sources... "
193 -DCMAKE_CXX_FLAGS:STRING=-std=c++11 \
194 -DBUILD_DOCUMENTATION:BOOL=OFF \
195 -DBUILD_EXAMPLES:BOOL=OFF \
196 -DBUILD_SHARED_LIBS:BOOL=ON \
197 -DBUILD_TESTING:BOOL=OFF \
198 -DCMAKE_BUILD_TYPE:STRING=$build_type \
199 -DModule_ITKReview:BOOL=ON \
200 -DModule_ITKVtkGlue:BOOL=OFF \
201 -DModule_ParabolicMorphology:BOOL=ON \
202 -DCMAKE_INSTALL_PREFIX:PATH=$prefix \
204 echo "==> Configuring sources... done."
206 echo "==> Compiling sources..."
208 make -j$number_of_threads
209 echo "==> Compiling sources... done."
211 echo "==> Installing package..."
214 echo "==> Installing package... done."