sbsv1/abld/e32util/prepdef.pl
changeset 607 378360dbbdba
parent 606 30b30f9da0b7
equal deleted inserted replaced
591:22486c9c7b15 607:378360dbbdba
       
     1 #!/usr/bin/perl
       
     2 # Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description:
       
    15 # e32toolp/e32util/prepdef.pl
       
    16 # 
       
    17 #
       
    18 
       
    19 
       
    20 use FindBin;		# for FindBin::Bin
       
    21 use Getopt::Long;
       
    22 
       
    23 my $PerlLibPath;    # fully qualified pathname of the directory containing our Perl modules
       
    24 
       
    25 BEGIN {
       
    26 # check user has a version of perl that will cope
       
    27 	require 5.005_03;
       
    28 # establish the path to the Perl libraries: currently the same directory as this script
       
    29 	$PerlLibPath = $FindBin::Bin;	# X:/epoc32/tools
       
    30 	if ($^O eq "MSWin32")
       
    31 	{
       
    32 		$PerlLibPath =~ s/\//\\/g;	# X:\epoc32\tools
       
    33 		$PerlLibPath .= "\\";
       
    34 	}
       
    35 }
       
    36 
       
    37 use lib $PerlLibPath;
       
    38 use Defutl;
       
    39 
       
    40 # Version
       
    41 my $MajorVersion = 1;
       
    42 my $MinorVersion = 1;
       
    43 my $PatchVersion = 1;
       
    44 
       
    45 # THE MAIN PROGRAM SECTION
       
    46 ##########################
       
    47 
       
    48 {
       
    49 	
       
    50 
       
    51 	# process the command-line
       
    52 	unless (@ARGV==2 ||  @ARGV==3 || @ARGV==4) {
       
    53 		&Usage;
       
    54 	}
       
    55 	my ($FRZFILE,$GENFILE,$DATASWITCH,$ABSENTSYM)=@ARGV;
       
    56 	
       
    57 	
       
    58 
       
    59 #	Read the Frozen .DEF file
       
    60 	my @FrzDataStruct;
       
    61 	my $FrzExportsOn=0;
       
    62 	eval { &Def_ReadFileL(\@FrzDataStruct, $FRZFILE, $FrzExportsOn); };
       
    63 	die $@ if $@;
       
    64 
       
    65 	eval { &WriteOutputFileL(\@FrzDataStruct, $GENFILE, $DATASWITCH, $ABSENTSYM); };
       
    66 	die $@ if $@;
       
    67 
       
    68 	exit;
       
    69 }
       
    70 
       
    71 #######################################################################
       
    72 # SUBROUTINES
       
    73 #######################################################################
       
    74 
       
    75 sub Usage () {
       
    76 
       
    77 	print(
       
    78 		"\n",
       
    79 		"PREPDEF - Prepare frozen DEF file for library generation V$MajorVersion.$MinorVersion.$PatchVersion\n",
       
    80 		"\n",
       
    81 		"PREPDEF [frozen .DEF file] [processed .DEF file] [nodatasizes] [entrypoint_name]\n",
       
    82 		"\n",
       
    83 		"\n",
       
    84 		"\n"
       
    85 	);
       
    86 	exit 1;
       
    87 }
       
    88 
       
    89 
       
    90 
       
    91 sub WriteOutputFileL ($$$$) {
       
    92 	my ($FrzStructRef, $FILE, $DATASWITCH, $ABSENTSYM)=@_;
       
    93 
       
    94 	my @Text;
       
    95 
       
    96 	if ($ABSENTSYM) {
       
    97 		$ABSENTSYM = '='.$ABSENTSYM;
       
    98 	}
       
    99 
       
   100 #	Process the frozen .DEF file
       
   101 	my $FrzRef;
       
   102 	my $ExportsDeclared;
       
   103 
       
   104 #	get the lines of text from the frozen .DEF file
       
   105 	foreach $FrzRef (@$FrzStructRef) {
       
   106 		next if (!$FrzRef);
       
   107 		if (!defined($$FrzRef{Ordinal})) {
       
   108 			push @Text, $$FrzRef{Line};
       
   109 			$ExportsDeclared = 1 if ($$FrzRef{Line} =~ /^\s*EXPORTS\s*(\s+\S+.*)?$/io);
       
   110 			next;
       
   111 		}
       
   112 		my $Comment='';
       
   113 		if ($$FrzRef{Comment}) {
       
   114 			$Comment=" ; $$FrzRef{Comment}";
       
   115 		}
       
   116 #		Mention if it is a Data symbol along with its size.
       
   117 		my $data = "";
       
   118 		if(defined $$FrzRef{Data})
       
   119 			{			
       
   120 			if ($DATASWITCH eq "nodatasizes")
       
   121 				{
       
   122 				$data = " DATA";
       
   123 				}
       
   124 			else
       
   125 				{
       
   126 				$data = " DATA $$FrzRef{Size}";
       
   127 				}
       
   128 			}
       
   129 		my $r3unused = $$FrzRef{R3Unused} ? " R3UNUSED" : "";
       
   130 		my $ord = $$FrzRef{Ordinal};
       
   131 		if ($$FrzRef{Absent}) {
       
   132 			push @Text, "\t\"_._.absent_export_$ord\"$ABSENTSYM \@ $ord NONAME$data$r3unused$Comment\n";
       
   133 		} else {
       
   134 			my $export = $$FrzRef{ExportName};
       
   135 			if ($export ne $$FrzRef{Name})
       
   136 				{
       
   137 				$export .= "=$$FrzRef{Name}";
       
   138 				}
       
   139 			push @Text, "\t$export \@ $ord NONAME$data$r3unused$Comment\n";
       
   140 		}
       
   141 	}
       
   142 	unshift @Text, "EXPORTS\n" unless ($ExportsDeclared);
       
   143 
       
   144 #	add a terminating newline
       
   145 	push @Text, "\n";
       
   146 
       
   147 #	write the new frozen .DEF file
       
   148 	eval { &Def_WriteFileL(\@Text, $FILE); };
       
   149 	die $@ if $@;
       
   150 }
       
   151