]> Creatis software - cpPlugins.git/blob - third_party_installers/cpPlugins_Install_CMAKE.sh
fafea8facb621bec50442cfeabf68fcee775fe12
[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 ## Check input parameters and process inputs (if needed)
25 if [ "$#" -eq 1 ]; then
26     valid_extensions=("zip" "tar" "tar.gz" "tar.bz2")
27     actual_ext=""
28     for ext in ${valid_extensions[@]}; do
29         if [ `basename $1 $ext` != $1 ]; then
30             actual_ext=$ext
31         fi
32     done
33     if [ "x$actual_ext" == "x" ]; then
34         echo "$0: Invalid file type."
35         exit 1
36     fi
37     canonical_path=`abspath $1`
38     source_dir=`dirname $canonical_path`/`basename $1 .$actual_ext`
39     build_dir=`dirname $canonical_path`/`basename $1 .$actual_ext`-build
40     echo -n "Cleaning directories... "
41     rm -rf $source_dir
42     rm -rf $build_dir
43     echo "done."
44     echo -n "Creating directories... "
45     mkdir -p $source_dir
46     mkdir -p $build_dir
47     echo "done."
48     echo -n "Extracting sources... "
49     if [ "$actual_ext" == "zip" ]; then
50         echo unzip $canonical_path
51     elif [ "$actual_ext" == "tar" ]; then
52         tar xf $canonical_path -C $source_dir --strip-components=1
53     elif [ "$actual_ext" == "tar.gz" ]; then
54         tar xzf $canonical_path -C $source_dir --strip-components=1
55     elif [ "$actual_ext" == "tar.bz2" ]; then
56         tar xjf $canonical_path -C $source_dir --strip-components=1
57     else
58         echo "$0: Invalid file type."
59         exit 1
60     fi
61     echo "done!"
62 elif [ "$#" -eq 2 ]; then
63     source_dir=`dirname $1`
64     build_dir=`dirname $2`
65 else
66     echo "Usage: [cmake_package] or [cmake_source_dir cmake_build_dir]" 
67 fi
68
69 echo "Given source dir : \"$source_dir\""
70 echo "Given build dir  : \"$build_dir\""
71
72 echo "Configuring sources... "
73 cd $build_dir
74 $source_dir/bootstrap --prefix=${HOME}/local
75 echo "Configuring sources... done."
76
77 echo "Compiling sources..."
78 cd $build_dir
79 make $number_of_processes
80 echo "Compiling sources... done."
81
82 echo "Installing package..."
83 cd $build_dir
84 make -j install
85 echo "Installing package... done."
86
87 ## eof - $RCSfile$