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