SubDir TOP plugins behaviourlayer python ;

if $(PYTHON.AVAILABLE) = yes
{
  #--------
  # pycel.py marshalling
  #--------
  local pycelcpp = [ DoSourceGrist PYCEL_py.cpp ] ;
  MarshallPyFile $(pycelcpp) : pycel.py : [ ConcatDirs $(TOP) scripts ] ;

  #--------
  # Swig-generated files.
  #--------
  local blcelcpp = blcel.cpp ;
  local blcelpy = [ DoSourceGrist blcelc.py ] ;
  MakeLocate $(blcelpy) : $(LOCATE.TARGETS) ;

  if ! [ Property build : projgen ]
  {
    blcelcpp = [ DoSourceGrist $(blcelcpp) ] ;

    if $(CMD.SWIG)
    {
      Swig $(blcelcpp) $(blcelpy) :
        [ DoSourceGrist blcel.i ] :
        python :
	-c++ -shadow $(CRYSTAL.CFLAGS) :
	[ ConcatDirs $(TOP) include ] :
	:
	$(SEARCH_SOURCE) [ ConcatDirs $(TOP) scripts ] :
	blcel :
	[ on $(blcelpy) GetVar LOCATE ] ;
      Depends blpythonclean : blcelswigclean ;
    }
    else
    {
      SEARCH on $(blcelcpp) = $(SEARCH_SOURCE) ;
      local frozenpy = $(blcelpy:G=frozenblcelpy) ;
      SEARCH on $(frozenpy) = [ ConcatDirs $(TOP) scripts ] ;
      Copy $(blcelpy) : $(frozenpy) ;
      Depends $(blcelpy) : $(frozenpy) ;
    }
  }
  Clean blpythonclean : $(blcelpy) ;

  rule InstallCelPythonPY
  {
    # Temporary override for InstallData.
    local SUBDIR = [ on $(<) GetVar LOCATE ] ;
    InstallData $(<) : $(>) ;
  }
  InstallCelPythonPY $(blcelpy) : bindings python ;


  #--------
  # blpython plugin.
  #--------
  Plugin blpython : $(blcelcpp) blpython.cpp blpython.h pytocel.cpp PYCEL_py.cpp ;
  LinkWith blpython : celtool ;
  ExternalLibs blpython : PYTHON CRYSTAL ;
  CFlags blpython :
    $(COMPILER.C++FLAGS.WARNING.NO_UNUSED) 
    $(COMPILER.C++FLAGS.WARNING.NO_UNINITIALIZED)
    $(COMPILER.C++FLAGS.STRICTALIASING.DISABLE) ;
}
