rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame] | 1 | #!/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";
|
| 44 | if (!-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 |
|
| 49 | open INI_FILE, "<$ini_file" or die "cannot open $ini_file\n";
|
| 50 |
|
| 51 | while (<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 | }
|
| 63 | close INI_FILE;
|
| 64 |
|
| 65 | while ($#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";
|
| 84 | if (!-d $makefolder) {
|
| 85 | die "$makefolder OR ..\\$makefolder did NOT exist!\n" if (!-d "..\\$makefolder");
|
| 86 | $makefolder = "..\\$makefolder";
|
| 87 | }
|
| 88 | $custombld = "${makefolder}\\custom.bld";
|
| 89 | die "$custombld did NOT exist!\n" if (!-e $custombld);
|
| 90 | open (FILE_HANDLE, "<$custombld") or die "cannot open $custombld\n";
|
| 91 | while (<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 | }
|
| 98 | close FILE_HANDLE;
|
| 99 |
|
| 100 | if ($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);
|
| 109 | system("md $dboutputdir") if (!-d $dboutputdir);
|
| 110 | system("md $outputdir") if (!-d $outputdir);
|
| 111 | if (!-d $builddir) {
|
| 112 | die "$builddir OR ..\\$builddir did NOT exist!\n" if (!-d "..\\$builddir");
|
| 113 | $builddir = "..\\$builddir";
|
| 114 | }
|
| 115 |
|
| 116 | $not_found_flag = 0;
|
| 117 | foreach $chkobj (@objs) {
|
| 118 | if (!-e $chkobj) { $not_found_flag = 1; last; }
|
| 119 | else { $found{$chkobj} = $chkobj; }
|
| 120 | }
|
| 121 |
|
| 122 | if ($not_found_flag == 0) { goto DEAL_OBJ; }
|
| 123 |
|
| 124 | if (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 |
|
| 132 | CHIP_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 |
|
| 170 | DEAL_OBJ:
|
| 171 | $allObjs = "";
|
| 172 | foreach $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 |
|
| 182 | if (!-e $extractObjExe) {
|
| 183 | die "$extractObjExe OR pcore\\tools\\$extractObjExe did NOT exist!\n" if (!-e "pcore\\tools\\$extractObjExe");
|
| 184 | $extractObjExe = "pcore\\tools\\$extractObjExe";
|
| 185 | }
|
| 186 | print("$extractObjExe $outputdir $allObjs\n");
|
| 187 | system("$extractObjExe $outputdir $allObjs");
|
| 188 |
|
| 189 | $dbfolder = "tst\\database";
|
| 190 |
|
| 191 | if (!-d $dbfolder) {
|
| 192 | die "$dbfolder OR ..\\$dbfolder did NOT exist!\n" if (!-d "..\\$dbfolder");
|
| 193 | $dbfolder = "..\\$dbfolder";
|
| 194 | }
|
| 195 | print("$extractObjExe $outputdir $allObjs\n");
|
| 196 | if (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 | }
|
| 203 | foreach $dbfile (@dbfiles) {
|
| 204 | next if ($dbfile !~ /$dbfileprefix/);
|
| 205 | system("copy /Y ${dbfolder}\\$dbfile ${dboutputdir}\\$dbfile");
|
| 206 | }
|
| 207 |
|
| 208 | exit 0;
|
| 209 |
|
| 210 | sub Usage {
|
| 211 | print <<"__EOFUSAGE";
|
| 212 | Usage: $0 [-h | custom=\$custom | (gprs|gsm) | [objs=a.obj,b.obj]]
|
| 213 | -h Help.
|
| 214 | __EOFUSAGE
|
| 215 | exit 0;
|
| 216 | }
|