[Feature]Upload Modem source code

Change-Id: Id4294f30faced84d3e6fd6d5e61e1111bf287a37
diff --git a/mcu/make.pl b/mcu/make.pl
new file mode 100644
index 0000000..e2d302b
--- /dev/null
+++ b/mcu/make.pl
@@ -0,0 +1,1813 @@
+#!/usr/bin/env perl 
+# 
+# Copyright Statement:
+# --------------------
+# This software is protected by Copyright and the information contained
+# herein is confidential. The software may not be copied and the information
+# contained herein may not be used or disclosed except with the written
+# permission of MediaTek Inc. (C) 2005
+# 
+# BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+# THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+# RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+# AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+# NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+# SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+# SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+# THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+# NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+# SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+# 
+# BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+# LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+# AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+# OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+# MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+# 
+# THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+# WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+# LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+# RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+# THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+# 
+BEGIN {
+  push @INC, '.';
+}
+$ENV{'PERL_USE_UNSAFE_INC'} = 1;
+# let Python NOT try to write .pyc files.
+$ENV{'PYTHONDONTWRITEBYTECODE'} = 1;
+
+require v5.8.6;
+BEGIN { push @INC, './'};
+use Cwd;
+use File::Copy;
+use File::Path;
+use File::Basename;
+use if ($^O eq "MSWin32"), Win32API::Registry => qw(:ALL);
+
+if ($^O ne "MSWin32") {
+  $ENV{"NUMBER_OF_PROCESSORS"} = `cat /proc/cpuinfo | grep 'processor' | wc -l | tr -d '\n'`;
+}
+
+# for mbis start stamp
+# get submit to queue epoch time
+my $submit_to_queue_time_string = "";
+if ($ENV{'SUBMIT_TO_QUEUE_GMT_TIMESTAMP'})
+{
+  my ($sec, $min, $hour, $mday, $mon, $year) = gmtime($ENV{'SUBMIT_TO_QUEUE_GMT_TIMESTAMP'}+28800);
+  $submit_to_queue_time_string = sprintf("%4.4d.%2.2d.%2.2d.%2.2d.%2.2d.%2.2d", $year+1900, $mon+1, $mday, $hour, $min, $sec);
+}
+
+# get epoch timestamp
+$build_time_sec = time;
+
+# convert to GMT+8 time
+($sec, $min, $hour, $mday, $mon, $year) = gmtime($build_time_sec+28800);
+$build_time_string = sprintf("%4.4d.%2.2d.%2.2d.%2.2d.%2.2d.%2.2d", $year+1900, $mon+1, $mday, $hour, $min, $sec);
+
+$core_root = "pcore";
+$plat      = "";
+@arguments = ();
+$project   = "";
+$action    = "";
+$m_in_lsf  = 0;
+$local_q   = 0;
+@mOpts     = ();
+$fullOpts  = "";
+$level     = "";
+$relDir    = "";
+$ini       = "build/make.ini";
+$myMF      = "build.mak";
+$enINI     = 1;
+($#ARGV < 0) && &Usage;
+(($#ARGV < 1) && ($enINI == 0)) && &Usage;
+
+my $newMoDIS    = 0;
+my $bypassMoDIS = 0;
+my $atMoDIS     = 0;
+my $newUESim    = 0;
+my $pureMoDIS   = 0;
+my $packMoDIS   = 0;
+my $chk_cmd     = 0;
+my $parallel_module_build = "NONE";
+
+my $concatenate_proj_mak = "";
+my $modisDir             = "";
+my $target_option        = "";
+
+$eutran_mode_support = "";
+$dummyvm = 0;
+
+#mbis default enable
+$mbis = "tools/mbis.pl";
+$arg_mbis_en          = "FALSE";
+$arg_mbis_en_obj_log  = "FALSE";
+$arg_mbis_en_save_log = "FALSE";
+$mbis_arg_exist       = 0;
+$mbis_en              = "FALSE";
+$mbis_en_obj_log      = "FALSE";
+$mbis_en_save_log     = "FALSE";
+@mbis_arg = ();
+if ($^O eq "MSWin32") {
+  if ($ENV{'LTE_DOMAIN'} eq "TRUE") {
+    $mbis_conf_file = "\\\\mtklwafs01\\moly\\wcpsm\\config\\mbis_conf.ini";
+  }
+  else {
+    $mbis_conf_file = "\\\\glbfs14\\sw_releases\\mbis\\scripts\\MBIS_conf.ini";
+  }
+}
+$mbis_conf_file = "/mtkeda/wcpsm/mbis/config/mbis_conf.ini" if($^O eq "linux");
+@orgARGVwithFlavor = ();
+$mbis_num_proc = 0;
+$mbis_target_build_with_Modis = 0;
+@actions = qw(errc_gen new update remake clean codegen emiclean emigen sysgen sys_auto_gen sys_mem_gen ckmemlayout drv_feature_check c,r c,u scan check_scan check check_dep remake_dep update_dep clean_codegen slim_codegen slim_update genlog elfpatch cksysdrv nvram_auto_gen cust_menu_tree_check genmoduleinfo gendummylis gendummysym umts_gen asngen asngen_l4 asnregen slim_mcddll lte_mcddll eas_gen memquery cga mcddll_update update_dsp);
+@orgARGV = @ARGV;
+@orgARGVwithFlavor = @orgARGV;
+$flavor = "DEFAULT";
+$localq_disk = "z:";
+$makeFolder = "make/common/";
+$projMakeFolder = "make/projects/";
+$OSversion = $^O;
+
+if ($^O eq "MSWin32") {
+  $makeCmd = "tools/make.exe";
+} else {
+  $makeCmd = "make";
+}
+
+if ($ENV{'MTK_INTERNAL'} eq 'TRUE') {
+  # MTK_INTERNAL is a internal environment flag
+} elsif (($ENV{'USERDOMAIN'} =~ /MTK|PMT|MBJ|MSZ|MTI|WISE|MEDIATEK|MWS|GCN|APJ/i) && ($ENV{'USERDNSDOMAIN'} =~ /MEDIATEK\.INC/i)) {
+  warn "Current user is from MTK internal, but the environment MTK_INTERNAL != TRUE\nPlease check ! Build script will continue after 30 sec.\n";
+  sleep 30;
+  $ENV{'MTK_INTERNAL'} = 'TRUE';
+}
+
+if (($ENV{'MTK_INTERNAL'} eq 'TRUE') && (-e "mtk_tools/Internal_function.pm")) {
+  require mtk_tools::Internal_function;
+}
+
+$no_pcibt      = "FALSE";
+$no_ltelib     = "FALSE";
+$no_ltecgen    = "FALSE";
+$no_dsp        = "FALSE";
+$update_dsp    = "FALSE";
+$deterministic = "FALSE";
+$no_warning_as_error = "FALSE";
+$VarioationProj_name = "";
+$force_getlte        = "FALSE";
+$ota_name        = "DEFAULT";
+$tareget_options = "";
+$ccache_dir      = "";
+$ccache_size     = "";
+$ccache_basedir  = "";
+$chk_rel_pkg     = "";
+$check_fo_license = "FALSE";
+$license_info     = "DEFAULT";
+$cust_lic         = "DEFAULT";
+$smart = 0;
+
+if(($ENV{'REDIRECT_OUT_DIR'} eq 'TRUE') && (defined $ENV{'OUT_DIR'})) {
+  print "ENV REDIRECT_OUT_DIR = $ENV{'REDIRECT_OUT_DIR'}\n";
+  print "OUT_DIR = $ENV{'OUT_DIR'}\n";
+  print "Trigger CF TO LOCAL success\n";
+  print "Prepare to create OUT folder and link...\n";
+  system("mkdir -p $ENV{'OUT_DIR'}/build") if (!-d "$ENV{'OUT_DIR'}/build");
+  system("mkdir -p $ENV{'OUT_DIR'}/build_internal") if (!-d "$ENV{'OUT_DIR'}/build_internal");
+  system("ln -sf $ENV{'OUT_DIR'}/build build");
+  system("ln -sf $ENV{'OUT_DIR'}/build_internal build_internal");
+  print "Prepare to create OUT folder and link...Done\n";
+}
+
+while ($#ARGV != -1) {
+  if ($ARGV[0] =~ /-bullseye$/i) {
+    $target_option .= " BULLSEYE_CONFIG=TRUE ";
+    $ENV{'COVBUILDZONE'}="$$";
+  } elsif ($ARGV[0] =~ /-bullseye=(.*)/i) {
+    $target_option .= " BULLSEYE_CONFIG=TRUE BULLSEYE_COVFILE=\"$1\" ";
+  } elsif ($ARGV[0] =~ /-clang7$/i) {
+    $target_option .= " CLANG_VER=7.0.0 ";
+  } elsif ($ARGV[0] =~ /-llvm-coverage$/i) {
+    $target_option .= " LLVM_COVERAGE=TRUE ";
+  } elsif ($ARGV[0] =~ /-modis/i) {
+    $newMoDIS = 1;
+  } elsif ($ARGV[0] =~ /-forcemodis/i) {
+    $bypassMoDIS = -1;
+  } elsif ($ARGV[0] =~ /-puremodis/i) {
+    $pureMoDIS = 1;
+  } elsif ($ARGV[0] =~ /-no_puremodis/i) {
+    $pureMoDIS = -1;
+  } elsif ($ARGV[0] =~ /-packmodis/i) {
+    $packMoDIS = 1;
+  } elsif ($ARGV[0] =~ /-no_packmodis/i) {
+    $packMoDIS = -1;
+  } elsif ($ARGV[0] =~ /-uesim/i) {
+    $newUESim = 1;
+  } elsif ($ARGV[0] =~ /-release/i) {
+    $modisDir = "Release";
+  } elsif ($ARGV[0] =~ /-debug/i) {
+    $modisDir = "Debug";
+  } elsif ($ARGV[0] =~ /-h/i) {
+    &Usage;
+  } elsif ($ARGV[0] =~ /^-(o|op|opt)=(.*)$/i) {
+    $fullOpts = $2;
+    $fullOpts =~ s/,/ /g;
+  } elsif ($ARGV[0] =~ /-lsf/i) {
+    $m_in_lsf = 1;
+  } elsif ($ARGV[0] =~ /-no_lsf/i) {
+    $not_enter_lsf = 1;
+  } elsif ($ARGV[0] =~ /-localq/i) {
+    $local_q = 1;
+  } elsif ($ARGV[0] =~ /-localpath/i) {
+    $local_p = 1;
+  } elsif ($ARGV[0] =~ /-disable_autotcm/i) {
+    $disable_autotcm = "TRUE";
+  } elsif ($ARGV[0] =~ /-klocwork/i) {
+    $RUN_KLOCWORK = 1;
+  } elsif ($ARGV[0] =~ /-disk=(.*)/i) {
+    $localq_disk = $1;
+  } elsif ($ARGV[0] =~ /^-mbis=(.*)$/i) {
+    # mbis get argument
+    @mbis_arg = split(",", $1);
+    &mbis_parse_arg;
+  } elsif ($ARGV[0] =~ /-no_cgen/i) {
+    $target_option .= " REMAKE_WITH_CGEN=FALSE ";
+  } elsif ($ARGV[0] =~ /(-parallel|-pll)/i) {
+    if ($^O ne "MSWin32") {
+      $parallel_module_build="TRUE";
+      $target_option .= " PARALLEL=$parallel_module_build";
+    }
+  } elsif ($ARGV[0] =~ /(-no_parallel|-no_pll)/i) {
+    if ($^O ne "MSWin32") {
+      $parallel_module_build="FALSE";
+      $target_option .= " PARALLEL=$parallel_module_build";
+    }
+  } elsif ($ARGV[0] =~ /-dbld/i) {
+    #Add for daily build
+    $daily_build = 1;
+  } elsif ($ARGV[0] =~ /(-no_pcibt|-no_pc)\b/i) {
+    $no_pcibt = "TRUE";
+  } elsif ($ARGV[0] =~ /(-all_pcibt|-all_pc)\b/i) {
+    $all_pcibt = "TRUE";
+  } elsif ($ARGV[0] =~ /(-no_dsp)\b/i) {
+    $no_dsp = "TRUE";
+  } elsif ($ARGV[0] =~ /(-no_w)\b/i) {
+    $no_warning_as_error = "TRUE";
+  } elsif ($ARGV[0] =~ /(-ota_name)=(.*)$/i) {
+    $ota_name = $2;
+  } elsif ($ARGV[0] =~ /-no_ltelib/i) {
+    $no_ltelib = "TRUE";
+    $no_ltecgen = "TRUE";
+  } elsif($ARGV[0] =~ /^-test=(.*)$/i){
+    $VarioationProj_name = $1;
+    $VarioationProj_fullPath = "make/common/variation/${VarioationProj_name}.mak";
+    &cktheMF($VarioationProj_fullPath);
+  } elsif($ARGV[0] =~ /^-rel=(.*)$/i){
+    $chk_rel_pkg = $1;
+  } elsif ($ARGV[0] =~ /-force_getlte/i) {
+    $force_getlte = "TRUE";
+  } elsif ($ARGV[0] =~ /-smart/i) {
+    $smart = 1;
+    #$target_options .= " SMART_CHECK=TRUE ";
+  } elsif ($ARGV[0] =~ /(-checkFO_license)=(.*)$/i) {
+    $check_fo_license = "TRUE";
+    $license_info = $2;
+  } elsif ($ARGV[0] =~ /(-cust_lic)=(.*)$/i) {
+    $cust_lic = $2;
+  } elsif($ARGV[0] =~ /(-ccache_dir|-c_dir)=(.*)$/i){
+    $ccache_dir = $2;
+    mkpath($ccache_dir) or die "[make.pl][Error:] Can Not create $ccache_dir! $!" if(!-d "$ccache_dir");
+    $target_options .= " CCACHE_DIR=$ccache_dir";
+  } elsif($ARGV[0] =~ /(-ccache_size|-c_size)=(.*)$/i){
+    $ccache_size = $2;
+    $target_options .= " CCACHE_SIZE=$ccache_size";
+  } elsif($ARGV[0] =~ /(-ccache_basedir|-c_bd)=(.*)$/i){
+    $ccache_basedir = $2;
+    $target_options .= " CCACHE_BASEDIR=$ccache_basedir";
+  } elsif ($ARGV[0] =~ /^-no_dep$/i) {
+    $target_option .= " NO_DEP=TRUE";
+  } elsif ($ARGV[0] =~ /^-deterministic$/i) {
+    $determinism = "TRUE";
+    $target_option .= " DETERMINISTIC=TRUE";
+  }
+  else {
+    if($ARGV[0] =~ /(.+)\.mak/i) {
+      $project_makefile = $1;
+      if ($^O ne "MSWin32") {
+        if ($project_makefile =~ /^make\/projects\/(\S+)/) {
+          $project_makefile = $1;
+        }
+      }
+      writeMakeINI();
+      shift(@ARGV);
+    }   
+    if (($project_makefile eq "") && ($enINI == 1) && (-e $ini)) {
+      open (FILE_HANDLE, "<$ini") or die "cannot open $ini\n";
+      while (<FILE_HANDLE>) {
+        if (/^(\S+)\s*=\s*(\S+)/) {
+          $keyname = $1;
+          $${keyname} = $2;
+        }
+      }
+      print "project_makefile=$project_makefile\n";
+      close FILE_HANDLE;
+    }
+
+    if($project_makefile =~ /\W/) {
+      ($project_name,$flavor) = split (/\W/, $project_makefile);
+    }
+    else {
+      $project_name = $project_makefile;
+    }
+    print "project_name = $project_name\n";
+    print "flavor = $flavor\n";
+    ($project_makefile eq "") && (die "Unrecognized \"$ARGV[0]\" or \"$ARGV[1]\"\nOr try $myCmd -h\n");
+
+    if ($#ARGV != -1) {
+      if ($ARGV[0] =~ /^[ucrUCR]$/) {
+        ($action = "clean") if ($ARGV[0] =~ /^[cC]$/);
+        ($action = "update") if ($ARGV[0] =~ /^[uU]$/);
+        ($action = "remake") if ($ARGV[0] =~ /^[rR]$/);
+        shift(@ARGV);
+        @arguments = @ARGV;
+        @ARGV = ();
+        last;
+      } else {
+        if ($ENV{'MTK_INTERNAL'} eq 'TRUE') {
+          unshift(@actions, "bm_new", "bm_remake", "bm_update", "find", "ckmake");
+          unshift(@actions, "cmmgen");
+          unshift(@actions, "cfggen","ckmemlayout2");
+        }
+        if ((-d "MoDIS_VC9/MoDIS_lib") || (-d "mtk_rel/${original_project_name}/${original_flavor}/MODIS/MoDIS_lib")) {
+          unshift(@actions, "new_modis", "sys_mem_gen_modis", "new_uesim", "sys_mem_gen_uesim");
+          unshift(@actions, "gen_modis", "gen_uesim") if (-e "MoDIS_VC9/createMoDIS.pl");
+          unshift(@actions, "codegen_modis", "clean_codegen_modis", "umts_gen_modis", "codegen_uesim", "clean_codegen_uesim", "umts_gen_uesim", "distclean_modis", "distclean_uesim");
+          unshift(@actions, "remake_modis", "clean_modis", "update_modis", "remake_uesim", "clean_uesim", "update_uesim");
+          unshift(@actions, "c,r_modis", "c,u_modis", "c,r_uesim", "c,u_uesim");
+          unshift(@actions, "scan_modis");
+          if ($^O eq "MSWin32") {
+            unshift(@actions, "ap_modis", "ap_uesim");
+          }
+        }
+        foreach $act (@actions) {
+          if (lc($ARGV[0]) eq $act) {
+            $action = $act;
+            if (($act eq "bm_update") || ($act eq "bm_remake")) {
+              ($action = "update") if ($act eq "bm_update");
+              ($action = "remake") if ($act eq "bm_remake");
+              if ( $fullOpts !~ /-k/) {
+                ($fullOpts eq "") ? ($fullOpts = "-k") : ($fullOpts .= " -k");
+              }
+            }
+            shift(@ARGV);
+            @arguments = @ARGV;
+            @ARGV = ();
+            last;
+          }
+        }
+      }
+    }
+    ($action eq "") && (die "Unrecognized \"$ARGV[0]\"\nLack off one of (@actions)\nOr try $myCmd -h\n");
+    ($#ARGV != -1)  && (die "Unrecognized \"@ARGV\"\nPlease check again or try $myCmd -h\n");
+    last;
+  }
+  shift(@ARGV);
+}
+(!-d "make")&&(die "Folder \"make\" does NOT exist!\nPlease help to check.\n");
+if(($ENV{'REDIRECT_OUT_DIR'} eq 'TRUE') && (defined $ENV{'OUT_DIR'})) {
+  $hostname = `hostname`;
+  system("perl -e \"print \'COMPUTERNAME=$hostname\';\" > \"${project_makefile}_cf.log\"");
+}
+
+
+$ENV{"PCIBT_NO_STOP"}   = "TRUE" if ($action =~ /^(bm_new|bm_update|bm_remake)$/i);
+$ENV{"CHK_RELPKG_ALL"}  = "TRUE" if ($all_pcibt eq "TRUE");
+$ENV{"DISABLE_AUTOTCM"} = "TRUE" if ($disable_autotcm eq "TRUE");
+$update_dsp             = "TRUE" if ($action =~ /update_dsp/);
+
+my $check_obj_file = "";
+my $obj_path;
+if ($action !~ /_(modis|uesim)$/i) {
+  $obj_path = "./build/${project_name}/$flavor/bin/obj";
+} else {
+  if ($action =~ /_(modis)$/i){
+    $obj_path = "./build/${project_name}/$flavor/MoDIS";
+  } elsif ($action =~ /_(uesim)$/i){
+    $obj_path = "./build/${project_name}/$flavor/UESim";
+  }
+}
+if($^O eq "linux"){
+  $check_obj_file = `find $obj_path -type f -name \"*.obj\"` if (-d "$obj_path");
+}
+
+if ($smart){
+  if ($check_obj_file eq "") {
+    print "Cannot find any object file under \"$obj_path\", start clean_new!\n";
+    $smart = 0;
+  } else {
+    print "Can find object files under \"$obj_path\", start smart_new!\n";
+    $target_options .= " SMART_CHECK=TRUE ";
+  }
+}
+
+if (($action !~ /_(modis|uesim)$/i) && ($action =~ /new|c,r|remake/i) && ($^O eq "MSWin32")) {
+  print "[Error:] Target build on Windows is not avaliable, please use the linux server to build Target!!\n";
+  exit 1;
+}
+
+if (($action =~ /^(new|rel)_(modis|uesim)$/i) || (($action =~ /^(bm_)?new$/i) && ($newMoDIS || $newUESim))) {
+  if ($pureMoDIS == 0) {
+    print "Auto turn on -puremodis when make $action\n";
+    $pureMoDIS = 1;
+  }
+  if ($^O ne "MSWin32") {
+    if($parallel_module_build eq "NONE") {
+      print "Auto turn on build modules in parallel (-pll) on Linux.\n";
+      $parallel_module_build = "TRUE";
+      $target_option .= " PARALLEL=$parallel_module_build";
+    }
+  }
+}
+
+# turn on building modules in parallel
+if (($action eq "new" || $action eq "bm_new") && (-e "make/common/parallel.mak")) {
+  if($parallel_module_build eq "NONE") {
+    print "Auto turn on build modules in parallel (-pll) on Linux.\n";
+    $parallel_module_build = "TRUE";
+    $target_option .= " PARALLEL=$parallel_module_build";
+  }
+}
+
+if ((-e "mtk_tools/Perl") && ($] >= 5.008006)) {
+  use lib "mtk_tools/Perl";
+  use Net::SMTP;
+}
+
+if (($local_q == 1) && ($local_p != 1)) {
+  chomp(my $cwd = cwd());
+  $cwd =~ s/\//\\/g;
+  system("subst $localq_disk $cwd");
+  chdir("$localq_disk");
+  print "cwd = $cwd\n";
+}
+
+chomp($cwd = getcwd());
+if ($cwd =~ /\s+/) {
+  $arrow = $cwd;
+  $arrow =~ s/\s/\^/g;
+  $arrow =~ s/[^\^]/ /g;
+  print "\n$cwd\n";
+  print "$arrow\n";
+  print "Space is not a legal character for a folder name.\nPlease check it !!\n";
+  exit 1;
+}
+
+sub cktheMF {
+  $the_makefile = $_[0];
+  (!-e $the_makefile) && (die "$the_makefile does NOT exist!\nPlease help to check.\n");
+  open (FILE_HANDLE, "<$the_makefile") or die "Cannot open $the_makefile. Please check if the file is READ-ONLY or not exists.\n";
+  while (<FILE_HANDLE>) {
+    if (/^(\w+)\b\s*=\s*(\S+)/) {
+      $keyname = lc($1);
+      $${keyname} = $2;
+    }
+  }
+  close FILE_HANDLE;
+  return 0;
+}
+
+# read the feature option from variation load makefile (ex: flavor)
+if ($VarioationProj_name ne "") {
+  &cktheMF($VarioationProj_fullPath);
+}
+
+my $projectFolder = "build/${project_name}/$flavor";
+
+if ($chk_cmd == 1) {
+  print "\n$projectFolder\n";
+  exit 0;
+}
+
+$original_projectFolder = $projectFolder;
+writeMakeINI();
+$tmpFolder = "$projectFolder/tmp";
+if ($action =~ /_(modis|uesim)$/i) {
+  if ((-d "$projectFolder/MoDIS") && ($action =~ /new_modis/i) && ($m_in_lsf != 1) && (!$smart)) {
+      rmtree("$projectFolder/MoDIS");
+  }
+  if ((-d "$projectFolder/UESim") && ($action =~ /new_uesim/i) && ($m_in_lsf != 1) && (!$smart)) {
+      rmtree("$projectFolder/UESim");
+  }
+  ($projectFolder, $tmpFolder) = &MoDIS_xgen_check($action);
+}
+
+if (($action eq "new" || $action eq "bm_new" ) && (!$smart)) {
+  if (-d "$projectFolder") {
+    opendir(DIR, $projectFolder) or die "Couldn't open directory, $!";
+    while ($file = readdir DIR) {
+      if ($file ne "." && $file ne ".." && $file ne "MoDIS" && $file ne "UESim") {
+        print "Clean folder : $projectFolder/$file \n";
+        rmtree("$projectFolder/$file");
+      }
+    }
+    closedir DIR;
+  }
+
+  my $buildInternalFolder = "build_internal/${project_name}/$flavor"; 
+  if (-d "$buildInternalFolder") {
+    opendir(DIR, $buildInternalFolder) or die "Couldn't open directory, $!";
+    while ($file = readdir DIR) {
+      if ($file ne "." && $file ne ".." && $file ne "MoDIS" && $file ne "UESim") {
+        print "Clean folder : $buildInternalFolder/$file \n";
+        rmtree("$buildInternalFolder/$file");
+      }
+    }
+    closedir DIR;
+  }
+}
+
+my @sm_logs=glob("$projectFolder/bin/log/smart_log* $projectFolder/UESim/_BUILD_XGEN/bin/log/smart_log* $projectFolder/MoDIS/_BUILD_XGEN/bin/log/smart_log*");
+unlink @sm_logs or die "Error: Cannot remove smart log files, please check!\n" if(@sm_logs);
+
+$tk_md_cus      = "";
+$plat           = "NONE";
+$targetFolder   = "$projectFolder/bin";
+$logFolder      = "$targetFolder/log";
+$enFile         = "${makeFolder}${project_name}_en.def";
+$disFile        = "${makeFolder}${project_name}_dis.def";
+$theVerno       = "make/common/Verno.bld";
+$toolsFolder    = "tools/";
+$MTKtoolsFolder = "mtk_tools/";
+$ori_prj_make_full_path = "${projMakeFolder}${project_makefile}.mak";
+$theMF = $ori_prj_make_full_path;
+&cktheMF($theMF);
+if(defined $modem_spec && $modem_spec ne "NONE") {
+  $theMF_modem = "make/common/modem_spec/${modem_spec}.mak";
+  &cktheMF($theMF_modem);
+}
+
+my $tk_md_cus_full_path;
+if (($tk_md_cus ne "") && ($tk_md_cus ne "NONE")) {
+  $tk_md_cus_full_path = "make/projects/tk_md_cus/${tk_md_cus}.mak";
+  if (-e "$tk_md_cus_full_path") {
+    &cktheMF($tk_md_cus_full_path);
+  } else {
+    print ("Error: TK_MD_CUS \"$tk_md_cus_full_path\" file does not exist in codebase, please check!\n");
+    exit 1;
+  }
+}
+
+if ($eutran_mode_support eq "NONE") {
+  $no_ltelib  = "TRUE";
+  $no_ltecgen = "TRUE";
+}
+
+my $action_flag = "TARGET";
+$action_flag = "UESIM" if ($action =~ /_(uesim)$/i);
+$action_flag = "MODIS" if ($action =~ /_(modis)$/i);
+
+if (($force_getlte eq "TRUE") && (-e "mtk_rel/$project_name/$flavor/$action_flag/label.ini.LTE")) {
+  unlink("mtk_rel/$project_name/$flavor/$action_flag/label.ini.LTE") or die "[make.pl][Error:] mtk_rel/$project_name/$flavor/$action_flag/label.ini.LTE $!";
+  print "Remove mtk_rel/$project_name/$flavor/$action_flag/label.ini.LTE successful\n";
+}
+
+if ((-e "label.ini") && (!-d "make/common/rel/mpd/5g") && ($no_ltelib eq "FALSE") && ($no_ltecgen eq "FALSE") && ($flavor!~ /BASIC/i) &&
+    (($action =~ /getusr/i) || ($action =~ /new/i) || ($action =~ /update/i) || ($action =~ /remake/i) || ($action =~ /codegen/i) || ($action =~ /c,u/i) || ($action =~/c,r/i))) {
+  if (-e "mtk_tools/USR/LTEUSR_Initial.pl") {
+    $result = system("perl mtk_tools/USR/LTEUSR_Initial.pl $project_name $flavor $action_flag $smart");
+    exit 1 if ($result);
+  } else {
+    die "[Error:] mtk_tools/USR/LTEUSR_Initial.pl is not exist!!\n";
+  }
+  die "[Error:] mtk_rel/$project_name/$flavor/$action_flag/MoDIS_lib is not exist, $project_name($flavor) can't build modis!!\n" if (($action =~ /_(modis)$/i) && (!-d "mtk_rel/$project_name/$flavor/$action_flag/MoDIS_lib"));
+  die "[Error:] mtk_rel/$project_name/$flavor/$action_flag/UESim_lib is not exist, $project_name($flavor) can't build uesim!!\n" if (($action =~ /_(uesim)$/i) && (!-d "mtk_rel/$project_name/$flavor/$action_flag/UESim_lib"));
+  die "[Error:] mtk_rel/$project_name/$flavor/$action_flag/lib is not exist, $project_name($flavor) can't build target!!\n"      if (($action !~ /_(uesim|modis)$/i) && (!-d "mtk_rel/$project_name/$flavor/$action_flag/lib"));
+}
+
+if ((-e "label.ini") && ($no_dsp eq "FALSE") && ($^O ne "MSWin32") && ($action !~ /_(modis|uesim)$/) &&
+    (($action =~ /getusr/i) || ($action =~ /new/i) || ($action =~ /update/i) || ($action =~ /remake/i) || ($action =~ /codegen/i) || ($action =~ /c,u/i) || ($action =~/c,r/i))){
+  if (-e "mtk_tools/USR/DSPUSR_Initial.pl") {
+    $result = system("perl mtk_tools/USR/DSPUSR_Initial.pl $project_name $flavor $dsp_project $dsp_flavor");
+  exit 1 if ($result);
+  } else {
+    die "[Error:] mtk_tools/USR/DSPUSR_Initial.pl is not exist!!\n";
+  }
+  die "[Error:] mtk_rel/$project_name/$flavor/dsp_rel is not exist, $project_name($flavor) can't build target!!\n" if (($action !~ /_(uesim|modis)$/i) && (!-d "mtk_rel/$project_name/$flavor/dsp_rel"));
+}
+
+# to prevent redundant dsp_package.log
+if ($no_dsp eq "TRUE") {
+  system ("rm -f $projectFolder/bin/log/dsp_package.log") if (-e "$projectFolder/bin/log/dsp_package.log");
+}
+
+if ((-e "label.ini") && (!-e "make/common/rel/hq/USR.txt")&&
+    (($action =~ /getusr/i) || ($action =~ /new/i) || ($action =~ /update/i) || ($action =~ /remake/i) || ($action =~ /codegen/i) || ($action =~ /c,u/i) || ($action =~/c,r/i))){
+  if (-e "mtk_tools/USR/CBrUSR_Initial.pl") {
+    $result = system("perl mtk_tools/USR/CBrUSR_Initial.pl $project_name $flavor $original_flavor $action_flag $smart");
+    exit 1 if ($result);
+  } else {
+    die "[Error:] mtk_tools/USR/CBrUSR_Initial.pl is not exist!!\n";
+  }
+  die "[Error:] mtk_rel/$project_name/$flavor/$action_flag/MoDIS_lib is not exist, $project_name($flavor) can't build modis!!\n" if (($action =~ /_(modis)$/i) && (!-d "mtk_rel/$project_name/$flavor/$action_flag/MoDIS_lib"));
+  die "[Error:] mtk_rel/$project_name/$flavor/$action_flag/UESim_lib is not exist, $project_name($flavor) can't build uesim!!\n" if (($action =~ /_(uesim)$/i) && (!-d "mtk_rel/$project_name/$flavor/$action_flag/UESim_lib"));
+  die "[Error:] mtk_rel/$project_name/$flavor/$action_flag/lib is not exist, $project_name($flavor) can't build target!!\n"      if (($action !~ /_(uesim|modis)$/i) && (!-d "mtk_rel/$project_name/$flavor/$action_flag/lib"));
+}
+
+if ((-e "label.ini") && (-e "make/common/rel/hq/USR.txt")&& (!-d "make/common/rel/mpd")&&
+    (($action =~ /getusr/i) || ($action =~ /new/i) || ($action =~ /update/i) || ($action =~ /remake/i) || ($action =~ /codegen/i) || ($action =~ /c,u/i) || ($action =~/c,r/i))){
+  if (-e "mtk_tools/USR/SwUSR_Initial.pl") {
+    $result = system("perl mtk_tools/USR/SwUSR_Initial.pl $project_name $flavor $action_flag $smart");
+    exit 1 if ($result);
+  } else {
+    die "[Error:] mtk_tools/USR/CBrUSR_Initial.pl is not exist!!\n";
+  }
+  die "[Error:] mtk_rel/$project_name/$flavor/$action_flag/MoDIS_lib is not exist, $project_name($flavor) can't build modis!!\n" if (($action =~ /_(modis)$/i) && (!-d "mtk_rel/$project_name/$flavor/$action_flag/MoDIS_lib"));
+  die "[Error:] mtk_rel/$project_name/$flavor/$action_flag/UESim_lib is not exist, $project_name($flavor) can't build uesim!!\n" if (($action =~ /_(uesim)$/i) && (!-d "mtk_rel/$project_name/$flavor/$action_flag/UESim_lib"));
+  die "[Error:] mtk_rel/$project_name/$flavor/$action_flag/lib is not exist, $project_name($flavor) can't build target!!\n"      if (($action !~ /_(uesim|modis)$/i) && (!-d "mtk_rel/$project_name/$flavor/$action_flag/lib"));
+}
+
+my @delTempFile = glob("$tmpFolder/*.*");
+#unlink(@delTempFile) or die "[make.pl][Error:] Remove failed @delTempFile $!" if(@delTempFile); #mark for smart new
+unlink("$tmpFolder/~buildinfo.tmp") or die "[make.pl][Error:] Remove failed $tmpFolder/~buildinfo.tmp $!" if(-e "$tmpFolder/~buildinfo.tmp");
+unlink("$tmpFolder/~remakemod.tmp") or die "[make.pl][Error:] Remove failed $tmpFolder/~remakemod.tmp $!" if(-e "$tmpFolder/~remakemod.tmp");
+unlink("$tmpFolder/~cleanmod.tmp")  or die "[make.pl][Error:] Remove failed $tmpFolder/~cleanmod.tmp $!"  if(-e "$tmpFolder/~cleanmod.tmp");
+unlink("$tmpFolder/~updatemod.tmp") or die "[make.pl][Error:] Remove failed $tmpFolder/~updatemod.tmp $!" if(-e "$tmpFolder/~updatemod.tmp");
+unlink("$tmpFolder/~scanmod.tmp")   or die "[make.pl][Error:] Remove failed $tmpFolder/~scanmod.tmp $!"   if(-e "$tmpFolder/~scanmod.tmp");
+mkpath($tmpFolder) or die "[make.pl][Error:] Can Not create $tmpFolder! $!" if(!-d "$tmpFolder");
+mkpath($logFolder) or die "[make.pl][Error:] Can Not create $logFolder! $!" if(!-d "$logFolder");
+mkpath($targetFolder) or die "[make.pl][Error:] Can Not create $targetFolder! $!" if(!-d "$targetFolder");
+
+if(-e "make/common/rel/hq/USR.txt")
+{
+  my $rel_err_msg = ""; 
+  my $output_file = "$targetFolder/all_mod_rel.mak";
+  unlink $output_file or die "[make.pl][Error:] Remove failed $output_file" if(-e $output_file);
+  $rel_err_msg .= `perl ./mtk_tools/USR/genModuleRel.pl REL_CR $output_file`;
+  $rel_err_msg .= `perl ./mtk_tools/USR/genModuleRel.pl REL_SUB $output_file`;
+  
+  #Check if module's MPD/Custom rel definition is duplicate
+  if (($rel_err_msg ne "") && ($no_pcibt ne "TRUE"))
+  {
+    print "$rel_err_msg";
+    print "Please refer http://wiki/display/MOLY/How+to+add+a+new+module for rel setting.\n";
+    exit 1;
+  }
+}
+# generate custom.bld
+&genCustombld();
+
+# smybol link to central tool chain if it's in MTK_INTERNAL
+my $central_compiler_path = "/mtkoss/imgtec/gcc-mips-mti-elf.2016.05-08/4.9.2/linux";
+my $compiler_path = "./tools/GCC/MIPS/4.9.2";
+
+if ($compiler_ver eq "MIPS_GCCV6"){
+  $central_compiler_path = "/mtkoss/imgtec/gcc-mips-mti-elf.2017.10-08/6.3.0/linux";
+  $compiler_path = "./tools/GCC/MIPS/6.3.0";
+  if ($compiler_isa eq "NANOMIPS"){
+    $central_compiler_path = "/mtkoss/imgtec/gcc-nanomips-elf.2019.03-06/6.3.0/linux";
+    $compiler_path = "./tools/GCC/NANOMIPS/6.3.0";
+  }
+} elsif ($compiler_ver eq "MIPS_GCCV4"){
+  $central_compiler_path = "/mtkoss/imgtec/gcc-mips-mti-elf.2016.05-08/4.9.2/linux";
+  $compiler_path = "./tools/GCC/MIPS/4.9.2";
+}
+
+if(-l "$compiler_path/linux") {
+  $exist_symlink_path = readlink("$compiler_path/linux");
+  if($exist_symlink_path ne "$central_compiler_path") {
+    system("rm -f $compiler_path/linux");
+  }
+}
+
+if(!-l "$compiler_path/linux" && !-d "$compiler_path/linux" && -d "$central_compiler_path") {
+  mkpath("$compiler_path") if(!-d "$compiler_path");
+  system("ln -s $central_compiler_path $compiler_path");
+}
+
+if ($action =~ /_(modis|uesim)$/ && !-d "$projectFolder/vs2017_header" && $^O eq "linux") {
+  print "Create vs2017 symbolic link ...\n";
+  system("./mtk_tools/vs2017/gen_symbolic.sh $projectFolder/vs2017_header  2>/dev/null");
+}
+
+# concatenate the project makefiles and the result is placed on build/$project/$flavorn/bin.
+# In here, the gen_concatenate_proj target does NOT do PCIBT.
+$concatenate_proj_mak = "${targetFolder}/~${project_makefile}.mak";
+my $gen_concate_option = "";
+my $modis_config = "FALSE";
+$gen_concate_option = $target_option;
+if ($action =~ /_(modis|uesim)$/i) {
+  $gen_concate_option .= " MODIS_CONFIG=TRUE";
+  $modis_config = "TRUE";
+}
+$gen_concate_option .= " NO_PCIBT=TRUE";
+
+#backup log files for smart build
+if (($smart) && ($^O ne "MSWin32")) {
+  my $backup_logFolder = "${logFolder}_bak";
+  my $move_log_file = "$backup_logFolder/log_move.log";
+  mkdir("$backup_logFolder") if (!-d "$backup_logFolder");
+  system("rm -f $move_log_file") if (-e "$move_log_file");
+  opendir(DIR, $logFolder) or die "Couldn't open directory, $!";
+  while ($file = readdir DIR) {
+    if ($file ne "." && $file ne ".." ) {
+      system("echo Move log files from $logFolder to $backup_logFolder: $file >> $move_log_file");
+      #print "Move log files from $logFolder to $backup_logFolder: $file\n";
+      if (-d "$logFolder/$file") {
+        system ("cp -pr $logFolder/$file $backup_logFolder");
+        system ("rm -rf $logFolder/$file");
+      } else {
+        if ($file =~ /info(.*)\.log/) {
+          system ("cp -p $logFolder/$file $backup_logFolder");
+        } else {
+          system ("mv $logFolder/$file $backup_logFolder");
+        }
+      }
+    }
+  }
+  closedir DIR;
+}
+
+my $return_code = system("${makeCmd} -f${makeFolder}${myMF} -r -R CORE_ROOT=$core_root PROJECT_NAME=$project_name \"PROJECT_MAKEFILE=$theMF\" FLAVOR=$flavor $target_options \"VARIATION_PROJ=$VarioationProj_name\" $gen_concate_option gen_concatenate_proj");
+die "Error: concatenate project makefiles failed." if(($return_code >> 8) ne 0);
+(!-e $concatenate_proj_mak) && (die "$concatenate_proj_mak does NOT exist!\nPlease help to check.\n");
+print "concatenate_proj_mak = $concatenate_proj_mak\n";
+$theMF = $concatenate_proj_mak;
+&cktheMF($theMF);
+exit 0 if($action eq "getusr");
+
+#add oriaction to store original action
+my $oriaction = $action;
+
+# for initial mbis config 
+&mbis_init;
+&mbis_start_probe;
+# mbis options
+system("echo MBIS_EN=$mbis_en >> $tmpFolder/~buildinfo.tmp");
+system("echo MBIS_EN_OBJ_LOG=$mbis_en_obj_log >> $tmpFolder/~buildinfo.tmp");
+system("echo NO_LTELIB=$no_ltelib >> $tmpFolder/~buildinfo.tmp");
+system("echo NO_LTECGEN=$no_ltecgen >> $tmpFolder/~buildinfo.tmp");
+system("echo NO_PCIBT=$no_pcibt >> $tmpFolder/~buildinfo.tmp");
+system("echo MCF_OTA_NAME=$ota_name >> $tmpFolder/~buildinfo.tmp");
+system("echo MODIS_CONFIG=$modis_config >> $tmpFolder/~buildinfo.tmp");
+system("echo NO_DSP=$no_dsp >> $tmpFolder/~buildinfo.tmp");
+system("echo NO_WARNING_AS_ERROR=$no_warning_as_error >> $tmpFolder/~buildinfo.tmp");
+system("echo CHECK_FO_LICENSE=$check_fo_license >> $tmpFolder/~buildinfo.tmp");
+system("echo LICENSE_INFO=$license_info >> $tmpFolder/~buildinfo.tmp");
+system("echo CUST_LIC=$cust_lic >> $tmpFolder/~buildinfo.tmp");
+system("echo VARIATION_PROJ=$VarioationProj_name >> $tmpFolder/~buildinfo.tmp");
+system("echo ORIACTION=$action >> $tmpFolder/~buildinfo.tmp");
+system("echo SRC_MAX_PACKAGE=$chk_rel_pkg >> $tmpFolder/~buildinfo.tmp");
+
+if (($action ne "ckmake") && ($action ne "drv_feature_check")) {
+  if ($m_in_lsf != 1) {
+    # Before executing actions, dump environment information to the build.log
+    system("echo USERNAME=$ENV{'USERNAME'} > $targetFolder/build.log");
+    system("perl -e \"print \'START TIME=\';\" >> $targetFolder/build.log");
+    system("perl tools/time.pl -n >> $targetFolder/build.log");
+  }
+}
+
+# Get network path
+open (FILE_HANDLE, ">$tmpFolder/~net_path.tmp") or die "Cannot open $tmpFolder/~net_path.tmp";
+if ($ENV{'MTK_INTERNAL'} eq 'TRUE') {
+  $net_path = &get_net_path;
+  print FILE_HANDLE "NET_PATH = $net_path\n";
+}
+close FILE_HANDLE;
+
+if(-e $theVerno) {
+  open (FILE_HANDLE, "<$theVerno") or die "cannot open $theVerno\n";
+  while (<FILE_HANDLE>) {
+    if ((/^([^\#]*)\#?.*/) && ($1 =~ /^(\w+)\s*=\s*(.*\S)\s*$/)) {
+      $keyname = lc($1);
+      $${keyname} = uc($2);
+    }
+  }
+  close FILE_HANDLE;
+}
+
+die "Please define VERNO in project makefile or $theVerno." if($verno eq "");
+if ($verno =~ /\s+/) {
+  $arrow = $verno;
+  $arrow =~ s/\s/\^/g;
+  $arrow =~ s/[^\^]/ /g;
+  print "\n$verno\n";
+  print "$arrow\n";
+  print "Space is not a legal character for VERNO name.\nPlease check it !!\n\n";
+  exit 1;
+}
+
+# Get custom_release value
+  open (FILE_HANDLE, "<make/common/Custom.bld") or die "Cannot open make/common/Custom.bld\n";
+  while (<FILE_HANDLE>) {
+    if (/^(\S+)\s*=\s*(\S+)/) {
+      $keyname = lc($1);
+      if(defined($${keyname}) && $${keyname} ne ""){
+        next;
+      }
+      #defined($${keyname}) && warn "$1 redefined in $thefile!\n";
+      $${keyname} = uc($2);
+    }
+  }
+  close FILE_HANDLE;
+
+# To check if FLAVOR length is less than 36 bytes
+die "ERROR: FLAVOR name should be less than 36 characters.\n" if(length($flavor)>36);
+die "ERROR: ORIGINAL_PROJECT_NAME name should be less than 128 characters.\n" if(length($original_project_name)>128);
+die "ERROR: ORIGINAL_FLAVOR name should be less than 36 characters.\n" if(length($original_flavor)>36);
+die "ERROR: ORIGINAL_VERNO name should be less than 64 characters.\n" if(defined $original_verno && length($original_verno)>64);
+
+if ($^O ne "MSWin32") {
+  @tools_Dirs = qw(tools/);
+} else {
+  @tools_Dirs = qw(tools/ tools/MinGW tools/MSYS);
+}
+
+push (@tools_file,$makeCmd);
+
+foreach $tools_Dirs (@tools_Dirs) {
+  if (!-d $tools_Dirs) {
+    warn "$tools_Dirs folder does NOT exist!\n";
+    &cp_3rdpartyTool;
+  }
+}
+
+foreach $tools_file (@tools_file) {
+  if (!-e $tools_file) {
+    warn "$tools_file does NOT exist!\n";
+    &cp_3rdpartyTool;
+  }
+}
+
+my $strBypassMoDIS = 0;
+my $notify_list;
+if ($^O eq "MSWin32") {
+  if ($ENV{'LTE_DOMAIN'} eq "TRUE") {
+    $notify_list = "\\\\mtklwafs01\\moly\\wcpsm\\config\\bm_conf.ini";
+  } else {
+    $notify_list = "\\\\glbfs14\\sw_releases\\3rd_party\\Scripts\\BM_conf.ini";
+  }
+}
+$notify_list = "/mtkeda/wcpsm/bm/config/bm_conf.ini" if($^O eq "linux");
+if (($ENV{'MTK_INTERNAL'} eq 'TRUE') && (-e "$notify_list")) {
+  %BM_conf = iniToHash($notify_list);
+  if ($bypassMoDIS > -1) {
+    $strBypassMoDIS = $BM_conf{'MODIS_RULE'}->{'MODIS_BYPASS'};
+  }
+}
+
+if ($ENV{"NUMBER_OF_PROCESSORS"} > 1) {
+  $PROCESS_NUM = $ENV{"NUMBER_OF_PROCESSORS"};
+  if($fullOpts !~ /-j/) {
+    ($fullOpts eq "") ? ($fullOpts = "-j$PROCESS_NUM") : ($fullOpts .= " -j$PROCESS_NUM");
+  }
+  if ($mbis_en eq "TRUE") {
+    $mbis_num_proc = $PROCESS_NUM;
+  }
+}
+
+if ($m_in_lsf == 1) {
+  die "NOT IN LSF SERVER!\n" if ($ENV{"LS_ADMINNAME"} eq "");
+  $computerName = $ENV{"COMPUTERNAME"};
+  if ($local_q != 1) {
+    system("echo set LAST_SUBMITTED_CF=$computerName >  build/last_cf.log");
+    $ENV{"TMP"} = "e:\\temp";
+    $ENV{"TEMP"} = "e:\\temp";
+    mkdir("e:/temp") if (!-d "e:/temp");
+  }
+  $ENV{"INLSF"} = $computerName;
+}
+
+if ($bypassMoDIS > -1) {
+  $bypassMoDIS = int(eval($strBypassMoDIS));
+}
+
+if ($ENV{COMPUTERNAME} =~ /mtks(cf|ib)/i) {
+  $m_in_lsf = 1;
+}
+
+if (($m_in_lsf == 0) && ($not_enter_lsf != 1)) {
+  if ($action =~ /^(bm_new|bm_update|bm_remake)$/i) {
+    system("${makeCmd} -f${makeFolder}${myMF} -r -R CORE_ROOT=$core_root PROJECT_NAME=$project_name \"PROJECT_MAKEFILE=$theMF\" FLAVOR=$flavor $target_options drv_feature_check") && exit 1;
+  }
+  if (($action =~ /new/i) && ($action !~ /new_viti/i) && ($ENV{"SESSIONNAME"} ne "") &&
+    ($ENV{"LSF_BINDIR"} ne "") && ($project !~ /BASIC/i) && ($project !~ /L1S/i) && ($project !~ /UDVT/i) && ($ENV{'MTK_INTERNAL'} eq 'TRUE')) {
+
+    chomp($cwd = cwd());
+    if ($cwd =~ /^[abg-z]/i) {
+      &pre_gen() if (($pureMoDIS == 1) || ((lc($action) ne "new_modis") && (lc($action) ne "new_uesim")));
+      $env_last_S_CF = "";
+      $lastSC = "build/last_cf.log";
+      if ((-e $lastSC) && (open(LOGF, "${lastSC}"))) {
+        while (<LOGF>) {
+          if (/set LAST_SUBMITTED_CF=(\S+)/) {
+            $env_last_S_CF = $1;
+            last;
+          }
+        }
+        close(LOGF);
+      }
+      if ($mbis_en eq "TRUE") {
+        $mbis_time = time;
+        system("echo T_S,DISPATCH_CF,P,$mbis_time >>$ENV{MBIS_BUILD_TIME_TMP}");
+      }
+      my $result = 0;
+      if ($env_last_S_CF eq "") {
+         $result = system("bsub -I \"perl $net_path\\m_cp2lsf.pl\" \"$net_path\" @orgARGV");
+      } else {
+        if (($output = `bhosts ${env_last_S_CF} mtkcf 2>&1`) =~ / Bad host name, host group name or cluster name/) {
+          $result = system("bsub -I \"perl $net_path\\m_cp2lsf.pl\" \"$net_path\" @orgARGV");
+        } else {
+          $result = system("bsub -I -m \"${env_last_S_CF}+2 mtkcf+1\" \"perl $net_path\\m_cp2lsf.pl\" \"$net_path\" @orgARGV");
+        }
+      }
+      &writeINI;
+      exit $result >> 8;
+    } else {
+      # make new in local E: driver
+      if (($ENV{"SESSIONNAME"} ne "") && ($ENV{"LSF_BINDIR"} ne "") && ($compiler eq "RVCT") && ($ENV{'MTK_INTERNAL'} eq 'TRUE')) {
+        &localq;
+      }
+    }
+  }
+}
+
+
+if ($action eq "c,r") {
+  @theAct = qw(clean remake);
+} elsif ($action eq "c,u") {
+  @theAct = qw(clean update);
+} elsif ($action eq "c,r_modis") {
+  @theAct = ("clean_modis remake_modis");
+} elsif ($action eq "c,u_modis") {
+  @theAct = ("clean_modis update_modis");
+} elsif ($action eq "c,r_uesim") {
+  @theAct = ("clean_uesim remake_uesim");
+} elsif ($action eq "c,u_uesim") {
+  @theAct = ("clean_uesim update_uesim");
+} else {
+  @theAct = ($action);
+}
+
+if ($newMoDIS == 1) {
+# make sure set $mbis_target_build_with_Modis should be after localq
+  $mbis_target_build_with_Modis = 1;
+  if ($action =~ /^c,r(_modis|_uesim)?$/) {
+    push(@theAct, "clean_modis remake_modis");
+  } elsif ($action =~ /^c,u(_modis|_uesim)?$/) {
+    push(@theAct, "clean_modis update_modis");
+  } else {
+    my $action2 = $action;
+    $action2 =~ s/_(modis|uesim)$//ig;
+    push(@theAct, $action2 . "_modis");
+  }
+}
+if ($newUESim == 1) {
+  $mbis_target_build_with_Modis = 1;
+  if ($action =~ /^c,r(_modis|_uesim)?$/) {
+    push(@theAct, "clean_uesim remake_uesim");
+  } elsif ($action =~ /^c,u(_modis|_uesim)?$/) {
+    push(@theAct, "clean_uesim update_uesim");
+  } else {
+    my $action2 = $action;
+    $action2 =~ s/_(modis|uesim)$//ig;
+    push(@theAct, $action2 . "_uesim");
+  }
+}
+
+if (($action ne "ckmake") && ($action ne "drv_feature_check")) {
+  # Before executing actions, dump environment information to the build.log
+  if(-e "./SubReleaseConfig.ini") {
+    print "copy ./SubReleaseConfig.ini $targetFolder";
+    copy("./SubReleaseConfig.ini", $targetFolder);
+  }
+  system("perl -e \"print \'BUILD START TIME=\';\" >> $targetFolder/build.log");
+  system("perl tools/time.pl -n >> $targetFolder/build.log");
+  system("echo NUMBER_OF_PROCESSORS=$ENV{\"NUMBER_OF_PROCESSORS\"} >>$targetFolder/build.log");
+  &mbis_info_probe;
+}
+
+# check current working folder length
+# if it is too long, it will cause build error. The max length is defined 90 characters.
+chomp($cwd = cwd());
+$len = length($cwd);
+$folder_limit = 90;
+if($^O eq "MSWin32" && $len > $folder_limit) {
+  if ($cwd =~ /.+\\(.+)/) {
+    $folder_name = $1;
+  }
+  print "Folder: $cwd\n";
+  print "Warning: The folder length from $folder_name($len characters) exceeds $folder_limit characters. Please reduce folder lengths!\n";
+  system("echo Warning: The folder path from $folder_name($len characters) exceeds $folder_limit characters. > $tmpFolder/~path_length.tmp");
+}
+
+my $result = 0;
+my %saw;
+@theAct = grep (!$saw{$_}++, @theAct);
+foreach my $action (@theAct) {
+  $ENV{"ACTION"} = $action;
+  if ($action =~ /_(modis|uesim)$/i) {
+    ($projectFolder, $tmpFolder) = &MoDIS_xgen_check($action);
+  }
+  &gen_buildinfo_tmp;
+
+  if ($action =~ /\b(clean)_(modis|uesim)\b/) {
+    if ($#arguments != -1) {
+      system("echo DO_CLEAN_MODULE=TRUE > $tmpFolder/~cleanmod.tmp");
+      system("echo CLEAN_MODS=@arguments >> $tmpFolder/~cleanmod.tmp");
+    }
+  }
+  if ($action eq "clean") {
+    if ($#arguments != -1) {
+      system("echo DO_CLEAN_MODULE=TRUE > $tmpFolder/~cleanmod.tmp");
+      system("echo CLEAN_MODS=@arguments >> $tmpFolder/~cleanmod.tmp");
+      system("${makeCmd} -f${makeFolder}${myMF} -r -R CORE_ROOT=$core_root PROJECT_NAME=$project_name \"PROJECT_MAKEFILE=$theMF\" FLAVOR=$flavor $target_options cleanmod");
+    } else {
+      system("echo DO_CLEAN_MODULE=FALSE > $tmpFolder/~cleanmod.tmp");
+      system("${makeCmd} -f${makeFolder}${myMF} -r -R CORE_ROOT=$core_root PROJECT_NAME=$project_name \"PROJECT_MAKEFILE=$theMF\" FLAVOR=$flavor $target_options cleanall");
+    }
+  } elsif (($action eq "remake") || ($action =~ /\b(remake)_(modis|uesim)\b/)) {
+    if ($#arguments != -1) {
+      system("echo DO_REMAKE_MODULE=TRUE > $tmpFolder/~remakemod.tmp");
+      system("echo REMAKE_MODS=@arguments >> $tmpFolder/~remakemod.tmp");
+      system("echo L_REMAKE_MODS=@l1core_arguments >> $tmpFolder/~remakemod.tmp");
+    }
+  } elsif (($action eq "update") || ($action =~ /\b(gen|update)_(modis|uesim)\b/)) {
+    if ($#arguments != -1) {
+      system("echo DO_UPDATE_MODULE=TRUE > $tmpFolder/~updatemod.tmp");
+      system("echo UPDATE_MODS=@arguments >> $tmpFolder/~updatemod.tmp");
+    }
+  } elsif (($action eq "scan") || ($action =~ /\b(scan)_(modis|uesim)\b/)) {
+    if ($#arguments != -1) {
+      system("echo DO_SCAN_MODULE=TRUE > $tmpFolder/~scanmod.tmp");
+      system("echo SCAN_MODS=@arguments >> $tmpFolder/~scanmod.tmp");
+    }
+  } elsif (($action eq "new") || ($action eq "bm_new") || ($action eq "codegen") || ($action =~ /_(modis|uesim)\b/)) {
+    # empty here to run through BT switch
+  } elsif ($action eq "check_scan") {
+    if ($#arguments != -1) {
+      system("echo DO_SCAN_MODULE=TRUE > $tmpFolder/~scanmod.tmp");
+      system("echo SCAN_MODS=@arguments >> $tmpFolder/~scanmod.tmp");
+    }
+    system("${makeCmd} -f${makeFolder}${myMF} -r -R CORE_ROOT=$core_root PROJECT_NAME=$project_name \"PROJECT_MAKEFILE=$theMF\" FLAVOR=$flavor $target_options CHECK_SCAN=TRUE scan");
+  } elsif ($action eq "check") {
+    system("perl ${toolsFolder}parse_comp_err.pl $projectFolder FALSE $tmpFolder TRUE");
+  } elsif ($action eq "check_dep") {
+      &Usage if (!@arguments);
+      &writeINI;
+      system("perl tools/GetDepMod.pl ./ \"$theMF\" $project_name $flavor @arguments") && exit 1;
+      exit 0;
+  } elsif ($action =~ /update_dep|remake_dep/i) {
+      &Usage if (!@arguments);
+      print "Scanning dependency modules...\n";
+      my $output;
+      if (($output = `perl tools/GetDepMod.pl ./ \"$theMF\" $project_name $flavor @arguments 2>&1`) =~ /=+DEPENDENCY MODULE\(S\)=+\n(.*)\n/) {
+        @arguments = split(/\s+/,$1);
+        $action = "update" if ($action eq "update_dep");
+        $action = "remake" if ($action eq "remake_dep");
+        print "The following module(s) will be rebuilt!\n";
+        print "===========================================================\n";
+        print "@arguments","\n";
+        print "===========================================================\n";
+        redo; # redo to generate ${makeFolder}~remakemod.tmp
+      } else {
+        print $output;
+        &writeINI;
+        exit 1;
+      }
+  } elsif ($action eq "memquery") {
+    #invoke memquery according to SINGLE_CORE_ONLY feature option defined in project makefile respectively
+    if ($#arguments != -1) {
+      system("echo \"@arguments\" > $tmpFolder/~memquery.tmp");
+    }
+      system("${makeCmd} -f ${makeFolder}${myMF} -r -R CORE_ROOT=$core_root PROJECT_NAME=$project_name \"PROJECT_MAKEFILE=$theMF\" FLAVOR=$flavor $target_options memquery");
+  } else {
+    if ($action !~ /^ckmake$/i) {
+      $result = system("${makeCmd} -f${makeFolder}${myMF} -r -R CORE_ROOT=$core_root PROJECT_NAME=$project_name \"PROJECT_MAKEFILE=$theMF\" FLAVOR=$flavor $target_options $target_option ckmake");
+      die "Error: ckmake failed!!!\n" if($result != 0);
+    }
+    $result = system("${makeCmd} -f${makeFolder}${myMF} -r -R CORE_ROOT=$core_root PROJECT_NAME=$project_name \"PROJECT_MAKEFILE=$theMF\" FLAVOR=$flavor $target_options $target_option $action");
+    if($result != 0) {
+      &error_handle;
+    } else{
+      &mbis_success if ($mbis_en eq "TRUE");
+      if (($custom_release eq "FALSE") && ($ENV{'MTK_INTERNAL'} eq 'TRUE')&& (-e "mtk_tools\\Internal_function.pm")) {
+        die "AAPMC parser Error!!!\n" if ($result != 0)
+      }
+    }
+    next;
+  }
+
+  if (($action eq "remake") || ($action eq "update") || ($action eq "new") || ($action eq "bm_new") || ($action eq "scan") || ($action eq "codegen") || ($action =~ /^new_(modis|uesim)$/i)) {
+    $result = system("${makeCmd} -f${makeFolder}${myMF} -r -R CORE_ROOT=$core_root PROJECT_NAME=$project_name \"PROJECT_MAKEFILE=$theMF\" FLAVOR=$flavor $target_options $target_option ckmake");
+    die "Error: ckmake failed!!!\n" if($result != 0);
+  }
+  if (($action eq "remake") || ($action eq "update") || ($action eq "new") || ($action eq "bm_new") || ($action eq "scan")) {
+    if ($action eq "bm_new") {
+      system("echo BM_NEW=TRUE >> $tmpFolder/~buildinfo.tmp");
+      #Add for daily build
+      if ($daily_build){
+        system("echo DAILY_BUILD=TRUE >> $tmpFolder/~buildinfo.tmp");
+      }
+      $result = system("${makeCmd} -f${makeFolder}${myMF} -k -r -R CORE_ROOT=$core_root PROJECT_NAME=$project_name \"PROJECT_MAKEFILE=$theMF\" FLAVOR=$flavor $target_options $target_option new");
+    } else {
+      $result = system("${makeCmd} -f${makeFolder}${myMF} -r -R CORE_ROOT=$core_root PROJECT_NAME=$project_name \"PROJECT_MAKEFILE=$theMF\" FLAVOR=$flavor $target_options $target_option $action");
+    }
+    if ($result == 0) {
+      if (($custom_release eq "FALSE") && ($ENV{'MTK_INTERNAL'} eq 'TRUE')&& (-e "mtk_tools\\Internal_function.pm")) {
+        $result = &AAPMC::Parse_AAPMCLog($AAPMCLOG,$project_name,$flavor,"$theMF");
+        die "AAPMC parser Error!!!\n" if ($result != 0)
+      }
+      &mbis_success if ($mbis_en eq "TRUE");
+    } else {
+      system("perl $mbis -i SUCCESSFUL_BUILD,0") if ($mbis_en eq "TRUE");
+      &error_handle;
+    }
+    last if ($mbis_target_build_with_Modis != 1);
+  } elsif ($action =~ /_(modis|uesim)\b/) {
+    $result = &MoDIS_build_process($action);
+  } elsif ($action eq "codegen") {
+    $result = system("${makeCmd} -f${makeFolder}${myMF} -r -R CORE_ROOT=$core_root PROJECT_NAME=$project_name \"PROJECT_MAKEFILE=$theMF\" FLAVOR=$flavor $target_options code_generate");
+    #mbis end probe
+    if ($result == 0) {
+      &mbis_success if ($mbis_en eq "TRUE");
+    }
+  }
+  if ($result != 0) {
+    system("perl $mbis -i SUCCESSFUL_BUILD,0") if ($mbis_en eq "TRUE");
+    print "Failed in $action\n";
+    last;
+  }
+}
+# [Linux] temporarily add
+unlink("nul") if($^O eq "linux" && -e "nul");
+unlink("NUL") if($^O eq "linux" && -e "NUL");
+&writeINI;
+if (($m_in_lsf != 1) && ($mbis_target_build_with_Modis == 1)) {
+  &mbis_end_probe;
+}
+#die "make.pl\n" if ($result != 0);
+exit $result >> 8;
+
+sub MoDIS_build_process {
+  my $modis_action = shift @_;
+  my $modis_result = 0;
+  if ($bypassMoDIS < 1) {
+    system("perl $mbis -t T_S,M_TOTAL,M_P") if ($mbis_en eq "TRUE");
+    my $modis_option = $target_option . " MODIS_CONFIG=TRUE PARTIAL_SOURCE=FALSE";
+    if (($modisDir ne "") && ($modisDir ne "undef")) {
+      $modis_option .= " MODIS_MODE=$modisDir";
+    } else {
+      $modisDir = "undef";
+    }
+    $modis_action =~ s/\b(bm)_//ig;
+    if ($modis_action =~ /_uesim\b/) {
+      $modis_action =~ s/_uesim\b/_modis/g;
+      $modis_option .= " UE_SIMULATOR=TRUE";
+    }
+    my $modis_cwd = cwd();
+    $modis_cwd =~ s/\//\\/g if ($^O eq "MSWin32");
+    my $modis_subst = "";
+    if (($^O eq "MSWin32") && ($modis_action !~ /^(gen|clean|scan|ap|at|rel)_(modis|uesim)$/i)) {
+      foreach my $disk (k..z) {
+        if (system("subst $disk: $modis_cwd\\.. >NUL 2>&1") == 0) {
+          $modis_subst = $disk;
+          last;
+        }
+      }
+      if ($modis_subst ne "") {
+        print "MoDIS subst disk for $modis_cwd is $modis_subst:\n";
+        chdir("$modis_subst:\\mcu\\");
+      } else {
+        warn "Warning: Execute subst for MoDIS fail !\n";
+      }
+    }
+    $modis_action = "new $modis_action" if ($pureMoDIS == 1);
+    $modis_action = "bullseye_config new $modis_action" if (($modis_option =~/BULLSEYE_CONFIG=TRUE/) && ($pureMoDIS == 1));
+    $modis_result = system("${makeCmd} -f${makeFolder}${myMF} -r -R CORE_ROOT=$core_root PROJECT_NAME=$project_name \"PROJECT_MAKEFILE=$theMF\" FLAVOR=$flavor $target_options $modis_option $modis_action");
+    chdir($modis_cwd);
+    system("subst $modis_subst: /D >NUL") if ($modis_subst ne "");
+    if ($modis_result == 0) {
+      if ($modis_action =~ /\b(new|remake|update)_(modis|uesim)\b/) {
+        system("perl $mbis -i SUCCESSFUL_BUILD,1") if ($mbis_en eq "TRUE");
+        #rel_atMoDIS
+      }
+      if (($modis_action eq "at_modis") || ($atMoDIS == 1)) {
+        chdir("$modis_cwd\\MoDIS_VC9");
+        $modis_result = system("perl modisAutoTest.pl at_modis $modisDir ..\\$theMF ..\\$theVerno");
+        chdir("$modis_cwd");
+      }
+    }
+    system("perl $mbis -t T_E,M_TOTAL,M_P") if ($mbis_en eq "TRUE");
+  } else {
+    print "Skip $modis_action for MoDIS\n";
+    $modis_result = 9 << 8;
+  }
+  return $modis_result;
+}
+
+sub MoDIS_xgen_check {
+  my $modis_action = shift @_;
+  my $result_projectFolder = "build/${project_name}/$flavor";
+  my $result_tmpFolder = "$result_projectFolder/tmp";
+  if ($modis_action =~ /_(modis|uesim)$/i) {
+    my $flag_packMoDIS = $packMoDIS;
+    my $path_packMoDIS;
+    $path_packMoDIS = "MoDIS" if ($modis_action =~ /_(modis)$/i);
+    $path_packMoDIS = "UESim" if ($modis_action =~ /_(uesim)$/i);
+    $path_packMoDIS .= "/_BUILD_XGEN";
+    if ($modis_action =~ /_(modis|uesim)$/i) {
+      if (($pureMoDIS != -1) && ($packMoDIS != -1)) {
+        $flag_packMoDIS = 1;
+      }
+    }
+    elsif ($pureMoDIS == 1) {
+      die "Error: -puremodis cannot be used with make $modis_action\n";
+    }
+    if ($flag_packMoDIS == 0) {
+      if (-d "$result_projectFolder/$path_packMoDIS") {
+        print "Auto turn on -packmodis when $result_projectFolder/$path_packMoDIS is found\n";
+        $flag_packMoDIS = 1;
+      }
+    }
+    if ($flag_packMoDIS == 1) {
+      $result_projectFolder .= "/" . $path_packMoDIS;
+      $target_option =~ s/\bPROJDIR=\S+//g;
+      $target_option .= " PROJDIR=./$result_projectFolder";
+      $result_tmpFolder = "$result_projectFolder/tmp";
+      if ($result_projectFolder ne $projectFolder) {
+        mkpath($result_projectFolder) if (! -d $result_projectFolder);
+        foreach my $file (glob "$projectFolder/*") {
+          next if (-d $file);
+          copy($file, $result_projectFolder);
+        }
+      }
+      if ($result_tmpFolder ne $tmpFolder) {
+        mkpath($result_tmpFolder) if (! -d $result_tmpFolder);
+        foreach my $file (glob "$tmpFolder/*") {
+          next if (-d $file);
+          copy($file, $result_tmpFolder);
+        }
+      }
+    }
+  }
+  return ($result_projectFolder, $result_tmpFolder);
+}
+
+#usage:
+#      my %hash=iniToHash('/tmp/myini.ini');
+#      print $hash{'TITLE'}->{'Name'},"\n";
+#
+sub iniToHash {
+  open(MYINI, $_[0]);
+  my %hash;
+  my $hashref;
+
+  while(<MYINI>) {
+    next if ((/^\s*$/) || (/^\s*#/));
+    if (/^\s*\[(.+)\]/) {
+      $hashref = $hash{$1} ||= {};
+    } elsif (/^\s*(\S+)\s*=\s*(.+)\s*$/) {
+      $hashref->{$1} = $2;
+    } elsif (/^\s*(\S+)\s*\+=\s*(.+)\s*$/) {
+      $hashref->{$1} = $hashref->{$1} . " $2";
+    }
+  }
+
+  close MYINI;
+  return %hash;
+}
+
+sub CurrTimeStr {
+  my($sec, $min, $hour, $mday, $mon, $year) = localtime(time);
+  return (sprintf "%4.4d/%2.2d/%2.2d %2.2d:%2.2d", $year+1900, $mon+1, $mday, $hour, $min);
+}
+
+sub cp_3rdpartyTool {
+  if ($ENV{'MTK_INTERNAL'} eq 'TRUE') {
+    if (-e "tools/thirdParties.pl") {
+      print("perl tools/thirdParties.pl -cp \n");
+      system("perl tools/thirdParties.pl -cp");
+    } else {
+      warn "tools/thirdParties.pl does NOT exist!\n";
+      exit 1;
+    }
+  } else {
+    warn "Lack off thirdParties tools!\n";
+    warn "Please refer to document: SOP_Third_Party_Package_Installation!\n";
+    exit 1;
+  }
+}
+
+sub Usage {
+
+  warn << "__END_OF_USAGE";
+
+Usage:
+    ./m ["project makefile"] action [modules]|file1[ file2[ ...]] | \@files
+or  ./m ["make/projects/project makefile"] action [modules]|file1[ file2[ ...]] | \@files
+
+Description:
+  project makefile = ELBRUS_FPGA(flavor).mak  (ELBRUS_FPGA(FLAVOR) project)
+                   = ...
+
+  action     = new             (codegen, clean, update, remake) (default)
+             = update or u     (scan, compile, link)
+             = slim_update     (scan, compile, link without generating mcddll)
+             = remake or r     (compile, link)
+             = clean or c      (clean)
+             = c,u             (clean and update)
+             = c,r             (clean and remake)
+             = codegen         (codegen)
+             = slim_codegen    (codegen without generating mcddll)
+             = mcddll_update   (codegen and generate mcddll)
+             = slim_mcddll     (generate mcddll without codegen)
+             = emigen          (emigen)
+             = emiclean        (emiclean)
+
+  module(s)  = modules name   (kal, verno, ...)
+   => OPTIONAL when action is one of (clean c remake r update u c,r c,u)
+
+Example:
+  ./m "ELBRUS_FPGA(LWTG).mak" new
+  ./m "ELBRUS_FPGA(LWTG).mak" c,u custom
+  ./m "make/projects/ELBRUS_FPGA(LWTG).mak" r drv custom
+__END_OF_USAGE
+
+  exit 1;
+}
+
+sub writeINI {
+  &writeMakeINI();
+  if (($action ne "ckmake") && ($action ne "drv_feature_check")) {
+    system("echo LOCAL_MACHINE=%COMPUTERNAME% >>$targetFolder/build.log");
+    system("echo PROJECT_NAME=$project_name>>$targetFolder/build.log");
+    system("echo PLATFORM=$plat>>$targetFolder/build.log");
+    system("echo FLAVOR=$flavor>>$targetFolder/build.log");
+    system("echo VERNO=$verno>>$targetFolder/build.log");
+    system("echo ARMLMD_LICENSE_FILE=%ARMLMD_LICENSE_FILE%>>$targetFolder/build.log");
+    system("perl tools/init/echo.pl -n COMMAND=make \"@orgARGV\">>$targetFolder/build.log");
+    system("perl -e \"print \'BUILD END TIME=\'\">>$targetFolder/build.log");
+    system("perl tools/time.pl -n>>$targetFolder/build.log");
+    $time_num=time;
+    #mbis end probe
+    # to aviod be called twice when enable lsf 
+    if (($m_in_lsf != 1)&&($mbis_target_build_with_Modis != 1)) { 
+      &mbis_end_probe;
+    }
+  }
+}
+
+sub writeMakeINI {
+  mkpath("build") if(!-d "build");
+  if ($enINI == 1) {
+    open (FILE_HANDLE, ">$ini") or die "cannot open $ini\n";
+    print FILE_HANDLE "project_makefile = $project_makefile\n";
+    print FILE_HANDLE "project_folder = ". $original_projectFolder."\n";
+    close FILE_HANDLE;
+  }
+}
+
+sub pre_gen {
+  print "pre gen\n";
+  if(defined($level) && ($level =~ /VENDOR/i)) {
+    print "Skip pre_gen for vendor release.\n";
+    return 0;
+  }
+  print "Before submitting into CF machines, pre-check the Makefile, sys_auto_gen\n";
+  $ENV{"ACTION"} = "sys_auto_gen";
+  my @f = glob("$tmpFolder/~*.tmp *.d");
+  if(@f) {
+    unlink(@f) or die "Remove failed $!";
+  }
+  &gen_buildinfo_tmp;
+  if( ($action eq "new_modis") or ($action eq "new_uesim")) {
+    $target_option .= " MODIS_CONFIG=TRUE";
+  }
+  $preTestResult = system("${makeCmd} -f${makeFolder}${myMF} -r -R CORE_ROOT=$core_root PROJECT_NAME=$project_name \"PROJECT_MAKEFILE=$theMF\" FLAVOR=$flavor $target_options $target_option sys_auto_gen");
+  if ($preTestResult != 0) {
+    &writeINI;
+    exit 1;
+  }
+  print "Pass pre-check for Makefile and sys_auto_gen\n";
+}
+
+sub localq {
+  my ($islocalpath) = @_;
+  my $result = 0;
+  print "Check if localq is available .... ";
+  unlink("$logFolder/localq.log") if (-e "$logFolder/localq.log");
+  system("bhosts $ENV{\"COMPUTERNAME\"} >$logFolder/localq.log 2>nul");
+  open(LOCALQ, "$logFolder/localq.log") || die "Can not open $logFolder/localq.log!";
+  while (<LOCALQ>) {
+    next if ($_ =~ /HOST_NAME/ig);
+    $_ =~ /(\S+)\s+(\S+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/ig;
+    $STATUS = $2;
+    $MAX = $4;
+    $NJOBS = $5;
+  }
+  close LOCALQ;
+  if (($NJOBS < $MAX) && ($STATUS =~ /ok/ig)) {
+    print "YES\n";
+    print "Enter the local queue.\n";
+    if (($action =~ /new/i) && ((($action ne "new_modis") && ($action ne "new_uesim")) || ($pureMoDIS == 1))) {
+      &pre_gen();
+    }
+    if ($islocalpath ne "") {
+      if ($RUN_KLOCWORK eq 1) {
+        print "bsub -q localq -m $ENV{\"COMPUTERNAME\"} -I kwinject --detach Cgen.exe,DrvGen.exe -T kwinject.trace perl make.pl -lsf -localq -localpath @orgARGV\n";
+        $result = system("bsub -q localq -m $ENV{\"COMPUTERNAME\"} -I kwinject --detach Cgen.exe,DrvGen.exe -T kwinject.trace perl make.pl -lsf -localq -localpath @orgARGV");
+      } else {
+        print "bsub -q localq -m $ENV{\"COMPUTERNAME\"} -I perl make.pl -lsf -localq -localpath @orgARGV\n";
+        $result = system("bsub -q localq -m $ENV{\"COMPUTERNAME\"} -I perl make.pl -lsf -localq -localpath @orgARGV");
+      }
+    } else {
+      if ($RUN_KLOCWORK eq 1) {
+        print "bsub -q localq -m $ENV{\"COMPUTERNAME\"} -I kwinject --detach Cgen.exe,DrvGen.exe -T kwinject.trace perl make.pl -lsf -localq @orgARGV\n";
+        $result = system("bsub -q localq -m $ENV{\"COMPUTERNAME\"} -I kwinject --detach Cgen.exe,DrvGen.exe -T kwinject.trace perl make.pl -lsf -localq @orgARGV");
+      } else {
+        print "bsub -q localq -m $ENV{\"COMPUTERNAME\"} -I perl make.pl -lsf -localq @orgARGV\n";
+        $result = system("bsub -q localq -m $ENV{\"COMPUTERNAME\"} -I perl make.pl -lsf -localq @orgARGV");
+      }
+    }
+    &writeINI;
+    exit $result >> 8;
+  } else {
+    print "NO\n";
+  }
+}
+
+sub get_net_path {
+  my $path;
+  my $current_path = cwd();
+  if ($^O eq "MSWin32") {
+    $current_path =~ s/\//\\/g;
+    if ($current_path=~/^([ABDG-Z]:)(.*)/i) {
+      my $disk = $1;
+      my $folder = $2;
+      $folder =~ s/\\$//;
+      my @disk = `net use $disk`;
+      if ($#disk != -1) {
+        $disk[1]=~/\s+(\\\\.*)\s*$/;
+        $path = $1.$folder;
+      } else {
+        @disk = `subst`;
+        my $subst_folder;
+        foreach my $subdisk (@disk) {
+          $subdisk =~ s/\s*$//;
+          if ($subdisk =~ /($disk.*)\s*\=\>\s*(.*)/i){
+            $subst_folder= $2;
+            $subst_folder =~ s/://;
+          }
+        }
+        if ($subst_folder =~ /^UNC\\(.+)/) {
+          $path = "\\\\".$1;
+        } else {
+          if ($subst_folder ne "") {
+            $path = "\\\\".$ENV{"COMPUTERNAME"}."\\".$subst_folder.$folder;
+          } else {
+            $path = "\\\\".$ENV{"COMPUTERNAME"}."\\".$disk.$folder;
+          }
+        }
+      }
+    } elsif ($current_path=~/^([CEF]):(.*)/i) {
+      my $disk = $1;
+      my $folder = $2;
+      if ($ENV{"USERNAME"} =~ /wcxbm/ig) {
+        $path = "\\\\".$ENV{"COMPUTERNAME"}."\\".$disk."\$\$".$folder;
+      } else {
+        $path = "\\\\".$ENV{"COMPUTERNAME"}."\\".$disk.$folder;
+      }
+    }
+  } else {
+    $path = $current_path;
+  }
+  $path =~ s/://g;
+  print "path=$path\n";
+  return $path;
+}
+
+sub mbis_start_probe {
+  my $mbis_log_folder;
+
+  if ($mbis_en eq "TRUE") {
+    if (!defined($ENV{"MBIS_BUILD_TIME_TMP"}) || !defined($ENV{"MBIS_BUILD_TIME_LOG"}) || !defined($ENV{"MBIS_BUILD_INFO_LOG"})) {
+      $mbis_log_folder = "$logFolder/mbis";
+      if (!-d "$mbis_log_folder") {
+        mkpath($mbis_log_folder) or die "Create Folder $mbis_log_folder Faild $!";
+      } else {
+        # delete last log file
+        if ($mbis_en_save_log ne "TRUE") {
+          my @f = glob("$mbis_log_folder/*.log");
+          unlink(@f) or die "Remove failed $!" if(@f);
+          my @f = glob("$mbis_log_folder/*.tmp");
+          unlink(@f) or die "Remove failed $!" if(@f);
+        }
+      }
+
+      if (!defined($ENV{MBIS_BUILD_TIME_TMP})) {
+        $ENV{MBIS_BUILD_TIME_TMP} = $mbis_log_folder . "/". $build_time_string . "_" . "mbis" . "_" . "time" . ".tmp";
+        #set title of mbis time tmp file
+        system("echo Time Stamp,Item Name,Type,Time>>$ENV{MBIS_BUILD_TIME_TMP}");
+        system("echo T_S,TOTAL,A,$build_time_sec >>$ENV{MBIS_BUILD_TIME_TMP}");
+      }
+
+      if (!defined($ENV{MBIS_BUILD_TIME_LOG})) {
+        $ENV{MBIS_BUILD_TIME_LOG} = $mbis_log_folder . "/". $build_time_string . "_" . "mbis" . "_" . "time" . ".log";
+        #set title of mbis time tmp file
+        system("echo Item Name,Type,Start Time,End Time,Duration Time>>$ENV{MBIS_BUILD_TIME_LOG}");
+      }
+
+      if (!defined($ENV{MBIS_BUILD_INFO_LOG})) {
+        $ENV{MBIS_BUILD_INFO_LOG} = $mbis_log_folder . "/". $build_time_string . "_" . "mbis" . "_" . "info" . ".log";
+        #set title of mbis time tmp file
+        system("echo Information Name,Information Content>>$ENV{MBIS_BUILD_INFO_LOG}");
+        system("echo SUBMIT_TO_QUEUE_DATETIME,$submit_to_queue_time_string>>$ENV{MBIS_BUILD_INFO_LOG}") if ($submit_to_queue_time_string ne "");
+        system("echo BUILD_START_DATATIME,$build_time_string>>$ENV{MBIS_BUILD_INFO_LOG}");
+      }
+      system("perl $mbis -s \"@orgARGVwithFlavor\"");
+    }
+  } else {
+    # MBIS_BUILD_TIME_TMP must not be null for makefile expand the command
+    $ENV{MBIS_BUILD_TIME_TMP}=tmp;
+  }
+}
+
+sub mbis_info_probe {
+  if ($mbis_en eq "TRUE") {
+    if (($ENV{'MTK_INTERNAL'} eq 'TRUE') && (-e "$mbis_conf_file")) {
+      %mbis_conf = iniToHash($mbis_conf_file);
+      $pilot_bm_list = $mbis_conf{'INIT_CONF'}->{'BM_LIST'};
+      if ($pilot_bm_list =~ /$ENV{USERNAME}/i) {
+         system("perl $mbis -i BM_BUILD,1");
+      } else {
+         system("perl $mbis -i BM_BUILD,0");
+      }
+    }
+    
+    $cur_path=cwd(); 
+    system("perl $mbis -i BUILD_FOLDER,\"$cur_path\"");
+    if($^O eq" MSWin32") {
+      system("perl $mbis -i BUILD_MACHINE,$ENV{COMPUTERNAME}");
+    } else {
+      $hostname = `hostname`;
+      system("perl $mbis -i BUILD_MACHINE,$hostname");
+      system("perl $mbis -i BUILD_USER,$ENV{USER}");
+    }
+    system("perl $mbis -i CUSTOM_RELEASE,$custom_release");
+    if ($mbis_num_proc == 0) {
+      $mbis_num_proc = $ENV{"NUMBER_OF_PROCESSORS"};
+    }
+    system("perl $mbis -i NUMBER_OF_PROCESSORS,$mbis_num_proc");
+    system("perl $mbis -i LSF,$m_in_lsf");
+    system("perl $mbis -i COMPILER,$compiler");
+    system("perl $mbis -i USER,$ENV{USERNAME}");
+    system("perl $mbis -i PROJECT_NAME,$project_name");
+    system("perl $mbis -i FLAVOR,$flavor");
+    system("perl $mbis -i VERNO,$verno");
+    system("perl $mbis -i PLATFORM,$plat");
+    system("perl $mbis -i PID,$$");
+    if (-e "make/common/rel/mpd/5g") {
+      system("perl $mbis -i CODEBASE,MPD_5G");
+    }
+    elsif (-e "make/common/rel/mpd/4g") {
+      system("perl $mbis -i CODEBASE,MPD_4G");
+    }
+    elsif (-e "make/common/rel/mpd/common") {
+      system("perl $mbis -i CODEBASE,MPD_23G");
+    }
+    elsif (-e "make/common/rel/hq/USR.txt") {
+      system("perl $mbis -i CODEBASE,SWRD");
+    } 
+    else {
+      system("perl $mbis -i CODEBASE,RELEASE");
+      if (-d "make/common/rel/sub_ps") {
+        system("perl $mbis -i REL_PACKAGE,SUB_PS");
+      } 
+      else {
+        system("perl $mbis -i REL_PACKAGE,SUB_L4");
+      }
+    }
+    if (-e "dailybuild.txt") {
+      system("perl $mbis -i DAILY_BUILD_PRODUCER,1");
+    } else {
+      system("perl $mbis -i DAILY_BUILD_PRODUCER,0");
+    }
+    if (-e "ewsprebuild.txt") {
+      system("perl $mbis -i EWS_PREBUILD_PRODUCER,1");
+    } else {
+      system("perl $mbis -i EWS_PREBUILD_PRODUCER,0");
+    }
+    my @folder_cnt = <./build/*/*>;
+    my $fld_cnt = 0;
+    foreach (@folder_cnt) {
+     $fld_cnt ++ if(-d "$_");
+    }
+    system("perl $mbis -i NUMBER_OF_PROJECT_FOLDER,$fld_cnt");
+  }
+}
+
+sub mbis_end_probe {
+  if ($mbis_en eq "TRUE") { 
+    system("perl $mbis -e");
+
+    # transfer mbis when in mpd domain
+    if (-e "make/common/rel/mpd") {
+      if (-e "/mtkeda/wcpsm/utilities/UploadToMPDShare/upload_to_mpdshare") {
+        my $upload_folder = sprintf("%4.4d.%2.2d.%2.2d", $year+1900, $mon+1, $mday);
+        system("/mtkeda/wcpsm/utilities/UploadToMPDShare/upload_to_mpdshare \"$logFolder/mbis/*_time.tmp\" \"/901.SM_MBIS_LOG/original_data/$upload_folder/\" 1>/dev/null 2>&1 &");
+        system("/mtkeda/wcpsm/utilities/UploadToMPDShare/upload_to_mpdshare \"$logFolder/mbis/*_info.log\" \"/901.SM_MBIS_LOG/original_data/$upload_folder/\" 1>/dev/null 2>&1 &");
+      }
+    }
+  }
+}
+
+sub mbis_parse_arg {
+  $mbis_arg_exist = 1;
+  foreach $arg (@mbis_arg) {
+    if ($arg =~ /^en_mbis$/i) {
+      $arg_mbis_en = "TRUE";
+    } elsif ($arg =~ /^dis_mbis$/i) {
+      $arg_mbis_en = "FALSE";
+    } elsif ($arg =~ /^dis_obj$/i) {
+      $arg_mbis_en_obj_log = "FALSE";
+    } elsif ($arg =~ /^en_obj$/i) {
+      $arg_mbis_en_obj_log = "TRUE";
+    } elsif ($arg =~ /^save_log$/i) {
+      $arg_mbis_en_save_log = "TRUE";
+    } else {
+      # with error command
+      $mbis_arg_exist = 0;
+      return ;
+    }
+  }
+  if ($arg_mbis_en ne "TRUE") {
+    $arg_mbis_en_obj_log  = "FALSE";
+    $arg_mbis_en_save_log = "FALSE";
+  }
+}
+
+sub mbis_init {
+  if (($ENV{'MTK_INTERNAL'} eq 'TRUE') && (-e "$mbis_conf_file")) {
+    %mbis_conf = iniToHash($mbis_conf_file);
+    $mbis_bm_list = $mbis_conf{'INIT_CONF'}->{'BM_LIST'};
+    $mbis_project_list = $mbis_conf{'INIT_CONF'}->{'PROJECT_LIST'};
+    @mbis_project_array=split /,/, $mbis_project_list;
+    $mbis_en = $mbis_conf{'INIT_CONF'}->{'EN_ALL_PROJECT'};
+    $mbis_en_obj_log = $mbis_conf{'INIT_CONF'}->{'EN_OBJ_LOG'};
+    # force all project enable mbis
+    # enable obj log for BM only
+    if ($mbis_en eq "TRUE") {
+      # check bm list
+      if ($mbis_bm_list =~ /$ENV{USERNAME}/i) {
+        $mbis_en = "TRUE";
+        $mbis_en_obj_log = "TRUE";
+      } else {
+        $mbis_en = "TRUE";
+        $mbis_en_obj_log = "FALSE";
+      }
+    }
+    # deal with mbis option from arg
+    if ($mbis_en eq "TRUE") {
+      print("MBIS init enable\n");
+      if ($mbis_en_obj_log eq "TRUE") {
+        print("MBIS obj log enable\n");
+      }
+      if ($mbis_arg_exist == 1) {
+        $mbis_en = $arg_mbis_en;
+        $mbis_en_obj_log = $arg_mbis_en_obj_log;
+        $mbis_en_save_log = $arg_mbis_en_save_log;
+        if ($mbis_en eq "TRUE") {
+          print("MBIS arg enable\n");
+        } else {
+          print("MBIS arg disable\n");
+        }
+      }
+    } else {
+      $mbis_en_obj_log  = "FALSE";
+      $mbis_en_save_log = "FALSE";
+      print("MBIS init disable\n");
+    }
+  }
+}
+
+sub mbis_success {
+  my $build_custom_folder;
+  my @files;
+  my $elfname;
+  my $elfsize;
+  # get elf size
+  $build_custom_folder = "$targetFolder";
+  opendir (DIR, $build_custom_folder) or die "no folder : $build_custom_folder";
+  my @files = grep {/^$project_name.*\.elf$/}  readdir DIR;
+  close DIR;
+  if (@files == 1) {
+    $elfname = pop @files;
+    # add elf file name 
+    system("perl $mbis -i ELF_FILE,$elfname");
+    $elfsize = -s "$build_custom_folder\\$elfname";
+    # add elf file size
+    system("perl $mbis -i ELF_SIZE,$elfsize");
+  }
+
+  # add success flag
+  system("perl $mbis -i SUCCESSFUL_BUILD,1");
+}
+
+sub error_handle {
+  my $build_folder = "$targetFolder";
+  opendir (DIR, $build_folder) or die "no folder : $build_folder\n";
+  my @files = grep {/.+\.bin$/}  readdir DIR;
+  close DIR;
+  my $flag = 0;
+  foreach (@files) {
+    next if($_ =~ /BOOTLOADER/i);
+    my $bin_file = $build_folder."/$_";
+    if (-d "$bin_file") {
+      rmtree($bin_file);
+      $flag = 1;
+    } elsif(-e "$bin_file") {
+      unlink($bin_file) or die "Remove failed $!";
+      $flag = 1;
+    }
+  }
+  unlink("$build_folder/dep/postgen_dep/cp_dsp_files.det") if (-e "$build_folder/dep/postgen_dep/cp_dsp_files.det");
+  print "Some errors happened during the build process. Delete the binary file\n" if($flag);
+# [Linux] temporarily add
+  unlink("nul") if($^O eq "linux" && -e "nul");
+  unlink("NUL") if($^O eq "linux" && -e "NUL");
+  &writeINI;
+  exit 1;
+}
+
+sub genCustombld {
+  $bldPathName = "$projectFolder/Custom.bld";
+  if(-e "make/common/rel/hq/USR.txt") {
+    $bldValue = "FALSE";
+  } else {
+    $bldValue = "TRUE";
+  }
+  if(-e $bldPathName) {
+    open BLDFILE,"<$projectFolder/Custom.bld" or die "Can not open $projectFolder/Custom.bld";
+    while(<BLDFILE>) {
+      if(/CUSTOM_RELEASE = $bldValue/) {
+        close BLDFILE;
+        return 0;
+      }
+    }
+    close BLDFILE;
+  }
+  open BLDFILE,">$projectFolder/Custom.bld" or die "Can not open $projectFolder/Custom.bld";
+  print BLDFILE "CUSTOM_RELEASE = $bldValue\n";
+  close BLDFILE;
+}
+
+sub read_remake_mods {
+  my $file = $_[0];
+  my @value = "";
+  open (FILE_HANDLE, "<$file") or die "cannot open $file\n";
+  while (<FILE_HANDLE>) {
+    if (/^NEED_REMAKE_MODS\s*=\s*(.*)/) {
+      @value = $1;
+    }
+  }
+  return @value;
+}
+
+sub gen_buildinfo_tmp {
+  if (open FILE_HANDLE, ">$tmpFolder/~buildinfo.tmp") {
+    my $timeStr = &CurrTimeStr;
+    my $dbg_timeStr = $timeStr;
+    $dbg_timeStr =~ s/ /_/g;
+    $dbg_timeStr =~ s/:/_/g;
+    $dbg_timeStr =~ s/\//_/g;
+    print FILE_HANDLE "PROJECT_NAME=$project_name\n";
+    print FILE_HANDLE "FLAVOR=$flavor\n";
+    print FILE_HANDLE "ORIACTION=$oriaction\n";
+    print FILE_HANDLE "APLAT=$plat\n";
+    print FILE_HANDLE "CMD_ARGU=$fullOpts\n";
+    print FILE_HANDLE "BUILD_DATE_TIME=$timeStr\n";
+    # mbis options
+    print FILE_HANDLE "MBIS_EN=$mbis_en\n";
+    print FILE_HANDLE "MBIS_EN_OBJ_LOG=$mbis_en_obj_log\n";
+    print FILE_HANDLE "DBG_BUILD_DATE_TIME=$dbg_timeStr\n";
+    print FILE_HANDLE "NO_LTELIB=$no_ltelib\n";
+    print FILE_HANDLE "NO_LTECGEN=$no_ltecgen\n";
+    print FILE_HANDLE "NO_PCIBT=$no_pcibt\n";
+    print FILE_HANDLE "MCF_OTA_NAME=$ota_name\n";
+    print FILE_HANDLE "MODIS_CONFIG=$modis_config\n";      
+    print FILE_HANDLE "NO_DSP=$no_dsp\n";
+    print FILE_HANDLE "NO_WARNING_AS_ERROR=$no_warning_as_error\n";
+    print FILE_HANDLE "CHECK_FO_LICENSE=$check_fo_license\n";    
+    print FILE_HANDLE "LICENSE_INFO=$license_info\n";
+    print FILE_HANDLE "CUST_LIC=$cust_lic\n";
+    print FILE_HANDLE "VARIATION_PROJ=$VarioationProj_name\n";
+    print FILE_HANDLE "SRC_MAX_PACKAGE=$chk_rel_pkg\n";
+    print FILE_HANDLE "UPDATE_DSP=$update_dsp\n";
+    close FILE_HANDLE;
+  } else {
+    warn "Fail to write $tmpFolder/~buildinfo.tmp: $!\n";
+  }
+}