sbsv1/abld/genutil/genutl.pm
author Zheng Shen <zheng.shen@nokia.com>
Mon, 30 Aug 2010 15:04:06 +0800
changeset 631 9435b9008a58
parent 599 fa7a3cc6effd
permissions -rw-r--r--
ROM Tools 13.1.0.1 Bug468 initialized static data built into a static library does not get initialized correctly
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
599
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     1
# Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     2
# All rights reserved.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     3
# This component and the accompanying materials are made available
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     4
# under the terms of "Eclipse Public License v1.0"
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     5
# which accompanies this distribution, and is available
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     6
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     7
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     8
# Initial Contributors:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     9
# Nokia Corporation - initial contribution.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    10
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    11
# Contributors:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    12
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    13
# Description:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    14
# Contains utility subroutines for MAKMAKE and associated scripts
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    15
# 
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
package Genutl;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    19
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    20
require Exporter;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    21
@ISA=qw(Exporter);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    22
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    23
@EXPORT=qw(
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    24
	Genutl_AnyToHex
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    25
	Genutl_VersionToUserString
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    26
	Genutl_VersionToHexString
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    27
	Genutl_VersionToFileAugment
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    28
	Genutl_StringToVersion
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    29
	Genutl_ParseVersionedName
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    30
	Genutl_NormaliseVersionedName
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    31
);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    32
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    33
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    34
sub Genutl_AnyToHex ($) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    35
# changes decimal and hexadecimal numbers to the required hexadecimal format
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    36
	my $Num=$_[0];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    37
	$Num=lc $Num;	# lower casing the x specifying hexadecimal essential
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    38
	if ($Num=~/^(\d{1,10}|0x[\dabcdef]{1,8})$/o) { # this isn't perfect
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    39
		$Num=oct $Num if $Num=~/^0x/o;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    40
		return sprintf "0x%.8lx", $Num;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    41
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    42
	return undef;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    43
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    44
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    45
sub Genutl_VersionToUserString(%) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    46
	my (%ver) = @_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    47
	return sprintf("%d\.%d", $ver{major}, $ver{minor});
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
sub Genutl_VersionToHexString(%) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    51
	my (%ver) = @_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    52
	return sprintf("%04x%04x", $ver{major}, $ver{minor});
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    53
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    54
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    55
sub Genutl_VersionToFileAugment(%) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    56
	my (%ver) = @_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    57
	return sprintf("{%04x%04x}", $ver{major}, $ver{minor});
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    58
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    59
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    60
sub Genutl_StringToVersion($) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    61
	my ($s) = @_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    62
	if ($s =~ /^(\d+)\.(\d+)$/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    63
		my %ver;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    64
		$ver{major} = $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    65
		$ver{minor} = $2;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    66
		if ($ver{major}<32768 and $ver{minor}<32768) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    67
			return %ver;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    68
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    69
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    70
	return undef;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    71
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    72
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    73
sub Genutl_ParseVersionedName($) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    74
	my ($nref) = @_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    75
	return 1 unless ($$nref =~ /\{|\}/);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    76
	my $a;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    77
	my $b;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    78
	if ($$nref =~ /(.*)\{((\d|a|b|c|d|e|f){8})\}(.*?)/i) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    79
		$a = $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    80
		$b = $3;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    81
	} elsif ($$nref =~ /(.*)\{\s*(\d+)\s*\.\s*(\d+)\s*\}(.*?)$/i) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    82
		$a = $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    83
		$b = $4;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    84
		my $major = $2;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    85
		my $minor = $3;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    86
		return 0 if ($major>=32768 or $minor>=32768);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    87
		$$nref = $a.sprintf("{%04x%04x}",$major,$minor).$b;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    88
	} else {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    89
		return 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    90
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    91
	if ($a=~/\{|\}/ or $b=~/\{|\}/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    92
		return 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    93
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    94
	return 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    95
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    96
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    97
sub Genutl_NormaliseVersionedName($) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    98
	my ($name) = @_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    99
	if ($name =~ /(.*)\{\s*(\d+)\s*\.\s*(\d+)\s*\}(.*?)$/i) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   100
		my $a = $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   101
		my $b = $4;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   102
		my $major = $2;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   103
		my $minor = $3;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   104
		return $a.sprintf("{%04x%04x}",$major,$minor).$b if ($major<32768 and $minor<32768);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   105
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   106
	return $name;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   107
}