Remove duplicated Erase iteration code by introducing EraseObject method in OwnerCont...
[platform/core/uifw/dali-core.git] / build / scripts / dali_env
index 99cc372..eaa4677 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 
-# Copyright (c) 2014 Samsung Electronics Co., Ltd.
+# Copyright (c) 2016 Samsung Electronics Co., Ltd.
 
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -39,7 +39,6 @@ my @system_packages = (
     "ccache",
     "libelementary-dev",
     "libexif-dev",
-    "libxml2-dev",
     "libgles2-mesa-dev",
     "libdrm-dev",
     "libgif-dev",
@@ -48,7 +47,18 @@ my @system_packages = (
     "libharfbuzz-dev",
     "doxygen",
     "lcov",
-    "libcurl4-gnutls-dev"
+    "libcurl4-gnutls-dev",
+);
+
+my @emscripten_system_packages = (
+    "gnome-common",
+    "curl",
+    "tar",
+    "build-essential",
+    "cmake",
+    "nodejs",
+    "default-jre",
+    "python2.7"
 );
 
 # Some packages like require building from source
@@ -63,7 +73,11 @@ my @source_pkgs = (
 
      # original version used with DALi is 3.25.19. 3.32.7 is the latest we can use before
      # upgrading DALi to use  c++0x or c++11
-     "version" => " 3.32.7", "make" => "make -j8 library=shared", "build-mode" =>"debug" }
+     "version" => " 3.32.7", "make" => "make -j8 library=shared", "build-mode" =>"debug" },
+
+    {"name" => "emscripten",
+     "portable" => "https://s3.amazonaws.com/mozilla-games/emscripten/releases/emsdk-portable.tar.gz"
+    }
 );
 
 ### Detect any http proxy, part of v8 installation requires this information
@@ -94,38 +108,56 @@ if($0 !~ m!^/!)
 $exec_path = dirname($exec_path);
 
 my $root_path = getcwd();
+
+# Search for the root dali-env directory
 if($exec_path =~ m!dali-env/opt/bin!)
 {
+    # We are using the installed dali_env script
+
     $root_path = $exec_path;
-    while($root_path !~ m!dali-env$!)
+    while(basename($root_path) ne "dali-env" && $root_path ne "")
     {
         $root_path = dirname($root_path);
     }
 }
-elsif($root_path =~ m!dali-env!)
+elsif($root_path =~ m!dali-env$! or $root_path =~ m!dali-env/!)
 {
-    while($root_path !~ m!dali-env$!)
+    # We are NOT using the installed dali_env script
+    # Find dali-env root from current directory
+
+    while(basename($root_path) ne "dali-env" && $root_path ne "")
     {
         $root_path = dirname($root_path);
     }
 }
 else
 {
-    $new_env = 1;
+    # dali-env root dir should be in the current directory
+
     $root_path .= "/dali-env";
+
+    if(! -e $root_path)
+    {
+      # Creating a new dali-env
+
+      $new_env = 1;
+    }
 }
 
-my $src_path     = "$root_path/src-packages";
-my $sbs_path     = "$root_path/target";
-my $install_path = "$root_path/opt";
+my $src_path         = "$root_path/src-packages";
+my $sbs_path         = "$root_path/target";
+my $install_path     = "$root_path/opt";
+my $emscripten_path  = "$root_path/emsdk_portable";
 
 my $opt_create=0;
 my $opt_setenv=0;
 my $opt_help=0;
 my $opt_man=0;
+my $opt_emscripten=0;
 
 GetOptions("create"     => \$opt_create,
            "setenv"     => \$opt_setenv,
+           "emscripten" => \$opt_emscripten,
            "help"       => \$opt_help,
            "man"        => \$opt_man) or pod2usage(2);
 
@@ -161,10 +193,28 @@ sub in_dali_env
 
 sub create_setenv
 {
+    if( ( -d $emscripten_path ) || $opt_emscripten )
+    {
+        print <<"EOF";
+#
+# Emscripten environment
+#  - which brazenly overwrites PATH so we set this first
+#  - NB: If you change the tools within emsdk then you'll need to recreate this file
+#
+
+EOF
+        my $emsdk_env_file = $emscripten_path . '/emsdk_set_env.sh';
+        open(FILE, $emsdk_env_file) or die "Can't read file enscripten env file" . $emsdk_env_file;
+        my @emsdk_env = <FILE>;
+        close (FILE);
+        print @emsdk_env;
+    }
+
     print <<"EOF";
+#
 # To use the desktop libraries, please add the following lines to your .bashrc or
 # create a setenv script from them, e.g. by running this command as follows
-# \$ dali_env -s > setenv
+# \$ $install_path/bin/dali_env -s > setenv
 #
 # You can then source this script by using
 # \$ . setenv
@@ -178,6 +228,9 @@ export LD_LIBRARY_PATH=$install_path/lib:\$LD_LIBRARY_PATH
 export INCLUDEDIR=$install_path/include
 export PKG_CONFIG_PATH=$install_path/lib/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig
 
+export DALI_WINDOW_WIDTH=480
+export DALI_WINDOW_HEIGHT=800
+
 EOF
 }
 
@@ -192,7 +245,7 @@ sub check_system_package
         if($x[0] ne "ii")
         {
             print "Attempting to install $package\n";
-            system("sudo apt-get -y install $package");
+            system("sudo apt-get -y --force-yes install $package");
         }
     }
 }
@@ -202,6 +255,12 @@ sub check_system_packages
     print "Checking for required system packages (may require sudo password)\n";
 
     check_system_package(@system_packages);
+
+    if($opt_emscripten)
+    {
+        check_system_package(@emscripten_system_packages);
+    }
+
     my $gnome_v =`dpkg -l gnome-common| tail -1| sed "s/ \\+/ /g" | cut -d' ' -f 3`;
     my @am = split(/\./, `automake --version | head -1 | cut -f4 -d' '`);
     if($gnome_v =~ /$2.24/ && $am[1]>10)
@@ -231,6 +290,10 @@ sub check_source_packages
         {
             install_v8( $pkgref );
         }
+        elsif($pkg eq "emscripten" && $opt_emscripten)
+        {
+            install_emscripten( $pkgref );
+        }
     }
 }
 
@@ -349,7 +412,7 @@ sub install_v8
 {
     my $v8 = $_[0];
     my $ret;
-    my $v8Version = $v8->{"version"} ;
+    my $v8Version = $v8->{"version"};
     print( "Checking if V8 ". $v8Version. " is installed \n");
 
 ####
@@ -513,6 +576,61 @@ END
 
 }
 
+################################################################################
+#
+# install the latest emscripten in a portable directory
+#
+################################################################################
+sub install_emscripten
+{
+    my $info = $_[0];
+    my $ret;
+    print( "Checking if Emscripten is up to date\n");
+
+    my $portable = $info->{"portable"};
+
+    my $current_dir = getcwd();
+
+    print( "\n");
+    print( "Installing or updating Emscripten.\n");
+    print( ".....You may need a cup of tea.\n");
+    print( ".......... In fact, take the afternoon off.\n");
+    print( "\n");
+
+    if(-e $emscripten_path)
+    {
+        chdir( $emscripten_path );
+    }
+    else
+    {
+        chdir( $root_path );
+
+        system("curl -O " . $portable) == 0
+            or die "curl failed with error $?. :" . $portable;
+
+        my($filename, $dirs, $suffix) = fileparse($portable);
+
+        system("tar -xvf " . $filename . $suffix) == 0
+            or die "tar unpack failed (nb tar.gz is the presumed downloaded format):" . $filename . $suffix;
+
+        system("rm " . $filename . $suffix) == 0
+            or die "Cannot remove emsdk portable tar file:" . $filename . $suffix;
+
+        chdir( $emscripten_path );
+    }
+
+    system("./emsdk update") == 0
+        or die "Cannot run emsdk? Did the install fail?";
+
+    system("./emsdk install latest");
+    system("./emsdk activate latest");
+    system("bash -c \"source ./emsdk_env.sh\""); # emsdk uses popd ie expects bash
+
+    system("emsdk list");
+
+    chdir($current_dir);
+}
+
 
 ################################################################################
 #                                       MAIN
@@ -528,6 +646,10 @@ if($opt_create)
         die "Already in a dali-env directory\n";
         # Could query if user wants to re-create?
     }
+    elsif(-e $root_path)
+    {
+        die "$root_path already exists\n";
+    }
     elsif(-e $new_root)
     {
         die "A dali-env directory already exists here\n";
@@ -583,6 +705,10 @@ Create a DALi environment directory in the current directory.
 
 Display environment variables to setup.
 
+=item B<-e|--emscripten>
+
+Include emscripten (use with -c to install with emscripten or -s to setup env vars with emscripten).
+
 =item B<-h|--help>
 
 Display this help