blob: cea71090fead2c6a97d72306e45c7f1dd006eaa7 [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001#
2# BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
3# THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
4# RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
5# AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
6# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
7# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
8# NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
9# SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
10# SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
11# THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
12# NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
13# SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
14#
15# BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
16# LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
17# AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
18# OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
19# MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
20#
21# THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
22# WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
23# LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
24# RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
25# THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
26#
27
28package tools::pack_dep_gen;
29use File::Basename;
30use File::Path;
31use strict;
32use Cwd qw(abs_path);
33use Exporter;
34use vars qw(@ISA @EXPORT @EXPORT_OK);
35@ISA = qw(Exporter);
36@EXPORT = qw(PushDependFile PrintDependModule PrintToDep);
37@EXPORT_OK = qw(PushDependFile PrintDependModule PrintToDep);
38
39return 1;
40
41my @collect_file;
42my $target;
43
44#*************************************************************************************************
45# Print source file to dependency file
46#*************************************************************************************************
47sub PrintToDep {
48 $target = shift;
49 my $printTarget = $target;
50 if ($^O eq "linux"){
51 if ($printTarget =~ /^(\.\.\/)*(\S*)/) {
52 $printTarget = $2;
53 }
54
55 foreach my $value (values %INC) {
56 if ($value =~ /[\/\\]Perl([\/\\].*)?[\/\\]lib[\/\\]/i) {
57 # skip system module
58 }
59 else {
60 push(@collect_file,$value);
61 }
62 }
63
64 my $file_dir = dirname($target);
65 mkpath($file_dir) or die "[Error:][pack_gen_dep.pm]Can Not create $file_dir! $!" if(!-d "$file_dir");
66
67 my $current_abs_path = abs_path("./");
68 my $element;
69 my $abs_element;
70 my $mcu_abs_path;
71 my $uni_com_abs_path;
72 open (det_file,">>$target") or &pack_error_handler("cannot open $target!", __FILE__, __LINE__);
73
74 if ($current_abs_path =~ /mcu(.*)/){
75 $uni_com_abs_path = $current_abs_path;
76 $uni_com_abs_path =~ s/\/mcu(.*)//;
77 } else {
78 print "[Error]: Cannot figure out the current path: $current_abs_path, please CHECK!\n";
79 exit 1;
80 }
81
82 $mcu_abs_path = "$uni_com_abs_path/mcu";
83 foreach $element (@collect_file){
84 $abs_element = abs_path($element);
85 $abs_element =~ s/$mcu_abs_path\///;
86 $abs_element =~ s/$uni_com_abs_path/../;
87 print det_file "$printTarget: $abs_element\n";
88 }
89 close(det_file);
90 }
91}
92
93#*************************************************************************************************
94# store source file to dependency file
95#*************************************************************************************************
96sub PushDependFile {
97 my $file = shift;
98
99 if (-e $file) {
100 push(@collect_file,$file);
101 }
102 else {
103 print "[Error]: $file does not exist in codebase, plase help to check!\n";
104 exit 1;
105 }
106}
107
108#*************************************************************************************************
109# Get source file from script
110#*************************************************************************************************
111sub PrintDependModule {
112 my $file = shift;
113 if ($^O eq "linux"){
114 if ($file eq "") {
115 PushDependFile($0);
116 }
117 else {
118 PushDependFile($file);
119 }
120 }
121}
122
123#*************************************************************************************************
124# Error Handling Message
125#*************************************************************************************************
126sub pack_error_handler {
127 my ($error_msg, $pack_file, $line_no) = @_;
128 my $final_error_msg = "Error: $error_msg at $pack_file line $line_no\n";
129 print "\n\n$final_error_msg";
130 die $final_error_msg;
131}