#!/bin/csh -fb
#  aimk
#
#___INFO__MARK_BEGIN__
##########################################################################
#
#  The Contents of this file are made available subject to the terms of
#  the Sun Industry Standards Source License Version 1.2
#
#  Sun Microsystems Inc., March, 2001
#
#
#  Sun Industry Standards Source License Version 1.2
#  =================================================
#  The contents of this file are subject to the Sun Industry Standards
#  Source License Version 1.2 (the "License"); You may not use this file
#  except in compliance with the License. You may obtain a copy of the
#  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
#
#  Software provided under this License is provided on an "AS IS" basis,
#  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
#  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
#  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
#  See the License for the specific provisions governing your rights and
#  obligations concerning the Software.
#
#  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
#
#  Copyright: 2001 by Sun Microsystems, Inc.
#
#  All Rights Reserved.
#
##########################################################################
#___INFO__MARK_END__
#
# Credit should be given to Robert Manchek manchek@CS.UTK.EDU for creating
# a similar aimk procedure for the PVM 3.x distribution, Jul 22 1991,
# which inspired the Grid Engine aimk build scheme.

# Make sure to avoid confusion between shell variables and environment
# variables 
#
set noglob
unsetenv buildarch BUILDARCH COMPILE_ARCH COMPILE_DIR LD_LIBRARY_PATH RMONLIB
unsetenv AIMK_INSURE AIMK_TARGET_BITS aimk_buildarch

set COMPILE_ARCH = ""
set COMPILE_DIR  = ""
set buildarch    = UNKNOWN
set WINCC        = ""
set WINCFLAGS    = ""
set WINLFLAGS    = ""
set WINLIBS      = ""
set AIMK_TARGETOPT   = 0
set NO_XDEPEND   = ""
set ERR_WARN_NONE = ""
set ERR_WARN_ALL = ""
set UNMODIFIED_ARGUMENTS = ( $argv )
set FORCE_32BIT = 0
set WERR        = 0
set WEXTRA      = 0
set STACKPROTECT = 0

if ( -f dist/util/arch ) then
   set buildarch = `dist/util/arch`
else
   echo script dist/util/arch not available
   exit 1
endif

set BUILDARCH = `scripts/compilearch -b $buildarch`
if ( $status != 0 ) then
  echo Unsupported architecture $buildarch
  exit 1
endif

set TARGET_BITS = `scripts/compilearch -t $buildarch`
if ( $status != 0 ) then
  echo Unsupported architecture $buildarch
  exit 1
endif

set COMPILE_ARCH = `scripts/compilearch -c $buildarch`
if ( $status != 0 ) then
  echo Unsupported architecture $buildarch
  exit 1
endif

#---------------------------------------------------------------------------
# Preparsing for all args which change BUILDARCH or which exit
# all args here must be read in the main parsing loop to ensure
# they are eaten from the command line.
# All variables which are set above in the switch-case must be reset here
# e.g. BUILDARCH, TARGET_BITS, buildarch ...
#
set i = 1
while ($i <= $#argv)
   set UNMODIFIED_ARGUMENTS[$i] = "$argv[$i]"
   switch ("$argv[$i]")
   case "-32":
      set AIMK_TARGETOPT = 1
      set TARGET_BITS = TARGET_32BIT
      if ($BUILDARCH == SOLARIS64) then
         set BUILDARCH = SOLARIS  
         set buildarch = sol-sparc
      else if ($BUILDARCH == HP1164) then
         set BUILDARCH = HP11
         set buildarch = hp11
      else if ($BUILDARCH == LINUXMIPS64 || $BUILDARCH == LINUXPPC64 || $BUILDARCH == LINUXS390X || $BUILDARCH == LINUXX64 ) then
         set FORCE_32BIT = 1
      else
         echo "32-bit switch not supported for $buildarch"
         exit 1
      endif
      breaksw
   case "-64":
      set AIMK_TARGETOPT = 1
      set TARGET_BITS = TARGET_64BIT
      if ($BUILDARCH == HP11) then
         set BUILDARCH = HP1164
         set buildarch = hp11-64
      else
         echo "64-bit switch not supported for $buildarch"
         exit 1
      endif
      breaksw
   case "-help":
   case "--help":
      goto usage
      breaksw
   endsw
   set i = `expr $i + 1`
end

# Source variables for definition of site dependent paths of software here
#
if ( -f aimk.site ) then
   source aimk.site
endif

# your private command line args go here
#
if ( -f aimk.private ) then
   source aimk.private
endif

goto start

usage:
   echo "usage: aimk <OPTIONS>"
   echo "OPTIONS are: "
   echo ""
   echo " -32               -> create 32 bit binaries (where supported)"
   echo " -64               -> create 64 bit binaries (where supported)"
   echo " -D*               -> include a macro definition in CFLAGS"
   echo " -add-copyright    -> insert a special copyright string in each binary"
   echo " -add-sun-copyright-> insert a Sun copyright string in each binary" 
   echo " -adoc             -> create source code documentation in adoc format"
   echo " -catman           -> generate man pages in catman format"
   echo " -cc               -> use cc/CC to compile c/c++ code"
   echo " -cov              -> complile for code coverage analysis"
   echo " -dce              -> enable dce security"
   echo " -debug            -> compile with debug information"
   echo " -efence           -> compile in debug mode and detect memory leaks"
   echo " -f                -> specify other Makefile instead of common/Makefile"
   echo " -flags            -> print C_FLAGS and INCLUDE_FLAGS to stdout, used by gelint"
   echo " -gcc              -> use gcc instead of system compiler (where supported)"
   echo " -gettext          -> build the gettext libraries"
   echo " -gprof            -> enable gprof profiling"
   echo " -gss              -> enable gss security"
   echo " -help             -> show this help"
   echo " -htmlman          -> generate man and html pages"
   echo " -htmlmankv        -> generate man and html pages checked out with '-kv' flag"
   echo " -insure           -> compile in debug mode and detect memory leaks"
   echo " -intl             -> compile with internationalization library (libintl)"
   echo " -javadoc          -> create source code documentation in Javadoc[TM] tool format"
   echo " -kerberos         -> enable kerberos authentication"
   echo " -man              -> generate man pages"
   echo " -mankv            -> generate man pages checked out with '-kv' flag"
   echo " -mo               -> generate the message catalogues (Solaris only)"
   echo " -no-core          -> don't compile the core system"
   echo " -no-java          -> don't compile Java[TM] class files"
   echo " -no-gui-inst      -> don't compile Java[TM] GUI installer"
   echo " -no-jni           -> don't compile JNI library"
   echo " -no-intl          -> do not compile with internationalization library"
   echo " -no-mk            -> only return the specific architecture string"
   echo " -no-opt           -> compile with no optimization"
   echo " -no-perfstat      -> don't use Perfstat Library on AIX"
   echo " -no-qmake         -> don't compile qmake"
   echo " -no-qmon          -> don't compile qmon 3rdparty libs and qmon client"
   echo " -no-qtcsh         -> don't compile qtcsh"
   echo " -no-remote        -> don't compile 3rdparty remote module (rsh, rshd, rlogin)"
   echo " -no-rmon          -> disable rmon debug output"
   echo " -no-secure        -> disable ssl security (enabled by default)"
   echo " -no-jemalloc      -> disable jemalloc (enabled by default on Linux hosts)"
   echo " -no-mtmalloc      -> disable mtmalloc (this is needed for dbx debugging)"
   echo " -only-core        -> build only the core system"
   echo " -only-depend      -> only compile 3rdparty/sge_depend"
   echo " -only-java        -> only compile Java[TM] class files"
   echo " -only-gui-inst    -> only compile Java[TM] GUI installer"
   echo " -only-jemalloc    -> build only the jemalloc library"
   echo " -only-qmake       -> build only qmake"
   echo " -only-qmon        -> build only qmon 3rdparty libs and qmon client"
   echo " -only-qtcsh       -> build only qtcsh"
   echo " -only-remote      -> build only 3rdparty remote module (rsh, rshd, rlogin)"
   echo " -only-64          -> build only 64 bit shared libraries for SOLARIS64, don't build 32 bit shared libraries"
   echo " -parallel n       -> spawn multiple make processes by passing option -j n to make"
   echo " -po               -> merge gridengine .pot with translations (Linux)"
   echo " -pot              -> extract message template to gridengine .pot file (Linux)"
   echo " -protected        -> create complete class file documentation"
   echo " -purify           -> instrument code with purify (implies -debug)"
   echo " -qmake            -> use qmake instead of make"
   echo " -shared-libs      -> create libraries as shared libs"
   echo " -spool-berkeleydb -> use berkeleydb spooling"
   echo " -spool-classic    -> use classic flatfile spooling"
   echo " -spool-targets    -> only create qmaster, spooldefaults and spoolinit"
   echo " -sunman           -> create man pages for Sun branded man pages (with -man[kv])"
   echo " -tight-ssh        -> compile SSH daemon with tight SGE integration"
   echo " -umap             -> compile with usermapping and hostgroup feature"
   echo " -werror           -> turn all compiler warnings into errors"
   echo " -wextra           -> turn on extra compiler warnings"
   echo " -with-jemalloc    -> build SGE with the jemalloc library"
   echo ""
   echo "Linking against system libraries"
   echo " -sys-hwloc        -> use the hwloc library provided by the system"
   echo " -sys-jemalloc     -> use the jemalloc library provided by the system"
   echo " -sys-libssl       -> use the ssl library provided by the system"
   echo ""
   echo "Deprecated Features (support will be removed by 2013 Q3)"
   echo " -plpa                 -> PLPA hardware topology support"
   echo " -solaris-pset         -> enable Solaris Processor Set binding support"
   echo " -spool-berkeleydb-rpc -> enable BerkeleyDB RPC server support"
   echo " -DOGLIBC_LINUX        -> support glibc 2.1 or older (Linux only)"

  exit
}

start:

#-----------------------------------------------------------------------------------
# Variables below define default behavior and default compiler and linker
# flags which are passed to make
#

# Master settings
set SOURCE           = `pwd`
set SDIR             = ".."
set MSDIR            = ""
set MAKEFILE         = "${SDIR}/common/Makefile.global"
set SOLARIS_ONLY_64  = 0
set ONLY_PARAM_SPEC  = 0

# SGE_INPUT_CFLAGS will be taken from environment and added to CFLAGS
if ( $?SGE_INPUT_CFLAGS ) then
   set INP_CFLAGS    = "$SGE_INPUT_CFLAGS"
else
   set INP_CFLAGS    = ""
endif

# Default build targets for which we have seperate make files
set SGE_DEPEND       = 0
set QMON             = 1
set CORE             = 1
set REMOTE           = 1
set QMAKE            = 1
set QMAKELIB         = ""
set QTCSH            = 1
set PLPA             = 0
set HWLOC            = 1
set HWLOC_CFLAGS     = "-O2"
set MAKEHWLOC        = 1
set MAKEJEMALLOCLIB  = 0
set LINKJEMALLOCLIB  = 0
set LINKMTMALLOCLIB  = 1
set MAKESTRPTIME     = 0
set MAKESNPRINTF     = 0
set MAKEFNMATCH      = 0
set MAKEWINGRIDLIB   = 0
set MAKEWINGRIDAPP   = 0
set WINGRIDLIB_A     = ""
# Can't use name WINGRIDLIB_STATIC_DEP because variable is too long
set WINGRIDLIB_A_DEP = "" 

set WITH_USERMAPPING = 0 # Compile without usermapping feature
set SGESSH           = 0

# Default Flags and Libraries
set OPTIMIZATION     = 1
set GPROFFED         = 0
set COVED            = 0
set USE_INSURE       = 0
set DEBUGGED         = 0
set COMPILE_DC       = 0
set CC               = cc
set CXX              = CC
set CFLAGS           = "-D$TARGET_BITS $INP_CFLAGS"
set CORE_INCLUDE     = "-I../common -I../libs -I../libs/uti -I../libs/juti -I../libs/gdi -I../libs/japi -I../libs/sgeobj -I../libs/cull -I../libs/rmon -I../libs/comm -I../libs/comm/lists -I../libs/sched -I../libs/evc -I../libs/evm -I../libs/mir -I../libs/lck -I../daemons/common -I../daemons/qmaster -I../daemons/execd -I../clients/common -I."
set DEBUG_FLAG       = ""
set INSURE_FLAG      = ""
set JEMALLOC_CFLAGS  = ""
set NOERR_CFLAG      = ""
set NOERR_PROTO      = ""
set NOERR_SSH        = ""
set MEMCFLAG         = ""
set JAVA_ARCH        = ""
set JAVA_LFLAGS      = ""
set JAVA             = 1
set JAVA_BINDIR      = "bin"
set JAVA_INCL        = "include"
set JAVA_SHAREDEXT   = ""
set JAVA_GUI_INST    = 1
set JNI              = 1
set JNI_TARGET       = "ALL"
set PROTECTED        = 0
set RUNPATH          = ""

set LFLAGS           = "-L."
set XLFLAGS          = ""
set XLIBS            = ""
set XMLIBS           = ""
set LIBS             = "-lm -lpthread"
set LIBRARY_LIBS     = ""  # used for linking shared objects like drmaa.so or jgdi.so. Overwritten by $LIBS if empty
set LD_WRAPPER       = ""
set DLLIB            = "-ldl"
set LOADAVGLIBS      = ""
set FSTYPELIBS       = ""
set TPLIB            = ""  # 3rdparty libs
set SLIBS            = ""
set FLAGS_OUT        = "false"
set DUMP             = 0


# Default settings for shared library creation
set SHAREDLIBS       = 0
set SHAREDEXT        = ".so"
set SHAREDLD         = ""
set SHARED_CFLAGS    = ""
set SHARED_LFLAGS    = ""

# linker flag for -ldrmaa name and version
set SONAME_LFLAG_DRMAA10 = ""
set SONAME_LFLAG_DRMAA95 = ""

# Flags for man page creation, copyright stuff and adoc
set BUILDMAN          = 0
set BUILDCATMAN       = 0
set BUILDGETTEXT      = 0
set BUILDHTMLMAN      = 0
set BUILDJAVADOC      = 0
set SGE_PRODUCT_MODE  = ge
set ADD_COPYRIGHT     = 0
set ADD_SUN_COPYRIGHT = 0
set ADOC              = 0

# Default name and command line flags for some build commands
set MAKE              = make
set MAKEOPT           = ""
set STRIP             = strip
set RANLIB            = echo
set AR                = ar
set ARFLAGS           = rscv
set PARALLEL          = ""  
set USE_QMAKE         = 0

# I18N, L10N stuff
set GETTEXTBASE       = "$SOURCE/3rdparty/gettext"
set MESSAGES          = "../dist/locale/gridenginenotuniq.pot"
set MESSAGES_BIN      = "gridengine.mo"
set CREATE_MSG        = 0
set CREATE_MSG_DIR    = ../dist/locale
set CREATE_MSG_LANG   = "de en"

# These targets are more difficult to port - not all platforms support these
set INTERACTTARGETS   = "qmake qtcsh"

# SECURE
set SEC               = 1
set SECFLAGS          = "-DSECURE -I$OPENSSL_HOME/include"
set SECLIB            = ""
set SECLIBS_STATIC    = "$OPENSSL_HOME/lib/libssl.a $OPENSSL_HOME/lib/libcrypto.a"
set KLFLAGS           = "-L$OPENSSL_HOME/lib"

# AIX
set PERFSTAT          = 1

# LINUX
set CORELIB           = ""

# Solaris
set SOLARISPSET       = 0

# WIN
set WINGRIDLIB        = ""
set WINGRIDLIB_DEP    = ""

# GSS
set GSSDEPEND         = ""
set GSSCLEAN          = ""
set GSSLIBS           = ""

# KERBEROS
set KRB	              = 0
set KRBTARGETS        = ""
set KRBDEPEND         = ""
set KRBCLEAN          = ""
set KRBLIBS           = ""
set KRBLIB            = ""
set KLIBS             = ""

# CRYPT
set AUTHLIBS          = "-lpam"

# PERLGUI
set PERLGUI           = ""
set PERLGUI_CLEAN     = ""

# SPOOLING - default method is dynamic spooling, 
# spooling methods berkeleydb and classic
set SPOOLING_METHOD = "dynamic"
set SPOOLING_LIBS   = "-lspoolloader -lspoold -lspool"
set SPOOLING_DEPS   = "spoolloaderlib spooldlib spoollib spoolclib spoolblib"
# we generate a berkeley db shared lib, so we need bdb include and lib path
set CFLAGS            = "-I$BERKELEYDB_HOME/include/${BDB_INCLUDE_SUBDIR} $CFLAGS"
set LFLAGS            = "-L$BERKELEYDB_HOME/lib/${BDB_LIB_SUBDIR} $LFLAGS"
set SHARED_LFLAGS    = "$SHARED_LFLAGS -L$BERKELEYDB_HOME/lib/${BDB_LIB_SUBDIR}"

# JUTI Targets
set JUTI_ALL  = juti_all
set JUTI_CLEAN  = juti_clean
set JUTI_DEPEND  = juti_depend

set AUTHUSER_ALL  = authuser
set LOADCHECK_ALL = loadcheck
set AUTHUSER_OBJ  = authuser.o
set LOADCHECK_OBJ = loadcheck.o
set JUTI_OBJ      = 

# Compile with gettext and libintl - we have platform dependent defaults
switch ($BUILDARCH) 
   case LINUXX64:
     set MAKEJEMALLOCLIB  = 1
     set LINKJEMALLOCLIB  = 1
     set WITH_GETTEXT = 1
     breaksw
   case LINUX*:
     set WITH_GETTEXT = 1
     breaksw
   case SOLARIS:
   case SOLARIS64:
   case SOLARIS86:
   case SOLARISAMD64:
      set WITH_GETTEXT = 1
      breaksw
   default:
      set WITH_GETTEXT = 0
      breaksw
endsw      

# X specific stuff (Xmt, Xbae ...)
#
# This stuff is for building the Xmt library
# If possible (i.e. imake is installed correctly)
# use the Imakefile (change Xmt.tmpl)
#
set XINCD                = "-I../3rdparty/qmon/Xbae -I../3rdparty/qmon/iconlist -I../3rdparty/qmon/ltree -I../3rdparty/qmon/outline -I../3rdparty/qmon/rowcol -I../3rdparty/qmon/spinbox -I../clients/qmon -I../3rdparty/qmon/tab"
if ( $?MY_XINCD ) then
   set XINCD             = "-I${MY_XINCD} ${XINCD}"
endif

if ( -x /usr/bin/freetype-config ) then
   set FREETYPE_CONFIG = "/usr/bin/freetype-config"
else
   set FREETYPE_CONFIG = "freetype-config"
endif

$FREETYPE_CONFIG --cflags >& /dev/null
if ($status == 0) then
   set XCFLAGS = `$FREETYPE_CONFIG --cflags`
else
   set XCFLAGS = ""
endif

set XMTINCD  = "-DHAVE_MEMMOVE -DXMT_HAS_STRERROR -I../3rdparty/qmon/Xmt310"
set XmtFileRootDir       = ""
set XmtFileSearchPath    = ""
# set   REPLAYXT_SUPPORT = 0
#
# The following DEFINES are necessary in special cases
# for more information see Xmt.tmpl
# -DNO_EDITRES       if libXmu is not available (HP)
# -DXMSTRING_TO_COMPOUND_TEXT_BUG  if tearoff menus dump core define this
# -DBACKSPACEBUG     if BackSpace in a Cli widget dumps core define this
# -DIBM_MANAGE_WORKAROUND     IBM/RS6000(AIX 3.2) if children of XmtLayout
#                             widget show up in upper left corner
# -DMISSING_METHOD_TYPES      for an old version of Motif 1.1
#                             (XmMenuProc not in XmP.h == old)
# -DXMTDEFAULTCONFIGDIR=\"$(XmtFileRootDir)\"   normally the home directory
# -DXMTFILESEARCHPATH=\"$(XmtFileSearchPath)\"  normally the home directory

unset nomk

set found
while ($#argv >= 1 && $?found)
   switch ("$argv[1]")
   # the following flags must be skipped
   case -32:
   case -64:
   case -help:
   case --help:
      breaksw
   case "-add-copyright"
      set ADD_COPYRIGHT = 1
      breaksw
   case "-add-sun-copyright"
      set ADD_SUN_COPYRIGHT = 1
      breaksw
   case "-adoc":
      set CORE   = 0
      set QMAKE  = 0
      set PLPA   = 0
      set HWLOC  = 0
      set MAKEHWLOC = 0
      set QMON   = 0
      set QTCSH  = 0
      set REMOTE = 0
      set ADOC = 1
      breaksw
   case "-catman":
      set BUILDCATMAN = "1"
      breaksw
   case "-cc"
      set CC       = cc
      set CXX      = CC
      breaksw
   case "-cov":
      set COVED      = 1
      set STRIP      = "echo"
      breaksw
   case "-crypto":
      set CFLAGS  = "-DCRYPTO -I$OPENSSL_HOME/include $CFLAGS"
      set LFLAGS  = "-L$OPENSSL_HOME/lib $LFLAGS"
      switch ($BUILDARCH)
         case HP11:
            set KLIBS = "-lcrypto"
            breaksw
         default:
            set CFLAGS = "-DLOAD_OPENSSL $CFLAGS"
            set KLIBS = ""
      endsw
      breaksw
   case "-D*":
      set CFLAGS = "$argv[1] $CFLAGS"
      breaksw
   case "-dce":
      set LIBS = " -ldce -threads $LIBS"
      set CFLAGS = " -DDCE -I/usr/include/dce $CFLAGS"
      breaksw
   case "-debug":
      set DEBUG_FLAG = "$DEBUG_FLAG -g -DSGE_LOCK_DEBUG"
      set DEBUGGED   = 1
      set STRIP      = "echo"
      breaksw
   case "-f":
      set argv   = ($argv[2-])
      if ($#argv >= 1) then
         set first_char = `echo $argv[1] | cut -c1`
         if ( "$first_char" == "/") then
            set MAKEFILE = $argv[1]
         else
            set MAKEFILE = "../$argv[1]"
         endif
         unset first_char
         set MSDIR = `dirname ${MAKEFILE}`
      else
         echo "usage: aimk [valid args] -f <makefile> [valid args]"
         exit 1
      endif
      breaksw
   case "-flags":
      set FLAGS_OUT = true
   breaksw
   case "-gcc"
      set CC       = gcc
      set CXX      = g++
      breaksw
   case "-gettext"
      set BUILDGETTEXT = 1
      breaksw
   case "-gprof":
      set DEBUG_FLAG = "$DEBUG_FLAG -pg"
      set GPROFFED   = 1
      set STRIP      = "echo"
      breaksw
   case "-gss":
      set GSSDEPEND = "gss_depend"
      set GSSCLEAN = "gss_clean"
      set CFLAGS  = "-DKERBEROS -I../security/gss -I$KRB_HOME/include -I$KRB_HOME/include/gssapi $CFLAGS"
      set GSSLIBS = "-lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err"
      breaksw
   case "-htmlman":
      set BUILDMAN = "1"
      set BUILDHTMLMAN = "1"
      set KVMAN = 0
      breaksw      
   case "-htmlmankv":
      set BUILDMAN = "1"
      set BUILDHTMLMAN = "1"
      set KVMAN = 1
      breaksw
   case "-insure"
      set USE_INSURE = 1
      set INSURE_FLAG = "-Zsl"
      set LFLAGS     = "-Zsl $LFLAGS"
      set DEBUGGED   = 1
      setenv SKIP_NONREENTRANT 1
      breaksw
   case "-efence"
      set LFLAGS     = "-lefence $LFLAGS"
      set DEBUGGED   = 1
      breaksw
   case  "-intl"
      set WITH_GETTEXT = 1
      breaksw
   case  "-javadoc"
      set BUILDJAVADOC = 1
      breaksw
   case "-kerberos":
      set KRB        = 1
      set KRBTARGETS = ""
      set KRBDEPEND  = "krb_depend"
      set KRBCLEAN   = "krb_clean"
      set KRBLIBS    = "libkrb.a"
      set KRBLIB     = "-lkrb"
      set CFLAGS     = "-DKERBEROS -I../security/krb -I$KRB_HOME/include -I$KRB_HOME/include/gssapi $CFLAGS"
      set KLFLAGS    = "-L$KRB_HOME/lib"
      set KLIBS      = "-lkrb5 -lk5crypto -lcom_err -lresolv"
      breaksw
   case "-man":
      set BUILDMAN   = 1
      set KVMAN      = 0
      breaksw
   case "-mankv":
      set BUILDMAN   = 1
      set KVMAN      = 1
      breaksw
   case "-mo"
      echo "BUILDARCH=$BUILDARCH"
      if ( $BUILDARCH == sol-sparc || $BUILDARCH == sol-sparc64 ) then
         scripts/msgmerge.csh
      else
         echo "Use a Solaris machine"
      endif
      exit 0
      breaksw
   case "-no-core":
      set CORE = 0
      breaksw
   case "-no-dump":
      set DUMP = 0
      breaksw
   case "-no-java"
      set JAVA = 0
      breaksw
   case "-no-gui-inst"
      set JAVA_GUI_INST = 0
      breaksw
   case "-no-jni"
      set JNI = 0
      breaksw
   case "-no-intl"
      set WITH_GETTEXT = 0
      breaksw
   case "-no-mk":
      set nomk
      breaksw
   case "-no-opt":
      set OPTIMIZATION = 0
      breaksw
   case "no-perfstat":
      set PERFSTAT = 0
      break;
   case "-no-qmake":
      set QMAKE = 0
      breaksw
   case "-no-qmon":
      set QMON = 0
      breaksw
   case "-no-qtcsh":
      set QTCSH = 0
      breaksw
   case "-no-remote":
      set REMOTE = 0
      breaksw
   case "-no-rmon":
      set CFLAGS  = "-DNO_SGE_COMPILE_DEBUG $CFLAGS"
      setenv RMONLIB  ""
      breaksw
   case "-no-secure":
      set SEC         = 0
      set SECFLAGS    = ""
      set SECLIB      = ""
      set SECLIBS_STATIC = ""
      set KLFLAGS     = ""
      breaksw
   case "-no-jemalloc":
      set MAKEJEMALLOCLIB = 0
      set LINKJEMALLOCLIB = 0
      breaksw
   case "-plpa":
      set PLPA = 1
      set HWLOC = 0
      set MAKEHWLOC = 0
      breaksw
   case "-solaris-pset":
      set SOLARISPSET = 1
      set HWLOC = 0
      set MAKEHWLOC = 0
      breaksw
   case "-no-hwloc":
      set HWLOC = 0
      set MAKEHWLOC = 0
      breaksw
   case "-no-mtmalloc":
      set LINKMTMALLOCLIB = 0
      breaksw
   case "-only-core":
      set CORE   = 1
      set JAVA   = 0
      set JAVA_GUI_INST = 0
      set QMAKE  = 0
      set PLPA   = 0
      set HWLOC  = 0
      set MAKEHWLOC = 0
      set QMON   = 0
      set QTCSH  = 0
      set REMOTE = 0
      set MAKEWINGRIDAPP = 0
      set MAKEWINGRIDLIB = 0
      set ONLY_PARAM_SPEC = 1
      breaksw
   case "-only-depend":
      set CORE       = 0
      set JAVA       = 0
      set JAVA_GUI_INST = 0
      set QMAKE      = 0
      set PLPA       = 0
      set HWLOC      = 0
      set MAKEHWLOC  = 0
      set QMON       = 0
      set QTCSH      = 0
      set REMOTE     = 0
      set SGE_DEPEND = 1
      set MAKEWINGRIDAPP = 0
      set MAKEWINGRIDLIB = 0
      set MAKEJEMALLOCLIB = 0
      set LINKJEMALLOCLIB = 0
      set ONLY_PARAM_SPEC = 1
      breaksw
   case "-only-java"
      set JAVA = 2
      set ONLY_PARAM_SPEC = 1
      breaksw
   case "-only-gui-inst"
      set JAVA_GUI_INST = 2
      set ONLY_PARAM_SPEC = 1
      breaksw
   case "-only-jemalloc":
      set CORE   = 0
      set JAVA   = 0
      set JAVA_GUI_INST = 0
      set QMAKE  = 0
      set PLPA   = 0
      set QMON   = 0
      set QTCSH  = 0
      set REMOTE = 0
      set MAKEJEMALLOCLIB = 1
      set LINKJEMALLOCLIB = 1
      set MAKEWINGRIDAPP = 0
      set MAKEWINGRIDLIB = 0
      set ONLY_PARAM_SPEC = 1
      breaksw
   case "-only-qmake":
      set CORE   = 0
      set JAVA   = 0
      set JAVA_GUI_INST = 0
      set QMAKE  = 1
      set PLPA   = 0
      set HWLOC  = 0
      set MAKEHWLOC = 0
      set QMON   = 0
      set QTCSH  = 0
      set REMOTE = 0
      set MAKEWINGRIDAPP = 0
      set MAKEWINGRIDLIB = 0
      set ONLY_PARAM_SPEC = 1
      breaksw
   case "-only-plpa":
      set PLPA   = 1
      set HWLOC  = 0
      set MAKEHWLOC = 0
      set CORE   = 0
      set JAVA   = 0
      set JAVA_GUI_INST = 0
      set QMAKE  = 0 
      set QMON   = 0
      set QTCSH  = 0
      set REMOTE = 0
      set MAKEWINGRIDAPP = 0
      set MAKEWINGRIDLIB = 0
      set ONLY_PARAM_SPEC = 1
      breaksw
   case "-only-qmon":
      set CORE   = 0
      set JAVA   = 0
      set JAVA_GUI_INST = 0
      set QMAKE  = 0
      set PLPA   = 0
      set HWLOC  = 0
      set MAKEHWLOC = 0
      set QMON   = 1
      set QTCSH  = 0
      set REMOTE = 0
      set MAKEWINGRIDAPP = 0
      set MAKEWINGRIDLIB = 0
      set ONLY_PARAM_SPEC = 1
      breaksw
   case "-only-qtcsh":
      set CORE   = 0
      set JAVA   = 0
      set JAVA_GUI_INST = 0
      set QMAKE  = 0
      set PLPA   = 0
      set HWLOC  = 0
      set MAKEHWLOC = 0

      set QMON   = 0
      set QTCSH  = 1
      set REMOTE = 0
      set MAKEWINGRIDAPP = 0
      set MAKEWINGRIDLIB = 0
      set ONLY_PARAM_SPEC = 1
      breaksw
   case "-only-wingrid":
      set CORE   = 0
      set JAVA   = 0
      set JAVA_GUI_INST = 0
      set QMAKE  = 0
      set PLPA   = 0
      set HWLOC  = 0
      set MAKEHWLOC = 0
      set QMON   = 0
      set QTCSH  = 0
      set REMOTE = 0
      set MAKEWINGRIDAPP = 1
      set MAKEWINGRIDLIB = 1
      set ONLY_PARAM_SPEC = 1
      breaksw
   case "-only-remote":
      set CORE   = 0
      set JAVA   = 0
      set JAVA_GUI_INST = 0
      set QMAKE  = 0
      set PLPA   = 0
      set HWLOC  = 0
      set MAKEHWLOC = 0
      set QMON   = 0
      set QTCSH  = 0
      set REMOTE = 1
      set MAKEWINGRIDAPP = 0
      set MAKEWINGRIDLIB = 0
      set ONLY_PARAM_SPEC = 1
      breaksw
   case "-only-64":
      set SOLARIS_ONLY_64 = 1
      breaksw
   case "-parallel":
      set argv     = ($argv[2-])
      set PARALLEL = "-j $argv[1]"
      breaksw
   case "-perlgui":
      set PERLGUI = "perlgui_all"
      set PERLGUI_CLEAN = "perlgui_clean"
      breaksw
   case "-po"
      if ( $buildarch == linux-x86 ) then
         scripts/msgmerge.csh merge
         echo ""
         echo "==========READY FOR TRANSLATION========="
         echo ""
      else
         echo "Must be done on Linux"
         exit 1
      endif
      exit 0
      breaksw
   case "-pot"
      if ( $buildarch != linux-x86 ) then
         echo "Must be done on linux-86 architecture"
         exit 1
      endif   
      rm -f dist/locale/gridenginenotuniq.pot
      rm -f dist/locale/gridengine.pot
      $0 -intl -only-core messages
      echo "Adding script messages"
      setenv BUILDARCH $BUILDARCH
      foreach f ( dist/inst_sge  dist/util/setfileperm.sh dist/util/arch_variables \
                  dist/util/qhold.sh dist/util/sgeCA/sge_ca )
         set pf = "/tmp/`basename $f`.pot"
         $TCLSH scripts/infotext_msg_parse.tcl -F $pf $f
         echo "Appending script pot file $pf" 
         cat $pf >> dist/locale/gridenginenotuniq.pot
         rm $pf
      end
      echo "Uniqing pot file"
      scripts/msgmerge.csh merge
      exit 0
      breaksw
   case "-protected":
      set PROTECTED = 1
      breaksw
   case "-purify":
      set LD_WRAPPER = "purify"
      set DEBUGGED   = 1
      breaksw
   case "-qmake"
      set USE_QMAKE    = 1
      set MAKE     = "qmake"
      set MAKEOPT = "-cwd -v PATH -pe make 2-100 -now n -- $MAKEOPT"
      breaksw
   case "-plpa" 
      breaksw
   case "-shared-libs":
      set SHAREDLIBS = 1
      breaksw
   case "-spool-berkeleydb":
      set SPOOLING_METHOD   = "berkeleydb"
      set SPOOLING_LIBS     = "-lspoolloader -lspoolb -lspool -ldb${BDB_LIB_SUFFIX}"
      set SPOOLING_DEPS     = "spoolloaderlib spoolblib spoollib"
      breaksw
   case "-spool-classic":
      set SPOOLING_METHOD = "classic"
      set SPOOLING_LIBS   = "-lspoolloader -lspoolc -lspool"
      set SPOOLING_DEPS   = "spoolloaderlib spoolclib spoollib"
      breaksw
   case "-classic-targets":   
      set CORE   = 1
      set QMAKE  = 0
      set QMON   = 0
      set QTCSH  = 0
      set REMOTE = 0
      set SPOOLING_METHOD = "classic"
      set SPOOLING_LIBS   = "-lspoolloader -lspoolc -lspool"  
      set SPOOLING_DEPS   = "spoolloaderlib spoolclib spoollib"
      set argv = ($argv sge_qmaster spoolinit spooldefaults)
      if ("$COMPILE_ARCH" != "") then
         set COMPILE_DIR = ${COMPILE_ARCH}_$SPOOLING_METHOD
      else
         set COMPILE_DIR = ${BUILDARCH}_$SPOOLING_METHOD
      endif 
      breaksw
   case "-sunman":
      set SGE_PRODUCT_MODE=sge
      breaksw
   case "-sys-jemalloc":
      setenv SGE_SYSJEMALLOC "SGE_SYSJEMALLOC"
      breaksw
   case "-sys-hwloc":
      setenv SGE_SYSHWLOC "SGE_SYSHWLOC"
      breaksw
   case "-sys-libssl":
      set SECFLAGS="-DSECURE"
      set SECLIBS_STATIC="-lssl -lcrypto"
      set KLFLAGS=""
      breaksw
   case "-umap"
      set WITH_USERMAPPING = 1
      breaksw
   case "-tight-ssh":
      set SGESSH = 1
      breaksw
   case "-werror":
      set WERR = 1
      breaksw
   case "-wextra":
      set WEXTRA = 1
      breaksw
   case "-stackprotect":
      set STACKPROTECT = 1
      breaksw
   case "-with-jemalloc"
      set MAKEJEMALLOCLIB = 1
      set LINKJEMALLOCLIB = 1
      breaksw
   default:
      unset found
      continue
      breaksw
   endsw
   if ($#argv > 1 ) then
      set argv     = ($argv[2-])
   else
      set argv     = ""
   endif
end

if ( $DEBUGGED && $USE_QMAKE ) then
   set MAKEOPT = "-verbose $MAKEOPT"
endif

if ( $?SGE_SYSJEMALLOC ) then
   set MAKEJEMALLOCLIB = 0
   set LINKJEMALLOCLIB = 1
endif

if ( $?SGE_SYSHWLOC ) then
   set MAKEHWLOC = 0
endif


set CFLAGS = "$CFLAGS -DSPOOLING_$SPOOLING_METHOD $SECFLAGS"

#---------------------------------------------------------------------------

if ($KRB == 1) then
   switch ($BUILDARCH)
    case HP11:
      set KLIBS = "-lcrypto"
      breaksw
   default:
      set CFLAGS = "-DLOAD_OPENSSL $CFLAGS"
      set KLIBS = ""
   endsw
endif


if ($SEC == 1) then
   switch ($BUILDARCH)
    case HP11:
      set SECLIB = "-lssl -lcrypto"
      breaksw
   default:
      set CFLAGS = "-DLOAD_OPENSSL $CFLAGS"
      set SECLIB = ""
   endsw
endif

#---------------------------------------------------------------------------
if ("$COMPILE_ARCH" == "") then
   set COMPILE_ARCH = $BUILDARCH
endif

if ($?nomk) then
   echo $COMPILE_ARCH
   exit 0
endif

if (! -d $COMPILE_ARCH) then
   echo " INFO: Architecture dir $COMPILE_ARCH not existing. Making"
   mkdir $COMPILE_ARCH
endif

if ( "$COMPILE_DIR" != "" ) then
   if (! -d $COMPILE_DIR) then
      mkdir $COMPILE_DIR
   endif
endif


switch ($BUILDARCH)
case AIX43:
case AIX:
   set MAKEWINGRIDLIB   = 0
   set MAKEWINGRIDAPP   = 0
   set COMPILE_DC = 1

   set LIBS = "$LIBS -lc"

   if ($BUILDARCH == "AIX43") then
     set AUTHLIBS = ""
   endif

   if ( $DEBUGGED == 1 ) then
      set DEBUG_FLAG = "$DEBUG_FLAG -qinitauto=01 -qro -qroconst"
   endif

   if ( $OPTIMIZATION == 1 ) then
      set OFLAG = "-O3 -qstrict -qmaxmem=8192"
   else
      set OFLAG    = "-qmaxmem=8192"
   endif

   set CC       = xlc_r
   set CXX      = xlC_r
   set CFLAGS   = "$OFLAG -DAIX -D$BUILDARCH -D_LARGE_FILES -DUSE_STDARG -DUSE_SGE_UNSETENV -DGETHOSTBYADDR_R5 -DGETHOSTBYNAME_R3 $DEBUG_FLAG $CFLAGS -bnoquiet"
   set DEPEND_FLAGS = "$CFLAGS $XMTINCD"
   set XMTDEF   = ""
   set XINCD    = "$XMTINCD $XINCD"
   set XCFLAGS  = "-bnodelcsect -DNeedFunctionPrototypes -DNeedVarargsPrototypes $XMTDEF $XINCD $XCFLAGS"
   set XLIBD    = ""
   set XLFLAGS  = "$XLIBD"
   set XLIBS    = "-lXm  -lXt -lXext -lX11 -lm -liconv -lc"
   set XMLIBS   = "$XLIBS"

   if ("$PERFSTAT" == 1) then
      set CFLAGS = "$CFLAGS -DHAS_AIX_PERFLIB"
      set LFLAGS = "$LFLAGS -lperfstat"
   endif

   if ("$WERR" == 1) then
      set CFLAGS = "$CFLAGS -qhalt=w"
   endif

   if ("$STACKPROTECT" == 1) then
      set CFLAGS = "$CFLAGS -qstackprotect"
   endif

   set SHAREDLD = "$SOURCE/scripts/ldAix"
   set SHARED_CFLAGS = ""
   set SHARED_LFLAGS = "$LFLAGS $KLFLAGS -brtl -bhalt:4 -bM:SRE -bE:lib.exp -H512 -T512 -bnoentry"

   # add DEBUG_FLAGS to LFLAGS after SHARED_LFLAGS - -g isn't recognized by ld
   set LFLAGS   = "$DEBUG_FLAG -brtl -bmaxdata:0x80000000 $LFLAGS"
   set JAVA_ARCH = "aix"
   set JAVA_LFLAGS = ""
   breaksw

case ALPHA5:
   set MAKEWINGRIDLIB   = 0
   set MAKEWINGRIDAPP   = 0
   set COMPILE_DC = 1
   set AUTHLIBS = ""

   if ( $OPTIMIZATION == 1 ) then
      set OFLAG = "-O3"
   else
      set OFLAG = ""
   endif

   set CXX = "cxx"
   set DLLIB = ""

   # gprof option is superset of debug option
   # -g3 produces better debugging information than -g1
   if ( $DEBUGGED == 1) then
      set DEBUG_FLAG = "-g2 -DSGE_LOCK_DEBUG"
      set OFLAG      = "-O"
   endif

   if ( $GPROFFED == 1) then
      set DEBUG_FLAG = "-g1 -pg -gen_feedback -non_shared"
   endif

   set NOERR_CFLAG  = "-w"
   set CFLAGS       = "$OFLAG -w2 -std1 -portable -pthread -warnprotos -DALPHA -D$BUILDARCH $DEBUG_FLAG $CFLAGS -DGETHOSTBYNAME_R3 -DGETHOSTBYADDR_R5 -DUSE_SGE_UNSETENV"
   set DEPEND_FLAGS = "$CFLAGS $XMTINCD"

   set SHAREDLD      = $CC
   set SHARED_CFLAGS = ""
   set SHARED_LFLAGS = "$SHARED_LFLAGS -L. -shared -pthread"

   set LFLAGS   = "-pthread $DEBUG_FLAG $LFLAGS"
   set XMTDEF   = ""
   set XINCD    = "$XMTINCD $XINCD"
   set XCFLAGS  = "-w -DFUNCPROTO=3 -DDEC -DSMT $XMTDEF $XINCD $XCFLAGS"
   set XLIBD    = ""
   set XLFLAGS  = "-taso $XLIBD"
   set XLIBS    = "-lXm -lXt -lXext -lX11 -lSM -lICE -lPW -ldnet_stub"
   set XMLIBS   = "$XLIBS"
   set LIBS     = "-lpset -lmach $LIBS"
   set JAVA_ARCH = "alpha"
   breaksw

case DARWIN_X86:
case DARWIN_X64:
case DARWIN_PPC:
   set MAKEWINGRIDLIB   = 0
   set MAKEWINGRIDAPP   = 0
   set COMPILE_DC = 1
   set HWLOC      = 0
   set MAKEHWLOC  = 0

   if ( $OPTIMIZATION == 1 ) then
      set OFLAG = "-O3"
   else
      set OFLAG = ""
   endif

   set CC = "gcc"
   set CXX = "g++"
   set DLLIB = "-ldl"

   if ( $DEBUGGED == 1) then
      set DEBUG_FLAG = "-g -DSGE_LOCK_DEBUG"
      set OFLAG = ""
   endif

   if ( $GPROFFED == 1) then
      set DEBUG_FLAG = "$DEBUG_FLAG -pg"
   endif

   if ($COVED == 1) then
      set DEBUG_FLAG = "$DEBUG_FLAG -fprofile-arcs -ftest-coverage"
   endif

   if ($BUILDARCH == "DARWIN_X86") then
      set X86_ARCH = "-arch i386"
   else if ($BUILDARCH == "DARWIN_X64") then
      set X86_ARCH = "-arch x86_64"
   else
      set X86_ARCH = ""
   endif

   set REL = `/usr/bin/uname -r`
   switch ($REL)
   case "6.*":
      set CFLAGS = "$OFLAG -no-cpp-precomp -flat_namespace -Wall -Wstrict-prototypes -DFD_SETSIZE=8192 -DDARWIN -DDARWIN6 -D$BUILDARCH -DGETHOSTBYNAME -DGETHOSTBYADDR_M $DEBUG_FLAG $CFLAGS"
      breaksw

   case "7.*":
   case "8.*":
      set CFLAGS = "$OFLAG -no-cpp-precomp -flat_namespace -Wall -Wstrict-prototypes -DFD_SETSIZE=8192 -DDARWIN -D$BUILDARCH -DGETHOSTBYNAME -DGETHOSTBYADDR_M $DEBUG_FLAG $CFLAGS"
      breaksw

   default:
      set CFLAGS = "$OFLAG -no-cpp-precomp -flat_namespace -Wall -Wno-format -Wstrict-prototypes -DFD_SETSIZE=8192 -DDARWIN -DDARWIN9 -D$BUILDARCH -DGETHOSTBYNAME -DGETHOSTBYADDR_M $DEBUG_FLAG $CFLAGS $X86_ARCH"
      set SHARED_LFLAGS = "$SHARED_LFLAGS $X86_ARCH"
      set LFLAGS        = "$LFLAGS        $X86_ARCH"
      breaksw
   endsw

   if ("$WERR" == 1) then
      set CFLAGS = "$CFLAGS -Werror"
   endif

   if ("$WEXTRA" == 1) then
      set CFLAGS = "$CFLAGS -Wextra"
   endif

   if ("$STACKPROTECT" == 1) then
      set CFLAGS = "$CFLAGS -fstack-protector-all"
   endif

   set DEPEND_FLAGS = "$CFLAGS $XMTINCD"
   set LFLAGS   = "$DEBUG_FLAG $LFLAGS"

   set SHAREDLD = "$CC -dynamiclib -flat_namespace -undefined warning"
   set SHARED_CFLAGS = "-dynamic -fno-common"
   set SHARED_LFLAGS = "$SHARED_LFLAGS -L."

   set SHAREDEXT = ".dylib"
   if ( $SHAREDLIBS == 1 ) then
      set libext = $(SHAREDEXT)
   else
      set libext = ".a"
   endif   
  
   # Can be overwritten in aimk.private or aimk.site 
   if ( ! $?MOTIFHOME ) then
      set MOTIFHOME = /Applications/Darwin/openmotif-2.2.3
   endif

   set XMTDEF   = ""
   set XMTINCD  = "$XMTINCD -I$MOTIFHOME/include"
   set XINCD    = "$XMTINCD $XINCD -I/usr/X11R6/include"
   set XCFLAGS  = "-DNeedFunctionPrototypes -DNeedVarargsPrototypes -Wno-error $XMTDEF $XINCD $XCFLAGS"
   set XLIBD    = "-L$MOTIFHOME/lib -L/usr/X11R6/lib"
   set XLIBS    = "-lXm -lXpm -lXt -lXext -lX11 -lSM -lICE"
   set XMLIBS   = "$XLIBS"
   if ("$ADOC" == 1) then
      set CFLAGS = "$CFLAGS -Wno-error"
   endif

   set XLFLAGS = "$XLIBD"

   set NOERR_CFLAG = "-Wno-error"
   set NOERR_PROTO = "-Wno-strict-prototypes"
   set JAVA_ARCH = ""
   # set JAVA_BINDIR = "Commands"
   # set JAVA_INCL = "Headers"
   # set JAVA_INCL = "Versions/Current/Headers"
   set JAVA_SHAREDEXT = ".jnilib"
   #set JAVA_LFLAGS = ""
   unset REL
   breaksw

case FREEBSD_*:
   set MAKEWINGRIDLIB   = 0
   set MAKEWINGRIDAPP   = 0
   set COMPILE_DC = 1
   set MAKE = gmake
   if ( $OPTIMIZATION == 1 ) then
      set OFLAG = "-O3"
   else
      set OFLAG = ""
   endif
   set ARFLAGS  = rcv
   set CC       = gcc
   set CXX      = g++
   set DLLIB	 = ""
   set PTHRDSFLAGS = "-D_REENTRANT -D__USE_REENTRANT"
   set CFLAGS   = "$OFLAG -Wall -DFREEBSD -D$BUILDARCH -DGETHOSTBYNAME_M -DGETHOSTBYADDR_M $DEBUG_FLAG $CFLAGS -I/usr/X11R6/include"
   set DEPEND_FLAGS = "$CFLAGS $XMTINCD"
   set NOERR_CFLAG = "-Wno-error"
   set LFLAGS   = "$DEBUG_FLAG $LFLAGS -export-dynamic"
   set LIBS     = "$LIBS -lkvm"
   set SHAREDLD = $CC
   set SHARED_CFLAGS = "-fPIC"
   set SHARED_LFLAGS = "$SHARED_LFLAGS -L. -shared -export-dynamic"
   set AUTHLIBS = "-lcrypt -lpam"
 
   set XMTDEF   = ""
   set XINCD    = "$XMTINCD $XINCD -I/usr/X11/include"
   set XCFLAGS  = "-Wno-strict-prototypes -Wno-error $XMTDEF $XINCD $XCFLAGS"
   set XLIBD    = "-L/usr/X11R6/lib"
   set XLFLAGS  = "$XLIBD"
   set XLIBS    = " -Xlinker -lXm -Xlinker -Bdynamic -lXpm -lXt -lXext -lX11 -lSM -lICE -lXp"
   set XMLIBS   = "$XLIBS"
   set RM	= "rm -f"
   set JAVA_ARCH = "linux"
   breaksw 

case NETBSD_*:
   set MAKEWINGRIDLIB   = 0
   set MAKEWINGRIDAPP   = 0
   set COMPILE_DC = 1

   set HWLOC      = 0
   set MAKEHWLOC  = 0

   set MAKE = gmake
   set OFLAG = "-O"
   set ARFLAGS  = rcv
   set CC       = gcc
   set CXX      = g++
   set DLLIB    = ""
   set PTHRDSFLAGS = "-D_REENTRANT -D__USE_REENTRANT"
   set CFLAGS   = "$OFLAG -Wall -DNETBSD -D$BUILDARCH -DGETHOSTBYNAME_M -DGETHOSTBYADDR_M $DEBUG_FLAG $CFLAGS -I/usr/X11R6/include"
   set DEPEND_FLAGS = "$CFLAGS $XMTINCD"
   set NOERR_CFLAG = "-Wno-error"
   set LFLAGS   = "$DEBUG_FLAG $LFLAGS -export-dynamic"
   set LIBS     = "$LIBS -lkvm"
   set SHAREDLD = $CC
   set SHARED_CFLAGS = "-fPIC"
   set SHARED_LFLAGS = "$SHARED_LFLAGS -L. -shared -export-dynamic"
   set AUTHLIBS = "-lcrypt -lpam"

   set XMTDEF   = ""
   set XINCD    = "$XMTINCD $XINCD -I/usr/X11/include -I/usr/pkg/include"
   set XCFLAGS  = "-Wno-strict-prototypes -Wno-error $XMTDEF $XINCD $XCFLAGS"
   set XLIBD    = "-L/usr/X11R6/lib -R/usr/X11R6/lib -L/usr/pkg/lib -R /usr/pkg/lib"
   set XLFLAGS  = "$XLIBD"
   set XLIBS    = " -lXm -lXpm -lXt -lXext -lX11 -lSM -lICE -lXp"
   set XMLIBS   = "$XLIBS"
   set RM       = "rm -f"
   set JAVA_ARCH = "netbsd"
   breaksw


case IRIX65:
   set MAKEWINGRIDLIB   = 0
   set MAKEWINGRIDAPP   = 0
   set AUTHLIBS = ""
   if ( $OPTIMIZATION == 1 ) then
      set OFLAG = "-O3"
   else
      set OFLAG = ""
   endif

   if ( $DEBUGGED == 1 ) then
      set OFLAG = ""
   endif 

   set DLLIB = ""

   set COMPILE_DC = 1
   set MAKE = gmake

   set HWLOC      = 0
   set MAKEHWLOC  = 0

   set CFLAGS   = "$OFLAG -Werror -woff 1035,3201,3496 -n32 -mips3 -mp -DFD_SETSIZE=8192 -DIRIX -D$BUILDARCH -DGETHOSTBYNAME_M -DGETHOSTBYADDR_M $DEBUG_FLAG -DUSE_SGE_UNSETENV $CFLAGS"
   set NOERR_CFLAG = "-woff 47,1110,1174,1209"
   set DEPEND_FLAGS = "$CFLAGS $XMTINCD"
   set LFLAGS   = "-n32 -mips3 $DEBUG_FLAG $LFLAGS"
   set LIBS     = "$LIBS"
   set XMTDEF   = ""
   set XINCD    = "$XMTINCD $XINCD"
   set XCFLAGS  = "$XMTDEF $XINCD -woff 1174,1498,1506,1185,1552,3496,1209 $XCFLAGS"
   set XLIBD    = ""
   set XLFLAGS  = "$XLIBD"
   set XLIBS    = "-lXm -lXt -lXext -lX11 -lPW -lm"
   set XMLIBS   = "$XLIBS"
   set RANLIB   = echo

   # set SONAME_LFLAG_DRMAA10 = "-W l,-soname,libdrmaa.so.1.0"
   # set SONAME_LFLAG_DRMAA95 = "-W l,-soname,libdrmaa.so.0.95"

   set SHAREDLD = ld
   set SHARED_CFLAGS = "-KPIC"
   set SHARED_LFLAGS = "$SHARED_LFLAGS -L. -shared"
   set JAVA_ARCH = "irix"
   breaksw

case HP11:
case HP1164:
   set MAKEWINGRIDLIB   = 0
   set MAKEWINGRIDAPP   = 0
   set MAKE = gmake
   set DLLIB = ""
   set OFLAG = ""
   set HOSTRESOLVEFLAGS = "-DGETHOSTBYNAME -DGETHOSTBYADDR"

   if ($BUILDARCH == HP11) then
      set MEMFLAG = +DD32
      set AUTHLIBS = "-lsec -lpam"
   else
      set MEMFLAG = +DD64
      set COMPILE_DC = 1
      set AUTHLIBS = "-lsec"
   endif
   if ($CC == gcc) then
      if ( $DEBUGGED == 0 ) then
         if ( $OPTIMIZATION != 0 ) then
            set OFLAG = "-O2"
         endif
      endif
      set CFLAGS = "$OFLAG -Wall -Wstrict-prototypes -D$BUILDARCH $HOSTRESOLVEFLAGS $DEBUG_FLAG $CFLAGS"
   else
      if ( $DEBUGGED == 0 ) then
         if ( $OPTIMIZATION != 0 ) then
            set OFLAG = "+O2"
         endif
      endif
      set CXX = "aCC"
      # Extended ANSI mode. Same as -Aa -D_HPUX_SOURCE +e.
      set CFLAGS = "-Ae $CFLAGS"

      # Enable all warnings
      #set CFLAGS = "+w1 $CFLAGS"

      # unix 98 mode (??)
      # set CFLAGS = "-D_XOPEN_SOURCE_EXTENDED $CFLAGS"

      set CFLAGS = "$MEMFLAG $OFLAG -DHPUX -D$BUILDARCH $HOSTRESOLVEFLAGS $DEBUG_FLAG $CFLAGS"
   endif

   set DEPEND_FLAGS = "$CFLAGS $XMTINCD"

   set SHAREDLD = ld
   if ( $CC == gcc ) then
      set SHARED_CFLAGS = "-fPIC"
      set SHARED_LFLAGS = "$SHARED_LFLAGS -L. -shared"
   else
      set SHARED_CFLAGS = "+Z"
      set SHARED_LFLAGS = "$SHARED_LFLAGS -L. -b +s"
   endif

   set CFLAGS = "-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -DUSE_SGE_UNSETENV $CFLAGS -D_REENTRANT"
   set LIBS     = "-lnsl $LIBS"

   if ($BUILDARCH == HP11) then
      set LFLAGS   = "$DEBUG_FLAG $LFLAGS +DD32 -Wl,+s"
   else
      #set LFLAGS   = "$DEBUG_FLAG $LFLAGS +DD64 -Wl,+s"
      set ORIGINORIGIN = '$$ORIGIN'
      set LFLAGS   = "$DEBUG_FLAG $LFLAGS +DD64 -Wl,+s -Wl,+b,'$ORIGINORIGIN'/../../lib/$buildarch"
   endif

   set XMTDEF   = "-DNO_EDITRES"
   set XINCD    = "$XMTINCD $XINCD"
   set XCFLAGS  = "$XMTDEF $XINCD $XCFLAGS"
   set XLIBD    = ""
   set XLFLAGS  = "$XLIBD"
   set XLIBS    = "-lXm -lXt -lXext -lXhp11 -lX11 -lm"
   set XMLIBS   = "$XLIBS"

   set SHAREDEXT = ".sl"
   set JAVA_ARCH = "hp-ux"

   # interesting compiler options
   # +ESlit or +ESconstlit (place consts / string literals in read only memory
   # we could use higher optimization +O3 or +O4
   # -z
   # +w1 (All warnings)
   # +W arg1,arg2,.. suppress individual warnings
   # -D_XOPEN_UNIX
   # -D_XOPEN_SOURCE_EXTENDED

   # http://docs.hp.com/en/B2355-90968/linkertasks.htm#BAJEBEEC
   # set RUNPATH = -Wl,+b,'\$$ORIGIN'/../../lib/$buildarch
   # echo "aimk RUNPATH: #${RUNPATH}#"
   if ($BUILDARCH == HP1164) then
      set RUNPATH = -Wl,+b,'\$$ORIGIN'/../../lib/$buildarch
      echo "aimk RUNPATH: #${RUNPATH}#"
   endif
   breaksw
   
case ALINUX:
case LINUX*:
   set MAKEWINGRIDLIB   = 0
   set MAKEWINGRIDAPP   = 0
   set AUTHLIBS = "-lcrypt -lpam"

   set CFLAGS = "$CFLAGS"

   set COMPILE_DC = 1

   # Optimization on LINUXIA64 is broken, qmon dumps
   if ($OPTIMIZATION == 1 && $BUILDARCH != LINUXIA64) then
      set OFLAG = "-O3"
   else
      set OFLAG = ""
   endif

   set CC  = gcc
   set CXX = g++

   if ($BUILDARCH == LINUXPPC) then
      set CFLAGS = "-m32 $CFLAGS"
      set LFLAGS = "-m32 $LFLAGS"
      set SHARED_LFLAGS = "-m32 $SHARED_LFLAGS"
   else if ($BUILDARCH == LINUXSPARC64 || $BUILDARCH == LINUXPPC64 || $BUILDARCH == LINUXMIPS64) then
      if ($FORCE_32BIT != 1) then
         set CFLAGS = "-m64 $CFLAGS"
         set LFLAGS = "-m64 $LFLAGS"
         set SHARED_LFLAGS = "-m64 $SHARED_LFLAGS"
      endif
   else if ($BUILDARCH == LINUXX64 && $FORCE_32BIT == 1) then
      set CFLAGS = "-m32 $CFLAGS"
      set HWLOC_CFLAGS = "-m32 -O2"
      set LFLAGS = "-m32 $LFLAGS"
      set SHARED_LFLAGS = "-m32 $SHARED_LFLAGS"
   else if ($BUILDARCH == LINUXS390X && $FORCE_32BIT == 1) then
      set CFLAGS = "-m31 $CFLAGS"
      set LFLAGS = "-m31 $LFLAGS"
      set SHARED_LFLAGS = "-m31 $SHARED_LFLAGS"
   endif

   if ($DEBUGGED == 1) then
      set DEBUG_FLAG = "-g $INSURE_FLAG -DSGE_LOCK_DEBUG"
   endif

   if ($GPROFFED == 1) then
      set DEBUG_FLAG = "$DEBUG_FLAG -pg"
   endif

   if ($COVED == 1) then
      set DEBUG_FLAG = "$DEBUG_FLAG -fprofile-arcs -ftest-coverage"
   endif

   if ( -f /lib/libc.so.6 ) then
      strings /lib/libc.so.6 | grep "GNU C Library" | grep '2.[234]' >& /dev/null
      if ($status == 0) then
         set CFLAGS = "-DHAS_IN_PORT_T $CFLAGS"
      endif
   else if ( -f /usr/include/netinet/in.h ) then
      grep typedef /usr/include/netinet/in.h | grep in_port_t >& /dev/null
      if ($status == 0) then
         set CFLAGS = "-DHAS_IN_PORT_T $CFLAGS"
      endif
   endif

   set CFLAGS = "$OFLAG -Wall -Wstrict-prototypes -DUSE_POLL -DLINUX -DLINUX_NATIVE -D$BUILDARCH -D$COMPILE_ARCH -D_GNU_SOURCE -DGETHOSTBYNAME_R6 -DGETHOSTBYADDR_R8 -DHAS_VSNPRINTF $DEBUG_FLAG $CFLAGS"

   if ("$WERR" == 1) then
      set CFLAGS = "$CFLAGS -Wno-strict-aliasing"
      set CFLAGS = "$CFLAGS -Werror"
   endif

   if ("$WEXTRA" == 1) then
      set CFLAGS = "$CFLAGS -Wextra"
   endif

   if ("$STACKPROTECT" == 1) then
      set CFLAGS = "$CFLAGS -fstack-protector-all"
   endif

   if ("$ADOC" == 1) then
      set CFLAGS = "$CFLAGS -Wno-error"
   endif

   if ( $TARGET_BITS == TARGET_32BIT ) then
      set CFLAGS = "$CFLAGS -D_FILE_OFFSET_BITS=64"
   endif

   set LFLAGS   = "$DEBUG_FLAG $LFLAGS"

   set SHAREDLD = $CC
   set SHARED_CFLAGS = "-fPIC"
   set SHARED_LFLAGS = "$SHARED_LFLAGS -L. -shared"

   set SONAME_LFLAG_DRMAA10 = "-Wl,-soname,libdrmaa.so.1.0"
   set SONAME_LFLAG_DRMAA95 = "-Wl,-soname,libdrmaa.so.0.95"

   if ( $SHAREDLIBS == 1 || $SPOOLING_METHOD == dynamic ) then
      set LFLAGS = "$LFLAGS -rdynamic"
   endif

   set NOERR_CFLAG = "-Wno-error"
   set NOERR_PROTO = "-Wno-strict-prototypes"

   if ( $DUMP == 1 ) then
      if ( -f $CORE_HOME/libcore.so ) then
         set LFLAGS   = "$LFLAGS -L$CORE_HOME"
         set CORELIB  = "-lcore"
      else
         echo "error: couldn't find  $CORE_HOME/libcore.so"
         exit 1
      endif
   endif

   set XMTDEF   = ""

   if ($TARGET_BITS == TARGET_32BIT || $BUILDARCH == ALINUX || $BUILDARCH == LINUXIA64) then
      set XLIBD    = "-L/usr/X11R6/lib"
   else
      set XLIBD    = "-L/usr/X11R6/lib64"
   endif

   set XLFLAGS  = "$XLIBD"

   if ( $PLPA == 1 ) then
      # PLPA lib header
      set CFLAGS = "$CFLAGS -DPLPA -DTHREADBINDING"
      if ( ( $BUILDARCH == LINUXX64 || \
         $BUILDARCH == LINUX86 ) && \
         $COMPILE_ARCH != "ULINUX86" && $COMPILE_ARCH != "ULINUXX64" ) then
         set CORE_INCLUDE = "$CORE_INCLUDE -I$SOURCE/3rdparty/plpa/plpa-1.3.1/src/libplpa"
         set LIBS = "$SOURCE/3rdparty/plpa/plpa-1.3.1/$COMPILE_ARCH/src/libplpa/.libs/libplpa.a $LIBS"
      endif 
   endif

   set DEPEND_FLAGS = "$CFLAGS $XMTINCD"

   if ($BUILDARCH != ALINUX) then
      set XINCD    = "$XMTINCD $XINCD -I/usr/X11R6/include"
      set XCFLAGS  = "-Wno-strict-prototypes -Wno-error $XMTDEF $XINCD $XCFLAGS"
      set XLIBS    = "-lXm -lXpm -lXt -lXext -lXmu -lX11 -lSM -lICE -lXp"
   else
      set XINCD    = "$XMTINCD $XINCD"
      set XCFLAGS  = "-DNeedFunctionPrototypes -Wno-error $XMTDEF $XINCD $XCFLAGS"
      set XLIBS    = "-Xlinker -Bstatic -Xlinker -Bdynamic -lXpm -lXt -lXext -lX11 -lSM -lICE -lXp -lXm"
   endif
   set XMLIBS   = "-lXt -lXm -lX11"

   set JAVA_ARCH = "linux"

   # due to -rpath relative_path the LD_LIBRARY_PATH not needed anymore
   set RUNPATH       = -Wl,-rpath,'\$$ORIGIN'/../../lib/$buildarch
   set LFLAGS        = "$LFLAGS $RUNPATH"
   set SHARED_LFLAGS = "$SHARED_LFLAGS $RUNPATH"

   if ( $COMPILE_ARCH == "ULINUX86" || $COMPILE_ARCH == "ULINUXX64" ) then
      echo "Ignore jemalloc for unsupported architectures!"
      set MAKEJEMALLOCLIB = 0
      set LINKJEMALLOCLIB = 0
   endif

   if ( $MAKEJEMALLOCLIB == 1 ) then
      set JEMALLOC_CFLAGS  = "-Wno-error -DMOZ_MEMORY_LINUX"
   endif

   if ( $LINKJEMALLOCLIB == 1) then
      set LIBRARY_LIBS = "$LIBS"
      set LIBS = "-ljemalloc $LIBS"
   endif

   breaksw

case CYGWIN_X86:
   set MAKEWINGRIDLIB   = 0
   set MAKEWINGRIDAPP   = 0
   set AUTHLIBS = "-lcrypt -lpam"

   set COMPILE_DC = 1

   if ($OPTIMIZATION == 1 ) then
      set OFLAG = "-O2"
   else
      set OFLAG = ""
   endif

   set HWLOC      = 0
   set MAKEHWLOC  = 0

   set CC  = gcc
   set CXX = g++

   if ($DEBUGGED == 1) then
      set DEBUG_FLAG = "-g $INSURE_FLAG -DSGE_LOCK_DEBUG"
   endif

   if ($GPROFFED == 1) then
      set DEBUG_FLAG = "$DEBUG_FLAG -pg"
   endif

   if ($COVED == 1) then
      set DEBUG_FLAG = "$DEBUG_FLAG -fprofile-arcs -ftest-coverage"
   endif

   set CFLAGS = "$CFLAGS -Wno-strict-aliasing"

   set CFLAGS = "$OFLAG -Wall -Wstrict-prototypes -DUSE_POLL -DLINUX -DOGLIBC_LINUX -DCYGWIN -D$BUILDARCH -D$COMPILE_ARCH -D_GNU_SOURCE -DGETHOSTBYNAME -DGETHOSTBYADDR -DHAS_VSNPRINTF $DEBUG_FLAG $CFLAGS"

   if ("$WERR" == 1) then
      set CFLAGS = "$CFLAGS -Werror"
   endif

   if ("$WEXTRA" == 1) then
      set CFLAGS = "$CFLAGS -Wextra"
   endif

   if ("$STACKPROTECT" == 1) then
      set CFLAGS = "$CFLAGS -fstack-protector-all"
   endif

   if ("$ADOC" == 1) then
      set CFLAGS = "$CFLAGS -Wno-error"
   endif

   if ( $TARGET_BITS == TARGET_32BIT ) then
      set CFLAGS = "$CFLAGS -D_FILE_OFFSET_BITS=64"
   endif

   set LFLAGS   = "$DEBUG_FLAG $LFLAGS"

   set SHAREDLD = $CC
   set SHARED_LFLAGS = "$SHARED_LFLAGS -L. -shared"

   set SONAME_LFLAG_DRMAA10 = "-Wl,-soname,libdrmaa.so.1.0"
   set SONAME_LFLAG_DRMAA95 = "-Wl,-soname,libdrmaa.so.0.95"

   set SHAREDEXT = ".dll"

   if ( $SHAREDLIBS == 1 || $SPOOLING_METHOD == dynamic ) then
      set LFLAGS = "$LFLAGS -rdynamic"
   endif

   set NOERR_CFLAG = "-Wno-error"
   set NOERR_PROTO = "-Wno-strict-prototypes"

   set XMTDEF   = ""

   if ($TARGET_BITS == TARGET_32BIT ) then
      set XLIBD    = "-L/usr/X11R6/lib"
   else
      set XLIBD    = "-L/usr/X11R6/lib64"
   endif

   set XLFLAGS  = "$XLIBD"

   set DEPEND_FLAGS = "$CFLAGS $XMTINCD"

   set XINCD    = "$XMTINCD $XINCD -I/usr/X11R6/include"
   set XCFLAGS  = "-Wno-strict-prototypes -Wno-error $XMTDEF $XINCD $XCFLAGS"
   set XLIBS    = "-lXm -lXpm -lXt -lXext -lXmu -lX11 -lSM -lICE -lXp"
   set XMLIBS   = "$XLIBS"

   set JAVA_ARCH = "linux"

   # due to -rpath relative_path the LD_LIBRARY_PATH not needed anymore
   set RUNPATH       = -Wl,-rpath,'\$$ORIGIN'/../../lib/$buildarch
   set LFLAGS        = "$LFLAGS $RUNPATH"
   set SHARED_LFLAGS = "$SHARED_LFLAGS $RUNPATH"

   breaksw

case WIN32_X86:
   setenv LD_LIBRARY_PATH /usr/lib/x86:/usr/local/lib
   set CC = gcc
   set WINCC = "env TMP=$WINTEMPDIR cl.exe"
   set RM = "rm -f"
   set MAKE = gmake

   # Default build targets for WIN32_X86 for which we have seperate make files
   set MAKEWINGRIDLIB   = 1
   set MAKEWINGRIDAPP   = 1
   set QMON             = 0
   set MAKESTRPTIME     = 0
   set MAKEFNMATCH      = 0
   set WITH_USERMAPPING = 0 # Compile without usermapping feature
   set COMPILE_DC       = 1
   set HWLOC            = 0
   set MAKEHWLOC        = 0
   set AUTHLIBS         = ""
   set JUTI_ALL         = ""
   set JUTI_DEPEND      = ""
   set JUTI_CLEAN       = ""
   set AUTHUSER_ALL     = authuser.exe
   set LOADCHECK_ALL    = loadcheck.exe
   set AUTHUSER_OBJ     = authuser.obj
   set LOADCHECK_OBJ    = loadcheck.obj
   set JUTI_OBJ         = juti.obj
   
   set CORE_INCLUDE     = "$CORE_INCLUDE -I../libs/wingrid"
   # libwingrid.a needs libdl for dlopen() etc.
   set WINGRIDLIB       = "-lwingrid -ldl"
   set WINGRIDLIB_DEP   = "libwingrid.a"
   set WINGRIDLIB_A     = "-lwingrid_static -ldl"
   set WINGRIDLIB_A_DEP = "libwingrid_static.a"

   if ($OPTIMIZATION == 1) then
      set OFLAG = "-O3"
   else
      set OFLAG = ""
   endif

   if ($CC == gcc) then
      set CC  = gcc
      set CXX = gcc
      set CFLAGS = "$DEBUG_FLAG $CFLAGS"
      set CFLAGS = "-DGETHOSTBYADDR_M -D_ALL_SOURCE -D_REENTRANT $CFLAGS"
      if (`uname -r` == "3.5") then
         set CFLAGS = "-DINTERIX $CFLAGS"
      else
         set CFLAGS = "-DINTERIX -DINTERIX52 $CFLAGS"
      endif
      set CFLAGS = "-D$COMPILE_ARCH -DGETHOSTBYNAME_M -DUSE_SGE_UNSETENV $CFLAGS" 
      set CFLAGS = "-Wall -O0 -pipe $CFLAGS -rpath /usr/lib/x86"
      #set LFLAGS = "-Wl,-EL,-b=pe-i1386 $LFLAGS"

      if ("$WERR" == 1) then
        set CFLAGS = "$CFLAGS -Werror"
      endif

      if ("$WEXTRA" == 1) then
        set CFLAGS = "$CFLAGS -Wextra"
      endif
   else
      set CC  = cc
      set CXX = cc
      set CFLAGS = "-X /Wall -X /WX $OFLAG -DINTERIX -D$COMPILE_ARCH -DUSE_SGE_UNSETENV $CFLAGS"
      set CFLAGS = "$DEBUG_FLAG $CFLAGS"
   endif

   if ($DEBUGGED == 1) then
      set DEBUG_FLAG = "-g $INSURE_FLAG -DSGE_LOCK_DEBUG"
      set OFLAG = ""
   endif

   if ($GPROFFED == 1) then
      set DEBUG_FLAG = "$DEBUG_FLAG -pg"
   endif

   if ( -f /lib/libc.so.6 ) then
      strings /lib/libc.so.6 | grep "GNU C Library" | grep '2.[234]' >& /dev/null
      if ($status == 0) then
         set CFLAGS = "-DHAS_IN_PORT_T $CFLAGS"
      endif
   endif

   set LFLAGS        = "$DEBUG_FLAG $LFLAGS -L$SOURCE/$COMPILE_ARCH"

   set SHAREDLD      = $CC
   set SHARED_LFLAGS = "-L. -shared"

   set NOERR_CFLAG  = "-Wno-error"
   set NOERR_PROTO  = "-Wno-strict-prototypes"
   
   set XMTDEF       = ""
   set XLIBD        = "-L/usr/X11R6/lib64"
   set XLFLAGS      = "$XLIBD"
   set DEPEND_FLAGS = "$CFLAGS $XMTINCD"
   set XINCD        = "$XMTINCD $XINCD -I/usr/X11R6/include -I/usr/local/include/bind"
   set XCFLAGS      = "-Wno-strict-prototypes -Wno-error $XMTDEF $XINCD $XCFLAGS"
   set XLIBS        = "-lXm -lXpm -lXt -lXext -lXmu -lX11 -lSM -lICE -lXp"
   set XMLIBS       = "$XLIBS"

   if ( $DEBUGGED == 1 ) then
      set WINCFLAGS = "/Od /D "WIN32" /D "_DEBUG" /MTd /Zi"
   else
      set WINCFLAGS = "/MT"
   endif
   set WINCFLAGS = "${WINCFLAGS} /D "WINDOWS" /D "_CONSOLE""
   set WINCFLAGS = "${WINCFLAGS} /D "_CRT_SECURE_NO_WARNINGS" /W3 /WX"
   set WINCFLAGS = "${WINCFLAGS} /nologo /c /EHsc"
   set WINCFLAGS = "${WINCFLAGS} -I'${WIN32_VS_I1}'"
   set WINCFLAGS = "${WINCFLAGS} -I'${WIN32_VS_I2}'"
   set WINCFLAGS = "${WINCFLAGS} -I'${WIN32_VS_I3}'"
   set WINCFLAGS = "${WINCFLAGS} -I'..\\common'"
   set WINCFLAGS = "${WINCFLAGS} -I'..\\utilbin'"
   set WINCFLAGS = "${WINCFLAGS} -I'..\\libs\\juti'"

   if ( $DEBUGGED == 1 ) then
      set WINLFLAGS = "/DEBUG"
   else
      set WINLFLAGS = ""
   endif 
   set WINLFLAGS = "${WINLFLAGS} /INCREMENTAL:NO /NOLOGO"
   set WINLFLAGS = "${WINLFLAGS} /MACHINE:X86"
   set WINLFLAGS = "${WINLFLAGS} /LIBPATH:'${WIN32_VS_L1}'"
   set WINLFLAGS = "${WINLFLAGS} /LIBPATH:'${WIN32_VS_L2}'"
   set WINLFLAGS = "${WINLFLAGS} /LIBPATH:'${WIN32_VS_L3}'"

   set WINLIBS = "pdh.lib ws2_32.lib advapi32.lib user32.lib"
   breaksw
   
case NECSX4:
   set MAKEWINGRIDLIB   = 0
   set MAKEWINGRIDAPP   = 0
#
# we need the '-hfloat0'-flag for CFLAGS and LFLAGS because the
# XDR-Libraray does not work properly for other floating point models
# float1 => (floating poit exceptions for value DBL_MAX during unpacking
# double values)
#
   set INTERACTTARGETS = ""
   set COMPILE_DC = 1

   set HWLOC      = 0
   set MAKEHWLOC  = 0

   set MAKE = make
   set CFLAGS = "-DNECSX4 -DGETHOSTBYNAME_M -DGETHOSTBYADDR_M -dir,novec,nopar,nopthr -hfloat0 $DEBUG_FLAG $CFLAGS"
   set DEPEND_FLAGS = "$CFLAGS $XMTINCD"
   set LFLAGS   = "-hfloat0 $DEBUG_FLAG $LFLAGS"
   set LIBS     = "$LIBS"
   set XMTDEF   = ""
   set XINCD    = ""
   set XCFLAGS  = "$XMTDEF $XINCD $XCFLAGS"
   set XLFLAGS  = ""
   if ( $SHAREDLIBS == 1 ) then
      echo creating shared libs not yet supported on $BUILDARCH
      exit 1
   endif
   set JAVA_ARCH = ""
   breaksw

case NECSX5:
   set MAKEWINGRIDLIB   = 0
   set MAKEWINGRIDAPP   = 0
   set INTERACTTARGETS = ""
   set COMPILE_DC = 1

   set HWLOC      = 0
   set MAKEHWLOC  = 0

   if ( $CORE == 1 ) then
      set MAKESTRPTIME = 1
      set MAKEFNMATCH = 1
   endif
   if ( $QTCSH == 1 ) then
      set MAKEFNMATCH = 1
   endif
   set MAKE = make
   set OFLAG = "-h1"
   set CFLAGS_NOOPT = "-DNECSX5 -DGETHOSTBYNAME_M -DGETHOSTBYADDR_M -D_REENTRANT -dir,novec,nopar,nopthr -hfloat0 $DEBUG_FLAG $CFLAGS"
   set CFLAGS = "$CFLAGS_NOOPT $OFLAG"
   set DEPEND_FLAGS = "$CFLAGS $XMTINCD"
   set LFLAGS   = "$DEBUG_FLAG $LFLAGS"
   set XMTDEF   = ""
   set XINCD    = ""
   set XCFLAGS  = "$XMTDEF $XINCD $XCFLAGS"
   set XLFLAGS  = ""
   if ( $SHAREDLIBS == 1 ) then
      echo creating shared libs not yet supported on $BUILDARCH
      exit 1
   endif
   set DLLIB = ""
   set JAVA_ARCH = ""
   breaksw

case SOLARIS:
case SOLARIS64:
case SOLARIS86:
case SOLARISAMD64:
   set MAKEWINGRIDLIB   = 0
   set MAKEWINGRIDAPP   = 0
   set COMPILE_DC = 1

   set ERR_WARN_NONE = "-errwarn=%none" # is set in XCFLAGS and for R_E_M_O_T_E target to switch off -errwarn=%all
   set NOERR_CFLAG   = "-errwarn=%none"
   set ERR_WARN_ALL = "-errwarn=%all"  # is set in cc specific section below
   set CFLAGS = "$CFLAGS -DSOLARIS -D$BUILDARCH -D__EXTENSIONS__ -D_POSIX_C_SOURCE=199506L -DGETHOSTBYNAME_R5 -DGETHOSTBYADDR_R7 -DUSE_POLL"
   set SHAREDLD = $CC

   if ($OPTIMIZATION == 1) then 
      if ( $CC == gcc ) then
         set OFLAG = "-O3"
      else
         if ( $BUILDARCH == SOLARIS86 ) then
            # Do not compile Grid Engine with -xO4 on SOLARIS86 platform
            # unless WS8 compiler with patch 112756-01 or higher is installed

            set compversion = `cc -V |& head -1 | cut -f4 -d" "`
            set patchcnt = `/bin/sh -c 'ls -d /var/sadm/patch/112756-* 2> /dev/null' | wc -l`
            set haspatch = `expr $patchcnt ">=" 1`
     #       set haspatch = 0
            if ( $compversion == 5.5 && $haspatch == 1 || $compversion != 5.5 ) then
               # set OFLAG = "-fast -xchip=pentium -xcache=generic"
               #
               # Due to compiler bugs in the X86 compiler
               #
               #   cc: Sun C 5.5 Patch 112761-13 2005/06/14
               #   cc: Sun C 5.8 Patch 121016-06 2007/08/01
               #
               # the -fast and -xchip switches make no sense. They cause SEGV when threads are
               # shut down. Following line will overwite the switches set above. It can be removed
               # as soon as there is a patch available for the compiler 
               #
               set OFLAG = "-xO3"
            else
               echo using \"-xO3\" optimization due to compiler bug
               set OFLAG = "-xO3"
     #          set OFLAG = "-xO3 -fns -fsimple=2 -fsingle -ftrap=%none -nofstore -xbuiltin=%all -xdepend -xlibmil"
            endif
         else
	         set OFLAG = "-fast -xchip=generic -xcache=generic"
         endif
      endif
   else
       set OFLAG = ""
   endif

   if ( $DEBUGGED == 1 ) then
      set DEBUG_FLAG = "-g $INSURE_FLAG -DSGE_LOCK_DEBUG"
   endif

   if ( $GPROFFED == 1 ) then
      if ( $CC == gcc ) then
         set DEBUG_FLAG = "-g -pg"
         set LIBS = "$LIBS -ldl"
      else
         set DEBUG_FLAG = "-g -xpg"
      endif
   endif

   if ($COVED == 1) then
      set OFLAG = ""
      if ( $CC == gcc ) then
         set DEBUG_FLAG = "$DEBUG_FLAG -fprofile-arcs -ftest-coverage"
      else
         set DEBUG_FLAG = "$DEBUG_FLAG -xprofile=tcov"
         set SHARED_LFLAGS = "$SHARED_LFLAGS -xprofile=tcov"
      endif
   endif

#   Check if this works on solaris 32 bit
#   if ( $TARGET_BITS == TARGET_32BIT ) then
#      set CFLAGS = "-DFD_SETSIZE=8192 $CFLAGS"
#   endif

   # INFO: rel is also used later ...
   set rel = `uname -r | cut -f 2 -d .`
   if ( $rel > 6 ) then
      set CFLAGS = "-DHAS_SOCKLEN_T $CFLAGS"
   endif

   if ( $rel < 10 ) then
      set CFLAGS = "-DUSE_SGE_UNSETENV $CFLAGS"
   endif

   set DEPEND_FLAGS = "$CFLAGS -D$BUILDARCH $XMTINCD"
   set MEMCFLAG = "-Xa"

   if ( $CC == cc ) then
      set LFLAGS = "-xildoff $LFLAGS"
      # the ERR_WARN_ALL breaks insure instrumented builds
      if ( $USE_INSURE == 0 ) then
         set CFLAGS = "$CFLAGS $ERR_WARN_ALL"
      endif
      set SHARED_CFLAGS = "-KPIC"

      if ( $BUILDARCH == SOLARIS64 ) then
         set MEMFLAG = "-xarch=v9"
         set LFLAGS = "-xarch=v9 $LFLAGS"
         set SHARED_LFLAGS = "$SHARED_LFLAGS -L. -G -xarch=v9"
      else if ( $BUILDARCH == SOLARISAMD64 ) then
         set CFLAGS = "-D_LARGEFILE64_SOURCE=1 $CFLAGS"
         
         set compversion = `cc -V | & head -1 | sed 's/[a-zA-Z :]*\([0-9].[0-9]*\).*$/\1/'`
         set major = `echo $compversion | cut -f1 -d"."`
         set minor = `echo $compversion | cut -f2 -d"."`
         if ($major <= 5 && $minor <= 8) then
            set MEMFLAG = "-xarch=amd64"
            set LFLAGS = "-xarch=amd64 $LFLAGS"
            set SHARED_LFLAGS = "$SHARED_LFLAGS -L. -G -xarch=amd64"
         else
            set MEMFLAG = "-xarch=sse2 -m64"
            set LFLAGS = "-xarch=sse2 -m64 $LFLAGS"
            set SHARED_LFLAGS = "$SHARED_LFLAGS -L. -G -xarch=sse2 -m64"
            set NO_XDEPEND = "-xdepend=no"
         endif
      else
         set CFLAGS = "-D_LARGEFILE64_SOURCE=1 $CFLAGS"
         set MEMFLAG = "-xarch=generic"
         set SHARED_LFLAGS = "$SHARED_LFLAGS -L. -G"
      endif
      set CFLAGS = "-Xc -v $OFLAG $MEMFLAG -ftrap=division $CFLAGS $DEBUG_FLAG"
   else if ( $CC == gcc) then
      set CFLAGS = "-Wall -Wstrict-prototypes $CFLAGS"
      set SHARED_CFLAGS = "-fPIC"
      set SHARED_LFLAGS = "$SHARED_LFLAGS -L. -shared"

      if ("$WERR" == 1) then
        set CFLAGS = "$CFLAGS -Werror"
      endif

      if ("$WEXTRA" == 1) then
        set CFLAGS = "$CFLAGS -Wextra"
      endif

      if ( $BUILDARCH == SOLARIS64 ) then
         set CFLAGS = "-m64 $CFLAGS"
         set MEMFLAG = "-m64"
         set LFLAGS = "-m64 $LFLAGS"
         set SHARED_LFLAGS = "$SHARED_LFLAGS -L. -G -m64"
      else if ( $BUILDARCH == SOLARISAMD64 ) then
         set CFLAGS = "-m64 $CFLAGS"
         set MEMFLAG = "-m64"
         set LFLAGS = "-m64 $LFLAGS"
         set SHARED_LFLAGS = "$SHARED_LFLAGS -L. -G -m64"
      else
         set SHARED_LFLAGS = "$SHARED_LFLAGS -L. -G"
         set MEMFLAG = ""
      endif
   endif

   set HWLOC_CFLAGS = "$OFLAG $MEMFLAG"

   if ( $SOLARISPSET == 1 ) then
      set CFLAGS = "$CFLAGS -DSOLARISPSET"
   endif


   # This is workaround for not POSIX fork() behaviour of -lthread
   # library. The man page of fork() tells following:
   # ...
   # Note that if a program is  linked  with  both  libraries
   # (-lthread  and  -lpthread),  the POSIX semantic of fork() pre-
   # vails.
   # 
   # TODO: use -lpthread only when jmx thread supports it!
   #       
   if ( $rel < 10 ) then
      # Solaris version < 10 needs -lpthread
      set LIBS     = "-lsocket -lnsl -lm -lpthread -lthread -lkstat" 
   else
      # Solaris versions >= 10 have posix fork()
      set LIBS     = "-lsocket -lnsl -lm -lthread -llgrp -lkstat"
   endif
   set QMAKELIB    = "-lnsl"
   set LOADAVGLIBS = "-lkstat"
   set FSTYPELIBS = "-lkstat"

   if ( $CC != gcc ) then
      set SONAME_LFLAG_DRMAA10 = "-h libdrmaa.so.1.0"
      set SONAME_LFLAG_DRMAA95 = "-h libdrmaa.so.0.95"
   endif

   set XMTDEF   = "-DXMT_CDE_BUG_FIX"

   set XINCD    = "-I/usr/dt/include -I/usr/openwin/include $XMTINCD $XINCD"
   set XLIBD    = "-L/usr/dt/lib -L/usr/openwin/lib"

   set XCFLAGS  = "$ERR_WARN_NONE -DNeedFunctionPrototypes -DNeedVarargsPrototypes $XMTDEF $XINCD $XCFLAGS"

   # workaround for opensolaris
   if ( `uname -r` == 5.11 && ( $BUILDARCH == SOLARISAMD64 )) then
       set XLIBD = "-L/usr/openwin/lib/64"
   endif    
   
   set XLFLAGS  = "$XLIBD"
   set XLIBS    = "-lXm -lXt -lXext -lXmu -lX11 -lw -lgen"
   set XMLIBS   = "$XLIBS"

   set RANLIB   = "echo"
   set JAVA_ARCH = "solaris"

   # due to -R relative_path the LD_LIBRARY_PATH not needed anymore
   set RUNPATH       = "-R "'\$$ORIGIN'/../../lib/$buildarch
   set LFLAGS        = "$LFLAGS $RUNPATH"
   set SHARED_LFLAGS = "$SHARED_LFLAGS $RUNPATH"

#   if ( $BUILDARCH == "SOLARISAMD64" ) then
#      set MAKEJEMALLOCLIB = 1
#   endif

   set LFLAGS   = "$LFLAGS $DEBUG_FLAG"
   set LIBRARY_LIBS = "$LIBS"

   if ( $MAKEJEMALLOCLIB == 1 ) then
      set JEMALLOC_CFLAGS  = "-DMOZ_MEMORY_SOLARIS -xc99"
   endif

   if ( $LINKJEMALLOCLIB == 1 ) then
      set LIBS = "-ljemalloc $LIBS"
   else
      if ( $LINKMTMALLOCLIB == 1 ) then
         set LIBS = "-lmtmalloc $LIBS"
      endif
   endif

   breaksw

case UNICOS*:
   set MAKEWINGRIDLIB   = 0
   set MAKEWINGRIDAPP   = 0
   set INTERACTTARGETS = ""

   set HWLOC      = 0
   set MAKEHWLOC  = 0

   set MAKE = gmake
   set ARFLAGS = rcv
   switch ($BUILDARCH)
      case UNICOS_TS:
         set CFLAGS   = "-DCRAY -DCRAYTS -DGETHOSTBYNAME_M $DEBUG_FLAG $CFLAGS"
         breaksw
      case UNICOS_TS_IEEE:
         set CFLAGS   = "-DCRAY -DCRAYTS -DCRAYTSIEEE -DGETHOSTBYNAME_M -DGETHOSTBYADDR_M $DEBUG_FLAG $CFLAGS"
         breaksw
      default:
         set CFLAGS   = "-DCRAY -DGETHOSTBYNAME_M $DEBUG_FLAG $CFLAGS"
   endsw
   set DEPEND_FLAGS = "$CFLAGS $XMTINCD"
   set LFLAGS   = ""
   set XMTDEF   = ""
   switch (`/bin/uname -r`)
      case "[0-8].*":
      case "9.[01]*":
         set XINCD    = "-I/usr/src/net/cvt/motif/lib $XMTINCD $XINCD"
         set XLIBD    = "-L/usr/src/net/cvt/motif/lib/Xm"
         set XLIBS    = "-lXm -lXt -lXext -lX11"
         breaksw
      default:
         set XINCD    = "$XMTINCD $XINCD"
         set XLIBD    = ""
         set XLIBS    = "-lXm -lXt -lXext -lX11 -lSM -lICE"
         breaksw
   endsw
   set XMLIBS   = "$XLIBS"
   set XCFLAGS  = "$XMTDEF $XINCD $XCFLAGS"
   set XLFLAGS  = "$XLIBD"
   set COMPILE_DC = 1
   if ( $SHAREDLIBS == 1 ) then
      echo creating shared libs not yet supported on $BUILDARCH
      exit 1
   endif
   set JAVA_ARCH = ""
   breaksw

default:
   set MAKEWINGRIDLIB   = 0
   set MAKEWINGRIDAPP   = 0
   echo "ERROR: Architecture $BUILDARCH not supported by aimk"
   exit 1
endsw

set DEPEND_FLAGS = "`echo $DEPEND_FLAGS | sed -e 's/-[^DI][^ ]*//g'`"

# we set SGE_ARCH_STRING down here because the sed command above
# would mess up the quotes around buildarch
set ARCH_STRING  = SGE_ARCH_STRING='\"'${buildarch}'\"'
set CFLAGS       = "-D$ARCH_STRING $CFLAGS"
set DEPEND_FLAGS = "-D$ARCH_STRING $DEPEND_FLAGS"

#---------------------------------------------------------------------------
if ( $JAVA > 0 || $BUILDJAVADOC == 1 || $JNI == 1 ) then

   # Make sure we can find JAVA_HOME
   if ( ${?JAVA_HOME} == 0 ) then
      echo "Please set JAVA_HOME or disable Java & JGDI support"
      echo "with aimk flags: -no-java -no-jni"
      exit 1
   endif

   if ( ${JAVA_HOME} == "/usr" ) then
      echo 'WARNING:'
      echo 'Setting $JAVA_HOME to "/usr" causes problems on some systems, '
      echo 'because the associated include path will be "/usr/include", '
      echo 'which is a reserved system include path.'
      echo
      echo 'Please either set $JAVA_HOME correctly or disable Java & JGDI support'
      echo 'with aimk flags: -no-java -no-jni'
      echo
      echo 'Contining without Java & JGDI support'
      echo

      if ( ${?JAVA_HOME_SET_BY_SGE} ) then
         unsetenv JAVA_HOME
      endif

      set JNI = 0
      set JAVA = 0
   endif
endif

if ( $JNI == 1 ) then

   set JAVA_INCL_DIR = "${JAVA_HOME}/${JAVA_INCL}"

   if ( ! -d "$JAVA_INCL_DIR" ) then
      echo 'WARNING:'
      echo 'Java include directory not found.'
      echo
      echo 'Please either set $JAVA_HOME correctly or disable Java & JGDI support'
      echo 'with aimk flags: -no-java -no-jni'
      exit 1
   else
      set CORE_INCLUDE = "$CORE_INCLUDE -I${JAVA_INCL_DIR}"
   endif

   if ("$JAVA_ARCH" != "") then
      set CORE_INCLUDE = "$CORE_INCLUDE -I${JAVA_INCL_DIR}/${JAVA_ARCH}"
      switch ($buildarch)
         case linux-x86:
         case nbsd-i386:
         case sol-x86:
         case usol-x86:
             set JAVA_LIB_ARCH = i386
             breaksw
         case sol-sparc64:
         case usol-sparc64:
             set JAVA_LIB_ARCH = sparcv9
             breaksw
         case linux-sparc:
         case sol-sparc:
         case usol-sparc:
             set JAVA_LIB_ARCH = sparc
             breaksw
         case linux-x64:
         case sol-amd64:
             if ($FORCE_32BIT == 1) then
                set JAVA_LIB_ARCH = i386
             else
                set JAVA_LIB_ARCH = amd64
             endif
             breaksw
         case linux-ia64:
             set JAVA_LIB_ARCH = ia64
             breaksw
         case linux-ppc:
             set JAVA_LIB_ARCH = ppc
             breaksw
         case linux-ppc64:
             set JAVA_LIB_ARCH = ppc64
             breaksw
         case hp11:
             set JAVA_LIB_ARCH = PA_RISC
             breaksw
         case hp11-64:
             set JAVA_LIB_ARCH = PA_RISC2.0W
             breaksw
         case fbsd-i386:
             set JAVA_LIB_ARCH = linux 
             breaksw
         case irix65:
             set JAVA_LIB_ARCH = "" 
             breaksw
         case darwin-*:
             set JAVA_LIB_ARCH = "" 
             breaksw
         case tru64:
             set JAVA_LIB_ARCH = "" 
             breaksw
         case aix:
             set JAVA_LIB_ARCH = "" 
             breaksw
         default:
             set JAVA_LIB_ARCH = ""
             echo "WARNING: no JAVA_LIB_ARCH for architecture $buildarch"
      endsw
      if ( "$JAVA_LIB_ARCH" != "") then
        set JAVA_LFLAGS="-L$JAVA_HOME/jre/lib/$JAVA_LIB_ARCH/server"
      else
        set JAVA_LFLAGS=""
      endif
   endif
   #
   # special treatment
   #
   if ( $buildarch == aix ) then
     set JAVA_LFLAGS="-L$JAVA_HOME/jre/bin/classic"
   else if ( $buildarch == darwin-x86 || $buildarch == darwin-x64 || $buildarch == darwin-ppc ) then
     set JAVA_LFLAGS="-L$JAVA_HOME/../Libraries"
   else if ( $buildarch == irix65 ) then
     set JAVA_LFLAGS="-L$JAVA_HOME/jre/lib32/mips"
   else if ( $buildarch == tru64 ) then
     set JAVA_LFLAGS="-L$JAVA_HOME/jre/lib/alpha/classic"
   endif  

else
   set JNI_TARGET = "NJ"
   set CFLAGS = "$CFLAGS -DNO_JNI"
endif

if ($JAVA_SHAREDEXT == "") then
   set JAVA_SHAREDEXT = "$SHAREDEXT"
endif

set MAKEOPT = "$MAKEOPT $PARALLEL"

# pass -DCOMPILE_DC define to compile where PTF and PDC are ported
#
if ( $COMPILE_DC == 1 ) then
   set CFLAGS = "$CFLAGS -DCOMPILE_DC"
endif

# create only shared libraries if requested - this is not yet the default
#
if ( $SHAREDLIBS == 1 ) then
   set LIBEXT = "$SHAREDEXT"
else
   set LIBEXT = ".a"
endif

# settings for spooling libraries - shared vs. static
# if we use the dynamic spooling, we need shared spooling libs
if ( $SPOOLING_METHOD == "dynamic" ) then
   set SPOOLLIBEXT = "$SHAREDEXT"
else
   set SPOOLLIBEXT = $LIBEXT
endif

# for gettext
#
if ( $WITH_GETTEXT == 1 ) then
   set   XGETTEXT    = "$GETTEXTBASE/$BUILDARCH/bin/xgettext --strict --foreign-user -k -k'sge_gettext' --language=C -j -o $MESSAGES"
   if ( "$?MYILIB" ) then
      set LFLAGS = "-L $MYILIB"
      echo "Using $MYILIB path for i18n support"
   else
      if ( $BUILDARCH == "SOLARIS" || $BUILDARCH == "SOLARIS64" || $BUILDARCH == "SOLARIS86" || $BUILDARCH == "SOLARISAMD64" || $BUILDARCH == "LINUX86" || $BUILDARCH == "LINUXIA64" || $BUILDARCH == "LINUXX64" || $BUILDARCH == "LINUXARM" || $BUILDARCH == "LINUXARM64" || $BUILDARCH == "LINUXPPC" || $BUILDARCH == "LINUXPPC64" || $BUILDARCH == "LINUXMIPS" || $BUILDARCH == "LINUXMIPS64" || $BUILDARCH == "LINUXSPARC" || $BUILDARCH == "LINUXSPARC64" || $BUILDARCH == "LINUXS390" || $BUILDARCH == "LINUXS390X" ) then
         set LIBINTL = ""
         set HFLAGS = ""
      else
         set HFLAGS = "-I$GETTEXTBASE/$BUILDARCH/include"
         set LFLAGS = "-L$GETTEXTBASE/$BUILDARCH/lib $LFLAGS"
         set LIBINTL = "-lintl -lnlsut"
      endif
   endif
   set LIBS = "$LIBINTL $LIBS"
   set CFLAGS = "$CFLAGS -D__SGE_COMPILE_WITH_GETTEXT__ $HFLAGS"
else
   set XGETTEXT = ""
endif

# for usermapping
#
if ( $WITH_USERMAPPING == 0 ) then
   set CFLAGS = "$CFLAGS -D__SGE_NO_USERMAPPING__"
endif

if ( $HWLOC == 1 ) then
   set CFLAGS = "$CFLAGS -DTHREADBINDING -DHWLOC"

   if ( $MAKEHWLOC == 1 ) then
      set CORE_INCLUDE = "$CORE_INCLUDE -I$SOURCE/3rdparty/hwloc/$HWLOC_DIRECTORY/include/ -I$SOURCE/3rdparty/hwloc/$HWLOC_DIRECTORY/$COMPILE_ARCH/include"
      set LIBS = "-L$SOURCE/3rdparty/hwloc/$HWLOC_DIRECTORY/$COMPILE_ARCH/src/.libs/ -lhwloc $LIBS"
   else
      set LIBS = "-lhwloc $LIBS"
   endif
endif



# create shared lib from LGPL code  - use $SHAREDEXT for shared lib extension
#
set GSHARED_CFLAGS = "$SHARED_CFLAGS"
set GSHARED_LFLAGS = "$SHARED_LFLAGS"

# change CC / CXX for insure
if ($USE_INSURE == 1) then
   set CC  = "insure $CC"
   set CXX = "insure $CXX"
endif

if ("$LIBRARY_LIBS" == "") then
   set LIBRARY_LIBS = "$LIBS" 
endif


#---------------------------------------------------------------------------
# Actual make targets begin here
#
echo "Building in directory: `pwd`"
if ("$COMPILE_DIR" == "") then
   echo making in $COMPILE_ARCH/ for $BUILDARCH at host `hostname`
else
   echo making in $COMPILE_DIR/ for $BUILDARCH at host `hostname`
endif

# -only-gui-inst option
if ( "$JAVA_GUI_INST" == 2 ) then
   echo _____Making JAVA GUI Installer_____

   if ( "$ADD_COPYRIGHT" == 1 ) then
      setenv AIMK_COPYRIGHT_DIR "$COPYRIGHT_DIR"
      setenv AIMK_COPYRIGHT "courtesy"
   else if ( "$ADD_SUN_COPYRIGHT" == 1 ) then
      setenv AIMK_COPYRIGHT_DIR "$SUN_COPYRIGHT_DIR"
      setenv AIMK_COPYRIGHT "sun"
   else
      setenv AIMK_COPYRIGHT_DIR ""
      setenv AIMK_COPYRIGHT ""
   endif
   ant -f clients/gui-installer/build.xml $argv

   if ( $status != 0 ) then
      echo not done
      exit 1
   endif
   echo done
   exit 0
endif

if ( "$BUILDMAN" == 1 ) then
   echo _________M_A_N_P_A_G_E_S__________________

   if ( $?MAN2HTMLPATH ) then
      setenv PATH ${PATH}:${MAN2HTMLPATH}
   endif   
   if ( $?GROFFPATH ) then
      setenv PATH ${PATH}:${GROFFPATH}
   else
      echo "groff must exist"
      echo not done
      exit 1
   endif   

   $SOURCE/scripts/mk_ascman $SOURCE $SGE_PRODUCT_MODE $BUILDMAN $BUILDHTMLMAN $KVMAN

   if ( $status != 0 ) then
      echo not done
      exit 1
   else
      echo done
      exit 0
   endif
endif

if ( "$BUILDCATMAN" == 1 ) then
   echo _________C_A_T_P_A_G_E_S__________________

   $SOURCE/scripts/mk_catman $SOURCE $SGE_PRODUCT_MODE

   if ( $status != 0 ) then
      echo not done
      exit 1
   else
      echo done
      exit 0
   endif

endif

if ( "$BUILDGETTEXT" == 1 ) then
   echo _________G_E_T_T_E_X_T____________________

   cd $SOURCE/3rdparty/gettext
   $SOURCE/scripts/install.gridware $COMPILE_ARCH
   if ( $status != 0 ) then
      echo not done
      exit 1
   else
      cd $SOURCE
      echo done
      exit 0
   endif

endif   

if ( "$BUILDJAVADOC" == 1 ) then
   echo _______J_A_V_A_D_O_C_S__________

   set target = "javadoc"

   if ( "$PROTECTED" == 1 ) then
      set target = "${target}.all"
   endif

   ant -f build.xml $target

   if ( $status != 0 ) then
      echo not done
      exit 1
   else
      echo done
      exit 0
   endif

endif

if ( "$SGE_DEPEND" == 1 ) then
   echo _________S_G_E__D_E_P_E_N_D_______________

   cd $SOURCE/3rdparty/sge_depend

   if ( ! -d $COMPILE_ARCH ) then
      echo " INFO: Architecture dir $COMPILE_ARCH not existing for sge_depend. Making"
      mkdir $COMPILE_ARCH
   endif

   cd $COMPILE_ARCH
   $MAKE $MAKEOPT -f ../Makefile "CC=$CC" "CFLAGS=$CFLAGS $XCFLAGS -U_GNU_SOURCE $NO_XDEPEND" "LFLAGS=$LFLAGS" "COMPILE_ARCH=$COMPILE_ARCH" $*

   if ( $status != 0 ) then
      echo not done
      exit 1
   endif

   cd $SOURCE
endif

if ( "$MAKEWINGRIDAPP" == 1 ) then
   echo ____W_I_N_3_2__A_P_P_L_I_C_A_T_I_O_N_S____

   if ( ! -d "${COMPILE_ARCH}" ) then
      mkdir "${COMPILE_ARCH}"
   endif
   cd "${COMPILE_ARCH}"

   switch ( "$argv" )
      case clean:
         set param = clean 
         set DEPEND = ""
         breaksw
      case depend:
         set param = depend
         set DEPEND = "../3rdparty/sge_depend/${COMPILE_ARCH}/sge_depend -l -S -Y ${DEPEND_FLAGS}"
         breaksw
      default
         set param = "$argv"
         set DEPEND = ""
      breaksw
   endsw

   $MAKE -f $SOURCE/utilbin/windows/Makefile "MAKE=$MAKE" "WINCC=$WINCC" \
      "WINCFLAGS=$WINCFLAGS" "WINLFLAGS=$WINLFLAGS" "SDIR=$SDIR" "RM=$RM" \
      "DEPEND=$DEPEND" "WINLIBS=$WINLIBS" $param

   if ( $status != 0 ) then
      echo not done
      exit 1
   endif

   cd ..
endif

if ( "$argv" == "depend" ) then
   if ( "$PLPA" == 1 ) then
      echo "No dependencies for 3rd_party plpa  ... skipping"
      set PLPA  = 0
   endif

   if ( "$HWLOC" == 1 ) then
      echo "No dependencies for 3rd_party hwloc ... skipping"
      set HWLOC     = 0
      set MAKEHWLOC = 0
   endif

   if ( "$QMAKE" == 1 ) then
      echo "No dependencies for 3rd_party qmake ... skipping"
      set QMAKE = 0
   endif

   if ( "$QTCSH" == 1 ) then
      echo "No dependencies for 3rd_party qtcsh ... skipping"
      set QTCSH = 0
   endif
endif

if ( "$MAKEWINGRIDLIB" == 1 ) then
   echo _________L_I_B__W_I_N_G_R_I_D_____________

   if ( ! -d "$COMPILE_ARCH" ) then
      mkdir $COMPILE_ARCH
   endif
   cd $COMPILE_ARCH

   switch ( "$argv" )
      case clean:
         set param = clean
         set DEPEND = ""
      breaksw

      case depend:
         set param = depend
         set DEPEND = "../3rdparty/sge_depend/$COMPILE_ARCH/sge_depend -l -S -Y $DEPEND_FLAGS"
      breaksw

      case messages:
         set param = messages
         set DEPEND = ""
      breaksw

      default:
         set param = wingridlib
         set DEPEND = ""
      breaksw
   endsw

   $MAKE $MAKEOPT -f $SOURCE/libs/wingrid/Makefile "MAKE=$MAKE" "CC=$CC" \
      "COMPILE_ARCH=$COMPILE_ARCH" \
      "CFLAGS=$CFLAGS $CORE_INCLUDE" "SOURCE=$SOURCE" \
      "KRBLIBS=$KRBLIBS" \
      "LFLAGS=$LFLAGS $KLFLAGS" "STRIP=$STRIP" "RANLIB=$RANLIB" \
      "AR=$AR" "ARFLAGS=$ARFLAGS" \
      "SHARED_CFLAGS=$SHARED_CFLAGS" "SHARED_LFLAGS=$SHARED_LFLAGS" \
      "DEPEND_FLAGS=$DEPEND_FLAGS" \
      "SHAREDLD=$SHAREDLD" "SHAREDEXT=$SHAREDEXT" "LIBEXT=$LIBEXT" \
      "SDIR=$SDIR" "DEPEND=$DEPEND" $param

   if ( $status != 0 ) then
      echo not done
      exit 1
   endif

   cd $SOURCE
endif

if ( "$MAKEJEMALLOCLIB" == 1 ) then
   echo _________3_r_d_p_a_r_t_y__J_E_M_A_L_L_O_C_

   cd $COMPILE_ARCH

   switch ( "$argv" )
      case clean:
         set param = clean
      breaksw

      case depend:
         set param = depend
      breaksw

      case messages:
         set param = messages
      breaksw

      case libjemalloc.so:
         set param = libjemalloc.so
      breaksw

      default:
         set param = ""
      breaksw
   endsw

   $MAKE $MAKEOPT -f $SOURCE/3rdparty/jemalloc/Makefile "MAKE=$MAKE" "CC=$CC" \
      "COMPILE_ARCH=$COMPILE_ARCH" "JEMALLOC_CFLAGS=$JEMALLOC_CFLAGS" \
      "CC=$CC" "CFLAGS=$CFLAGS" "SOURCE=$SOURCE" "SDIR=$SDIR" \
      "LFLAGS=$LFLAGS" "STRIP=$STRIP" "RANLIB=$RANLIB" \
      "AR=$AR" "ARFLAGS=$ARFLAGS" \
      "SHARED_CFLAGS=$SHARED_CFLAGS" "SHARED_LFLAGS=$SHARED_LFLAGS" \
      "DEPEND_FLAGS=$DEPEND_FLAGS" \
      "SHAREDLD=$SHAREDLD" "SHAREDEXT=$SHAREDEXT" "LIBEXT=$LIBEXT" $param

   if ( $status != 0 ) then
      echo not done
      exit 1
   endif

   cd $SOURCE
endif

if ( "$PLPA" == 1 ) then
   echo _________3_r_d_p_a_r_t_y__P_L_P_A_______

   if ( ( $BUILDARCH == LINUXX64 || \
      $BUILDARCH == LINUX86 ) && \
      $COMPILE_ARCH != "ULINUX86" && $COMPILE_ARCH != "ULINUXX64" ) then
      
      if ( ! -d $SOURCE/3rdparty/plpa/plpa-1.3.1/$COMPILE_ARCH || \
	      ! -r $SOURCE/3rdparty/plpa/plpa-1.3.1/$COMPILE_ARCH/Makefile ) then
         mkdir -p $SOURCE/3rdparty/plpa/plpa-1.3.1/$COMPILE_ARCH
         cd $SOURCE/3rdparty/plpa/plpa-1.3.1/$COMPILE_ARCH
         env -u LD_LIBRARY_PATH -u CPP CFLAGS="$HWLOC_CFLAGS" ../configure --enable-static --disable-shared --with-pic
      endif

      cd $SOURCE/3rdparty/plpa/plpa-1.3.1/$COMPILE_ARCH

      $MAKE $MAKEOPT -f Makefile "MAKE=$MAKE" "COMPILE_ARCH=$COMPILE_ARCH" $argv

      if ( $status != 0 ) then
         echo not done
         exit 1
      endif
   
   else
      echo plpa on architecture "$BUILDARCH" not supported
   endif 

   cd $SOURCE
endif

if ( "$MAKEHWLOC" == 1 ) then
   echo _________3_r_d_p_a_r_t_y__H_W_L_O_C_______

      set maj_ver = `echo $HWLOC_VERSION| cut -f 1 -d .`
      set min_ver = `echo $HWLOC_VERSION| cut -f 2 -d .`

      if ( "$maj_ver" == 1 && "$min_ver" <= 2 ) then
        set HWLOC_CFLAGS_EXTRA = "--disable-xml"
      else
        set HWLOC_CFLAGS_EXTRA = "--disable-libxml2 --disable-pci"
      endif

      if ( ! -d $SOURCE/3rdparty/hwloc/$HWLOC_DIRECTORY/$COMPILE_ARCH || \
           ! -r $SOURCE/3rdparty/hwloc/$HWLOC_DIRECTORY/$COMPILE_ARCH/Makefile ) then
         mkdir -p $SOURCE/3rdparty/hwloc/$HWLOC_DIRECTORY/$COMPILE_ARCH
         cd $SOURCE/3rdparty/hwloc/$HWLOC_DIRECTORY/$COMPILE_ARCH
         env CFLAGS="$HWLOC_CFLAGS" ../configure --enable-static --disable-shared $HWLOC_CFLAGS_EXTRA
      endif

      cd $SOURCE/3rdparty/hwloc/$HWLOC_DIRECTORY/$COMPILE_ARCH

      $MAKE $MAKEOPT -f Makefile "MAKE=$MAKE" "COMPILE_ARCH=$COMPILE_ARCH" $argv

      if ( $status != 0 ) then
         echo not done
         exit 1
      endif

   cd $SOURCE
endif

if ( "$MAKESTRPTIME" == 1 ) then
   echo _________3_r_d_p_a_r_t_y__S_T_R_P_T_I_M_E_

   # Set TPLIB, LIBS, and CFLAGS for all compiles

   set TPLIB = "$TPLIB libstrptime.a"

   set LIBS = "$LIBS -lstrptime"

   set CFLAGS = "-I$SOURCE/3rdparty/strptime $CFLAGS"

   cd $COMPILE_ARCH

  $MAKE $MAKEOPT -f $SOURCE/3rdparty/strptime/Makefile "MAKE=$MAKE" "CC=$CC" \
      "COMPILE_ARCH=$COMPILE_ARCH" \
      "CFLAGS=$CFLAGS" "SOURCE=$SOURCE" \
      "KRBLIBS=$KRBLIBS" \
      "LFLAGS=$LFLAGS $KLFLAGS" "STRIP=$STRIP" "RANLIB=$RANLIB" \
      "AR=$AR" "ARFLAGS=$ARFLAGS" \
      "SHARED_CFLAGS=$SHARED_CFLAGS" "SHARED_LFLAGS=$SHARED_LFLAGS" \
      "DEPEND_FLAGS=$DEPEND_FLAGS" \
      "SHAREDLD=$SHAREDLD" "SHAREDEXT=$SHAREDEXT" "LIBEXT=$LIBEXT" $argv

   if ( $status != 0 ) then
      echo not done
      exit 1
   endif

   cd $SOURCE
endif

if ( "$MAKESNPRINTF" == 1 && "$JAVA" != 2 ) then
   echo ______3_r_d_p_a_r_t_y__S_N_P_R_I_N_T_F___

   set TPLIB = "$TPLIB libsnprintf.a"
   set LIBS = "$LIBS -L$SOURCE/$COMPILE_ARCH -lsnprintf"
   set CFLAGS = "-DUSE_SNPRINTF $CFLAGS"
   set CFLAGS = "-I$SOURCE/3rdparty/snprintf $CFLAGS"
   cd $COMPILE_ARCH

  $MAKE $MAKEOPT -f $SOURCE/3rdparty/snprintf/Makefile "MAKE=$MAKE" "CC=$CC" \
      "COMPILE_ARCH=$COMPILE_ARCH" \
      "CFLAGS=$CFLAGS" "SOURCE=$SOURCE" \
      "KRBLIBS=$KRBLIBS" \
      "LFLAGS=$LFLAGS $KLFLAGS" "STRIP=$STRIP" "RANLIB=$RANLIB" \
      "AR=$AR" "ARFLAGS=$ARFLAGS" \
      "SHARED_CFLAGS=$SHARED_CFLAGS" "SHARED_LFLAGS=$SHARED_LFLAGS" \
      "DEPEND_FLAGS=$DEPEND_FLAGS" \
      "SHAREDLD=$SHAREDLD" "SHAREDEXT=$SHAREDEXT" "LIBEXT=$LIBEXT" $argv

   #if ( $status != 0 ) then
   #   echo not done
   #   exit 1
   #endif

   cd $SOURCE
endif

if ( "$MAKEFNMATCH" == 1 ) then
   echo _________3_r_d_p_a_r_t_y__F_N_M_A_T_C_H___

   # Set TPLIB, LIBS, and CFLAGS for all compiles

   set TPLIB = "$TPLIB libfnmatch.a"

   set LIBS = "$LIBS -lfnmatch"

   set CFLAGS = "-I$SOURCE/3rdparty/fnmatch $CFLAGS"

   cd $COMPILE_ARCH

  $MAKE $MAKEOPT -f $SOURCE/3rdparty/fnmatch/Makefile "MAKE=$MAKE" "CC=$CC" \
      "COMPILE_ARCH=$COMPILE_ARCH" \
      "CFLAGS=$CFLAGS" "SOURCE=$SOURCE" \
      "KRBLIBS=$KRBLIBS" \
      "LFLAGS=$LFLAGS $KLFLAGS" "STRIP=$STRIP" "RANLIB=$RANLIB" \
      "AR=$AR" "ARFLAGS=$ARFLAGS" \
      "SHARED_CFLAGS=$SHARED_CFLAGS" "SHARED_LFLAGS=$SHARED_LFLAGS" \
      "DEPEND_FLAGS=$DEPEND_FLAGS" \
      "SHAREDLD=$SHAREDLD" "SHAREDEXT=$SHAREDEXT" "LIBEXT=$LIBEXT" $argv

   if ( $status != 0 ) then
      echo not done
      exit 1
   endif

   cd $SOURCE
endif

if ( "$ADD_COPYRIGHT" == 1 ) then
   set CFLAGS = "-DADD_COPYRIGHT -I$COPYRIGHT_DIR $CFLAGS"
else if ( "$ADD_SUN_COPYRIGHT" == 1 ) then
   set CFLAGS = "-DADD_COPYRIGHT -DADD_SUN_COPYRIGHT -I$SUN_COPYRIGHT_DIR $CFLAGS"
endif

if ( "$CORE" == 1 && "$JAVA" != 2 ) then
   if ( "$COMPILE_DIR" == "" ) then
      cd $COMPILE_ARCH
   else
      cd $COMPILE_DIR
   endif

   # spooledit is only available if berkeleydb is available.
   # if we build with spooling method classic, touch spooledit
   if ( $SPOOLING_METHOD == classic ) then
      touch -t 202012312358 libspoolb.a spooledit.o
      touch -t 202012312359 spooledit
   endif

   # we must map the symbolic spooling lib names the target filenames,
   # otherwise make will always relink qmaster, spoolinit ...
   set new_deps = ""
   foreach dep ( $SPOOLING_DEPS )
      switch ( $dep )
         case spoolloaderlib:
            set new_deps = "$new_deps libspoolloader$LIBEXT"
            breaksw
         case spooldlib:
            set new_deps = "$new_deps libspoold$LIBEXT"
            breaksw
         case spoolblib:
            set new_deps = "$new_deps libspoolb$SPOOLLIBEXT"
            breaksw
         case spoolclib:
            set new_deps = "$new_deps libspoolc$SPOOLLIBEXT"
            breaksw
         case spoollib:
            set new_deps = "$new_deps libspool$LIBEXT"
            breaksw
      endsw
   end
   set SPOOLING_DEPS = "$new_deps"

   if ( "$FLAGS_OUT" == true ) then
   echo ___C_O_M_P_I_L_E__I_N_C_L_U_D_E__ F_L_A_G_S___
      echo "CFLAGS:$CFLAGS"
      echo "INCLUDES:$CORE_INCLUDE $XINCD"
      exit 0
   endif

   echo _________C_O_R_E__S_Y_S_T_E_M_____________
   $MAKE $MAKEOPT -f $MAKEFILE "MAKE=$MAKE" "CC=$CC" \
         "LD_WRAPPER=$LD_WRAPPER" \
         "CFLAGS=$CFLAGS $CORE_INCLUDE" \
         "CORELIB=$CORELIB" \
         "DEPEND_FLAGS=$DEPEND_FLAGS $CORE_INCLUDE" \
         "SDIR=$SDIR" "SOURCE=$SOURCE" "COMPILE_ARCH=$COMPILE_ARCH" \
         "SECLIB=$SECLIB" \
         "SECLIBS_STATIC=$SECLIBS_STATIC" \
         "WINGRIDLIB=$WINGRIDLIB" "WINGRIDLIB_DEP=$WINGRIDLIB_DEP" \
         "WINGRIDLIB_STATIC=$WINGRIDLIB_A" "WINGRIDLIB_STATIC_DEP=$WINGRIDLIB_A_DEP" \
         "KRBTARGETS=$KRBTARGETS" "KRBDEPEND=$KRBDEPEND" "KRBCLEAN=$KRBCLEAN"\
         "KRBLIBS=$KRBLIBS" "AUTHLIBS=$AUTHLIBS" \
         "KRBLIB=$KRBLIB" "GSSDEPEND=$GSSDEPEND" \
         "GSSCLEAN=$GSSCLEAN" "MSDIR=$MSDIR" "SLIBS=$GSSLIBS $KLIBS" "LIBS=$LIBS" \
         "XCFLAGS=$XCFLAGS" "XLFLAGS=$XLFLAGS" \
         "XLIBS=$XLIBS" "XMLIBS=$XMLIBS" "LFLAGS=$LFLAGS $KLFLAGS" "STRIP=$STRIP" \
         "RANLIB=$RANLIB" "AR=$AR" "ARFLAGS=$ARFLAGS" \
         "NOERR_PROTO=$NOERR_PROTO" "NOERR_CFLAG=$NOERR_CFLAG" \
         "COMPILE_DC=$COMPILE_DC" "LOADAVGLIBS=$LOADAVGLIBS" \
         "FSTYPELIBS=$FSTYPELIBS" "TPLIB=$TPLIB" \
         "XGETTEXT=$XGETTEXT" "MESSAGES=$MESSAGES" \
         "INTERACTTARGETS=$INTERACTTARGETS" \
         "LIBEXT=$LIBEXT" "SHAREDEXT=$SHAREDEXT" "SHAREDLD=$SHAREDLD" \
         "SHARED_CFLAGS=$SHARED_CFLAGS" "SHARED_LFLAGS=$SHARED_LFLAGS $KLFLAGS" \
         "SPOOLING_LIBS=$SPOOLING_LIBS" "SPOOLING_DEPS=$SPOOLING_DEPS" \
         "SPOOLLIBEXT=$SPOOLLIBEXT" \
         "BDB_LIB_SUFFIX=${BDB_LIB_SUFFIX}" \
         "DLLIB=$DLLIB" \
         "MEMCFLAG=$MEMCFLAG" \
         "CORE_INCLUDE=$CORE_INCLUDE" \
         "PERLGUI=$PERLGUI" "PERL=$PERL" "SWIG=$SWIG" \
         "JAVA_BINDIR=$JAVA_BINDIR" "JAVA_SHAREDEXT=$JAVA_SHAREDEXT" \
         "JNI_TARGET=$JNI_TARGET" \
         "JAVA_LFLAGS=$JAVA_LFLAGS" \
         "SONAME_LFLAG_DRMAA10=$SONAME_LFLAG_DRMAA10" \
         "SONAME_LFLAG_DRMAA95=$SONAME_LFLAG_DRMAA95" \
         "JUTI_ALL=$JUTI_ALL" "JUTI_CLEAN=$JUTI_CLEAN" "JUTI_DEPEND=$JUTI_DEPEND" \
         "AUTHUSER_ALL=$AUTHUSER_ALL" "LOADCHECK_ALL=$LOADCHECK_ALL" \
         "AUTHUSER_OBJ=$AUTHUSER_OBJ" "LOADCHECK_OBJ=$LOADCHECK_OBJ" \
         "JUTI_OBJ=$JUTI_OBJ" \
         "WINCC=$WINCC" "WINCFLAGS=$WINCFLAGS" "WINLFLAGS=$WINLFLAGS" \
         "WINLIBS=$WINLIBS" "LIBRARY_LIBS=$LIBRARY_LIBS" \
         $argv
   if ( $status != 0 ) then
      echo not done
      exit 1
   endif

   cd $SOURCE
endif

if ( "$JAVA" > 0 ) then
   echo _____Making JAVA targets_____

   # ant -D does not work, so we set an env var
   if ( $AIMK_TARGETOPT == 1) then
      setenv AIMK_TARGET_BITS $TARGET_BITS
      setenv aimk_buildarch $buildarch
   endif
   if ( $USE_INSURE == 1 ) then
      setenv AIMK_INSURE -insure
   else
      setenv AIMK_INSURE ""
   endif
   if ( $DEBUGGED == 1 ) then
      setenv AIMK_DEBUG true
   else
      setenv AIMK_DEBUG ""
   endif  

   if ( "$ADD_COPYRIGHT" == 1 ) then
      setenv AIMK_COPYRIGHT_DIR "$COPYRIGHT_DIR"
      setenv AIMK_COPYRIGHT "courtesy"
   else if ( "$ADD_SUN_COPYRIGHT" == 1 ) then
      setenv AIMK_COPYRIGHT_DIR "$SUN_COPYRIGHT_DIR"
      setenv AIMK_COPYRIGHT "sun"
   else
      setenv AIMK_COPYRIGHT_DIR ""
      setenv AIMK_COPYRIGHT ""
   endif
   # -no-gui-inst option
   if ( "$JAVA_GUI_INST" == 0 ) then
      setenv BUILD_NO_GUI_INSTALLER 1
   endif
   ant -f build.xml $argv
   # how to propagate ant opts to first and then second build.xml
   # ant -Dsge.ant.args='-DA="a" -DB="b" -DC="c"' -f build.xml $argv
   
   if ( $status != 0 ) then
      echo not done
      exit 1
   endif

   if ( $JAVA == 2 ) then
      echo done
      exit 0
   endif

endif

if ( "$QMON" == 1 ) then
   echo _________Q_M_O_N__________________________

   cd $SOURCE/3rdparty/qmon

   if (! -d $COMPILE_ARCH) then
      echo " INFO: Architecture dir $COMPILE_ARCH not existing for 3rdparty Qmon Libs. Making"
      mkdir $COMPILE_ARCH
   endif

   cd $COMPILE_ARCH

   $MAKE $MAKEOPT -f ../Makefile "MAKE=$MAKE" "CC=$CC" \
         "LD_WRAPPER=$LD_WRAPPER" \
         "CFLAGS=$CFLAGS" "SDIR=$SDIR" "SOURCE=$SOURCE" \
         "COMPILE_ARCH=$COMPILE_ARCH" \
         "XCFLAGS=$XCFLAGS" "XLFLAGS=$XLFLAGS" "KRBLIBS=$KRBLIBS" \
         "XLIBS=$XLIBS" "XMLIBS=$XMLIBS" "LFLAGS=$LFLAGS $KLFLAGS" "STRIP=$STRIP" "RANLIB=$RANLIB" \
         "AR=$AR" "ARFLAGS=$ARFLAGS" "TPLIB=$TPLIB" \
         "MEMCFLAG=$MEMCFLAG"  \
         "SHARED_CFLAGS=$SHARED_CFLAGS" "SHARED_LFLAGS=$SHARED_LFLAGS" \
         "GSHARED_CFLAGS=$GSHARED_CFLAGS" "GSHARED_LFLAGS=$GSHARED_LFLAGS" \
         "SHAREDLD=$SHAREDLD" "SHAREDEXT=$SHAREDEXT" "LIBEXT=$LIBEXT" $argv

   if ( $status != 0 ) then
      echo not done
      exit 1
   endif

   cd $SOURCE

   cd $COMPILE_ARCH

   $MAKE $MAKEOPT -f $SOURCE/clients/qmon/Makefile \
         "MAKE=$MAKE" "CC=$CC" \
         "LD_WRAPPER=$LD_WRAPPER" \
         "CFLAGS=$CFLAGS $CORE_INCLUDE" \
         "DEPEND_FLAGS=$DEPEND_FLAGS $CORE_INCLUDE" \
         "SDIR=$SDIR" "SOURCE=$SOURCE" "COMPILE_ARCH=$COMPILE_ARCH" \
         "SECLIB=$SECLIB"\
         "KRBTARGETS=$KRBTARGETS" "KRBDEPEND=$KRBDEPEND" "KRBCLEAN=$KRBCLEAN"\
         "KRBLIBS=$KRBLIBS" "KRBLIB=$KRBLIB" "GSSDEPEND=$GSSDEPEND" \
         "GSSCLEAN=$GSSCLEAN" "MSDIR=$MSDIR" "SLIBS=$GSSLIBS $KLIBS" "LIBS=$LIBS" \
         "XCFLAGS=$XCFLAGS" "XLFLAGS=$XLFLAGS" \
         "XLIBS=$XLIBS" "XMLIBS=$XMLIBS" "LFLAGS=$LFLAGS $KLFLAGS" "STRIP=$STRIP" \
         "RANLIB=$RANLIB" "AR=$AR" "ARFLAGS=$ARFLAGS" \
         "NOERR_PROTO=$NOERR_PROTO" \
         "NOERR_CFLAG=$NOERR_CFLAG" \
         "COMPILE_DC=$COMPILE_DC" "LOADAVGLIBS=$LOADAVGLIBS" "FSTYPELIBS=$FSTYPELIBS" "TPLIB=$TPLIB" \
         "XGETTEXT=$XGETTEXT" "MESSAGES=$MESSAGES" \
         "INTERACTTARGETS=$INTERACTTARGETS" \
         "LIBEXT=$LIBEXT" "SHAREDEXT=$SHAREDEXT" "SHAREDLD=$SHAREDLD" \
         "SHARED_CFLAGS=$SHARED_CFLAGS" "SHARED_LFLAGS=$SHARED_LFLAGS $KLFLAGS" \
         "SPOOLLIBEXT=$SPOOLLIBEXT" \
         "SPOOLING_LIBS=$SPOOLING_LIBS" "SPOOLING_DEPS=$SPOOLING_DEPS" \
         "DLLIB=$DLLIB" \
         "MEMCFLAG=$MEMCFLAG" \
         $argv
   if ( $status != 0 ) then
      echo not done
      exit 1
   endif
   
   cd $SOURCE
endif

if ( "$REMOTE" == 1) then
   echo _________3_r_d_p_a_r_t_y__R_E_M_O_T_E_____

   cd $SOURCE/3rdparty/remote

   if ( ! -d $COMPILE_ARCH ) then
      echo " INFO: Architecture dir $COMPILE_ARCH not existing for 3rdparty remote. Making"
      mkdir $COMPILE_ARCH
   endif

   if ( $COMPILE_ARCH == "NECSX5" ) then
      set CFLAGS_REMOTE = "$CFLAGS_NOOPT"
   else
      set CFLAGS_REMOTE = "$CFLAGS $ERR_WARN_NONE"
   endif

   set REMOTE_LFLAGS = "$LFLAGS -L$SOURCE/$COMPILE_ARCH"

   cd $COMPILE_ARCH

   $MAKE $MAKEOPT -f ../Makefile "MAKE=$MAKE" "CC=$CC" \
      "CFLAGS=$CFLAGS_REMOTE" "LIBS=$LIBS" "SOURCE=$SOURCE" \
      "KRBLIBS=$KRBLIBS" "DLLIB=$DLLIB" \
      "LFLAGS=$REMOTE_LFLAGS $KLFLAGS" "STRIP=$STRIP" "RANLIB=$RANLIB" \
      "AR=$AR" "ARFLAGS=$ARFLAGS" "LIBEXT=$LIBEXT" \
      "WINGRIDLIB=$WINGRIDLIB" "WINGRIDLIB_DEP=$WINGRIDLIB_DEP" \
      "MEMCFLAG=$MEMCFLAG" "COMPILE_ARCH=$COMPILE_ARCH" $argv

   if ( $status != 0 ) then
      echo not done
      exit 1
   endif

   cd $SOURCE
endif

if ( "$QMAKE" == 1) then
   echo _________3_r_d_p_a_r_t_y__Q_M_A_K_E_______

   if ( ! -d $SOURCE/3rdparty/qmake/$COMPILE_ARCH || \
	! -r $SOURCE/3rdparty/qmake/$COMPILE_ARCH/Makefile ) then
      mkdir -p $SOURCE/3rdparty/qmake/$COMPILE_ARCH
      cd $SOURCE/3rdparty/qmake/$COMPILE_ARCH
      env REMOTE=sge CFLAGS="${CFLAGS} ${NOERR_CFLAG}" LIBS="$QMAKELIB" SGE_ARCH=$buildarch \
       ../configure --srcdir=..
   endif

   cd $SOURCE/3rdparty/qmake/$COMPILE_ARCH

   $MAKE $MAKEOPT -f Makefile "MAKE=$MAKE" "COMPILE_ARCH=$COMPILE_ARCH" "DLLIB=$DLLIB" $argv

   if ( $status != 0 ) then
      echo not done
      exit 1
   endif

   cd $SOURCE
endif


if ( "$SGESSH" == 1) then
   echo _________3_r_d_p_a_r_t_y__SSH_____________

   cd $SOURCE/3rdparty/openssh

   if ( ! -d $COMPILE_ARCH ) then
      echo " INFO: Architecture dir $COMPILE_ARCH not existing for 3rdparty openssh. Making"
      mkdir $COMPILE_ARCH
   endif

   cd $COMPILE_ARCH

   if ( ! -d $SOURCE/3rdparty/openssh/$COMPILE_ARCH || \
          ! -r $SOURCE/3rdparty/openssh/$COMPILE_ARCH/Makefile ) then
      mkdir -p $SOURCE/3rdparty/openssh/$COMPILE_ARCH
      cd $SOURCE/3rdparty/openssh/$COMPILE_ARCH

      env REMOTE=sge SGE_ARCH=$buildarch LD_LIBRARY_PATH=${OPENSSL_HOME}/lib\
      MAKE="${MAKE}" CFLAGS="${CFLAGS} ${NOERR_CFLAG}" CC="${CC}" AR="${AR}" \
      ../configure --with-grd=${COMPILE_ARCH} --srcdir=.. \
         --with-cflags="${MEMCFLAG} ${NOERR_SSH} ${NOERR_PROTO} -DSGESSH_INTEGRATION" \
         --with-ldflags="${LFLAGS}" \
         --with-libs="-L../../../${COMPILE_ARCH} -L../../../3rdparty/remote/${COMPILE_ARCH}/ -lsgeremote -luti -lcommlists -llck -lrmon ${LIBS} ${SLIBS}" \
         --with-ssl-dir=${OPENSSL_HOME}
   endif

   $MAKE $MAKEOPT -f Makefile "MAKE=$MAKE" "CC=$CC" \
     "COMPILE_ARCH=$COMPILE_ARCH" $argv

   if ( $status != 0 ) then
      echo not done
      exit 1
   endif

   cd $SOURCE
endif


if ( "$QTCSH" == 1) then
   echo _________3_r_d_p_a_r_t_y__Q_T_C_S_H_______

   # with shared libs: qtcsh requires finding libsge.so during build
   # for AIX, we have to pass special options to make
   set SGE_COPTS = "$DEBUG_FLAG $INSURE_FLAG"
   set SGE_LOPTS = "$INSURE_FLAG"


   if ( $SHAREDLIBS == 1 ) then
      set SHARED_PATH_NAME = `dist/util/arch -lib`

      switch ( $COMPILE_ARCH )
         case AIX43:
            set SGE_LOPTS = "-brtl"
            breaksw
      endsw

      setenv $SHARED_PATH_NAME ${SOURCE}/${COMPILE_ARCH}
   endif

   set SGE_LIBS = "-lsge -lpthread"

   if ( "$COMPILE_ARCH" == "NECSX5" ) then
      set SGE_LIBS = "$SGE_LIBS -lfnmatch"
   else if ( "$COMPILE_ARCH" == "WIN32_X86" ) then
      set SGE_LIBS = "$SGE_LIBS $WINGRIDLIB"
   endif

   if ( ! -d $SOURCE/3rdparty/qtcsh/$COMPILE_ARCH || \
	! -r $SOURCE/3rdparty/qtcsh/$COMPILE_ARCH/Makefile ) then
      mkdir -p $SOURCE/3rdparty/qtcsh/$COMPILE_ARCH
      cd $SOURCE/3rdparty/qtcsh/$COMPILE_ARCH
      env REMOTE=sge CFLAGS="${CFLAGS} ${NOERR_CFLAG}" SGE_ARCH=$buildarch \
       ../configure --with-sge=${COMPILE_ARCH} --srcdir=..
   endif

   cd $SOURCE/3rdparty/qtcsh/$COMPILE_ARCH

   $MAKE $MAKEOPT -f Makefile "MAKE=$MAKE" "CC=$CC" "COMPILE_ARCH=$COMPILE_ARCH" \
         "SGE_LIBS=$LFLAGS $KLFLAGS $SGE_LIBS $SECLIB $KRBLIB $KLIBS $DLLIB" \
         "SGE_COPTS=$SGE_COPTS" "SGE_LOPTS=$SGE_LOPTS" "DLLIB=$DLLIB" $argv

   if ( $status != 0 ) then
      echo not done
      exit 1
   endif

   if ( $SHAREDLIBS == 1 ) then
      unsetenv $SHARED_PATH_NAME
   endif

   cd $SOURCE
endif

if ( "$ADOC" == 1) then
   echo _________3_r_d_p_a_r_t_y__A_D_O_C_________

   cd $SOURCE/3rdparty/adoc

   if ( ! -d $COMPILE_ARCH ) then
      echo " INFO: Architecture dir $COMPILE_ARCH not existing for 3rdparty adoc. Making"
      mkdir $COMPILE_ARCH
   endif

   cd $COMPILE_ARCH

   $MAKE $MAKEOPT -f ../Makefile.aimk "MAKE=$MAKE" "CC=$CC" "CFLAGS=$CFLAGS" \
         "LFLAGS=$LFLAGS" $argv

   if ( $status != 0 ) then
      echo not done
      exit 1
   endif

   cd $SOURCE

   unset noglob

   set DIR_LIBS = "{libs/*}"
   set DIR_CORE = "{common,clients/*,daemons/*}"
   set DIR_TESTSUITE = "{../testsuite,../testsuite/*,../testsuite/*/*,../testsuite/*/*/*,../testsuite/*/*/*/*}"
   set SOURCE_LIBS = "$DIR_LIBS/*.c $DIR_LIBS/*.h"
   set SOURCE_CORE = "$DIR_CORE/*.c $DIR_CORE/*.h"
   set SOURCE_TESTSUITE = "$DIR_TESTSUITE/*.tcl $DIR_TESTSUITE/*.exp"

   set EDITION = "1.0"
   set REVISION = `grep GDI_VERSION libs/gdi/version.* | cut -f 2 -d '"'`

   echo "Creating documentation for libs: libcomm.texi"
   3rdparty/adoc/$COMPILE_ARCH/adoc --no-warnings -f -b -DPROJECT "Grid Engine Communication Library" -DEDITION "$EDITION" -DREVISION "SGE $REVISION" -DCOPYRIGHT "The Grid Engine Team" -DAUTHOR "The Grid Engine Team" -I -xon -xitemize -2 libs/comm/*.h libs/comm/*.c -o $COMPILE_ARCH/libcomm.texi

   echo "Creating documentation for libs: libcull.texi"
   3rdparty/adoc/$COMPILE_ARCH/adoc --no-warnings -f -b -DPROJECT "Grid Engine CULL Library" -DEDITION "$EDITION" -DREVISION "SGE $REVISION" -DCOPYRIGHT "The Grid Engine Team" -DAUTHOR "The Grid Engine Team" -I -xon -xitemize -2 libs/cull/*.h libs/cull/*.c -o $COMPILE_ARCH/libcull.texi

   echo "Creating documentation for libs: eventclient.texi"
   3rdparty/adoc/$COMPILE_ARCH/adoc --no-warnings -f -b -DPROJECT "Event Client Interface" -DEDITION "$EDITION" -DREVISION "SGE $REVISION" -DCOPYRIGHT "The Grid Engine Team" -DAUTHOR "The Grid Engine Team" -I -xon -xitemize -2 libs/evc/*.h libs/evc/*.c libs/evm/*.h libs/evm/*.c -o $COMPILE_ARCH/eventclient.texi

   echo "Creating documentation for libs: libgdi.texi"
   3rdparty/adoc/$COMPILE_ARCH/adoc --no-warnings -f -b -DPROJECT "Grid Engine GDI Library" -DEDITION "$EDITION" -DREVISION "SGE $REVISION" -DCOPYRIGHT "The Grid Engine Team" -DAUTHOR "The Grid Engine Team" -I -xon -xitemize -2 libs/gdi/*.h libs/gdi/*.c -o $COMPILE_ARCH/libgdi.texi

   echo "Creating documentation for libs: libmir.texi"
   3rdparty/adoc/$COMPILE_ARCH/adoc --no-warnings -f -b -DPROJECT "Grid Engine Mirror Interface" -DEDITION "$EDITION" -DREVISION "SGE $REVISION" -DCOPYRIGHT "The Grid Engine Team" -DAUTHOR "The Grid Engine Team" -I -xon -xitemize -2 libs/mir/*.h libs/mir/*.c -o $COMPILE_ARCH/libmir.texi

   echo "Creating documentation for libs: librmon.texi"
   3rdparty/adoc/$COMPILE_ARCH/adoc --no-warnings -f -b -DPROJECT "Grid Engine RMON Library" -DEDITION "$EDITION" -DREVISION "SGE $REVISION" -DCOPYRIGHT "The Grid Engine Team" -DAUTHOR "The Grid Engine Team" -I -xon -xitemize -2 libs/rmon/*.h libs/rmon/*.c -o $COMPILE_ARCH/librmon.texi

   echo "Creating documentation for libs: libsched.texi"
   3rdparty/adoc/$COMPILE_ARCH/adoc --no-warnings -f -b -DPROJECT "Grid Engine SCHED Library" -DEDITION "$EDITION" -DREVISION "SGE $REVISION" -DCOPYRIGHT "The Grid Engine Team" -DAUTHOR "The Grid Engine Team" -I -xon -xitemize -2 libs/sched/*.h libs/sched/*.c -o $COMPILE_ARCH/libsched.texi

   echo "Creating documentation for libs: libsgeobj.texi"
   3rdparty/adoc/$COMPILE_ARCH/adoc --no-warnings -f -b -DPROJECT "Grid Engine SGEOBJ Library" -DEDITION "$EDITION" -DREVISION "SGE $REVISION" -DCOPYRIGHT "The Grid Engine Team" -DAUTHOR "The Grid Engine Team" -I -xon -xitemize -2 libs/sgeobj/*.h libs/sgeobj/*.c -o $COMPILE_ARCH/libsgeobj.texi

   echo "Creating documentation for libs: libjapi.texi"
   3rdparty/adoc/$COMPILE_ARCH/adoc --no-warnings -f -b -DPROJECT "Grid Engine Job API Library" -DEDITION "$EDITION" -DREVISION "SGE $REVISION" -DCOPYRIGHT "The Grid Engine Team" -DAUTHOR "The Grid Engine Team" -I -xon -xitemize -2 libs/japi/japi.h libs/japi/japi.c -o $COMPILE_ARCH/libjapi.texi

   echo "Creating documentation for libs: libuti.texi"
   3rdparty/adoc/$COMPILE_ARCH/adoc --no-warnings -f -b -DPROJECT "Grid Engine Utility Library" -DEDITION "$EDITION" -DREVISION "SGE $REVISION" -DCOPYRIGHT "The Grid Engine Team" -DAUTHOR "The Grid Engine Team" -I -xon -xitemize -2 libs/uti/*.h libs/uti/*.c -o $COMPILE_ARCH/libuti.texi

   echo "Creating documentation for libs: libdrmaa.texi"
endif
echo done.

# On SOLARIS64, if there was no special target (i.e. $argv = "") 
# and no "-only-*" parameter specified, the shared libraries for
# SOLARIS are also built.
if ( $BUILDARCH == SOLARIS64 && $ONLY_PARAM_SPEC == 0 && "${SOLARIS_ONLY_64}" != 1 ) then
      if ( "$argv" == "" ) then 
         echo ""
         echo "Executing aimk again to build 32 bit shared libraries."
         if ( "$JAVA" > 0 ) then
            ./aimk -32 -only-core libdrmaa.so libjgdi.so libjuti.so
         else 
            ./aimk -32 -only-core libdrmaa.so libjuti.so
         endif
       else if ( "$argv" == "clean" ) then 
            ./aimk -32 -only-core clean 
       endif 
      exit $status
   endif
endif

# On HP11 we are always building (and cleaning) a 32bit version
if ( $BUILDARCH == HP1164 ) then
   set ONLY_64_FLAG = 0
   set arguments = "" 
   set i = 1
   while ($i <= $#UNMODIFIED_ARGUMENTS)
      switch ("$UNMODIFIED_ARGUMENTS[$i]")
         case "-only-64":
         case "-64":
            set ONLY_64_FLAG = 1
            breaksw
         default: 
            set arguments = "$arguments $UNMODIFIED_ARGUMENTS[$i]"
            breaksw
      endsw
      @ i++ 
   end 
   if ( "$ONLY_64_FLAG" != 1 ) then 
      # compile the 32 bit version 
      ./aimk -32 "$arguments"
   endif 
endif 

echo done.

exit 0
