if ! $(BUILDTOP)
{
BUILDTOP = . ;
}

# Include configuration.  The value of JAMCONFIG may be overridden by targets
# which recursively invoke 'jam' with a custom configuration file.  For
# instance, this is done with the 'msvcgen' target (see CS/mk/msvcgen/Jamfile).
JAMCONFIG ?= $(BUILDTOP)/Jamconfig ;
include $(JAMCONFIG) ;
if ! $(JAMCONFIG_READ)
{
  EXIT "Failed to find configuration information. Please configure project." ;
}

# CFLAGS.  Don't use FDefines here since Boost Jam doesn't have it, and we have
# not yet included mk/jam/build.jam which provides an emulation layer for
# Boost.  We can not include build.jam earlier because these flags need to be
# defined before build.jam is included.  :-(
COMPILER.CFLAGS.debug += -DCS_DEBUG ;
COMPILER.CFLAGS.profile += -g3 -pg ;
COMPILER.LFLAGS.profile += -g3 -pg ;

# Put output files into out/systemname.
LOCATE.OBJECTS = $(BUILDTOP)/out/$(OSFULL[1]:L) ;
LOCATE.TARGETS = $(BUILDTOP) ;
LOCATE.DOCS = $(BUILDTOP)/out/docs ;

# Include CS build rules.
include $(TOP)/mk/jam/build.jam ;

# Set up default application icon.
ApplicationIconDefault macosx : gui : appicon.icns : $(TOP) libs csutil macosx ;
ApplicationIconDefault win32 : gui : cs1.ico : $(TOP) libs csutil win32 ;

# Set up a property which clients can query to determine if the build directory
# differs from source directory.  This allows clients to perform conditional
# actions based upon this knowledge.  We safely detect if the two directories
# differ by checking if 'cssysdef.h' is present in $(BUILDTOP)/include.  If it
# is not, then the directories differ.
buildheaders = [ GLOB [ ConcatDirs $(BUILDTOP) include ] : *.h ] ;
if ! [ IsElem cssysdef.h : $(buildheaders:BS) ]
{
  SetProperty build : standalone ;
}

# List of plugins which should be linked in when building static.
if $(USE_NEW_RENDERER) = "yes"
{
  SetProperty build : newrenderer ;

  STATIC.PLUGINLIST =
    ball
    ballldr
    bezier
    bezierldr
    bugplug
    crossbld
    csbmpimg
    csconin
    csfont
    csgifimg
    csjpgimg
    csddsimg
    csparser
    cspngimg
    cssynldr
    dynavis
    emit
    emitldr
    engine
    engseq
    explo
    exploldr
    fire
    fireldr
    fountain
    fountldr
    frustvis
    genmesh
    gmeshldr
    haze
    hazeldr
    ieplex
    imgplex
    nullmesh
    rain
    rainldr
    opcode
    reporter
    sequence
    simpcon
    snow
    snowldr
    spiral
    spirldr
    spr2d
    spr2dldr
    spr3d
    spr3dldr
    starldr
    stars
    stdrep
    stdpt
    thing
    thingldr
    vfs
    xmlread
    rendstep_stencil
    rendstep_std
    rendloop_loader
    glshader_fixed
    glshader_arb
    glrender3d
    shadermgr
    xmlshader
    chunklod
    ;
}
else
{
  STATIC.PLUGINLIST =
    ball
    ballldr
    bezier
    bezierldr
    bugplug
    crossbld
    csbmpimg
    csconin
    csfont
    csgifimg
    csjpgimg
    csddsimg
    csparser
    cspngimg
    cssynldr
    dynavis
    emit
    emitldr
    engine
    engseq
    explo
    exploldr
    fire
    fireldr
    fountain
    fountldr
    frustvis
    genmesh
    gl3d
    gmeshldr
    haze
    hazeldr
    ieplex
    imgplex
    nullmesh
    rain
    rainldr
    opcode
    reporter
    sequence
    simpcon
    snow
    snowldr
    soft3d
    spiral
    spirldr
    spr2d
    spr2dldr
    spr3d
    spr3dldr
    starldr
    stars
    stdrep
    stdpt
    thing
    thingldr
    vfs
    xmlread
    ;
}

if $(GLX.AVAILABLE) = "yes" { STATIC.PLUGINLIST += glx2d ; }
if $(X11.AVAILABLE) = "yes" { STATIC.PLUGINLIST += x2d xextshm xwin ; }
if $(XFREE86VM.AVAILABLE) = "yes" { STATIC.PLUGINLIST += xext86vm ; }
if $(DIRECTX.AVAILABLE) = "yes" { STATIC.PLUGINLIST += ddraw2d ; }
if $(TARGET.OS) = "WIN32" && $(GL.AVAILABLE) = "yes"
  { STATIC.PLUGINLIST += glwin32 ; }
if $(TARGET.OS) = "MACOS_X" { STATIC.PLUGINLIST += cgdriver2d ; }
if $(TARGET.OS) = "MACOS_X" && $(GL.AVAILABLE) = "yes"
  { STATIC.PLUGINLIST += glosx2d ; }
