blob: 09f871d0c2e0cca9912a90fb67d3c323a78bede1 [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$custom = "Dragonfly_Demo";
37$proj = "gprs"; # gprs or gsm
38@objs = ();#qw(custom_wap_cust_pack.obj nvram_cust_pack.obj);
39$outputdir = "C:\\CustPack\\BIN";
40$dboutputdir = "C:\\CustPack";
41$extractObjExe = "ExtractObj.exe";
42
43$ini_file = "ExtractObj.ini";
44if (!-e $ini_file) {
45 die "$ini_file OR pcore\\tools\\$ini_file did NOT exist!\n" if (!-e "pcore\\tools\\$ini_file");
46 $ini_file = "pcore\\tools\\$ini_file";
47}
48
49open INI_FILE, "<$ini_file" or die "cannot open $ini_file\n";
50
51while (<INI_FILE>) {
52 if (/^\s*CUSTOM\s*=\s*\"(\S+)\"\s/) {
53 $custom = $1;
54 } elsif (/^\s*PROJECT\s*=\s*\"(\S+)\"\s/) {
55 $proj = $1;
56 } elsif (/^\s*OBJ\d+\s*=\s*\"(\S+)\"\s/) {
57 push(@objs, $1);
58 } elsif (/^\s*OUTPUTDIR\s*=\s*\"(\S+)\"\s/) {
59 $dboutputdir = $1;
60 $outputdir = $1."\\BIN";
61 }
62}
63close INI_FILE;
64
65while ($#ARGV != -1) {
66 if ($ARGV[0] =~ /-h/) {
67 Usage();
68 } elsif ($ARGV[0] =~ /^custom=(\w+)/) {
69 $custom = $1;
70 } elsif ($ARGV[0] =~ /(gprs|gsm|umts)/i) {
71 $proj = $ARGV[0];
72 } elsif ($ARGV[0] =~ /^objs=(\S+)/) {
73 @objs = split(',', $1);
74 } else {
75 Usage();
76 }
77 shift(@ARGV);
78}
79
80$fromelf = "fromelf";
81$builddir = "build\\${custom}\\${proj}";
82
83$makefolder = "make";
84if (!-d $makefolder) {
85 die "$makefolder OR ..\\$makefolder did NOT exist!\n" if (!-d "..\\$makefolder");
86 $makefolder = "..\\$makefolder";
87}
88$custombld = "${makefolder}\\custom.bld";
89die "$custombld did NOT exist!\n" if (!-e $custombld);
90open (FILE_HANDLE, "<$custombld") or die "cannot open $custombld\n";
91while (<FILE_HANDLE>) {
92 if (/^(\S+)\s*=\s*(\S+)/) {
93 $keyname = lc($1);
94 defined($${keyname}) && warn "$1 redefined in $custombld!\n";
95 $${keyname} = uc($2);
96 }
97}
98close FILE_HANDLE;
99
100if ($custom_release eq "TRUE") {
101 $dbfileprefix = "BPLGUInfoCustomAppSrcP_MT62";
102} else {
103 $dbfileprefix = "BPLGUInfoCustomApp_MT62";
104}
105
106
107#system("rd /s /q $outputdir") if (-d $outputdir);
108#system("rd /s /q $dboutputdir") if (-d $dboutputdir);
109system("md $dboutputdir") if (!-d $dboutputdir);
110system("md $outputdir") if (!-d $outputdir);
111if (!-d $builddir) {
112 die "$builddir OR ..\\$builddir did NOT exist!\n" if (!-d "..\\$builddir");
113 $builddir = "..\\$builddir";
114}
115
116$not_found_flag = 0;
117foreach $chkobj (@objs) {
118 if (!-e $chkobj) { $not_found_flag = 1; last; }
119 else { $found{$chkobj} = $chkobj; }
120}
121
122if ($not_found_flag == 0) { goto DEAL_OBJ; }
123
124if (opendir(OBJDIRS, $builddir)) {
125 @syndirs = sort readdir(OBJDIRS);
126 closedir(OBJDIRS);
127 shift(@syndirs); shift(@syndirs); ## . and ..
128} else {
129 die "Could not open $builddir";
130}
131
132CHIP_DIR: foreach $tarDir (@syndirs) {
133 next if ($tarDir !~ m/o$/);
134 $tarDir = "$builddir\\$tarDir";
135 if (opendir(OBJDIRS, $tarDir)) {
136 @moduledirs = sort readdir(OBJDIRS);
137 closedir(OBJDIRS);
138 shift(@moduledirs); shift(@moduledirs); ## . and ..
139 } else {
140 warn "Could not open $tarDir\n";
141 next;
142 }
143
144 foreach $chkobj (@objs) { undef($found{$chkobj}); }
145
146 CHIP_OBJ: foreach $m (@moduledirs) {
147 next if ($m eq "lib");
148 $tarDir2 = "$tarDir\\$m";
149 if (opendir(OBJDIRS, $tarDir2)) {
150 @objfiles = sort readdir(OBJDIRS);
151 closedir(OBJDIRS);
152 shift(@objfiles); shift(@objfiles); ## . and ..
153 } else {
154 warn "Could not open $tarDir2\n";
155 next;
156 }
157 foreach $objfile (@objfiles) {
158 foreach $chkobj (@objs) {
159 next if (defined($found{$chkobj}));
160 next if ($objfile ne $chkobj);
161 $found{$chkobj} = "$tarDir2\\$chkobj";
162 }
163 }
164 foreach $chkobj (@objs) { next CHIP_OBJ if (!defined($found{$chkobj}));}
165 print "Found all obj files @ $tarDir\n";
166 last CHIP_DIR;
167 }
168}
169
170DEAL_OBJ:
171$allObjs = "";
172foreach $chkobj (@objs) {
173 $chktxt = $found{$chkobj};
174 die "$chkobj did NOT exist!\n" if (!-e $found{$chkobj});
175 $allObjs .= " $chktxt";
176 $chktxt =~ s/\.obj/\.txt/;
177 system("del /f /q $chktxt") if (-e $chktxt);
178 print("$fromelf -text -v -s $found{$chkobj} > $chktxt\n");
179 system("$fromelf -text -v -s $found{$chkobj} > $chktxt");
180}
181
182if (!-e $extractObjExe) {
183 die "$extractObjExe OR pcore\\tools\\$extractObjExe did NOT exist!\n" if (!-e "pcore\\tools\\$extractObjExe");
184 $extractObjExe = "pcore\\tools\\$extractObjExe";
185}
186print("$extractObjExe $outputdir $allObjs\n");
187system("$extractObjExe $outputdir $allObjs");
188
189$dbfolder = "tst\\database";
190
191if (!-d $dbfolder) {
192 die "$dbfolder OR ..\\$dbfolder did NOT exist!\n" if (!-d "..\\$dbfolder");
193 $dbfolder = "..\\$dbfolder";
194}
195print("$extractObjExe $outputdir $allObjs\n");
196if (opendir(OBJDIRS, $dbfolder)) {
197 @dbfiles= sort readdir(OBJDIRS);
198 closedir(OBJDIRS);
199 shift(@dbfiles); shift(@dbfiles); ## . and ..
200} else {
201 die "Could not open $dbfolder\n";
202}
203foreach $dbfile (@dbfiles) {
204 next if ($dbfile !~ /$dbfileprefix/);
205 system("copy /Y ${dbfolder}\\$dbfile ${dboutputdir}\\$dbfile");
206}
207
208exit 0;
209
210sub Usage {
211 print <<"__EOFUSAGE";
212Usage: $0 [-h | custom=\$custom | (gprs|gsm) | [objs=a.obj,b.obj]]
213 -h Help.
214__EOFUSAGE
215 exit 0;
216}