#!/devtool/local/bin/perl
# mfsize        *** internal script (called by vmake !)
#
# @(#)mfsize		1997-11-18
#
# analyze size of pascal data types
#
# 1. create definition file from include modules
# 2. create size analyzer program
# 3. run size analyzer program
#
# TOOL          directory for tool scripts
# KEEPFLG       optional keep intermediate files flag
#
#
#    ========== licence begin  GPL
#    Copyright (C) 2001 SAP AG
#
#    This program is free software; you can redistribute it and/or
#    modify it under the terms of the GNU General Public License
#    as published by the Free Software Foundation; either version 2
#    of the License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#    ========== licence end
#

package mfsize;
use Env;
use File::Basename;
use Carp;
do "$TOOLVARS";
if ( $@ ) { print "$@"; exit }
ToolTrace("mfsize called with @ARGV\n");

$USAGE = "usage: mfsize [-<symbol>=<value>] [-k] unpacked-include-modules\n";

do "$TOOL/bin/mf_opts$TOOLEXT";
if ( $@ ) { print "$@"; exit }

if ( @ARGV < 1 ) { print $USAGE; exit 1 }

@CONS = "";
@TYPS =	"";

foreach $ARG (@ARGV) {
	$_ = $ARG;
	CASE: {

		if(/.*\.con/) { push @CONS, $ARG; last CASE }

		if(/.*\.typ/) { push @TYPS, $ARG; last CASE }

        print "illegal input file: $ARG\n";
        exit 2;

	} #CASE
}
# $_ contains the last argument

$ARG = basename($_);
($ARG) = $ARG =~ /(\.*[^\.]*)/ ;  # alle Endungen werden abgeschnitten

$PASTYP= "";
$PASOPT= "";

@CONCOMOPTS;

system("$TOOL/pgm/mfcat $ARG.cns CONST @CONS") == 0
	or croak "Error while executing \"$TOOL/pgm/mfcat $ARG.cns CONST @CONS\"\n".
	"message: $!\n";

system("$TOOL/pgm/mfcat $ARG.tps TYPE $PASTYP @TYPS") == 0
	or croak "Error while executing \"$TOOL/pgm/mfcat $ARG.tps TYPE $PASTYP @TYPS\"\n".
	"message: $!\n";

system("$TOOL/pgm/mfcat $ARG.tuc TYPE $ARG.typ") == 0
	or croak "Error while executing \"$TOOL/pgm/mfcat $ARG.tuc TYPE $ARG.typ\"\n".
	"message: $!\n";

system("$TOOL/pgm/mfconcom", "-n", @CONCOMOPTS, "$ARG.tuc", "$ARG.t", $MACH, $KIND, $TRACE, $COMP, $OS, $OSSPEC) == 0
	or croak "Error while executing \"$TOOL/pgm/mfconcom -n @CONCOMOPTS $ARG.tuc $ARG.t $MACH $KIND $TRACE $COMP $OS $OSSPEC\"\n".
	"message: $!\n";


# creates $ARG.top $ARG.body
system("$TOOL/pgm/sizeof $ARG.t") == 0
	or croak "Error while executing \"$TOOL/pgm/sizeof $ARG.t\"\n".
	"message: $!\n";

open(FILE_OUT, "+>$ARG.puc") or croak "Can't open $ARG.puc (output): $!\n";
foreach $I ($PASOPT, "$ARG.top", "$ARG.cns", "$ARG.tps", "$ARG.body") {
	if ( -f $I ) {
		open(FILE_IN, "<$I") or croak "Can't open $I (input): $!\n";
		print FILE_OUT <FILE_IN>;
		close FILE_IN;
	}
}
close FILE_OUT;

system("$TOOL/pgm/mfconcom", "-n", @CONCOMOPTS, "$ARG.puc", "$ARG.p", $MACH, $KIND, $TRACE, $COMP, $OS, $OSSPEC) == 0
	or croak "Error while executing \"$TOOL/pgm/mfconcom -n @CONCOMOPTS $ARG.puc $ARG.p $MACH $KIND $TRACE $COMP $OS $OSSPEC\"\n".
	"message: $!\n";

@ARGV = ( "-Kt", @KEEPFLG, "$ARG.p" );
do "$TOOL/bin/compp$TOOLEXT";
if ( $@ ) { warn "Error while executing compp:\n", "$@"; exit }

$OUT = "$ARG.out";
@ARGV = ( "-BuildNrFunction=", "-nowhatstring", @KEEPFLG, "-o", $OUT, "$ARG.o" );
do "$TOOL/bin/linklnk$TOOLEXT";
if ( $@ ) { warn "Error while executing linklnk:\n", "$@"; exit }

system("$OUT > $ARG.usiz") == 0
	or croak "Error while executing \"$OUT > $ARG.usiz\"\n".
	"message: $!\n";

open(FILE_OUT, "+>$ARG.siz") or croak "Can't open $ARG.siz (output): $!\n";
print FILE_OUT "--- $MACH ---\n";
open(FILE_IN, "<$ARG.usiz") or croak "Can't open $ARG.usiz (input): $!\n";
print FILE_OUT sort <FILE_IN>;
close FILE_IN;
close FILE_OUT;


if (-r "$WRK/size/$ARG.cpp.siz" && ($CHECK00SIZES eq "YES")) {
    system ("$TOOL/Posix/diff $ARG.siz $WRK/size/$ARG.cpp.siz");
}

if ( @KEEPFLG == 0 ) {
    unlink "$ARG.tuc", "$ARG.puc", "$ARG.cns", "$ARG.tps", "$ARG.t",
			"$ARG.top", "$ARG.body", "$ARG.p", "$ARG.o", $OUT, "$ARG.usiz";
}


__END__

Hier kann ein langer Kommentar stehen!
