TOP ?= "@top_srcdir@" ;
BUILDTOP ?= "@top_builddir@" ;

SubDir TOP ;

IncludeDir ;
IncludeDir "include" ;
IncludeDir $(BUILDTOP) : : literal transient ;

# Construct a distclean target
CleanDir clean : out ;

Clean distclean : configure.lineno config.status config.status.lineno
		  config.log config.cache aclocal.m4
		  Jamconfig Jamfile ;
CleanDir distclean : autom4te.cache ;
Depends distclean : clean ;
Help distclean : "Remove configuration information and built targets" ;

Clean maintainerclean : configure aclocal.m4 config.h.in ;
Depends maintainerclean : distclean ;

# Enable msvcgen
MsvcGenVariable customize : custom.cslib ;
MsvcGenSubDir TOP msvc : common ;
MsvcGenSubDir TOP msvc 7 : 7 ;
MsvcGenSubDir TOP msvc 71 : 71 ;
MsvcGenSubDir TOP msvc 8 : 8 ;
MsvcGenTemplateDir TOP mk msvcgen ;
# What the typical user will need. 
MsvcGenWorkspace cel : : "grp.+_(?!cel$)" static ;
# Workspace for static variants of plugins and apps.
MsvcGenWorkspace static : static ^lib.* : "grp.+_(?!static$)" ;

local hash = "\$" ;
MsvcGenConfig CRYSTAL.AVAILABLE : yes ;
MsvcGenConfig CRYSTAL.DEFINES ;
MsvcGenConfig CRYSTAL.CFLAGS ;
MsvcGenConfig CRYSTAL.LFLAGS ;
MsvcGenConfig CRYSTAL.LIBS : "libcrystalspace.lib" ;
MsvcGenConfig CRYSTAL.LIBS.DEBUG : "libcrystalspace_d.lib" ;
MsvcGenConfig CRYSTAL.INCDIRS :
  [ ConcatDirs .. .. .. CS include ]
  [ ConcatDirs .. .. .. CS include csutil win32 ]
  [ ConcatDirs "$(hash)(CRYSTAL)" include ]
  [ ConcatDirs "$(hash)(CRYSTAL)" include csutil win32 ] ;
MsvcGenConfig CRYSTAL.LIBDIRS :
  [ ConcatDirs .. .. .. CS out release$(MSVC_VERSION) libs ]
  [ ConcatDirs .. .. .. CS libs csutil win32 libs ]
  [ ConcatDirs "$(hash)(CRYSTAL)" out release$(MSVC_VERSION) libs ]
  [ ConcatDirs "$(hash)(CRYSTAL)" libs csutil win32 libs ] ;
MsvcGenConfig CRYSTAL.LIBDIRS.DEBUG :
  [ ConcatDirs .. .. .. CS out debug$(MSVC_VERSION) libs ]
  [ ConcatDirs .. .. .. CS libs csutil win32 libs ]
  [ ConcatDirs "$(hash)(CRYSTAL)" out debug$(MSVC_VERSION) libs ]
  [ ConcatDirs "$(hash)(CRYSTAL)" libs csutil win32 libs ] ;
MsvcGenConfig CRYSTAL.STATICDEPS : $(TOP)/crystalspace_staticplugins_msvc.jam ;
MsvcGenConfig HAVE_STATIC_PLUGINS : yes ;

MsvcGenConfig PYTHON.AVAILABLE : no ;

# Header subdirectories (order sensitive: libraries before plugins and apps)
SubInclude TOP docs ;
SubInclude TOP "include" ;
SubInclude TOP libs ;
SubInclude TOP plugins ;
SubInclude TOP apps ;
SubInclude TOP data ;

# Install vfs.cfg
# @@@ FIXME: There are at least two problems which prevent our vfs.cfg from
#     working properly once installed:
# (1) It incorrectly mounts directories relative to $*, the application
#     resource directory, rather than relative to the CEL installation
#     directory.  We need instead to install a specially customized version of
#     vfs.cfg.
# (2) VFS will never see our installed vfs.cfg because it only scans the
#     application resource directory, the application directory, and the CS
#     installation directory for vfs.cfg files; and there is no API allowing us
#     to tell VFS to scan for additional foreign vfs.cfg files, such as ours.
#     To resolve this issue, VFS and/or csInitializer API will need to be
#     updated to allow specification of foreign configuration locations.
VFS_CONFIGFILE = vfs.cfg ;
SEARCH on $(VFS_CONFIGFILE) = $(SUBDIR) ;
Depends install_config : [ DoInstall $(VFS_CONFIGFILE) : $(appconfdir) ] ;

# Generate cel-config
rule CelConfigGen
{
  SEARCH on $(>) = $(SUBDIR) ;
  MakeLocate $(<) : $(LOCATE.TARGETS) ;
  Depends $(<) : $(>) ;
  Clean $(<)clean : $(<) ;
  Depends clean : $(<)clean ;
}

rule CelLocalLinkName
{
  local lflag = $(<) ;
  local Lflag = $(LOCATE.OBJECTS)/libs ;
  exportsummary += $(lflag) ;
  exportsummary += $(Lflag) ;
}

exportlibs ?= "celtool" ;

rule CollectLinkOptions
{
  for entry in $(exportlibs)
  {
    CelLocalLinkName $(entry) ;
  }
}

CollectLinkOptions ;

actions CelConfigGen
{
  cat > $(<) << __END__
#!/bin/sh
# cel-config -- Autogenerated.

prefix="$(prefix)"
exec_prefix="$(exec_prefix)"
appincdir="$(appincdir)"
libdir="$(libdir)"
plugindir="$(plugindir)"
version="$(PACKAGE_VERSION)"
packagename="$(PACKAGE_NAME)"
makeout="$(LOCATE.OBJECTS)"
longversion="$(PACKAGE_STRING)"
exportsummary=" $(exportsummary) "
libs="$(exportlibs)"
staticdeps="$(STATICPLUGINS.DEPENDENCIES)"
optlibs="$(INSTALLEDLIBS_OPTIONAL)"

__END__
  cat $(>) >> $(<)
  chmod +x $(<)
}

CelConfigGen cel-config : cel-config.template ;
Depends cel-config : Jamfile Jamconfig ;
Depends all : cel-config ;
Depends install_bin :
  [ DoInstall cel-config : $(bindir) : $(INSTALL_PROGRAM) ] ;

# Deprecated...
SEARCH on cel.cex = $(SUBDIR) ;
Depends install_bin : [ DoInstall cel.cex : $(bindir) : $(INSTALL_PROGRAM) ] ;
