]> Creatis software - cpPlugins.git/blob - third_party_installers/cpPlugins_Install_QT4.sh
...
[cpPlugins.git] / third_party_installers / 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
140 ## Create paths
141 if [ "x$source_file" != "x" ]; then
142     echo -n "==> Cleaning directories... "
143     rm -rf $source_dir
144     rm -rf $build_dir
145     echo "done."
146     echo -n "==> Creating directories... "
147     mkdir -p $source_dir
148     mkdir -p $build_dir
149     echo "done."
150 fi
151
152 ## Extract source code
153 if [ "x$source_file" != "x" ]; then
154     echo -n "==> Extracting sources... "
155     base_path=`abspath $source_file`
156     base_ext=`get_file_extension $base_path`
157     if [ "$base_ext" == "zip" ]; then
158         echo unzip $base_path
159     elif [ "$base_ext" == "tar" ]; then
160         tar xf $base_path -C $source_dir --strip-components=1
161     elif [ "$base_ext" == "tar.gz" ]; then
162         tar xzf $base_path -C $source_dir --strip-components=1
163     elif [ "$base_ext" == "tar.bz2" ]; then
164         tar xjf $base_path -C $source_dir --strip-components=1
165     fi
166     echo "done."
167 fi
168
169 # Apply patch
170 if [ "x$patch_file" != "x" ]; then
171     echo -n "==> Applying patch... "
172     cd $source_dir
173     patch -p0 < $patch_file
174     echo "done."
175 fi
176
177 echo "==> Configuring sources... "
178 cd $build_dir
179 if [ "x$full_compile" == "xfull" ]; then
180     $source_dir/configure \
181         -prefix $prefix \
182         -$build_type \
183         -opensource -shared -fast \
184         -no-webkit \
185         -optimized-qmake \
186         $particular_options \
187         -confirm-license
188 else
189     $source_dir/configure \
190         -prefix $prefix \
191         -$build_type \
192         -opensource -shared -fast \
193         -no-phonon \
194         -no-phonon-backend \
195         -no-webkit \
196         -no-openvg \
197         -nomake demos -nomake examples \
198         -optimized-qmake \
199         $particular_options \
200         -confirm-license
201 fi
202 echo "==> Configuring sources... done."
203
204 echo "==> Compiling sources..."
205 cd $build_dir
206 make -j$number_of_threads
207 echo "==> Compiling sources... done."
208
209 echo "==> Installing package..."
210 cd $build_dir
211 make -j install
212 echo "==> Installing package... done."
213
214 ## eof - $RCSfile$