#!/usr/bin/perl
# toolvars      *** included perl script
#
# @(#)toolvars  12-11-1997
#
# 1996-11-27: add 'mfconcom'-var 'REL' for 'cbackup'
# 1994-01-20: let "OPTIMIZE" depend on "VMAKE_VERSION"
#
# included by several shell scripts, defines system specific values
#
use Env;

if ($RELVER eq ""){
	print "\n!!! WARNING:  RELVER not set!!!\n";
	exit 1;
}

if (! $ENV{INSTROOT}){
	print "\n!!! WARNING:  INSTROOT not set!!!\n";
	exit 1;
}

$ADABAS_COPYRIGHT="Copyright © SAP AG 1997";
if ($RELVER eq "R61") {
	$ADABAS_VERSION="6.1";
}
elsif ($RELVER eq "R62") {
	$ADABAS_VERSION="6.2";
}
elsif ($RELVER eq "R70") {
	$ADABAS_VERSION="7.0";
}
elsif ($RELVER eq "R71") {
	$ADABAS_VERSION="7.1";
}
elsif ($RELVER eq "R72") {
	$ADABAS_VERSION="7.2";
}
elsif ($RELVER eq "R73") {
	$ADABAS_VERSION="7.3";
}


$SQLVERSION="REL30";$ENV{SQLVERSION} = $SQLVERSION; # export $SQLVERSION

$OSSPEC=HPUX;
$ENV{OSSPEC} = $OSSPEC;		# export $OSSPEC
if (defined $ENV{"MACH"}) {
	$MACH = $ENV{"MACH"};
} else {
	$MACH = "PA11";
}
$ENV{MACH} = $MACH;		# export $MACH
$OS = "UNIX";
$ENV{OS}         = $OS;			# export $OS

$COMP="PTOC";
if ($RELVER eq "R61") {
	#@CONCOMOPTS = ( "-REL=R61" );
	@CONCOMOPTS = ( "-$SQLVERSION=1", "-REL=R61" );
	#@CONCOMOPTS = ( "-SAG=1", "-$SQLVERSION=1", "-REL=R61" );
}
else {
	#@CONCOMOPTS = ( );
	@CONCOMOPTS = ( "-$SQLVERSION=1" );
	#@CONCOMOPTS = ( "-SAG=1", "-$SQLVERSION=1" );
}
push @CONCOMOPTS, "-RELVER=$RELVER";
push @CONCOMOPTS, "-DIAGNOSE=1" if defined( $ENV{'DIAGNOSE'} );


if ( not $CC ) {
    $CC = "cc";
}
#else take CC from the environment
if ( not $CXX ) {
	$CXX = "aCC";
}
#else take CXX from the environment PTS 1001861

if ($RELVER ge "R72")  # &gar PTS 1002110
{
	$LD = $CXX;
}
else
{
	$LD	= $CC;
}
if ($MACH eq "HP9") {
	$AS		= "as";
} elsif (($MACH eq "PA11") || ($MACH eq "PA20W")) {
	$AS		= $CC;
}
$AR		= "ar";
$NULL = "/dev/null";
# set C and CXX as environment variable
$ENV{CC}=$CC;
$ENV{CXX}=$CXX;
#
# Additional compiler flags may be set temporary in the environment
# before calling vmake.
#

@ASFLAGS = ();

# 98/06/19 &gar: for differences between C and C++-Compiling in UNIX !
# @CCFLAGS   -> FLAGS for both ( C, C++ )
# @CFLAGS    -> FLAGS for C only
# @CXXFLAGS  -> FLAGS for C++ only
  @CXXFLAGS = split /\s+/, $CXXFLAGS;
  @CFLAGS = split /\s+/, $CFLAGS;
@CCFLAGS = split /\s+/, $CCFLAGS;
push @CCFLAGS, "-D$SQLVERSION",  "-D$OSSPEC", "-D$MACH", "-DSAG";
push @CCFLAGS, "-DDIAGNOSE" if defined( $ENV{'DIAGNOSE'} );
@CCMODEANSI = ();
@CCMODENORM = ();
@CCMODELINT = ();


# RTS 1000166
@EXCEPT_FLAG = ();

push @CCFLAGS, "-D_REENTRANT", "-I$INSTROOT/incl", "-I$WRK/incl";

if ($MACH eq "HP9") {
	@LINTFLAGS = @CCFLAGS;
	push @CCFLAGS, "+DA1.0", "+DS1.0", "-Dunix";
	push @CFLAGS, "-D_FILE_OFFSET_BITS=64";
	@CCMODEANSI = ("-Ae");
	@CCMODELINT = ("-Ae");
	@CCMODENORM = ("-Ae");
} elsif ($MACH eq "PA11") {
	push @CCFLAGS, "-DHP9";
	push @CCFLAGS, "+DA1.1", "+DS2.0", "-Dunix";
	push @CFlags, "-D_FILE_OFFSET_BITS=64";
	@CCMODEKR = ("-Ac", "-D_HPUX_SOURCE");
} elsif ($MACH eq "PA20W") {
	push @CCFLAGS, "-DHP9";
	push @CCFLAGS, "+DA2.0W", "+DS2.0", "-Dunix", "-DBIT64";
	push @CONCOMOPTS, "-BIT64=1";
	@CCMODEKR = ("-Ac", "-D_HPUX_SOURCE");
	push @ASFLAGS, "+DA2.0W", "+DS2.0";
}



# "OPTIMIZE" now depends on "VMAKE_VERSION" (needed on AIX)
if ($CURR_VERSION =~ /^f/i) {
    # the old value, it was used for everything
    if ($MACH eq "HP9") {
        @OPTIMIZE = "+O2";
    } elsif ($MACH eq "PA11") {
		@OPTIMIZE = ("+O3", "+Olibcalls");
    } elsif ($MACH eq "PA20W") {
	    @OPTIMIZE = ("+O3", "+Olibcalls");
	}
}
elsif ($CURR_VERSION =~ /^q/i) { 	@OPTIMIZE = "+O2" }
else {
    # VMAKE_VERSION is quick or slow
    # one level less than fast - not yet really tested
    # the idea is to combine range checks with less risky code
    @OPTIMIZE = "+O2";
}

# CTS 1103440
@DEBUG_FLAGS = ("-g");



# cba 98/07/16 : cause of differeces of C- and C++-Linker
# we may have different linker options on some UNIX-platforms
# we use @LDFLAGS for C-linking and @LDXXFLAGS for C++-Linking
# &gar 99/06/03: for linkdll new variable DLDFLAGS and DLDXXFLAGS
# ( PTS 1103001 )
# initialize
if ($MACH eq "HP9")
{
	@LDFLAGS  = @LDXXFLAGS = ("+DA1.0", "+DS1.0" );
	push @LDXXFLAGS, "-ldld";
	push @LDFLAGS, "-Wl,-a,archive_shared", "-ldld";
	@KLDFLAGS = ("+DA1.0", "+DS1.0", "-Wl,-a,archive");
	@DLDFLAGS  = @DLDXXFLAGS = ("-Wl,-b");
}
elsif ($MACH eq "PA11")
{
	@LDFLAGS  = @KLDFLAGS = @LDXXFLAGS = ("+DA1.1", "+DS2.0" );
	@DLDFLAGS  = @DLDXXFLAGS = ("-b");
}
elsif ($MACH eq "PA20W")
{
	@LDFLAGS  = @KLDFLAGS = @LDXXFLAGS = ("+DA2.0W", "+DS2.0" );
	@DLDFLAGS  = @DLDXXFLAGS = ("-b");
}

# &gar PTS 1001828
@PRF_FLAGS = ();

# &gar OFLAGS for call options
# used in link... and comp...
# always initialize here with ()
@OFLAGS=();

$SR_ID = "static char ident_sr[] =";
$MF_ID = "static char ident_mf[] =";
$PC_ID = "static char ident_pc[] =";
$CC_ID = "static char ident_cc[] =";
$ID_END= ";";

if (($MACH eq "HP9") || ($MACH eq "PA11")) {
	@PCFLAGS= ( "-qn", "-e" );
} elsif ($MACH eq "PA20W") {
	@PCFLAGS= ( "-qn", "-e" , "-64" );
}
@ARFLAGS = ( "rcs" );
$RANLIB = "ar ts";


if (($MACH eq "HP9") || ($MACH eq "PA11")) {
	@LIBPC = ( "$TOOL/lib/libsqlptc.a" );	# static, not dynamic lib
	@LIBPC_PROF = ( "$TOOL/lib/libsqlptc.a");	# static, not dynamic lib
} elsif ($MACH eq "PA20W") {
	@LIBPC = ( "$TOOL/lib/pa20_64/libsqlptc.a");
	@LIBPC_PROF = ( "$TOOL/lib/pa20_64/libsqlptc.a");
}
if ($MACH eq "HP9") {
	@LIBSCR = "-lHcurses";
} else {
	@LIBSCR = "-lcurses";
}
@LIBMATH = "-lm";
@DYNAMIC_LIB = ();
@LIBNET = ();
@LIBCSCI    = ();

#
# PTS 1002837 jrg 26.5.1999
@LIBMPROC = ();

@LIBAIO = ();


if ( $SQLVERSION eq "REL30" )  { $TRACETYPE = "tsp_trace" }
	else { $TRACETYPE = "tracetext" }


#################################################
# vmake environment variables must be set by hand
#################################################

if ( ! $DEVENV ) {
#   $DEVENV = "YES";		# Pascal vsp-modules
    $DEVENV = "NO";			# Assembler or C vsp-modules
}
$ENV{DEVENV} = $DEVENV; # export $DEVENV

undef($CCOMP);
$CCOMP = "GENC";
$ENV{CCOMP} = $CCOMP;
undef($CPPCOMP);
undef($COBCOMP);
undef($FORCOMP);
undef($PASCOMP);


# ================================================================

$DLL_TYPE = "sl";
if (($MACH eq "HP9") ||($MACH eq "PA11")) {
	push @CCFLAGS, "+Z";		# "position independent code" required
}
$ENV{DLL_TYPE} = $DLL_TYPE;		# can be exported even if not set

$ARCH_TYPE = ".a";
$ENV{ARCH_TYPE} = $ARCH_TYPE;		# can be exported even if not set

# PTS 1103820 jrg
# since it can be expected to have python and/or perl already installed
# on the machine, the location of includes and libraries needed can be
# overwritten by environment.
#
if (! $ENV{PYTHON_INCLUDE})
{
	$PYTHON_INCLUDE = $ENV{TOOL} . "/Python/include";
    $ENV{PYTHON_INCLUDE} = $PYTHON_INCLUDE;
}
if (! $ENV{ACTIVEPERL_INCLUDE})
{
	$ACTIVEPERL_INCLUDE = "";
	$ENV{ACTIVEPERL_INCLUDE} = $ACTIVEPERL_INCLUDE;
}
if (! $ENV{ACTIVEPERL_LIB})
{
	$ACTIVEPERL_LIB = "";
	$ENV{ACTIVEPERL_LIB} = $ACTIVEPERL_LIB;
}
if (! $ENV{COREPERL_INCLUDE})
{
	$COREPERL_INCLUDE = $ENV{TOOL} . "/Perl/lib/CORE";
	$ENV{COREPERL_INCLUDE} = $COREPERL_INCLUDE;
}
if (! $ENV{COREPERL_LIB})
{
	$COREPERL_LIB = $ENV{TOOL} . "/Perl/lib/CORE";
	$ENV{COREPERL_LIB} = $COREPERL_LIB;
}

# CTS 1103482
if ($MACH eq "PA20W") {
	$ENV{INSTLIB} = $INSTROOT."/lib/pa20_64";
} else {
    $ENV{INSTLIB} = $INSTROOT."/lib";
}

$TraceFile = "$WRK/$VMAKE_VERSION/prot/trace.prot";
sub ToolTrace {
	# usage ToolTrace($string, \@daten)
	if ( $ENV{'TOOLTRACE'}) {
		local( $string, $r_daten ) = @_;
		open( TOOLTRACE, ">>$TraceFile") || die "Can't open $TraceFile (append): $!\n";
		print TOOLTRACE sprintf($string, @$r_daten);
		close(TOOLTRACE);
	}
}


# initializing flush of output buffer
$|=1; print "";
