Added libcurl dependency for Ubuntu builds
[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     "libcurl4-gnutls-dev"
51 );
52
53 # Make best guess as to where this program was run from (note, it is
54 # always possible to override the location of $0 by the calling
55 # program, so we can't really tell for sure that this is where we
56 # expect it to be. :/
57
58 my $new_env   = 0;
59 my $exec_path = $0;
60 if($0 !~ m!^/!)
61 {
62     $exec_path = abs_path($0);
63 }
64 $exec_path = dirname($exec_path);
65
66 my $root_path = getcwd();
67 if($exec_path =~ m!dali-env/opt/bin!)
68 {
69     $root_path = $exec_path;
70     while($root_path !~ m!dali-env$!)
71     {
72         $root_path = dirname($root_path);
73     }
74 }
75 elsif($root_path =~ m!dali-env!)
76 {
77     while($root_path !~ m!dali-env$!)
78     {
79         $root_path = dirname($root_path);
80     }
81 }
82 else
83 {
84     $new_env = 1;
85     $root_path .= "/dali-env";
86 }
87
88 my $src_path     = "$root_path/src-packages";
89 my $sbs_path     = "$root_path/target";
90 my $install_path = "$root_path/opt";
91
92 my $opt_create=0;
93 my $opt_setenv=0;
94 my $opt_help=0;
95 my $opt_man=0;
96
97 GetOptions("create"     => \$opt_create,
98            "setenv"     => \$opt_setenv,
99            "help"       => \$opt_help,
100            "man"        => \$opt_man) or pod2usage(2);
101
102 pod2usage(1) if $opt_help;
103 pod2usage(-exitstatus => 0, -verbose => 2) if $opt_man;
104
105
106 ################################################################################
107
108 sub create_env
109 {
110     mkpath("$install_path/bin");
111     mkpath("$install_path/lib/pkgconfig");
112     mkpath("$install_path/include");
113     mkpath("$install_path/share/aclocal");
114     mkpath("$src_path");
115     mkpath("$sbs_path");
116
117     copy($0, "$install_path/bin/dali_env");
118     chmod(0755, "$install_path/bin/dali_env");
119 }
120
121 ################################################################################
122
123 sub in_dali_env
124 {
125     my $cwd = substr(getcwd(), 0, length($root_path));
126     #print "cwd = $cwd\nroot = $root_path\n";
127     return $cwd eq $root_path;
128 }
129
130 ################################################################################
131
132 sub create_setenv
133 {
134     print <<"EOF";
135 # To use the desktop libraries, please add the following lines to your .bashrc or
136 # create a setenv script from them, e.g. by running this command as follows
137 # \$ dali_env -s > setenv
138 #
139 # You can then source this script by using
140 # \$ . setenv
141 #
142 # Use DESKTOP_PREFIX when running configure in dali/build/slp:
143 # \$ CXXFLAGS="-g -O0" ./configure --prefix=\$DESKTOP_PREFIX
144
145 export DESKTOP_PREFIX=$install_path
146 export PATH=$install_path/bin:\$PATH
147 export LD_LIBRARY_PATH=$install_path/lib:\$LD_LIBRARY_PATH
148 export INCLUDEDIR=$install_path/include
149 export PKG_CONFIG_PATH=$install_path/lib/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig
150
151 EOF
152 }
153
154 ################################################################################
155
156 sub check_system_package
157 {
158     my $package;
159     foreach $package (@_)
160     {
161         my @x=split(/\s+/, `dpkg -l $package|grep $package`);
162         if($x[0] ne "ii")
163         {
164             print "Attempting to install $package\n";
165             system("sudo apt-get -y install $package");
166         }
167     }
168 }
169
170 sub check_system_packages
171 {
172     print "Checking for required system packages (may require sudo password)\n";
173
174     check_system_package(@system_packages);
175     my $gnome_v =`dpkg -l gnome-common| tail -1| sed "s/ \\+/ /g" | cut -d' ' -f 3`;
176     my @am = split(/\./, `automake --version | head -1 | cut -f4 -d' '`);
177     if($gnome_v =~ /$2.24/ && $am[1]>10)
178     {
179         die "Gnome common and automake are not compatible - automake is too new\n";
180     }
181     my @gpp_v = (`g++ --version  | head -1` =~ /(\d+)\.(\d+)\.(\d+)/);
182
183     if(! (($gpp_v[0] > 4)
184           ||
185           ($gpp_v[0] == 4 && $gpp_v[1] > 4)
186           ||
187           ($gpp_v[0] == 4 && $gpp_v[1] == 4 && $gpp_v[2] >= 5)))
188     {
189         die "You need g++ 4.5.1 or greater to build dali\n";
190     }
191 }
192
193 ################################################################################
194
195 sub create_link
196 {
197     my $arch=`uname -i`;
198     $arch =~ s/\r|\n//g;
199
200     my $link = "/usr/lib/$arch-linux-gnu/libturbojpeg.so";
201
202     unless (-e $link)
203     {
204        print "Creating libjpegturbo symbolic link\n";
205        system("sudo ln -s $link.0 $link");
206     }
207 }
208
209 ################################################################################
210 #                                       MAIN
211 ################################################################################
212
213
214 if($opt_create)
215 {
216     my $new_root = getcwd() . "/dali-env";
217
218     if($exec_path =~ m!dali-env/opt/bin!)
219     {
220         die "Already in a dali-env directory\n";
221         # Could query if user wants to re-create?
222     }
223     elsif(-e $new_root)
224     {
225         die "A dali-env directory already exists here\n";
226     }
227
228     check_system_packages();
229
230     create_link();
231
232     create_env();
233     create_setenv();
234 }
235 elsif($opt_setenv)
236 {
237     if(! -d $root_path)
238     {
239         die "$root_path does not exist\n";
240     }
241     elsif($new_env)
242     {
243         die "$root_path is not an existing environment\n";
244     }
245     create_setenv();
246 }
247 else
248 {
249     pod2usage(1);
250 }
251
252 __END__
253
254 =head1 NAME
255
256 dali_env - Create the DALi environment for Ubuntu
257
258 =head1 SYNOPSIS
259
260 dali_env [-c] [-s] [-h|-m]
261
262 =head1 OPTIONS
263
264 =over 28
265
266 =item B<-c|--create>
267
268 Create a DALi environment directory in the current directory.
269
270 =item B<-s|--setenv>
271
272 Display environment variables to setup.
273
274 =item B<-h|--help>
275
276 Display this help
277
278 =item B<-m|--man>
279
280 Display the manual page
281
282 =back
283
284 =head1 DESCRIPTION
285
286 B<dali_env>
287
288 Gets the required dependencies for DALi and them to a local directory. Can also create a setenv script to point to the installation.
289
290 =cut