blob: e2d302b82199ad1be38bbe7a12922541f7a56416 [file] [log] [blame]
yu.dongc33b3072024-08-21 23:14:49 -07001#!/usr/bin/env perl
2#
3# Copyright Statement:
4# --------------------
5# This software is protected by Copyright and the information contained
6# herein is confidential. The software may not be copied and the information
7# contained herein may not be used or disclosed except with the written
8# permission of MediaTek Inc. (C) 2005
9#
10# BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
11# THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
12# RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
13# AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
14# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
15# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
16# NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
17# SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
18# SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
19# THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
20# NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
21# SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
22#
23# BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
24# LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
25# AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
26# OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
27# MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
28#
29# THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
30# WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
31# LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
32# RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
33# THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
34#
35BEGIN {
36 push @INC, '.';
37}
38$ENV{'PERL_USE_UNSAFE_INC'} = 1;
39# let Python NOT try to write .pyc files.
40$ENV{'PYTHONDONTWRITEBYTECODE'} = 1;
41
42require v5.8.6;
43BEGIN { push @INC, './'};
44use Cwd;
45use File::Copy;
46use File::Path;
47use File::Basename;
48use if ($^O eq "MSWin32"), Win32API::Registry => qw(:ALL);
49
50if ($^O ne "MSWin32") {
51 $ENV{"NUMBER_OF_PROCESSORS"} = `cat /proc/cpuinfo | grep 'processor' | wc -l | tr -d '\n'`;
52}
53
54# for mbis start stamp
55# get submit to queue epoch time
56my $submit_to_queue_time_string = "";
57if ($ENV{'SUBMIT_TO_QUEUE_GMT_TIMESTAMP'})
58{
59 my ($sec, $min, $hour, $mday, $mon, $year) = gmtime($ENV{'SUBMIT_TO_QUEUE_GMT_TIMESTAMP'}+28800);
60 $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);
61}
62
63# get epoch timestamp
64$build_time_sec = time;
65
66# convert to GMT+8 time
67($sec, $min, $hour, $mday, $mon, $year) = gmtime($build_time_sec+28800);
68$build_time_string = sprintf("%4.4d.%2.2d.%2.2d.%2.2d.%2.2d.%2.2d", $year+1900, $mon+1, $mday, $hour, $min, $sec);
69
70$core_root = "pcore";
71$plat = "";
72@arguments = ();
73$project = "";
74$action = "";
75$m_in_lsf = 0;
76$local_q = 0;
77@mOpts = ();
78$fullOpts = "";
79$level = "";
80$relDir = "";
81$ini = "build/make.ini";
82$myMF = "build.mak";
83$enINI = 1;
84($#ARGV < 0) && &Usage;
85(($#ARGV < 1) && ($enINI == 0)) && &Usage;
86
87my $newMoDIS = 0;
88my $bypassMoDIS = 0;
89my $atMoDIS = 0;
90my $newUESim = 0;
91my $pureMoDIS = 0;
92my $packMoDIS = 0;
93my $chk_cmd = 0;
94my $parallel_module_build = "NONE";
95
96my $concatenate_proj_mak = "";
97my $modisDir = "";
98my $target_option = "";
99
100$eutran_mode_support = "";
101$dummyvm = 0;
102
103#mbis default enable
104$mbis = "tools/mbis.pl";
105$arg_mbis_en = "FALSE";
106$arg_mbis_en_obj_log = "FALSE";
107$arg_mbis_en_save_log = "FALSE";
108$mbis_arg_exist = 0;
109$mbis_en = "FALSE";
110$mbis_en_obj_log = "FALSE";
111$mbis_en_save_log = "FALSE";
112@mbis_arg = ();
113if ($^O eq "MSWin32") {
114 if ($ENV{'LTE_DOMAIN'} eq "TRUE") {
115 $mbis_conf_file = "\\\\mtklwafs01\\moly\\wcpsm\\config\\mbis_conf.ini";
116 }
117 else {
118 $mbis_conf_file = "\\\\glbfs14\\sw_releases\\mbis\\scripts\\MBIS_conf.ini";
119 }
120}
121$mbis_conf_file = "/mtkeda/wcpsm/mbis/config/mbis_conf.ini" if($^O eq "linux");
122@orgARGVwithFlavor = ();
123$mbis_num_proc = 0;
124$mbis_target_build_with_Modis = 0;
125@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);
126@orgARGV = @ARGV;
127@orgARGVwithFlavor = @orgARGV;
128$flavor = "DEFAULT";
129$localq_disk = "z:";
130$makeFolder = "make/common/";
131$projMakeFolder = "make/projects/";
132$OSversion = $^O;
133
134if ($^O eq "MSWin32") {
135 $makeCmd = "tools/make.exe";
136} else {
137 $makeCmd = "make";
138}
139
140if ($ENV{'MTK_INTERNAL'} eq 'TRUE') {
141 # MTK_INTERNAL is a internal environment flag
142} elsif (($ENV{'USERDOMAIN'} =~ /MTK|PMT|MBJ|MSZ|MTI|WISE|MEDIATEK|MWS|GCN|APJ/i) && ($ENV{'USERDNSDOMAIN'} =~ /MEDIATEK\.INC/i)) {
143 warn "Current user is from MTK internal, but the environment MTK_INTERNAL != TRUE\nPlease check ! Build script will continue after 30 sec.\n";
144 sleep 30;
145 $ENV{'MTK_INTERNAL'} = 'TRUE';
146}
147
148if (($ENV{'MTK_INTERNAL'} eq 'TRUE') && (-e "mtk_tools/Internal_function.pm")) {
149 require mtk_tools::Internal_function;
150}
151
152$no_pcibt = "FALSE";
153$no_ltelib = "FALSE";
154$no_ltecgen = "FALSE";
155$no_dsp = "FALSE";
156$update_dsp = "FALSE";
157$deterministic = "FALSE";
158$no_warning_as_error = "FALSE";
159$VarioationProj_name = "";
160$force_getlte = "FALSE";
161$ota_name = "DEFAULT";
162$tareget_options = "";
163$ccache_dir = "";
164$ccache_size = "";
165$ccache_basedir = "";
166$chk_rel_pkg = "";
167$check_fo_license = "FALSE";
168$license_info = "DEFAULT";
169$cust_lic = "DEFAULT";
170$smart = 0;
171
172if(($ENV{'REDIRECT_OUT_DIR'} eq 'TRUE') && (defined $ENV{'OUT_DIR'})) {
173 print "ENV REDIRECT_OUT_DIR = $ENV{'REDIRECT_OUT_DIR'}\n";
174 print "OUT_DIR = $ENV{'OUT_DIR'}\n";
175 print "Trigger CF TO LOCAL success\n";
176 print "Prepare to create OUT folder and link...\n";
177 system("mkdir -p $ENV{'OUT_DIR'}/build") if (!-d "$ENV{'OUT_DIR'}/build");
178 system("mkdir -p $ENV{'OUT_DIR'}/build_internal") if (!-d "$ENV{'OUT_DIR'}/build_internal");
179 system("ln -sf $ENV{'OUT_DIR'}/build build");
180 system("ln -sf $ENV{'OUT_DIR'}/build_internal build_internal");
181 print "Prepare to create OUT folder and link...Done\n";
182}
183
184while ($#ARGV != -1) {
185 if ($ARGV[0] =~ /-bullseye$/i) {
186 $target_option .= " BULLSEYE_CONFIG=TRUE ";
187 $ENV{'COVBUILDZONE'}="$$";
188 } elsif ($ARGV[0] =~ /-bullseye=(.*)/i) {
189 $target_option .= " BULLSEYE_CONFIG=TRUE BULLSEYE_COVFILE=\"$1\" ";
190 } elsif ($ARGV[0] =~ /-clang7$/i) {
191 $target_option .= " CLANG_VER=7.0.0 ";
192 } elsif ($ARGV[0] =~ /-llvm-coverage$/i) {
193 $target_option .= " LLVM_COVERAGE=TRUE ";
194 } elsif ($ARGV[0] =~ /-modis/i) {
195 $newMoDIS = 1;
196 } elsif ($ARGV[0] =~ /-forcemodis/i) {
197 $bypassMoDIS = -1;
198 } elsif ($ARGV[0] =~ /-puremodis/i) {
199 $pureMoDIS = 1;
200 } elsif ($ARGV[0] =~ /-no_puremodis/i) {
201 $pureMoDIS = -1;
202 } elsif ($ARGV[0] =~ /-packmodis/i) {
203 $packMoDIS = 1;
204 } elsif ($ARGV[0] =~ /-no_packmodis/i) {
205 $packMoDIS = -1;
206 } elsif ($ARGV[0] =~ /-uesim/i) {
207 $newUESim = 1;
208 } elsif ($ARGV[0] =~ /-release/i) {
209 $modisDir = "Release";
210 } elsif ($ARGV[0] =~ /-debug/i) {
211 $modisDir = "Debug";
212 } elsif ($ARGV[0] =~ /-h/i) {
213 &Usage;
214 } elsif ($ARGV[0] =~ /^-(o|op|opt)=(.*)$/i) {
215 $fullOpts = $2;
216 $fullOpts =~ s/,/ /g;
217 } elsif ($ARGV[0] =~ /-lsf/i) {
218 $m_in_lsf = 1;
219 } elsif ($ARGV[0] =~ /-no_lsf/i) {
220 $not_enter_lsf = 1;
221 } elsif ($ARGV[0] =~ /-localq/i) {
222 $local_q = 1;
223 } elsif ($ARGV[0] =~ /-localpath/i) {
224 $local_p = 1;
225 } elsif ($ARGV[0] =~ /-disable_autotcm/i) {
226 $disable_autotcm = "TRUE";
227 } elsif ($ARGV[0] =~ /-klocwork/i) {
228 $RUN_KLOCWORK = 1;
229 } elsif ($ARGV[0] =~ /-disk=(.*)/i) {
230 $localq_disk = $1;
231 } elsif ($ARGV[0] =~ /^-mbis=(.*)$/i) {
232 # mbis get argument
233 @mbis_arg = split(",", $1);
234 &mbis_parse_arg;
235 } elsif ($ARGV[0] =~ /-no_cgen/i) {
236 $target_option .= " REMAKE_WITH_CGEN=FALSE ";
237 } elsif ($ARGV[0] =~ /(-parallel|-pll)/i) {
238 if ($^O ne "MSWin32") {
239 $parallel_module_build="TRUE";
240 $target_option .= " PARALLEL=$parallel_module_build";
241 }
242 } elsif ($ARGV[0] =~ /(-no_parallel|-no_pll)/i) {
243 if ($^O ne "MSWin32") {
244 $parallel_module_build="FALSE";
245 $target_option .= " PARALLEL=$parallel_module_build";
246 }
247 } elsif ($ARGV[0] =~ /-dbld/i) {
248 #Add for daily build
249 $daily_build = 1;
250 } elsif ($ARGV[0] =~ /(-no_pcibt|-no_pc)\b/i) {
251 $no_pcibt = "TRUE";
252 } elsif ($ARGV[0] =~ /(-all_pcibt|-all_pc)\b/i) {
253 $all_pcibt = "TRUE";
254 } elsif ($ARGV[0] =~ /(-no_dsp)\b/i) {
255 $no_dsp = "TRUE";
256 } elsif ($ARGV[0] =~ /(-no_w)\b/i) {
257 $no_warning_as_error = "TRUE";
258 } elsif ($ARGV[0] =~ /(-ota_name)=(.*)$/i) {
259 $ota_name = $2;
260 } elsif ($ARGV[0] =~ /-no_ltelib/i) {
261 $no_ltelib = "TRUE";
262 $no_ltecgen = "TRUE";
263 } elsif($ARGV[0] =~ /^-test=(.*)$/i){
264 $VarioationProj_name = $1;
265 $VarioationProj_fullPath = "make/common/variation/${VarioationProj_name}.mak";
266 &cktheMF($VarioationProj_fullPath);
267 } elsif($ARGV[0] =~ /^-rel=(.*)$/i){
268 $chk_rel_pkg = $1;
269 } elsif ($ARGV[0] =~ /-force_getlte/i) {
270 $force_getlte = "TRUE";
271 } elsif ($ARGV[0] =~ /-smart/i) {
272 $smart = 1;
273 #$target_options .= " SMART_CHECK=TRUE ";
274 } elsif ($ARGV[0] =~ /(-checkFO_license)=(.*)$/i) {
275 $check_fo_license = "TRUE";
276 $license_info = $2;
277 } elsif ($ARGV[0] =~ /(-cust_lic)=(.*)$/i) {
278 $cust_lic = $2;
279 } elsif($ARGV[0] =~ /(-ccache_dir|-c_dir)=(.*)$/i){
280 $ccache_dir = $2;
281 mkpath($ccache_dir) or die "[make.pl][Error:] Can Not create $ccache_dir! $!" if(!-d "$ccache_dir");
282 $target_options .= " CCACHE_DIR=$ccache_dir";
283 } elsif($ARGV[0] =~ /(-ccache_size|-c_size)=(.*)$/i){
284 $ccache_size = $2;
285 $target_options .= " CCACHE_SIZE=$ccache_size";
286 } elsif($ARGV[0] =~ /(-ccache_basedir|-c_bd)=(.*)$/i){
287 $ccache_basedir = $2;
288 $target_options .= " CCACHE_BASEDIR=$ccache_basedir";
289 } elsif ($ARGV[0] =~ /^-no_dep$/i) {
290 $target_option .= " NO_DEP=TRUE";
291 } elsif ($ARGV[0] =~ /^-deterministic$/i) {
292 $determinism = "TRUE";
293 $target_option .= " DETERMINISTIC=TRUE";
294 }
295 else {
296 if($ARGV[0] =~ /(.+)\.mak/i) {
297 $project_makefile = $1;
298 if ($^O ne "MSWin32") {
299 if ($project_makefile =~ /^make\/projects\/(\S+)/) {
300 $project_makefile = $1;
301 }
302 }
303 writeMakeINI();
304 shift(@ARGV);
305 }
306 if (($project_makefile eq "") && ($enINI == 1) && (-e $ini)) {
307 open (FILE_HANDLE, "<$ini") or die "cannot open $ini\n";
308 while (<FILE_HANDLE>) {
309 if (/^(\S+)\s*=\s*(\S+)/) {
310 $keyname = $1;
311 $${keyname} = $2;
312 }
313 }
314 print "project_makefile=$project_makefile\n";
315 close FILE_HANDLE;
316 }
317
318 if($project_makefile =~ /\W/) {
319 ($project_name,$flavor) = split (/\W/, $project_makefile);
320 }
321 else {
322 $project_name = $project_makefile;
323 }
324 print "project_name = $project_name\n";
325 print "flavor = $flavor\n";
326 ($project_makefile eq "") && (die "Unrecognized \"$ARGV[0]\" or \"$ARGV[1]\"\nOr try $myCmd -h\n");
327
328 if ($#ARGV != -1) {
329 if ($ARGV[0] =~ /^[ucrUCR]$/) {
330 ($action = "clean") if ($ARGV[0] =~ /^[cC]$/);
331 ($action = "update") if ($ARGV[0] =~ /^[uU]$/);
332 ($action = "remake") if ($ARGV[0] =~ /^[rR]$/);
333 shift(@ARGV);
334 @arguments = @ARGV;
335 @ARGV = ();
336 last;
337 } else {
338 if ($ENV{'MTK_INTERNAL'} eq 'TRUE') {
339 unshift(@actions, "bm_new", "bm_remake", "bm_update", "find", "ckmake");
340 unshift(@actions, "cmmgen");
341 unshift(@actions, "cfggen","ckmemlayout2");
342 }
343 if ((-d "MoDIS_VC9/MoDIS_lib") || (-d "mtk_rel/${original_project_name}/${original_flavor}/MODIS/MoDIS_lib")) {
344 unshift(@actions, "new_modis", "sys_mem_gen_modis", "new_uesim", "sys_mem_gen_uesim");
345 unshift(@actions, "gen_modis", "gen_uesim") if (-e "MoDIS_VC9/createMoDIS.pl");
346 unshift(@actions, "codegen_modis", "clean_codegen_modis", "umts_gen_modis", "codegen_uesim", "clean_codegen_uesim", "umts_gen_uesim", "distclean_modis", "distclean_uesim");
347 unshift(@actions, "remake_modis", "clean_modis", "update_modis", "remake_uesim", "clean_uesim", "update_uesim");
348 unshift(@actions, "c,r_modis", "c,u_modis", "c,r_uesim", "c,u_uesim");
349 unshift(@actions, "scan_modis");
350 if ($^O eq "MSWin32") {
351 unshift(@actions, "ap_modis", "ap_uesim");
352 }
353 }
354 foreach $act (@actions) {
355 if (lc($ARGV[0]) eq $act) {
356 $action = $act;
357 if (($act eq "bm_update") || ($act eq "bm_remake")) {
358 ($action = "update") if ($act eq "bm_update");
359 ($action = "remake") if ($act eq "bm_remake");
360 if ( $fullOpts !~ /-k/) {
361 ($fullOpts eq "") ? ($fullOpts = "-k") : ($fullOpts .= " -k");
362 }
363 }
364 shift(@ARGV);
365 @arguments = @ARGV;
366 @ARGV = ();
367 last;
368 }
369 }
370 }
371 }
372 ($action eq "") && (die "Unrecognized \"$ARGV[0]\"\nLack off one of (@actions)\nOr try $myCmd -h\n");
373 ($#ARGV != -1) && (die "Unrecognized \"@ARGV\"\nPlease check again or try $myCmd -h\n");
374 last;
375 }
376 shift(@ARGV);
377}
378(!-d "make")&&(die "Folder \"make\" does NOT exist!\nPlease help to check.\n");
379if(($ENV{'REDIRECT_OUT_DIR'} eq 'TRUE') && (defined $ENV{'OUT_DIR'})) {
380 $hostname = `hostname`;
381 system("perl -e \"print \'COMPUTERNAME=$hostname\';\" > \"${project_makefile}_cf.log\"");
382}
383
384
385$ENV{"PCIBT_NO_STOP"} = "TRUE" if ($action =~ /^(bm_new|bm_update|bm_remake)$/i);
386$ENV{"CHK_RELPKG_ALL"} = "TRUE" if ($all_pcibt eq "TRUE");
387$ENV{"DISABLE_AUTOTCM"} = "TRUE" if ($disable_autotcm eq "TRUE");
388$update_dsp = "TRUE" if ($action =~ /update_dsp/);
389
390my $check_obj_file = "";
391my $obj_path;
392if ($action !~ /_(modis|uesim)$/i) {
393 $obj_path = "./build/${project_name}/$flavor/bin/obj";
394} else {
395 if ($action =~ /_(modis)$/i){
396 $obj_path = "./build/${project_name}/$flavor/MoDIS";
397 } elsif ($action =~ /_(uesim)$/i){
398 $obj_path = "./build/${project_name}/$flavor/UESim";
399 }
400}
401if($^O eq "linux"){
402 $check_obj_file = `find $obj_path -type f -name \"*.obj\"` if (-d "$obj_path");
403}
404
405if ($smart){
406 if ($check_obj_file eq "") {
407 print "Cannot find any object file under \"$obj_path\", start clean_new!\n";
408 $smart = 0;
409 } else {
410 print "Can find object files under \"$obj_path\", start smart_new!\n";
411 $target_options .= " SMART_CHECK=TRUE ";
412 }
413}
414
415if (($action !~ /_(modis|uesim)$/i) && ($action =~ /new|c,r|remake/i) && ($^O eq "MSWin32")) {
416 print "[Error:] Target build on Windows is not avaliable, please use the linux server to build Target!!\n";
417 exit 1;
418}
419
420if (($action =~ /^(new|rel)_(modis|uesim)$/i) || (($action =~ /^(bm_)?new$/i) && ($newMoDIS || $newUESim))) {
421 if ($pureMoDIS == 0) {
422 print "Auto turn on -puremodis when make $action\n";
423 $pureMoDIS = 1;
424 }
425 if ($^O ne "MSWin32") {
426 if($parallel_module_build eq "NONE") {
427 print "Auto turn on build modules in parallel (-pll) on Linux.\n";
428 $parallel_module_build = "TRUE";
429 $target_option .= " PARALLEL=$parallel_module_build";
430 }
431 }
432}
433
434# turn on building modules in parallel
435if (($action eq "new" || $action eq "bm_new") && (-e "make/common/parallel.mak")) {
436 if($parallel_module_build eq "NONE") {
437 print "Auto turn on build modules in parallel (-pll) on Linux.\n";
438 $parallel_module_build = "TRUE";
439 $target_option .= " PARALLEL=$parallel_module_build";
440 }
441}
442
443if ((-e "mtk_tools/Perl") && ($] >= 5.008006)) {
444 use lib "mtk_tools/Perl";
445 use Net::SMTP;
446}
447
448if (($local_q == 1) && ($local_p != 1)) {
449 chomp(my $cwd = cwd());
450 $cwd =~ s/\//\\/g;
451 system("subst $localq_disk $cwd");
452 chdir("$localq_disk");
453 print "cwd = $cwd\n";
454}
455
456chomp($cwd = getcwd());
457if ($cwd =~ /\s+/) {
458 $arrow = $cwd;
459 $arrow =~ s/\s/\^/g;
460 $arrow =~ s/[^\^]/ /g;
461 print "\n$cwd\n";
462 print "$arrow\n";
463 print "Space is not a legal character for a folder name.\nPlease check it !!\n";
464 exit 1;
465}
466
467sub cktheMF {
468 $the_makefile = $_[0];
469 (!-e $the_makefile) && (die "$the_makefile does NOT exist!\nPlease help to check.\n");
470 open (FILE_HANDLE, "<$the_makefile") or die "Cannot open $the_makefile. Please check if the file is READ-ONLY or not exists.\n";
471 while (<FILE_HANDLE>) {
472 if (/^(\w+)\b\s*=\s*(\S+)/) {
473 $keyname = lc($1);
474 $${keyname} = $2;
475 }
476 }
477 close FILE_HANDLE;
478 return 0;
479}
480
481# read the feature option from variation load makefile (ex: flavor)
482if ($VarioationProj_name ne "") {
483 &cktheMF($VarioationProj_fullPath);
484}
485
486my $projectFolder = "build/${project_name}/$flavor";
487
488if ($chk_cmd == 1) {
489 print "\n$projectFolder\n";
490 exit 0;
491}
492
493$original_projectFolder = $projectFolder;
494writeMakeINI();
495$tmpFolder = "$projectFolder/tmp";
496if ($action =~ /_(modis|uesim)$/i) {
497 if ((-d "$projectFolder/MoDIS") && ($action =~ /new_modis/i) && ($m_in_lsf != 1) && (!$smart)) {
498 rmtree("$projectFolder/MoDIS");
499 }
500 if ((-d "$projectFolder/UESim") && ($action =~ /new_uesim/i) && ($m_in_lsf != 1) && (!$smart)) {
501 rmtree("$projectFolder/UESim");
502 }
503 ($projectFolder, $tmpFolder) = &MoDIS_xgen_check($action);
504}
505
506if (($action eq "new" || $action eq "bm_new" ) && (!$smart)) {
507 if (-d "$projectFolder") {
508 opendir(DIR, $projectFolder) or die "Couldn't open directory, $!";
509 while ($file = readdir DIR) {
510 if ($file ne "." && $file ne ".." && $file ne "MoDIS" && $file ne "UESim") {
511 print "Clean folder : $projectFolder/$file \n";
512 rmtree("$projectFolder/$file");
513 }
514 }
515 closedir DIR;
516 }
517
518 my $buildInternalFolder = "build_internal/${project_name}/$flavor";
519 if (-d "$buildInternalFolder") {
520 opendir(DIR, $buildInternalFolder) or die "Couldn't open directory, $!";
521 while ($file = readdir DIR) {
522 if ($file ne "." && $file ne ".." && $file ne "MoDIS" && $file ne "UESim") {
523 print "Clean folder : $buildInternalFolder/$file \n";
524 rmtree("$buildInternalFolder/$file");
525 }
526 }
527 closedir DIR;
528 }
529}
530
531my @sm_logs=glob("$projectFolder/bin/log/smart_log* $projectFolder/UESim/_BUILD_XGEN/bin/log/smart_log* $projectFolder/MoDIS/_BUILD_XGEN/bin/log/smart_log*");
532unlink @sm_logs or die "Error: Cannot remove smart log files, please check!\n" if(@sm_logs);
533
534$tk_md_cus = "";
535$plat = "NONE";
536$targetFolder = "$projectFolder/bin";
537$logFolder = "$targetFolder/log";
538$enFile = "${makeFolder}${project_name}_en.def";
539$disFile = "${makeFolder}${project_name}_dis.def";
540$theVerno = "make/common/Verno.bld";
541$toolsFolder = "tools/";
542$MTKtoolsFolder = "mtk_tools/";
543$ori_prj_make_full_path = "${projMakeFolder}${project_makefile}.mak";
544$theMF = $ori_prj_make_full_path;
545&cktheMF($theMF);
546if(defined $modem_spec && $modem_spec ne "NONE") {
547 $theMF_modem = "make/common/modem_spec/${modem_spec}.mak";
548 &cktheMF($theMF_modem);
549}
550
551my $tk_md_cus_full_path;
552if (($tk_md_cus ne "") && ($tk_md_cus ne "NONE")) {
553 $tk_md_cus_full_path = "make/projects/tk_md_cus/${tk_md_cus}.mak";
554 if (-e "$tk_md_cus_full_path") {
555 &cktheMF($tk_md_cus_full_path);
556 } else {
557 print ("Error: TK_MD_CUS \"$tk_md_cus_full_path\" file does not exist in codebase, please check!\n");
558 exit 1;
559 }
560}
561
562if ($eutran_mode_support eq "NONE") {
563 $no_ltelib = "TRUE";
564 $no_ltecgen = "TRUE";
565}
566
567my $action_flag = "TARGET";
568$action_flag = "UESIM" if ($action =~ /_(uesim)$/i);
569$action_flag = "MODIS" if ($action =~ /_(modis)$/i);
570
571if (($force_getlte eq "TRUE") && (-e "mtk_rel/$project_name/$flavor/$action_flag/label.ini.LTE")) {
572 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 $!";
573 print "Remove mtk_rel/$project_name/$flavor/$action_flag/label.ini.LTE successful\n";
574}
575
576if ((-e "label.ini") && (!-d "make/common/rel/mpd/5g") && ($no_ltelib eq "FALSE") && ($no_ltecgen eq "FALSE") && ($flavor!~ /BASIC/i) &&
577 (($action =~ /getusr/i) || ($action =~ /new/i) || ($action =~ /update/i) || ($action =~ /remake/i) || ($action =~ /codegen/i) || ($action =~ /c,u/i) || ($action =~/c,r/i))) {
578 if (-e "mtk_tools/USR/LTEUSR_Initial.pl") {
579 $result = system("perl mtk_tools/USR/LTEUSR_Initial.pl $project_name $flavor $action_flag $smart");
580 exit 1 if ($result);
581 } else {
582 die "[Error:] mtk_tools/USR/LTEUSR_Initial.pl is not exist!!\n";
583 }
584 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"));
585 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"));
586 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"));
587}
588
589if ((-e "label.ini") && ($no_dsp eq "FALSE") && ($^O ne "MSWin32") && ($action !~ /_(modis|uesim)$/) &&
590 (($action =~ /getusr/i) || ($action =~ /new/i) || ($action =~ /update/i) || ($action =~ /remake/i) || ($action =~ /codegen/i) || ($action =~ /c,u/i) || ($action =~/c,r/i))){
591 if (-e "mtk_tools/USR/DSPUSR_Initial.pl") {
592 $result = system("perl mtk_tools/USR/DSPUSR_Initial.pl $project_name $flavor $dsp_project $dsp_flavor");
593 exit 1 if ($result);
594 } else {
595 die "[Error:] mtk_tools/USR/DSPUSR_Initial.pl is not exist!!\n";
596 }
597 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"));
598}
599
600# to prevent redundant dsp_package.log
601if ($no_dsp eq "TRUE") {
602 system ("rm -f $projectFolder/bin/log/dsp_package.log") if (-e "$projectFolder/bin/log/dsp_package.log");
603}
604
605if ((-e "label.ini") && (!-e "make/common/rel/hq/USR.txt")&&
606 (($action =~ /getusr/i) || ($action =~ /new/i) || ($action =~ /update/i) || ($action =~ /remake/i) || ($action =~ /codegen/i) || ($action =~ /c,u/i) || ($action =~/c,r/i))){
607 if (-e "mtk_tools/USR/CBrUSR_Initial.pl") {
608 $result = system("perl mtk_tools/USR/CBrUSR_Initial.pl $project_name $flavor $original_flavor $action_flag $smart");
609 exit 1 if ($result);
610 } else {
611 die "[Error:] mtk_tools/USR/CBrUSR_Initial.pl is not exist!!\n";
612 }
613 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"));
614 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"));
615 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"));
616}
617
618if ((-e "label.ini") && (-e "make/common/rel/hq/USR.txt")&& (!-d "make/common/rel/mpd")&&
619 (($action =~ /getusr/i) || ($action =~ /new/i) || ($action =~ /update/i) || ($action =~ /remake/i) || ($action =~ /codegen/i) || ($action =~ /c,u/i) || ($action =~/c,r/i))){
620 if (-e "mtk_tools/USR/SwUSR_Initial.pl") {
621 $result = system("perl mtk_tools/USR/SwUSR_Initial.pl $project_name $flavor $action_flag $smart");
622 exit 1 if ($result);
623 } else {
624 die "[Error:] mtk_tools/USR/CBrUSR_Initial.pl is not exist!!\n";
625 }
626 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"));
627 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"));
628 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"));
629}
630
631my @delTempFile = glob("$tmpFolder/*.*");
632#unlink(@delTempFile) or die "[make.pl][Error:] Remove failed @delTempFile $!" if(@delTempFile); #mark for smart new
633unlink("$tmpFolder/~buildinfo.tmp") or die "[make.pl][Error:] Remove failed $tmpFolder/~buildinfo.tmp $!" if(-e "$tmpFolder/~buildinfo.tmp");
634unlink("$tmpFolder/~remakemod.tmp") or die "[make.pl][Error:] Remove failed $tmpFolder/~remakemod.tmp $!" if(-e "$tmpFolder/~remakemod.tmp");
635unlink("$tmpFolder/~cleanmod.tmp") or die "[make.pl][Error:] Remove failed $tmpFolder/~cleanmod.tmp $!" if(-e "$tmpFolder/~cleanmod.tmp");
636unlink("$tmpFolder/~updatemod.tmp") or die "[make.pl][Error:] Remove failed $tmpFolder/~updatemod.tmp $!" if(-e "$tmpFolder/~updatemod.tmp");
637unlink("$tmpFolder/~scanmod.tmp") or die "[make.pl][Error:] Remove failed $tmpFolder/~scanmod.tmp $!" if(-e "$tmpFolder/~scanmod.tmp");
638mkpath($tmpFolder) or die "[make.pl][Error:] Can Not create $tmpFolder! $!" if(!-d "$tmpFolder");
639mkpath($logFolder) or die "[make.pl][Error:] Can Not create $logFolder! $!" if(!-d "$logFolder");
640mkpath($targetFolder) or die "[make.pl][Error:] Can Not create $targetFolder! $!" if(!-d "$targetFolder");
641
642if(-e "make/common/rel/hq/USR.txt")
643{
644 my $rel_err_msg = "";
645 my $output_file = "$targetFolder/all_mod_rel.mak";
646 unlink $output_file or die "[make.pl][Error:] Remove failed $output_file" if(-e $output_file);
647 $rel_err_msg .= `perl ./mtk_tools/USR/genModuleRel.pl REL_CR $output_file`;
648 $rel_err_msg .= `perl ./mtk_tools/USR/genModuleRel.pl REL_SUB $output_file`;
649
650 #Check if module's MPD/Custom rel definition is duplicate
651 if (($rel_err_msg ne "") && ($no_pcibt ne "TRUE"))
652 {
653 print "$rel_err_msg";
654 print "Please refer http://wiki/display/MOLY/How+to+add+a+new+module for rel setting.\n";
655 exit 1;
656 }
657}
658# generate custom.bld
659&genCustombld();
660
661# smybol link to central tool chain if it's in MTK_INTERNAL
662my $central_compiler_path = "/mtkoss/imgtec/gcc-mips-mti-elf.2016.05-08/4.9.2/linux";
663my $compiler_path = "./tools/GCC/MIPS/4.9.2";
664
665if ($compiler_ver eq "MIPS_GCCV6"){
666 $central_compiler_path = "/mtkoss/imgtec/gcc-mips-mti-elf.2017.10-08/6.3.0/linux";
667 $compiler_path = "./tools/GCC/MIPS/6.3.0";
668 if ($compiler_isa eq "NANOMIPS"){
669 $central_compiler_path = "/mtkoss/imgtec/gcc-nanomips-elf.2019.03-06/6.3.0/linux";
670 $compiler_path = "./tools/GCC/NANOMIPS/6.3.0";
671 }
672} elsif ($compiler_ver eq "MIPS_GCCV4"){
673 $central_compiler_path = "/mtkoss/imgtec/gcc-mips-mti-elf.2016.05-08/4.9.2/linux";
674 $compiler_path = "./tools/GCC/MIPS/4.9.2";
675}
676
677if(-l "$compiler_path/linux") {
678 $exist_symlink_path = readlink("$compiler_path/linux");
679 if($exist_symlink_path ne "$central_compiler_path") {
680 system("rm -f $compiler_path/linux");
681 }
682}
683
684if(!-l "$compiler_path/linux" && !-d "$compiler_path/linux" && -d "$central_compiler_path") {
685 mkpath("$compiler_path") if(!-d "$compiler_path");
686 system("ln -s $central_compiler_path $compiler_path");
687}
688
689if ($action =~ /_(modis|uesim)$/ && !-d "$projectFolder/vs2017_header" && $^O eq "linux") {
690 print "Create vs2017 symbolic link ...\n";
691 system("./mtk_tools/vs2017/gen_symbolic.sh $projectFolder/vs2017_header 2>/dev/null");
692}
693
694# concatenate the project makefiles and the result is placed on build/$project/$flavorn/bin.
695# In here, the gen_concatenate_proj target does NOT do PCIBT.
696$concatenate_proj_mak = "${targetFolder}/~${project_makefile}.mak";
697my $gen_concate_option = "";
698my $modis_config = "FALSE";
699$gen_concate_option = $target_option;
700if ($action =~ /_(modis|uesim)$/i) {
701 $gen_concate_option .= " MODIS_CONFIG=TRUE";
702 $modis_config = "TRUE";
703}
704$gen_concate_option .= " NO_PCIBT=TRUE";
705
706#backup log files for smart build
707if (($smart) && ($^O ne "MSWin32")) {
708 my $backup_logFolder = "${logFolder}_bak";
709 my $move_log_file = "$backup_logFolder/log_move.log";
710 mkdir("$backup_logFolder") if (!-d "$backup_logFolder");
711 system("rm -f $move_log_file") if (-e "$move_log_file");
712 opendir(DIR, $logFolder) or die "Couldn't open directory, $!";
713 while ($file = readdir DIR) {
714 if ($file ne "." && $file ne ".." ) {
715 system("echo Move log files from $logFolder to $backup_logFolder: $file >> $move_log_file");
716 #print "Move log files from $logFolder to $backup_logFolder: $file\n";
717 if (-d "$logFolder/$file") {
718 system ("cp -pr $logFolder/$file $backup_logFolder");
719 system ("rm -rf $logFolder/$file");
720 } else {
721 if ($file =~ /info(.*)\.log/) {
722 system ("cp -p $logFolder/$file $backup_logFolder");
723 } else {
724 system ("mv $logFolder/$file $backup_logFolder");
725 }
726 }
727 }
728 }
729 closedir DIR;
730}
731
732my $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");
733die "Error: concatenate project makefiles failed." if(($return_code >> 8) ne 0);
734(!-e $concatenate_proj_mak) && (die "$concatenate_proj_mak does NOT exist!\nPlease help to check.\n");
735print "concatenate_proj_mak = $concatenate_proj_mak\n";
736$theMF = $concatenate_proj_mak;
737&cktheMF($theMF);
738exit 0 if($action eq "getusr");
739
740#add oriaction to store original action
741my $oriaction = $action;
742
743# for initial mbis config
744&mbis_init;
745&mbis_start_probe;
746# mbis options
747system("echo MBIS_EN=$mbis_en >> $tmpFolder/~buildinfo.tmp");
748system("echo MBIS_EN_OBJ_LOG=$mbis_en_obj_log >> $tmpFolder/~buildinfo.tmp");
749system("echo NO_LTELIB=$no_ltelib >> $tmpFolder/~buildinfo.tmp");
750system("echo NO_LTECGEN=$no_ltecgen >> $tmpFolder/~buildinfo.tmp");
751system("echo NO_PCIBT=$no_pcibt >> $tmpFolder/~buildinfo.tmp");
752system("echo MCF_OTA_NAME=$ota_name >> $tmpFolder/~buildinfo.tmp");
753system("echo MODIS_CONFIG=$modis_config >> $tmpFolder/~buildinfo.tmp");
754system("echo NO_DSP=$no_dsp >> $tmpFolder/~buildinfo.tmp");
755system("echo NO_WARNING_AS_ERROR=$no_warning_as_error >> $tmpFolder/~buildinfo.tmp");
756system("echo CHECK_FO_LICENSE=$check_fo_license >> $tmpFolder/~buildinfo.tmp");
757system("echo LICENSE_INFO=$license_info >> $tmpFolder/~buildinfo.tmp");
758system("echo CUST_LIC=$cust_lic >> $tmpFolder/~buildinfo.tmp");
759system("echo VARIATION_PROJ=$VarioationProj_name >> $tmpFolder/~buildinfo.tmp");
760system("echo ORIACTION=$action >> $tmpFolder/~buildinfo.tmp");
761system("echo SRC_MAX_PACKAGE=$chk_rel_pkg >> $tmpFolder/~buildinfo.tmp");
762
763if (($action ne "ckmake") && ($action ne "drv_feature_check")) {
764 if ($m_in_lsf != 1) {
765 # Before executing actions, dump environment information to the build.log
766 system("echo USERNAME=$ENV{'USERNAME'} > $targetFolder/build.log");
767 system("perl -e \"print \'START TIME=\';\" >> $targetFolder/build.log");
768 system("perl tools/time.pl -n >> $targetFolder/build.log");
769 }
770}
771
772# Get network path
773open (FILE_HANDLE, ">$tmpFolder/~net_path.tmp") or die "Cannot open $tmpFolder/~net_path.tmp";
774if ($ENV{'MTK_INTERNAL'} eq 'TRUE') {
775 $net_path = &get_net_path;
776 print FILE_HANDLE "NET_PATH = $net_path\n";
777}
778close FILE_HANDLE;
779
780if(-e $theVerno) {
781 open (FILE_HANDLE, "<$theVerno") or die "cannot open $theVerno\n";
782 while (<FILE_HANDLE>) {
783 if ((/^([^\#]*)\#?.*/) && ($1 =~ /^(\w+)\s*=\s*(.*\S)\s*$/)) {
784 $keyname = lc($1);
785 $${keyname} = uc($2);
786 }
787 }
788 close FILE_HANDLE;
789}
790
791die "Please define VERNO in project makefile or $theVerno." if($verno eq "");
792if ($verno =~ /\s+/) {
793 $arrow = $verno;
794 $arrow =~ s/\s/\^/g;
795 $arrow =~ s/[^\^]/ /g;
796 print "\n$verno\n";
797 print "$arrow\n";
798 print "Space is not a legal character for VERNO name.\nPlease check it !!\n\n";
799 exit 1;
800}
801
802# Get custom_release value
803 open (FILE_HANDLE, "<make/common/Custom.bld") or die "Cannot open make/common/Custom.bld\n";
804 while (<FILE_HANDLE>) {
805 if (/^(\S+)\s*=\s*(\S+)/) {
806 $keyname = lc($1);
807 if(defined($${keyname}) && $${keyname} ne ""){
808 next;
809 }
810 #defined($${keyname}) && warn "$1 redefined in $thefile!\n";
811 $${keyname} = uc($2);
812 }
813 }
814 close FILE_HANDLE;
815
816# To check if FLAVOR length is less than 36 bytes
817die "ERROR: FLAVOR name should be less than 36 characters.\n" if(length($flavor)>36);
818die "ERROR: ORIGINAL_PROJECT_NAME name should be less than 128 characters.\n" if(length($original_project_name)>128);
819die "ERROR: ORIGINAL_FLAVOR name should be less than 36 characters.\n" if(length($original_flavor)>36);
820die "ERROR: ORIGINAL_VERNO name should be less than 64 characters.\n" if(defined $original_verno && length($original_verno)>64);
821
822if ($^O ne "MSWin32") {
823 @tools_Dirs = qw(tools/);
824} else {
825 @tools_Dirs = qw(tools/ tools/MinGW tools/MSYS);
826}
827
828push (@tools_file,$makeCmd);
829
830foreach $tools_Dirs (@tools_Dirs) {
831 if (!-d $tools_Dirs) {
832 warn "$tools_Dirs folder does NOT exist!\n";
833 &cp_3rdpartyTool;
834 }
835}
836
837foreach $tools_file (@tools_file) {
838 if (!-e $tools_file) {
839 warn "$tools_file does NOT exist!\n";
840 &cp_3rdpartyTool;
841 }
842}
843
844my $strBypassMoDIS = 0;
845my $notify_list;
846if ($^O eq "MSWin32") {
847 if ($ENV{'LTE_DOMAIN'} eq "TRUE") {
848 $notify_list = "\\\\mtklwafs01\\moly\\wcpsm\\config\\bm_conf.ini";
849 } else {
850 $notify_list = "\\\\glbfs14\\sw_releases\\3rd_party\\Scripts\\BM_conf.ini";
851 }
852}
853$notify_list = "/mtkeda/wcpsm/bm/config/bm_conf.ini" if($^O eq "linux");
854if (($ENV{'MTK_INTERNAL'} eq 'TRUE') && (-e "$notify_list")) {
855 %BM_conf = iniToHash($notify_list);
856 if ($bypassMoDIS > -1) {
857 $strBypassMoDIS = $BM_conf{'MODIS_RULE'}->{'MODIS_BYPASS'};
858 }
859}
860
861if ($ENV{"NUMBER_OF_PROCESSORS"} > 1) {
862 $PROCESS_NUM = $ENV{"NUMBER_OF_PROCESSORS"};
863 if($fullOpts !~ /-j/) {
864 ($fullOpts eq "") ? ($fullOpts = "-j$PROCESS_NUM") : ($fullOpts .= " -j$PROCESS_NUM");
865 }
866 if ($mbis_en eq "TRUE") {
867 $mbis_num_proc = $PROCESS_NUM;
868 }
869}
870
871if ($m_in_lsf == 1) {
872 die "NOT IN LSF SERVER!\n" if ($ENV{"LS_ADMINNAME"} eq "");
873 $computerName = $ENV{"COMPUTERNAME"};
874 if ($local_q != 1) {
875 system("echo set LAST_SUBMITTED_CF=$computerName > build/last_cf.log");
876 $ENV{"TMP"} = "e:\\temp";
877 $ENV{"TEMP"} = "e:\\temp";
878 mkdir("e:/temp") if (!-d "e:/temp");
879 }
880 $ENV{"INLSF"} = $computerName;
881}
882
883if ($bypassMoDIS > -1) {
884 $bypassMoDIS = int(eval($strBypassMoDIS));
885}
886
887if ($ENV{COMPUTERNAME} =~ /mtks(cf|ib)/i) {
888 $m_in_lsf = 1;
889}
890
891if (($m_in_lsf == 0) && ($not_enter_lsf != 1)) {
892 if ($action =~ /^(bm_new|bm_update|bm_remake)$/i) {
893 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;
894 }
895 if (($action =~ /new/i) && ($action !~ /new_viti/i) && ($ENV{"SESSIONNAME"} ne "") &&
896 ($ENV{"LSF_BINDIR"} ne "") && ($project !~ /BASIC/i) && ($project !~ /L1S/i) && ($project !~ /UDVT/i) && ($ENV{'MTK_INTERNAL'} eq 'TRUE')) {
897
898 chomp($cwd = cwd());
899 if ($cwd =~ /^[abg-z]/i) {
900 &pre_gen() if (($pureMoDIS == 1) || ((lc($action) ne "new_modis") && (lc($action) ne "new_uesim")));
901 $env_last_S_CF = "";
902 $lastSC = "build/last_cf.log";
903 if ((-e $lastSC) && (open(LOGF, "${lastSC}"))) {
904 while (<LOGF>) {
905 if (/set LAST_SUBMITTED_CF=(\S+)/) {
906 $env_last_S_CF = $1;
907 last;
908 }
909 }
910 close(LOGF);
911 }
912 if ($mbis_en eq "TRUE") {
913 $mbis_time = time;
914 system("echo T_S,DISPATCH_CF,P,$mbis_time >>$ENV{MBIS_BUILD_TIME_TMP}");
915 }
916 my $result = 0;
917 if ($env_last_S_CF eq "") {
918 $result = system("bsub -I \"perl $net_path\\m_cp2lsf.pl\" \"$net_path\" @orgARGV");
919 } else {
920 if (($output = `bhosts ${env_last_S_CF} mtkcf 2>&1`) =~ / Bad host name, host group name or cluster name/) {
921 $result = system("bsub -I \"perl $net_path\\m_cp2lsf.pl\" \"$net_path\" @orgARGV");
922 } else {
923 $result = system("bsub -I -m \"${env_last_S_CF}+2 mtkcf+1\" \"perl $net_path\\m_cp2lsf.pl\" \"$net_path\" @orgARGV");
924 }
925 }
926 &writeINI;
927 exit $result >> 8;
928 } else {
929 # make new in local E: driver
930 if (($ENV{"SESSIONNAME"} ne "") && ($ENV{"LSF_BINDIR"} ne "") && ($compiler eq "RVCT") && ($ENV{'MTK_INTERNAL'} eq 'TRUE')) {
931 &localq;
932 }
933 }
934 }
935}
936
937
938if ($action eq "c,r") {
939 @theAct = qw(clean remake);
940} elsif ($action eq "c,u") {
941 @theAct = qw(clean update);
942} elsif ($action eq "c,r_modis") {
943 @theAct = ("clean_modis remake_modis");
944} elsif ($action eq "c,u_modis") {
945 @theAct = ("clean_modis update_modis");
946} elsif ($action eq "c,r_uesim") {
947 @theAct = ("clean_uesim remake_uesim");
948} elsif ($action eq "c,u_uesim") {
949 @theAct = ("clean_uesim update_uesim");
950} else {
951 @theAct = ($action);
952}
953
954if ($newMoDIS == 1) {
955# make sure set $mbis_target_build_with_Modis should be after localq
956 $mbis_target_build_with_Modis = 1;
957 if ($action =~ /^c,r(_modis|_uesim)?$/) {
958 push(@theAct, "clean_modis remake_modis");
959 } elsif ($action =~ /^c,u(_modis|_uesim)?$/) {
960 push(@theAct, "clean_modis update_modis");
961 } else {
962 my $action2 = $action;
963 $action2 =~ s/_(modis|uesim)$//ig;
964 push(@theAct, $action2 . "_modis");
965 }
966}
967if ($newUESim == 1) {
968 $mbis_target_build_with_Modis = 1;
969 if ($action =~ /^c,r(_modis|_uesim)?$/) {
970 push(@theAct, "clean_uesim remake_uesim");
971 } elsif ($action =~ /^c,u(_modis|_uesim)?$/) {
972 push(@theAct, "clean_uesim update_uesim");
973 } else {
974 my $action2 = $action;
975 $action2 =~ s/_(modis|uesim)$//ig;
976 push(@theAct, $action2 . "_uesim");
977 }
978}
979
980if (($action ne "ckmake") && ($action ne "drv_feature_check")) {
981 # Before executing actions, dump environment information to the build.log
982 if(-e "./SubReleaseConfig.ini") {
983 print "copy ./SubReleaseConfig.ini $targetFolder";
984 copy("./SubReleaseConfig.ini", $targetFolder);
985 }
986 system("perl -e \"print \'BUILD START TIME=\';\" >> $targetFolder/build.log");
987 system("perl tools/time.pl -n >> $targetFolder/build.log");
988 system("echo NUMBER_OF_PROCESSORS=$ENV{\"NUMBER_OF_PROCESSORS\"} >>$targetFolder/build.log");
989 &mbis_info_probe;
990}
991
992# check current working folder length
993# if it is too long, it will cause build error. The max length is defined 90 characters.
994chomp($cwd = cwd());
995$len = length($cwd);
996$folder_limit = 90;
997if($^O eq "MSWin32" && $len > $folder_limit) {
998 if ($cwd =~ /.+\\(.+)/) {
999 $folder_name = $1;
1000 }
1001 print "Folder: $cwd\n";
1002 print "Warning: The folder length from $folder_name($len characters) exceeds $folder_limit characters. Please reduce folder lengths!\n";
1003 system("echo Warning: The folder path from $folder_name($len characters) exceeds $folder_limit characters. > $tmpFolder/~path_length.tmp");
1004}
1005
1006my $result = 0;
1007my %saw;
1008@theAct = grep (!$saw{$_}++, @theAct);
1009foreach my $action (@theAct) {
1010 $ENV{"ACTION"} = $action;
1011 if ($action =~ /_(modis|uesim)$/i) {
1012 ($projectFolder, $tmpFolder) = &MoDIS_xgen_check($action);
1013 }
1014 &gen_buildinfo_tmp;
1015
1016 if ($action =~ /\b(clean)_(modis|uesim)\b/) {
1017 if ($#arguments != -1) {
1018 system("echo DO_CLEAN_MODULE=TRUE > $tmpFolder/~cleanmod.tmp");
1019 system("echo CLEAN_MODS=@arguments >> $tmpFolder/~cleanmod.tmp");
1020 }
1021 }
1022 if ($action eq "clean") {
1023 if ($#arguments != -1) {
1024 system("echo DO_CLEAN_MODULE=TRUE > $tmpFolder/~cleanmod.tmp");
1025 system("echo CLEAN_MODS=@arguments >> $tmpFolder/~cleanmod.tmp");
1026 system("${makeCmd} -f${makeFolder}${myMF} -r -R CORE_ROOT=$core_root PROJECT_NAME=$project_name \"PROJECT_MAKEFILE=$theMF\" FLAVOR=$flavor $target_options cleanmod");
1027 } else {
1028 system("echo DO_CLEAN_MODULE=FALSE > $tmpFolder/~cleanmod.tmp");
1029 system("${makeCmd} -f${makeFolder}${myMF} -r -R CORE_ROOT=$core_root PROJECT_NAME=$project_name \"PROJECT_MAKEFILE=$theMF\" FLAVOR=$flavor $target_options cleanall");
1030 }
1031 } elsif (($action eq "remake") || ($action =~ /\b(remake)_(modis|uesim)\b/)) {
1032 if ($#arguments != -1) {
1033 system("echo DO_REMAKE_MODULE=TRUE > $tmpFolder/~remakemod.tmp");
1034 system("echo REMAKE_MODS=@arguments >> $tmpFolder/~remakemod.tmp");
1035 system("echo L_REMAKE_MODS=@l1core_arguments >> $tmpFolder/~remakemod.tmp");
1036 }
1037 } elsif (($action eq "update") || ($action =~ /\b(gen|update)_(modis|uesim)\b/)) {
1038 if ($#arguments != -1) {
1039 system("echo DO_UPDATE_MODULE=TRUE > $tmpFolder/~updatemod.tmp");
1040 system("echo UPDATE_MODS=@arguments >> $tmpFolder/~updatemod.tmp");
1041 }
1042 } elsif (($action eq "scan") || ($action =~ /\b(scan)_(modis|uesim)\b/)) {
1043 if ($#arguments != -1) {
1044 system("echo DO_SCAN_MODULE=TRUE > $tmpFolder/~scanmod.tmp");
1045 system("echo SCAN_MODS=@arguments >> $tmpFolder/~scanmod.tmp");
1046 }
1047 } elsif (($action eq "new") || ($action eq "bm_new") || ($action eq "codegen") || ($action =~ /_(modis|uesim)\b/)) {
1048 # empty here to run through BT switch
1049 } elsif ($action eq "check_scan") {
1050 if ($#arguments != -1) {
1051 system("echo DO_SCAN_MODULE=TRUE > $tmpFolder/~scanmod.tmp");
1052 system("echo SCAN_MODS=@arguments >> $tmpFolder/~scanmod.tmp");
1053 }
1054 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");
1055 } elsif ($action eq "check") {
1056 system("perl ${toolsFolder}parse_comp_err.pl $projectFolder FALSE $tmpFolder TRUE");
1057 } elsif ($action eq "check_dep") {
1058 &Usage if (!@arguments);
1059 &writeINI;
1060 system("perl tools/GetDepMod.pl ./ \"$theMF\" $project_name $flavor @arguments") && exit 1;
1061 exit 0;
1062 } elsif ($action =~ /update_dep|remake_dep/i) {
1063 &Usage if (!@arguments);
1064 print "Scanning dependency modules...\n";
1065 my $output;
1066 if (($output = `perl tools/GetDepMod.pl ./ \"$theMF\" $project_name $flavor @arguments 2>&1`) =~ /=+DEPENDENCY MODULE\(S\)=+\n(.*)\n/) {
1067 @arguments = split(/\s+/,$1);
1068 $action = "update" if ($action eq "update_dep");
1069 $action = "remake" if ($action eq "remake_dep");
1070 print "The following module(s) will be rebuilt!\n";
1071 print "===========================================================\n";
1072 print "@arguments","\n";
1073 print "===========================================================\n";
1074 redo; # redo to generate ${makeFolder}~remakemod.tmp
1075 } else {
1076 print $output;
1077 &writeINI;
1078 exit 1;
1079 }
1080 } elsif ($action eq "memquery") {
1081 #invoke memquery according to SINGLE_CORE_ONLY feature option defined in project makefile respectively
1082 if ($#arguments != -1) {
1083 system("echo \"@arguments\" > $tmpFolder/~memquery.tmp");
1084 }
1085 system("${makeCmd} -f ${makeFolder}${myMF} -r -R CORE_ROOT=$core_root PROJECT_NAME=$project_name \"PROJECT_MAKEFILE=$theMF\" FLAVOR=$flavor $target_options memquery");
1086 } else {
1087 if ($action !~ /^ckmake$/i) {
1088 $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");
1089 die "Error: ckmake failed!!!\n" if($result != 0);
1090 }
1091 $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");
1092 if($result != 0) {
1093 &error_handle;
1094 } else{
1095 &mbis_success if ($mbis_en eq "TRUE");
1096 if (($custom_release eq "FALSE") && ($ENV{'MTK_INTERNAL'} eq 'TRUE')&& (-e "mtk_tools\\Internal_function.pm")) {
1097 die "AAPMC parser Error!!!\n" if ($result != 0)
1098 }
1099 }
1100 next;
1101 }
1102
1103 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)) {
1104 $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");
1105 die "Error: ckmake failed!!!\n" if($result != 0);
1106 }
1107 if (($action eq "remake") || ($action eq "update") || ($action eq "new") || ($action eq "bm_new") || ($action eq "scan")) {
1108 if ($action eq "bm_new") {
1109 system("echo BM_NEW=TRUE >> $tmpFolder/~buildinfo.tmp");
1110 #Add for daily build
1111 if ($daily_build){
1112 system("echo DAILY_BUILD=TRUE >> $tmpFolder/~buildinfo.tmp");
1113 }
1114 $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");
1115 } else {
1116 $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");
1117 }
1118 if ($result == 0) {
1119 if (($custom_release eq "FALSE") && ($ENV{'MTK_INTERNAL'} eq 'TRUE')&& (-e "mtk_tools\\Internal_function.pm")) {
1120 $result = &AAPMC::Parse_AAPMCLog($AAPMCLOG,$project_name,$flavor,"$theMF");
1121 die "AAPMC parser Error!!!\n" if ($result != 0)
1122 }
1123 &mbis_success if ($mbis_en eq "TRUE");
1124 } else {
1125 system("perl $mbis -i SUCCESSFUL_BUILD,0") if ($mbis_en eq "TRUE");
1126 &error_handle;
1127 }
1128 last if ($mbis_target_build_with_Modis != 1);
1129 } elsif ($action =~ /_(modis|uesim)\b/) {
1130 $result = &MoDIS_build_process($action);
1131 } elsif ($action eq "codegen") {
1132 $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");
1133 #mbis end probe
1134 if ($result == 0) {
1135 &mbis_success if ($mbis_en eq "TRUE");
1136 }
1137 }
1138 if ($result != 0) {
1139 system("perl $mbis -i SUCCESSFUL_BUILD,0") if ($mbis_en eq "TRUE");
1140 print "Failed in $action\n";
1141 last;
1142 }
1143}
1144# [Linux] temporarily add
1145unlink("nul") if($^O eq "linux" && -e "nul");
1146unlink("NUL") if($^O eq "linux" && -e "NUL");
1147&writeINI;
1148if (($m_in_lsf != 1) && ($mbis_target_build_with_Modis == 1)) {
1149 &mbis_end_probe;
1150}
1151#die "make.pl\n" if ($result != 0);
1152exit $result >> 8;
1153
1154sub MoDIS_build_process {
1155 my $modis_action = shift @_;
1156 my $modis_result = 0;
1157 if ($bypassMoDIS < 1) {
1158 system("perl $mbis -t T_S,M_TOTAL,M_P") if ($mbis_en eq "TRUE");
1159 my $modis_option = $target_option . " MODIS_CONFIG=TRUE PARTIAL_SOURCE=FALSE";
1160 if (($modisDir ne "") && ($modisDir ne "undef")) {
1161 $modis_option .= " MODIS_MODE=$modisDir";
1162 } else {
1163 $modisDir = "undef";
1164 }
1165 $modis_action =~ s/\b(bm)_//ig;
1166 if ($modis_action =~ /_uesim\b/) {
1167 $modis_action =~ s/_uesim\b/_modis/g;
1168 $modis_option .= " UE_SIMULATOR=TRUE";
1169 }
1170 my $modis_cwd = cwd();
1171 $modis_cwd =~ s/\//\\/g if ($^O eq "MSWin32");
1172 my $modis_subst = "";
1173 if (($^O eq "MSWin32") && ($modis_action !~ /^(gen|clean|scan|ap|at|rel)_(modis|uesim)$/i)) {
1174 foreach my $disk (k..z) {
1175 if (system("subst $disk: $modis_cwd\\.. >NUL 2>&1") == 0) {
1176 $modis_subst = $disk;
1177 last;
1178 }
1179 }
1180 if ($modis_subst ne "") {
1181 print "MoDIS subst disk for $modis_cwd is $modis_subst:\n";
1182 chdir("$modis_subst:\\mcu\\");
1183 } else {
1184 warn "Warning: Execute subst for MoDIS fail !\n";
1185 }
1186 }
1187 $modis_action = "new $modis_action" if ($pureMoDIS == 1);
1188 $modis_action = "bullseye_config new $modis_action" if (($modis_option =~/BULLSEYE_CONFIG=TRUE/) && ($pureMoDIS == 1));
1189 $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");
1190 chdir($modis_cwd);
1191 system("subst $modis_subst: /D >NUL") if ($modis_subst ne "");
1192 if ($modis_result == 0) {
1193 if ($modis_action =~ /\b(new|remake|update)_(modis|uesim)\b/) {
1194 system("perl $mbis -i SUCCESSFUL_BUILD,1") if ($mbis_en eq "TRUE");
1195 #rel_atMoDIS
1196 }
1197 if (($modis_action eq "at_modis") || ($atMoDIS == 1)) {
1198 chdir("$modis_cwd\\MoDIS_VC9");
1199 $modis_result = system("perl modisAutoTest.pl at_modis $modisDir ..\\$theMF ..\\$theVerno");
1200 chdir("$modis_cwd");
1201 }
1202 }
1203 system("perl $mbis -t T_E,M_TOTAL,M_P") if ($mbis_en eq "TRUE");
1204 } else {
1205 print "Skip $modis_action for MoDIS\n";
1206 $modis_result = 9 << 8;
1207 }
1208 return $modis_result;
1209}
1210
1211sub MoDIS_xgen_check {
1212 my $modis_action = shift @_;
1213 my $result_projectFolder = "build/${project_name}/$flavor";
1214 my $result_tmpFolder = "$result_projectFolder/tmp";
1215 if ($modis_action =~ /_(modis|uesim)$/i) {
1216 my $flag_packMoDIS = $packMoDIS;
1217 my $path_packMoDIS;
1218 $path_packMoDIS = "MoDIS" if ($modis_action =~ /_(modis)$/i);
1219 $path_packMoDIS = "UESim" if ($modis_action =~ /_(uesim)$/i);
1220 $path_packMoDIS .= "/_BUILD_XGEN";
1221 if ($modis_action =~ /_(modis|uesim)$/i) {
1222 if (($pureMoDIS != -1) && ($packMoDIS != -1)) {
1223 $flag_packMoDIS = 1;
1224 }
1225 }
1226 elsif ($pureMoDIS == 1) {
1227 die "Error: -puremodis cannot be used with make $modis_action\n";
1228 }
1229 if ($flag_packMoDIS == 0) {
1230 if (-d "$result_projectFolder/$path_packMoDIS") {
1231 print "Auto turn on -packmodis when $result_projectFolder/$path_packMoDIS is found\n";
1232 $flag_packMoDIS = 1;
1233 }
1234 }
1235 if ($flag_packMoDIS == 1) {
1236 $result_projectFolder .= "/" . $path_packMoDIS;
1237 $target_option =~ s/\bPROJDIR=\S+//g;
1238 $target_option .= " PROJDIR=./$result_projectFolder";
1239 $result_tmpFolder = "$result_projectFolder/tmp";
1240 if ($result_projectFolder ne $projectFolder) {
1241 mkpath($result_projectFolder) if (! -d $result_projectFolder);
1242 foreach my $file (glob "$projectFolder/*") {
1243 next if (-d $file);
1244 copy($file, $result_projectFolder);
1245 }
1246 }
1247 if ($result_tmpFolder ne $tmpFolder) {
1248 mkpath($result_tmpFolder) if (! -d $result_tmpFolder);
1249 foreach my $file (glob "$tmpFolder/*") {
1250 next if (-d $file);
1251 copy($file, $result_tmpFolder);
1252 }
1253 }
1254 }
1255 }
1256 return ($result_projectFolder, $result_tmpFolder);
1257}
1258
1259#usage:
1260# my %hash=iniToHash('/tmp/myini.ini');
1261# print $hash{'TITLE'}->{'Name'},"\n";
1262#
1263sub iniToHash {
1264 open(MYINI, $_[0]);
1265 my %hash;
1266 my $hashref;
1267
1268 while(<MYINI>) {
1269 next if ((/^\s*$/) || (/^\s*#/));
1270 if (/^\s*\[(.+)\]/) {
1271 $hashref = $hash{$1} ||= {};
1272 } elsif (/^\s*(\S+)\s*=\s*(.+)\s*$/) {
1273 $hashref->{$1} = $2;
1274 } elsif (/^\s*(\S+)\s*\+=\s*(.+)\s*$/) {
1275 $hashref->{$1} = $hashref->{$1} . " $2";
1276 }
1277 }
1278
1279 close MYINI;
1280 return %hash;
1281}
1282
1283sub CurrTimeStr {
1284 my($sec, $min, $hour, $mday, $mon, $year) = localtime(time);
1285 return (sprintf "%4.4d/%2.2d/%2.2d %2.2d:%2.2d", $year+1900, $mon+1, $mday, $hour, $min);
1286}
1287
1288sub cp_3rdpartyTool {
1289 if ($ENV{'MTK_INTERNAL'} eq 'TRUE') {
1290 if (-e "tools/thirdParties.pl") {
1291 print("perl tools/thirdParties.pl -cp \n");
1292 system("perl tools/thirdParties.pl -cp");
1293 } else {
1294 warn "tools/thirdParties.pl does NOT exist!\n";
1295 exit 1;
1296 }
1297 } else {
1298 warn "Lack off thirdParties tools!\n";
1299 warn "Please refer to document: SOP_Third_Party_Package_Installation!\n";
1300 exit 1;
1301 }
1302}
1303
1304sub Usage {
1305
1306 warn << "__END_OF_USAGE";
1307
1308Usage:
1309 ./m ["project makefile"] action [modules]|file1[ file2[ ...]] | \@files
1310or ./m ["make/projects/project makefile"] action [modules]|file1[ file2[ ...]] | \@files
1311
1312Description:
1313 project makefile = ELBRUS_FPGA(flavor).mak (ELBRUS_FPGA(FLAVOR) project)
1314 = ...
1315
1316 action = new (codegen, clean, update, remake) (default)
1317 = update or u (scan, compile, link)
1318 = slim_update (scan, compile, link without generating mcddll)
1319 = remake or r (compile, link)
1320 = clean or c (clean)
1321 = c,u (clean and update)
1322 = c,r (clean and remake)
1323 = codegen (codegen)
1324 = slim_codegen (codegen without generating mcddll)
1325 = mcddll_update (codegen and generate mcddll)
1326 = slim_mcddll (generate mcddll without codegen)
1327 = emigen (emigen)
1328 = emiclean (emiclean)
1329
1330 module(s) = modules name (kal, verno, ...)
1331 => OPTIONAL when action is one of (clean c remake r update u c,r c,u)
1332
1333Example:
1334 ./m "ELBRUS_FPGA(LWTG).mak" new
1335 ./m "ELBRUS_FPGA(LWTG).mak" c,u custom
1336 ./m "make/projects/ELBRUS_FPGA(LWTG).mak" r drv custom
1337__END_OF_USAGE
1338
1339 exit 1;
1340}
1341
1342sub writeINI {
1343 &writeMakeINI();
1344 if (($action ne "ckmake") && ($action ne "drv_feature_check")) {
1345 system("echo LOCAL_MACHINE=%COMPUTERNAME% >>$targetFolder/build.log");
1346 system("echo PROJECT_NAME=$project_name>>$targetFolder/build.log");
1347 system("echo PLATFORM=$plat>>$targetFolder/build.log");
1348 system("echo FLAVOR=$flavor>>$targetFolder/build.log");
1349 system("echo VERNO=$verno>>$targetFolder/build.log");
1350 system("echo ARMLMD_LICENSE_FILE=%ARMLMD_LICENSE_FILE%>>$targetFolder/build.log");
1351 system("perl tools/init/echo.pl -n COMMAND=make \"@orgARGV\">>$targetFolder/build.log");
1352 system("perl -e \"print \'BUILD END TIME=\'\">>$targetFolder/build.log");
1353 system("perl tools/time.pl -n>>$targetFolder/build.log");
1354 $time_num=time;
1355 #mbis end probe
1356 # to aviod be called twice when enable lsf
1357 if (($m_in_lsf != 1)&&($mbis_target_build_with_Modis != 1)) {
1358 &mbis_end_probe;
1359 }
1360 }
1361}
1362
1363sub writeMakeINI {
1364 mkpath("build") if(!-d "build");
1365 if ($enINI == 1) {
1366 open (FILE_HANDLE, ">$ini") or die "cannot open $ini\n";
1367 print FILE_HANDLE "project_makefile = $project_makefile\n";
1368 print FILE_HANDLE "project_folder = ". $original_projectFolder."\n";
1369 close FILE_HANDLE;
1370 }
1371}
1372
1373sub pre_gen {
1374 print "pre gen\n";
1375 if(defined($level) && ($level =~ /VENDOR/i)) {
1376 print "Skip pre_gen for vendor release.\n";
1377 return 0;
1378 }
1379 print "Before submitting into CF machines, pre-check the Makefile, sys_auto_gen\n";
1380 $ENV{"ACTION"} = "sys_auto_gen";
1381 my @f = glob("$tmpFolder/~*.tmp *.d");
1382 if(@f) {
1383 unlink(@f) or die "Remove failed $!";
1384 }
1385 &gen_buildinfo_tmp;
1386 if( ($action eq "new_modis") or ($action eq "new_uesim")) {
1387 $target_option .= " MODIS_CONFIG=TRUE";
1388 }
1389 $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");
1390 if ($preTestResult != 0) {
1391 &writeINI;
1392 exit 1;
1393 }
1394 print "Pass pre-check for Makefile and sys_auto_gen\n";
1395}
1396
1397sub localq {
1398 my ($islocalpath) = @_;
1399 my $result = 0;
1400 print "Check if localq is available .... ";
1401 unlink("$logFolder/localq.log") if (-e "$logFolder/localq.log");
1402 system("bhosts $ENV{\"COMPUTERNAME\"} >$logFolder/localq.log 2>nul");
1403 open(LOCALQ, "$logFolder/localq.log") || die "Can not open $logFolder/localq.log!";
1404 while (<LOCALQ>) {
1405 next if ($_ =~ /HOST_NAME/ig);
1406 $_ =~ /(\S+)\s+(\S+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/ig;
1407 $STATUS = $2;
1408 $MAX = $4;
1409 $NJOBS = $5;
1410 }
1411 close LOCALQ;
1412 if (($NJOBS < $MAX) && ($STATUS =~ /ok/ig)) {
1413 print "YES\n";
1414 print "Enter the local queue.\n";
1415 if (($action =~ /new/i) && ((($action ne "new_modis") && ($action ne "new_uesim")) || ($pureMoDIS == 1))) {
1416 &pre_gen();
1417 }
1418 if ($islocalpath ne "") {
1419 if ($RUN_KLOCWORK eq 1) {
1420 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";
1421 $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");
1422 } else {
1423 print "bsub -q localq -m $ENV{\"COMPUTERNAME\"} -I perl make.pl -lsf -localq -localpath @orgARGV\n";
1424 $result = system("bsub -q localq -m $ENV{\"COMPUTERNAME\"} -I perl make.pl -lsf -localq -localpath @orgARGV");
1425 }
1426 } else {
1427 if ($RUN_KLOCWORK eq 1) {
1428 print "bsub -q localq -m $ENV{\"COMPUTERNAME\"} -I kwinject --detach Cgen.exe,DrvGen.exe -T kwinject.trace perl make.pl -lsf -localq @orgARGV\n";
1429 $result = system("bsub -q localq -m $ENV{\"COMPUTERNAME\"} -I kwinject --detach Cgen.exe,DrvGen.exe -T kwinject.trace perl make.pl -lsf -localq @orgARGV");
1430 } else {
1431 print "bsub -q localq -m $ENV{\"COMPUTERNAME\"} -I perl make.pl -lsf -localq @orgARGV\n";
1432 $result = system("bsub -q localq -m $ENV{\"COMPUTERNAME\"} -I perl make.pl -lsf -localq @orgARGV");
1433 }
1434 }
1435 &writeINI;
1436 exit $result >> 8;
1437 } else {
1438 print "NO\n";
1439 }
1440}
1441
1442sub get_net_path {
1443 my $path;
1444 my $current_path = cwd();
1445 if ($^O eq "MSWin32") {
1446 $current_path =~ s/\//\\/g;
1447 if ($current_path=~/^([ABDG-Z]:)(.*)/i) {
1448 my $disk = $1;
1449 my $folder = $2;
1450 $folder =~ s/\\$//;
1451 my @disk = `net use $disk`;
1452 if ($#disk != -1) {
1453 $disk[1]=~/\s+(\\\\.*)\s*$/;
1454 $path = $1.$folder;
1455 } else {
1456 @disk = `subst`;
1457 my $subst_folder;
1458 foreach my $subdisk (@disk) {
1459 $subdisk =~ s/\s*$//;
1460 if ($subdisk =~ /($disk.*)\s*\=\>\s*(.*)/i){
1461 $subst_folder= $2;
1462 $subst_folder =~ s/://;
1463 }
1464 }
1465 if ($subst_folder =~ /^UNC\\(.+)/) {
1466 $path = "\\\\".$1;
1467 } else {
1468 if ($subst_folder ne "") {
1469 $path = "\\\\".$ENV{"COMPUTERNAME"}."\\".$subst_folder.$folder;
1470 } else {
1471 $path = "\\\\".$ENV{"COMPUTERNAME"}."\\".$disk.$folder;
1472 }
1473 }
1474 }
1475 } elsif ($current_path=~/^([CEF]):(.*)/i) {
1476 my $disk = $1;
1477 my $folder = $2;
1478 if ($ENV{"USERNAME"} =~ /wcxbm/ig) {
1479 $path = "\\\\".$ENV{"COMPUTERNAME"}."\\".$disk."\$\$".$folder;
1480 } else {
1481 $path = "\\\\".$ENV{"COMPUTERNAME"}."\\".$disk.$folder;
1482 }
1483 }
1484 } else {
1485 $path = $current_path;
1486 }
1487 $path =~ s/://g;
1488 print "path=$path\n";
1489 return $path;
1490}
1491
1492sub mbis_start_probe {
1493 my $mbis_log_folder;
1494
1495 if ($mbis_en eq "TRUE") {
1496 if (!defined($ENV{"MBIS_BUILD_TIME_TMP"}) || !defined($ENV{"MBIS_BUILD_TIME_LOG"}) || !defined($ENV{"MBIS_BUILD_INFO_LOG"})) {
1497 $mbis_log_folder = "$logFolder/mbis";
1498 if (!-d "$mbis_log_folder") {
1499 mkpath($mbis_log_folder) or die "Create Folder $mbis_log_folder Faild $!";
1500 } else {
1501 # delete last log file
1502 if ($mbis_en_save_log ne "TRUE") {
1503 my @f = glob("$mbis_log_folder/*.log");
1504 unlink(@f) or die "Remove failed $!" if(@f);
1505 my @f = glob("$mbis_log_folder/*.tmp");
1506 unlink(@f) or die "Remove failed $!" if(@f);
1507 }
1508 }
1509
1510 if (!defined($ENV{MBIS_BUILD_TIME_TMP})) {
1511 $ENV{MBIS_BUILD_TIME_TMP} = $mbis_log_folder . "/". $build_time_string . "_" . "mbis" . "_" . "time" . ".tmp";
1512 #set title of mbis time tmp file
1513 system("echo Time Stamp,Item Name,Type,Time>>$ENV{MBIS_BUILD_TIME_TMP}");
1514 system("echo T_S,TOTAL,A,$build_time_sec >>$ENV{MBIS_BUILD_TIME_TMP}");
1515 }
1516
1517 if (!defined($ENV{MBIS_BUILD_TIME_LOG})) {
1518 $ENV{MBIS_BUILD_TIME_LOG} = $mbis_log_folder . "/". $build_time_string . "_" . "mbis" . "_" . "time" . ".log";
1519 #set title of mbis time tmp file
1520 system("echo Item Name,Type,Start Time,End Time,Duration Time>>$ENV{MBIS_BUILD_TIME_LOG}");
1521 }
1522
1523 if (!defined($ENV{MBIS_BUILD_INFO_LOG})) {
1524 $ENV{MBIS_BUILD_INFO_LOG} = $mbis_log_folder . "/". $build_time_string . "_" . "mbis" . "_" . "info" . ".log";
1525 #set title of mbis time tmp file
1526 system("echo Information Name,Information Content>>$ENV{MBIS_BUILD_INFO_LOG}");
1527 system("echo SUBMIT_TO_QUEUE_DATETIME,$submit_to_queue_time_string>>$ENV{MBIS_BUILD_INFO_LOG}") if ($submit_to_queue_time_string ne "");
1528 system("echo BUILD_START_DATATIME,$build_time_string>>$ENV{MBIS_BUILD_INFO_LOG}");
1529 }
1530 system("perl $mbis -s \"@orgARGVwithFlavor\"");
1531 }
1532 } else {
1533 # MBIS_BUILD_TIME_TMP must not be null for makefile expand the command
1534 $ENV{MBIS_BUILD_TIME_TMP}=tmp;
1535 }
1536}
1537
1538sub mbis_info_probe {
1539 if ($mbis_en eq "TRUE") {
1540 if (($ENV{'MTK_INTERNAL'} eq 'TRUE') && (-e "$mbis_conf_file")) {
1541 %mbis_conf = iniToHash($mbis_conf_file);
1542 $pilot_bm_list = $mbis_conf{'INIT_CONF'}->{'BM_LIST'};
1543 if ($pilot_bm_list =~ /$ENV{USERNAME}/i) {
1544 system("perl $mbis -i BM_BUILD,1");
1545 } else {
1546 system("perl $mbis -i BM_BUILD,0");
1547 }
1548 }
1549
1550 $cur_path=cwd();
1551 system("perl $mbis -i BUILD_FOLDER,\"$cur_path\"");
1552 if($^O eq" MSWin32") {
1553 system("perl $mbis -i BUILD_MACHINE,$ENV{COMPUTERNAME}");
1554 } else {
1555 $hostname = `hostname`;
1556 system("perl $mbis -i BUILD_MACHINE,$hostname");
1557 system("perl $mbis -i BUILD_USER,$ENV{USER}");
1558 }
1559 system("perl $mbis -i CUSTOM_RELEASE,$custom_release");
1560 if ($mbis_num_proc == 0) {
1561 $mbis_num_proc = $ENV{"NUMBER_OF_PROCESSORS"};
1562 }
1563 system("perl $mbis -i NUMBER_OF_PROCESSORS,$mbis_num_proc");
1564 system("perl $mbis -i LSF,$m_in_lsf");
1565 system("perl $mbis -i COMPILER,$compiler");
1566 system("perl $mbis -i USER,$ENV{USERNAME}");
1567 system("perl $mbis -i PROJECT_NAME,$project_name");
1568 system("perl $mbis -i FLAVOR,$flavor");
1569 system("perl $mbis -i VERNO,$verno");
1570 system("perl $mbis -i PLATFORM,$plat");
1571 system("perl $mbis -i PID,$$");
1572 if (-e "make/common/rel/mpd/5g") {
1573 system("perl $mbis -i CODEBASE,MPD_5G");
1574 }
1575 elsif (-e "make/common/rel/mpd/4g") {
1576 system("perl $mbis -i CODEBASE,MPD_4G");
1577 }
1578 elsif (-e "make/common/rel/mpd/common") {
1579 system("perl $mbis -i CODEBASE,MPD_23G");
1580 }
1581 elsif (-e "make/common/rel/hq/USR.txt") {
1582 system("perl $mbis -i CODEBASE,SWRD");
1583 }
1584 else {
1585 system("perl $mbis -i CODEBASE,RELEASE");
1586 if (-d "make/common/rel/sub_ps") {
1587 system("perl $mbis -i REL_PACKAGE,SUB_PS");
1588 }
1589 else {
1590 system("perl $mbis -i REL_PACKAGE,SUB_L4");
1591 }
1592 }
1593 if (-e "dailybuild.txt") {
1594 system("perl $mbis -i DAILY_BUILD_PRODUCER,1");
1595 } else {
1596 system("perl $mbis -i DAILY_BUILD_PRODUCER,0");
1597 }
1598 if (-e "ewsprebuild.txt") {
1599 system("perl $mbis -i EWS_PREBUILD_PRODUCER,1");
1600 } else {
1601 system("perl $mbis -i EWS_PREBUILD_PRODUCER,0");
1602 }
1603 my @folder_cnt = <./build/*/*>;
1604 my $fld_cnt = 0;
1605 foreach (@folder_cnt) {
1606 $fld_cnt ++ if(-d "$_");
1607 }
1608 system("perl $mbis -i NUMBER_OF_PROJECT_FOLDER,$fld_cnt");
1609 }
1610}
1611
1612sub mbis_end_probe {
1613 if ($mbis_en eq "TRUE") {
1614 system("perl $mbis -e");
1615
1616 # transfer mbis when in mpd domain
1617 if (-e "make/common/rel/mpd") {
1618 if (-e "/mtkeda/wcpsm/utilities/UploadToMPDShare/upload_to_mpdshare") {
1619 my $upload_folder = sprintf("%4.4d.%2.2d.%2.2d", $year+1900, $mon+1, $mday);
1620 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 &");
1621 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 &");
1622 }
1623 }
1624 }
1625}
1626
1627sub mbis_parse_arg {
1628 $mbis_arg_exist = 1;
1629 foreach $arg (@mbis_arg) {
1630 if ($arg =~ /^en_mbis$/i) {
1631 $arg_mbis_en = "TRUE";
1632 } elsif ($arg =~ /^dis_mbis$/i) {
1633 $arg_mbis_en = "FALSE";
1634 } elsif ($arg =~ /^dis_obj$/i) {
1635 $arg_mbis_en_obj_log = "FALSE";
1636 } elsif ($arg =~ /^en_obj$/i) {
1637 $arg_mbis_en_obj_log = "TRUE";
1638 } elsif ($arg =~ /^save_log$/i) {
1639 $arg_mbis_en_save_log = "TRUE";
1640 } else {
1641 # with error command
1642 $mbis_arg_exist = 0;
1643 return ;
1644 }
1645 }
1646 if ($arg_mbis_en ne "TRUE") {
1647 $arg_mbis_en_obj_log = "FALSE";
1648 $arg_mbis_en_save_log = "FALSE";
1649 }
1650}
1651
1652sub mbis_init {
1653 if (($ENV{'MTK_INTERNAL'} eq 'TRUE') && (-e "$mbis_conf_file")) {
1654 %mbis_conf = iniToHash($mbis_conf_file);
1655 $mbis_bm_list = $mbis_conf{'INIT_CONF'}->{'BM_LIST'};
1656 $mbis_project_list = $mbis_conf{'INIT_CONF'}->{'PROJECT_LIST'};
1657 @mbis_project_array=split /,/, $mbis_project_list;
1658 $mbis_en = $mbis_conf{'INIT_CONF'}->{'EN_ALL_PROJECT'};
1659 $mbis_en_obj_log = $mbis_conf{'INIT_CONF'}->{'EN_OBJ_LOG'};
1660 # force all project enable mbis
1661 # enable obj log for BM only
1662 if ($mbis_en eq "TRUE") {
1663 # check bm list
1664 if ($mbis_bm_list =~ /$ENV{USERNAME}/i) {
1665 $mbis_en = "TRUE";
1666 $mbis_en_obj_log = "TRUE";
1667 } else {
1668 $mbis_en = "TRUE";
1669 $mbis_en_obj_log = "FALSE";
1670 }
1671 }
1672 # deal with mbis option from arg
1673 if ($mbis_en eq "TRUE") {
1674 print("MBIS init enable\n");
1675 if ($mbis_en_obj_log eq "TRUE") {
1676 print("MBIS obj log enable\n");
1677 }
1678 if ($mbis_arg_exist == 1) {
1679 $mbis_en = $arg_mbis_en;
1680 $mbis_en_obj_log = $arg_mbis_en_obj_log;
1681 $mbis_en_save_log = $arg_mbis_en_save_log;
1682 if ($mbis_en eq "TRUE") {
1683 print("MBIS arg enable\n");
1684 } else {
1685 print("MBIS arg disable\n");
1686 }
1687 }
1688 } else {
1689 $mbis_en_obj_log = "FALSE";
1690 $mbis_en_save_log = "FALSE";
1691 print("MBIS init disable\n");
1692 }
1693 }
1694}
1695
1696sub mbis_success {
1697 my $build_custom_folder;
1698 my @files;
1699 my $elfname;
1700 my $elfsize;
1701 # get elf size
1702 $build_custom_folder = "$targetFolder";
1703 opendir (DIR, $build_custom_folder) or die "no folder : $build_custom_folder";
1704 my @files = grep {/^$project_name.*\.elf$/} readdir DIR;
1705 close DIR;
1706 if (@files == 1) {
1707 $elfname = pop @files;
1708 # add elf file name
1709 system("perl $mbis -i ELF_FILE,$elfname");
1710 $elfsize = -s "$build_custom_folder\\$elfname";
1711 # add elf file size
1712 system("perl $mbis -i ELF_SIZE,$elfsize");
1713 }
1714
1715 # add success flag
1716 system("perl $mbis -i SUCCESSFUL_BUILD,1");
1717}
1718
1719sub error_handle {
1720 my $build_folder = "$targetFolder";
1721 opendir (DIR, $build_folder) or die "no folder : $build_folder\n";
1722 my @files = grep {/.+\.bin$/} readdir DIR;
1723 close DIR;
1724 my $flag = 0;
1725 foreach (@files) {
1726 next if($_ =~ /BOOTLOADER/i);
1727 my $bin_file = $build_folder."/$_";
1728 if (-d "$bin_file") {
1729 rmtree($bin_file);
1730 $flag = 1;
1731 } elsif(-e "$bin_file") {
1732 unlink($bin_file) or die "Remove failed $!";
1733 $flag = 1;
1734 }
1735 }
1736 unlink("$build_folder/dep/postgen_dep/cp_dsp_files.det") if (-e "$build_folder/dep/postgen_dep/cp_dsp_files.det");
1737 print "Some errors happened during the build process. Delete the binary file\n" if($flag);
1738# [Linux] temporarily add
1739 unlink("nul") if($^O eq "linux" && -e "nul");
1740 unlink("NUL") if($^O eq "linux" && -e "NUL");
1741 &writeINI;
1742 exit 1;
1743}
1744
1745sub genCustombld {
1746 $bldPathName = "$projectFolder/Custom.bld";
1747 if(-e "make/common/rel/hq/USR.txt") {
1748 $bldValue = "FALSE";
1749 } else {
1750 $bldValue = "TRUE";
1751 }
1752 if(-e $bldPathName) {
1753 open BLDFILE,"<$projectFolder/Custom.bld" or die "Can not open $projectFolder/Custom.bld";
1754 while(<BLDFILE>) {
1755 if(/CUSTOM_RELEASE = $bldValue/) {
1756 close BLDFILE;
1757 return 0;
1758 }
1759 }
1760 close BLDFILE;
1761 }
1762 open BLDFILE,">$projectFolder/Custom.bld" or die "Can not open $projectFolder/Custom.bld";
1763 print BLDFILE "CUSTOM_RELEASE = $bldValue\n";
1764 close BLDFILE;
1765}
1766
1767sub read_remake_mods {
1768 my $file = $_[0];
1769 my @value = "";
1770 open (FILE_HANDLE, "<$file") or die "cannot open $file\n";
1771 while (<FILE_HANDLE>) {
1772 if (/^NEED_REMAKE_MODS\s*=\s*(.*)/) {
1773 @value = $1;
1774 }
1775 }
1776 return @value;
1777}
1778
1779sub gen_buildinfo_tmp {
1780 if (open FILE_HANDLE, ">$tmpFolder/~buildinfo.tmp") {
1781 my $timeStr = &CurrTimeStr;
1782 my $dbg_timeStr = $timeStr;
1783 $dbg_timeStr =~ s/ /_/g;
1784 $dbg_timeStr =~ s/:/_/g;
1785 $dbg_timeStr =~ s/\//_/g;
1786 print FILE_HANDLE "PROJECT_NAME=$project_name\n";
1787 print FILE_HANDLE "FLAVOR=$flavor\n";
1788 print FILE_HANDLE "ORIACTION=$oriaction\n";
1789 print FILE_HANDLE "APLAT=$plat\n";
1790 print FILE_HANDLE "CMD_ARGU=$fullOpts\n";
1791 print FILE_HANDLE "BUILD_DATE_TIME=$timeStr\n";
1792 # mbis options
1793 print FILE_HANDLE "MBIS_EN=$mbis_en\n";
1794 print FILE_HANDLE "MBIS_EN_OBJ_LOG=$mbis_en_obj_log\n";
1795 print FILE_HANDLE "DBG_BUILD_DATE_TIME=$dbg_timeStr\n";
1796 print FILE_HANDLE "NO_LTELIB=$no_ltelib\n";
1797 print FILE_HANDLE "NO_LTECGEN=$no_ltecgen\n";
1798 print FILE_HANDLE "NO_PCIBT=$no_pcibt\n";
1799 print FILE_HANDLE "MCF_OTA_NAME=$ota_name\n";
1800 print FILE_HANDLE "MODIS_CONFIG=$modis_config\n";
1801 print FILE_HANDLE "NO_DSP=$no_dsp\n";
1802 print FILE_HANDLE "NO_WARNING_AS_ERROR=$no_warning_as_error\n";
1803 print FILE_HANDLE "CHECK_FO_LICENSE=$check_fo_license\n";
1804 print FILE_HANDLE "LICENSE_INFO=$license_info\n";
1805 print FILE_HANDLE "CUST_LIC=$cust_lic\n";
1806 print FILE_HANDLE "VARIATION_PROJ=$VarioationProj_name\n";
1807 print FILE_HANDLE "SRC_MAX_PACKAGE=$chk_rel_pkg\n";
1808 print FILE_HANDLE "UPDATE_DSP=$update_dsp\n";
1809 close FILE_HANDLE;
1810 } else {
1811 warn "Fail to write $tmpFolder/~buildinfo.tmp: $!\n";
1812 }
1813}