Index: data/Jamfile
===================================================================
--- data/Jamfile	(revision 2418)
+++ data/Jamfile	(working copy)
@@ -15,6 +15,6 @@
   : data ;
 
 InstallData [ Wildcard cally : *.caf *.cmf *.csf ] : data cally ;
-InstallData [ Wildcard config : *.cfg ] : data config ;
+InstallConfig [ Wildcard config : *.cfg ] ;
 InstallData [ Wildcard images : *.jpg *.png *.gif ] : data images ;
 InstallData [ Wildcard sounds : *.zip ] : data sounds ;
Index: libs/celtool/Jamfile
===================================================================
--- libs/celtool/Jamfile	(revision 2418)
+++ libs/celtool/Jamfile	(working copy)
@@ -6,3 +6,7 @@
   [ Wildcard [ ConcatDirs $(DOTDOT) $(DOTDOT) include celtool ] : *.h ] :
   shared ;
 ExternalLibs celtool : CRYSTAL ;
+
+CFlags celtool : [ FDefines CEL_CONFIGDIR='\"$(appconfdir)\"' ]
+  [ FDefines CEL_PLUGINDIR='\"$(plugindir)\"'  ] ;
+
Index: libs/celtool/initapp.cpp
===================================================================
--- libs/celtool/initapp.cpp	(revision 2418)
+++ libs/celtool/initapp.cpp	(working copy)
@@ -18,12 +18,36 @@
 
 #include "celtool/initapp.h"
 #include <csutil/syspath.h>
+#include "iutil/cfgmgr.h"
 
+#include "csutil/verbosity.h"
+#include "csutil/cfgacc.h"
+#include "csutil/cfgfile.h"
+#include "csutil/cmdline.h"
+#include "csutil/csshlib.h"
+
 // Recurse into subdirectories when scanning for plugins? Disabled presently
 // because some developers run CEL programs from within the source tree, and it
 // can be quite costly to recurse over the entire tree.
 #define CEL_PLUGIN_SCAN_RECURSE false
 
+// These defines should be set by the configure script
+#ifndef CEL_CONFIGDIR
+#ifdef CS_COMPILER_GCC
+#warning CEL_CONFIGDIR not set
+#endif
+#define CEL_CONFIGDIR "/usr/local/" CS_PACKAGE_NAME
+#endif
+#ifndef CEL_PLUGINDIR
+#ifdef CEL_COMPILER_GCC
+#warning CEL_PLUGINDIR not set
+#endif
+#define CEL_PLUGINDIR "/usr/local/" CS_PACKAGE_NAME "/lib"
+#endif
+
+
+static bool cel_config_done = false;
+
 void celInitializer::setup_plugin_dirs(iObjectRegistry* r, char const* dir0)
 {
   static bool done = false;
@@ -48,7 +72,7 @@
     }
     else
     {
-      cel_paths.AddUniqueExpanded("/usr/lib/cel/", CEL_PLUGIN_SCAN_RECURSE);
+      cel_paths.AddUniqueExpanded(CEL_PLUGINDIR, CEL_PLUGIN_SCAN_RECURSE);
     }
 
     if (dir0 != 0)
@@ -71,12 +95,68 @@
 bool celInitializer::RequestPluginsV(iObjectRegistry* r, va_list args)
 {
   SetupCelPluginDirs(r);
-  return superclass::RequestPluginsV(r, args);
+  bool const ok = superclass::RequestPluginsV(r, args);
+  LoadCelVFS(r);
+  return ok;
 }
 
 bool celInitializer::RequestPlugins(iObjectRegistry* r,
   csArray<csPluginRequest> const& a)
 {
   SetupCelPluginDirs(r);
-  return superclass::RequestPlugins(r, a);
+  bool const ok = superclass::RequestPlugins(r, a);
+  // find and add cel vfs file if its not done already
+  LoadCelVFS(r);
+  return ok;
 }
+
+bool celInitializer::LoadMountsFromFile(iObjectRegistry* r, char const* configPath)
+{
+  csRef<iConfigManager> cfg_mgr = CS_QUERY_REGISTRY(r, iConfigManager);
+  csRef<iVFS> vfs = CS_QUERY_REGISTRY(r, iVFS);
+  csRef<iConfigFile> vfs_file = cfg_mgr->AddDomain(configPath, NULL, 0);
+  return vfs->LoadMountsFromFile(vfs_file);
+}
+
+bool celInitializer::LoadCelVFS(iObjectRegistry* r)
+{
+  bool ok = false;
+  if (cel_config_done) return true;
+  // find and add cel vfs file
+  csPathsList cel_env_path;
+  csString cel_env (getenv ("CEL"));
+  // find dir
+  if (cel_env.IsEmpty())
+    cel_env_path = csPathsList(CEL_CONFIGDIR);
+  else
+  {
+    cel_env_path = csPathsList(cel_env);
+  }
+  // check vfs.cfg file is actually there.
+  csPathsList vfs_file_path = 
+	    csPathsUtilities::LocateFile(cel_env_path,"vfs.cfg");
+  if (vfs_file_path.Length())
+  {
+    csString cel_vfs_file = 
+      vfs_file_path[0].path+csString(CS_PATH_SEPARATOR)+csString("vfs.cfg");
+    ok = LoadMountsFromFile(r,cel_vfs_file);
+  }
+  /* else
+     * error goes here */
+  cel_config_done = true;
+  return ok;
+}
+
+iVFS* celInitializer::SetupVFS(iObjectRegistry* r, const char* pluginID)
+{
+  csRef<iVFS> vfs = superclass::SetupVFS(r, pluginID);
+  LoadCelVFS(r);
+  return vfs;
+}
+
+bool celInitializer::SetupConfigManager (
+		  iObjectRegistry* r, char const* configName, char const* AppID)
+{
+  SetupVFS(r);
+  return superclass::SetupConfigManager(r,configName,AppID);  
+}
Index: include/celtool/initapp.h
===================================================================
--- include/celtool/initapp.h	(revision 2418)
+++ include/celtool/initapp.h	(working copy)
@@ -40,7 +40,8 @@
 {
 private:
   typedef csInitializer superclass;
-
+  static bool LoadCelVFS(iObjectRegistry* r);
+  static bool LoadMountsFromFile(iObjectRegistry* r, char const* configPath);
 protected:
   static void setup_plugin_dirs(iObjectRegistry*, char const* detected_dir);
 
@@ -73,7 +74,8 @@
 
   /**
    * A convenience wrapper for csInitializer::RequestPlugins() which first
-   * invokes celInitializer::SetupCelPluginDirs().
+   * invokes celInitializer::SetupCelPluginDirs() and also loads cel vfs file
+   * through celInitializer::SetupVFS().
    *
    * The variable arguments should contain four entries for every plugin you
    * wish to load: SCF class name, SCF interface name, inteface ID, and
@@ -92,7 +94,8 @@
 
   /**
    * A convenience wrapper for csInitializer::RequestPlugins() which first
-   * invokes celInitializer::SetupCelPluginDirs().
+   * invokes celInitializer::SetupCelPluginDirs() and also loads cel vfs file
+   * through celInitializer::SetupVFS().
    *
    * Unlike the variable-argument RequestPlugins(...) method which expects you
    * to know the list of requested plugins at compile-time, this overload
@@ -110,6 +113,21 @@
    * terminate the list with #CS_REQUEST_END.
    */
   static bool RequestPlugins(iObjectRegistry*,csArray<csPluginRequest> const&);
+  
+  /**
+   * A convenience wrapper for csInitializer::SetupVFS that will also load
+   * cel vfs.cfg file.
+  */
+  static iVFS* SetupVFS(iObjectRegistry* objectReg,
+	                const char* pluginID = "crystalspace.kernel.vfs");
+
+  /**
+   * A convenience wrapper for csInitializer::SetupConfigManager() which makes 
+   * sure cel vfs.cfg is loaded so config files can be loaded from cel vfs.
+  */ 
+  static bool SetupConfigManager (iObjectRegistry* r, char const* configName, 
+		  	          char const* AppID = 0);
+
 };
 
 #endif // __CELTOOL_INITAPP_H__
Index: apps/celtest/celtest.cpp
===================================================================
--- apps/celtest/celtest.cpp	(revision 2418)
+++ apps/celtest/celtest.cpp	(working copy)
@@ -264,7 +264,7 @@
 
   csRef<iPcMesh> pcmesh = CEL_QUERY_PROPCLASS_ENT (entity_cam, iPcMesh);
   bool hascal3d = true;
-  pcmesh->SetPath ("/cel/data");
+  pcmesh->SetPath ("/cellib/objects");
   hascal3d = pcmesh->SetMesh ("test", "cally.cal3d");
 
   csRef<iPcLinearMovement> pclinmove = CEL_QUERY_PROPCLASS_ENT (entity_cam,
@@ -358,13 +358,12 @@
 {
   csDebuggingGraph::SetupGraph (object_reg);
 
-  if (!csInitializer::SetupConfigManager (object_reg,
+  if (!celInitializer::SetupConfigManager (object_reg,
   	"/celconfig/celtest.cfg"))
   {
     return ReportError ("Can't setup config file!");
   }
 
-
   if (!celInitializer::RequestPlugins (object_reg,
   	CS_REQUEST_VFS,
 	CS_REQUEST_OPENGL3D,
Index: Jamfile.in
===================================================================
--- Jamfile.in	(revision 2418)
+++ Jamfile.in	(working copy)
@@ -67,21 +67,29 @@
 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.
+# helper rules to create cel vfs.cfg
+rule VfsCfgGen
+{
+  Depends $(<) : $(>) ;
+  Always $(<) ;
+  Clean vfsclean : $(<) ;
+}
+
+actions VfsCfgGen
+{
+  cat $(>) > $(<)
+  echo "" >> $(<)
+  echo "; Configuration-time installation paths." >> $(<)
+  echo "VFS.$(TARGET.OS.NORMALIZED).CEL_DATADIR = $(appdatadir)/data" >> $(<)
+  echo "VFS.$(TARGET.OS.NORMALIZED).CEL_CONFIGDIR = $(appconfdir)" >> $(<)
+}
+
+# Build our own vfs.cfg
 VFS_CONFIGFILE = vfs.cfg ;
-SEARCH on $(VFS_CONFIGFILE) = $(SUBDIR) ;
+MakeLocate $(VFS_CONFIGFILE) : $(LOCATE_TARGET) ;
+SEARCH on $(VFS_CONFIGFILE) = $(LOCATE_TARGET) ;
+VfsCfgGen $(VFS_CONFIGFILE) : $(SUBDIR)/vfs.cfg.template ;
+
 Depends install_config : [ DoInstall $(VFS_CONFIGFILE) : $(appconfdir) ] ;
 
 # Generate cel-config
