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