]> Creatis software - cpPlugins.git/blob - third_party_installers/cpPlugins_Install_CMAKE.sh
...
[cpPlugins.git] / third_party_installers / cpPlugins_Install_CMAKE.sh
1 #!/bin/bash
2
3 function abspath()
4 {
5     pushd . > /dev/null
6     if [ -d "$1" ]; then
7         cd "$1"
8         dirs -l +0
9     else
10         cd "`dirname \"$1\"`"
11         cur_dir=`dirs -l +0`
12         if [ "$cur_dir" == "/" ]; then
13             echo "$cur_dir`basename \"$1\"`"
14         else
15             echo "$cur_dir/`basename \"$1\"`"
16         fi
17     fi
18     popd > /dev/null
19 }
20
21 ## Some configuration variables
22 number_of_processes="-j4"
23
24 # Locate qmake executable
25 qmake_locations=("/usr/bin" "/usr/local/bin" "${HOME}/local/bin")
26 qmake_exec=""
27 for loc in ${qmake_locations[@]}; do
28     qmake_file="$loc/qmake"
29     if [ -x $qmake_file ]; then
30         version=`$qmake_file --version | grep Using\ Qt\ version | cut -d ' ' -f 4`
31         if [ "${version:0:3}" == "4.8" ]; then
32             qmake_exec=$qmake_file
33         fi
34     fi
35 done
36
37 if [ -x $qmake_exec ]; then
38     qt_options="--qt-gui --qt-qmake=$qmake_exec"
39 else
40     qt_options="--no-qt-gui"
41 fi
42
43 ## Check input parameters and process inputs (if needed)
44 if [ "$#" -eq 1 ]; then
45     valid_extensions=("zip" "tar" "tar.gz" "tar.bz2")
46     actual_ext=""
47     for ext in ${valid_extensions[@]}; do
48         if [ `basename $1 $ext` != $1 ]; then
49             actual_ext=$ext
50         fi
51     done
52     if [ "x$actual_ext" == "x" ]; then
53         echo "$0: Invalid file type."
54         exit 1
55     fi
56     canonical_path=`abspath $1`
57     source_dir=`dirname $canonical_path`/`basename $1 .$actual_ext`
58     build_dir=`dirname $canonical_path`/`basename $1 .$actual_ext`-build
59     echo -n "Cleaning directories... "
60     rm -rf $source_dir
61     rm -rf $build_dir
62     echo "done."
63     echo -n "Creating directories... "
64     mkdir -p $source_dir
65     mkdir -p $build_dir
66     echo "done."
67     echo -n "Extracting sources... "
68     if [ "$actual_ext" == "zip" ]; then
69         echo unzip $canonical_path
70     elif [ "$actual_ext" == "tar" ]; then
71         tar xf $canonical_path -C $source_dir --strip-components=1
72     elif [ "$actual_ext" == "tar.gz" ]; then
73         tar xzf $canonical_path -C $source_dir --strip-components=1
74     elif [ "$actual_ext" == "tar.bz2" ]; then
75         tar xjf $canonical_path -C $source_dir --strip-components=1
76     else
77         echo "$0: Invalid file type."
78         exit 1
79     fi
80     echo "done!"
81 elif [ "$#" -eq 2 ]; then
82     source_dir=`dirname $1`
83     build_dir=`dirname $2`
84 else
85     echo "Usage: [cmake_package] or [cmake_source_dir cmake_build_dir]" 
86 fi
87
88 echo "Given source dir : \"$source_dir\""
89 echo "Given build dir  : \"$build_dir\""
90
91 echo "Configuring sources... "
92 cd $build_dir
93 $source_dir/bootstrap --prefix=${HOME}/local $qt_options
94 echo "Configuring sources... done."
95
96 echo "Compiling sources..."
97 cd $build_dir
98 make $number_of_processes
99 echo "Compiling sources... done."
100
101 echo "Installing package..."
102 cd $build_dir
103 make -j install
104 echo "Installing package... done."
105
106 ## eof - $RCSfile$