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

# Include config
JAMCONFIG ?= $(BUILDTOP)/Jamconfig ;
include $(JAMCONFIG) ;
if ! $(JAMCONFIG_READ)
{
  EXIT "Couldn't find config. Please configure the project." ;
}

# CFLAGS
COMPILER.CFLAGS.debug += -DCS_DEBUG ;
COMPILER.CFLAGS.profile += -g3 -pg ;
COMPILER.LFLAGS.profile += -g3 -pg ;

# csutil requires zlib
APPLICATION.LFLAGS += $(ZLIB.LFLAGS) ;
APPLICATION.CFLAGS += $(ZLIB.CFLAGS) ;
# csThread may require pthread
if $(PTHREAD.AVAILABLE) = "yes"
{
  LINKLIBS += $(PTHREAD.LFLAGS) ;
  C++FLAGS += $(PTHREAD.CFLAGS) ;
  CFLAGS += $(PTHREAD.CFLAGS) ;
}

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

# List of plugins which should be linked in when building static.
if $(USE_NEW_RENDERER) = "yes"
{
  STATIC.PLUGINLIST =
    ball
    ballldr
    bezier
    bezierldr
    bugplug
    crossbld
    csbmpimg
    csconin
    csfont
    csgifimg
    csjpgimg
    csparser
    cspngimg
    cssynldr
    dynavis
    emit
    emitldr
    engine
    engseq
    explo
    exploldr
    fire
    fireldr
    fountain
    fountldr
    frustvis
    genmesh
    gmeshldr
    gtreeldr
    haze
    hazeldr
    ieplex
    imgplex
    motion
    motldr
    nullmesh
    rain
    rainldr
    rapid
    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
    csparser
    cspngimg
    cssynldr
    dynavis
    emit
    emitldr
    engine
    engseq
    explo
    exploldr
    fire
    fireldr
    fountain
    fountldr
    frustvis
    genmesh
    gl3d
    gmeshldr
    gtreeldr
    haze
    hazeldr
    ieplex
    imgplex
    motion
    motldr
    nullmesh
    rain
    rainldr
    rapid
    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 += cocoa2d cgdriver2d ; }
if $(TARGET.OS) = "MACOS_X" && $(GL.AVAILABLE) = "yes"
  { STATIC.PLUGINLIST += glosx2d ; }

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

# Project-specific settings.
if $(TARGET.OS) = MACOS_X
{
  ApplicationIconDefaultOSX appicon.icns : $(TOP) libs csutil macosx ;
}

# Common include directory.
IncludeDir
    $(BUILDTOP)/include
    $(TOP)
    $(TOP)/include
    $(TOP)/apps
    $(TOP)/libs
    $(TOP)/plugins
    ;
