sbsv1/abld/e32util/featurevariantparser.pm
author andy simpson <andrews@symbian.org>
Fri, 30 Jul 2010 15:14:33 +0100
changeset 622 c26070468a42
parent 599 fa7a3cc6effd
permissions -rw-r--r--
Add export for s60ibymacros.pm (re-applies missing part of fix for Bug 2901
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
599
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     1
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     2
# Copyright (c) 2007 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
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    16
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    17
# Module FEATUREVARIANTPARSER. Parses .VAR files and returns key variables.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    18
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    19
# The following hashes can be used with this module:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    20
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    21
# NAME 				-> Returns the name of the variant file (without the extension)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    22
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    23
# FULLPATH 			-> Returns the full path of the variant file (including the extension)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    24
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    25
# VALID 			-> Set to 1 if the variant file is valid, otherwise set to 0
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    26
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    27
# VIRTUAL 			-> Set to 1 if the variant is a grouping node, otherwise set to 0
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    28
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    29
# ROM_INCLUDES 		-> Returns a pointer to the list of ROM_INCLUDES (including Parent nodes).
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    30
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    31
# BUILD_INCLUDES 	-> Returns a pointer to the list of BUILD_INCLUDES (including Parent nodes).
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    32
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    33
# VARIANT_HRH 		-> Returns the full VARIANT_HRH file path used by the VAR file.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    34
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    35
# PARENTS			-> Returns a pointer to the list of all the parent nodes, starting with immediate parent
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    36
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    37
# CHILDREN			-> Returns a pointer to the list of all the children nodes.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    38
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    39
# USAGE : The GetVariant method should only be called using featurevariantparser->GetVariant(var_name, directory(optional) );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    40
# If the directory for the VAR file is not supplied,the default directory will be searched for var_name.var
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    41
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    42
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    43
package featurevariantparser;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    44
use File::Spec;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    45
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    46
my @buildinclude;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    47
my @rominclude;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    48
my @parents;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    49
my @childNodes;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    50
my $virtual;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    51
my $childNodeStatus;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    52
my $varianthrh;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    53
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    54
my $defaultDir = "$ENV{EPOCROOT}epoc32\\tools\\variant";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    55
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    56
my $dir;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    57
my $fullpath;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    58
my $fulldir;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    59
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    60
my $pathregex = '.+[^\s]'  ;   # Regex to match all characters (including \ or /), excluding whitespaces.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    61
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    62
our $verbose = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    63
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    64
# Wrapper function to return all the correct variables
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    65
# Arguments : (Variant Name, Variant Directory(optional))
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    66
# Returns a Hash.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    67
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    68
# Note: This has to return a copy of all the data - no references!
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    69
#  There are package globals that are reused on a call to this function
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    70
#  so references would go out of date after repeated calls to GetVariant
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    71
#  This package should have been written using objects - too late now
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    72
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    73
sub GetVariant
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    74
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    75
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    76
    @buildinclude    = ();
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    77
    @rominclude      = ();
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    78
    @parents         = ();
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    79
    @childNodes      = ();
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    80
    $dir             = "";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    81
    $fullpath        = "";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    82
    $varianthrh      = "";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    83
    $virtual         = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    84
    $childNodeStatus = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    85
    
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    86
    my $parnodes = "";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    87
    my %data;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    88
    my $children  = "";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    89
    my $romincs   = "";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    90
    my $buildincs = "";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    91
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    92
    $data{'VALID'} = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    93
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    94
    my ( $empty, $varname, $dirname ) = @_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    95
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    96
    my $fullvarpath = ReturnFullVariantPath( $varname, $dirname );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    97
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    98
    if ( $dirname )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    99
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   100
        $fulldir = $dirname;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   101
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   102
    else
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   103
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   104
        $fulldir = $defaultDir;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   105
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   106
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   107
    $data{'FULLPATH'} = "$fullvarpath";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   108
    $data{'NAME'}     = "$varname";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   109
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   110
    # If the variant file exists, check the syntax and setup variables.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   111
    if ( FileExists($fullvarpath) )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   112
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   113
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   114
        if ( CheckVarFileSyntax( $fullvarpath, $varname ) )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   115
        {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   116
            $data{'VALID'} = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   117
        }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   118
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   119
    else
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   120
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   121
        print "ERROR: $fullpath" . " does not exist\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   122
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   123
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   124
    my $count = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   125
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   126
    # If VAR file is valid, setup all other variables.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   127
    if ( $data{'VALID'} )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   128
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   129
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   130
        $romincs   = FindRomInclude($fullvarpath);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   131
        $buildincs = FindBuildInclude($fullvarpath);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   132
        $children  = FindChildNodes($fullvarpath);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   133
        $parnodes  = FindParentNodes($fullvarpath);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   134
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   135
        # Remove empty elements from the BUILD_INCLUDE list     
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   136
        @$buildincs = grep /\S/, @$buildincs;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   137
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   138
        # Fix paths for all BUILD_INCLUDES
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   139
        for ( my $i = 0 ; $i < scalar(@$buildincs) ; $i++ )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   140
        {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   141
            @$buildincs[$i] = FixPaths( @$buildincs[$i] );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   142
        }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   143
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   144
        # Remove empty elements from the ROM_INCLUDE list
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   145
		@$romincs = grep /\S/, @$romincs;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   146
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   147
        # Fix paths for all ROM_INCLUDES
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   148
        for ( my $i = 0 ; $i < scalar(@$romincs) ; $i++ )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   149
        {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   150
            @$romincs[$i] = FixPaths( @$romincs[$i] );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   151
        }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   152
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   153
        # Remove empty elements from the CHILDREN list
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   154
		@$children = grep /\S/, @$children;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   155
		
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   156
        # Remove empty elements from the PARENT list
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   157
		@$parnodes = grep /\S/, @$parnodes;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   158
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   159
        $data{'BUILD_INCLUDES'} = CloneList($buildincs);        
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   160
        $data{'ROM_INCLUDES'}   = CloneList($romincs);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   161
        $data{'PARENTS'}        = CloneList($parnodes);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   162
        $data{'CHILDREN'}       = CloneList($children);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   163
        $data{'VARIANT_HRH'}    = $varianthrh;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   164
        $data{'VIRTUAL'}        = $virtual;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   165
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   166
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   167
    # If variant file is not valid, return reference to a blank array
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   168
    else
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   169
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   170
        $data{'BUILD_INCLUDES'} = [];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   171
        $data{'ROM_INCLUDES'}   = [];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   172
        $data{'VARIANT_HRH'}    = "";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   173
        $data{'PARENTS'}        = [];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   174
        $data{'CHILDREN'}       = [];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   175
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   176
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   177
    return %data;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   178
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   179
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   180
# Helper method that clones a reference to a simple list
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   181
sub CloneList
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   182
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   183
    my $ref = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   184
    
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   185
    # Check the reference is a list
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   186
    die "Not a list ref" if ref($ref) ne 'ARRAY';
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   187
    
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   188
    # Create a new list object
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   189
    my @list;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   190
    foreach my $entry ( @$ref )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   191
        {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   192
        # Only clone lists of scalars
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   193
        die "Not a scalar" if ref($entry);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   194
        
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   195
        # Add the entry to the new list
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   196
        push @list, $entry;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   197
        }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   198
    
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   199
    # return a reference to the copy    
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   200
    return \@list;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   201
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   202
    
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   203
# Method to correct all the slashes, and also append EPOCROOT if the path begins with a \ or /
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   204
# If path doesn't start with \ or /, returns an abosulte canonical path
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   205
sub FixPaths
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   206
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   207
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   208
    my $arr = $_[0];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   209
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   210
    if ( $arr =~ m/^\// )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   211
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   212
       $arr =~ s/^\/?//;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   213
        return File::Spec->canonpath( "$ENV{EPOCROOT}" . "$arr" );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   214
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   215
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   216
    elsif ( $arr =~ m/^\\/ )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   217
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   218
        $arr =~ s/^\\?//;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   219
        return File::Spec->canonpath( "$ENV{EPOCROOT}" . "$arr" );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   220
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   221
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   222
    else
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   223
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   224
        return File::Spec->rel2abs( File::Spec->canonpath("$arr") );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   225
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   226
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   227
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   228
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   229
# Method to construct a full variant path from the variant file and directory
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   230
sub ReturnFullVariantPath
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   231
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   232
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   233
    my $vardirectory = $_[1];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   234
    my $varname      = $_[0];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   235
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   236
    # Check if a directory is supplied
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   237
    if ($vardirectory)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   238
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   239
        $dir = "$vardirectory";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   240
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   241
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   242
    else
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   243
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   244
        $dir = $defaultDir;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   245
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   246
    my $filename = "$varname" . "\.var";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   247
    $fullpath = File::Spec->catfile( File::Spec->rel2abs($dir), $filename );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   248
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   249
    if ( !File::Spec->file_name_is_absolute($fullpath) )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   250
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   251
        $fullpath = File::Spec->rel2abs($fullpath);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   252
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   253
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   254
    return $fullpath;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   255
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   256
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   257
# Method to find the BUILDINCLUDE values of the VAR file.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   258
sub FindBuildInclude
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   259
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   260
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   261
    my $filename = $_[0];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   262
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   263
    my $parentNodes;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   264
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   265
    # Construct a list of parent nodes if node is a child
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   266
    if ($childNodeStatus)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   267
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   268
        $parentNodes = FindParentNodes("$filename");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   269
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   270
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   271
    if ($parentNodes)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   272
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   273
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   274
        # Go through and build the list of all parent BUILD_INCLUDES
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   275
        for ( my $i = scalar(@$parentNodes) - 1 ; $i >= 0 ; $i-- )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   276
        {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   277
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   278
            my $tmp = ReturnFullVariantPath( @$parentNodes[$i], $fulldir );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   279
            open( NEWHANDLE, "<$tmp" );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   280
            while (<NEWHANDLE>)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   281
            {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   282
                if (/BUILD_INCLUDE/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   283
                {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   284
                    ExtractBuildIncludeValue($_);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   285
                }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   286
            }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   287
            close(NEWHANDLE);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   288
        }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   289
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   290
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   291
    # Append the BUILD_INCLUDES of the VAR file in the end
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   292
    open( NEWHANDLE, "<$filename" );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   293
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   294
    while (<NEWHANDLE>)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   295
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   296
        if (/BUILD_INCLUDE/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   297
        {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   298
            ExtractBuildIncludeValue($_);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   299
        }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   300
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   301
    close(NEWHANDLE);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   302
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   303
    undef(@parents);    # Flush out parent array
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   304
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   305
    return \@buildinclude;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   306
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   307
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   308
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   309
# Method to extract the BUILD_INCLUDE value of a node.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   310
sub ExtractBuildIncludeValue
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   311
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   312
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   313
# If modifier append is found, push the buildinclude to the end of the array list.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   314
    if (/^BUILD_INCLUDE\s+append\s+($pathregex)/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   315
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   316
        push( @buildinclude, ($1) );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   317
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   318
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   319
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   320
# If modifier prepend is found, push the buildinclude to the beginning of the array list.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   321
    if (/^BUILD_INCLUDE\s+prepend\s+($pathregex)/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   322
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   323
        unshift( @buildinclude, ($1) );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   324
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   325
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   326
#If keyword set is found, then empty the buildinclude variable and push the new value
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   327
    if (/^BUILD_INCLUDE\s+set\s+($pathregex)/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   328
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   329
        undef(@buildinclude);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   330
        push( @buildinclude, ($1) );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   331
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   332
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   333
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   334
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   335
# Method to find the ROMINCLUDE values of the VAR file.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   336
sub FindRomInclude
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   337
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   338
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   339
    my $filename = $_[0];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   340
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   341
    my $parentNodes;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   342
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   343
    # Construct a list of parent nodes if node is a child
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   344
    if ($childNodeStatus)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   345
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   346
        $parentNodes = FindParentNodes("$filename");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   347
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   348
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   349
    if ($parentNodes)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   350
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   351
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   352
        # Go through and build the list of all parent ROM_INCLUDES
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   353
        for ( my $i = scalar(@$parentNodes) - 1 ; $i >= 0 ; $i-- )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   354
        {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   355
            my $t = ReturnFullVariantPath( @$parentNodes[$i], $fulldir );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   356
            open( NEWHANDLE, "<$t" );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   357
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   358
            while (<NEWHANDLE>)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   359
            {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   360
                if (/ROM_INCLUDE/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   361
                {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   362
                    ExtractRomIncludeValue($_);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   363
                }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   364
            }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   365
            close(NEWHANDLE);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   366
        }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   367
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   368
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   369
    # Append the ROM_INCLUDES of the VAR file in the end
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   370
    open( NEWHANDLE, "<$filename" );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   371
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   372
    while (<NEWHANDLE>)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   373
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   374
        if (/ROM_INCLUDE/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   375
        {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   376
            ExtractRomIncludeValue($_);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   377
        }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   378
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   379
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   380
    undef(@parents);    # Flush out parent array;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   381
    return \@rominclude;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   382
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   383
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   384
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   385
# Method to extract the ROM_INCLUDE value of a node.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   386
sub ExtractRomIncludeValue
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   387
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   388
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   389
# If modifier append is found, push the rominclude to the end of the array list.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   390
    if (/^ROM_INCLUDE\s+append\s+($pathregex)/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   391
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   392
        push( @rominclude, ($1) );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   393
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   394
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   395
# If modifier prepend is found, push the rominclude to the beginning of the array list.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   396
    if (/^ROM_INCLUDE\s+prepend\s+($pathregex)/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   397
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   398
        unshift( @rominclude, ($1) );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   399
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   400
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   401
# If keyword set is found, then empty the rominclude variable and push the new value
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   402
    if (/^ROM_INCLUDE\s+set\s+($pathregex)/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   403
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   404
        undef(@rominclude);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   405
        push( @rominclude, ($1) );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   406
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   407
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   408
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   409
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   410
# Method to find the immediate parent node of a child node
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   411
sub ExtractExtendsValue
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   412
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   413
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   414
    $_[0] =~ m/^EXTENDS\s+(\w+)/;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   415
    return $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   416
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   417
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   418
# Extract the value of the VARIANT keyword
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   419
sub ExtractVariantValue
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   420
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   421
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   422
    $_[0] =~ m/^VARIANT\s+(\w+)/;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   423
    return $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   424
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   425
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   426
# Extracts the value of the HRH file from the VARIANT_HRH line supplied
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   427
sub ExtractHrhValue
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   428
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   429
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   430
    $_[0] =~ m/^VARIANT_HRH\s+($pathregex)/;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   431
    return $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   432
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   433
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   434
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   435
# Finds if the variant file is a group node
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   436
# Note: This method is only a supplementary method, not actually used during this module
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   437
#       Provides a quick way to check is any VAR file is grouping node or not without loading the entire file.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   438
sub IsVirtual
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   439
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   440
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   441
    my $filename = $_[0];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   442
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   443
    open( READHANDLE, "<$filename" );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   444
    while (<READHANDLE>)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   445
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   446
        if (/^VIRTUAL\s*$/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   447
        {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   448
            close(READHANDLE);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   449
            return 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   450
        }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   451
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   452
    close(READHANDLE);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   453
    return 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   454
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   455
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   456
# Constructs a list of Parent nodes for a given Child node.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   457
sub FindParentNodes
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   458
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   459
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   460
    my $filename   = $_[0];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   461
    my $hasparents = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   462
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   463
    open( READHANDLE, "<$filename" );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   464
    while (<READHANDLE>)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   465
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   466
        if (/EXTENDS/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   467
        {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   468
            $hasparents = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   469
            push( @parents, ExtractExtendsValue($_) );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   470
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   471
        }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   472
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   473
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   474
    close(READHANDLE);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   475
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   476
    if ( $hasparents == 1 )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   477
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   478
        FindParentNodes(
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   479
            ReturnFullVariantPath( @parents[ scalar(@parents) - 1 ], $fulldir )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   480
        );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   481
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   482
    else
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   483
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   484
        return \@parents;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   485
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   486
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   487
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   488
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   489
# Constructs a list of Child nodes for a given Parent node (full path or .var path required)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   490
sub FindChildNodes
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   491
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   492
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   493
    my $var = ReturnNativeVarName("$_[0]");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   494
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   495
    my $tmpname    = "";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   496
    my @childarray = ();
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   497
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   498
    opendir( DIR, $fulldir );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   499
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   500
    while ( defined( my $file = readdir(DIR) ) )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   501
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   502
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   503
        if ( $file =~ m/\.var$/ )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   504
        {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   505
            $tmpname = $file;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   506
            $tmpname =~ s/\.var$//;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   507
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   508
            open( FILEHANDLE, ReturnFullVariantPath( $tmpname, $fulldir ) );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   509
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   510
            while (<FILEHANDLE>)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   511
            {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   512
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   513
                if (/^EXTENDS/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   514
                {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   515
                    if ( lc $var eq lc ExtractExtendsValue($_) )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   516
                    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   517
                        push( @childarray, $tmpname );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   518
                    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   519
                }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   520
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   521
            }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   522
            close(FILEHANDLE);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   523
        }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   524
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   525
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   526
    close(DIR);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   527
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   528
    foreach my $child (@childarray)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   529
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   530
        push( @childNodes, $child );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   531
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   532
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   533
    foreach my $child (@childarray)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   534
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   535
        FindChildNodes( ReturnFullVariantPath( $child, $fulldir ) );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   536
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   537
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   538
    return \@childNodes;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   539
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   540
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   541
# Method to return all the buildable (i.e. No syntax erros and non-virtual) list of
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   542
# variants that can be built in the specified directory. If no directory is specified,
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   543
# the default location is searched.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   544
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   545
# Usage: GetBuildableFeatureVariants(<Directory>)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   546
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   547
sub GetBuildableFeatureVariants
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   548
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   549
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   550
    my $empty = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   551
    my $dir   = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   552
    my @list;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   553
    my $fulldir;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   554
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   555
    if ( $dir )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   556
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   557
        $fulldir = $dir;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   558
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   559
    else
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   560
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   561
        $fulldir = $defaultDir;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   562
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   563
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   564
    opendir( DIR, $fulldir );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   565
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   566
    while ( defined( my $file = readdir(DIR) ) )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   567
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   568
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   569
        if ( $file =~ m/\.var$/ )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   570
        {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   571
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   572
            $file =~ s/\.var$//;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   573
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   574
            my $fullpath = ReturnFullVariantPath( $file, $fulldir );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   575
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   576
            if ( CheckVarFileSyntax( $fullpath, $file )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   577
                && !IsVirtual($fullpath) )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   578
            {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   579
                push( @list, $file );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   580
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   581
            }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   582
        }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   583
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   584
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   585
    return sort @list;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   586
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   587
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   588
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   589
# Method to return a list of the valid and non-virtual children of a given VAR node, in a given location.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   590
# If the calling var file is non-virtual, it is returned as the only element of the list If not, then
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   591
# the method parses though and finds all buildable children
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   592
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   593
# USAGE: ResolveFeatureVariant(<varname>,<dirame>);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   594
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   595
sub ResolveFeatureVariant
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   596
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   597
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   598
    my $empty   = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   599
    my $varfile = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   600
    my $dir     = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   601
    my $fulldir;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   602
    my @list;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   603
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   604
    if ( !$dir eq "" )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   605
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   606
        $fulldir = $dir;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   607
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   608
    else
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   609
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   610
        $fulldir = $defaultDir;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   611
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   612
    my $fullpath = ReturnFullVariantPath( $varfile, $fulldir );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   613
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   614
    if ( CheckVarFileSyntax( $fullpath, $varfile ) && !IsVirtual($fullpath) )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   615
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   616
        push( @list, $varfile );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   617
        return @list;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   618
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   619
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   620
    my %variant = GetVariant( 0, $varfile, $fulldir );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   621
    my $child = $variant{'CHILDREN'};
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   622
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   623
    foreach my $item (@$child)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   624
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   625
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   626
        my $fullpath = ReturnFullVariantPath( $item, $fulldir );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   627
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   628
        if ( CheckVarFileSyntax( $fullpath, $item ) && !IsVirtual($fullpath) )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   629
        {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   630
            push( @list, $item );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   631
        }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   632
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   633
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   634
    return @list;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   635
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   636
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   637
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   638
# Method to return all valid (no syntax errors only) list of variants
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   639
# in the specified directory. If no directory is specified,the default location is searched.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   640
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   641
# Usage: GetValidVariants(<Directory>)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   642
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   643
sub GetValidVariants
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   644
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   645
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   646
    my $empty = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   647
    my $dir   = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   648
    my @list;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   649
    my $fulldir;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   650
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   651
    if ( !$dir eq "" )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   652
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   653
        $fulldir = $dir;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   654
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   655
    else
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   656
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   657
        $fulldir = $defaultDir;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   658
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   659
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   660
    opendir( DIR, $fulldir );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   661
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   662
    while ( defined( my $file = readdir(DIR) ) )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   663
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   664
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   665
        if ( $file =~ m/\.var$/ )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   666
        {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   667
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   668
            $file =~ s/\.var$//;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   669
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   670
            my $fullpath = ReturnFullVariantPath( $file, $fulldir );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   671
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   672
            if ( CheckVarFileSyntax( $fullpath, $file ) )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   673
            {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   674
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   675
                push( @list, $file );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   676
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   677
            }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   678
        }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   679
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   680
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   681
    return sort @list;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   682
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   683
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   684
# Returns the Variant name from a complete path, without the .var extension
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   685
sub ReturnNativeVarName
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   686
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   687
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   688
    my $tmp = "$_[0]";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   689
    $tmp =~ /^.*[\\|\/](.*)\.var$/i;  
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   690
    return $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   691
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   692
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   693
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   694
# Checks if a file passed to this function exists.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   695
sub FileExists
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   696
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   697
	return -e $_[0];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   698
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   699
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   700
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   701
# Checks if the default variant file (default.var) exists in the directory supplied.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   702
# If no directory is supplied, looks under the default location.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   703
# Should only be called directly from the featurevariantparser module reference, not from any methods within the module.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   704
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   705
# USAGE: featurevariantparser->DefaultExists(<DirName>);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   706
# <DirName> : Optional -- Specifies which directory to look under to find the default.var file. Can be relative or absolute.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   707
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   708
sub DefaultExists
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   709
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   710
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   711
    my $dirToSearch = "";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   712
    if ( $_[1] )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   713
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   714
        $dirToSearch = $_[1];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   715
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   716
    else
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   717
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   718
        $dirToSearch = $defaultDir;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   719
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   720
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   721
    $dirToSearch =
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   722
      File::Spec->canonpath(
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   723
        File::Spec->rel2abs( File::Spec->canonpath("$dirToSearch") ) );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   724
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   725
    return ( -e "$dirToSearch/default.var" );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   726
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   727
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   728
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   729
# Checks the variant file for the correct syntax and reports any errors
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   730
# Also sets up some variables(VIRTUAL ,VARIANT_HRH and VARIANT) whilst file is being parsed.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   731
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   732
# Usage: CheckVarFileSyntaxt(<fullpath>,<varfile>) . Note: <varfile> without .var
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   733
sub CheckVarFileSyntax
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   734
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   735
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   736
    my $fullpath          = $_[0];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   737
    my $varname           = $_[1];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   738
    my $varianthrhpresent = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   739
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   740
    open( READVAR, "<$fullpath" );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   741
    my $exp  = "#";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   742
    my $line = "";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   743
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   744
    while (<READVAR>)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   745
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   746
        $line = $.;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   747
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   748
	# Checks for a valid argument supplied to EXTENDS keyword. Checks for one and only one argument supplied.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   749
        if (/^EXTENDS/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   750
        {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   751
            if ( !m/^EXTENDS\s+./ )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   752
            {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   753
                print "\nERROR: Invalid format supplied to argument EXTENDS on line "
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   754
                  . "$."
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   755
                  . " in file "
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   756
                  . "$fullpath";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   757
                return 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   758
            }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   759
            my $str = ExtractExtendsValue($_);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   760
            if ( $str =~ /\s+/ )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   761
            {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   762
                print "\nERROR: Cannot extend from two nodes. Error in line "
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   763
                  . "$."
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   764
                  . " in file "
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   765
                  . "$fullpath";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   766
                return 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   767
            }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   768
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   769
            $childNodeStatus = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   770
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   771
        }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   772
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   773
        # Checks for the grammar of BUILD_INCLUDE, i.e. KEYWORD MODIFIER VALUE
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   774
        elsif (/^BUILD_INCLUDE/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   775
        {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   776
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   777
          if (!m/^BUILD_INCLUDE\s+(append|prepend|set)\s+$pathregex/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   778
            {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   779
                print "\nERROR: Invalid syntax supplied to keyword BUILD_INCLUDE on line "
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   780
                  . "$."
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   781
                  . " in file "
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   782
                  . "$fullpath";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   783
                return 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   784
            }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   785
            
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   786
		 if (m/^BUILD_INCLUDE\s+(append|prepend|set)\s+$pathregex\s+$pathregex/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   787
            {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   788
                print "\nERROR: Too many arguments supplied to keyword BUILD_INCLUDE on line "
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   789
                  . "$."
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   790
                  . " in file "
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   791
                  . "$fullpath";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   792
                return 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   793
            }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   794
        }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   795
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   796
        # Checks for the grammar of ROM_INCLUDE, i.e. KEYWORD MODIFIER VALUE
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   797
        elsif (/^ROM_INCLUDE/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   798
        {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   799
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   800
		if (!m/^ROM_INCLUDE\s+(append|prepend|set)\s+$pathregex/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   801
            {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   802
                print "\nERROR: Invalid syntax supplied to keyword ROM_INCLUDE on line "
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   803
                  . "$."
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   804
                  . " in file "
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   805
                  . "$fullpath";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   806
                return 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   807
            }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   808
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   809
       if (m/^ROM_INCLUDE\s+(append|prepend|set)\s+$pathregex\s+$pathregex/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   810
            {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   811
                print "\nERROR: Too many arguments supplied to keyword ROM_INCLUDE on line "
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   812
                  . "$."
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   813
                  . " in file "
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   814
                  . "$fullpath";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   815
                return 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   816
            }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   817
        }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   818
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   819
        # Checks for a valid VARIANT name
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   820
        elsif (/^VARIANT[^_HRH]/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   821
        {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   822
            if ( !m/^VARIANT\s+\w+/ )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   823
            {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   824
                print "\nERROR: VARIANT name not specified on line " . "$."
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   825
                  . " in file "
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   826
                  . "$fullpath";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   827
                return 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   828
            }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   829
            if ( uc("$varname") ne uc( ExtractVariantValue($_) ) )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   830
            {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   831
                print "\nERROR: VARIANT filename does not match variant name specified on line "
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   832
                  . "$line"
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   833
                  . " in file "
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   834
                  . "$fullpath"
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   835
                  . "\nVariant value extracted from the VAR file is " . "$_";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   836
            }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   837
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   838
        }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   839
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   840
        # Checks that keyword VIRTUAL is declared correctly
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   841
        elsif (/^VIRTUAL/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   842
        {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   843
            if (m/^VIRTUAL\s+\w+/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   844
            {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   845
                print "\nERROR: Invalid declaration of VIRTUAL on line " . "$."
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   846
                  . " in file "
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   847
                  . "$fullpath";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   848
                return 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   849
            }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   850
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   851
            $virtual = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   852
        }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   853
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   854
        # Checks if VARIANT_HRH is declared correctly.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   855
        elsif (/^VARIANT_HRH/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   856
        {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   857
            $varianthrhpresent = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   858
            my $lineno = $.;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   859
            if ( !m/^VARIANT_HRH\s+./ )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   860
            {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   861
                print "\nERROR: Invalid format supplied to argument VARIANT_HRH on line "
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   862
                  . "$lineno"
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   863
                  . " in file "
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   864
                  . "$fullpath";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   865
                return 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   866
            }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   867
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   868
            my $str = ExtractHrhValue($_);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   869
            if ( $str =~ /\s+/ )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   870
            {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   871
                print "\nERROR: Cannot have 2 or more hrh files. Error in line "
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   872
                  . "$lineno"
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   873
                  . " in file "
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   874
                  . "$fullpath";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   875
                return 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   876
            }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   877
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   878
            if ( !FileExists( FixPaths($str) ) )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   879
            {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   880
                print "\nERROR: VARIANT HRH file : "
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   881
                  . FixPaths($str)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   882
                  . " specified on line "
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   883
                  . "$lineno"
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   884
                  . " does not exist";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   885
                return 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   886
            }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   887
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   888
            $varianthrh = FixPaths( ExtractHrhValue($_) );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   889
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   890
        }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   891
        
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   892
        # If none of the valid keywords are found
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   893
        else
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   894
        {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   895
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   896
            # Do nothing if a comment or blank line is found
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   897
            if ( (m/$exp\s+\S/) || (m/$exp\S/) || ( !m/./ ) || (m/^\n/) )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   898
            {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   899
            }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   900
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   901
            # Unsupported keyword
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   902
            else
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   903
            {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   904
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   905
                print "\nERROR: Invalid keyword " . '"' . "$_" . '"'
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   906
                  . " found on line " . "$."
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   907
                  . " in file "
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   908
                  . "$fullpath";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   909
                return 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   910
            }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   911
        }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   912
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   913
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   914
    close(READVAR);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   915
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   916
    # If no HRH file defined, check if the default one exists
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   917
    if ( !$varianthrhpresent )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   918
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   919
        print "\nINFO: No VARIANT_HRH defined in VAR file, using $ENV{EPOCROOT}epoc32\\include\\variant\\$varname\.hrh" if ($verbose);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   920
        my $str =
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   921
          ExtractHrhValue(
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   922
            "VARIANT_HRH $ENV{EPOCROOT}epoc32\\include\\variant\\$varname\.hrh"
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   923
          );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   924
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   925
        if ( !FileExists($str) )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   926
        {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   927
            print "\nERROR: VARIANT HRH file : " . "$str " . "does not exist\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   928
            return 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   929
        }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   930
        else
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   931
        {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   932
            $varianthrh = $str;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   933
        }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   934
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   935
    return 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   936
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   937
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   938
1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   939