Merge "LLVM/Emscripten fixes" into tizen
[platform/core/uifw/dali-core.git] / build / scripts / dali_env
1 #!/usr/bin/perl
2
3 # Copyright (c) 2014 Samsung Electronics Co., Ltd.
4
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8
9 # http://www.apache.org/licenses/LICENSE-2.0
10
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 use Cwd;
18 use Cwd 'abs_path';
19 use File::Basename;
20 use File::Path;
21 use File::Copy;
22 use File::Copy::Recursive qw(dircopy);
23 use strict;
24 use Getopt::Long;
25 use Pod::Usage;
26
27 ################################################################################
28 #                                SYSTEM PACKAGES                               #
29 ################################################################################
30 # Add any required system packages to this list - if they are not present, then
31 # this script will attempt to install them for you.
32 my @system_packages = (
33     "automake",
34     "g++",
35     "pkg-config",
36     "libtool",
37     "ccache",
38     "libboost-dev",
39     "libboost-thread-dev",
40     "libelementary-dev",
41     "libexif-dev",
42     "libxml2-dev",
43     "libgles2-mesa-dev",
44     "libdrm-dev",
45     "libgif-dev",
46     "libturbojpeg",
47     "libfribidi-dev",
48     "doxygen",
49     "lcov",
50 );
51
52 # Make best guess as to where this program was run from (note, it is
53 # always possible to override the location of $0 by the calling
54 # program, so we can't really tell for sure that this is where we
55 # expect it to be. :/
56
57 my $new_env   = 0;
58 my $exec_path = $0;
59 if($0 !~ m!^/!)
60 {
61     $exec_path = abs_path($0);
62 }
63 $exec_path = dirname($exec_path);
64
65 my $root_path = getcwd();
66 if($exec_path =~ m!dali-env/opt/bin!)
67 {
68     $root_path = $exec_path;
69     while($root_path !~ m!dali-env$!)
70     {
71         $root_path = dirname($root_path);
72     }
73 }
74 elsif($root_path =~ m!dali-env!)
75 {
76     while($root_path !~ m!dali-env$!)
77     {
78         $root_path = dirname($root_path);
79     }
80 }
81 else
82 {
83     $new_env = 1;
84     $root_path .= "/dali-env";
85 }
86
87 my $src_path     = "$root_path/src-packages";
88 my $sbs_path     = "$root_path/target";
89 my $install_path = "$root_path/opt";
90
91 my $opt_create=0;
92 my $opt_setenv=0;
93 my $opt_help=0;
94 my $opt_man=0;
95
96 GetOptions("create"     => \$opt_create,
97            "setenv"     => \$opt_setenv,
98            "help"       => \$opt_help,
99            "man"        => \$opt_man) or pod2usage(2);
100
101 pod2usage(1) if $opt_help;
102 pod2usage(-exitstatus => 0, -verbose => 2) if $opt_man;
103
104
105 ################################################################################
106
107 sub create_env
108 {
109     mkpath("$install_path/bin");
110     mkpath("$install_path/lib/pkgconfig");
111     mkpath("$install_path/include");
112     mkpath("$install_path/share/aclocal");
113     mkpath("$src_path");
114     mkpath("$sbs_path");
115
116     copy($0, "$install_path/bin/dali_env");
117     chmod(0755, "$install_path/bin/dali_env");
118 }
119
120 ################################################################################
121
122 sub in_dali_env
123 {
124     my $cwd = substr(getcwd(), 0, length($root_path));
125     #print "cwd = $cwd\nroot = $root_path\n";
126     return $cwd eq $root_path;
127 }
128
129 ################################################################################
130
131 sub create_setenv
132 {
133     print <<"EOF";
134 # To use the desktop libraries, please add the following lines to your .bashrc or
135 # create a setenv script from them, e.g. by running this command as follows
136 # \$ dali_env -s > setenv
137 #
138 # You can then source this script by using
139 # \$ . setenv
140 #
141 # Use DESKTOP_PREFIX when running configure in dali/build/slp:
142 # \$ CXXFLAGS="-g -O0" ./configure --prefix=\$DESKTOP_PREFIX
143
144 export DESKTOP_PREFIX=$install_path
145 export PATH=$install_path/bin:\$PATH
146 export LD_LIBRARY_PATH=$install_path/lib:\$LD_LIBRARY_PATH
147 export INCLUDEDIR=$install_path/include
148 export PKG_CONFIG_PATH=$install_path/lib/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig
149
150 EOF
151 }
152
153 ################################################################################
154
155 sub check_system_package
156 {
157     my $package;
158     foreach $package (@_)
159     {
160         my @x=split(/\s+/, `dpkg -l $package|grep $package`);
161         if($x[0] ne "ii")
162         {
163             print "Attempting to install $package\n";
164             system("sudo apt-get -y install $package");
165         }
166     }
167 }
168
169 sub check_system_packages
170 {
171     print "Checking for required system packages (may require sudo password)\n";
172
173     check_system_package(@system_packages);
174     my $gnome_v =`dpkg -l gnome-common| tail -1| sed "s/ \\+/ /g" | cut -d' ' -f 3`;
175     my @am = split(/\./, `automake --version | head -1 | cut -f4 -d' '`);
176     if($gnome_v =~ /$2.24/ && $am[1]>10)
177     {
178         die "Gnome common and automake are not compatible - automake is too new\n";
179     }
180     my @gpp_v = (`g++ --version  | head -1` =~ /(\d+)\.(\d+)\.(\d+)/);
181
182     if(! (($gpp_v[0] > 4)
183           ||
184           ($gpp_v[0] == 4 && $gpp_v[1] > 4)
185           ||
186           ($gpp_v[0] == 4 && $gpp_v[1] == 4 && $gpp_v[2] >= 5)))
187     {
188         die "You need g++ 4.5.1 or greater to build dali\n";
189     }
190 }
191
192 ################################################################################
193
194 sub create_link
195 {
196     my $arch=`uname -i`;
197     $arch =~ s/\r|\n//g;
198
199     my $link = "/usr/lib/$arch-linux-gnu/libturbojpeg.so";
200
201     unless (-e $link)
202     {
203        print "Creating libjpegturbo symbolic link\n";
204        system("sudo ln -s $link.0 $link");
205     }
206 }
207
208 ################################################################################
209 #                                       MAIN
210 ################################################################################
211
212
213 if($opt_create)
214 {
215     my $new_root = getcwd() . "/dali-env";
216
217     if($exec_path =~ m!dali-env/opt/bin!)
218     {
219         die "Already in a dali-env directory\n";
220         # Could query if user wants to re-create?
221     }
222     elsif(-e $new_root)
223     {
224         die "A dali-env directory already exists here\n";
225     }
226
227     check_system_packages();
228
229     create_link();
230
231     create_env();
232     create_setenv();
233 }
234 elsif($opt_setenv)
235 {
236     if(! -d $root_path)
237     {
238         die "$root_path does not exist\n";
239     }
240     elsif($new_env)
241     {
242         die "$root_path is not an existing environment\n";
243     }
244     create_setenv();
245 }
246 else
247 {
248     pod2usage(1);
249 }
250
251 __END__
252
253 =head1 NAME
254
255 dali_env - Create the DALi environment for Ubuntu
256
257 =head1 SYNOPSIS
258
259 dali_env [-c] [-s] [-h|-m]
260
261 =head1 OPTIONS
262
263 =over 28
264
265 =item B<-c|--create>
266
267 Create a DALi environment directory in the current directory.
268
269 =item B<-s|--setenv>
270
271 Display environment variables to setup.
272
273 =item B<-h|--help>
274
275 Display this help
276
277 =item B<-m|--man>
278
279 Display the manual page
280
281 =back
282
283 =head1 DESCRIPTION
284
285 B<dali_env>
286
287 Gets the required dependencies for DALi and them to a local directory. Can also create a setenv script to point to the installation.
288
289 =cut