sbsv1/abld/bldmake/metabld.pl
author Ross Qin <ross.qin@nokia.com>
Tue, 02 Nov 2010 16:54:53 +0800
changeset 673 7ae5f757318b
parent 599 fa7a3cc6effd
permissions -rw-r--r--
update release info
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
599
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     1
# Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     2
# All rights reserved.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     3
# This component and the accompanying materials are made available
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     4
# under the terms of "Eclipse Public License v1.0"
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     5
# which accompanies this distribution, and is available
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     6
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     7
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     8
# Initial Contributors:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     9
# Nokia Corporation - initial contribution.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    10
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    11
# Contributors:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    12
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    13
# Description:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    14
# all variables called *Path* are set up to end with a backslash
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    15
# all variables called *Path or *File are stored as absolute (file)paths within makmake
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    16
# all variables called UpPath* are stored as relative paths within makmake
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    17
# 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    18
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    19
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    20
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    21
use FindBin;		# for FindBin::Bin
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    22
use File::Find;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    23
use Cwd;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    24
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    25
my $PerlLibPath;    # fully qualified pathname of the directory containing our Perl modules
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    26
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    27
BEGIN {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    28
# check user has a version of perl that will cope
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    29
	require 5.005_03;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    30
# establish the path to the Perl libraries: currently the same directory as this script
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    31
	$PerlLibPath = $FindBin::Bin;	# X:/epoc32/tools
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    32
	$PerlLibPath =~ s/\//\\/g;	# X:\epoc32\tools
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    33
	$PerlLibPath .= "\\";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    34
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    35
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    36
use lib $PerlLibPath;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    37
use E32env;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    38
use Prepfile;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    39
use Pathutl;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    40
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    41
# autoflush prevents our ouptut from getting jumbled up
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    42
use FileHandle;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    43
autoflush STDOUT 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    44
autoflush STDERR 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    45
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    46
my (@Commands, @BldInfDirs);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    47
# should end in .mbc where .mbc means for "MetaBld Configuration file"
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    48
# must end in .mbc if passed on command-line
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    49
my $ConfigFile;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    50
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    51
my $StartDir=&cwd();
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    52
my $relative;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    53
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    54
	# Process command-line
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    55
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    56
  	unless (@ARGV)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    57
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    58
		&Usage();
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    59
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    60
	else
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    61
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    62
		# check to see if we are using a relative path 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    63
	  	if ($ARGV[0] eq "-r")
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    64
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    65
			$relative = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    66
			shift @ARGV;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    67
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    68
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    69
		# check for a root from a config file in EPOCROOT dir as first argument
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    70
	  	if (-e "$ENV{EPOCROOT}$ARGV[0].mbc")
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    71
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    72
		  	$ConfigFile="$ENV{EPOCROOT}$ARGV[0].mbc";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    73
		  	shift @ARGV;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    74
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    75
		# check for a config file as the first argument
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    76
	  	elsif ($ARGV[0]=~/.mbc$/io)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    77
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    78
			$ConfigFile=shift @ARGV;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    79
			if ($ConfigFile=~/^.:/o)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    80
				{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    81
				&Error("Config file can't be specified with a drive letter, as \"$ConfigFile\" is");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    82
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    83
			unless (-e $ConfigFile)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    84
				{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    85
				&Error("Can't find file $ConfigFile");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    86
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    87
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    88
		if (@ARGV)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    89
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    90
			# pass any other arguments as commands
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    91
			@Commands=("@ARGV");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    92
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    93
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    94
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    95
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    96
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    97
	# scan config file if necessary
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    98
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    99
	if ($ConfigFile)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   100
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   101
		# make config file path absolute
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   102
		$ConfigFile=&Path_AbsToWork($ConfigFile);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   103
		
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   104
		my @Config2D;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   105
		eval { &Prepfile_ProcessL(\@Config2D, $ConfigFile); };
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   106
		&Error($@) if $@;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   107
		
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   108
		my %CheckDir;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   109
		
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   110
		my @ConfigCommands;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   111
		my $Section='';
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   112
		my @Death;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   113
		my $Line;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   114
		my $CurFile=$ConfigFile;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   115
	  LINE: foreach $Line (@Config2D)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   116
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   117
			my $LineNum=shift @$Line;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   118
			$_=shift @$Line;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   119
			if ($LineNum eq '#')
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   120
				{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   121
				$CurFile=$_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   122
				next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   123
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   124
			if (/^SECTION_(\w*)$/io)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   125
				{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   126
				$Section=uc $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   127
				if ($Section=~/^(COMMANDS|DIRS|OPTIONALDIRS)$/o)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   128
					{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   129
					if (@$Line)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   130
						{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   131
						push @Death, "$CurFile($LineNum) : Can't specify anything on the same line as a section header\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   132
						}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   133
					next LINE;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   134
					}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   135
				push @Death, "$CurFile($LineNum) : Unknown section header - $_\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   136
				$Section=0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   137
				next LINE;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   138
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   139
			unshift @$Line, $_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   140
			if ($Section eq 'COMMANDS')
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   141
				{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   142
				if ($$Line[0]=~/^ONEOFF$/io)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   143
					{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   144
					# check syntax for oneoff commands
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   145
					unless (@$Line>=3)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   146
						{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   147
						push @Death, "$CurFile($LineNum) : Too few arguments for oneoff command\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   148
						}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   149
					# resolve oneoff dir relative to .mb file location
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   150
					$$Line[1]=~s-^.*[^\\]$-$&\\-o; # add trailing backslash if necessary
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   151
					$$Line[1]=&Path_MakeAbs($CurFile, $$Line[1]);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   152
					unless (-d $$Line[1])
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   153
						{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   154
						warn "$CurFile($LineNum) : Can't find dir $$Line[1]\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   155
						}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   156
					}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   157
				push @ConfigCommands, "@$Line";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   158
				next LINE;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   159
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   160
			if ($Section eq 'DIRS' || $Section eq 'OPTIONALDIRS')
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   161
				{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   162
				my $Dir;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   163
				foreach $Dir (@$Line)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   164
					{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   165
					if ($Dir=~/^.:/o)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   166
						{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   167
						push @Death, "$CurFile($LineNum) : directory $Dir is specified with a drive letter\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   168
						next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   169
						}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   170
					$Dir=~s-^.*[^\\]$-$&\\-o;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   171
					$Dir=&Path_MakeAbs($CurFile, $Dir); # dirs must be the same for check
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   172
					if ($CheckDir{uc $Dir})
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   173
						{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   174
						# Silently ignore duplicate directories - #including of several .mbc files
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   175
						# will often cause directory duplication.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   176
						# We can't do the same for duplicate commands because the order in which
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   177
						# the commands are executed might be significant.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   178
						# push @Death, "$CurFile($LineNum) : Directory $Dir already specified\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   179
						next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   180
						}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   181
					print "$Dir\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   182
					
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   183
					unless (-d $Dir)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   184
						{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   185
						if ($Section ne 'OPTIONALDIRS')
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   186
							{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   187
							push @Death, "$CurFile($LineNum) : Can't find directory $Dir\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   188
							}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   189
						next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   190
						}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   191
					push @BldInfDirs, $Dir;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   192
					$CheckDir{uc $Dir}=$LineNum;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   193
					}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   194
				next LINE;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   195
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   196
			else
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   197
				{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   198
				push @Death, "$CurFile($LineNum) : No section specified\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   199
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   200
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   201
		
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   202
		if (@Death)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   203
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   204
			chomp $Death[$#Death];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   205
			&Error(@Death);
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
		# apply the commands unless already collected
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   209
		unless (@Commands)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   210
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   211
			&Error("$ConfigFile : No Commands specified") unless @ConfigCommands;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   212
			@Commands=@ConfigCommands;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   213
			}
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
	# Should have commands now
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   217
	&Usage() unless @Commands;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   218
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   219
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   220
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   221
	# Search for the BLD.INF files if necessary
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   222
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   223
	my $mystartdir;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   224
	if ($relative)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   225
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   226
		$mystartdir = substr($StartDir, 2);
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
	$mystartdir=~s:\/:\\:g;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   230
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   231
	if ($mystartdir ne "\\")
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   232
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   233
		$mystartdir=$mystartdir."\\";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   234
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   235
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   236
	unless (@BldInfDirs)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   237
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   238
		# find the files in the source directories - skip the EPOCROOT directory
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   239
		
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   240
		my $EPOCROOTDir=$E32env::Data{EPOCPath};
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   241
		$EPOCROOTDir=~s/^\\([^\\]*).*$/$1/o;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   242
		
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   243
		opendir DIR, $mystartdir or &Error("Can't open dir: $!");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   244
		# remove ., .. and EPOCROOT dir
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   245
		my @SrcDirs=grep !/^(\.\.?|$EPOCROOTDir|RECYCLER|System Volume Information)$/i, readdir DIR; 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   246
		foreach (@SrcDirs)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   247
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   248
			# prepend with current path
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   249
			$_=$mystartdir.$_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   250
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   251
		@SrcDirs=grep -d, @SrcDirs;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   252
		find(\&BldInfDirs, @SrcDirs);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   253
		@BldInfDirs=sort @BldInfDirs;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   254
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   255
		# if we are doing it relative to current location, need to include current dir
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   256
		# if it contains a bld.inf
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   257
		if (-f "BLD.INF" && $relative)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   258
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   259
			push @BldInfDirs, $mystartdir;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   260
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   261
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   262
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   263
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   264
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   265
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   266
	# Execute the commands
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   267
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   268
	my $Time=localtime;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   269
	print "=== metabld started $Time.\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   270
	my $Command;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   271
	foreach $Command (@Commands)
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
		$Time=localtime;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   275
		# Check if we should execute this command just the once
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   276
		if ($Command=~s/^\s*ONEOFF\s+(\S+)\s+(.*)$/$2/io)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   277
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   278
			my $OneOffDir=$1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   279
			# execute the command once rather than for each BLD.INF directory
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   280
			chdir $OneOffDir or &Error("Can't change dir to $OneOffDir: $!");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   281
			print
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   282
			(
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   283
			 "===-------------------------------------------------\n",
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   284
			 "=== $Command\n",
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   285
			 "===-------------------------------------------------\n",
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   286
			 "=== $Command started $Time.\n",
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   287
			 "=== $Command == $OneOffDir\n"
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   288
			);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   289
			system( "$Command");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   290
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   291
		else
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   292
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   293
			# execute the command for each BLD.INF directory
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   294
			print
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   295
			(
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   296
			 "===-------------------------------------------------\n",
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   297
			 "=== $Command\n",
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   298
			 "===-------------------------------------------------\n",
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   299
			 "=== $Command started $Time.\n",
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   300
			);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   301
			my $Dir;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   302
			foreach $Dir (@BldInfDirs)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   303
				{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   304
				chdir $Dir or &Error("Can't change dir to $Dir: $!");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   305
				print "=== $Command == $Dir\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   306
				system( "$Command");
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
		chdir $StartDir or &Error("Can't change dir to $StartDir: $!");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   310
		$Time=localtime;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   311
		print "=== $Command finished $Time.\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   312
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   313
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   314
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   315
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   316
#################################################
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   317
#	SUBROUTINES
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
sub Usage
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   321
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   322
	print <<ENDHERESTRING;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   323
usage: metabld [EPOCROOT .mbc file basename|.mbc config file] [command]
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   324
MetaBld is a tool for carrying out build commands across several components.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   325
A .mbc config file contains directories and commands, eg:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   326
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   327
SECTION_COMMANDS
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   328
bldmake bldfiles
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   329
abld target wins udeb
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   330
// "oneoff" means carry out command just once, not for each directory.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   331
// First arg after "oneoff" must be a start dir, and can be "."
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   332
oneoff \\e32\\rombuild rom xxx
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   333
oneoff . \\e32test\\group\\abld test build wins urel
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   334
SECTION_DIRS
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   335
\\e32
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   336
\\f32\\group
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   337
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   338
It's possible to #include lists of dirs from other files if necessary,
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   339
and may be useful for carrying out different sets of commands on the same set
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   340
of directories via different .mbc files.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   341
If a command is specified on the command-line, it will be executed instead
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   342
of any commands specified in a .mbc file.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   343
If no directories are specified in a .mbc file, then all the directories
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   344
containing a bld.inf file on the current drive will be searched for instead.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   345
ENDHERESTRING
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   346
exit 1;
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
sub Error (@)
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
	die
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   353
	@_, "\n",
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   354
	"Error executing metabld.bat\n"
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   355
	;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   356
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   357
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   358
sub BldInfDirs
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   359
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   360
	s-\/-\\-go;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   361
	if (/^BLD.INF$/io)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   362
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   363
		$File::Find::dir=~s-\/-\\-go;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   364
		push @BldInfDirs, $File::Find::dir;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   365
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   366
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   367