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] [-m=cmake_executable] [-t=build_type[MinSizeRel/Debug/Release]]"
40 ## Analyze command-line arguments
45 prefix="${HOME}/local"
46 build_type="MinSizeRel"
78 ## Check command line arguments
79 if [ "x$source_dir" == "x" ]; then
80 if [ "x$source_file" != "x" ]; then
81 base_path=`abspath $source_file`
82 base_ext=`get_file_extension $base_path`
83 base_dir=`dirname $base_path`
84 if [ "x$base_ext" != "x" ]; then
85 source_dir="$base_dir"/`basename $base_path .$base_ext`
87 echo "Error: Input compressed file extension not recognized."
95 if [ "x$build_dir" == "x" ]; then
96 if [ "x$source_dir" != "x" ]; then
98 if [ "${source_dir:$((${#str}-1)):1}" == "/" ]; then
99 base_dir=`echo $source_dir | rev | cut -c 2- | rev`
101 build_dir="$base_dir-build"
108 ## Locate cmake executable
109 if [ "x$cmake_exec" == "x" ]; then
110 cmake_locations=("/usr/bin" "/usr/local/bin" "${HOME}/local/bin")
112 for loc in ${cmake_locations[@]}; do
113 cmake_file="$loc/cmake"
114 if [ -x $cmake_file ]; then
115 str=`$cmake_file --version | grep version`
117 if [ "$cmake_ver" \< "$version" ]; then
119 cmake_exec=$cmake_file
124 if [ ! -x $cmake_exec ]; then
125 echo "ERROR: no valid cmake found."
128 cmake_exec=`abspath $cmake_exec`
130 ## Other configuration variables
132 number_of_cores=`grep -c ^processor /proc/cpuinfo`
133 number_of_threads=`expr $number_of_cores / 2`
134 if [ "x$source_file" != "x" ]; then
135 source_file=`abspath $source_file`
137 source_dir=`abspath $source_dir`
138 build_dir=`abspath $build_dir`
140 echo "====================================================================="
141 echo "==> Source file : $source_file"
142 echo "==> Source dir : $source_dir"
143 echo "==> Build dir : $build_dir"
144 echo "==> Build type : $build_type"
145 echo "==> Prefix : $prefix"
146 echo "==> cmake : $cmake_exec"
147 echo "==> Platform : $platform"
148 echo "==> Number of cores : $number_of_cores"
149 echo "==> Number of threads : $number_of_threads"
150 echo "====================================================================="
151 read -n1 -r -p "Continue? [Y/N]... " key
153 if [ "$key" != 'Y' -a "$key" != 'y' ] ; then
158 if [ "x$source_file" != "x" ]; then
159 echo -n "==> Cleaning directories... "
163 echo -n "==> Creating directories... "
169 ## Extract source code
170 if [ "x$source_file" != "x" ]; then
171 echo -n "==> Extracting sources... "
172 base_path=`abspath $source_file`
173 base_ext=`get_file_extension $base_path`
174 if [ "$base_ext" == "zip" ]; then
175 echo unzip $base_path
176 elif [ "$base_ext" == "tar" ]; then
177 tar xf $base_path -C $source_dir --strip-components=1
178 elif [ "$base_ext" == "tar.gz" ]; then
179 tar xzf $base_path -C $source_dir --strip-components=1
180 elif [ "$base_ext" == "tar.bz2" ]; then
181 tar xjf $base_path -C $source_dir --strip-components=1
186 echo "==> Configuring sources... "
189 -DCMAKE_CXX_FLAGS:STRING=-std=c++11 \
190 -DBUILD_DOCUMENTATION:BOOL=OFF \
191 -DBUILD_EXAMPLES:BOOL=OFF \
192 -DBUILD_SHARED_LIBS:BOOL=ON \
193 -DBUILD_TESTING:BOOL=OFF \
194 -DCMAKE_BUILD_TYPE:STRING=$build_type \
195 -DModule_ITKReview:BOOL=ON \
196 -DModule_ITKVtkGlue:BOOL=OFF \
197 -DModule_ParabolicMorphology:BOOL=ON \
198 -DCMAKE_INSTALL_PREFIX:PATH=$prefix \
200 echo "==> Configuring sources... done."
202 echo "==> Compiling sources..."
204 make -j$number_of_threads
205 echo "==> Compiling sources... done."
207 echo "==> Installing package..."
210 echo "==> Installing package... done."