os/boardsupport/haitest/bspsvs/tools/perl/BuildOrbiter/BuildOrbiter.pl
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
#
sl@0
     2
# Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
# All rights reserved.
sl@0
     4
# This component and the accompanying materials are made available
sl@0
     5
# under the terms of "Eclipse Public License v1.0"
sl@0
     6
# which accompanies this distribution, and is available
sl@0
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
#
sl@0
     9
# Initial Contributors:
sl@0
    10
# Nokia Corporation - initial contribution.
sl@0
    11
#
sl@0
    12
# Contributors:
sl@0
    13
#
sl@0
    14
# Description:
sl@0
    15
#
sl@0
    16
sl@0
    17
use File::Copy;
sl@0
    18
use Getopt::Long;
sl@0
    19
use Cwd;
sl@0
    20
use Archive::Zip;
sl@0
    21
use Archive::Zip::Tree;
sl@0
    22
sl@0
    23
sub Usage()
sl@0
    24
	{
sl@0
    25
	print <<USAGE_EOF;
sl@0
    26
Usage
sl@0
    27
perl buildorbiter.pl --in=FileNameIn --out=FileNameOut --help
sl@0
    28
sl@0
    29
    --in=FileNameIn             : Input oby file name
sl@0
    30
sl@0
    31
    --out=FileNameOut           : Output zip file name
sl@0
    32
sl@0
    33
    --help                      : This help
sl@0
    34
USAGE_EOF
sl@0
    35
	exit( 0 )
sl@0
    36
	}
sl@0
    37
sl@0
    38
sub main()
sl@0
    39
	{
sl@0
    40
	my	$help='';
sl@0
    41
	my	$input="";
sl@0
    42
	my	$output="";
sl@0
    43
sl@0
    44
	GetOptions(
sl@0
    45
		'in=s'		=> \$input,
sl@0
    46
		'out=s'		=> \$output,
sl@0
    47
		'help' 		=> \$help
sl@0
    48
	);
sl@0
    49
sl@0
    50
	if($help or ($input eq "") or ($output eq "") )
sl@0
    51
		{
sl@0
    52
		Usage();
sl@0
    53
		exit(0);
sl@0
    54
		}
sl@0
    55
sl@0
    56
	my	$curdir = cwd;
sl@0
    57
	$_ = $curdir;
sl@0
    58
	s/\//\\/g;
sl@0
    59
	$curdir = $_;
sl@0
    60
sl@0
    61
	my	$theEpocRoot=$ENV{EPOCROOT};
sl@0
    62
	my	@epocdir = "$theEpocRoot.\\epoc32";
sl@0
    63
sl@0
    64
	open FH, "$input" || die "Couldn't open $input file for Reading: $!\n";
sl@0
    65
sl@0
    66
	while ( <FH> )
sl@0
    67
		{
sl@0
    68
		chomp;                  # no newline
sl@0
    69
		s/#.*//;                # no comments
sl@0
    70
		s/^\s+//;               # no leading white
sl@0
    71
		s/\s+$//;               # no trailing white
sl@0
    72
		next unless length;     # anything left?
sl@0
    73
		if ( /(^file|^data)\s*=\s*(\S+)\s+(\S+)/ )
sl@0
    74
			{
sl@0
    75
			my	$inputFile=$2;
sl@0
    76
sl@0
    77
			$inputFile =~ m/(\S*)(\\|\/)(\S+)$/;
sl@0
    78
sl@0
    79
			my	$dir=$curdir.$1;
sl@0
    80
			unless ( -d $dir )
sl@0
    81
				{
sl@0
    82
				system("mkdir $dir");
sl@0
    83
				}
sl@0
    84
			printf "Copying: $inputFile\n";
sl@0
    85
			copy($inputFile, $dir) or die "File cannot be copied.";
sl@0
    86
			}
sl@0
    87
		}
sl@0
    88
	close FH;
sl@0
    89
sl@0
    90
	my	$zip = Archive::Zip->new();
sl@0
    91
	if ( $input =~ m/(\S*)(\\|\/)(\S+)$/ )
sl@0
    92
		{
sl@0
    93
		$zip->addFile("$input", $3);
sl@0
    94
		}
sl@0
    95
	else
sl@0
    96
		{
sl@0
    97
		$zip->addFile("$input");
sl@0
    98
		}
sl@0
    99
	$zip->addTree("epoc32", "epoc32");
sl@0
   100
	die 'write error' if $zip->writeToFileNamed( "$output" ) != AZ_OK;
sl@0
   101
	printf "Completed\n";
sl@0
   102
	}
sl@0
   103
sl@0
   104
main();