#
# GetInstDir.pm
#
#
#    ========== licence begin LGPL
#    Copyright (C) 2002 SAP AG
#
#    This library is free software; you can redistribute it and/or
#    modify it under the terms of the GNU Lesser General Public
#    License as published by the Free Software Foundation; either
#    version 2.1 of the License, or (at your option) any later version.
#
#    This library 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
#    Lesser General Public License for more details.
#
#    You should have received a copy of the GNU Lesser General Public
#    License along with this library; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#    ========== licence end
#


package GetInstDir;

sub GetVersionLayer {
	my $RELVER           = $ENV{'RELVER'};
	my $CORRECTION_LEVEL = $ENV{'CORRECTION_LEVEL'};

	# only for releases >= 72
	my ($Release) = ($RELVER =~ /^R(\d\d)$/);
	return undef unless (defined $Release && $Release >= 72);

	# for 72.04.xx or 72.05.xx
	# the name of the directory is 7240 or 7250
	my $Correction = $CORRECTION_LEVEL;
	$Correction *= 10 if ($Release == 72);

	my $VersionLayer = 100 * $Release + $Correction;
	return ($VersionLayer);
}

sub GetSDKRoot {
	my $VersionLayer = GetVersionLayer ();
	my $INSTROOT = $ENV{'INSTROOT'};

	my $SDKRoot = $INSTROOT."/sdk/".$VersionLayer;

	if ($^O =~ /mswin/i) {
		$SDKRoot =~ s/\//\\/g;
	} else {
		$SDKRoot =~ s/\\/\//g;
	}
	return $SDKRoot;
}

sub GetSDKRootLib {
	my $BIT64  = $ENV{'BIT64'};
	my $OSSPEC = $ENV{'OSSPEC'};
	my $MACH   = $ENV{'MACH'};

	my $SDKRootLib = GetSDKRoot ()."/lib";
	unless ($BIT64 != 1 || $MACH =~ /ALPHA/ || ($OSSPEC =~ /LINUX/ and $MACH =~ /IA64/)) {
		$SDKRootLib .= "/lib64";
	}

	if ($^O =~ /mswin/i) {
		$SDKRootLib =~ s/\//\\/g;
	} else {
		$SDKRootLib =~ s/\\/\//g;
	}
	return $SDKRootLib;
}

sub GetSDKRootPgm {
	my $BIT64  = $ENV{'BIT64'};
	my $OSSPEC = $ENV{'OSSPEC'};
	my $MACH   = $ENV{'MACH'};

	my $SDKRootPgm = GetSDKRoot ()."/pgm";
	unless ($BIT64 != 1 || $MACH =~ /ALPHA/ || ($OSSPEC =~ /LINUX/ and $MACH =~ /IA64/)) {
		$SDKRootPgm .= "/pgm64";
	}

	if ($^O =~ /mswin/i) {
		$SDKRootPgm =~ s/\//\\/g;
	} else {
		$SDKRootPgm =~ s/\\/\//g;
	}
	return $SDKRootPgm;
}

sub GetInstRuntime {
	my $BIT64  = $ENV{'BIT64'};
	my $OSSPEC = $ENV{'OSSPEC'};
	my $MACH   = $ENV{'MACH'};
	my $INSTROOT = $ENV{'INSTROOT'};

	my $VersionLayer = GetVersionLayer ();
	return undef unless (defined $VersionLayer);

	my $RuntimeDir = $INSTROOT."/runtime/".$VersionLayer;
	if ($OSSPEC eq 'WIN32' ) {
		$RuntimeDir .= "/pgm";
		unless ($BIT64 != 1) {
			$RuntimeDir .= "/pgm64";
		}
        } else {
		$RuntimeDir .= "/lib";
		unless ($BIT64 != 1 || $MACH =~ /ALPHA/ || $MACH =~ /IA64/ ) {
			$RuntimeDir .= "/lib64";
		}
        }
	$RuntimeDir =~ s/\\/\//g;
	return $RuntimeDir;
}

1;
