blob: 04ca9fba156a257d4cdb3576abfaea96e9e836ee [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001#!/usr/bin/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#
35#
36#*****************************************************************************
37#
38# Filename:
39# ---------
40# MauiInfo.pm
41#
42# Description:
43# ------------
44# this script is used to handle MAUI related info.
45#
46# Auther:
47# -------
48# Shinn Lin
49#
50# Note:
51# -----
52#
53# Log:
54# -----
55# 2010/02/10 Create.
56#
57
58#BEGIN { push @INC, 'U:\\00MyPerlLib'} # add additional library path
59package MauiInfo;
60use strict;
61
62#******************************************************************************
63# Global Data
64#******************************************************************************
65my $f_cacheIncPath = 1;
66
67my $g_prjName = '';
68my $g_mcuPath = ".";
69my @g_incMods = ("plutommi", "venusmmi");
70my @g_incPath = ();
71
72my $g_isCompileInfoReady = 0;
73my $g_removeTempFile = 1;
74
75
76
77return 1; # return true
78
79#******************************************************************************
80# FUNCTION
81# setInfo
82# DESCRIPTION
83# xxx
84# PARAMETERS
85# xxx
86# RETURNS
87# xxx
88#******************************************************************************
89sub setInfo()
90{
91 ($g_mcuPath, $g_prjName) = @_;
92}
93
94
95#******************************************************************************
96# FUNCTION
97# setIncMods
98# DESCRIPTION
99# xxx
100# PARAMETERS
101# xxx
102# RETURNS
103# xxx
104#******************************************************************************
105sub setIncMods()
106{
107 @g_incMods = @_;
108}
109
110
111#******************************************************************************
112# FUNCTION
113# getIncPath
114# DESCRIPTION
115# xxx
116# PARAMETERS
117# xxx
118# RETURNS
119# xxx
120#******************************************************************************
121sub getIncPath()
122{
123 my ($incFile) = @_;
124
125 if (!$g_isCompileInfoReady)
126 {
127 &readCompileInfo(\@g_incMods, \@g_incPath, 0);
128 $g_isCompileInfoReady = 1;
129 }
130
131 return searchIncPath($incFile, \@g_incPath);
132
133}
134
135
136
137#******************************************************************************
138# Local Function
139#******************************************************************************
140
141#******************************************************************************
142# FUNCTION
143# searchIncPath
144# DESCRIPTION
145# xxx
146# PARAMETERS
147# xxx
148# RETURNS
149# xxx
150#******************************************************************************
151my %incCacheHash = ();
152sub searchIncPath()
153{
154 my ($incFile, $incPath_aref) = @_;
155
156 if ($f_cacheIncPath)
157 {
158 return $incCacheHash{$incFile} if (defined $incCacheHash{$incFile});
159 }
160
161 foreach my $incPath (@{$incPath_aref})
162 {
163 my $filepath = "$incPath\\$incFile";
164 if (-e $filepath)
165 {
166 $incCacheHash{$incFile} = $incPath if ($f_cacheIncPath);
167 return $incPath;
168 }
169 }
170 return "";
171}
172
173
174#******************************************************************************
175# FUNCTION
176# readCompileInfo
177# DESCRIPTION
178# xxx
179# PARAMETERS
180# xxx
181# RETURNS
182# xxx
183#******************************************************************************
184sub readCompileInfo()
185{
186 my ($incMod_aref, $incPath_aref, $def_aref) = @_;
187
188 if ($g_prjName eq "")
189 {
190 push @{$incPath_aref}, "."; # no project specified, just put current dir to inc path
191 print "[Warning] no compile info!\n";
192 return;
193 }
194
195 my $infoFilename = "$g_mcuPath\\build\\$g_prjName\\log\\info.log";
196
197 my %defHash = ();
198 my %incHash = ();
199
200 my $inSection;
201 if ($incPath_aref || $def_aref)
202 {
203 # read common options and common include path from info.log
204 open(hFile, "<$infoFilename") or die "can't open $infoFilename";
205 my @fileData = <hFile>;
206 close(hFile);
207
208 foreach my $line (@fileData)
209 {
210 if ($line =~ /\[ COMMON OPTION \]/)
211 {
212 $inSection = 1;
213 next;
214 }
215 elsif ($line =~ /\[ COMMON INCLUDE PATH \]/)
216 {
217 $inSection = 2;
218 next;
219 }
220
221 if ($line =~ /(^[^\[][^\s]*)/)
222 {
223 if ($inSection == 1)
224 {
225 #print "$1\n";
226 if ($def_aref && !(defined $defHash{$1}))
227 {
228 push @{$def_aref}, $1;
229 $defHash{$1} = 1;
230 }
231 }
232 elsif ($inSection == 2)
233 {
234 my $incPath = "$1";
235
236 if ($incPath !~ /:/)
237 {
238 $incPath = "$g_mcuPath\\$incPath";
239 }
240 #print "$incPath\n";
241
242 if ($incPath_aref && !(defined $incHash{$incPath}))
243 {
244 push @{$incPath_aref}, $incPath;
245 $incHash{$incPath} = 1;
246 }
247 }
248 }
249 else
250 {
251 $inSection = 0;
252 }
253 }
254 }
255
256 # read inc from *.inc
257 if ($incPath_aref)
258 {
259 foreach my $myMod (@{$incMod_aref})
260 {
261 my @incFiles = ();
262 if (&getFileList("$g_mcuPath\\make\\$myMod\\*.inc", 1, \@incFiles) > 0)
263 {
264 foreach my $incFilename (@incFiles)
265 {
266 open(hFile, "<$incFilename") or die "can't open $incFilename";
267 my @fileData = <hFile>;
268 close(hFile);
269
270 foreach my $line (@fileData)
271 {
272 if ($line =~ /(^[^\s]+)([\s]*$)/)
273 {
274 my $incPath = "$g_mcuPath\\$1";
275 #$incPaths = "$incPaths\n-I$g_mcuPath\\$1";
276 if (!(defined $incHash{$incPath}))
277 {
278 push @{$incPath_aref}, $incPath;
279 $incHash{$incPath} = 1;
280 }
281 }
282 }
283 }
284 }
285 else
286 {
287 print "[Warning] can't find *.inc for $myMod\n";
288 }
289 }
290 }
291
292 # read macro from *.def
293 if ($def_aref)
294 {
295 foreach my $myMod (@{$incMod_aref})
296 {
297 my @defFiles = ();
298 if (&getFileList("$g_mcuPath\\make\\$myMod\\*.def", 1, \@defFiles) > 0)
299 {
300 foreach my $defFilename (@defFiles)
301 {
302 open(hFile, "<$defFilename") or die "can't open $defFilename";
303 my @fileData = <hFile>;
304 close(hFile);
305
306 foreach my $line (@fileData)
307 {
308 if ($line =~ /(^[^\s]+)([\s]*$)/)
309 {
310 #$commonOptions = "$commonOptions\n-D$1";
311 if (!(defined $defHash{$1}))
312 {
313 push @{$def_aref}, $1;
314 $defHash{$1} = 1;
315 }
316 }
317 }
318 }
319 }
320 else
321 {
322 print "[Warning] can't find *.def for $myMod\n";
323 }
324 }
325 }
326}
327
328
329#******************************************************************************
330# FUNCTION
331# getFileList
332# DESCRIPTION
333# get file/path list for given search string
334# PARAMETERS
335# xxx
336# RETURNS
337# xxx
338#******************************************************************************
339sub getFileList()
340{
341 my $rootDir;
342 my $incSubDir; # include sub dir (1) or not (0)
343 my $fileList_ref;
344
345 ($rootDir, $incSubDir, $fileList_ref) = @_;
346
347 my @fileData = ();
348
349 # get file list
350 my $tmpFilename = "~tmpFile.lst";
351
352 my $dirStr = "$rootDir /b";
353 $dirStr .= " /s" if ($incSubDir);
354
355 system("dir ".$dirStr." > $tmpFilename");
356 open(hFile, "<$tmpFilename") or die "[ERROR] can't open $tmpFilename\n";
357 @fileData = <hFile>;
358 close(hFile);
359 system("del $tmpFilename") if ($g_removeTempFile);
360
361 foreach my $line (@fileData)
362 {
363 my $name = $line;
364 push @{$fileList_ref}, $name if ($name !~ /^[\s]*$/);
365 #print "$name";
366 }
367 return scalar(@{$fileList_ref});
368}
369