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