(dali_env) Added libssl-dev dependency
[platform/core/uifw/dali-core.git] / build / scripts / dali_env
1 #!/usr/bin/perl
2
3 # Copyright (c) 2018 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 Config;
18 use Cwd;
19 use Cwd 'abs_path';
20 use File::Basename;
21 use File::Path;
22 use File::Copy;
23 use File::Copy::Recursive qw(dircopy);
24 use strict;
25 use Getopt::Long;
26 use Pod::Usage;
27
28 ################################################################################
29 #                                SYSTEM PACKAGES                               #
30 ################################################################################
31 # Add any required system packages to this list - if they are not present, then
32 # this script will attempt to install them for you.
33 my @system_packages = (
34     "automake",
35     "cmake",
36     "g++",
37     "pkg-config",
38     "libtool",
39     "ccache",
40     "libelementary-dev",
41     "libexif-dev",
42     "libgles2-mesa-dev",
43     "libdrm-dev",
44     "libgif-dev",
45     "libturbojpeg",
46     "libfribidi-dev",
47     "libharfbuzz-dev",
48     "doxygen",
49     "lcov",
50     "libcurl4-gnutls-dev",
51     "curl",
52     "libssl-dev",
53 );
54
55 # Some packages like require building from source
56 # v8 is currently disabled until we can get it working without a http proxy being setup
57 my @source_pkgs = (
58
59     {"name" => "disabled-v8",
60      "force-rebuild" => 0,
61      "use_depot_tools" => 1,
62      "repo" => "https://chromium.googlesource.com/v8/v8.git",
63      "depot_tools_repo" => "https://chromium.googlesource.com/chromium/tools/depot_tools.git",
64
65      # original version used with DALi is 3.25.19. 3.32.7 is the latest we can use before
66      # upgrading DALi to use  c++0x or c++11
67      "version" => " 3.32.7", "make" => "make -j8 library=shared", "build-mode" =>"debug" },
68 );
69
70 ### Detect any http proxy, part of v8 installation requires this information
71 my $http_proxy_port;
72 my $http_proxy_ip;
73
74 if( exists $ENV{http_proxy} )
75 {
76   # string  split into 3 items  http, //ip, port
77   my @http_proxy_info =  split( /:/,$ENV{http_proxy}, );
78
79   $http_proxy_ip =  @http_proxy_info[1];
80   $http_proxy_ip =~ s/[\/]//g;;  # remove forward slashes
81   $http_proxy_port =  @http_proxy_info[2];
82 }
83
84 # Make best guess as to where this program was run from (note, it is
85 # always possible to override the location of $0 by the calling
86 # program, so we can't really tell for sure that this is where we
87 # expect it to be. :/
88
89 my $new_env   = 0;
90 my $exec_path = $0;
91 if($0 !~ m!^/!)
92 {
93     $exec_path = abs_path($0);
94 }
95 $exec_path = dirname($exec_path);
96
97 my $root_path = getcwd();
98
99 # Search for the root dali-env directory
100 if($exec_path =~ m!dali-env/opt/bin!)
101 {
102     # We are using the installed dali_env script
103
104     $root_path = $exec_path;
105     while(basename($root_path) ne "dali-env" && $root_path ne "")
106     {
107         $root_path = dirname($root_path);
108     }
109 }
110 elsif($root_path =~ m!dali-env$! or $root_path =~ m!dali-env/!)
111 {
112     # We are NOT using the installed dali_env script
113     # Find dali-env root from current directory
114
115     while(basename($root_path) ne "dali-env" && $root_path ne "")
116     {
117         $root_path = dirname($root_path);
118     }
119 }
120 else
121 {
122     # dali-env root dir should be in the current directory
123
124     $root_path .= "/dali-env";
125
126     if(! -e $root_path)
127     {
128       # Creating a new dali-env
129
130       $new_env = 1;
131     }
132 }
133
134 my $src_path         = "$root_path/src-packages";
135 my $sbs_path         = "$root_path/target";
136 my $install_path     = "$root_path/opt";
137
138 my $opt_create=0;
139 my $opt_setenv=0;
140 my $opt_help=0;
141 my $opt_man=0;
142
143 GetOptions("create"     => \$opt_create,
144            "setenv"     => \$opt_setenv,
145            "help"       => \$opt_help,
146            "man"        => \$opt_man) or pod2usage(2);
147
148 pod2usage(1) if $opt_help;
149 pod2usage(-exitstatus => 0, -verbose => 2) if $opt_man;
150
151
152 ################################################################################
153
154 sub create_env
155 {
156     mkpath("$install_path/bin");
157     mkpath("$install_path/lib/pkgconfig");
158     mkpath("$install_path/include");
159     mkpath("$install_path/share/aclocal");
160     mkpath("$src_path");
161     mkpath("$sbs_path");
162
163     copy($0, "$install_path/bin/dali_env");
164     chmod(0755, "$install_path/bin/dali_env");
165 }
166
167 ################################################################################
168
169 sub in_dali_env
170 {
171     my $cwd = substr(getcwd(), 0, length($root_path));
172     #print "cwd = $cwd\nroot = $root_path\n";
173     return $cwd eq $root_path;
174 }
175
176 ################################################################################
177
178 sub create_setenv
179 {
180     print <<"EOF";
181 #
182 # To use the desktop libraries, please add the following lines to your .bashrc or
183 # create a setenv script from them, e.g. by running this command as follows
184 # \$ $install_path/bin/dali_env -s > setenv
185 #
186 # You can then source this script by using
187 # \$ . setenv
188 #
189 # Use DESKTOP_PREFIX when running configure in dali/build/tizen:
190 # \$ CXXFLAGS="-g -O0" ./configure --prefix=\$DESKTOP_PREFIX
191
192 export DESKTOP_PREFIX=$install_path
193 export PATH=$install_path/bin:\$PATH
194 export LD_LIBRARY_PATH=$install_path/lib:\$LD_LIBRARY_PATH
195 export INCLUDEDIR=$install_path/include
196 export PKG_CONFIG_PATH=$install_path/lib/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig
197 export DOTNET_CLI_TELEMETRY_OPTOUT=1
198 export DALI_WINDOW_WIDTH=480
199 export DALI_WINDOW_HEIGHT=800
200
201 EOF
202 }
203
204 ################################################################################
205
206 sub check_system_package
207 {
208     my $package;
209     foreach $package (@_)
210     {
211         my @x=split(/\s+/, `dpkg -l $package|grep $package`);
212         if($x[0] ne "ii")
213         {
214             print "Attempting to install $package\n";
215             system("sudo apt-get -y --force-yes install $package");
216         }
217     }
218 }
219
220 sub check_system_packages
221 {
222     print "Checking for required system packages (may require sudo password)\n";
223
224     check_system_package(@system_packages);
225
226     my $gnome_v =`dpkg -l gnome-common| tail -1| sed "s/ \\+/ /g" | cut -d' ' -f 3`;
227     my @am = split(/\./, `automake --version | head -1 | cut -f4 -d' '`);
228     if($gnome_v =~ /$2.24/ && $am[1]>10)
229     {
230         die "Gnome common and automake are not compatible - automake is too new\n";
231     }
232     my @gpp_v = (`g++ --version  | head -1` =~ /(\d+)\.(\d+)\.(\d+)/);
233
234     if(! (($gpp_v[0] > 4)
235           ||
236           ($gpp_v[0] == 4 && $gpp_v[1] > 4)
237           ||
238           ($gpp_v[0] == 4 && $gpp_v[1] == 4 && $gpp_v[2] >= 5)))
239     {
240         die "You need g++ 4.5.1 or greater to build dali\n";
241     }
242 }
243
244 sub check_source_packages
245 {
246     my $pkgref;
247
248     foreach $pkgref (@source_pkgs)
249     {
250         my $pkg = $pkgref->{"name"};
251         if($pkg eq "v8")
252         {
253             install_v8( $pkgref );
254         }
255     }
256 }
257
258 ################################################################################
259
260 sub create_link
261 {
262     my $arch=`uname -i`;
263     $arch =~ s/\r|\n//g;
264
265     my $link = "/usr/lib/$arch-linux-gnu/libturbojpeg.so";
266
267     unless (-e $link)
268     {
269        print "Creating libjpegturbo symbolic link\n";
270        system("sudo ln -s $link.0 $link");
271     }
272 }
273
274 ################################################################################
275 # Helper to run and print out the command being run and quit if it fails
276 #
277 sub run_command
278 {
279   my $command = $_[0];
280   my $ret;
281   print("Running: $command\n");
282   $ret = system("$command");
283   if($ret >> 8) { die "$command failed \n"; }
284 }
285
286 ################################################################################
287 # later versions of v8 (post mid 2014) require googles depot_tools to build.
288 #
289 sub install_google_depot_tools
290 {
291
292 ####
293 # clone the depo_tools into the source directory and set the path up
294 ####
295     my $v8 = $_[0];
296
297     my $depot_tools_directory = $src_path . "/depot_tools";
298     my $depot_tools_repo = $v8->{"depot_tools_repo"};
299
300     # clear the directory if exists
301     rmtree( $depot_tools_directory );
302
303     # clone the depot tools
304     run_command( "git clone " . $depot_tools_repo. " " . $depot_tools_directory );
305
306     # add it the the path
307     $ENV{PATH} = "$ENV{PATH}:$depot_tools_directory";
308
309     # need to setup a config file for the proxy
310     create_boto_config_file( $v8 , $depot_tools_directory );
311
312     # set the config location as an environment variable ( used by scripts depot_tools)
313     $ENV{NO_AUTH_BOTO_CONFIG}="$src_path/depot_tools/.boto";
314
315     # change to depot tools directory
316     chdir( $depot_tools_directory );
317
318     # fetch v8
319     run_command("fetch --nohooks v8");
320
321 }
322
323
324 ################################################################################
325 # later versions of v8 use boto, which currently requires having proxy manually set
326 #
327 sub create_boto_config_file
328 {
329     my $v8 = $_[0];
330     my $depot_tools_directory = $_[1];
331     print(" depot_tools directory = $depot_tools_directory\n");
332
333     print("Configuring boto with http proxy IP = ". $http_proxy_ip . ", Port = " . $http_proxy_port . "\n");
334
335 # Create the proxy info for the boto file
336 my $fileContents = <<"END";
337 [Boto]
338 debug = 0
339 num_retries = 2
340
341 proxy = $http_proxy_ip
342 proxy_port = $http_proxy_port
343 END
344       # Place the config file in the depot tools folder
345     my $filename = $depot_tools_directory . "/" . ".boto";
346     print("Creating Boto config file with proxy settings to file ". $filename . "\n");
347     my $fh;
348     open( $fh, '>',  $filename );
349     print { $fh } $fileContents;
350     close( $fh );
351
352     # export the environment variable
353     run_command("gclient config https://gclient.googlecode.com/svn/trunk/gclient");
354
355     run_command("gclient runhooks");
356
357
358
359 }
360 ################################################################################
361 # We need a specific version of V8 to work with DALi
362 # - Check a txt file in dali-env to see if v8 needs upgrading (checks gcc version too)
363 # - Clones the source
364 # - builds dependencies (v8 automatically clones it's GYP build system)
365 # - Builds it
366 # - Create a package file
367 # It is cloned, then built from source, we create a package file for it, then
368 # it's copied into dali-env
369 sub install_v8
370 {
371     my $v8 = $_[0];
372     my $ret;
373     my $v8Version = $v8->{"version"};
374     print( "Checking if V8 ". $v8Version. " is installed \n");
375
376 ####
377 # Check currently installed version
378 # We create a text file with v8 and gcc version in the filename to compare with
379 # Version file is stored as "v8_2.3.4_installed_built_with_gcc_4_8_3.txt"
380 ####
381     # get the gcc version, so if the compiler is updated v8 is re-built
382     # note: v8 requires gcc version GCC >= 4.6
383     my $gccVersion = `gcc --version | grep ^gcc | sed 's/^.* //g'`;
384     chomp( $gccVersion );
385     my $versionTextFile = $src_path . "/v8_" . $v8Version. "_" . $v8->{"build-mode"} . "_installed_built_with_gcc_". $gccVersion .".txt";
386
387     # use stat to see if file exists
388     my @install_stats = stat $versionTextFile;
389     if( (scalar(@install_stats)) && $v8->{"force-rebuild"} != 1 )
390     {
391       print("Correct V8 version installed\n");
392       return;
393     }
394     else
395     {
396       # delete older versions of the version file first ( otherwise when downgrading it thinks version is still installed)
397       system( "rm " . $src_path . "/v8_*.txt  >/dev/null 2>&1");
398     }
399
400
401 ####
402 # Clone the v8 source repository and checkout the version we want
403 ####
404     # Need to clone it from repo
405     my $v8_source_directory;
406
407
408
409     # newer version of v8 use depot_tools with gclient, git cloned builds do not work
410     if( $v8->{"use_depot_tools"} == 1)
411     {
412       install_google_depot_tools( $v8 );
413
414       # v8 is checkout out under depot_tools path
415       $v8_source_directory = $src_path . "/depot_tools/v8";
416     }
417     else
418     {
419       $v8_source_directory = $src_path . "/v8";
420
421       # delete the old v8 source directpry if exists
422       rmtree( $v8_source_directory );
423
424       # clone the repository
425       run_command( "git clone " . $v8->{"repo"} . " " . $v8_source_directory );
426     }
427
428     # change to the source directoy for the checkout
429     chdir( $v8_source_directory );
430
431     # checkout the version DALi is compatible with
432     run_command( "git checkout ". $v8Version );
433
434 ####
435 # Run make dependencies then make for the specific target
436 ####
437     if( $v8->{"use_depot_tools"} == 1)
438     {
439       run_command("gclient sync");
440     }
441     else
442     {
443       run_command("make dependencies");
444     }
445
446     # assemble the make command
447     my $makeCommand = $v8->{"make"};
448
449     # need to append architecture and build mode, e.g. x64.debug
450     my $buildTarget;
451     if( $Config{use64bitint} ) {
452        print("Building 64 bit version of V8\n");
453        $buildTarget= "x64." . $v8->{"build-mode"}
454     }
455     else{
456       print("Building 32 bit version of V8\n");
457        $buildTarget= "ia32." . $v8->{"build-mode"}
458     }
459     $makeCommand .= " " . $buildTarget;
460     print("Running: $makeCommand\n");
461     run_command( $makeCommand );
462
463 ####
464 # Manually install the library / header files
465 ####
466
467     # Need to manually install (make install not available on v8 )
468     my $libSourceDir = "$v8_source_directory/out/$buildTarget/lib.target/";
469     my $headerSourceDir = "$v8_source_directory/include/";
470
471     my $libDestinationDir = $install_path . "/lib/";
472     my $headerDestinationDir = $install_path . "/include/v8/";
473
474     # delete any current v8 libs
475     system( "rm " . $libDestinationDir . "libv8*");
476     system( "rm " . $libDestinationDir . "libicu*");
477
478
479     # copy the library and header files
480     dircopy( $libSourceDir, $libDestinationDir);
481     dircopy( $headerSourceDir, $headerDestinationDir);
482
483
484     # Copy libv8.so to libv8.so.version (  e.g. libv8.so.1.2.4)
485     my $v8SoFile = $libDestinationDir . "libv8.so";
486     my $v8SoVersionFile = $libDestinationDir . "libv8.so." . $v8Version;
487     move( $v8SoFile, $v8SoVersionFile );
488
489     # symlink the libv8.so.1.2.3 to libv8.so
490     symlink( $v8SoVersionFile, $v8SoFile );
491     print( "source dir = " . $libSourceDir . " dest dir ". $libDestinationDir . " \n" );
492
493
494 ####
495 # Create the package file in,
496 # we keep the library files and header files in v8 sub-directories
497 ####
498 my $fileContents = <<"END";
499 prefix=$install_path
500 exec_prefix=\${prefix}
501 apiversion=$v8Version
502 libdir=\${exec_prefix}/lib
503 includedir=\${prefix}/include/v8
504
505 Name: v8 JavaScript engine - runtime library
506 Description: V8 is Google's open source JavaScript engine.
507 Version: \${apiversion}
508 Libs: -L\${libdir} -lv8 -licuuc -licui18n
509 Cflags: -I\${includedir}
510 END
511
512   my $filename = $install_path . "/lib/pkgconfig/" . "v8.pc";
513   print("writing to file ". $filename . "\n");
514   my $fh;
515   if( open( $fh, '>',  $filename ) )
516   {
517     print { $fh } $fileContents;
518     close( $fh );
519   }
520   else
521   {
522     die "failed to create " . $filename ."\n";
523   }
524
525   print("Installed V8 " .$v8Version . " OK\n");
526
527 #####
528 #
529 ####
530       my $versionFile;
531       open( $versionFile, '>',  $versionTextFile );
532       close( $versionFile );
533       print("Installing V8 version $v8Version\n");
534
535 }
536
537 ################################################################################
538 #                                       MAIN
539 ################################################################################
540
541
542 if($opt_create)
543 {
544     my $new_root = getcwd() . "/dali-env";
545
546     if($exec_path =~ m!dali-env/opt/bin!)
547     {
548         die "Already in a dali-env directory\n";
549         # Could query if user wants to re-create?
550     }
551     elsif(-e $root_path)
552     {
553         die "$root_path already exists\n";
554     }
555     elsif(-e $new_root)
556     {
557         die "A dali-env directory already exists here\n";
558     }
559
560     check_system_packages();
561
562     create_link();
563
564     create_env();
565
566     # do this after source directory structure created in create_env
567     check_source_packages();
568
569     create_setenv();
570 }
571 elsif($opt_setenv)
572 {
573     if(! -d $root_path)
574     {
575         die "$root_path does not exist\n";
576     }
577     elsif($new_env)
578     {
579         die "$root_path is not an existing environment\n";
580     }
581     create_setenv();
582 }
583 else
584 {
585     pod2usage(1);
586 }
587
588 __END__
589
590 =head1 NAME
591
592 dali_env - Create the DALi environment for Ubuntu
593
594 =head1 SYNOPSIS
595
596 dali_env [-c] [-s] [-h|-m]
597
598 =head1 OPTIONS
599
600 =over 28
601
602 =item B<-c|--create>
603
604 Create a DALi environment directory in the current directory.
605
606 =item B<-s|--setenv>
607
608 Display environment variables to setup.
609
610 =item B<-h|--help>
611
612 Display this help
613
614 =item B<-m|--man>
615
616 Display the manual page
617
618 =back
619
620 =head1 DESCRIPTION
621
622 B<dali_env>
623
624 Gets the required dependencies for DALi and them to a local directory. Can also create a setenv script to point to the installation.
625
626 =cut