perl学习之MTK主要脚本make2.pl注释

声明:本脚本源自MTK,仅供个人学习使用,如商用请联系MTK,本人不对此承担任何责任

#!/usr/local/bin/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
# 
(!-d "make")&&(die "Folder \"make\" does NOT exist!\nPlease help to check.\n");#kaka whether "make " is a directory

use Win32::OLE qw(in);                           #sf.kaka use WIN32::OLE to get/write excel docs

if ((-e "mtk_tools\\Perl") && ($] >= 5.008006)){ #sf.kaka perl exists 
use lib "mtk_tools\\Perl";
use Win32::Process;                            #sf.kaka process management
use Win32;                                     #sf.kakasame time to above
use File::Basename;                            #sf.kaka use file parse/process module
Parse::CSV->import() if (eval "require Parse::CSV");   #sf.kaka can't find the two pm: parse,mime
MIME::Lite->import() if (eval "require MIME::Lite");
}

$myCmd = "make";    #sf.kaka make.bat <=> m.bat
$plat = "";         #sf.kaka platform name
$custom = "MTK";    ##customer name:*****      eg: make custom = ***** gprs 
@arguments = ();    #sf.kaka empty list
$project = "";     ##sf.kaka gprs ,gsm and so on
$action = "";      #sf.kaka new,r,update and so on
$m_in_lsf = 0;
@mOpts = ();       #sf.kaka optional
$fullOpts = "";
$level = "";
$relDir = "";
$MoDISLogDir = "_BUILD_LOG"; #sf.kaka for MoDIS building logs
$modisDir = "";
$MoDIS_poweron_result = 0;
$ini = "make.ini";
$enINI = 0;
($enINI = 1) if (($ENV{"USERDOMAIN"} =~ /MTK/i) || ($ENV{"USERDOMAIN"} =~ /PMT/i) || ($ENV{"USERDOMAIN"} =~ /MBJ/i));
#kaka userdomain of my machine is:CNHSZXPCC1RD ,so not matched 
($#ARGV < 0) && &Usage;                      # sf.kaka $#index of last parameter of ARGV
(($#ARGV < 1) && ($enINI == 0)) && &Usage;   #sf.kaka sub func call to output operate warning msg 
      
$newMoDIS = 0;
$atMoDIS = 0;
$dummyvm = 0;
@levels = qw(level2_src level2_obj level1 vendor); 
#kaka qw string the chars seperated by blankspace ,("level2_src","level2_obj","level","vendor")

@actions = qw(new update remake clean resgen codegen emiclean emigen sysgen ckscatter mmi_feature_check mmi_obj_check operator_check viewlog c,r c,u ckcr);
unshift(@actions, "bootloader") if ((-d "bootloader") && (-d "bootloader\\src")); #sf.kaka add bootloader to array actions
unshift(@actions, "fota") if ((-d "fota") && (-d "fota\\src")); ##sf.kaka the same
@projects = qw(l1s gsm gprs basic umts); 
@orgARGV = @ARGV; ##sf.kaka parameters list


###sf.kaka for example:make custotm=kaka25_07b_cmcc gprs new

while ($#ARGV != -1) {
if ($ARGV[0] =~ /^(p|pl|pla|plat|platf|platfo|platfor|platform)=(\w+)/i) {   ##determine the action by first parameter 
    $plat = $2;                     ##match platform :NULL
} elsif ($ARGV[0] =~ /^(c|cu|cus|cust|custo|custom)=(\w+)/i) {
    $custom = $2; ##kaka25_07b_cmcc 
} elsif ($ARGV[0] =~ /-modis/i) {
    $newMoDIS = 1;   ## NULL for modis prj construct 
} elsif ($ARGV[0] =~ /-atmodis/i) {
    $atMoDIS = 1;    ##NULL 
} elsif ($ARGV[0] =~ /-dummyvm/i) {
    $dummyvm = 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 = "CMD_ARGU=$2";
    @mOpts = split(",", $2);
} elsif ($ARGV[0] =~ /-lsf/i) {
    $m_in_lsf = 1;
} else {
    foreach $m (@projects) {
      if (lc($ARGV[0]) eq $m) { 
        $project = $m;       ##sf.kaka gprs
        shift(@ARGV);        ##sf.kaka delete @ARGV first element ,so delete gprs
        last;
      } elsif (lc($ARGV[1]) eq $m) {
        $project = $m;
        if ($ARGV[0] =~ /^mt6\d\d\d\w?$/i) { ##the prj mtk use itsself
          $plat = $ARGV[0];
        } else {
          $custom = $ARGV[0];
        }
        shift(@ARGV);
        shift(@ARGV);
        last;
      }
    }
    if (($project 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;
        }
      }
      close FILE_HANDLE;
      print "custom=$custom; plat=$plat; project=$project\n";
    }

    ##sf.kaka no prj name ,output relative warnings
    ($project eq "") && (die "Unrecognized \"$ARGV[0]\" or \"$ARGV[1]\"\nLack off one of (@projects)\nOr try $myCmd -h\n"); 
  

if ($#ARGV != -1) {     
      if ($ARGV[0] =~ /^[ucrUCR]$/) {    ##sf.kaka for simple write patten:make kaka25_07b_cmcc gprs r
        ($action = "clean") if ($ARGV[0] =~ /^[cC]$/);
        ($action = "update") if ($ARGV[0] =~ /^[uU]$/);
        ($action = "remake") if ($ARGV[0] =~ /^[rR]$/);
        shift(@ARGV);
        @arguments = @ARGV; ##sf.kaka parameter list
        @ARGV = ();
        last;     ##sf.kaka relative datas:custom,project,active,arguments have all been got,end the cycle
      } else {
unshift(@actions, "bm_new", "check", "notify","warn_notify", "cq_notify", "err_out", "db_notify", "db_modis_notify", "bm_remake", "bm_update", "patch", "ckmake")
          if (($ENV{"USERDOMAIN"} =~ /MTK/i) || ($ENV{"USERDOMAIN"} =~ /PMT/i) || ($ENV{"USERDOMAIN"} =~ /MBJ/i));##sf.kaka
if (-d "MoDIS") { ##sf.kaka following actions are about modis prj 
   unshift(@actions, "new_modis") if ((-e "MoDIS\\createMoDIS.pl") || (-e "MoDIS\\MoDIS.dsw"));
   unshift(@actions, "gen_modis") if (-e "MoDIS\\createMoDIS.pl");
   unshift(@actions, "codegen_modis") if (-e "MoDIS\\modisCodegen.pl");
   unshift(@actions, "remake_modis", "clean_modis") if (-e "MoDIS\\MoDIS.dsw");
   unshift(@actions, "at_modis", "ap_modis");
        }
unshift(@actions, "cmmgen", "rel") if (($ENV{"USERDOMAIN"} =~ /MTK/i) || ($ENV{"USERDOMAIN"} =~ /PMT/i) || ($ENV{"USERDOMAIN"} =~ /MBJ/i));
        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");
              ($fullOpts eq "") ? ($fullOpts = "CMD_ARGU=-k") : ($fullOpts .= ",-k");
              push(@mOpts, "-k");     #sf.kaka place para -k to the tail of array mOpts
     }
            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 check again or try $myCmd -h\n");
    if ($action eq "rel" || $action eq "ckcr") {
      $relDir = $arguments[0];
      shift(@arguments);
      ($#arguments == -1) && die "Lack off release level(@levels).\nOr try $myCmd -h\n";
      foreach $arg (@levels) {
        if (lc($arguments[0]) eq $arg) {
          $level = $arg;
          shift(@arguments);
          last;
        }
      }
      ($level eq "") && die "Lack off release level(@levels).\nOr try $myCmd -h\n";
      ($#arguments != -1) && (warn ");
    }
    last;
}
shift(@ARGV); ##sf.kaka in cycle ,delete first element
}

if ($ENV{"OS"} eq "Windows_NT") {   ##sf.kaka windows os
$delCmd = "del /Q";
$dirDelim = "\\";
$makeFolder = "make\\";       ##sf.kaka directory to place relative compile files 
} else {
$delCmd = "rm";
$dirDelim = "/";
$makeFolder = "make/";
}

chomp($cwd = `cd`);
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\n";
exit;
}

##sf.kaka our prj dismatched
if ($custom =~ /^(\w+)\((\w+)\)$/i) # match <custom>(<flavor>)=>SUPERMAN29_DEMO(JATAAYU)
{
    $custom = uc($1);
    $flavor = uc($2);
    $flavorMF = "${custom}_${project}($flavor).mak";
    #(!-e "${makeFolder}${flavorMF}") && (die "${makeFolder}${flavorMF} does NOT exist!\nPlease help to check.\n");
    if (-e "${makeFolder}${flavorMF}")
    {

        print ("copy /y ${makeFolder}${flavorMF} ${makeFolder}${custom}_${project}.mak\n");
        system("copy /y ${makeFolder}${flavorMF} ${makeFolder}${custom}_${project}.mak > nul");#kaka /y is existed,replace directly without user confirm
        print ("perl make\\flavor_conf.pl $custom $flavor $project\n");
        $fla_rel = system("perl make\\flavor_conf.pl $custom $flavor $project");
    }
    
    die "\nPlease check \"FLAVOR = XXX\" is exist and setting correct in make file !!\n\n" if($fla_rel);
    
    @tmpARGV = @orgARGV;
    @orgARGV = ();
    foreach (@tmpARGV)
    {
        $_ = $custom if (/^(${custom}\($flavor\))$/i);
        push (@orgARGV, $_);
    }
}

if ($ENV{"OS"} eq "Windows_NT") {
$toolsFolder = "tools\\";
$MTKtoolsFolder = "mtk_tools\\";

$prj_file = "make\\${custom}_${project}.mak"; ##sf.kaka kaka25_07b_cmcc_gprs.mak

if($custom eq "MTK")
{
   $prj_file="make\\${plat}_${project}.mak";
}

my $package = &get_package;##sf.kaka REL_CR_L4, REL_CR_MMI, REL_CR_OBJ, REL_CR_PROTOCOL

if ($package =~ /_(OBJ)_/i)
{
   @tools_Dirs = qw(tools\\);
}
else
{
@tools_Dirs = qw(tools\\ tools\\MinGW tools\\MSYS);##sf.kaka just exe here,for third party software
}

$makeCmd = "tools\\make.exe";
push (@tools_file,$makeCmd) ; ##sf.kaka one of the tools
@mmi_path = qw(plutommi\\Customer\\ResGenerator lcmmi\\Customer\\ResGenerator);#sf.kaka we use the first dir
foreach $mmi_path (@mmi_path) ##sf.kaka for 7zip,convert tools
{
next if (!-d $mmi_path);
$sevenZa_file = $mmi_path.""; 
   push (@tools_file,$sevenZa_file) ;
$convert = $mmi_path."";
   push (@tools_file,$convert) ;
last;
}
} else {
$toolsFolder = "tools/";
$MTKtoolsFolder = "mtk_tools/";

$prj_file = "make/${custom}_${project}.mak";

if($custom eq "MTK")
{
   $prj_file="make/${plat}_${project}.mak";
}

my $package = &get_package;
if ($package =~ /_(OBJ)_/i)
{
   @tools_Dirs = qw(tools/);
}
else
{
@tools_Dirs = qw(tools/ tools/MinGW tools/MSYS);
}

$makeCmd = "tools/make";
push (@tools_file,$makeCmd) ;
@mmi_path = qw(plutommi/Customer/ResGenerator lcmmi/Customer/ResGenerator);
foreach $mmi_path (@mmi_path) 
{
next if (!-d $mmi_path);
$sevenZa_file = $mmi_path."/7za.exe";
   push (@tools_file,$sevenZa_file) ;
$convert = $mmi_path."/convert.exe";
   push (@tools_file,$convert) ;
last;
}
}


qw(tools\\ tools\\MinGW   tools\\MSYS);
foreach $tools_Dirs (@tools_Dirs) 
{
if (!-d $tools_Dirs)    ##sf.kaka not exist this dir
{
   warn "$tools_Dirs folder does NOT exist!\n";
   &cp_3rdpartyTool; ##sf.kaka mtk get its 3rdparty tools
}
}

foreach $tools_file (@tools_file)
{
if (!-e $tools_file) 
{
   warn "$tools_file does NOT exist!\n";
   &cp_3rdpartyTool;
}
}

if (($action eq "update") || ($action eq "remake") || ($action eq "new") || ($action eq "bm_new") ||
    ($action eq "c,r") || ($action eq "c,u")) {
if ($ENV{"NUMBER_OF_PROCESSORS"} > 1) { #sf.kaka in my machine its value 2
    if ($fullOpts eq "") {
      $fullOpts = "CMD_ARGU=-j$ENV{\"NUMBER_OF_PROCESSORS\"}";
    } else {
      $fullOpts .= ",-j$ENV{\"NUMBER_OF_PROCESSORS\"}";
    }
}
}


##sf.kaka not understand it fully maybe mmi_app and so on
if ($fullOpts ne "") {
$fullOpts =~ s/"/\\"/g;
$fullOpts = "\"$fullOpts\"";
$fullOpts =~ s/,/ /g;
$makeCmd .= " " . join(" ", @mOpts) . " $fullOpts ";
}

$msdev = 'msdev';
$cl = 'cl';
$is_msdev = 0;
$is_cl = 0;
$VSCommonDir = "C:\\Program Files\\Microsoft Visual Studio\\Common";
$MSDevDir = "C:\\Program Files\\Microsoft Visual Studio\\Common\\MSDev98";
$MSVCDir = "C:\\Program Files\\Microsoft Visual Studio\\VC98";
$VcOsDir = "WIN95";


##sf.kaka set relative environment variables for modis op 
if (($newMoDIS == 1) || ($atMoDIS == 1) || ($action =~ /MoDIS/i)) {
if ((-d $VSCommonDir) && (-d $MSDevDir) && (-d $MSVCDir)) { ##sf.kaka vc6 have been installed correctly
    if ($ENV{"OS"} eq "Windows_NT") {
      $VcOsDir = "WINNT"; ##sf.kaka just this
      $ENV{"PATH"} = "${MSDevDir}\\BIN;${MSVCDir}\\BIN;${VSCommonDir}\\TOOLS\\${VcOsDir};${VSCommonDir}\\TOOLS;" . $ENV{"PATH"};
    } else {
      $ENV{"PATH"} = "${MSDevDir}\\BIN;${MSVCDir}\\BIN;${VSCommonDir}\\TOOLS\\${VcOsDir};${VSCommonDir}\\TOOLS;" .$ENV{"windir"}. ";" . $ENV{"PATH"};
    }
    $ENV{"INCLUDE"} = "${MSVCDir}\\ATL\\INCLUDE;${MSVCDir}\\INCLUDE;${MSVCDir}\\MFC\\INCLUDE;". $ENV{"INCLUDE"};
    $ENV{"LIB"} = "${MSVCDir}\\LIB;${MSVCDir}\\MFC\\LIB;". $ENV{"LIB"};
} else {
    print "$VSCommonDir does NOT exist!\n" if (!-d $VSCommonDir);
    print "$MSDevDir does NOT exist!\n" if (!-d $MSDevDir);
    print "$MSVCDir does NOT exist!\n" if (!-d $MSVCDir);
}
$is_msdev = system("$msdev /? > nul 2>&1"); ##sf.kaka if zero ,msdev tools exists
$is_cl = system("$cl > nul 2>&1"); ##sf.kaka the same to above
}

if ($m_in_lsf == 1) {
die "NOT IN LSF SERVER!\n" if ($ENV{"LS_ADMINNAME"} eq "");
$computerName = $ENV{"COMPUTERNAME"};
system("echo set LAST_SUBMITTED_CF=$computerName > LAST_S_C.bat");
$ENV{"TMP"} = "e:\\temp";
$ENV{"TEMP"} = "e:\\temp";
system("mkdir e:\\temp > nul 2>&1") if (!-d "e:\\temp");
}

if ($plat ne "") {
$plat =~ y/a-z/A-Z/; 
$theMF = "${makeFolder}${plat}_${project}.mak";
$enFile = "${makeFolder}${plat}_${project}_en.def";
$disFile = "${makeFolder}${plat}_${project}_dis.def";
if ($project =~ /GPRS/i) {
    $theVerno = "${makeFolder}verno_classb.bld";
} elsif ($project =~ /UMTS/i) {
    $theVerno = "${makeFolder}verno_classb_umts.bld";
} else {
    $theVerno = "${makeFolder}verno.bld";
}
} else {
$custom =~ y/a-z/A-Z/;##sf.kaka this match symbol not seen ,should seet tht internet again maybe!
$plat = "NONE";
$theMF = "${makeFolder}${custom}_${project}.mak";
$enFile = "${makeFolder}${custom}_${project}_en.def";##sf.kaka this file not exist
$disFile = "${makeFolder}${custom}_${project}_dis.def";##sf.kaka this file not exist
$theVerno = "${makeFolder}Verno_${custom}.bld";
if (($custom eq "MTK") || ($custom =~ /\bMT62\d\d\w?\b/i)) {##sf.kaka mtk use
    if ($custom =~ /\bMT62\d\d\w?\b/i) {
      $plat= $custom;
      $custom = "MTK";      
    }
    if ($project =~ /GPRS/i) {
      $theVerno = "${makeFolder}verno_classb.bld";
    } elsif ($project =~ /UMTS/i) {
      $theVerno = "${makeFolder}verno_classb_umts.bld";
    } else {
      $theVerno = "${makeFolder}verno.bld";
    }
}
}
(!-e $theMF) && (die "$theMF does NOT exist!\nPlease help to check.\n");
(!-e $theVerno) && (die "$theVerno does NOT exist!\nPlease help to check.\n");
$myMF = "gsm2.mak";

open (FILE_HANDLE, "<$theMF") or die "cannot open $theMF\n";
while (<FILE_HANDLE>) {
if (/^(\S+)\s*=\s*(\S+)/) { ##sf.kaka parse kaka25_07b_cmcc_gprs.mak
    $keyname = lc($1); 
    #defined($${keyname}) && warn "$1 redefined in $thefile!\n";
    $${keyname} = uc($2);
}
}
close FILE_HANDLE;

# To copy needed GIS folder from Server to the local disk.
if ($demo_project eq "TRUE") { ##sf.kaka TRUE for MTK internal demo prj
if ((defined $gis_support) && ($gis_support ne "NONE")) {
    if ($gis_support eq "MAPBAR_NAVI") {
      open(FILE_HANDLE,"vendor\\gis\\mapbar\\map\\navi_map_version.ini") || die "Cannot open vendor\\gis\\mapbar\\map\\navi_map_version.ini:$!";
      $vendor="mapbar";
    } elsif ($gis_support eq "MAPBAR_BUS") {
      open(FILE_HANDLE,"vendor\\gis\\mapbar\\map\\bus_map_version.ini") || die "Cannot open vendor\\gis\\mapbar\\map\\bus_map_version.ini:$!";
      $vendor="mapbar";
    } elsif ($gis_support eq "SUNAVI") {
      open(FILE_HANDLE,"vendor\\gis\\sunavi\\map\\sunavi_map_version.ini") || die "Cannot open vendor\\gis\\mapbar\\map\\sunavi_map_version.ini:$!";
      $vendor="sunavi";
    }
    while (<FILE_HANDLE>) {
      if (/\[TEST_SOURCE\]\s+=\s+(.+)/){
       # For internal
        $test_source = $1;
        $dir_exist=system("dir /b $test_source>nul");
      $test_source =~ /.+\\(.+)?\"/;
       $target_folder=$1;
      }
    }
    close(FILE_HANDLE);
    if ((!-d "vendor\\gis\\$vendor\\map\\$target_folder") && ($dir_exist == 0)) {
      print "mkdir vendor\\gis\\$vendor\\map\\$target_folder\n";
      system("mkdir vendor\\gis\\$vendor\\map\\$target_folder");
      print "xcopy /e /Y $test_source vendor\\gis\\$vendor\\map\\$target_folder\n";
      system("xcopy /e /Y $test_source vendor\\gis\\$vendor\\map\\$target_folder > nul");
    }
}
} else {
#For customer projects, release all demo maps.
if ((defined $gis_support) && ($gis_support ne "NONE")) {
    open(FILE_HANDLE,"vendor\\gis\\mapbar\\map\\navi_map_version.ini") || die "Cannot open vendor\\gis\\mapbar\\map\\navi_map_version.ini:$!";
      while (<FILE_HANDLE>) {
        if (/\[DEMO_SOURCE\]\s+=\s+(.+)/){
          $demo_source1 = $1;
          $dir1_exist=system("dir /b $demo_source1>nul");
         $demo_source1 =~ /.+\\(.+)?\"/;
          $target_folder1=$1;
        }
      }
    close(FILE_HANDLE);
    open(FILE_HANDLE,"vendor\\gis\\mapbar\\map\\bus_map_version.ini") || die "Cannot open vendor\\gis\\mapbar\\map\\bus_map_version.ini:$!";
      while (<FILE_HANDLE>) {
        if (/\[DEMO_SOURCE\]\s+=\s+(.+)/){
          $demo_source2 = $1;
          $dir2_exist=system("dir /b $demo_source2>nul");
         $demo_source2 =~ /.+\\(.+)?\"/;
          $target_folder2=$1;
        }
      }
    close(FILE_HANDLE);
    open(FILE_HANDLE,"vendor\\gis\\sunavi\\map\\sunavi_map_version.ini") || die "Cannot open vendor\\gis\\mapbar\\map\\sunavi_map_version.ini:$!";
      while (<FILE_HANDLE>) {
        if (/\[DEMO_SOURCE\]\s+=\s+(.+)/){
          $demo_source3 = $1;
          $dir3_exist=system("dir /b $demo_source3>nul");
         $demo_source3 =~ /.+\\(.+)?\"/;
          $target_folder3=$1;
        }
      }
    close(FILE_HANDLE);
}
if ((!-d "vendor\\gis\\mapbar\\map\\target_folder1") && ($dir1_exist == 0)) {
    print "mkdir vendor\\gis\\mapbar\\map\\target_folder1\n";
    system("mkdir vendor\\gis\\mapbar\\map\\target_folder1");
    print "xcopy /e /Y $demo_source1 vendor\\gis\\mapbar\\map\\target_folder1\n";
    system("xcopy /e /Y $demo_source1 vendor\\gis\\mapbar\\map\\target_folder1 > nul");
}
if ((!-e "vendor\\gis\\mapbar\\map\\target_folder2") && ($dir2_exist == 0)) {
    print "mkdir vendor\\gis\\mapbar\\map\\target_folder2\n";
    system("mkdir vendor\\gis\\mapbar\\map\\target_folder2");
    print "xcopy /e /Y $demo_source2 vendor\\gis\\mapbar\\map\\target_folder2\n";
    system("xcopy /e /Y $demo_source2 vendor\\gis\\mapbar\\map\\target_folder2 > nul");
}
if ((!-d "vendor\\gis\\sunavi\\map\\target_folder3") && ($dir3_exist == 0)) {
    print "mkdir vendor\\gis\\sunavi\\map\\target_folder3\n";
    system("mkdir vendor\\gis\\sunavi\\map\\target_folder3");
    print "xcopy /e /Y $demo_source3 vendor\\gis\\sunavi\\map\\target_folder3\n";
    system("xcopy /e /Y $demo_source3 vendor\\gis\\sunavi\\map\\target_folder3 > nul");
}
}

# To check if the Java settings in the project makefile was the same with the romizing one.

if (-e "make\\~romizing.log") {    ##sf.kaka not exist in practical prj
system("del /Q make\\~romizing\.log");
}
$romizing_flag = 0;
if ($j2me_support eq "IJET"){##sf.kaka NONE in practical prj
if (-e "custom\\j2me\\IJET\\$board_ver\\$board_ver\.rec") {
open (FILE_HANDLE, "<custom\\j2me\\IJET\\$board_ver\\$board_ver\.rec") or die "Cannot open custom\\j2me\\IJET\\$board_ver\\$board_ver\.rec:$!\n";
open (WRITE_HANDLE, ">>make\\~romizing\.log") or die "Cannot open make\\~romizing.log:$!\n";
while (<FILE_HANDLE>) {
    if (/^(\S+)\s*=\s*(\S+)/) {
      $rec_keyname = lc($1);
      if ($${rec_keyname} ne uc($2)) {
      print "ERROR! $rec_keyname mismatched in the project makefile(".$${rec_keyname}.") and the romizing(".uc($2).").\n";
      print WRITE_HANDLE "ERROR! $rec_keyname mismatched in the project makefile(".$${rec_keyname}.") and the romizing(".uc($2).").\n";
      $romizing_flag = 1;
      }
    }
}
close WRITE_HANDLE;
close FILE_HANDLE;
if ($romizing_flag eq "1") {
if ($empty_resource eq "TRUE") {
   exit 1;
    }
}

}
}
if ($modisDir eq "") {
if ((($mmi_version eq "PLUTO_MMI") || ($mmi_version eq "NEPTUNE_MMI")) && ($empty_resource eq "FALSE")) {##sf.kaka PLUTOMMI TRUE
    $modisDir = "Debug";
} else {
    $modisDir = "Release"; ##sf.kaka just this
}
}

if (($m_in_lsf == 0) && ($action =~ /new/i) && ($ENV{"SESSIONNAME"} ne "") &&    ##sf.kaka SESSIONAME :Console
    ($ENV{"LSF_BINDIR"} ne "") && ($project !~ /BASIC/i) && ($project !~ /L1S/i)) {

chomp($cwd = `cd`);
if (($cwd =~ /^[a-df-z]/i) && ($ENV{COMPUTERNAME} !~ /mtkcf/i)) {

    print "Before submitting into CF machines, pre-check the Makefile and cmmgen\n"; 
    $ENV{"ACTION"} = "cmmgen";
    system("$delCmd ${makeFolder}~*.tmp *.d > nul 2>&1");
    system("echo CUSTOMER=$custom > ${makeFolder}~buildinfo.tmp");
    system("echo PROJECT=$project >> ${makeFolder}~buildinfo.tmp");
    system("echo APLAT=$plat >> ${makeFolder}~buildinfo.tmp");
    $timeStr = &CurrTimeStr;
    system("echo BUILD_DATE_TIME=$timeStr >> ${makeFolder}~buildinfo.tmp");
    $preTestResult = system("${makeCmd} -f${makeFolder}${myMF} -r -R CUSTOMER=$custom PROJECT=$project cmmgen");##sf.kaka not understand
    (&writeINI && exit 1) if ($preTestResult != 0);
    print "Pass pre-check for Makefile and cmmgen\n";

    $env_last_S_CF = "";
    $lastSC = "LAST_S_C.bat";
    if ((-e $lastSC) && (open(LOGF, "${lastSC}"))) {
      while (<LOGF>) {
        if (/set LAST_SUBMITTED_CF=(\S+)/) {
          $env_last_S_CF = $1;
          last;
        }
      }
      close(LOGF);
    }
#    $ENV{"NUMBER_OF_PROCESSORS"} = 1;
    if ($env_last_S_CF eq "") {
      system("bsub -I perl m_cp2lsf.pl @orgARGV");
    } else {
      system("bsub -I -m \"${env_last_S_CF}+2 mtkcf+1\" perl m_cp2lsf.pl @orgARGV");
    }
    &writeINI;
    exit 0;
}
}

if ($#arguments != -1) {##sf.kaka for mmi_app,mmi_framework and so on
if (($action eq "clean") || ($action eq "remake") || ($action eq "update") ||
      ($action eq "c,r") || ($action eq "c,u") || ($action eq "remake_modis") ||
      ($action eq "clean_modis")) {
    $chk_wrong = 0;
    foreach $argu (@arguments) {
      next if ((lc($argu) eq "modis_ui") && (($action eq "remake_modis") || ($action eq "clean_modis")));
#      (!-d "${makeFolder}$argu") && (!-d "${makeFolder}${argu}_classb") && ($chk_wrong = 1) && print "Wrong module name ==> $argu\n";
    }
    ($chk_wrong == 1) && die "Please check and retry again\n";
}
}

if ($action eq "c,r") {
@theAct = qw(clean remake);
} elsif ($action eq "c,u") {
@theAct = qw(clean update);
} else {
@theAct = ($action);
}

foreach $action (@theAct) {
$ENV{"ACTION"} = $action;
system("$delCmd ${makeFolder}~*.tmp *.d > nul 2>&1"); ##sf.kaka del temp files
system("echo CUSTOMER=$custom > ${makeFolder}~buildinfo.tmp");
system("echo PROJECT=$project >> ${makeFolder}~buildinfo.tmp");
system("echo APLAT=$plat >> ${makeFolder}~buildinfo.tmp");
$timeStr = &CurrTimeStr;
system("echo BUILD_DATE_TIME=$timeStr >> ${makeFolder}~buildinfo.tmp");
##sf.kaka del relative info to file

if ($action eq "clean") {
    if ($#arguments != -1) {
      system("echo DO_CLEAN_MODULE=TRUE > ${makeFolder}~cleanmod.tmp");
      system("echo >> ${makeFolder}~cleanmod.tmp");
      system("${makeCmd} -f${makeFolder}${myMF} -r -R CUSTOMER=$custom PROJECT=$project cleanmod");
    } else {
      system("echo DO_CLEAN_MODULE=FALSE > ${makeFolder}~cleanmod.tmp");
      system("${makeCmd} -f${makeFolder}${myMF} -r -R CUSTOMER=$custom PROJECT=$project cleanall");
    }
} elsif (($action eq "remake") && ($#arguments != -1)) {
    system("echo DO_REMAKE_MODULE=TRUE > ${makeFolder}~remakemod.tmp");
    system("echo >> ${makeFolder}~remakemod.tmp");
} elsif (($action eq "update") && ($#arguments != -1)) {
    system("echo DO_UPDATE_MODULE=TRUE > ${makeFolder}~updatemod.tmp");
    system("echo >> ${makeFolder}~updatemod.tmp");
} elsif ($action eq "codegen") {
    system("${makeCmd} -f${makeFolder}${myMF} -r -R CUSTOMER=$custom PROJECT=$project code_generate");
} elsif ($action eq "check") {
    system("perl ${toolsFolder}parse_comp_err.pl $custom");
} elsif ($action eq "notify") {
    system("perl ${MTKtoolsFolder}notify_err.pl $custom $project bm_notify");
} elsif ($action eq "warn_notify") {
    system("perl ${MTKtoolsFolder}notify_err.pl $custom $project warn_notify");
} elsif ($action eq "cq_notify") {
    system("perl ${MTKtoolsFolder}notify_err.pl $custom $project cq_notify"); 
} elsif ($action eq "err_out") {
    system("perl ${MTKtoolsFolder}notify_err.pl $custom $project err_out");
} elsif ($action eq "db_notify") {
    system("perl ${MTKtoolsFolder}notify_err.pl $custom $project db_notify");
} elsif ($action eq "db_modis_notify") {
    system("perl ${MTKtoolsFolder}notify_err.pl $custom $project db_modis_notify");
} elsif ($action eq "patch") {
    system("perl ${MTKtoolsFolder}patch_file.pl $custom $project @arguments");
} elsif ($action =~ /_modis$/) { ##sf.kaka gen_modis codegen_modis and so on
    &chdirMoDIS;   ##sf.kaka change work dir to 
    &genMoDIS if (($action eq "new_modis") || ($action eq "gen_modis"));
    &codegenMoDIS if (($action eq "new_modis") || ($action eq "codegen_modis"));
    &cleanMoDIS if (($action eq "new_modis") || ($action eq "clean_modis"));
    &remakeMoDIS if (($action eq "new_modis") || ($action eq "remake_modis"));
    &MoDIS_auto_power_on_test if ($action eq "new_modis") || ($action eq "ap_modis");
    &at_MoDIS if ($action eq "at_modis");
    &chdirToMcu;
    $mcddllpath = "ps\\mcddll";
    if ((-d $mcddllpath) && (-e "${mcddllpath}\\mcddll.dsw")) {
      if ($action eq "new_modis") {
       chdir($mcddllpath);
       system("$msdev mcddll.dsw /MAKE \"mcddll - Win32 $modisDir\" /rebuild > nul 2>&1");
      chdir("..\\..");
        if (-e "${mcddllpath}\\mcddll.dll") {
          system("copy /y ${mcddllpath}\\mcddll.dll tst\\database_modis\\mcddll.dll > nul");
        }
      } elsif ($action eq "remake_modis") {
       chdir($mcddllpath);
       system("$msdev mcddll.dsw /MAKE \"mcddll - Win32 $modisDir\" > nul 2>&1");
       chdir("..\\..");
        if (-e "${mcddllpath}\\mcddll.dll") {
          system("copy /y ${mcddllpath}\\mcddll.dll tst\\database_modis\\mcddll.dll > nul");
        }
      }
    }
} elsif ($action eq "viewlog") {
    $logDir = ".\\build\\${custom}\\log";
    die "$logDir does NOT exist\n" if (!-d $logDir);
    if ($#arguments != -1) {
      foreach $argu (@arguments) {
        if (-e "${logDir}\\${argu}.log") {
          system("start ${logDir}\\${argu}.log");
        } elsif (-e "${logDir}\\${argu}_classb.log") {
          system("start ${logDir}\\${argu}_classb.log");
        } else {
           warn "${logDir}\\${argu}.log does NOT exist\n";
        }
      }
    } else {
      while ($argu = <$logDir\\*.log>) {
        system("start ${argu}") if (-e "${argu}");
      }
    }
} elsif ($action eq "rel") {
    #(!-e $disFile) && (die "$disFile does NOT exist!\nPlease help to check.\n");
    if (!-e $enFile) {
      warn "$enFile does NOT exist!\nCreate an EMPTY $enFile\n";
      sleep 2;
      system "copy /y nul $enFile > nul";
    }
    system("echo LEVEL=$level >> ${makeFolder}~buildinfo.tmp");
    system("echo DUMMYVM=TRUE >> ${makeFolder}~buildinfo.tmp") if ($dummyvm == 1);
    system("$makeCmd -f${makeFolder}custom_release.mak -r -R CUSTOMER=$custom PROJECT=$project RELEASE_DIR=$relDir LEVEL=$level");
    &writeINI;
    exit 0;
} elsif ($action eq "ckcr") {
    if(-e "error") {
      system("del /Q error");
    }
    if(-e "ckrelpkg.log") {
      system("del /Q ckrelpkg.log");
    }
    system("$makeCmd -f${makeFolder}custom_release.mak -r -R CUSTOMER=$custom PROJECT=$project RELEASE_DIR=$relDir LEVEL=$level ckcr 2>error");
    system("perl mtk_tools\\ckrelpkg.pl NONE $theVerno TRUE $custom>>error");
    if (-e "error") {
      open(preCR,"<error") || die "Cannot not open custom release pre-check log:$!\n";
      $crlf = $/;
      undef $/;
      $errorContent = <preCR>;
      $/ = $crlf;
      if (($errorContent =~ /\*\*\*/) || ($errorContent =~ /Error:/i)) {
       print "\nCustom Release script check error\n\n";
       print "$errorContent\n";
       exit 1;
      }
    }
} elsif (($action ne "new") && ($action ne "bm_new")) {
    system("${makeCmd} -f${makeFolder}${myMF} -r -R CUSTOMER=$custom PROJECT=$project $action");
    next;
}

if (($action eq "remake") || ($action eq "update") ||
      ($action eq "new")|| ($action eq "bm_new")) {
    if ($action eq "bm_new") {
      system("echo BM_NEW=TRUE >> ${makeFolder}~buildinfo.tmp");
      $result = system("${makeCmd} -f${makeFolder}${myMF} -k -r -R CUSTOMER=$custom PROJECT=$project new");
    } else {
      $result = system("${makeCmd} -f${makeFolder}${myMF} -r -R CUSTOMER=$custom PROJECT=$project $action");
    }

&writeINI;
    if ((($newMoDIS == 1) || ($atMoDIS == 1)) && (($result == 0) && (-d "MoDIS"))) {
      &chdirMoDIS;
      &genMoDIS;
      &codegenMoDIS;
      &cleanMoDIS;
      &remakeMoDIS;
      &MoDIS_auto_power_on_test;
      if ($atMoDIS == 1) {
       &at_MoDIS;
      }
      &chdirToMcu;
    }
    exit 0;
}
}

&writeINI;
exit 0;

sub genMoDIS {
&chdirToMcu; 
system("${makeCmd} -f${makeFolder}${myMF} -r -R CUSTOMER=$custom PROJECT=$project cleanlog");
&chdirMoDIS;
if (!-e "createMoDIS.pl") {
    warn "Skip genMoDIS due to script createMoDIS.pl does NOT exist!\n";
    return;
}
print("perl createMoDIS.pl ..\\$theMF\n") if (-e "createMoDIS.pl");
system("perl createMoDIS.pl ..\\$theMF") if (-e "createMoDIS.pl");
}

sub codegenMoDIS {
if (!-e "modisCodegen.pl") {
    warn "Skip codegenMoDIS due to script modisCodegen.pl does NOT exist!\n";
    return;
}
die "Could not run \"cl.exe\". Please check your PATH!\n" if ($is_cl != 0);
mkdir($MoDISLogDir) if (!-d $MoDISLogDir);
print("perl modisCodegen.pl ..\\$theMF > ${MoDISLogDir}\\codegen.log\n") if (-e "modisCodegen.pl");
system("perl modisCodegen.pl ..\\$theMF > ${MoDISLogDir}\\codegen.log") if (-e "modisCodegen.pl");
}

sub cleanMoDIS {
die "Could not run \"msdev.exe\". Please check your PATH!\n" if ($is_msdev != 0);
if ($#arguments != -1) {
    foreach $argu (@arguments) {
      if (($project =~ /(GPRS|UMTS)/i) && ((lc($argu) eq "l1") || (lc($argu) eq "rr") || (lc($argu) eq "mm")
         || (lc($argu) eq "l4") || (lc($argu) eq "peer") || (lc($argu) eq "interface"))) {
        $argu .= "_classb";
      }
      if (((!-e "${argu}\\${argu}.ini") && (lc($argu) ne "modis_ui")) || (!-e "${argu}\\${argu}.dsp")) {
        warn "SKIP $argu since ${argu}\\${argu}.ini or ${argu}\\${argu}.dsp does NOT exist\n";
        next;
      }
      print("$msdev MoDIS.dsw /MAKE \"$argu - Win32 $modisDir\" /clean\n");
      system("$msdev MoDIS.dsw /MAKE \"$argu - Win32 $modisDir\" /clean");
    }
} else {
    print("$msdev MoDIS.dsw /MAKE \"MoDIS - Win32 $modisDir\" /clean\n");
    system("$msdev MoDIS.dsw /MAKE \"MoDIS - Win32 $modisDir\" /clean");
}
}

sub remakeMoDIS {
mkdir($MoDISLogDir) if (!-d $MoDISLogDir);
die "Could not run \"msdev.exe\". Please check your PATH!\n" if ($is_msdev != 0);

if ($#arguments != -1) {
    foreach $argu (@arguments) {
      if (($project =~ /(GPRS|UMTS)/i) && ((lc($argu) eq "l1") || (lc($argu) eq "rr") || (lc($argu) eq "mm")
         || (lc($argu) eq "l4") || (lc($argu) eq "peer") || (lc($argu) eq "interface"))) {
        $argu .= "_classb";
      }
      if (((!-e "${argu}\\${argu}.ini") && (lc($argu) ne "modis_ui")) || (!-e "${argu}\\${argu}.dsp")) {
        warn "SKIP $argu since ${argu}\\${argu}.ini or ${argu}\\${argu}.dsp does NOT exist\n";
        next;
      }
      system("perl ../tools/time.pl");
      print("$msdev MoDIS.dsw /MAKE \"$argu - Win32 $modisDir\" /OUT ${MoDISLogDir}\\${argu}.log\n");
      $result = system("$msdev MoDIS.dsw /MAKE \"$argu - Win32 $modisDir\" /OUT ${MoDISLogDir}\\${argu}.log");
      if ($result == 0) {
        print("      ==> [P]\n");
      } else {
        print("      ==> [F]\n");
      }
    }
} else {
    print("\nBuilding MoDIS ...\n");
    if ((-e "lib_list") && (open(LOGF, "<lib_list"))) {
      while ($f = <LOGF>) {
        chomp($f);
        next if (!-e "${f}\\${f}.ini");
        next if (!-e "${f}\\${f}.dsp");
        system("perl ../tools/time.pl");
        print("$msdev MoDIS.dsw /MAKE \"$f - Win32 $modisDir\" /OUT ${MoDISLogDir}\\${f}.log\n");
        $result = system("$msdev MoDIS.dsw /MAKE \"$f - Win32 $modisDir\" /OUT ${MoDISLogDir}\\${f}.log");
        if ($result == 0) {
          print("      ==> [P]\n");
        } else {
          print("      ==> [F]\n");
        }
      }
      close(LOGF);
    }
}
system("perl ../tools/time.pl");
print("$msdev MoDIS.dsw /MAKE \"MoDIS - Win32 $modisDir\" /OUT ${MoDISLogDir}\\MoDIS.log\n");
system("$msdev MoDIS.dsw /MAKE \"MoDIS - Win32 $modisDir\" /OUT ${MoDISLogDir}\\MoDIS.log");
if (-e "MoDIS\\${modisDir}\\MoDIS.exe") {
    print("      ==> [P]\n");
} else {
    print("      ==> [F]\n");
}
}

sub MoDIS_auto_power_on_test{
# MoDIS auto power on test
#$ENV{"MoDIS"} = 'AutoPower';

chomp(my $cwd = `cd`);
my $is_in_lsf = ($ENV{"atMoDIS_LSF_remote"})?1:0;

$ENV{"MoDIS"} = 'AutoPower' if ($action eq "ap_modis");

if ((-e "MoDIS\\${modisDir}\\MoDIS.exe") && ($ENV{"MoDIS"} eq 'AutoPower')) {
   $MoDIS_poweron_result = 0;
   $WIN32FS = "$cwd\\WIN32FS";
    
    # Backup/Recover WIN32FS
    if (-e "${WIN32FS}_BAK") {
      # Recover file system
      print ("\nrobocopy ${WIN32FS}_BAK $WIN32FS /MIR /R:3 /W:3 /LOG:robo_win32fs.log");
      system("robocopy ${WIN32FS}_BAK $WIN32FS /MIR /R:3 /W:3 /LOG:robo_win32fs.log");
    } else {
      # Backup file system
      print ("\nrobocopy $WIN32FS ${WIN32FS}_BAK /MIR /LOG:robo_win32fs.log");
      system("robocopy $WIN32FS ${WIN32FS}_BAK /MIR /LOG:robo_win32fs.log");
    }
    
    if (-e "_BUILD_LOG\\_PowerOn.log") {
     unlink("_BUILD_LOG\\_PowerOn.log");
    }
   
    print "\n";
    system("perl ../tools/time.pl");
    print("MoDIS Auto PowerOn Test\n");
    chdir("MoDIS\\$modisDir");
    chomp($cwd = `cd`);
    if ($is_in_lsf) {
      system("call start MoDIS.exe");
    } else {
      Win32::Process::Create( $MoDIS_Process,
                               "$cwd\\MoDIS.exe",
                               "MoDIS.exe",
                               0,
                               CREATE_NEW_CONSOLE,
                               $cwd) || assert(Win32::FormatMessage( Win32::GetLastError() ));
    }
    chdir("..\\..\\");

    sleep 60;
    
    if (-e "_BUILD_LOG\\_PowerOn.log") {
      open MoDIS_AutoPower, "<_BUILD_LOG\\_PowerOn.log" or assert("\ncannot open mcu\\MoDIS\\_BUILD_LOG\\_PowerOn.log\n\n");
      $backup = $/;
      undef $/;
      $MoDIS_AutoPower_Result = <MoDIS_AutoPower>;
      $/ = $backup;
      close MoDIS_AutoPower;
   
      if ($MoDIS_AutoPower_Result =~ /(Auto Power ON Success)/i) {
        $MoDIS_poweron_result = 1;
        print("      ==> [P]\n\n");
      }
    }

    unless ($MoDIS_poweron_result) {
      if ($is_in_lsf) {
        # MoDIS auto poweron fail, kill its process
        $objWMI = Win32::OLE->GetObject('winmgmts:\\\\.\\root\\cimv2');
        $colProcesses = $objWMI->InstancesOf('Win32_Process');
        foreach my $objProcess (in $colProcesses) {
            if ($objProcess->Name =~ /^(modis.exe)$/i) {
                $objName = $objProcess->Name;
                $objPID = $objProcess->ProcessID;
                $objWMIProcess = Win32::OLE->GetObject('winmgmts:\\\\.\\root\\cimv2:Win32_Process.Handle=\'' . $objPID . '\'');
                if ($intRC = $objWMIProcess->Terminate()) {
                    print "Could not kill process \"$objName\" (PID=$objPID). Error code: " . $intRC, "\n";
                }
            }
        }
      } else {
       $MoDIS_Process->Kill(STILL_ACTIVE);
      }
      print("      ==> [F]\n\n");
    }

}
# end of MoDIS auto power on test
}

sub at_MoDIS {

unless ((-e "..\\mtk_tools\\Perl") && ($] >= 5.008006)){
   assert("Perl package doesn't exist or Perl version is less then 5.008006. Your Perl version is $]\n");
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值