#! /usr/bin/perl
#
# $Header: //sapdb/TOOLSRC/develop/sys/src/BuildPackage/Vars.pm#22 $
# $DateTime: 2003/01/10 13:00:18 $
# $Change: 34332 $
#
# Desc:	- define vars for plattform specific vars
#		
#
#
#    ========== 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 BuildPackage::Vars;

use Exporter;

@ISA = ('Exporter');

@EXPORT = ('$WRK','$OWN','$USR','$INSTROOT',
		'$MAJ','$MIN','$COR','$BUILD',
		'$BIT', '$VERSION_PATH', '$BUILDROOT',
		'$SOEXT','$EXEEXT','$OS32_PATH','$OS64_PATH',
		'$ARCH','$OS','$PACKAGEPATH','$image_server',
		'$XMLFile','$CDImagePath','$CDIMAGEOS',
		'$LIBPATH','$RUNTIME_PATH','$RUNTIME_VERSION',
		'$USE_FTP','SetVars' ,'$LC_RELEASE','$LC_ROOT','$LC_POOL_ROOT',
		'$LC_STATE','$LC_PACK_NAME','$LC_PACK_NAME_OLD','$LC_OWN','$LC_POOL_DIR',
		'$SAPDB_POOL_DIR',,'$SAPDB_POOL_ROOT','$LC_BUILD_SELECT','$APO_REL','$APO_SHORT_VERS','$APO_BUILD',
		'$APOMAKE','$APO_STATE','$APO_POOL_DIR','$EM_MAKE','$APO_VARIANT',
		'$APO_PACK_NAME_OLD','$LC_INNER_SUBDIR','$SAPDB_COMPONENTS_DIR','$LCAPPS_COMPONENTS_DIR'
		);



$USE_FTP = 1;

$WRK=$ENV{'WRK'};
$WRK=~s/\\/\//g;


$LIBPATH="lib";

if(exists $ENV{BIT64} or $^O=~/.*osf.*/i){
        $BIT='64';
	  $^O=~/osf|linux/i or $LIBPATH="$LIBPATH/lib64";
}
else{
         $BIT='32';
}

$OWN=$ENV{'OWN'};
$OWN=~s/\\/\//g;
$INSTROOT=$ENV{INSTROOT};
$INSTROOT=~s/\\/\//g;
$PACKAGEPATH="$WRK/fast/install";
$PACKAGEPATH =~ s/\\/\//g;
$LC_STATE = $ENV{'LC_STATE'};
($MAJ,$MIN) = ($ENV{'RELVER'} =~ /R(\d)(\d+)/ );
$COR = $ENV{'CORRECTION_LEVEL'}; 
$COR = "0$COR" if length($COR) == 1;
$BUILD = $ENV{'BUILDPRAEFIX'};
$BUILD = "0$BUILD" if length($BUILD) == 1;
$BUILDROOT="$WRK/fast/install/buildroot";
$USR="$OWN/usr";
$cor = $COR;
$cor =~ s/^0//;
$build = $BUILD;
$build =~ s/^0//;

$SAPDB_COMPONENTS_DIR = 'SAPDB_COMPONENTS';
$LCAPPS_COMPONENTS_DIR = 'LCAPPS_COMPONENTS';

$LC_POOL_ROOT = ((exists $ENV{'LC_POOL_ROOT'} and $ENV{'LC_POOL_ROOT'} =~ /\S/) ? $ENV{'LC_POOL_ROOT'} : '/LC_POOL'); 
$LC_POOL_DIR = "$LC_POOL_ROOT/LC_$MAJ$MIN$COR".(($LC_STATE =~ /DEV|COR/i) ? "" : $BUILD)."_${BIT}_${LC_STATE}";

$SAPDB_POOL_ROOT = ((exists $ENV{'SAPDB_POOL_ROOT'} and $ENV{'SAPDB_POOL_ROOT'} =~ /\S/) ? $ENV{'SAPDB_POOL_ROOT'} : '/SAPDB_COMPONENTS_POOL');
$SAPDB_POOL_DIR = "$SAPDB_POOL_ROOT/SDBC_$MAJ$MIN$COR".(($LC_STATE =~ /DEV|COR/i) ? "" : $BUILD)."_${BIT}_${LC_STATE}";



$image_server="p26325.bea.sap.corp";
$XMLFile = "$ENV{'WRK'}/fast/install/pcr_releases.xml";
$CDImagePath = 'CD-Images/PCR_REL';
$CDImagePath =~ s/\//\\/g if $^O =~ /mswin/i; 
if($^O=~/.*win32.*/i){
	$ARCH="i386";
	$ARCH='ia64' if exists $ENV{'BIT64'};
	$OS="win";
	$CDIMAGEOS='NT';
	$LIBPATH="pgm";
	$SOEXT="dll";
	$EXEEXT = '.exe';
	$OS32_PATH = "NT\\I386";
	$OS64_PATH = "NT\\IA64";
}
elsif($^O=~/linux/i){
	$ARCH="i386";
	$ARCH='ia64' if exists $ENV{'BIT64'};
	$OS="linux";
	$SOEXT="so";
	$OS32_PATH="UNIX/LINUX_32";
}
elsif($^O=~/.*aix.*/i){
	$ARCH="ppc";
	$SOEXT="so";
	$OS32_PATH="UNIX/AIX_32";
	my $outtext = `oslevel`;
	if($outtext =~ /^5/){
		$OS = 'aix5';
		$OS64_PATH = 'UNIX/AIX5_64';
	}
	else{
		$OS="aix";
		$OS64_PATH="UNIX/AIX_64";
	}	
}
elsif($^O=~/.*solaris.*/i){
	$ARCH="sparc";
	$OS="sun";
	$SOEXT="so";
	$OS32_PATH="UNIX/SUNOS_32";
	$OS64_PATH="UNIX/SUNOS_64";
}
elsif($^O=~/.*osf.*/i){
	$ARCH="alpha";
	$OS="tru64";
	$SOEXT="so";
	$OS64_PATH="UNIX/DEC_64";
}
elsif($^O=~/.*hp.*/i){
	$ARCH="hppa";
	$OS="hpux";
	$SOEXT="sl";
	$OS32_PATH="UNIX/HP11_32";
	$OS64_PATH="UNIX/HP11_64";
}
elsif($^O=~/svr4/i){
	$ARCH="mips";
	$OS="reliant";
	$SOEXT="so";
	$OS32_PATH="UNIX/RLX_32";
	$OS64_PATH="UNIX/RLX_64";
}

$LC_PACK_NAME_OLD = "sapdb-server-$OS-${BIT}bit-$ARCH-${MAJ}_${MIN}_${cor}_${build}.sar";


$RUNTIME_VERSION = "$MAJ$MIN$COR";
if($MAJ == 7 && $MIN == 2){
	my $cor = $COR;
	$cor =~ s/^0*//; # remove nulls at begin of line
	$RUNTIME_VERSION = $MAJ.$MIN.$cor.'0'; 
}

$RUNTIME_PATH= 'runtime/'.$RUNTIME_VERSION;


#
# find out if it is a final assembly make
#

if ($^O !~ /mswin/i){
	if(-d $LC_POOL_ROOT && ($> == getpwnam('makefact') || $> == getpwnam('falcmake') || $> == getpwnam('vmake'))){	
		$EM_MAKE = 1;
	}
}

if(exists $ENV{'EM_MAKE'}){
		$EM_MAKE = 1;
	}



#
# special vars for APO COM packages
#

if(exists $ENV{'APOMAKE'}){

	$APOMAKE = 1;

	my ($maj,$min,$cor,$build) = ($ENV{'LCVERSION'} =~ /SAPDB_(\d)(\d)(\d+)_b(\d+)/);
	my $cor_short = $cor;
	$cor_short =~ s/^0*//;						# remove leading zeros
	$cor_short = '0' unless $cor_short =~ /\S/;	#
	my $build_short = $build;
	$build_short =~ s/^0*//;
	$build_short eq '' and $build_short = '0';
	$cor = "0$cor" if length($cor) == 1;
	$build = "0$build" if length($build) == 1;

	
	$LC_OWN = $ENV{'LC_OWN'};
	
	if($^O =~ /mswin/i){
		($LC_BUILD_SELECT) = ($LC_OWN =~ /\\(\d{3})\\*$/);
	}
	else{
		($LC_BUILD_SELECT) = ($LC_OWN =~ /\/(\d{3})\/*$/);
	}
		
	
	defined $LC_BUILD_SELECT and $LC_BUILD_SELECT =~ /\S/ or 
	$LC_BUILD_SELECT = 'LastBuild';
	
	$LC_PACK_NAME_OLD = "sapdb-server-$OS-${BIT}bit-$ARCH-${maj}_${min}_${cor_short}_${build_short}.sar";
	
	$LC_INNER_SUBDIR = "sapdb-server-$OS-${BIT}bit-$ARCH-${maj}_${min}_${cor_short}_${build_short}";


	$LC_PACK_NAME = "SAPDB${maj}${min}${cor}_${build}.SAR";

	$LC_RELEASE = "$maj.$min.$cor.$build";
	
	$LC_ROOT = $ENV{'LCROOT'};

	($APO_STATE) = ($ENV{'BRANCH_INFO'} =~ /(DEV|COR|HOT)/);
	$APO_STATE = 'RAMP' unless defined $APO_STATE;
 	
	$LC_POOL_DIR = "$LC_POOL_ROOT/LC_$maj$min$cor".(($LC_STATE =~ /DEV|COR/i) ? "" : $build)."_${BIT}_${LC_STATE}";

	$APO_REL = $ENV{'APO_COM_RELEASE'};

	$APO_BUILD = $ENV{'APO_COM_BUILD'};
	
	$APO_SHORT_VERS = $APO_REL;

	$APO_SHORT_VERS =~ s/\.//g;

	$APO_SHORT_VERS .= $APO_BUILD; 

	$APO_VARIANT = $ENV{'VMAKE_DEFAULT_VARIANT'};

	defined $APO_VARIANT and $APO_VARIANT =~ /Debug|Release/ or
		$APO_VARIANT = 'Release';
	
	$APO_VARIANT =~ s/Release/opt/;
	$APO_VARIANT =~ s/Debug/dbg/;

	$APO_PACK_NAME_OLD = ["sapdb-apo${APO_SHORT_VERS}_livecache-$OS-${BIT}bit-$ARCH-${maj}_${min}_${cor_short}_${build_short}.sar",
						 "LCA${maj}${min}${cor}${build}_${APO_BUILD}.SAR"							
						];

	$APO_POOL_DIR = "$LC_POOL_DIR/$LC_BUILD_SELECT/LCAPPS_${APO_SHORT_VERS}_${APO_VARIANT}_${APO_STATE}";		
}


sub SetVars{
	my ($hrArgs,$err) = @_;
	ref($hrArgs) eq 'HASH' or return undef;
	my %vars = %$hrArgs;
	foreach my $var (keys(%vars)){
		if(exists $BuildPackage::Vars::{$var}){
			${$var} = $vars{$var};
		}
		else{
			if(defined $err and ref($err) eq 'CODE'){
				&$err ("cannot set unknown scalar \$BuildPackage::Vars::$var to $vars{$var}\n");
			}
		}
	}
		
	return 1;
}

1;

