#!/usr/bin/perl -w
#
# Program:     set_soenv.in
# Version:     $Revision: 1.157 $
# Date:        $Date: 2007/10/04 08:12:49 $
# Author:      Willem van Dorp, Ross Nicholson, Oisin Boydell - Sun Microsystems, Ireland.
#
#---------------------------------------------------------------------------
#---------------------------------------------------------------------------
# Description:
# set_soenv generates a file that contains all necessary 
# environment variables for the build proces of OpenOffice
# on Linux, NetBSD, Solaris, Windows NT and Mac OS X/Darwin.
#
# Program steps.
#
# I.    Checking the command-line arguments.
# IIa.  Declaring variables for the system commands, etc.
# IIb.  Declaring the environment variables.
# III.  Initialising the variables for the system commands, etc.
# IV.   Print out some important messages etc.
# V.    Initialising the environment variables.
# VI.   Open the output file.
# VII.  Writing the data to the output file.
# VIII. Closing output file.
# IX.   Sourcing the output file.
# X.    Set up the build environment.
# XI.   Moving the output file to the build home directory.
#
#---------------------------------------------------------------------------
#
use strict;                        # pragma
use File::Basename;


#
#--------------------------------------------------------
# IIa. Declaring variables for the system commands, etc.
#--------------------------------------------------------
#
my ( $outfile, $outfile_sh, $outfile_bat, $bootfile, $newline, $comment, $comment4nt, $compiler, $unsetenv, $setenv, $unset, $set, $ds, $ps, $cur_dir, 
     $par_dir, $I, $L, $D, $buildenv, $answer, $tmp, $MINGW, $USE_MINGW, $platform,
     $cygwinver, $empty, $no_ant, $no_stl, $no_gcc_include, 
     $no_gxx_include, $warnfile, $Warning, $result, $unsetvars, $unsetvarssh, $unsetvarsbat, $exportvars, $win_format_var, $perl_os, @mingw_lib_include_paths, $mingw_lib_include_path);
#
#-------------------------------------------------
# IIb. Declaring environment values (constants).
#-------------------------------------------------
#
# Platform independent constant values.
my @DICTIONARIES = ("DADK", "DEDE", "ENGB", "ENUS", "HUHU", "ITIT", "RURU", "THTH", "SWTZ" );
my ( $CALL_CDECL, $COMMON_OUTDIR, $BMP_WRITES_FLAG, 
     $common_build, $NO_REC_RES, $SO3, $SOLAR_JAVA, 
     $SOLAR_PLUGIN, $TF_PACKAGES, $TF_SDBAPI, $TF_FILEURL, $UPDATER, $BUILD_DELIVER, $VCL, 
     $TF_CFGDATA, $TF_SVDATA, $CC, $CXX,
     $BUILD_SOSL, $ENABLEUNICODE, $NEW_JAR_PACK, $NO_BSYMBOLIC, 
     $BUILD_SOSL_RELEASE, $RSC_ONCE );
#
# Platform dependent constant values.
my ( $BIG_SVX, $COM, $CPU, $CPUNAME, $CVER, $GLIBC, $GUI, $GUIBASE, $GUIENV,
      $GVER, $GVERDIR, $OS, $OSVERSION, $OUTPATH, $INPATH, $PATH_SEPERATOR, $XPVERSION,
      $DYNAMIC_CRT, $SET_EXCEPTIONS, $use_shl_versions, $CDPATHx, $JRELIBDIR,
      $JREEXTRALIBDIR, $JRETOOLKITDIR, $JRETHREADDIR, $EXCEPTIONS, $WRAPCMD );
#
#-------------------------------------------
# IIc. Declaring the environment variables.
#-------------------------------------------
#
# Help variables.
my ( $USR, $ETC, $BIN, $LIB, $LIB64, $INC, $INCLUDE, $DEV, $OPT, $LOCAL, $SOLENV, $SOLVER, $CONFIG, 
     $USR_BIN, $USR_LIB, $USR_LOCAL, $USR_CCS, $JAVA_BIN, $JAVA_LIB, $JAVA_INCLUDE,
     $SOLARENVINC, $USR_DT, $USR_OPENWIN, $SHELL_PATH, $XLIB, $XINC,
     $CYGWIN_PATH, $language, $dict, $ASM_PATH, $ps_STLPORT_LIB, $L_STLPORT_LIB,
     $STLPORT_stlport, $STLPORT_inc_stlport, $PERL_PATH );

# Environment variables.
my ( $oldPATH, $SRC_ROOT, $SO_HOME, $JAVA_HOME, $JDK, $SHELL,
     $UPD, $SOLARUPD, $WORK_STAMP, $TF_UCB, 
     $SOLARSRC, $DEVROOT, $SOLARVER, $SOLARVERSION, $SOLARENV, 
     $STAR_INIROOT, $STAR_INIROOTOLD, $STAR_STANDLST, $STAR_SSCOMMON, $STAR_SSOLARINI, 
     $STAR_REGISTRY, $STAR_RESOURCEPATH, $DMAKEROOT, $CLASSPATH, $XCLASSPATH, $COMPATH,
     $MSPDB_PATH, $MIDL_PATH, $CSC_PATH,
     $LD_LIBRARY_PATH, $PATH, $SOLAREXTRAINC, $SOLAREXTRALIB, $SOLARLIB, 
     $SOLARINC, $LOCALINI, $PATHEXTRA, $FRAMEWORKSHOME, $COMEX, $PERL, 
     $COMP_ENV, $ILIB, $JAVAHOME, $PSDK_HOME, $DIRECTXSDK_LIB, $USE_NEW_SDK, $FRAME_HOME, 
     $ATL_LIB, $ATL_INCLUDE, $MFC_LIB, $MFC_INCLUDE, $NO_HIDS, $TEMP, $COMMON_BUILD_TOOLS, $WIN_GREP, $WIN_FIND, $WIN_LS,
     $WIN_GNUCOPY, $WIN_TOUCH, $STLPORT4, $MOZILLA_VERSION, $MOZILLA_TOOLKIT, $PREBUILD_MOZAB,
	 $PROEXT,
     $SYSTEM_PYTHON, $PYTHONPATH, $PYTHONHOME, $SYSTEM_MOZILLA);
#
#-------------------------------------------
# IId. Declaring the aliases.
#-------------------------------------------
#
my ( $dmake, $build, $build_client, $nmake, $mkout, $deliver, $zipdep );
#

#-------------------------------------------------------------
# IIIa. Initialising constants.
#-------------------------------------------------------------
#
$UPD            = '680';          # the project's UPD
$newline        = "\n";             # Perl newline character
$unsetenv       = "unsetenv";       # c-shell command
$setenv         = "setenv";         # c-shell command
$unset          = "unset";          # msdos batch file command
$set            = "set";            # msdos batch file command
$ds             = "/";              # directory separator
$ps             = ":";              # path separator
$cur_dir        = ".";              # current directory
$par_dir        = "..";             # parrent directory
$I              = " -I";            # include search path
$L              = " -L";            # library search path
$D              = " -D";            # define search path
$empty          = "";               # used as argument
$no_stl         = "NO_STLPORT4";    # possible argument
$warnfile       = "warn";           # logfile configure warnings.
$Warning        = "";               # container for warning messages
$STLPORT4       = 'NO_STLPORT4';     # Location of STLport4
$SYSTEM_PYTHON	= 'YES';
$SYSTEM_MOZILLA = '';
$JDK 		= 'sun';
$MINGW          = '0'; # use MinGW for Windows build
$USE_MINGW      = '';     # use MinGW in cygwin or pure-mingw
$CC             = 'cc';           # C compiler
$CXX            = 'c++';          # C++ compiler
$EXCEPTIONS     = 'dwarf2';   # Exception handling type
$MOZILLA_VERSION	= ''; # mozilla version to use to build mozilla
$MOZILLA_TOOLKIT	= ''; # GUI toolkit to use to build mozilla
$WRAPCMD        = "";               # Wrapper (only for winnt)
$GLIBC          = "";               # Whether the platform uses glibc
$PROEXT         = ".pro";

#
#--------------------------------------------------------------------
# IV. Initialise the warning container and print a note to the user.
#--------------------------------------------------------------------
#
# Add the configure (pre-requisite) warnings to the warning container
# , $Warning.
AddWarning( "configure", "" );
#
print ("Setting up the environment for building OpenOffice.org $newline");
#
#--------------------------------------------------
# V. Setting the environment variables/values.
#--------------------------------------------------
#
# A. Checking the platform first.
#
if ('DEFAULT' eq "DEFAULT")
{  $platform          = `../solenv/bin/config.guess`;
}
else
{  $platform           = `PosixFormat('DEFAULT')/bin/config.guess`;

}

chomp( $platform );

# get perls idea for OS
# needed to differentiate cygwin/native perl on windows
$perl_os = $^O;

#
# B. Gathering information from the system.
#
# 1. Path
$oldPATH = $ENV{"PATH"};
chomp( $oldPATH );                  # cut off new line
#
# C. Setting the constant values.
#
# Setting platform independent constant values.
print "Setting platform independent values... ";
# NB: Language options now set at 'ToFile' stage. 
$BMP_WRITES_FLAG      = "TRUE";
$BUILD_SOSL_RELEASE   = "TRUE";
$RSC_ONCE             = "TRUE";
$CALL_CDECL           = "TRUE";
$COMMON_OUTDIR        = "";
$common_build         = "";
$NO_REC_RES           = "TRUE";
$NO_HIDS              = "TRUE";
$SO3                  = "TRUE";
$SOLAR_JAVA           = "TRUE";
$SOLAR_PLUGIN         = "TRUE";
$TF_PACKAGES          = "TRUE";
$TF_FILEURL           = "TRUE";
$TF_CFGDATA           = "TRUE";
$TF_SVDATA            = "TRUE";
$TF_SDBAPI            = "ist_da";
$TF_UCB               = "ist_da";
$UPDATER              = "YES";
$BUILD_DELIVER        = "true";
$VCL                  = "TRUE";
$BUILD_SOSL           = "true";
$ENABLEUNICODE        = "TRUE";
$NEW_JAR_PACK         = "TRUE";
$NO_BSYMBOLIC         = "TRUE";
$comment              = "#";           # UNIX script comment character
$comment4nt           = "rem";         # Windows 4nt script comment character

# Some JREs do not need the following variable.
$JREEXTRALIBDIR = "";

# Setting platform dependent constant values.
if ( $platform =~ m/solaris/ ) 
{     print "Setting Solaris specific values... ";
   if ($platform =~ m/^i[3456]86/)
   {  
      if ( $CC =~ "gcc") {
         $outfile        = "SolarisX86GccEnv.Set";
         $OUTPATH        = "unxsogi";
      } else {
         $outfile        = "SolarisX86Env.Set";
         $OUTPATH        = "unxsoli4";
      }
      $CPU            = "I";
      $CPUNAME        = "INTEL";
	  $JRELIBDIR      = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."i386";
	  $JRETOOLKITDIR  = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."i386".$ds."motif21";
	  $JRETHREADDIR   = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."i386".$ds."native_threads";

   }
   else
   {
      if ( $CC =~ "gcc") {
         $outfile        = "SolarisSparcGccEnv.Set"; 
         $OUTPATH        = "unxsogs";
      } else {
         $outfile        = "SolarisSparcEnv.Set"; 
         $OUTPATH        = "unxsols4";
      }
      $CPU            = "S";
      $CPUNAME        = "SPARC";
	  $JRELIBDIR      = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."sparc";
	  $JRETOOLKITDIR  = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."sparc".$ds."motif21";
	  $JRETHREADDIR   = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."sparc".$ds."native_threads";
   }

   if ( $CC =~ "gcc") {
       $COM            = "GCC";
       $CVER           = "C300";
   } else {
       $COM            = "C52";
       $CVER           = "C52";
       $COMEX          = 4;
   }
   $BIG_SVX        = "TRUE";
   $COMPATH        = '/usr/bin'; 
   $GUI            = "UNX";
   $GUIBASE        = "unx";
   $GUIENV         = "sal";
   $GVER           = "VCL";
   $INPATH         = $OUTPATH.$PROEXT;
   $GVERDIR        = $INPATH;
   $OS             = "SOLARIS";
   $PATH_SEPERATOR = $ps;
}
elsif ( $platform =~ m/netbsd/ ) 
{
#Set platform specific values: 
   if ($platform =~ m/^i[3456]86/)
   {  print "Setting NetBSD x86 specific values... ";
      $outfile        = "NetBSDX86Env.Set"; 
      $CPU            = "I";
      $CPUNAME        = "INTEL";
      $OUTPATH        = "unxbsdi";
      $JRELIBDIR      = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."i386";
      $JRETOOLKITDIR  = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."i386".$ds."client";
      $JRETHREADDIR   = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."i386".$ds."native_threads";
   }
   elsif ($platform =~ m/^sparc/)
   {  print "Setting NetBSD Sparc specific values... ";
      $outfile        = "NetBSDSparcEnv.Set"; 
      $CPU            = "S";
      $CPUNAME        = "SPARC";
      $OUTPATH        = "unxbsds";
      $JRELIBDIR      = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."sparc";
      $JRETOOLKITDIR  = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."sparc".$ds."client";
      $JRETHREADDIR   = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."sparc".$ds."native_threads";
   }
   elsif ($platform =~ m/powerpc/)
   {  print "Setting NetBSD PPC specific values... ";
      $outfile        = "NetBSDPPCEnv.Set"; 
      $CPU            = "P";
      $CPUNAME        = "POWERPC";
      $OUTPATH        = "unxbsdppc";
      $JRELIBDIR      = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."ppc";
      $JRETOOLKITDIR  = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."ppc".$ds."classic";
      $JRETHREADDIR   = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."ppc".$ds."native_threads";
   }
   else
   { print "Unsupported NetBSD architecture: $platform \n";
     exit 1;
   }
   #Conditional setting depending on gcc3:
      $CVER           = "C300";
      $OUTPATH        = $OUTPATH."2";
   # General NetBSD settings:
      $BIG_SVX        = "TRUE";
      $COM            = "GCC";
      $COMPATH        = '/usr/bin'; 
      $GUI            = "UNX";
      $GUIBASE        = "unx";
      $GUIENV         = "sal";
      $GVER           = "VCL";
      $INPATH         = $OUTPATH.$PROEXT;
      $GVERDIR        = $INPATH;
      $OS             = "NETBSD";
      $PATH_SEPERATOR = $ps;
      $XPVERSION      = "3"; 
}
elsif ( $platform =~ m/freebsd/ ) 
{     $BIG_SVX        = "TRUE";
      $COM            = "GCC";
      $COMPATH        = '/usr/bin'; 
      $CVER           = "C300";
      $GUI            = "UNX";
      $GUIBASE        = "unx";
      $GUIENV         = "sal";
      $GVER           = "VCL";
      $OS             = "FREEBSD";
      $PATH_SEPERATOR = $ps;
      $XPVERSION      = "3";
      $OSVERSION      = '';
   if ($platform =~ m/^amd64/)
   {  my ( $JAVA_OS );
      print "Setting FreeBSD AMD64 specific values... ";
      $outfile        = "FreeBSDAMDEnv.Set";
      $CPU            = "X";
      $CPUNAME        = "X86_64";
      $OUTPATH        = "unxfbsdx";
      $JAVA_OS        = '/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home';
      $JAVA_OS        =~ s/.*\///;
      if ($JAVA_OS =~ m/^linux/)
      {  $JRELIBDIR      = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."i386";
         $JRETOOLKITDIR  = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."i386".$ds."client";
         $JRETHREADDIR   = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."i386".$ds."native_threads";
         $JREEXTRALIBDIR = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."i386".$ds."xawt";
      }
      else
      {  $JRELIBDIR      = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."amd64";
         $JRETOOLKITDIR  = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."amd64".$ds."server";
         $JRETHREADDIR   = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."amd64".$ds."native_threads";
         $JREEXTRALIBDIR = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."amd64".$ds."xawt";
      }
   }
   elsif ($platform =~ m/^i386/)
   {  print "Setting FreeBSD x86 specific values... ";
      $outfile        = "FreeBSDX86Env.Set";
      $CPU            = "I";
      $CPUNAME        = "INTEL";
      $OUTPATH        = "unxfbsdi";
      $JRELIBDIR      = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."i386";
      $JRETOOLKITDIR  = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."i386".$ds."client";
      $JRETHREADDIR   = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."i386".$ds."native_threads";
      $JREEXTRALIBDIR = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."i386".$ds."xawt";
   }
   else
   {  print "Unsupported FreeBSD architecture: $platform \n";
         exit 1;
   }
   if( 40001 >= 30401 ) {
      $CVER        = "C341";
   }
      $INPATH         = $OUTPATH.$PROEXT;
      $GVERDIR        = $INPATH;
} 
elsif ( $platform =~ m/linux-gnu/ ) 
{
# General Linux settings:
      $CVER           = "C300";
      $BIG_SVX        = "TRUE";
      $COM            = "GCC";
      $COMPATH        = '/usr/bin'; 
      $GLIBC          = "2REDHAT60";
      $GUI            = "UNX";
      $GUIBASE        = "unx";
      $GUIENV         = "sal";
      $GVER           = "VCL";
      $OS             = "LINUX";
      $PATH_SEPERATOR = $ps;
      $XPVERSION      = "3"; 

#Set platform specific values: 
   if ($platform =~ m/^i[3456]86/)
   {  print "Setting Linux x86 specific values... ";
      $outfile        = "LinuxX86Env.Set"; 
      $CPU            = "I";
      $CPUNAME        = "INTEL";
      
      if ($JDK =~ m/^[Ii][Bb][Mm]/)
      { $JRELIBDIR     = '$JAVA_HOME'.$ds."jre".$ds."bin";
        $JRETOOLKITDIR = '$JAVA_HOME'.$ds."jre".$ds."bin".$ds."classic";
        $JRETHREADDIR  = '$JAVA_HOME'.$ds."jre".$ds."bin"; }

      elsif ($JDK =~ m/^[Bb][Ee][Aa]/)
      { $JRELIBDIR     = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."i386";
        $JREEXTRALIBDIR = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."i386".$ds."xawt";
        $JRETOOLKITDIR  = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."i386".$ds."jrockit";
        $JRETHREADDIR   = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."i386".$ds."native_threads"; }

      else {      
      $JRELIBDIR      = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."i386";
        $JREEXTRALIBDIR = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."i386".$ds."xawt";
      $JRETOOLKITDIR  = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."i386".$ds."client";
      $JRETHREADDIR   = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."i386".$ds."native_threads";
      }

      if( 40001 >= 30401 ) {
         $OUTPATH     = "unxlngi6";
      	 $CVER        = "C341";
      }
      else {
         $OUTPATH     = "unxlngi4";
      }
   }
   elsif ($platform =~ m/^x86_64/)
   {  print "Setting Linux x86-64 specific values... ";
      $outfile        = "LinuxX86-64Env.Set";
      $CPU            = "X";
      $CPUNAME        = "X86_64";
      $CVER           = "C341";
      $OUTPATH        = "unxlngx6";
      # Blackdown.org JDK porting project uses `amd64' and `server' in JDK 1.4.2 RC1
      $JRELIBDIR      = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."amd64";
      $JRETOOLKITDIR  = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."amd64".$ds."server";
      $JRETHREADDIR   = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."amd64".$ds."native_threads";
   }
   elsif ($platform =~ m/^sparc/)
 
   {  print "Setting Linux Sparc specific values... ";
      $outfile        = "LinuxSparcEnv.Set"; 
      $CPU            = "S";
      $CPUNAME        = "SPARC";
      $OUTPATH        = "unxlngs";
      $JRELIBDIR      = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."sparc";
      $JRETOOLKITDIR  = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."sparc".$ds."client";
      $JRETHREADDIR   = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."sparc".$ds."native_threads";
   }
   elsif ($platform =~ m/^powerpc/)
   {
      if (($platform =~ m/^powerpc64/) && ('4' eq '8')) {
         print "Setting Linux PPC64 specific values... ";
         $outfile = "LinuxPPC64Env.Set"; 
         $OUTPATH = "unxlngppc64";
         $CPUNAME = "POWERPC64";

         if ( $JDK eq "gcj" ) {
            $JRELIBDIR      = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."ppc64";
            $JRETOOLKITDIR  = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."ppc64".$ds."client";
            $JRETHREADDIR   = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."ppc64".$ds."native_threads";
         }
      }
      else {
         print "Setting Linux PPC specific values... ";
         $outfile = "LinuxPPCEnv.Set"; 
         $OUTPATH = "unxlngppc";
         $CPUNAME = "POWERPC";

         if ( $JDK eq "gcj" ) {
            $JRELIBDIR      = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."ppc";
            $JRETOOLKITDIR  = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."ppc".$ds."client";
            $JRETHREADDIR   = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."ppc".$ds."native_threads"; }
         elsif ($JDK =~ m/^[Ii][Bb][Mm]/)
         {  $JRELIBDIR     = '$JAVA_HOME'.$ds."jre".$ds."bin";
            $JRETOOLKITDIR = '$JAVA_HOME'.$ds."jre".$ds."bin".$ds."classic";
            $JRETHREADDIR  = '$JAVA_HOME'.$ds."jre".$ds."bin";
            $JREEXTRALIBDIR = '$JAVA_HOME'.$ds."jre".$ds."bin".$ds."xawt";
         }
      }

      $CPU            = "P";

# the "standard" ppc j2sdk is IBMJava2-ppc-142
      if ( $JDK ne "gcj" ) {
          $JRELIBDIR      = '$JAVA_HOME'.$ds."jre".$ds."bin";
          $JRETOOLKITDIR  = '$JAVA_HOME'.$ds."jre".$ds."bin".$ds."classic";
          $JRETHREADDIR   = '$JAVA_HOME'.$ds."jre".$ds."bin";
      }
   }
   elsif ($platform =~ m/^s390/)
   {  print "Setting Linux S/390 specific values... ";
      $outfile        = "LinuxS390Env.Set";
      $CPU            = "3";
      $CPUNAME        = "S390";
      $OUTPATH        = "unxlngs390";
      $JRELIBDIR      = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."s390";
      $JRETOOLKITDIR  = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."s390".$ds."client";
      $JRETHREADDIR   = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."s390".$ds."native_threads";
   }
   elsif ($platform =~ m/^alpha/) 
   {  print "Setting Linux Alpha specific values... ";
      $outfile        = "LinuxAlphaEnv.Set"; 
      $CPU            = "A";
      $CPUNAME        = "ALPHA_";
      $OUTPATH        = "unxlnga";
      $JRELIBDIR      = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."alpha";
      $JRETOOLKITDIR  = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."alpha".$ds."client";
      $JRETHREADDIR   = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."alpha".$ds."native_threads";
   }
   elsif ($platform =~ m/^arm[45]l/) 
   {  print "Setting Linux ARM specific values... ";
      $outfile        = "LinuxARMEnv.Set"; 
      $CPU            = "R";
      $CPUNAME        = "ARM";
      $OUTPATH        = "unxlngr";
      $JRELIBDIR      = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."arm";
      $JRETOOLKITDIR  = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."arm".$ds."client";
      $JRETHREADDIR   = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."arm".$ds."native_threads";
   }

   $INPATH         = $OUTPATH.$PROEXT;
   $GVERDIR        = $INPATH;
}
elsif ( $platform =~ m/osf1/ ) 
{     print "Setting Tru64 specific values... ";
      $outfile        = "Tru64AlphaEnv.Set"; 
      $BIG_SVX        = "TRUE";
      $COM            = "CXX";
      $COMPATH        = '/usr/bin'; 
      $CPU            = "A";
      $CPUNAME        = "ALPHA_";
      $CVER           = "C62";
      $GUI            = "UNX";
      $GUIBASE        = "unx";
      $GUIENV         = "sal";
      $GVER           = "VCL";
      $OUTPATH        = "unxt64";
      $INPATH         = $OUTPATH.$PROEXT;
      $GVERDIR        = $INPATH;
      $OS             = "TRU64";
      $PATH_SEPERATOR = $ps;
      $XPVERSION      = "3";
      $JRELIBDIR      = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."alpha";
      $JRETOOLKITDIR  = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."alpha".$ds."client";
      $JRETHREADDIR   = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."alpha".$ds."native_threads";
} 
elsif ( $platform =~ m/irix/ )
{     print "Setting Irix specific values... ";
      $outfile        = "IrixMipsEnv.Set";
      $BIG_SVX        = "TRUE";
      if ($CC =~ "gcc" ) {
            $COM          = "GCC";
            $OUTPATH        = "unxirgm";
            $CVER           = "C300";
      }
	  else {
	  	$COM            = "C730";
        $CVER           = "C730";
        $OUTPATH        = "unxirxm3";
      }
      $COMPATH        = '/usr/bin';
      $CPU            = "M";
      $CPUNAME        = "MIPS";
      $GUI            = "UNX";
      $GUIBASE        = "unx";
      $GUIENV         = "sal";
      $GVER           = "VCL";
      $INPATH         = $OUTPATH.$PROEXT;
      $GVERDIR        = $INPATH;
      $OS             = "IRIX";
      $PATH_SEPERATOR = $ps;
      $XPVERSION      = "3";
      $JRELIBDIR      = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."mips";
      $JRETOOLKITDIR  = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."mips".$ds."client";
      $JRETHREADDIR   = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."mips".$ds."native_threads";
}
elsif ( $platform =~ m/cygwin/ ) 
{ 
      $COMPATH        = PosixFormat('/usr/bin');
      $MSPDB_PATH     = PosixFormat('');
      $MIDL_PATH      = PosixFormat('');
      $CSC_PATH       = PosixFormat('');
      $PSDK_HOME      = PosixFormat('');
      $DIRECTXSDK_LIB = PosixFormat('');
      $FRAME_HOME     = PosixFormat('');
      $USE_NEW_SDK    = "TRUE";
      $CPUNAME        = "INTEL";
      $CPU            = "I";
      $GUI            = "WNT";
      $GUIBASE        = "WIN";
      $GUIENV         = "WNT";
      $GVER           = "NT351";
      $OS             = "WNT";
      $DYNAMIC_CRT    = "TRUE";
      $SET_EXCEPTIONS = "TRUE";
      $use_shl_versions = "TRUE";
  if ( $MINGW eq "yes" )
  {   # At the moment this implies the use of tcsh
	  print "Setting Windows NT cygwin MinGW specific values... ";
	  $WRAPCMD        = "guw.exe";
      $outfile        = "winmingw.set"; 
      $COM            = "GCC";
      $COMPATH        =~ s/\/bin$//i;
      if ( $USE_MINGW ne "cygwin" )
      { $CC             = $WRAPCMD." ".$CC;
        $CXX            = $WRAPCMD." ".$CXX;
      }
      $CVER           = "C341";
      $OUTPATH        = "wntgcci";
      $INPATH         = $OUTPATH.$PROEXT;
      $GVERDIR        = $INPATH;
      $PATH_SEPERATOR = ':';
      $ATL_INCLUDE = '$SOLARVER'.$ds.'$INPATH'.$ds."inc".$ds."external".$ds."mingw".$ds."include".$ds."atl". " ".'$PSDK_HOME'.$ds."include".$ds."atl";
  }
  else # The MSVC section starts here
  {   $outfile        = "winenv.set";
      $COM            = "MSC";
      # COMPATH for MSC is differently used
      $COMPATH        =~ s/\/bin$//i;
      $OUTPATH        = "wntmsci";
      $INPATH         = $OUTPATH.$PROEXT;
      $GVERDIR        = $INPATH;
      $COMEX          = '';
      if ( "" eq "10" ) { # .NET 2003 needs M1310
          $CVER        = "M1310";
          $ATL_LIB     = $COMPATH.$ds."atlmfc".$ds."lib";
          $ATL_INCLUDE = $COMPATH.$ds."atlmfc".$ds."include";
          $MFC_LIB     = "";
          $MFC_INCLUDE = "";
      } elsif ( "" eq "11" ) { # .NET 2005 needs M1400
          $CVER        = "M1400";
          if ( "" ) {
              $ATL_LIB     = $PSDK_HOME.$ds."lib"; # Doesn't exist for VSE
              $ATL_INCLUDE = $PSDK_HOME.$ds."include".$ds."atl";
              $MFC_LIB     = $PSDK_HOME.$ds."lib"; # Doesn't exist for VSE
              $MFC_INCLUDE = $PSDK_HOME.$ds."include".$ds."mfc";
          } else {
              $ATL_LIB     = $COMPATH.$ds."atlmfc".$ds."lib";
              $ATL_INCLUDE = $COMPATH.$ds."atlmfc".$ds."include";
              $MFC_LIB     = $COMPATH.$ds."atlmfc".$ds."lib";
              $MFC_INCLUDE = $PSDK_HOME.$ds."include".$ds."mfc";
          }
      } else {                   # Unsupported
          die "Unsupported value for COMEX variable.\n";
      }
  if ( "tcsh" ne "4nt" )
  {   print "Setting Windows NT cygwin without 4NT specific values... ";
	  $WRAPCMD        = "guw.exe";
	  $CC             = $WRAPCMD." ".$CC;
	  $CXX            = $WRAPCMD." ".$CXX;
      $PATH_SEPERATOR = ':';
  }
  else # "tcsh" ne "4nt"
  {   print "Setting Windows NT with 4NT specific values... ";
      # Change path to lower case.
      $COMPATH        = lc $COMPATH;
      $PATH_SEPERATOR = ';';
  }

  }
}
elsif ( $platform =~ m/darwin/ ) 
{     print "Setting Mac OS X/Darwin specific values... ";
      $BIG_SVX        = "TRUE";
      $COM            = "GCC";
      $COMPATH        = '/usr/bin'; 
      if ($platform =~ m/^i[3456]86/)
      {
          print "Setting values for Mac OS X/Darwin on x86... ";
          $outfile        = "MacOSXX86Env.Set"; 
          $CPU            = "I";
          $CPUNAME        = "INTEL";
          $OUTPATH        = "unxmacxi";
      }
      elsif ($platform =~ m/^powerpc/)
      {
          print "Setting values for Mac OS X/Darwin on PowerPC... ";
          $outfile        = "MacOSXPPCEnv.Set"; 
          $CPU            = "P";
          $CPUNAME        = "POWERPC";
          $OUTPATH        = "unxmacxp";
      }
      if (40001 >= 30401) {
	  $CVER           = "C341";
      } else {
	  $CVER           = "C300";
      }
      $GUI            = "UNX";
      $GUIENV         = "sal";
      $GVER           = "VCL";
      $INPATH         = $OUTPATH.$PROEXT;
      $GVERDIR        = $INPATH;
      $OS             = "MACOSX";
      $PATH_SEPERATOR = $ps;
      # GUIBASE is set below; may be "aqua" or "unx".
}
elsif ( $platform =~ m/aix/ )
{
   if( $platform !~ m/^powerpc/ )
   {
	print "\nAIX has only been ported and tested on powerpc\n";
	AddWarning( "set_soenv", "Platform $platform has not been tested");
   }
   print "Setting AIX PPC specific values... ";
   $outfile        = "aixPPCEnv.Set"; 
   $CPU            = "P";
   $CPUNAME        = "POWERPC";
   $OUTPATH        = "unxlngppc";
   $JRELIBDIR      = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."ppc";
   $JRETOOLKITDIR  = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."ppc".$ds."classic";
   $JRETHREADDIR   = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."ppc".$ds."native_threads";
   $BIG_SVX        = "TRUE";
   $COM            = "GCC";
   $CVER           = "C300";
   $COMPATH        = '/usr/bin'; 
   $GUI            = "UNX";
   $GUIBASE        = "unx";
   $GUIENV         = "sal";
   $GVER           = "VCL";
   $INPATH         = $OUTPATH.$PROEXT;
   $GVERDIR        = $INPATH;
   $OS             = "AIX";
   $PATH_SEPERATOR = $ps;
   $XPVERSION      = "3"; 
}
else {
	print "\nset_soenv:  Cannot figure out what platform you are running\n";
	print "For $platform.\n";
	exit 1;
}
print "done\n";

#
# D. Gathering directory information from the user.
#
# If the directory does not exist something is strange.
# 1. OpenOffice.org build home directory.
$SRC_ROOT  = `pwd`; 
$SRC_ROOT =~ s/\/config_office//;
chomp($SRC_ROOT);
CheckPathExist( $SRC_ROOT );

#-----------------------------------------------------------------------------------------------------
# Copy top level makefile from config_office/ to $SRC_ROOT
#-----------------------------------------------------------------------------------------------------
if (! -e "makefile.rc")
{  AddWarning( "set_soenv", "makefile.rc not found in config_office/. Could not copy to SRC_ROOT." );
}
else
{  `cp -f makefile.rc $SRC_ROOT/makefile.mk`;
}

# 2. Java home directory.
# JAVA_HOME as argument from autoconf.
$JAVA_HOME = PosixFormat('/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home') ;

if ( $platform =~ m/cygwin/ ) {
   $JAVA_HOME =~ s/[\s\/]+$//;	# remove trailing \n or \/ if there is any.
}
# 3. shell path.
# Check whether autoconf found a valid shell path.
if ("tcsh" eq "tcsh")
{  # SHELL as argument from autoconf.
   $SHELL_PATH = '/bin';
   $SHELL = '/bin'."\/tcsh";
}
elsif ("tcsh" eq "bash")
{
   $SHELL_PATH = '/bin';
   $SHELL = '/bin'."\/bash";
}
elsif ("tcsh" eq "4nt")
{  # /bin is NO_SHELLPATH_NEEDED for 4nt - 
   $SHELL_PATH = '';
}
else {
   die "Not a recognized shell: tcsh !";
}


if ( 'NO_STLPORT4' eq $no_stl )
{
   $STLPORT4 = "$no_stl";
}

# ml.exe assembler path for Windows users.
if ($platform =~ m/cygwin/)
{  $ASM_PATH = PosixFormat('NO_ASM_HOME');
}

# Check for prebuild mozab libraries if we don't build them # ourselves
# and we're also not using the external system mozilla installation.
#
# FIXME! This check should be done in configure and not here, but
# the $OS, $COM, $CPU variables are not yet present there.
#
if ( "NO" eq "YES" and "" ne "TRUE" and "" ne "YES" )
{  print("\nChecking for prebuilt Mozilla libraries ...");
   my $mozbinfile = $SRC_ROOT."/moz/zipped/";
   if ( $^O eq 'MSWin32' ) {
       chomp( $mozbinfile = qx{cygpath -d "$mozbinfile"} );
   }
   $mozbinfile .= $OS.$COM.$CPU;
   if ( -e $mozbinfile."inc.zip"
        and -e $mozbinfile."lib.zip"
        and -e $mozbinfile."runtime.zip" )
   {   print " found.\n";
       $PREBUILD_MOZAB = "YES";
   }
   else
   {   print " not found!\n\n";
       print "If you don\'t use the system mozilla and also not build the needed\n";
       print "mozilla libraries yourself you have to provide the needed files\n";
       print "$OS$COM$CPU\{inc,lib,runtime\}.zip in moz/zipped/ .\n";
       print "These files can be found here:\n";
       print "  <http://tools.openoffice.org/moz_prebuild/680/>.\n\n";
       die;
   }
}
else
{
   $PREBUILD_MOZAB = "";
}

#
# E. Determining the envionment values based on the information
#    that was gathered earlier on.
#
print "Setting the environment variables... ";
$USR                  = $ds."usr";
$ETC                  = $ds."etc";
$BIN                  = $ds."bin";
$LIB                  = $ds."lib";
$LIB64                = $ds."lib";
$LIB64               .= "64"
if ($platform =~ m/x86_64-.*-linux-gnu/);
$LIB64               .= "64" 
if (($platform =~ m/powerpc64-.*-linux-gnu/) && ('4' eq '8'));
$INC                  = $ds."inc";
$INCLUDE              = $ds."include";
$DEV                  = $ds."dev";
$OPT                  = $ds."opt";
$LOCAL                = $ds."local";
$SOLENV               = $ds."solenv";
$SOLVER               = $ds."solver";
$CONFIG               = $ds."config";
$USR_BIN              = $USR.$BIN;
$USR_LIB              = $USR.$LIB64;
$USR_LOCAL            = $USR.$ds."local";
$USR_CCS              = $USR.$ds."ccs";
$USR_OPENWIN          = $USR.$ds."openwin";
$USR_DT               = $USR.$ds."dt";
$COMMON_BUILD_TOOLS   = '$SRC_ROOT'.$ds."external".$ds."common";

# Generate alternate output file for sh?
$outfile_sh = $outfile.".sh";
if ("tcsh" eq "4nt") {
    # Generate output file for 4nt?
    $outfile_bat = $outfile;
    $outfile_bat =~ s/set$/bat/i;
} else {
    undef $outfile_bat;
}

if ($STLPORT4 ne $no_stl) {
	$ps_STLPORT_LIB		= $ps.'$STLPORT4'.$LIB64;
	$L_STLPORT_LIB		= $L.'$STLPORT4'.$LIB64;
	$STLPORT_stlport 	= $I.'$STLPORT4'.$ds.'stlport';
	$STLPORT_inc_stlport	= $I.'$STLPORT4'.$ds.'include'.$ds.'stlport';
} else {
        $ps_STLPORT_LIB         = "";
        $L_STLPORT_LIB          = "";
        $STLPORT_stlport        = $I.$SRC_ROOT.$SOLVER.$ds.$UPD.$ds.$INPATH.$INC.$ds."stl";
        $STLPORT_inc_stlport    = "";
}


# Windows NT only variables
if ($platform =~ m/cygwin/)
{  
   if ( $JAVA_HOME ne "" )
   {
      $JAVA_LIB             = $JAVA_HOME.$LIB;
   }
   # Import SystemDrive enviroment variable
   use Env qw(SYSTEMDRIVE);
   # Change $SYSTEMDRIVE to lower case.
   $SYSTEMDRIVE          = lc $SYSTEMDRIVE;
   use Env qw(SYSTEMROOT);
   $CYGWIN_PATH          = PosixFormat('NO_CYGWIN'); # Windows bash path
   $WIN_GREP             = '$CYGWIN_PATH'.$ds."grep.exe";
   $WIN_FIND             = '$CYGWIN_PATH'.$ds."find.exe";
   $WIN_LS               = '$CYGWIN_PATH'.$ds."ls.exe";
   $WIN_GNUCOPY          = '$CYGWIN_PATH'.$ds."cp.exe";
   $WIN_TOUCH            = '$CYGWIN_PATH'.$ds."touch.exe";
}

if ( $JAVA_HOME ne "" )
{
   $JAVA_BIN             = $JAVA_HOME.$BIN;
   $JAVA_INCLUDE         = $JAVA_HOME.$ds."include";
}


$PERL                 = PosixFormat('/usr/bin/perl'); # Perl program
$PERL_PATH            = dirname('/usr/bin/perl'); # Perl Path 
$XLIB                 = PosixFormat('no_x_libraries'); # X11 libraries
$XINC                 = PosixFormat('no_x_includes'); # X11 includes


# Mac OS X/Darwin only variables.
if ( $platform =~ m/darwin/ )
{  $FRAMEWORKSHOME       = $ds."System".$ds."Library".$ds."Frameworks";
   if ( $XLIB eq "no_x_libraries" ) {
      $GUIBASE  = "aqua";
   } else {
      $GUIBASE  = "unx";
   }
}

# Same as UPD, used in the buildproces.
$SOLARUPD             = $UPD;
# The project's workstamp.
$WORK_STAMP            = "SRC680";
# Location of the source.
$SOLARSRC             = '$SRC_ROOT';
#
$DEVROOT              = '$SRC_ROOT';
# Set solenv and solver to given or default values. 
# Location of the solenv tree.
if ('DEFAULT' eq "DEFAULT")
{  $SOLARENV          = $SRC_ROOT.$SOLENV;
}
else
{  $SOLARENV          =  PosixFormat('DEFAULT');
}
# Location of the solver tree.
if ('DEFAULT' eq "DEFAULT")
{  $SOLARVER          = $SRC_ROOT.$SOLVER.$ds.$UPD;
}
else
{  $SOLARVER          = PosixFormat('DEFAULT').$ds.$UPD;
}
#Location of Solar version.
$SOLARVERSION         = '$SOLARVER';

$SOLARENVINC          = '$SOLARENV'.$INC;
# Location of 
$LOCALINI             = '$SOLARENV'.$CONFIG;
# Location of 
$STAR_INIROOT         = '$SOLARENV'.$CONFIG;
# Location of 
$STAR_INIROOTOLD      = '$SOLARENV'.$CONFIG;
# Location of 
$STAR_STANDLST        = '$SOLARENV'.$CONFIG.$ds."stand.lst";
# Location of 
$STAR_SSCOMMON        = '$SOLARENV'.$CONFIG.$ds."ssolar.cmn";
# Location of 
$STAR_SSOLARINI       = '$SOLARENV'.$CONFIG.$ds."ssolar.ini";
# Path to the OpenOffice.org recourses.
$STAR_RESOURCEPATH    = '$SOLARVER'.$ds.'$INPATH'.$BIN;
# Location of the registry file.
$STAR_REGISTRY        = '$STAR_RESOURCEPATH'.$ds."applicat.rdb";
# Location of dmake resource. 
$DMAKEROOT            = '$SOLARENVINC'.$ds."startup";
# Location of JDK classes .zip file.
# but in jdk 1.2 it is called rt.jar and it lives in jre/lib
$CLASSPATH            = '$JAVA_HOME'.$ds.'jre'.$LIB.$ds."rt.jar".$ps.'.';
# Location of the JDK supported standard classes.zip file.
# see above for why the change
$XCLASSPATH           = '$JAVA_HOME'.$ds.'jre'.$LIB.$ds."rt.jar".$ps.'.';

# Paths to run time shared libraries.
if ($platform =~ m/solaris/) 
{  $LD_LIBRARY_PATH   = $cur_dir.
                        $ps.$USR_DT.$LIB.
                        $ps.$USR_OPENWIN.$LIB.
                        $ps.$USR_LOCAL.$LIB.
                        $ps.$par_dir.$LIB.
                        $ps_STLPORT_LIB.
                        $ps.$JRELIBDIR.
			$ps.$JREEXTRALIBDIR.
                        $ps.$JRETOOLKITDIR.
                        $ps.$JRETHREADDIR.
                        $ps.'$SOLARVER'.$ds.'$INPATH'.$LIB;
}
elsif ($platform =~ m/linux-gnu|netbsd|osf1|freebsd|aix/)
{  $LD_LIBRARY_PATH   = $cur_dir.
                        $ps.'$SOLARENV'.$ds.'$INPATH'.$LIB.
                        $ps.$JRELIBDIR.
			$ps.$JREEXTRALIBDIR.
                        $ps.$JRETOOLKITDIR.
                        $ps.$JRETHREADDIR.
                        $ps.$par_dir.$LIB64.
                        $ps_STLPORT_LIB.
                        $ps.'$SOLARVER'.$ds.'$INPATH'.$LIB.
                       $ps.$ENV{'LD_LIBRARY_PATH'};
}
elsif ($platform =~ m/irix/)
{  $LD_LIBRARY_PATH   = $cur_dir.
                        $ps.'$SOLARENV'.$ds.'$INPATH'.$LIB.
                        $ps.$JRELIBDIR.
			$ps.$JREEXTRALIBDIR.
                        $ps.$JRETOOLKITDIR.
                        $ps.$JRETHREADDIR.
                        $ps.$USR_LOCAL.$LIB.
                        $ps.$par_dir.$LIB.
                        $ps.'$SOLARVER'.$ds.'$INPATH'.$LIB;
}
elsif ($platform =~ m/darwin/)
{  $LD_LIBRARY_PATH   = $cur_dir.
                        $ps.'$SOLARVER'.$ds.'$INPATH'.$LIB.
                        $ps_STLPORT_LIB;
}
elsif ($platform !~ m/cygwin/)
{  AddWarning( "set_soenv", "$platform not configured for runtime shared libraries" );
}
	
# Location used by the linker to create libraries.
if ($platform =~ m/solaris/) 
{  $SOLAREXTRALIB     = $L.$par_dir.$LIB.
                        $L.'$SOLARENV'.$ds.'$OUTPATH'.$ds."lib.solaris.2.6".
                        $L.$LIB.
                        $L.$USR.$LIB.
                        $L.$USR.$LOCAL.$LIB.
                        $L.$USR_DT.$LIB.
                        $L.$USR_OPENWIN.$LIB;
}
elsif ($platform =~ m/linux-gnu|netbsd|osf1|irix|freebsd|aix/)
{
   $SOLAREXTRALIB     = $L.$par_dir.$LIB64;
}
elsif ($platform =~ m/darwin/) 
{  $SOLAREXTRALIB     = $L.$LIB.
                        $L.$USR.$LIB;
}
elsif ($platform !~ m/cygwin/ )
{  AddWarning( "set_soenv", "$platform not configured for linkage create libraries" );
}

# Windows NT only variables
if ($platform =~ m/cygwin/)
{  $COMP_ENV          = $OUTPATH;

   $JAVAHOME          = '$JAVA_HOME';

   $ILIB             = $cur_dir.$ps_STLPORT_LIB;
   # Mingw is different
   if ( $COM eq "MSC" )
   {  $ILIB       .=   $ps.$SOLARVER.$ds.$INPATH.$LIB. 
                        $ps.$JAVA_HOME.$LIB.
                        $ps.'$PSDK_HOME'.$LIB.
                        $ps.'$FRAME_HOME'.$LIB.
                        $ps.'$COMPATH'.$LIB;
      if ( '' ne "" ) {
          $ILIB   .= $ps.$DIRECTXSDK_LIB;
      }
   }
   elsif ( $COM eq "GCC" )
   {  $ILIB       .=    $ps.$SOLARVER.$ds.$INPATH.$LIB.
                        $ps.$SOLARVER.$ds.$INPATH.$BIN.
                        $ps.$JAVA_HOME.$LIB;
      if ( $USE_MINGW eq "cygwin" )
      {  $ILIB    .= $ps.'$COMPATH'.$LIB.$ds."mingw".
                     $ps.'$COMPATH'.$LIB.$ds."w32api";
      }
      $ILIB       .= $ps.'$COMPATH'.$LIB.
                     $ps.'$PSDK_HOME'.$LIB;
      if ( '@ENABLE_DIRETX@' )
      {   $ILIB   .= $ps.'';
      }
   }

   $JAVAHOME          = '$JAVA_HOME';

}
     
# The general environment path.
if ($platform =~ m/linux-gnu|netbsd|odf1|irix|freebsd|aix|solaris/)
{  $PATH              = $cur_dir.
                        $ps.'$SOLARVER'.$ds.'$INPATH'.$BIN.
                        $ps.'$SOLARENV'.$ds.'$OUTPATH'.$BIN.
                        $ps.'$SOLARENV'.$BIN;

   if ($platform =~ m/solaris/) {
	$PATH .= $ps.$USR_CCS.$BIN;
   }

   $PATH             .= $ps.$oldPATH;

   my @javaBits;
   if (( $JAVA_HOME ne "" ) && ( $JDK ne "gcj" )) {
      @javaBits = ( '$JAVA_HOME'.$BIN, 'javac' );
   } else {
      @javaBits = (); 
   }
   $PATH              = GetCorrectPath ($PATH,
                                        $COMPATH, $CC,
                                        $PERL_PATH, 'perl',
                                        $SHELL_PATH, 'tcsh',
                                        @javaBits);
}

elsif ($platform =~ m/cygwin/)
{  # The PATH variable is completely created from scratch. Everything that is not
   # needed is appended to the end.

   my ( $noldPATH );
   $noldPATH = $oldPATH;
   # convert path to posix if using native NT perl
   $noldPATH = PosixFormat($noldPATH);

   $PATH              = $cur_dir.
                        $ps.'$SOLARVER'.$ds.'$INPATH'.$BIN.
                        $ps.'$SOLARENV'.$ds."bin".
                        $ps.'$SOLARENV'.$ds.'$OUTPATH'.$BIN;

   if ( $JAVA_HOME ne "" )
   {
      # hack either "hotspot" or "client" should be used, depending on the jdk version:
      # 1.2.x   -   no such directory, unsupported 
      # 1.3.x   -   hotspot, client missing
      # 1.4.x   -   client, hotspot missing
      
      $PATH .= $ps.$JAVA_HOME.$BIN;
	  if ( -d $JAVA_HOME.$ds."jre".$ds."bin".$ds."hotspot" ) {
		  $PATH .= $ps.$JAVA_HOME.$ds."jre".$ds."bin".$ds."hotspot";
	  }
	  if ( -d $JAVA_HOME.$ds."jre".$ds."bin".$ds."client" ) {
		  $PATH .= $ps.$JAVA_HOME.$ds."jre".$ds."bin".$ds."client";
	  }
   }

   # Add path to compiler
   if ( $COM eq "MSC" ) {
      $PATH .= $ps.'$COMPATH'.$BIN;
   } else { # Mingw is different
      $PATH .= $ps.$COMPATH.$BIN;
   }
   if ( $COM eq "MSC" ) {
	   # for .NET to find mspdb71.dll (needed by CL.EXE C/C++ Compiler)
	   if ( $PATH !~ /(?:[:]|\A)(?:$MSPDB_PATH)(?:[:]|\Z)/ ) {
		   $PATH .= $ps.$MSPDB_PATH;
	   }
	   if ( ( $COMEX eq "10" ) || ( $COMEX eq "11" ) ) {
		   # .NET needs midl.exe
		   if ( $PATH !~ /(?:[:]|\A)(?:$MIDL_PATH)(?:[:]|\Z)/ ) {
			   $PATH .= $ps.$MIDL_PATH;
		   }
		   # .NET needs csc.exe
		   if ( $PATH !~ /(?:[:]|\A)(?:$CSC_PATH)(?:[:]|\Z)/ ) {
			   $PATH .= $ps.$CSC_PATH;
		   }
		   # Native installer needs some files if the Windows Installer SDK
		   if ( $PATH !~ /(?:[:]|\A)(?:$PSDK_HOME\/bin)(?:[:]|\Z)/i ) {
			   $PATH .= $ps.$PSDK_HOME.$BIN;
		   }
	   }
   } else { # Mingw is different
	   # Native installer needs some files if the Windows Installer SDK
	   if ( $PATH !~ /(?:[:]|\A)(?:$PSDK_HOME\/bin)(?:[:]|\Z)/i ) {
		   $PATH .= $ps.$PSDK_HOME.$BIN;
	   }
   }

   if ( $ASM_PATH ne "ASM_IN_PATH" )
   {   $PATH          .= $ps.$ASM_PATH;
   } 
   # zip.exe / unzip.exe path for Windows users.
   my $zip_home_path = PosixFormat('/usr/bin');
   if ( $PATH !~ /(?:[:]|\A)(?:$zip_home_path)(?:[:]|\Z)/ ) {
       $PATH          .= $ps.$zip_home_path;
   }

   # Possible cygwin paths must follow behind the OOo and MS paths

   # Check if $PERL_PATH is already set in PATH
   if ( ! ( $PATH =~ /(?:[:]|\A)(?:$PERL_PATH)(?:[:]|\Z)/ ) )
   {
      $PATH          .= $ps.$PERL_PATH;
   }
   # Check if $SHELL_PATH is already set in PATH
   if ( ( "tcsh" ne "4nt" ) && ( $PATH !~ /(?:[:]|\A)(?:$SHELL_PATH)(?:[:]|\Z)/ ) )
   {   $PATH          .= $ps.$SHELL_PATH;
   }
   # Check if $CYGWIN_PATH is already set in PATH
   if ( $PATH !~ /(?:[:]|\A)(?:$CYGWIN_PATH)(?:[:]|\Z)/ ) {
      $PATH           .= $ps.$CYGWIN_PATH;
   }
   $PATH              .= $ps_STLPORT_LIB;
   # nsis path for Windows users.
   my $nsis_path = PosixFormat('');
   if ( $PATH !~ /(?:[:]|\A)(?:$nsis_path)(?:[:]|\Z)/ ) {
       $PATH          .= $ps.$nsis_path;
   }
   # path to sn.exe (signing) for Windows users.
   my $sn_path = PosixFormat('/bin');
   if ( $PATH !~ /(?:[:]|\A)(?:$sn_path)(?:[:]|\Z)/ ) {
       $PATH          .= $ps.$sn_path;
   }


   # Add the rest of the original path if it is still missing.
   if ($^O eq "cygwin") { # Not for ActiveState perl
       my $expandedPATH = $PATH;
       $expandedPATH =~ s/(\$\w+)/$1/eeg;
       foreach my $pathentry (split($ps,$noldPATH)) {
           if ( ! ( $expandedPATH =~ /(?:$ps|\A)(?:$pathentry)(?:$ps|\Z)/ ) ) {
               $PATH .= $ps.$pathentry;
               $expandedPATH .= $ps.$pathentry;
           }
       }
   } else {
       $PATH          .= $ps.$noldPATH;
   }
}

elsif ($platform =~ m/darwin/)
{  $PATH              = $cur_dir.
                        $ps.'$SOLARVER'.$ds.'$INPATH'.$BIN.
                        $ps.'$SOLARENV'.$ds.'$OUTPATH'.$BIN.
                        $ps.'$SOLARENV'.$BIN;

  # Append old PATH
  $PATH             .= $ps.$oldPATH;

  # append PATHEXTRA
  $PATHEXTRA         = "/usr/bin:/bin:/usr/sbin:/sbin:/Coding/OOO-CWS/cws/solenv/bin";                      
  $PATH             .= $PATHEXTRA;
}
else
{  AddWarning( "set_soenv", "$platform not configured for general environment paths" );
}

# Linker library search directory paths. 
if ($platform =~ m/solaris/) 
{  $SOLARLIB          = $L.$par_dir.$LIB.
                        $L.'$SOLARENV'.$ds.'$OUTPATH'.$LIB.
                        $L.'$SOLARVER'.$ds.'$INPATH'.$LIB.
                        $L.'$SOLARENV'.$ds.'$OUTPATH'.$LIB.
                        $L.'$SOLARENV'.$ds.'$OUTPATH'.$LIB."solaris.2.6".
                        $L.$LIB.
                        $L.$USR_LIB;
   if ( $CC =~ "gcc" ) {
      my $temp = $COMPATH;
      $temp =~ s:/bin$::;
      $SOLARLIB      .= $L.$temp.$LIB;
   }
   $SOLARLIB         .= $L.$USR_LOCAL.$LIB.
                        $L.$USR_DT.$LIB.
                        $L.$USR_OPENWIN.$LIB.
                        $L.'$JAVA_HOME'.$LIB.
                        $L.$JRELIBDIR.
                        $L.$JRETOOLKITDIR.
                        $L.$JRETHREADDIR.
                        $L_STLPORT_LIB.
                        $L.$XLIB;
}
elsif ($platform =~ m/linux-gnu|netbasd|osf1|irix|aix|freebsd/)
{  $SOLARLIB          = $L.$par_dir.$LIB.
                        $L.'$SOLARENV'.$ds.'$OUTPATH'.$LIB.
                        $L.'$SOLARVER'.$ds.'$INPATH'.$LIB.
                        $L.'$SOLARENV'.$ds.'$OUTPATH'.$LIB.
                        $L.'$JAVA_HOME'.$LIB64.
                        $L.$JRELIBDIR.
                        $L.$JRETOOLKITDIR.
                        $L.$JRETHREADDIR.
                        $L_STLPORT_LIB.
                        $L.$XLIB;
}
elsif ($platform =~ m/cygwin/)
{  $SOLARLIB          = $L.'$SOLARVER'.$ds.'$INPATH'.$LIB.
                        $L.$par_dir.$LIB.
                        $L_STLPORT_LIB.
                        $L.'$SOLARENV'.$ds.'$OUTPATH'.$LIB;
} 
elsif ($platform =~ m/darwin/) 
{  $SOLARLIB          = $L.'$SOLARVER'.$ds.'$INPATH'.$LIB.
                        $L_STLPORT_LIB.
                        $L.$USR_LIB;
    # [ed] 6/15/02 Add in X11 libraries onto the library path
    if ($GUIBASE eq "unx") {
       $SOLARLIB      .= $L.$XLIB;
    }

}

if ($SYSTEM_MOZILLA eq "YES")
{
       $SOLARLIB .= $L.""
}

# Location of the compiler include search directory paths.
$SOLARINC             = $I.$cur_dir.
                        $I.'$SOLARVER'.$ds.'$INPATH'.$INC.$ds."stl".
                        $I.'$SOLARVER'.$ds.'$INPATH'.$INC.$ds."external".
                        $I.'$SOLARVER'.$ds.'$INPATH'.$INC.
                        $I.'$SOLARENV'.$ds.'$OUTPATH'.$INC.
                        $I.'$SOLARENV'.$INC.
                        $I.'$SRC_ROOT'.$ds."res";

if ($platform =~ m/solaris|linux-gnu|osf1|freebsd|netbsd|irix/)
{
$SOLARINC	     .= $STLPORT_stlport;
if ($platform =~ m/linux|freebsd|netbsd/)
{
# This simply adds an include path, so even cases that break the FHS work
$SOLARINC            .= $STLPORT_inc_stlport;
}
if ($platform =~ m/solaris/ && $CC !=~ "gcc")
{
$SOLARINC            .= '/SC5 ';
}
# Platform dependent include path at the top of this list of include paths
if ($platform =~ m/solaris/)
{   my $temp;
    $temp =~ s:$COMPATH:/bin\$:;
    $SOLARINC         .= $I.$temp.$ds."include";
}
if ($platform =~ m/linux-gnu/)
{
# This simply adds an include path, so even cases that break the FHS work
   $SOLARINC         .= $STLPORT_inc_stlport;
}


   	$SOLARINC      .= $I.'$SOLARENV'.$INC.$ds."Xp31".
                     $I.'$JAVA_HOME'.$INCLUDE;

	#include system dependent Java include directory
	if (!($JDK eq "gcj"))
	{
   		if ($platform =~ m/solaris/)
   		{  $SOLARINC   .=$I.'$JAVA_HOME'.$INCLUDE.$ds."solaris";
   		}
   		elsif  ($platform =~ m/linux-gnu|osf1/)
   		{  $SOLARINC   .=$I.'$JAVA_HOME'.$INCLUDE.$ds."linux";
   		}
   		elsif ($platform =~ m/freebsd/)
   		{
      		$SOLARINC   .=$I.'$JAVA_HOME'.$INCLUDE.$ds."freebsd";
      		$SOLARINC   .=$I.'$JAVA_HOME'.$INCLUDE.$ds."bsd";
      		$SOLARINC   .=$I.'$JAVA_HOME'.$INCLUDE.$ds."linux";
   		}
   		elsif ($platform =~ m/netbsd/)
   		{  $SOLARINC   .=$I.'$JAVA_HOME'.$INCLUDE.$ds."netbsd";
   		}
   		elsif ($platform =~ m/irix/)
   		{  $SOLARINC   .=$I.'$JAVA_HOME'.$INCLUDE.$ds."irix";
   		}

   		#java threads include path

   		$SOLARINC .=$I.'$JAVA_HOME'.$INCLUDE.$ds."native_threads".$ds."include";
	}
    #The tail, if needed
    if ($platform =~ m/linux-gnu|freebsd|netbsd/)
    {  $SOLARINC  .= $I.$XINC;
    }
    elsif ($platform =~ m/osf1/)
    {  $SOLARINC  .= $I.$XINC.
                     $I.$USR.$INCLUDE;
    }
}
elsif ($platform =~ m/cygwin/)
{  $SOLARINC         .= $STLPORT_stlport.
                        $I.'$JAVA_HOME'.$ds."include".$ds."win32".
                        $I.'$JAVA_HOME'.$ds."include";
   # Mingw is different
   if ( $COM eq "MSC" )
   {  $SOLARINC       .= $I.'$PSDK_HOME'.$INCLUDE.
                         $I.'$COMPATH'.$ds."include";
      if ( '' ne "" ) {
          $SOLARINC   .= $I.PosixFormat('').$INCLUDE;
      }
   }
   elsif ( $COM eq "GCC" )
   {  $SOLARINC       .= $I.'$SOLARVER'.$ds.'$INPATH'.$INC.$ds."external".$ds."mingw".$ds."include";
     if ( $USE_MINGW eq "cygwin" )
     {  $SOLARINC    .= $I.'$COMPATH'.$ds."include".$ds."mingw".$ds."include".
                        $I.'$COMPATH'.$ds."include".$ds."w32api"; }
        $SOLARINC    .= $I.'$COMPATH'.$ds."include";
     @mingw_lib_include_paths = split( / /, "" );
     foreach $mingw_lib_include_path (@mingw_lib_include_paths)
       {   chomp $mingw_lib_include_path;
           if ( $mingw_lib_include_path ne $COMPATH.$ds."include" && $mingw_lib_include_path ne "" )
           {
              $SOLARINC   .= $I.$mingw_lib_include_path;
           }
       }
     $SOLARINC .= $I."/usr/include/c++/4.0.0".$I."/usr/include/c++/4.0.0".$ds."mingw32".
                  $I.'$PSDK_HOME'.$INCLUDE;
   }
   if ( '' ne "" ) {
       $SOLARINC   .= $I.PosixFormat('').$INCLUDE;
   }
}
elsif ($platform =~ m/darwin/)
{  $SOLARINC         .= $STLPORT_stlport.
						$I.$FRAMEWORKSHOME.$ds."JavaVM.framework".$ds."Versions".$ds."Current".$ds."Headers".
                        $I.$FRAMEWORKSHOME.$ds."JavaVM.framework".$ds."Headers";
   # [ed] 6/15/02 Add in X11 headers as appropriate for the build
   if ($GUIBASE eq "unx") {
      $SOLARINC      .= $I.$XINC.
                        $I.$XINC.$ds."freetype2";
   }
}
else
{  AddWarning( "set_soenv", "$platform not configured for system dependant include dir" );
}

if ($SYSTEM_PYTHON eq "NO")
{
	$PYTHONPATH           = '.'.$ps.'$SOLARVER'.$ds.'$INPATH'.$ds.'lib'.$ps.'$SOLARVER'.$ds.'$INPATH'.$ds.'lib'.$ds.'python'.$ps.'$SOLARVER'.$ds.'$INPATH'.$ds.'lib'.$ds.'python'.$ds.'lib-dynload'.$ps.'$SOLARVER'.$ds.'$INPATH'.$ds.'lib'.$ds.'pyuno'.$ps.'$SOLARVER'.$ds.'$INPATH'.$ds.'bin'.$ds.'pyuno';
	$PYTHONHOME           = '$SOLARVER'.$ds.'$INPATH';
}

#
print "done\n";

#
# F. Setting the different aliases.
#
print "Setting the aliases... ";
# 1. alias for a full product make. 
# ToFile will take care for the right 4nt format
	$mkout           = '"perl $SOLARENV/bin/mkout.pl"';
	$deliver         = '"perl $SOLARENV/bin/deliver.pl"';
	$build           = '"perl $SOLARENV/bin/build.pl"';
	$build_client    = '"perl $SOLARENV/bin/build_client.pl"';
	$zipdep          = '"perl $SOLARENV/bin/zipdep.pl"';
# 3. alias for a full product make
$nmake           = '"dmake"';
print "done\n";
#
#--------------------------
# VI. Open the output file.
#--------------------------
#
open( OUT, ">$outfile" ) ||
   die "Cannot open $outfile: $!\n";

# Create sh environment file
open( OUT_SH, ">$outfile_sh" ) ||
  die "Cannot open $outfile_sh: $!\n";

if(defined($outfile_bat))
{  # Create bat environment file
   open( OUT_BAT, ">$outfile_bat" ) ||
   die "Cannot open $outfile_bat: $!\n";
}

#
#------------------------------------------
# VII. Writing the data to the output file.
#------------------------------------------
#
# Write file header.
CreateFileHeader( *OUT, $UPD, $platform, "(t)csh", "#" );
CreateFileHeader( *OUT_SH, $UPD, $platform, "sh/bash/ksh", "#" );
CreateFileHeader( *OUT_BAT, $UPD, $platform, "4nt", "rem" ) if defined($outfile_bat);

ToFile( "SRC_ROOT",	     $SRC_ROOT,          "e" );
ToFile( "SHELL",             $SHELL,             "e" );
ToFile( "JAVA_HOME",         $JAVA_HOME,         "e" );
ToFile( "ANT_HOME",          "/Developer/Java/Ant",       "e" );
ToFile( "ANT_LIB",           "/Developer/Java/Ant/lib",        "e" );
ToFile( "ANT",               "/Developer/Java/Ant/bin/ant",            "e" );
ToFile( "JDKLIB",            $JAVA_LIB,          "e" );
ToFile( "STLPORT4",          $STLPORT4,          "e" );
ToFile( "ASM_PATH",          $ASM_PATH,          "e" );
ToFile( "BUILD_SOSL",        $BUILD_SOSL,        "e" );
ToFile( "FRAMEWORKSHOME",    $FRAMEWORKSHOME,    "e" );
ToFile( "Empty",             $empty,             "n" );

#
# Writing the platform independent constant values to file.
# (c = comment, e = environment variable, a = alias )
ToFile( "Platform independent constant values.", $empty, "c" );
# dictionaries
if (',ENUS,' =~ m/ALL,/s)
{
   foreach $dict (@DICTIONARIES)
   {
      ToFile( "DIC_$dict",     "TRUE",          "e" );
   }
   ToFile( "DIC_ALL",          "TRUE",          "e" );
}
else
{	
   foreach $dict (@DICTIONARIES)
   {   if (',ENUS,' =~ m/$dict,/s)
       {   my $val="TRUE";
           ToFile( "DIC_$dict",     $val,          "e" );
       }
       else
       {   my $val;
           undef $val;
           ToFile( "DIC_$dict",     $val,          "e" );
       }
   }
}
# Languages
ToFile( "WITH_LANG",         "en-US",      "e" );
ToFile( "INTRO_BITMAPS",     "",  "e" );
ToFile( "ABOUT_BITMAPS",     "",  "e" );
ToFile( "OOO_VENDOR",        "",     "e" );
ToFile( "WITH_POOR_HELP_LOCALIZATIONS", "", "e" );

ToFile( "CALL_CDECL",        $CALL_CDECL,        "e" );
ToFile( "COMMON_OUTDIR",     $COMMON_OUTDIR,     "e" );
ToFile( "common_build",      $common_build,      "e" );
ToFile( "BMP_WRITES_FLAG",   $BMP_WRITES_FLAG,   "e" );
ToFile( "BUILD_SOSL_RELEASE", $BUILD_SOSL_RELEASE, "e" );
ToFile( "NO_REC_RES",        $NO_REC_RES,        "e" );
ToFile( "NO_HIDS",           $NO_HIDS,           "e" );
ToFile( "SO3",               $SO3,               "e" );
ToFile( "SOLAR_PLUGIN",      $SOLAR_PLUGIN,      "e" );
ToFile( "TF_PACKAGES",       $TF_PACKAGES,       "e" );
ToFile( "TF_FILEURL",        $TF_FILEURL,        "e" );
ToFile( "TF_CFGDATA",        $TF_CFGDATA,        "e" );
ToFile( "TF_SVDATA",         $TF_SVDATA,         "e" );
ToFile( "TF_SDBAPI",         $TF_SDBAPI,         "e" );
ToFile( "TF_UCB",            $TF_UCB,            "e" );
ToFile( "UPDATER",           $UPDATER,           "e" );
ToFile( "build_deliver",     $BUILD_DELIVER,     "e" );
ToFile( "VCL",               $VCL,               "e" );
ToFile( "ENABLEUNICODE",     $ENABLEUNICODE,     "e" );
ToFile( "NEW_JAR_PACK",      $NEW_JAR_PACK,      "e" );
ToFile( "NO_BSYMBOLIC",      $NO_BSYMBOLIC,      "e" );
ToFile( "TF_FILTER",         "TRUE",             "e" );
if ("FALSE" eq "TRUE") {
ToFile( "debug",             "true",             "e" );
}
if ("FALSE" eq "FALSE") {
ToFile( "EXTERNAL_WARNINGS_NOT_ERRORS", "TRUE",  "e" );
}
ToFile( "PRODUCT",           "full",        "e" );
ToFile( "PROFULLSWITCH",     "product=full",  "e" );
ToFile( "PROEXT",            $PROEXT,            "e" );
ToFile( "UNIXWRAPPERNAME",   "","e" );
ToFile( "BUILD_MOZAB",       "",    "e" );
ToFile( "PREBUILD_MOZAB",    $PREBUILD_MOZAB,    "e" );
ToFile( "MOZILLA_VERSION",   $MOZILLA_VERSION,   "e" );
ToFile( "DEFAULT_MOZILLA_TOOLKIT", $MOZILLA_TOOLKIT, "e" );
ToFile( "BUILD_VER_STRING",  "", "e" );
ToFile( "ENABLE_VBA",  "YES", "e" );
ToFile( "VBA_EXTENSION",  "YES", "e" );
if ($platform =~ m/linux-gnu/ && $platform =~ m/powerpc/) {
ToFile( "JITC_PROCESSOR_TYPE","6",                 "e" );
}
ToFile( "DEFAULT_TO_ENGLISH_FOR_PACKING",  "yes", "e" );
ToFile( "ENABLE_GTK",        "",       "e" );
ToFile( "GTK_CFLAGS",        "",       "e" );
ToFile( "GTK_LIBS",          "",         "e" );
ToFile( "ENABLE_SYSTRAY_GTK", "", "e" );
ToFile( "ENABLE_STATIC_GTK", "FALSE", "e" );
ToFile( "ENABLE_CAIRO",      "",     "e" );
ToFile( "ENABLE_DBUS",       "",      "e" );
ToFile( "ENABLE_GNOMEVFS",   "",  "e" );
ToFile( "ENABLE_KDE",        "",       "e" );
ToFile( "KDE_CFLAGS",        "",       "e" );
ToFile( "KDE_LIBS",          "",         "e" );
ToFile( "ENABLE_KAB",        "",       "e" );
ToFile( "MOC",               "moc",              "e" );
ToFile( "PSPRINT",           "TRUE",             "e" );
# [ed] 5/14/02 If we're building Aqua graphics, insert a C macro to indicate this.
# There may be a better way to do this, like splitting unxmacxp into two, but
# hopefully this hack will work for now...

if ($platform =~ m/darwin/)
{
    my $macosxCdefs="";
    
    if( ! -x "/usr/bin/sw_vers" ) {
        
        ToFile( "BUILD_OS_DARWIN", "TRUE", "e");

        $macosxCdefs.=" -DBUILD_OS_DARWIN";
        open DARVER, "/usr/bin/uname -v |";
        my $s=<DARVER>;
        chomp $s;
        if ( $s =~ /(\d+?)\.(\d+?)(.*?)/)
        {
            ToFile("BUILD_OS_MAJOR", $1, "e");
            $macosxCdefs.=" -DBUILD_OS_MAJOR=" . $1;

            ToFile("BUILD_OS_MINOR", $2, "e");
            $macosxCdefs.=" -DBUILD_OS_MINOR=" . $2;
            
            $s=$3;
            if ( $s =~ /(\d+?)/) {
                ToFile("BUILD_OS_REV", $1, "e");
                $macosxCdefs.=" -DBUILD_OS_REV=" . $1;
            } else {
                ToFile("BUILD_OS_REV", "0", "e");
                $macosxCdefs.=" -DBUILD_OS_REV=0";
            }
        }
        close DARVER;
    }
    else
    {
        $macosxCdefs.=" -DBUILD_OS_APPLEOSX";
        ToFile("BUILD_OS_APPLEOSX", "TRUE", "e");
        
        open OSXVER, "/usr/bin/sw_vers -productVersion |";
        while (<OSXVER>) {
            if (/^\s*(\d+?)\.(\d+?)(\.(\d+?))*\s*$/) {
                ToFile("BUILD_OS_MAJOR", $1, "e");
                $macosxCdefs.=" -DBUILD_OS_MAJOR=" . $1;

                ToFile("BUILD_OS_MINOR", $2, "e");
                $macosxCdefs.=" -DBUILD_OS_MINOR=" . $2;

                if($3 ne "") {
                    ToFile("BUILD_OS_REV", $4, "e");
                    $macosxCdefs.=" -DBUILD_OS_REV=" . $4;
                } else {
                    ToFile("BUILD_OS_REV", 0, "e");
                    $macosxCdefs.=" -DBUILD_OS_REV=0";
                }
                last;
            }
        }
        close(OSXVER);
    }
    
    if ( $GUIBASE eq "aqua" ) {
        $macosxCdefs.=" -DQUARTZ";
    }
    
    ToFile( "ENVCDEFS", $macosxCdefs, "e");
}

ToFile( "MKDEPENDSOLVER",    "TRUE",             "e" );
#
# Writing the platform dependent constant values to file.
# (c = comment, e = environment variable, a = alias )
ToFile( "Platform dependent constant values.", $empty, "c" );
ToFile( "SOLAR_JAVA",        $SOLAR_JAVA,        "e" );
ToFile( "BIG_SVX",           $BIG_SVX,           "e" );
ToFile( "COM",               $COM,               "e" );
ToFile( "COMPATH",           $COMPATH,           "e" );
ToFile( "CPU",               $CPU,               "e" );
ToFile( "CPUNAME",           $CPUNAME,           "e" );
ToFile( "CVER",              $CVER,              "e" );
ToFile( "GUI",               $GUI,               "e" );
ToFile( "GLIBC",             $GLIBC,             "e" );
ToFile( "GUIBASE",           $GUIBASE,           "e" );
ToFile( "GUIENV",            $GUIENV,            "e" );
ToFile( "GVER",              $GVER,              "e" );
ToFile( "OS",                $OS,                "e" );
ToFile( "EXCEPTIONS",        $EXCEPTIONS,        "e" );
ToFile( "OSVERSION",         $OSVERSION,         "e" );
ToFile( "PTHREAD_CFLAGS",    "", "e" );
ToFile( "PTHREAD_LIBS",      "",   "e" );
ToFile( "OUTPATH",           $OUTPATH,           "e" );
ToFile( "INPATH",            $INPATH,            "e" );
ToFile( "GVERDIR",           $GVERDIR,           "e" );
ToFile( "PATH_SEPERATOR",    $PATH_SEPERATOR,    "e" );
ToFile( "XPVERSION",         $XPVERSION,         "e" );
ToFile( "COMEX",             $COMEX,             "e" );
ToFile( "CDPATHx",           $CDPATHx,           "e" );
ToFile( "DYNAMIC_CRT",       $DYNAMIC_CRT,       "e" );
ToFile( "SET_EXCEPTIONS",    $SET_EXCEPTIONS,    "e" );
ToFile( "use_shl_versions",  $use_shl_versions,  "e" );
ToFile( "WRAPCMD",           $WRAPCMD,           "e" );
#
# Writing the variables to file.
# (c = comment, e = environment variable, a = alias, n = newline )
ToFile( "Variable values.",  $empty,             "c" );
if ( $platform =~ m/cygwin/ )
{  ToFile( "CYGWIN_PATH",       $CYGWIN_PATH,       "e" );
   ToFile( "PSDK_HOME",         $PSDK_HOME,         "e" );
   ToFile( "DIRECTXSDK_LIB",    $DIRECTXSDK_LIB,    "e" );
   ToFile( "ATL_LIB",           $ATL_LIB,         "e" );
   if ( $MINGW ne "yes" )
   {  ToFile( "ATL_INCLUDE",       $ATL_INCLUDE,       "e" );
   }
   ToFile( "MFC_LIB",           $MFC_LIB,         "e" );
   ToFile( "MFC_INCLUDE",       $MFC_INCLUDE,       "e" );
   ToFile( "NSIS_PATH",         "",      "e" );
   ToFile( "DISABLE_ACTIVEX",   "","e" );
   ToFile( "USE_NEW_SDK",       $USE_NEW_SDK,       "e" );
}
ToFile( "PERL",              $PERL,              "e" );
ToFile( "RPM",               "",            "e" );
ToFile( "DPKG",              "",           "e" );
ToFile( "PKGMK",             "",          "e" );
ToFile( "GNUMAKE",           "make",        "e" );
ToFile( "UPD",               $UPD,               "e" );
ToFile( "SOLARUPD",          $SOLARUPD,          "e" );
ToFile( "WORK_STAMP",        $WORK_STAMP,        "e" );
ToFile( "SOLARVER",          $SOLARVER,          "e" );
ToFile( "SOLARVERSION",      $SOLARVERSION,      "e" );
ToFile( "SOLARENV",          $SOLARENV,          "e" );
ToFile( "SOLARENVINC",       $SOLARENVINC,       "e" );
ToFile( "LOCALINI",          $LOCALINI,          "e" );
ToFile( "STAR_INIROOT",      $STAR_INIROOT,      "e" );
ToFile( "STAR_INIROOTOLD",   $STAR_INIROOTOLD,   "e" );
ToFile( "STAR_STANDLST",     $STAR_STANDLST,     "e" );
ToFile( "STAR_SSCOMMON",     $STAR_SSCOMMON,     "e" );
ToFile( "STAR_SSOLARINI",    $STAR_SSOLARINI,    "e" );
ToFile( "STAR_RESOURCEPATH", $STAR_RESOURCEPATH, "e" );
ToFile( "STAR_REGISTRY",     $STAR_REGISTRY,     "e" );
ToFile( "DMAKEROOT",         $DMAKEROOT,         "e" );
if ( $JDK ne "gcj" ) {
   ToFile( "CLASSPATH",         $CLASSPATH,         "e" );
   ToFile( "XCLASSPATH",        $XCLASSPATH,        "e" );
}
else {
   ToFile( "JAVACISGCJ",       '',      "e" );
}
if ( $GUI eq "UNX" ) {
   ToFile( "AWTLIB",           '-ljawt',          "e" );
}
if ( 'sun' ne '' )
{ 
   ToFile( "JDK",             "sun",           "e" );
   ToFile( "JAVAINTERPRETER", "/usr/bin/java","e" );
   ToFile( "JAVACOMPILER",    "/usr/bin/javac",  "e" );
   ToFile( "JAVAAOTCOMPILER", "","e" );
   ToFile( "JAVADOC",         "/usr/bin/javadoc",       "e" );
}
if ( $platform =~ m/darwin/ )
{  ToFile( "DYLD_LIBRARY_PATH", $LD_LIBRARY_PATH,   "e" );
}
else {
  if ( $platform =~ m/irix/ ) {
    ToFile( "LD_LIBRARYN32_PATH",   $LD_LIBRARY_PATH,   "e" );
  }
  else {
    ToFile( "LD_LIBRARY_PATH",   $LD_LIBRARY_PATH,   "e" );
  }
}
ToFile( "SCPDEFS",           ' -DWITHOUT_FONTOOO -DWITHOUT_MATHMLDTD -DWITHOUT_FONTOOO -DWITHOUT_MATHMLDTD -DWITHOUT_FONTOOO -DWITHOUT_MATHMLDTD -DWITHOUT_FONTOOO -DWITHOUT_MATHMLDTD -DWITHOUT_FONTOOO -DWITHOUT_MATHMLDTD',        "e" );
ToFile( "SOLAREXTRAINC",     $SOLAREXTRAINC,     "e" );
ToFile( "SOLAREXTRALIB",     $SOLAREXTRALIB,     "e" );
ToFile( "PATH",              $PATH,              "e" );
ToFile( "PATHEXTRA",         $PATHEXTRA,         "e" );
ToFile( "SOLARLIB",          $SOLARLIB,          "e" );
ToFile( "SOLARINC",          $SOLARINC,          "e" );
ToFile( "COMP_ENV",          $COMP_ENV,          "e" );
ToFile( "JAVAHOME",          $JAVAHOME,          "e" );
ToFile( "CC",                $CC,                "e" );
ToFile( "HAVE_GCC_VISIBILITY_FEATURE",
		"TRUE", "e" );
ToFile( "HAVE_LD_HASH_STYLE","FALSE","e" );
ToFile( "CXX",               $CXX,               "e" );
ToFile( "MINGWCXX",          "",       "e" );
ToFile( "MINGWSTRIP",        "",     "e" );
ToFile( "USE_SYSTEM_STL",    "", "e" );
ToFile( "ALLOC",             "",          "e" );
ToFile( "ENABLE_SYMBOLS",    "",    "e" );
ToFile( "DISABLE_STRIP",     "",     "e" );
ToFile( "LFS_CFLAGS",        "-D_FILE_OFFSET_BITS=no",     "e" );
ToFile( "ENABLE_CRASHDUMP",  "",  "e" );
ToFile( "ENABLE_CUPS",       "TRUE",       "e" );
ToFile( "ENABLE_FONTCONFIG", "", "e" );
ToFile( "ENABLE_DIRECTX",    "",    "e" );
ToFile( "ENABLE_PCH",        "",       "e" );
ToFile( "VC_STANDARD",       "",      "e" );
ToFile( "WITH_GPC",          "NO",         "e" );
ToFile( "WITH_MYSPELL_DICTS","YES","e");
ToFile( "ENABLE_LOCKDOWN",   "",  "e" );
ToFile( "WITH_LIBSN",        "NO",       "e" );
ToFile( "LIBSN_CFLAGS",      "",     "e" );
ToFile( "LIBSN_LIBS",        "",       "e" );
ToFile( "WITH_LDAP",         "NO",        "e" );
ToFile( "WITH_OPENLDAP",     "",    "e" );
ToFile( "WITH_MOZILLA",      "NO",     "e" );
ToFile( "SYSTEM_MOZILLA",    "",   "e" );
ToFile( "MOZ_FLAVOUR",       "",      "e" );
ToFile( "NSPR_LIB",          "",         "e" );
ToFile( "NSS_LIB",           "",          "e" );
ToFile( "MOZ_INC",           "",          "e" );
ToFile( "MOZ_LIB",           "",          "e" );
ToFile( "MOZ_LIB_XPCOM",     "",    "e" );
ToFile( "MOZ_NSPR_CFLAGS",   "",  "e" );
ToFile( "MOZ_NSS_CFLAGS",    "",   "e" );
ToFile( "MOZ_LDAP_CFLAGS",   "",  "e" );
ToFile( "WITH_FONTS",        "YES",       "e" );
ToFile( "WITHOUT_AFMS",      "",     "e" );
ToFile( "WITHOUT_PPDS",      "",     "e" );
ToFile( "WITH_BINFILTER",    "NO",   "e" );
ToFile( "BUILD_TYPE",        "OOo EXT DICTIONARIES EPM JPEG EXPAT FREETYPE LIBWPD LIBXMLSEC BERKELEYDB HSQLDB BSH XALAN BOOST VIGRA UNIXODBC SANE ICU X11_EXTENSIONS SNDFILE PORTAUDIO AGG BITSTREAM_VERA_FONTS",       "e" );
ToFile( "WITH_FONTOOO",      "NO",     "e" );
ToFile( "ENABLE_EVOAB2",     "",    "e" );
ToFile( "GOBJECT_CFLAGS",    "",   "e" );
ToFile( "GOBJECT_LIBS",      "",     "e" );
ToFile( "SYSTEM_MSPACK",     "",    "e" );
if ( 'yes' eq "no" ) {
  ToFile( "LINKFLAGSRUNPATH",'',                   "e" );
}
ToFile( "EPM",               "no",              "e" );
ToFile( "BUILD_EPM",         "YES",        "e" );
ToFile( "PKGFORMAT",         "portable",        "e" );
ToFile( "SYSTEM_STDLIBS",    "YES",   "e" );
ToFile( "SYSTEM_ZLIB",       "YES",      "e" );
ToFile( "SYSTEM_PYTHON",     "YES",    "e" );
ToFile( "PYTHON_CFLAGS",     "-I/System/Library/Frameworks/Python.framework/Versions/2.3/include/python2.3",    "e" );
ToFile( "PYTHON_LIBS",       "-framework Python",      "e" );
if ($SYSTEM_PYTHON eq "NO") {
ToFile( "HOME",              "/Users/mox",             "e" );
}
ToFile( "SYSTEM_ICU",        "NO",       "e" );
ToFile( "SYSTEM_GENBRK",     "",    "e" );
ToFile( "SYSTEM_GENCCODE",   "",  "e" );
ToFile( "SYSTEM_GENCMN",     "",    "e" );
ToFile( "SYSTEM_JPEG",       "NO",      "e" );
ToFile( "SYSTEM_FREETYPE",   "NO",  "e" );
ToFile( "FREETYPE_CFLAGS",   "-I/usr/X11R6/include -I/usr/X11R6/include/freetype2  ",  "e" );
ToFile( "FREETYPE_LIBS",     "-L/usr/X11R6/lib -lfreetype -lz  ",    "e" );
ToFile( "SYSTEM_CAIRO",      "",     "e" );
ToFile( "CAIRO_CFLAGS",      "-I/opt/inkscape/include/cairo  ",     "e" );
ToFile( "CAIRO_LIBS",        "-L/opt/inkscape/lib -lcairo  ",       "e" );
ToFile( "SYSTEM_LIBWPD",     "NO",    "e" );
ToFile( "LIBWPD_CFLAGS",     "",    "e" );
ToFile( "LIBWPD_LIBS",       "",      "e" );
ToFile( "SYSTEM_LIBXML",     "YES",    "e" );
ToFile( "USE_FT_EMBOLDEN",   "NO",  "e" );
ToFile( "LIBXML_CFLAGS",     "-I/usr/include/libxml2  ",    "e" );
ToFile( "LIBXML_LIBS",       "-lxml2 -lpthread -lz -liconv -lm  ",      "e" );
ToFile( "SYSTEM_EXPAT",      "NO",     "e" );
ToFile( "SYSTEM_DB",         "NO",        "e" );
ToFile( "DB_VERSION",        "",       "e" );
ToFile( "DB_INCLUDES",       "",      "e" );
ToFile( "DB_JAR",            "",           "e" );
ToFile( "SYSTEM_HSQLDB",     "NO",    "e" );
ToFile( "HSQLDB_JAR",        "",       "e" );
ToFile( "SYSTEM_BSH",        "NO",       "e" );
ToFile( "BSH_JAR",           "",          "e" );
ToFile( "SYSTEM_XML_APIS",   "NO",  "e" );
ToFile( "XML_APIS_JAR",      "",     "e" );
ToFile( "SYSTEM_XERCES",     "NO",    "e" );
ToFile( "XERCES_JAR",        "",       "e" );
ToFile( "SYSTEM_XALAN",      "NO",     "e" );
ToFile( "XALAN_JAR",         "",        "e" );
ToFile( "SERIALIZER_JAR",    "",   "e" );
ToFile( "SYSTEM_ODBC_HEADERS","NO","e" );
ToFile( "SYSTEM_LIBXSLT",    "YES",   "e" );
ToFile( "LIBXSLT_CFLAGS",    "-I/usr/include/libxml2  ",   "e" );
ToFile( "LIBXSLT_LIBS",      "-lxslt -lxml2 -lpthread -lz -liconv -lm  ",     "e" );
ToFile( "SYSTEM_SANE_HEADER","NO","e" );
ToFile( "SYSTEM_XRENDER_HEADERS","NO","e" );
ToFile( "SYSTEM_CURL",       "YES",      "e" );
ToFile( "CURL_CFLAGS",       "",      "e" );
ToFile( "CURL_LIBS",         "-L/usr/lib -lcurl -lssl -lcrypto -lz",        "e" );
ToFile( "SYSTEM_BOOST",      "NO",     "e" );
ToFile( "SYSTEM_VIGRA",      "NO",     "e" );
ToFile( "SYSTEM_NAS",        "",       "e" );
ToFile( "NAS_INCLUDES",      "",     "e" );
ToFile( "ENABLE_NAS",        "",       "e" );
ToFile( "ENABLE_PASF",       "YES",      "e" );
ToFile( "SYSTEM_SNDFILE",    "NO",   "e" );
ToFile( "SNDFILE_CFLAGS",    "",   "e" );
ToFile( "SNDFILE_LIBS",	     "-lsndfile",	   "e" );
ToFile( "SYSTEM_PORTAUDIO",  "NO", "e" );
ToFile( "PA_VER",            "18",           "e" );
ToFile( "SYSTEM_NEON",       "",      "e" );
ToFile( "NEON_VERSION",      "",     "e" );
ToFile( "NEON_LIBS",         "",        "e" );
ToFile( "NEON_CFLAGS",       "",      "e" );
ToFile( "DISABLE_NEON",      "TRUE",     "e" );
ToFile( "DISABLE_XAW",       "",      "e" );
ToFile( "ENABLE_AGG",        "YES",       "e" );
ToFile( "SYSTEM_AGG",	     "NO",       "e" );
ToFile( "AGG_VERSION",	     "2300",      "e" );
ToFile( "BUILD_DMAKE",       "YES",      "e" );
ToFile( "BUILD_UNOWINREG",   "NO",  "e" );
ToFile( "USE_XINERAMA",      "YES",     "e" );
ToFile( "XINERAMA_LINK",     "dynamic",    "e" );
ToFile( "SYSTEM_HUNSPELL",   "NO",  "e" );
ToFile( "HUNSPELL_CFLAGS",   "",  "e" );
ToFile( "HUNSPELL_LIBS",     "",    "e" );
ToFile( "SYSTEM_HYPH",       "NO",      "e" );
ToFile( "SYSTEM_MYTHES",     "NO",    "e" );
ToFile( "PAM",               "",              "e" );
ToFile( "NEW_SHADOW_API",    "",   "e" );
ToFile( "PAM_LINK",          "",         "e" );
ToFile( "CRYPT_LINK",        "",       "e" );
ToFile( "XAU_LIBS",          "",         "e" );
ToFile( "GXX_INCLUDE_PATH",  "/usr/include/c++/4.0.0", "e" );
ToFile( "COMMON_BUILD_TOOLS",$COMMON_BUILD_TOOLS,  "e" );
if ($platform !~ m/cygwin/)
{  ToFile( "TEMP",              $TEMP,              "e" );
   ToFile( "TMP",               $TEMP,              "e" );
}
ToFile( "SOLARSRC",           $SOLARSRC,           "e" );
if ( $platform =~ m/cygwin/ )
{
   # these variables marked with "j" are used with cygwin only
   if ( $MINGW eq "yes" )
   {  my ($tempstring);
      $tempstring = $ILIB;
      $tempstring =~ s/:/;/g;
      ToFile( "ILIB",              $tempstring,              "e" );
      ToFile( "ATL_INCLUDE",       $ATL_INCLUDE,       "e" );
      ToFile( "DIRECTXSDK_HOME",    "",    "e" );
      ToFile( "USE_MINGW",         $USE_MINGW,              "e" ); }
   else
   {  ToFile( "ILIB",              $ILIB,              "j" ); }

   ToFile( "GREP",              $WIN_GREP,          "e" );
   ToFile( "FIND",              $WIN_FIND,          "e" );
   ToFile( "LS",                $WIN_LS,            "e" );
   ToFile( "GNUCOPY",           $WIN_GNUCOPY,       "e" );
   ToFile( "TOUCH",             $WIN_TOUCH,         "e" );
}
# $perlpre is only used for the following three variables
# and only set for 4nt.
my $perlpre = "";
if (( $platform =~ m/cygwin/ ) and ( 'tcsh' eq "4nt" )) {
   ToFile( "HOME",              "   ",          "e" );
   $perlpre = "perl ".${SOLARENV}.${BIN}.${ds};
}
ToFile( "DELIVER",       $perlpre."deliver.pl",     "e" );
ToFile( "MKOUT",         $perlpre."mkout.pl",       "e" );
ToFile( "ZIPDEP",        $perlpre."zipdep.pl",      "e" );

ToFile( "USE_SHELL",             'tcsh',     "e" );
if ($SYSTEM_PYTHON eq "NO")
{
  if ( $platform =~ m/cygwin/ ) {
    ToFile( "PYTHONPATH",        $PYTHONPATH,        "j" );
    ToFile( "PYTHONHOME",        $PYTHONHOME,        "j" );
  } else {
    ToFile( "PYTHONPATH",        $PYTHONPATH,        "e" );
    ToFile( "PYTHONHOME",        $PYTHONHOME,        "e" );
  }
}

#
# Writing the aliases to file.
ToFile( "Aliases.",          $empty,             "c" );
ToFile( "Don't set aliases when bootstrapping", $empty, "c" );
ToFile( 'if ( ! ${?_ISBOOTSTRAP_} ) then', $empty, "y");
ToFile( "if test -z \"\$_ISBOOTSTRAP_\"; then", $empty, "z");

ToFile( "alias mkout",       $mkout,             "a" );
ToFile( "alias deliver",     $deliver,           "a" );
ToFile( "alias build",       $build,             "a" );
ToFile( "alias build_client",$build_client,      "a" );
ToFile( "alias zipdep",      $zipdep,            "a" );
if ( $platform !~ m/cygwin/ )
{  ToFile( "alias nmake",       $nmake,             "a" );
}

ToFile( "endif",             $empty, "y");
ToFile( "fi",                $empty, "z");

# write make command for dmake for W32-4nt
if ( $platform =~ m/cygwin/ and 'tcsh' eq "4nt" )
{
  ToFile( "build the dmake executable.", $empty, "c");
  ToFile( "if not exist \%SOLARENV\\\%OUTPATH\\bin\\dmake.exe (cd \%SRC_ROOT\\dmake \^ set INCLUDE=\%COMPATH\\include;\%PSDK_HOME\\include \^ set LIB=\%COMPATH\\lib;\%PSDK_HOME\\lib \^ call make.bat win95-vpp40 \^ cd \%SRC_ROOT)", $empty, "x");
  ToFile( "if not exist \%SOLARENV\\\%OUTPATH\\bin\\dmake.exe ( mkdir /S \%SOLARENV\\\%OUTPATH\\bin \^ copy dmake\\dmake.exe \%SOLARENV\\\%OUTPATH\\bin\\dmake.exe )", $empty, "x");
  ToFile( "\@echo Warning! LIB and INCLUDE will be cleared!", $empty, "x");
  ToFile( "\@unset INCLUDE LIB", $empty, "x");
  ToFile( "check for correct dmake.", $empty, "c");
  ToFile( '@if "%@SEARCH[dmake]" == "" ( @echo dmake not build or missing! Invalid build environment! ^ unset SOLARENV ^ cancel )', $empty, "x");
  ToFile( '@dmake -V > dmakecheck.out', $empty, "x");
  ToFile( '@ffind /Tcygwin /C /B dmakecheck.out && ( @echo Found cygwin build dmake! Invalid! ^ unset SOLARENV ^ cancel )', $empty, "x");
  ToFile( "  ", $empty, "x");
}

# Check if the right dmake version is used. (W32-tcsh only)
if ( $platform =~ m/cygwin/ and 'tcsh' ne "4nt" ) {
    ToFile( "Check if the right dmake version is used.", $empty, "c" );
    # Invalidate build environment.
    ToFile( "WORK_STAMP", "_invalid_", "e" );
    # Don't test the dmake version if this file is sourced by bootstrap
    ToFile( "bash -c 'if test -n \"\$_ISBOOTSTRAP_\" || (dmake.exe -V | grep -e \"-cygwin\\|OS := cygwin\" > /dev/null ); then true; else echo -e \"\\n\\nERROR: Not a cygwin build dmake or dmake missing, please check!\\n\\n\" ; sleep 5; false ; fi' || exit 1", $empty, "y");
    # Restore valid environment if test was successful.
    ToFile( "WORK_STAMP",        $WORK_STAMP,        "e" );
    ToFile( "", $empty, "n");
}

# on Solaris, MacOSX and FreeBSD, set GNUCOPY and GNUPATCH
if ($platform =~ m/solaris|darwin|freebsd/)
{
  ToFile( "GNUPATCH",   "/usr/bin/patch",	"e");
  ToFile( "GNUCOPY",	"",	"e");
}
ToFile( "SAL_ENABLE_FILE_LOCKING",	"1",	"e");
#
# Writing unset variables you might not need to file.
# 
print OUT $unsetvars;

print OUT_SH "export $exportvars$newline";
print OUT_SH "unset $unsetvarssh$newline";

if(defined($outfile_bat))
{  print OUT_BAT $unsetvarsbat;
}

#
#---------------------------
# VIII. Closing output file.
#---------------------------
#
close( OUT ) || print "Can't close $outfile: $!";

close( OUT_SH ) || print "Can't close $outfile_sh: $!";

if( defined($outfile_bat))
{  close( OUT_BAT ) || print "Can't close $outfile_bat: $!";
}

#
#------------------------------
# IX. Sourcing the output file.
#------------------------------
#
#---------------------------------
# X. Set up the build environment.
#---------------------------------
#
#--------------------------------------------------------
# XI. Moving the output file to the build home directory.
#--------------------------------------------------------
#
$tmp = $SRC_ROOT.$ds.$outfile;
if (rename( $outfile, $tmp ) ne 1)
{  `mv -f $outfile $tmp`;
}

$tmp = $SRC_ROOT.$ds.$outfile_sh;
if (rename( $outfile_sh, $tmp ) ne 1)
{  `mv -f $outfile_sh $tmp`;
}

if(defined($outfile_bat))
{
    $tmp = $SRC_ROOT.$ds.$outfile_bat;
    if (rename( $outfile_bat, $tmp ) ne 1)
    {  `mv -f $outfile_bat $tmp`;
    }
}

#
#--------------------------------------------------------
# XII. Message at the end.
#--------------------------------------------------------
#
#
print "*********************************************************".
      "******************* $newline"."*"."$newline";
print "* OpenOffice.org $UPD configuration. $newline";
for ( $tmp = 0; $tmp < 2; $tmp++ ) 
{  print "* $newline";
}
print "* Configuration part of OpenOffice.org $UPD build is finished. $newline* $newline";
print "* NB! Be aware that you might not be able to build OpenOffice.org if you $newline".
      "* ignore any warning message that were generated during this configuration $newline".
      "* process. $newline* $newline";

if ( $Warning ne "" ) 
{  print "$Warning*"; 
   print "$newline";
}

print "*$newline* USAGE: $newline";
print "* Source $outfile (in tcsh)";
print " or $outfile.sh (in sh)";
print "$newline";
print "* in order to set up the build-environment variables.$newline";
for ( $tmp = 0; $tmp < 2; $tmp++ ) 
{  print "* $newline";
}
print "*********************************************************".
      "******************* $newline";

$bootfile = "bootstrap";
open( OUT, ">$bootfile" ) ||
die "Cannot open $bootfile: $!\n";
print OUT "#!/bin/sh\n";
print OUT "_ISBOOTSTRAP_=TRUE ; export _ISBOOTSTRAP_ ; . $SRC_ROOT/$outfile.sh\n"; 
print OUT "unset _ISBOOTSTRAP_; export _ISBOOTSTRAP_\n"; 
if ( $MINGW eq "yes" )
{  print OUT 'PATH="/usr/bin:$PATH" : export PATH'."\n"; }
close( OUT ) || print "Can't close $bootfile: $!";
system(`cat bootstrap.1 >> bootstrap`);
system(`chmod +x bootstrap`);
#
#--------------------------------------------------------
# Moving the bootstrap file to the build home directory.
#--------------------------------------------------------
#
$tmp = $SRC_ROOT.$ds.$bootfile;
if (rename( $bootfile, $tmp ) ne 1)
{  `mv -f $bootfile $tmp`;
}

print "Configure completed\n";
if ( "tcsh" ne "4nt" ) {
	print "You may now run ./bootstrap in $SRC_ROOT\n";
}
if ( $Warning ne "" ) {
	print "***** WARNINGS ISSUED *****\n";
}

#
#-----------------
# XII. Functions.
#-----------------
#
#-------------------------------------------------------------
# Function name: CheckPathName 
# Description:   chops off the '/' character if it's the last
#                character in a pathname. also adds the '/'
#                character if it's not the first character
#                in a path.
# Arguments:     1. Path (string)
# Return value:  Path (string)
#-------------------------------------------------------------
sub CheckPathName 
{  my $retrn = $_[ 0 ];
   if (($platform =~ m/cygwin/) or ( 'tcsh' ne "4nt" ))
   {  # Check if the first character is not a '/'.
      if ( !( $_[ 0 ] =~ /^\// ) ) 
      {  $retrn = $ds.$_[ 0 ];
      }
   }
   # kill the last '/','\','\n' if they exists.
   $retrn =~ s![\s/\\]+$!!;
   # Done!
   return( $retrn );
}
#-------------------------------------------------------------
# Function name: CheckPathExist 
# Description:   Checks whether the directory that is given
#                as an argument exists. If not abort.
# Arguments:     1. Path (string)
# Return value:  void
#-------------------------------------------------------------
sub CheckPathExist 
{  my $dir = $_[ 0 ];
   if ( !( -d $dir ) and $^O ne 'MSWin32' )
   {  print ( "The directory $_[ 0 ] does not exist. Please create first.\n" );
      exit 1;
   }
   else
   {  # Don't check under ActiveState Perl (Windows). The path is possibly
      # posix and it cannot handle it.
      return "true";
   }
}
#------------------------------------------------------------
# Function name: CreateFileHeader 
# Description:   Creates a header for the outfile.
# Arguments:     1. File to write to
#                2. UPD (string)
#                3. Platform (string)
#                4. name of shell for this file
#                5. comment to use for this file
# Return value:  void
#------------------------------------------------------------
sub CreateFileHeader 
{  my $timestamp = `date`;
   chomp( $timestamp );
   my $filehandle = $_[0];
   my $comment = $_[4];
   print { $filehandle } "$comment #################################################################"; 
   print { $filehandle } $newline;
   print { $filehandle } "$comment OpenOffice.org $_[ 1 ] build environment file for: $_[ 2 ]. $newline"; 
   print { $filehandle } "$comment Generated on: $timestamp $newline"; 
   print { $filehandle } "$comment Source this file to set up the build environment. $newline"; 
   print { $filehandle } "$comment 1. exec $_[3] $newline"; 
   print { $filehandle } "$comment 2. source $outfile $newline"; 
   print { $filehandle } "$comment #################################################################"; 
   print { $filehandle } $newline;
}
#---------------------------------------------------------
# Function name: ToFile
# Description:   Writes the environment variable in the
#                output file.
# Arguments:     1. Name of environment variable (string)
#                2. Value of environment variable (string)
#                3. e - env. var
#                   a - alias
#                   c - comment
#                   n - newline
#                   j - env. var in DOS style (WINNT only)
#                   x - raw, write as is to OUT_BAT
#                   y - raw, write as is to OUT
#                   z - raw, write as is to OUT_SH
# Return value:  void
#---------------------------------------------------------
sub ToFile {
   if ( $_[ 2 ] eq "e" ) {
      # Write an environment variable to file.
      if (defined $_[ 1 ] && $_[ 1 ] ne "" ) {
         my $envvar = $_[ 1 ];
         my $envvarbash = $envvar;
         if ("tcsh" eq "4nt" ) {
             # expand the variables
             $envvar =~ s/(\$\{?\w+\}?)/$1/eeg ;
             # Some variables need to be translated
             $win_format_var = WinFormat( $envvar );
             # The excluded variables are translated by cygwin
             if ( $_[ 0 ] !~ /^PATH$|^TMP$|^TEMP$|^TMPDIR$|^HOME$/i ) {
                 $envvar = $win_format_var;
             }
             # Tcsh/bash needs backslashes quoted
             $envvar =~ s/\\/\\\\/g;
             $envvarbash = $envvar;
         }
         printf("%-12s %-17s %-10s %s\n", "The variable", $_[ 0 ], "is set to:", $envvar);
         print OUT "$setenv $_[ 0 ] \"$envvar\"$newline";  # to tcsh file
         print OUT_SH "$_[ 0 ]=\"$envvarbash\"$newline";   # to sh file
         $exportvars .= " $_[ 0 ]";                        # add to export list for sh file
         if(defined($outfile_bat)) {
             print OUT_BAT "IF DEFINED $_[ 0 ] $unset $_[ 0 ]$newline";
             print OUT_BAT "$set $_[ 0 ]=$win_format_var$newline";
         }
      } else {
         printf("%-12s %-17s %-10s %s\n", "The variable", $_[ 0 ], "is set to:", "unset") ; # to stdout
         $unsetvars .= "$unsetenv $_[ 0 ] >& /dev/null$newline"; # for tcsh file
         $unsetvarssh .= " $_[ 0 ]";                             # for sh file
         if(defined($outfile_bat)) {
             $unsetvarsbat .= "$unset $_[ 0 ] >& NUL$newline";
         }
      }
   }
   elsif ( $_[ 2 ] eq "a" ) 
   {  # Write an alias to file.
      print "The $_[ 0 ] is set to: $_[ 1 ]\n";    # to stdout
      print OUT "$_[ 0 ] $_[ 1 ]$newline";         # to tcsh file
      print OUT_SH "$_[ 0 ]=$_[ 1 ]$newline";      # to sh file
      if(defined($outfile_bat)) # create the correct 4nt alias format
      {  my $aliastmp = $_[ 1 ];
         $aliastmp =~ s/\$/\%/g;
         $aliastmp =~ s!/!\\!g;
         $aliastmp =~ s!"!!g;
         print OUT_BAT "$_[ 0 ]=".'`'.$aliastmp.'`'.$newline;
      }
   }
   elsif ( $_[ 2 ] eq "c" ) 
   {  # Write a comment to file.
      print "$newline";
      print "$comment$newline";
      print "$comment $_[ 0 ]$newline";
      print "$comment$newline";
      print OUT "$newline";
      print OUT "$comment$newline";
      print OUT "$comment $_[ 0 ]$newline";
      print OUT "$comment$newline";
      print OUT_SH "$newline";
      print OUT_SH "$comment$newline";
      print OUT_SH "$comment $_[ 0 ]$newline";
      print OUT_SH "$comment$newline";
      if(defined($outfile_bat)) {
          print OUT_BAT "$newline";
          print OUT_BAT "$comment4nt$newline";
          print OUT_BAT "$comment4nt $_[ 0 ]$newline";
          print OUT_BAT "$comment4nt$newline";
      }
   }
   elsif ( $_[ 2 ] eq "n" )
   {  #Write a newline to a file
      print OUT "$newline";
      print OUT_SH "$newline";
      print OUT_BAT "$newline" if defined($outfile_bat);
   }
   elsif ( $_[ 2 ] eq "x" )
   {
      #Write first argument as is, and nothing else
      print OUT_BAT "$_[ 0 ]$newline" if defined($outfile_bat);
   }
   elsif ( $_[ 2 ] eq "y" )
   {
      #Write first argument as is, and nothing else
      print OUT "$_[ 0 ]$newline";
   }
   elsif ( $_[ 2 ] eq "z" )
   {
      #Write first argument as is, and nothing else
      print OUT_SH "$_[ 0 ]$newline";
   }
   elsif ( $_[ 2 ] eq "j" ) {
      if ((defined $_[ 1 ]) and ( $platform =~ m/cygwin/ )) {
         printf("%-12s %-17s %-10s %-39s\n", "The variable", $_[ 0 ], "is set to:", $_[ 1 ]) ; # to stdout
         $win_format_var = WinFormat( $_[ 1 ] );  #Filter for Windows
         $win_format_var =~ s/\\/\\\\/g;
         print OUT "$setenv $_[ 0 ] \"$win_format_var\"$newline";

         print OUT_SH "$_[ 0 ]=\"$win_format_var\"$newline"; # to sh file
         $exportvars .= " $_[ 0 ]";                          # add to export list for sh file

         if (defined($outfile_bat)) {
             $win_format_var = WinFormat( $_[ 1 ] );  #Filter for Windows
             print OUT_BAT "IF DEFINED $_[ 0 ] $unset $_[ 0 ]$newline";
             print OUT_BAT "$set $_[ 0 ]=$win_format_var$newline";
         }
      }
      else
      {
          print "Type \"j\" only intended for Windows!$newline";
          print "use \"e\" to set and unset variables.$newline";
      }
   }
   else 
   {  print "Unknown type!$newline";
   }
}
#----------------------------------------------------------
# Function name: PosixFormat
# Description:   Format variables to Posix Style Format. Should only be used 
#                with DOS-style path variables.
# Arguments:     1. Variable (string)
# Return value:  Reformatted String
#----------------------------------------------------------
sub PosixFormat
{  my ( $variable, $d1, $d2 );
   $variable = $_[ 0 ];
   # ToDo: Do the replacement only if Windows and var contains "\" and ":"
   if ( $platform =~ m/cygwin/ )
   {   $variable =~ s/(\$\{?\w+\}?)/$1/eeg ;         # expand the variables
       $variable =~ s/(\$\{?\w+\}?)/$1/eeg ;         # expand the variables twice!
   	   if ( ( $variable =~ /\\/ ) and ( $variable =~ /:/ ) )
	   {   $variable =~ s{([c-z]):}{/cygdrive/$1}gi;
		   # Map drives to /cgydrive/drive
		   # We do this also for old cygwins, back
		   # replacement in winformat.
	   }
	   $variable =~ s!\\!/!g;
	   $variable =~ s/;/:/g;

	   # Search for posix path :path with space: and replace with short dos path
	   while ( $variable =~ /(?::|\A)[\'\"]?([^:]+ [^:]+)[\'\"]?(?::|\Z)/ ) {
               $d1 = $1 ;
               if ( $d1 =~ m/"$/ ) { die( "A part of $variable is enclosed in quotes, fix this!"); }
               chomp( $d2 = qx{cygpath -d "$d1"} ) || die( "Path with space: $1 propably doesn't exist!" );
               # Be arefull with \s
               $d2 =~ s/\\/\\\\/g;
               chomp( $d2 = qx{cygpath -u "$d2"} ) ;
               $variable =~ s/\Q$d1\E/$d2/ ;
	   }
   }
   return $variable;
}
#----------------------------------------------------------
# Function name: WinFormat 
# Description:   Format variables to Windows Format.
# Arguments:     1. Variable (string)
# Return value:  Reformatted String
#----------------------------------------------------------
sub WinFormat         
{  my ( $variable, $d1, $d1_prefix, $d1_fname, @split_var );  
   $variable = $_[ 0 ];
   $variable =~ s/^\s+//g ; #remove leading spaces
   $variable =~ s/\s+$//g ; #remove trailing spaces
   # Here should be NO "\"! If yes, PosixFormat() was forgotten before !
   if ( $variable =~ /\\/ )
   {
	   die("Error! Variable contains \"\\\" : $variable PosixFormat() missing?");
   }
   $variable =~ s/\$\{PATH\}/%PATH/g ;     # explicit replace ${PATH}
   $variable =~ s/(\$\{?\w+\}?)/$1/eeg ;   # expand the variables
   $variable =~ s/(\$\{?\w+\}?)/$1/eeg ;   # expand the variables twice!
   $variable =~ s/:+/:/g ;                 # remove multiple ;

       $variable =~ s/:/;/g;
       # Search for posix path entry and replace with cygpath -w entry ( -d if filename contains space )
       if ( $variable =~ /^\s*-\w/ )
       {
           # Include paths
           @split_var = split(/\s+-/,$variable);
		   $split_var[0] =~ s/^-//; # split deletes the "-" from all but the first element
           foreach $d1 ( @split_var )
           {
               $d1 = "-".$d1;
               if ( $d1 =~ /^(-\w)[\'\"]?((?:\/[\w\.~ ]+)+)[\'\"]?/ )
               # This regex: option -> $1, filename without quotes -> $2
               {
                   $d1_prefix = $1;
                   $d1_fname = $2;
                   if ( $d1_fname =~ / / ) {
                       # Use DOS 8.3 style to avoid quoting
                       chomp( $d1_fname = qx{cygpath -d "$d1_fname"} );
                   }   # ! This fails when $d1 doesn't exist!
                   else {
                       chomp( $d1_fname = qx{cygpath -w "$d1_fname"} ); # Use "normal" filenames
                   }
                   $d1 = $d1_prefix.$d1_fname;
               }
               else
               {   # relative paths here
                   # Do nothing.
               }
           }
           $variable = join(' ',@split_var);
       }
       elsif ( $variable eq ";" ) {}
       else {
           # Normal paths

           # One special case is if "perl " is prepended.
           $variable =~ /^(perl\s+)?(.*)$/;
           my $perlpre = $1;
           if ( !defined($perlpre) ) { $perlpre = ""; }
           $variable = $2;

           @split_var = split(/;/,$variable);
           foreach $d1 ( @split_var ) {
               if ( $d1 =~ /(?:^\/[\w\.~ ]+)+/ ) {
                   if ( $d1 =~ / / ) {
                       chomp( $d1 = qx{cygpath -d "$d1"} ); # Use DOS 8.3 style to avoid quoting
                   }                                        # ! This fails when $d1 doesn't exist!
                   else {
                       chomp( $d1 = qx{cygpath -w "$d1"} ); # Use "normal" filenames
                   }
               }
               else {
                   # relative paths here
                   # Do nothing.
               }
           }
           $variable = $perlpre.join(';',@split_var);
           if ( ($perlpre ne "") && ($^O eq "cygwin")) {
               # Cygwin's perl needs quoted backslashes
               $variable =~ s#\\#\\\\#g;
           }
       }
       $variable =~ s/\//\\/g; # Remaining \ come from e.g.: ../foo/baa
   return $variable;
}

#--------------------------------------------------------
# Function name: GetCorrectPath
# Description:   Creates the build environment. 
# Arguments:     1.   existing / original path
#                2... pairs of <path, executable>
# Return value:  String - Correct Path
#--------------------------------------------------------
sub GetCorrectPath
{
	sub PathLookup
	{
	    my $cmd = shift;
	    while (@_) {
		my $elem = shift;
		
		-x "$elem/$cmd" && return $elem;
	    }
	    return '';
	}

	sub SaneGrep
	{
	    # Perl grep is unbelievably strange.
	    my $needle = shift;
	    while (@_) {
		my $haystack = shift;
		if ($needle eq $haystack) {
		    return 1;
		} 
	    }
	    return 0;
	}	

	sub CleanupPath
	{
	    my @elements = @_;
	    my @cleanName = ();

	    while (@elements) {
		my $elem = shift @elements;
		if (!SaneGrep ($elem, @cleanName)) {
			push @cleanName, $elem;
		}
	    }

	    return @cleanName;
	}

	my $oldPath = shift;
	my @originalPairs = @_;
	my @pairs = @originalPairs;
	my @Path = split /$ps/, $oldPath;

	while (@pairs) {
	    my $path = shift @pairs;
	    my $cmd = shift @pairs;
	    my $to_append = 1;
	    my $elem;

	    if (! -x "$path/$cmd") {
		AddWarning ("Missing executable $path/$cmd\n");
	    }

	    for $elem (@Path) {
		if ($elem eq $path) {
#		    print "Hit duplicate path in path; break\n";
		    $to_append = 0;
		    last;
		}
		if (-f "$elem/$cmd") {
#		    print "Element already in path ...\n";
		    unshift @Path, $path;
		    $to_append = 0;
		    last;
		} else {
#		    print "No file $elem/$cmd\n";
		}
	    }
	    if ($to_append) {
		push @Path, $path;
	    }
	}

	@pairs = @originalPairs;
	while (@pairs) {
	    my $path = shift @pairs;
	    my $cmd = shift @pairs;
	    my $realpath;

	    $realpath = PathLookup ($cmd, @Path);
	    if (!($realpath eq $path)) {
		AddWarning ("Path conflict for executables " .
                            "$path/$cmd against $realpath");
	    }
	}

	return join $ps, CleanupPath (@Path);
}

#------------------------------------------------------------
# Function name: AddWarning 
# Description:   Adds any kind of warning for the user.
#                The warning will be shown at the end
#                of this script.
# Arguments:     1. Add the configure warnings or the set_soenv
#                   warning (string).
#                2. Warning (string).
# Return value:  void
#------------------------------------------------------------
sub AddWarning 
{  if ( $_[ 0 ] eq "configure" ) 
   {  open( IN, $warnfile );
      while ( <IN> ) 
      {  $Warning = $Warning."* - ".$_;
      }
      close( IN );
      # Remove the temporary warning file.
      # unlink ( $warnfile );
   }
   elsif ( $_[ 0 ] eq "set_soenv" ) 
   {  my ( $arg1 );
      $arg1 = $_[ 1 ];
      chomp( $arg1 );                            # cut off new line      
      $Warning = $Warning."* - set_soenv: warning: $arg1 $newline";  # add the warning  
   }
}
#-------------------
# That's all folks!
#-------------------
