]> Creatis software - cpPlugins.git/blob - dependencies/cpPlugins_Install_QT4.sh
36c5d13824804fcb952b9545ad86afee760e35c4
[cpPlugins.git] / dependencies / cpPlugins_Install_QT4.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 function get_file_extension
22 {
23     valid_extensions=("zip" "tar" "tar.gz" "tar.bz2")
24     actual_file=`abspath $1`
25     actual_ext=""
26     for ext in ${valid_extensions[@]}; do
27         test_str=`dirname $actual_file`/`basename $actual_file $ext`
28         if [ $test_str != $actual_file ]; then
29             actual_ext=$ext
30         fi
31     done
32     echo "$actual_ext"
33 }
34
35 function print_help()
36 {
37     echo "Usage: `basename $0` -f=compressed_code -c=source_dir -b=build_dir [-t=build_type[release/debug]] [-p=instalation_prefix] [--full]"
38 }
39
40 ## Analyze command-line arguments
41 if [ $# -eq 0 ]; then
42         print_help
43         exit 1
44 fi
45 full_compile="0"
46 prefix="${HOME}/local"
47 build_type="release"
48 for i in "$@"; do
49     case $i in
50     -f=*|--file=*)
51     source_file="${i#*=}"
52     shift
53     ;;
54     -c=*|--source_dir=*)
55     source_dir="${i#*=}"
56     shift
57     ;;
58     -b=*|--build_dir=*)
59     build_dir="${i#*=}"
60     shift
61     ;;
62     -t=*|--build_type=*)
63     build_type="${i#*=}"
64     shift
65     ;;
66     -p=*|--prefix=*)
67     prefix="${i#*=}"
68     shift
69     ;;
70     --full)
71     full_compile="1"
72     shift
73     ;;
74     *)
75     ;;
76     esac
77 done
78
79 ## Check command line arguments
80 if [ "x$source_dir" == "x" ]; then
81     if [ "x$source_file" != "x" ]; then
82         base_path=`abspath $source_file`
83         base_ext=`get_file_extension $base_path`
84         base_dir=`dirname $base_path`
85         if [ "x$base_ext" != "x" ]; then
86             source_dir="$base_dir"/`basename $base_path .$base_ext`
87         else
88             echo "Error: Input compressed file extension not recognized."
89             exit 1
90         fi
91     else
92         print_help
93         exit 1
94     fi
95 fi
96 if [ "x$build_dir" == "x" ]; then
97     if [ "x$source_dir" != "x" ]; then
98         base_dir=$source_dir
99         if [ "${source_dir:$((${#str}-1)):1}" == "/" ]; then
100             base_dir=`echo $source_dir | rev | cut -c 2- | rev`
101         fi
102         build_dir="$base_dir-build"
103     else
104         print_help
105         exit 1
106     fi
107 fi
108
109 ## Other configuration variables
110 platform=`uname`
111 particular_options=""
112 patch_file=""
113 if [ "$platform" == "Darwin" ]; then
114     particular_options=-no-framework
115     bash_path=`abspath $0`
116     bash_dir=`dirname $bash_path`
117     patch_file=$bash_dir/qt-4.8.6.patch
118 fi
119 number_of_cores=`grep -c ^processor /proc/cpuinfo`
120 number_of_threads=`expr $number_of_cores / 2`
121 if [ "x$source_file" != "x" ]; then
122     source_file=`abspath $source_file`
123 fi
124 source_dir=`abspath $source_dir`
125 build_dir=`abspath $build_dir`
126
127 echo "====================================================================="
128 echo "==> Source file       : $source_file"
129 echo "==> Source dir        : $source_dir"
130 echo "==> Build dir         : $build_dir"
131 echo "==> Build type        : $build_type"
132 echo "==> Prefix            : $prefix"
133 echo "==> Full compile      : $full_compile"
134 echo "==> Platform          : $platform"
135 echo "==> Number of cores   : $number_of_cores"
136 echo "==> Number of threads : $number_of_threads"
137 echo "==> Patch file        : $patch_file"
138 echo "====================================================================="
139 read -n1 -r -p "Continue? [Y/N]... " key
140 echo
141 if [ "$key" != 'Y' -a "$key" != 'y' ] ; then
142     exit 1
143 fi
144
145 ## Create paths
146 if [ "x$source_file" != "x" ]; then
147     echo -n "==> Cleaning directories... "
148     rm -rf $source_dir
149     rm -rf $build_dir
150     echo "done."
151     echo -n "==> Creating directories... "
152     mkdir -p $source_dir
153     mkdir -p $build_dir
154     echo "done."
155 fi
156
157 ## Extract source code
158 if [ "x$source_file" != "x" ]; then
159     echo -n "==> Extracting sources... "
160     base_path=`abspath $source_file`
161     base_ext=`get_file_extension $base_path`
162     if [ "$base_ext" == "zip" ]; then
163         echo unzip $base_path
164     elif [ "$base_ext" == "tar" ]; then
165         tar xf $base_path -C $source_dir --strip-components=1
166     elif [ "$base_ext" == "tar.gz" ]; then
167         tar xzf $base_path -C $source_dir --strip-components=1
168     elif [ "$base_ext" == "tar.bz2" ]; then
169         tar xjf $base_path -C $source_dir --strip-components=1
170     fi
171     echo "done."
172 fi
173
174 # Apply patch
175 if [ "x$patch_file" != "x" ]; then
176     echo -n "==> Applying patch... "
177     cd $source_dir
178     patch -p0 < $patch_file
179     echo "done."
180 fi
181
182 echo "==> Configuring sources... "
183 cd $build_dir
184 if [ "x$full_compile" == "xfull" ]; then
185     $source_dir/configure \
186         -prefix $prefix \
187         -$build_type \
188         -opensource -shared -fast \
189         -no-webkit \
190         -optimized-qmake \
191         $particular_options \
192         -confirm-license
193 else
194     $source_dir/configure \
195         -prefix $prefix \
196         -$build_type \
197         -opensource -shared -fast \
198         -no-phonon \
199         -no-phonon-backend \
200         -no-webkit \
201         -no-openvg \
202         -nomake demos -nomake examples \
203         -optimized-qmake \
204         $particular_options \
205         -confirm-license
206 fi
207 echo "==> Configuring sources... done."
208
209 echo "==> Compiling sources..."
210 cd $build_dir
211 make -j$number_of_threads
212 echo "==> Compiling sources... done."
213
214 echo "==> Installing package..."
215 cd $build_dir
216 make -j install
217 echo "==> Installing package... done."
218
219 ## eof - $RCSfile$