From ceb40effc0c82a31782dacd360ec0f9bb86670ef Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leonardo=20Fl=C3=B3rez-Valencia?= Date: Thu, 20 Apr 2017 15:16:20 -0500 Subject: [PATCH] ... --- install/cpPlugins_Install_Dependencies.sh | 409 +++++++++++----------- install/cpPlugins_Install_Functions.sh | 90 +++-- 2 files changed, 261 insertions(+), 238 deletions(-) diff --git a/install/cpPlugins_Install_Dependencies.sh b/install/cpPlugins_Install_Dependencies.sh index c18416d..cbfb986 100755 --- a/install/cpPlugins_Install_Dependencies.sh +++ b/install/cpPlugins_Install_Dependencies.sh @@ -1,6 +1,5 @@ #!/bin/bash - # =================== # = Welcome message = # =================== @@ -14,39 +13,53 @@ echo "#######################################################################" # = Various values = # ================== -number_of_cores=`nproc --all` -number_of_threads=`expr $number_of_cores / 2` -install_prefix="$HOME/local" -build_type="release" -linking_mode="shared" +number_of_threads="nope" +while ! [[ "$number_of_threads" =~ ^[0-9]+$ ]]; do + echo -n "--> How many threads do you want to use to compile?: " + read number_of_threads +done +read -e -p "--> Please provide where you want to install the packages I will generate: " tmp +install_prefix="${tmp/#\~/$HOME}" +echo "--> What kind of compilation will you want to perform?" +echo " [0] Debug" +echo " [1] Release" +echo -n " Please choose a number and press [ENTER]: " +read choice +qt_build_type="release" +tk_build_type="MinSizeRel" +if [ "$choice" -eq 0 ]; then + qt_build_type="debug" + tk_build_type="Debug" +fi +echo "--> What kind of linkage will you want to perform?" +echo " [0] Static" +echo " [1] Shared" +echo -n " Please choose a number and press [ENTER]: " +read choice +link_type="shared" +if [ "$choice" -eq 0 ]; then + link_type="static" +fi cur_dir=`pwd` bash_dir=`readlink -f ${0/#\~/$HOME} | xargs dirname` echo "#######################################################################" -echo " Number of cores : $number_of_cores " -echo " Number of threads : $number_of_threads " -echo " Install prefix : $install_prefix " -echo " Build type : $build_type " -echo " Linking mode : $linking_mode " -echo " Current directory : $cur_dir " -echo " Bash directory : $bash_dir " +echo " PLEASE REVIEW THE FOLLOWING INFORMATION:" +echo "#######################################################################" +echo " Number of threads : $number_of_threads" +echo " Install prefix : $install_prefix" +echo " Build type : $qt_build_type;$tk_build_type" +echo " Linking mode : $link_type" +echo " Current directory : $cur_dir" +echo " Bash directory : $bash_dir" echo "#######################################################################" read -p "Is this ok? [y/N] " -n 1 -r echo if [[ $REPLY =~ ^[Nn]$ ]]; then - echo "Sorry to hear this. Please change these values by modifying this script." + echo "Sorry to hear this. Please change these values by re-executing this script." exit 1 fi -if [ "$build_type" == "release" ]; then - itk_build_type="MinSizeRel" - vtk_build_type="MinSizeRel" -else - itk_build_type="Debug" - vtk_build_type="Debug" -fi - - # ===================== # = Include functions = # ===================== @@ -63,203 +76,193 @@ if [[ $REPLY =~ ^[Yy]$ ]]; then echo "#####################" echo "# Configuring Qt4.8 #" echo "#####################" - qmake_exe=`find_executables qmake qmake-qt4` + qmake_exe=`choose_installation \`which -a qmake qmake-qt4\`` if [ "x$qmake_exe" == "x" ]; then - qmake_source_dir="" - qmake_binary_dir="" - echo "----> Ok, we will compile Qt4.8 from source code <----" - read -e -p "--> Please provide a valid location of Qt4.8's source code (either a compressed file or directory): " tmp - qmake_loc=`readlink -f ${tmp/#\~/$HOME}` - if [[ -f $qmake_loc ]]; then - echo -n "--> Expanding Qt4.8 source code... " - qmake_source_dir=`dirname $qmake_loc`/`echo \`basename $qmake_loc\` | sed 's/\./_/g'`_sources - qmake_binary_dir=`dirname $qmake_loc`/`echo \`basename $qmake_loc\` | sed 's/\./_/g'`_binary - rm -rf $qmake_source_dir $qmake_binary_dir - mkdir -p $qmake_source_dir - uncompress $qmake_loc $qmake_source_dir - echo "done!" - else - qmake_source_dir=$qmake_loc - qmake_binary_dir="$qmake_loc"_binary - fi + qmake_source_dir=`prepare_compilation` + qmake_binary_dir="$qmake_source_dir"_build + rm -rf $qmake_binary_dir mkdir -p $qmake_binary_dir cd $qmake_binary_dir $qmake_source_dir/configure \ - -$build_type -opensource -$linking_mode -fast \ + -$qt_build_type -opensource -$link_type -fast \ -optimized-qmake -confirm-license \ -nomake demos -nomake examples \ -prefix $install_prefix make -j$number_of_threads -k make -j install cd $cur_dir - qmake_exe="" - qmake_execs=($install_prefix/bin/qmake $install_prefix/bin/qmake-qt4) - for i in $qmake_execs; do - if [[ -f "$i" ]]; then - qmake_exe=$i - break - fi - done - fi - if [ "x$qmake_exe" == "x" ]; then - echo "Sorry, could not find a vaild qmake executable. Bailing out!!!" - exit 1 - fi - qt_version=`$qmake_exe -v | grep Using\ Qt\ version | sed 's/Using\ Qt\ version\ //g'` - if version_gt 4.8 $qt_version; then - echo "*** FATAL ERROR: your Qt version is $qt_version, but needed version should be 4.8 ***" fi fi -# =============== -# = Build CMake = -# =============== -echo "#####################" -echo "# Configuring CMake #" -echo "#####################" -cmake_exe=`find_executables cmake` -if [ "x$cmake_exe" == "x" ]; then - cmake_source_dir="" - cmake_binary_dir="" - echo "----> Ok, we will compile CMake from source code <----" - read -e -p "--> Please provide a valid location of CMake's source code (either a compressed file or directory): " tmp - cmake_loc=`readlink -f ${tmp/#\~/$HOME}` - if [[ -f $cmake_loc ]]; then - echo -n "--> Expanding CMake source code... " - cmake_source_dir=`dirname $cmake_loc`/`echo \`basename $cmake_loc\` | sed 's/\./_/g'`_sources - cmake_binary_dir=`dirname $cmake_loc`/`echo \`basename $cmake_loc\` | sed 's/\./_/g'`_binary - rm -rf $cmake_source_dir $cmake_binary_dir - mkdir -p $cmake_source_dir - uncompress $cmake_loc $cmake_source_dir - echo "done!" - else - cmake_source_dir=$cmake_loc - cmake_binary_dir="$cmake_loc"_binary - fi - cmake_qt_options="--no-qt-gui" - if [ -x "$qmake_exe" ]; then - cmake_qt_options="--qt-gui --qt-qmake=$qmake_exe" - fi - mkdir -p $cmake_binary_dir - cd $cmake_binary_dir - $cmake_source_dir/bootstrap --prefix=$install_prefix $cmake_qt_options - make -j$number_of_threads -k - make -j install - cd $cur_dir - cmake_exe="" - cmake_execs=($install_prefix/bin/cmake) - for i in $cmake_execs; do - if [[ -f "$i" ]]; then - cmake_exe=$i - break - fi - done -fi -if [ "x$cmake_exe" == "x" ]; then - echo "Sorry, could not find a vaild cmake executable. Bailing out!!!" - exit 1 -fi -cmake_version=`$cmake_exe -version | grep cmake\ version | sed 's/cmake\ version\ //g'` -if version_gt 3.0 $cmake_version; then - echo "*** FATAL ERROR: your CMake version is $cmake_version, but needed version should be at least 3.0 ***" -fi +# qmake_exe="" +# qmake_execs=($install_prefix/bin/qmake $install_prefix/bin/qmake-qt4) +# for i in $qmake_execs; do +# if [[ -f "$i" ]]; then +# qmake_exe=$i +# break +# fi +# done +# fi +# if [ "x$qmake_exe" == "x" ]; then +# echo "Sorry, could not find a vaild qmake executable. Bailing out!!!" +# exit 1 +# fi +# qt_version=`$qmake_exe -v | grep Using\ Qt\ version | sed 's/Using\ Qt\ version\ //g'` +# if version_gt 4.8 $qt_version; then +# echo "*** FATAL ERROR: your Qt version is $qt_version, but needed version should be 4.8 ***" +# fi +# fi -# ============= -# = Build ITK = -# ============= +# # =============== +# # = Build CMake = +# # =============== -echo "#####################" -echo "# Configuring ITK #" -echo "#####################" -itk_source_dir="" -itk_binary_dir="" -echo "----> Ok, we will compile ITK from source code <----" -read -e -p "--> Please provide a valid location of ITK's source code (either a compressed file or directory): " tmp -itk_loc=`readlink -f ${tmp/#\~/$HOME}` -if [[ -f $itk_loc ]]; then - echo -n "--> Expanding ITK source code... " - itk_source_dir=`dirname $itk_loc`/`echo \`basename $itk_loc\` | sed 's/\./_/g'`_sources - itk_binary_dir=`dirname $itk_loc`/`echo \`basename $itk_loc\` | sed 's/\./_/g'`_binary - rm -rf $itk_source_dir $itk_binary_dir - mkdir -p $itk_source_dir - uncompress $itk_loc $itk_source_dir - echo "done!" -else - itk_source_dir=$itk_loc - itk_binary_dir="$itk_loc"_binary -fi -mkdir -p $itk_binary_dir -cd $itk_binary_dir -$cmake_exe \ - -DCMAKE_CXX_FLAGS:STRING=-std=c++11 \ - -DBUILD_DOCUMENTATION:BOOL=OFF \ - -DBUILD_EXAMPLES:BOOL=OFF \ - -DBUILD_SHARED_LIBS:BOOL=ON \ - -DBUILD_TESTING:BOOL=OFF \ - -DCMAKE_BUILD_TYPE:STRING=$itk_build_type \ - -DModule_ITKReview:BOOL=ON \ - -DModule_ITKVtkGlue:BOOL=OFF \ - -DCMAKE_INSTALL_PREFIX:PATH=$install_prefix \ - $itk_source_dir -make -j$number_of_threads -k -make -j install -cd $cur_dir +# echo "#####################" +# echo "# Configuring CMake #" +# echo "#####################" +# cmake_exe=`find_executables cmake` +# if [ "x$cmake_exe" == "x" ]; then +# cmake_source_dir="" +# cmake_binary_dir="" +# echo "----> Ok, we will compile CMake from source code <----" +# read -e -p "--> Please provide a valid location of CMake's source code (either a compressed file or directory): " tmp +# cmake_loc=`readlink -f ${tmp/#\~/$HOME}` +# if [[ -f $cmake_loc ]]; then +# echo -n "--> Expanding CMake source code... " +# cmake_source_dir=`dirname $cmake_loc`/`echo \`basename $cmake_loc\` | sed 's/\./_/g'`_sources +# cmake_binary_dir=`dirname $cmake_loc`/`echo \`basename $cmake_loc\` | sed 's/\./_/g'`_binary +# rm -rf $cmake_source_dir $cmake_binary_dir +# mkdir -p $cmake_source_dir +# uncompress $cmake_loc $cmake_source_dir +# echo "done!" +# else +# cmake_source_dir=$cmake_loc +# cmake_binary_dir="$cmake_loc"_binary +# fi +# cmake_qt_options="--no-qt-gui" +# if [ -x "$qmake_exe" ]; then +# cmake_qt_options="--qt-gui --qt-qmake=$qmake_exe" +# fi +# mkdir -p $cmake_binary_dir +# cd $cmake_binary_dir +# $cmake_source_dir/bootstrap --prefix=$install_prefix $cmake_qt_options +# make -j$number_of_threads -k +# make -j install +# cd $cur_dir +# cmake_exe="" +# cmake_execs=($install_prefix/bin/cmake) +# for i in $cmake_execs; do +# if [[ -f "$i" ]]; then +# cmake_exe=$i +# break +# fi +# done +# fi +# if [ "x$cmake_exe" == "x" ]; then +# echo "Sorry, could not find a vaild cmake executable. Bailing out!!!" +# exit 1 +# fi +# cmake_version=`$cmake_exe -version | grep cmake\ version | sed 's/cmake\ version\ //g'` +# if version_gt 3.0 $cmake_version; then +# echo "*** FATAL ERROR: your CMake version is $cmake_version, but needed version should be at least 3.0 ***" +# fi -# ============= -# = Build VTK = -# ============= +# # ============= +# # = Build ITK = +# # ============= -echo "#####################" -echo "# Configuring VTK #" -echo "#####################" -vtk_source_dir="" -vtk_binary_dir="" -echo "----> Ok, we will compile VTK from source code <----" -read -e -p "--> Please provide a valid location of VTK's source code (either a compressed file or directory): " tmp -vtk_loc=`readlink -f ${tmp/#\~/$HOME}` -if [[ -f $vtk_loc ]]; then - echo -n "--> Expanding VTK source code... " - vtk_source_dir=`dirname $vtk_loc`/`echo \`basename $vtk_loc\` | sed 's/\./_/g'`_sources - vtk_binary_dir=`dirname $vtk_loc`/`echo \`basename $vtk_loc\` | sed 's/\./_/g'`_binary - rm -rf $vtk_source_dir $vtk_binary_dir - mkdir -p $vtk_source_dir - uncompress $vtk_loc $vtk_source_dir - echo "done!" -else - vtk_source_dir=$vtk_loc - vtk_binary_dir="$vtk_loc"_binary -fi -mkdir -p $vtk_binary_dir -cd $vtk_binary_dir -if [ "x$qmake_exe" == "x" ]; then - $cmake_exe \ - -DCMAKE_CXX_FLAGS:STRING=-std=c++11 \ - -DBUILD_DOCUMENTATION:BOOL=OFF \ - -DBUILD_EXAMPLES:BOOL=OFF \ - -DBUILD_SHARED_LIBS:BOOL=ON \ - -DBUILD_TESTING:BOOL=OFF \ - -DCMAKE_BUILD_TYPE:STRING=$vtk_build_type \ - -DCMAKE_INSTALL_PREFIX:PATH=$install_prefix \ - $vtk_source_dir -else - $cmake_exe \ - -DCMAKE_CXX_FLAGS:STRING=-std=c++11 \ - -DBUILD_DOCUMENTATION:BOOL=OFF \ - -DBUILD_EXAMPLES:BOOL=OFF \ - -DBUILD_SHARED_LIBS:BOOL=ON \ - -DBUILD_TESTING:BOOL=OFF \ - -DQT_QMAKE_EXECUTABLE:PATH=$qmake_exe \ - -DCMAKE_BUILD_TYPE:STRING=$vtk_build_type \ - -DModule_vtkGUISupportQt:BOOL=ON \ - -DModule_vtkGUISupportQtOpenGL:BOOL=ON \ - -DModule_vtkGUISupportQtSQL:BOOL=OFF \ - -DModule_vtkGUISupportQtWebkit:BOOL=OFF \ - -DCMAKE_INSTALL_PREFIX:PATH=$install_prefix \ - $vtk_source_dir -fi -make -j$number_of_threads -k -make -j install -cd $cur_dir +# echo "#####################" +# echo "# Configuring ITK #" +# echo "#####################" +# itk_source_dir="" +# itk_binary_dir="" +# echo "----> Ok, we will compile ITK from source code <----" +# read -e -p "--> Please provide a valid location of ITK's source code (either a compressed file or directory): " tmp +# itk_loc=`readlink -f ${tmp/#\~/$HOME}` +# if [[ -f $itk_loc ]]; then +# echo -n "--> Expanding ITK source code... " +# itk_source_dir=`dirname $itk_loc`/`echo \`basename $itk_loc\` | sed 's/\./_/g'`_sources +# itk_binary_dir=`dirname $itk_loc`/`echo \`basename $itk_loc\` | sed 's/\./_/g'`_binary +# rm -rf $itk_source_dir $itk_binary_dir +# mkdir -p $itk_source_dir +# uncompress $itk_loc $itk_source_dir +# echo "done!" +# else +# itk_source_dir=$itk_loc +# itk_binary_dir="$itk_loc"_binary +# fi +# mkdir -p $itk_binary_dir +# cd $itk_binary_dir +# $cmake_exe \ +# -DCMAKE_CXX_FLAGS:STRING=-std=c++11 \ +# -DBUILD_DOCUMENTATION:BOOL=OFF \ +# -DBUILD_EXAMPLES:BOOL=OFF \ +# -DBUILD_SHARED_LIBS:BOOL=ON \ +# -DBUILD_TESTING:BOOL=OFF \ +# -DCMAKE_BUILD_TYPE:STRING=$itk_build_type \ +# -DModule_ITKReview:BOOL=ON \ +# -DModule_ITKVtkGlue:BOOL=OFF \ +# -DCMAKE_INSTALL_PREFIX:PATH=$install_prefix \ +# $itk_source_dir +# make -j$number_of_threads -k +# make -j install +# cd $cur_dir + +# # ============= +# # = Build VTK = +# # ============= + +# echo "#####################" +# echo "# Configuring VTK #" +# echo "#####################" +# vtk_source_dir="" +# vtk_binary_dir="" +# echo "----> Ok, we will compile VTK from source code <----" +# read -e -p "--> Please provide a valid location of VTK's source code (either a compressed file or directory): " tmp +# vtk_loc=`readlink -f ${tmp/#\~/$HOME}` +# if [[ -f $vtk_loc ]]; then +# echo -n "--> Expanding VTK source code... " +# vtk_source_dir=`dirname $vtk_loc`/`echo \`basename $vtk_loc\` | sed 's/\./_/g'`_sources +# vtk_binary_dir=`dirname $vtk_loc`/`echo \`basename $vtk_loc\` | sed 's/\./_/g'`_binary +# rm -rf $vtk_source_dir $vtk_binary_dir +# mkdir -p $vtk_source_dir +# uncompress $vtk_loc $vtk_source_dir +# echo "done!" +# else +# vtk_source_dir=$vtk_loc +# vtk_binary_dir="$vtk_loc"_binary +# fi +# mkdir -p $vtk_binary_dir +# cd $vtk_binary_dir +# if [ "x$qmake_exe" == "x" ]; then +# $cmake_exe \ +# -DCMAKE_CXX_FLAGS:STRING=-std=c++11 \ +# -DBUILD_DOCUMENTATION:BOOL=OFF \ +# -DBUILD_EXAMPLES:BOOL=OFF \ +# -DBUILD_SHARED_LIBS:BOOL=ON \ +# -DBUILD_TESTING:BOOL=OFF \ +# -DCMAKE_BUILD_TYPE:STRING=$vtk_build_type \ +# -DCMAKE_INSTALL_PREFIX:PATH=$install_prefix \ +# $vtk_source_dir +# else +# $cmake_exe \ +# -DCMAKE_CXX_FLAGS:STRING=-std=c++11 \ +# -DBUILD_DOCUMENTATION:BOOL=OFF \ +# -DBUILD_EXAMPLES:BOOL=OFF \ +# -DBUILD_SHARED_LIBS:BOOL=ON \ +# -DBUILD_TESTING:BOOL=OFF \ +# -DQT_QMAKE_EXECUTABLE:PATH=$qmake_exe \ +# -DCMAKE_BUILD_TYPE:STRING=$vtk_build_type \ +# -DModule_vtkGUISupportQt:BOOL=ON \ +# -DModule_vtkGUISupportQtOpenGL:BOOL=ON \ +# -DModule_vtkGUISupportQtSQL:BOOL=OFF \ +# -DModule_vtkGUISupportQtWebkit:BOOL=OFF \ +# -DCMAKE_INSTALL_PREFIX:PATH=$install_prefix \ +# $vtk_source_dir +# fi +# make -j$number_of_threads -k +# make -j install +# cd $cur_dir ## eof - $RCSfile$ diff --git a/install/cpPlugins_Install_Functions.sh b/install/cpPlugins_Install_Functions.sh index f69aca0..311fc07 100644 --- a/install/cpPlugins_Install_Functions.sh +++ b/install/cpPlugins_Install_Functions.sh @@ -51,45 +51,65 @@ function uncompress { eval $uz_command } -# ============================= -# = Find executables function = -# ============================= +# ================================ +# = Choose installation function = +# ================================ -function find_executables { - exe="" - execs=`which -a $@` - if [ "${#execs[@]}" -gt "0" ]; then - (>&2 echo "--> I have found a(some) executable(s), please choose one:") - c=0 - choices=() - for i in ${execs[@]}; do - (>&2 echo " [$c] $i") - choices+=("$i") - c=$[$c+1] - done - (>&2 echo " [$c] Manually choose another installation") - c=$[$c+1] - (>&2 echo " [$c] Compile from source code") - (>&2 echo -n " Please choose a number and press [ENTER]: ") - read choice - if [ "$choice" -lt "${#choices[@]}" ]; then - exe=${choices[$choice]} - elif [ "$choice" -eq "${#choices[@]}" ]; then - read -e -p "Please provide a valid location: " tmp - exe=`readlink -f ${tmp/#\~/$HOME}` - fi +function choose_installation { + ## Load choices + choices=() + for i in $@; do + choices+=("$i") + done + + ## Print menu + if [ "${#choices[@]}" -eq 0 ]; then + (>&2 echo "--> I have not found any installation, please choose:") else - (>&2 echo "--> I have not found any valid install, please choose:") - (>&2 echo " [0] Manually choose an installation") - (>&2 echo " [1] Compile from source code") - (>&2 echo -n " Please choose a number and press [ENTER]: ") - read choice - if [ "$choice" -eq "0" ]; then - read -e -p "Please provide a valid location: " tmp - exe=`readlink -f ${tmp/#\~/$HOME}` - fi + (>&2 echo "--> I have found a(some) installation(s), please choose one:") + fi + c=0 + for i in ${choices[@]}; do + (>&2 echo " [$c] $i") + c=$[$c+1] + done + (>&2 echo " [$c] Manually choose another installation") + c=$[$c+1] + (>&2 echo " [$c] Compile from source code") + + ## Get user input + (>&2 echo -n " Please choose a number and press [ENTER]: ") + read choice + exe="" + if [ "$choice" -lt "${#choices[@]}" ]; then + exe=${choices[$choice]} + elif [ "$choice" -eq "${#choices[@]}" ]; then + read -e -p "Please provide a valid location: " tmp + exe=`readlink -f ${tmp/#\~/$HOME}` fi echo "$exe" } +# ================================ +# = Prepare compilation function = +# ================================ + +function prepare_compilation { + source_dir="" + (>&2 echo "----> Ok, I will compile from source code <----") + read -e -p "--> Please provide a valid location of source code (either a compressed file or directory): " tmp + loc=`readlink -f ${tmp/#\~/$HOME}` + if [[ -f $loc ]]; then + (>&2 echo -n "--> Expanding source code... ") + source_dir=`dirname $loc`/`echo \`basename $loc\` | sed 's/\./_/g'`_sources + rm -rf $source_dir + mkdir -p $source_dir + uncompress $loc $source_dir + (>&2 echo "done!") + else + source_dir=$loc + fi + echo "$source_dir" +} + ## eof - $RCSfile$ -- 2.47.1