]> Creatis software - cpPlugins.git/blobdiff - third_party_installers/cpPlugins_Install_QT4.sh
...
[cpPlugins.git] / third_party_installers / cpPlugins_Install_QT4.sh
index cb3afc329a1b7b809468296ca785b8b7d10e6836..36c5d13824804fcb952b9545ad86afee760e35c4 100755 (executable)
 #!/bin/bash
 
-## Check input parameters and process inputs (if needed)
-if [ "$#" -eq 1 ]; then
+function abspath()
+{
+    pushd . > /dev/null
+    if [ -d "$1" ]; then
+        cd "$1"
+        dirs -l +0
+    else
+        cd "`dirname \"$1\"`"
+        cur_dir=`dirs -l +0`
+        if [ "$cur_dir" == "/" ]; then
+            echo "$cur_dir`basename \"$1\"`"
+        else
+            echo "$cur_dir/`basename \"$1\"`"
+        fi
+    fi
+    popd > /dev/null
+}
+
+function get_file_extension
+{
     valid_extensions=("zip" "tar" "tar.gz" "tar.bz2")
+    actual_file=`abspath $1`
     actual_ext=""
     for ext in ${valid_extensions[@]}; do
-        if [ `basename $1 $ext` != $1 ]; then
+        test_str=`dirname $actual_file`/`basename $actual_file $ext`
+        if [ $test_str != $actual_file ]; then
             actual_ext=$ext
         fi
     done
-    if [ "x$actual_ext" == "x" ]; then
-        echo "$0: Invalid file type."
+    echo "$actual_ext"
+}
+
+function print_help()
+{
+    echo "Usage: `basename $0` -f=compressed_code -c=source_dir -b=build_dir [-t=build_type[release/debug]] [-p=instalation_prefix] [--full]"
+}
+
+## Analyze command-line arguments
+if [ $# -eq 0 ]; then
+        print_help
+        exit 1
+fi
+full_compile="0"
+prefix="${HOME}/local"
+build_type="release"
+for i in "$@"; do
+    case $i in
+    -f=*|--file=*)
+    source_file="${i#*=}"
+    shift
+    ;;
+    -c=*|--source_dir=*)
+    source_dir="${i#*=}"
+    shift
+    ;;
+    -b=*|--build_dir=*)
+    build_dir="${i#*=}"
+    shift
+    ;;
+    -t=*|--build_type=*)
+    build_type="${i#*=}"
+    shift
+    ;;
+    -p=*|--prefix=*)
+    prefix="${i#*=}"
+    shift
+    ;;
+    --full)
+    full_compile="1"
+    shift
+    ;;
+    *)
+    ;;
+    esac
+done
+
+## Check command line arguments
+if [ "x$source_dir" == "x" ]; then
+    if [ "x$source_file" != "x" ]; then
+        base_path=`abspath $source_file`
+        base_ext=`get_file_extension $base_path`
+        base_dir=`dirname $base_path`
+        if [ "x$base_ext" != "x" ]; then
+            source_dir="$base_dir"/`basename $base_path .$base_ext`
+        else
+            echo "Error: Input compressed file extension not recognized."
+            exit 1
+        fi
+    else
+        print_help
+        exit 1
+    fi
+fi
+if [ "x$build_dir" == "x" ]; then
+    if [ "x$source_dir" != "x" ]; then
+        base_dir=$source_dir
+        if [ "${source_dir:$((${#str}-1)):1}" == "/" ]; then
+            base_dir=`echo $source_dir | rev | cut -c 2- | rev`
+        fi
+        build_dir="$base_dir-build"
+    else
+        print_help
         exit 1
     fi
-    canonical_path=`readlink -e $1`
-    source_dir=`dirname $canonical_path`/`basename $1 .$actual_ext`
-    build_dir=`dirname $canonical_path`/`basename $1 .$actual_ext`-build
-    echo -n "Cleaning directories... "
+fi
+
+## Other configuration variables
+platform=`uname`
+particular_options=""
+patch_file=""
+if [ "$platform" == "Darwin" ]; then
+    particular_options=-no-framework
+    bash_path=`abspath $0`
+    bash_dir=`dirname $bash_path`
+    patch_file=$bash_dir/qt-4.8.6.patch
+fi
+number_of_cores=`grep -c ^processor /proc/cpuinfo`
+number_of_threads=`expr $number_of_cores / 2`
+if [ "x$source_file" != "x" ]; then
+    source_file=`abspath $source_file`
+fi
+source_dir=`abspath $source_dir`
+build_dir=`abspath $build_dir`
+
+echo "====================================================================="
+echo "==> Source file       : $source_file"
+echo "==> Source dir        : $source_dir"
+echo "==> Build dir         : $build_dir"
+echo "==> Build type        : $build_type"
+echo "==> Prefix            : $prefix"
+echo "==> Full compile      : $full_compile"
+echo "==> Platform          : $platform"
+echo "==> Number of cores   : $number_of_cores"
+echo "==> Number of threads : $number_of_threads"
+echo "==> Patch file        : $patch_file"
+echo "====================================================================="
+read -n1 -r -p "Continue? [Y/N]... " key
+echo
+if [ "$key" != 'Y' -a "$key" != 'y' ] ; then
+    exit 1
+fi
+
+## Create paths
+if [ "x$source_file" != "x" ]; then
+    echo -n "==> Cleaning directories... "
     rm -rf $source_dir
     rm -rf $build_dir
     echo "done."
-    echo -n "Creating directories... "
+    echo -n "==> Creating directories... "
     mkdir -p $source_dir
     mkdir -p $build_dir
     echo "done."
-    echo -n "Extracting sources... "
-    if [ "$actual_ext" == "zip" ]; then
-        echo unzip $canonical_path
-    elif [ "$actual_ext" == "tar" ]; then
-        tar xf $canonical_path -C $source_dir --strip-components=1
-    elif [ "$actual_ext" == "tar.gz" ]; then
-        tar xzf $canonical_path -C $source_dir --strip-components=1
-    elif [ "$actual_ext" == "tar.bz2" ]; then
-        tar xjf $canonical_path -C $source_dir --strip-components=1
-    else
-        echo "$0: Invalid file type."
-        exit 1
+fi
+
+## Extract source code
+if [ "x$source_file" != "x" ]; then
+    echo -n "==> Extracting sources... "
+    base_path=`abspath $source_file`
+    base_ext=`get_file_extension $base_path`
+    if [ "$base_ext" == "zip" ]; then
+        echo unzip $base_path
+    elif [ "$base_ext" == "tar" ]; then
+        tar xf $base_path -C $source_dir --strip-components=1
+    elif [ "$base_ext" == "tar.gz" ]; then
+        tar xzf $base_path -C $source_dir --strip-components=1
+    elif [ "$base_ext" == "tar.bz2" ]; then
+        tar xjf $base_path -C $source_dir --strip-components=1
     fi
-    echo "done!"
-elif [ "$#" -eq 2 ]; then
-    source_dir=`dirname $1`
-    build_dir=`dirname $2`
-else
-    echo "Usage: [qt4_package] or [qt4_source_dir qt4_build_dir]" 
+    echo "done."
 fi
 
-echo "Given source dir : \"$source_dir\""
-echo "Given build dir  : \"$build_dir\""
+# Apply patch
+if [ "x$patch_file" != "x" ]; then
+    echo -n "==> Applying patch... "
+    cd $source_dir
+    patch -p0 < $patch_file
+    echo "done."
+fi
 
-echo "Configuring sources... "
+echo "==> Configuring sources... "
 cd $build_dir
-$source_dir/configure \
-    -prefix ${HOME}/local \
-    -release -opensource -shared -fast -no-webkit \
-    -optimized-qmake -no-framework \
-    -confirm-license yes
-echo "Configuring sources... done."
+if [ "x$full_compile" == "xfull" ]; then
+    $source_dir/configure \
+        -prefix $prefix \
+        -$build_type \
+        -opensource -shared -fast \
+        -no-webkit \
+        -optimized-qmake \
+        $particular_options \
+        -confirm-license
+else
+    $source_dir/configure \
+        -prefix $prefix \
+        -$build_type \
+        -opensource -shared -fast \
+        -no-phonon \
+        -no-phonon-backend \
+        -no-webkit \
+        -no-openvg \
+        -nomake demos -nomake examples \
+        -optimized-qmake \
+        $particular_options \
+        -confirm-license
+fi
+echo "==> Configuring sources... done."
 
-echo "Compiling sources..."
+echo "==> Compiling sources..."
 cd $build_dir
-make
-echo "Compiling sources... done."
+make -j$number_of_threads
+echo "==> Compiling sources... done."
 
-echo "Installing package..."
+echo "==> Installing package..."
 cd $build_dir
 make -j install
-echo "Installing package... done."
+echo "==> Installing package... done."
 
 ## eof - $RCSfile$