[dali_2.3.46] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / build / scripts / dali_env
1 #!/usr/bin/perl
2
3 # Copyright (c) 2024 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     "libmagick++-dev",
61     "libxml-parser-perl",
62 );
63
64 my $ubuntu_version = (split(/\s+/, `lsb_release -d`))[2];
65 if (${ubuntu_version} > 20)
66 {
67     # Add unique packages for 20.04 and above
68     push @system_packages, "libefl-all-dev";
69 }
70 else
71 {
72     # Add unique packages for Ubuntu releases before 20.04
73     push @system_packages, "libelementary-dev";
74 }
75
76 # Some packages like require building from source
77 # v8 is currently disabled until we can get it working without a http proxy being setup
78 my @source_pkgs = (
79
80     {"name" => "disabled-v8",
81      "force-rebuild" => 0,
82      "use_depot_tools" => 1,
83      "repo" => "https://chromium.googlesource.com/v8/v8.git",
84      "depot_tools_repo" => "https://chromium.googlesource.com/chromium/tools/depot_tools.git",
85
86      # original version used with DALi is 3.25.19. 3.32.7 is the latest we can use before
87      # upgrading DALi to use  c++0x or c++11
88      "version" => " 3.32.7", "make" => "make -j8 library=shared", "build-mode" =>"debug" },
89     {"name" => "gtest" },
90 );
91
92 ### Detect any http proxy, part of v8 installation requires this information
93 my $http_proxy_port;
94 my $http_proxy_ip;
95
96 if( exists $ENV{http_proxy} )
97 {
98   # string  split into 3 items  http, //ip, port
99   my @http_proxy_info =  split( /:/,$ENV{http_proxy}, );
100
101   $http_proxy_ip =  @http_proxy_info[1];
102   $http_proxy_ip =~ s/[\/]//g;;  # remove forward slashes
103   $http_proxy_port =  @http_proxy_info[2];
104 }
105
106 # Make best guess as to where this program was run from (note, it is
107 # always possible to override the location of $0 by the calling
108 # program, so we can't really tell for sure that this is where we
109 # expect it to be. :/
110
111 my $new_env   = 0;
112 my $exec_path = $0;
113 if($0 !~ m!^/!)
114 {
115     $exec_path = abs_path($0);
116 }
117 $exec_path = dirname($exec_path);
118
119 my $root_path = getcwd();
120
121 # Search for the root dali-env directory
122 if($exec_path =~ m!dali-env/opt/bin!)
123 {
124     # We are using the installed dali_env script
125
126     $root_path = $exec_path;
127     while(basename($root_path) ne "dali-env" && $root_path ne "")
128     {
129         $root_path = dirname($root_path);
130     }
131 }
132 elsif($root_path =~ m!dali-env$! or $root_path =~ m!dali-env/!)
133 {
134     # We are NOT using the installed dali_env script
135     # Find dali-env root from current directory
136
137     while(basename($root_path) ne "dali-env" && $root_path ne "")
138     {
139         $root_path = dirname($root_path);
140     }
141 }
142 else
143 {
144     # dali-env root dir should be in the current directory
145
146     $root_path .= "/dali-env";
147
148     if(! -e $root_path)
149     {
150       # Creating a new dali-env
151
152       $new_env = 1;
153     }
154 }
155
156 my $src_path         = "$root_path/src-packages";
157 my $sbs_path         = "$root_path/target";
158 my $install_path     = "$root_path/opt";
159
160 my $opt_create=0;
161 my $opt_force;
162 my $opt_envfile="setenv";
163 my $opt_setenv=0;
164 my $opt_help=0;
165 my $opt_man=0;
166 my $opt_vk_version="1.3.280.1";
167 my $opt_vulkan=undef;
168 my $opt_usd=0;
169
170 GetOptions("create"     => \$opt_create,
171            "envfile=s"  => \$opt_envfile,
172            "force"      => \$opt_force,
173            "setenv"     => \$opt_setenv,
174            "help"       => \$opt_help,
175            "vulkan:s"   => \$opt_vulkan,
176            "usd"        => \$opt_usd,
177            "man"        => \$opt_man) or pod2usage(2);
178
179 pod2usage(1) if $opt_help;
180 pod2usage(-exitstatus => 0, -verbose => 2) if $opt_man;
181
182 if($opt_vulkan ne "")
183 {
184     $opt_vk_version=$opt_vulkan;
185 }
186
187 ################################################################################
188
189 # Taken from IO::Interactive (to avoid yet more perl dependencies!)
190 sub is_interactive {
191     my ($out_handle) = (@_, select);    # Default to default output handle
192
193     # Not interactive if output is not to terminal...
194     return 0 if not -t $out_handle;
195
196     # If *ARGV is opened, we're interactive if...
197     if ( tied(*ARGV) or defined(fileno(ARGV)) ) { # this is what 'Scalar::Util::openhandle *ARGV' boils down to
198
199         # ...it's currently opened to the magic '-' file
200         return -t *STDIN if defined $ARGV && $ARGV eq '-';
201
202         # ...it's at end-of-file and the next file is the magic '-' file
203         return @ARGV>0 && $ARGV[0] eq '-' && -t *STDIN if eof *ARGV;
204
205         # ...it's directly attached to the terminal
206         return -t *ARGV;
207     }
208
209     # If *ARGV isn't opened, it will be interactive if *STDIN is attached
210     # to a terminal.
211     else {
212         return -t *STDIN;
213     }
214 }
215
216 ################################################################################
217
218 sub create_env
219 {
220     mkpath("$install_path/bin");
221     mkpath("$install_path/lib/pkgconfig");
222     mkpath("$install_path/include");
223     mkpath("$install_path/share/aclocal");
224     mkpath("$src_path");
225     mkpath("$sbs_path");
226
227     copy($0, "$install_path/bin/dali_env");
228     chmod(0755, "$install_path/bin/dali_env");
229 }
230
231 ################################################################################
232
233 sub in_dali_env
234 {
235     my $cwd = substr(getcwd(), 0, length($root_path));
236     #print "cwd = $cwd\nroot = $root_path\n";
237     return $cwd eq $root_path;
238 }
239
240 ################################################################################
241
242 sub create_setenv
243 {
244     # Setup vulkan environment if necessary
245     my $vulkan_env="";
246     if(defined($opt_vulkan))
247     {
248         $vulkan_env=<<"EOF";
249 export VULKAN_VERSION=${opt_vk_version}
250 export VULKAN_ROOT=${root_path}/vulkan/\${VULKAN_VERSION}
251 . \${VULKAN_ROOT}/setup-env.sh
252 EOF
253     }
254
255     my $oldfh;
256     my $fh;
257     if($opt_envfile && is_interactive())
258     {
259         print "Writing environment script to $opt_envfile\n";
260         open($fh, ">", $opt_envfile)|| die "Can't open $opt_envfile for writing:$!\n";
261         $oldfh = select($fh);
262     }
263
264     print <<"EOF";
265 # To use the desktop libraries, please add the following lines to your .bashrc or
266 # create a setenv script from them, e.g. by running this command as follows
267 # \$ $install_path/bin/dali_env -s
268 #
269 # You can then source this script by using
270 # \$ . setenv
271 #
272 # Use DESKTOP_PREFIX when running configure or cmake in dali/build/tizen:
273 # \$ CXXFLAGS="-g -O0" ./configure --prefix=\$DESKTOP_PREFIX
274 # _OR_
275 # \$ CXXFLAGS="-g -O0" cmake -DCMAKE_INSTALL_PREFIX=\$DESKTOP_PREFIX
276
277 ${vulkan_env}
278 export DESKTOP_PREFIX=$install_path
279 export PATH=$install_path/bin:\$PATH
280 export LD_LIBRARY_PATH=$install_path/lib:\$LD_LIBRARY_PATH
281 export INCLUDEDIR=$install_path/include
282 export PKG_CONFIG_PATH=$install_path/lib/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig
283 export DOTNET_CLI_TELEMETRY_OPTOUT=1
284 export DALI_MULTI_SAMPLING_LEVEL=4
285 export DALI_WINDOW_WIDTH=480
286 export DALI_WINDOW_HEIGHT=800
287
288 EOF
289     if($fh)
290     {
291         close($fh);
292         select($oldfh);
293     }
294 }
295
296 ################################################################################
297 sub download_archive
298 {
299     my ($archive, $url, $download_info) = @_;
300
301     # Avoid excessive downloading of the same file
302     if(! -e "/tmp/$archive")
303     {
304         print "Downloading $download_info\nfrom: $url\n";
305         system('wget','-P','/tmp',$url);
306         die "Can't download archive" if(! -e "/tmp/$archive");
307     }
308 }
309
310 sub untar_archive
311 {
312     my $archive=shift;
313     system('tar','-xf',"/tmp/$archive", '--checkpoint=5000', '--checkpoint-action=ttyout=.');
314 }
315
316 sub install_vulkan
317 {
318     if(defined($opt_vulkan))
319     {
320         my $archive="vulkansdk-linux-x86_64-${opt_vk_version}.tar.xz";
321         my $url="https://sdk.lunarg.com/sdk/download/${opt_vk_version}/linux/$archive";
322         download_archive($archive, $url, "Vulkan SDK version ${opt_vk_version}");
323
324         my $vulkan_install_path="$root_path/vulkan";
325         print "Unpacking vulkan archive\n";
326         mkpath($vulkan_install_path);
327         chdir($vulkan_install_path);
328         untar_archive($archive);
329         print("\n");
330         chdir("$root_path/..");
331
332         my $fh;
333         open($fh, ">", "$install_path/lib/pkgconfig/vulkan.pc") || die "Can't open vulkan.pc for writing: $!\n";
334
335         $vulkan_install_path .= "/${opt_vk_version}";
336         print $fh <<"EOF";
337 prefix=${vulkan_install_path}/x86_64
338 exec_prefix=${vulkan_install_path}/x86_64
339 libdir=\${prefix}/lib
340 includedir=\${prefix}/include
341
342 Name: Vulkan-Loader
343 Description: Vulkan Loader
344 Version: ${opt_vk_version}
345 Libs: -L\${libdir} -lvulkan
346 Libs.private:  -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
347 Cflags: -I\${includedir}
348 EOF
349         close($fh);
350
351         open($fh, ">", "$install_path/lib/pkgconfig/glslang.pc") || die "Can't open glslang.pc for writing: $!\n";
352         print $fh <<"EOF";
353 prefix=${vulkan_install_path}/x86_64
354 exec_prefix=${vulkan_install_path}/x86_64
355 libdir=\${prefix}/lib
356 includedir=\${prefix}/include
357
358 Name: glslang
359 Description: OpenGL and OpenGL ES shader front end and validator
360 Version: ${opt_vk_version}
361 Libs: -L\${libdir} -lglslang -lOSDependent -lSPVRemapper -lshaderc -lshaderc_combined
362 Cflags: -I\${includedir}
363 EOF
364         close($fh);
365
366         open($fh, ">", "$install_path/lib/pkgconfig/SPIRV-Tools.pc") || die "Can't open SPIRV-Tools.pc for writing: $!\n";
367         print $fh <<"EOF";
368 prefix=${vulkan_install_path}/x86_64
369 exec_prefix=${vulkan_install_path}/x86_64
370 libdir=\${prefix}/lib
371 includedir=\${prefix}/include
372
373 Name: SPIRV-Tools
374 Description: Tools for SPIR-V
375 Version: ${opt_vk_version}
376 Libs: -L\${libdir} -lSPIRV-Tools -lSPIRV-Tools-link -lSPIRV-Tools-opt
377 Cflags: -I\${includedir}
378 EOF
379         close($fh);
380
381         print "Written pkg-config files to $install_path/lib/pkg-config\n";
382     }
383 }
384
385 sub install_usd
386 {
387     if($opt_usd)
388     {
389         my $boost_archive="boost-1.84.0.tar.gz";
390         my $boost_url="https://github.com/boostorg/boost/releases/download/boost-1.84.0/$boost_archive";
391         download_archive($boost_archive, $boost_url, "Boost");
392
393         my $tbb_archive="2019_U9.tar.gz";
394         my $tbb_url="https://github.com/oneapi-src/oneTBB/archive/refs/tags/$tbb_archive";
395         download_archive($tbb_archive, $tbb_url, "LibTBB");
396
397         my $openusd_archive="32-bit-arm-and-tizen-support.tar.gz";
398         my $openusd_url="https://github.com/dalihub/OpenUSD/archive/refs/tags/$openusd_archive";
399         download_archive($openusd_archive, $openusd_url, "OpenUSD");
400
401         my $usd_install_path=$install_path;
402         my $usd_source_path="$src_path/usd";
403
404         print "Unpacking Boost, TBB & OpenUSD archives\n";
405         mkpath($usd_source_path);
406         chdir($usd_source_path);
407         untar_archive($boost_archive);
408         untar_archive($tbb_archive);
409         untar_archive($openusd_archive);
410
411         mkpath("$usd_install_path/lib");
412         mkpath("$usd_install_path/include");
413
414         my $boost_source_path="$usd_source_path/boost-1.84.0";
415         print "Building Boost\n";
416         chdir("$boost_source_path");
417         system('cmake',"-DCMAKE_INSTALL_PREFIX=$usd_install_path", '.');
418         system('make','-j8','install');
419
420         my $tbb_source_path="$usd_source_path/oneTBB-2019_U9";
421         print "Building TBB\n";
422         chdir("$tbb_source_path");
423         system('make','-j8');
424         my $tbbBuildFolder=`make info | grep tbb_build_prefix | cut -d= -f 2`;
425         chomp($tbbBuildFolder);
426         $tbbBuildFolder=$tbbBuildFolder . "_release";
427         print "$tbbBuildFolder Hello";
428         system("install -m 644 ./build/$tbbBuildFolder/*.so* $usd_install_path/lib/");
429         system('cp','-rf','include/tbb',"$usd_install_path/include/");
430
431         my $openusd_source_path="$usd_source_path/OpenUSD-32-bit-arm-and-tizen-support";
432         print "Building USD\n";
433         chdir("$openusd_source_path");
434         system('cmake',
435                '-DPXR_ENABLE_PYTHON_SUPPORT=OFF',
436                '-DPXR_ENABLE_PTEX_SUPPORT=OFF',
437                '-DPXR_ENABLE_OPENVDB_SUPPORT=OFF',
438                '-DPXR_ENABLE_HDF5_SUPPORT=OFF',
439                '-DPXR_ENABLE_MATERIALX_SUPPORT=OFF',
440                '-DPXR_BUILD_IMAGING=OFF',
441                '-DPXR_BUILD_USD_IMAGING=OFF',
442                '-DPXR_BUILD_USDVIEW=OFF',
443                '-DPXR_BUILD_DOCUMENTATION=OFF',
444                '-DPXR_BUILD_HTML_DOCUMENTATION=OFF',
445                '-DPXR_BUILD_PYTHON_DOCUMENTATION=OFF',
446                '-DPXR_BUILD_TESTS=OFF',
447                '-DPXR_BUILD_EXAMPLES=OFF',
448                '-DPXR_BUILD_TUTORIALS=OFF',
449                '-DPXR_BUILD_USD_TOOLS=OFF',
450                '-DPXR_BUILD_MAYAPY_TESTS=OFF',
451                '-DPXR_BUILD_ANIMX_TESTS=OFF',
452                "-DTBB_ROOT_DIR=$usd_install_path",
453                "-DBOOST_ROOT=$usd_install_path",
454                "-DCMAKE_INSTALL_PREFIX=$usd_install_path",
455                '.'
456               );
457         system('make','-j8','install');
458
459         print("\n");
460         chdir("$root_path/..");
461     }
462 }
463
464 sub check_system_package
465 {
466     my $package;
467     foreach $package (@_)
468     {
469         my @x=split(/\s+/, `dpkg -l $package 2> /dev/null|grep $package`);
470         if($x[0] ne "ii")
471         {
472             # Check if the package is available to install, exit-code is 0 if the package is found.
473             if(system("apt-cache show $package > /dev/null 2>&1") == 0)
474             {
475                 print "Attempting to install $package\n";
476                 system("sudo apt-get -y --allow-change-held-packages --allow-downgrades install $package");
477             }
478         }
479     }
480 }
481
482 sub check_system_packages
483 {
484     print "Checking for required system packages (may require sudo password)\n";
485
486     check_system_package(@system_packages);
487
488     my $gnome_v =`dpkg -l gnome-common| tail -1| sed "s/ \\+/ /g" | cut -d' ' -f 3`;
489     my @am = split(/\./, `automake --version | head -1 | cut -f4 -d' '`);
490     if($gnome_v =~ /$2.24/ && $am[1]>10)
491     {
492         die "Gnome common and automake are not compatible - automake is too new\n";
493     }
494     my @gpp_v = (`g++ --version  | head -1` =~ /(\d+)\.(\d+)\.(\d+)/);
495
496     if(! (($gpp_v[0] > 4)
497           ||
498           ($gpp_v[0] == 4 && $gpp_v[1] > 4)
499           ||
500           ($gpp_v[0] == 4 && $gpp_v[1] == 4 && $gpp_v[2] >= 5)))
501     {
502         die "You need g++ 4.5.1 or greater to build dali\n";
503     }
504 }
505
506 sub check_source_packages
507 {
508     my $pkgref;
509
510     foreach $pkgref (@source_pkgs)
511     {
512         my $pkg = $pkgref->{"name"};
513         if($pkg eq "v8")
514         {
515             install_v8( $pkgref );
516         }
517         elsif ($pkg eq "gtest")
518         {
519             if(! -e "/usr/lib/libgtest.a")
520             {
521                 print "Attempting to build $pkg\n";
522                 # from https://www.eriksmistad.no/getting-started-with-google-test-on-ubuntu/
523                 run_command("cd /usr/src/gtest; sudo cmake CMakeLists.txt; sudo make; sudo cp lib/*.a /usr/lib; cd -;");
524             }
525         }
526     }
527 }
528
529 ################################################################################
530
531 sub create_link
532 {
533     my $arch=`uname -i`;
534     $arch =~ s/\r|\n//g;
535
536     my $link = "/usr/lib/$arch-linux-gnu/libturbojpeg.so";
537
538     unless (-e $link)
539     {
540        print "Creating libjpegturbo symbolic link\n";
541        system("sudo ln -s $link.0 $link");
542     }
543 }
544
545 ################################################################################
546 # Helper to run and print out the command being run and quit if it fails
547 #
548 sub run_command
549 {
550   my $command = $_[0];
551   my $ret;
552   print("Running: $command\n");
553   $ret = system("$command");
554   if($ret >> 8) { die "$command failed \n"; }
555 }
556
557 ################################################################################
558 # later versions of v8 (post mid 2014) require googles depot_tools to build.
559 #
560 sub install_google_depot_tools
561 {
562
563 ####
564 # clone the depo_tools into the source directory and set the path up
565 ####
566     my $v8 = $_[0];
567
568     my $depot_tools_directory = $src_path . "/depot_tools";
569     my $depot_tools_repo = $v8->{"depot_tools_repo"};
570
571     # clear the directory if exists
572     rmtree( $depot_tools_directory );
573
574     # clone the depot tools
575     run_command( "git clone " . $depot_tools_repo. " " . $depot_tools_directory );
576
577     # add it the the path
578     $ENV{PATH} = "$ENV{PATH}:$depot_tools_directory";
579
580     # need to setup a config file for the proxy
581     create_boto_config_file( $v8 , $depot_tools_directory );
582
583     # set the config location as an environment variable ( used by scripts depot_tools)
584     $ENV{NO_AUTH_BOTO_CONFIG}="$src_path/depot_tools/.boto";
585
586     # change to depot tools directory
587     chdir( $depot_tools_directory );
588
589     # fetch v8
590     run_command("fetch --nohooks v8");
591
592 }
593
594
595 ################################################################################
596 # later versions of v8 use boto, which currently requires having proxy manually set
597 #
598 sub create_boto_config_file
599 {
600     my $v8 = $_[0];
601     my $depot_tools_directory = $_[1];
602     print(" depot_tools directory = $depot_tools_directory\n");
603
604     print("Configuring boto with http proxy IP = ". $http_proxy_ip . ", Port = " . $http_proxy_port . "\n");
605
606 # Create the proxy info for the boto file
607 my $fileContents = <<"END";
608 [Boto]
609 debug = 0
610 num_retries = 2
611
612 proxy = $http_proxy_ip
613 proxy_port = $http_proxy_port
614 END
615       # Place the config file in the depot tools folder
616     my $filename = $depot_tools_directory . "/" . ".boto";
617     print("Creating Boto config file with proxy settings to file ". $filename . "\n");
618     my $fh;
619     open( $fh, '>',  $filename );
620     print { $fh } $fileContents;
621     close( $fh );
622
623     # export the environment variable
624     run_command("gclient config https://gclient.googlecode.com/svn/trunk/gclient");
625
626     run_command("gclient runhooks");
627
628
629
630 }
631 ################################################################################
632 # We need a specific version of V8 to work with DALi
633 # - Check a txt file in dali-env to see if v8 needs upgrading (checks gcc version too)
634 # - Clones the source
635 # - builds dependencies (v8 automatically clones it's GYP build system)
636 # - Builds it
637 # - Create a package file
638 # It is cloned, then built from source, we create a package file for it, then
639 # it's copied into dali-env
640 sub install_v8
641 {
642     my $v8 = $_[0];
643     my $ret;
644     my $v8Version = $v8->{"version"};
645     print( "Checking if V8 ". $v8Version. " is installed \n");
646
647 ####
648 # Check currently installed version
649 # We create a text file with v8 and gcc version in the filename to compare with
650 # Version file is stored as "v8_2.3.4_installed_built_with_gcc_4_8_3.txt"
651 ####
652     # get the gcc version, so if the compiler is updated v8 is re-built
653     # note: v8 requires gcc version GCC >= 4.6
654     my $gccVersion = `gcc --version | grep ^gcc | sed 's/^.* //g'`;
655     chomp( $gccVersion );
656     my $versionTextFile = $src_path . "/v8_" . $v8Version. "_" . $v8->{"build-mode"} . "_installed_built_with_gcc_". $gccVersion .".txt";
657
658     # use stat to see if file exists
659     my @install_stats = stat $versionTextFile;
660     if( (scalar(@install_stats)) && $v8->{"force-rebuild"} != 1 )
661     {
662       print("Correct V8 version installed\n");
663       return;
664     }
665     else
666     {
667       # delete older versions of the version file first ( otherwise when downgrading it thinks version is still installed)
668       system( "rm " . $src_path . "/v8_*.txt  >/dev/null 2>&1");
669     }
670
671
672 ####
673 # Clone the v8 source repository and checkout the version we want
674 ####
675     # Need to clone it from repo
676     my $v8_source_directory;
677
678
679
680     # newer version of v8 use depot_tools with gclient, git cloned builds do not work
681     if( $v8->{"use_depot_tools"} == 1)
682     {
683       install_google_depot_tools( $v8 );
684
685       # v8 is checkout out under depot_tools path
686       $v8_source_directory = $src_path . "/depot_tools/v8";
687     }
688     else
689     {
690       $v8_source_directory = $src_path . "/v8";
691
692       # delete the old v8 source directpry if exists
693       rmtree( $v8_source_directory );
694
695       # clone the repository
696       run_command( "git clone " . $v8->{"repo"} . " " . $v8_source_directory );
697     }
698
699     # change to the source directoy for the checkout
700     chdir( $v8_source_directory );
701
702     # checkout the version DALi is compatible with
703     run_command( "git checkout ". $v8Version );
704
705 ####
706 # Run make dependencies then make for the specific target
707 ####
708     if( $v8->{"use_depot_tools"} == 1)
709     {
710       run_command("gclient sync");
711     }
712     else
713     {
714       run_command("make dependencies");
715     }
716
717     # assemble the make command
718     my $makeCommand = $v8->{"make"};
719
720     # need to append architecture and build mode, e.g. x64.debug
721     my $buildTarget;
722     if( $Config{use64bitint} ) {
723        print("Building 64 bit version of V8\n");
724        $buildTarget= "x64." . $v8->{"build-mode"}
725     }
726     else{
727       print("Building 32 bit version of V8\n");
728        $buildTarget= "ia32." . $v8->{"build-mode"}
729     }
730     $makeCommand .= " " . $buildTarget;
731     print("Running: $makeCommand\n");
732     run_command( $makeCommand );
733
734 ####
735 # Manually install the library / header files
736 ####
737
738     # Need to manually install (make install not available on v8 )
739     my $libSourceDir = "$v8_source_directory/out/$buildTarget/lib.target/";
740     my $headerSourceDir = "$v8_source_directory/include/";
741
742     my $libDestinationDir = $install_path . "/lib/";
743     my $headerDestinationDir = $install_path . "/include/v8/";
744
745     # delete any current v8 libs
746     system( "rm " . $libDestinationDir . "libv8*");
747     system( "rm " . $libDestinationDir . "libicu*");
748
749
750     # copy the library and header files
751     dircopy( $libSourceDir, $libDestinationDir);
752     dircopy( $headerSourceDir, $headerDestinationDir);
753
754
755     # Copy libv8.so to libv8.so.version (  e.g. libv8.so.1.2.4)
756     my $v8SoFile = $libDestinationDir . "libv8.so";
757     my $v8SoVersionFile = $libDestinationDir . "libv8.so." . $v8Version;
758     move( $v8SoFile, $v8SoVersionFile );
759
760     # symlink the libv8.so.1.2.3 to libv8.so
761     symlink( $v8SoVersionFile, $v8SoFile );
762     print( "source dir = " . $libSourceDir . " dest dir ". $libDestinationDir . " \n" );
763
764
765 ####
766 # Create the package file in,
767 # we keep the library files and header files in v8 sub-directories
768 ####
769 my $fileContents = <<"END";
770 prefix=$install_path
771 exec_prefix=\${prefix}
772 apiversion=$v8Version
773 libdir=\${exec_prefix}/lib
774 includedir=\${prefix}/include/v8
775
776 Name: v8 JavaScript engine - runtime library
777 Description: V8 is Google's open source JavaScript engine.
778 Version: \${apiversion}
779 Libs: -L\${libdir} -lv8 -licuuc -licui18n
780 Cflags: -I\${includedir}
781 END
782
783   my $filename = $install_path . "/lib/pkgconfig/" . "v8.pc";
784   print("writing to file ". $filename . "\n");
785   my $fh;
786   if( open( $fh, '>',  $filename ) )
787   {
788     print { $fh } $fileContents;
789     close( $fh );
790   }
791   else
792   {
793     die "failed to create " . $filename ."\n";
794   }
795
796   print("Installed V8 " .$v8Version . " OK\n");
797
798 #####
799 #
800 ####
801       my $versionFile;
802       open( $versionFile, '>',  $versionTextFile );
803       close( $versionFile );
804       print("Installing V8 version $v8Version\n");
805
806 }
807
808 ################################################################################
809 #                                       MAIN
810 ################################################################################
811
812
813 if($opt_create)
814 {
815     my $new_root = getcwd() . "/dali-env";
816
817     if($exec_path =~ m!dali-env/opt/bin!)
818     {
819         die "Already in a dali-env directory\n";
820         # Could query if user wants to re-create?
821     }
822     elsif(-e $root_path && !$opt_force)
823     {
824         die "$root_path already exists\n";
825     }
826     elsif(-e $new_root && !$opt_force)
827     {
828         die "A dali-env directory already exists here\n";
829     }
830     if($opt_force)
831     {
832         system('rm','-rf',"$root_path");
833     }
834
835     check_system_packages();
836
837     create_link();
838
839     create_env();
840
841     # do this after source directory structure created in create_env
842     check_source_packages();
843
844     install_vulkan();
845     install_usd();
846     create_setenv();
847 }
848 elsif($opt_setenv)
849 {
850     if(! -d $root_path)
851     {
852         die "$root_path does not exist\n";
853     }
854     elsif($new_env)
855     {
856         die "$root_path is not an existing environment\n";
857     }
858     create_setenv();
859 }
860 else
861 {
862     pod2usage(1);
863 }
864
865 __END__
866
867 =head1 NAME
868
869 dali_env - Create the DALi environment for Ubuntu
870
871 =head1 SYNOPSIS
872
873 dali_env [-c] [-s] [-h|-m]
874
875 =head1 OPTIONS
876
877 =over 28
878
879 =item B<-c|--create>
880
881 Create a DALi environment directory in the current directory.
882
883 =item B<-f|--force>
884
885 Removes any existing dali-env directory before creating a new one.
886
887 =item B<-s|--setenv>
888
889 If run interactively, then writes environment variables to environment file.
890 If non-interactive, then outputs environment to STDOUT.
891
892 =item B<-e|--envfile> environment-file
893
894 Set the filename for the environment settings, defaults to "setenv"
895
896 =item B<-v|--vulkan> [vulkan-option]
897
898 Install the Vulkan SDK (By default, uses 1.3.280.1) with the optional version
899 number. Adds several .pc files into dali-env/opt/lib/pkg-config directory,
900 and requires a new environment file to be written.
901
902 =item B<-u|--usd>
903
904 Installs the OpenUSD library and its dependencies.
905
906 =item B<-h|--help>
907
908 Display this help
909
910 =item B<-m|--man>
911
912 Display the manual page
913
914 =back
915
916 =head1 DESCRIPTION
917
918 B<dali_env>
919
920 Gets the required dependencies for DALi and installs them to a local directory. Can also create a setenv script to point to the installation.
921
922 =cut