Index: trunk/SophyaPI/PIext/cxxexecutor.cc
===================================================================
--- trunk/SophyaPI/PIext/cxxexecutor.cc	(revision 1276)
+++ trunk/SophyaPI/PIext/cxxexecutor.cc	(revision 1287)
@@ -5,4 +5,5 @@
 #include "strutilxx.h"
 #include "dvlist.h"
+#include "cxxcmplnk.h"
 
 #include "nomgadapter.h"
@@ -12,5 +13,6 @@
 /* --Methode-- */
 CxxExecutor::CxxExecutor(PIACmd *mpiac, PIStdImgApp* /* app */)
-  : mUserCodeFn(""), mUserFctFn(""), mCompOpt(""), mLinkOpt(""), mMyLibs("")
+  : mUserCodeFn(""), mUserFctFn("")
+  , mCompOpt(""), mLinkOpt(""), mMyLibs("")
   , mDefTmp(""), mDefRoot("cxx_spiapp"), mDefFunc("usercxx"), mPrtLevel(1)
 {
@@ -19,8 +21,7 @@
 
 // Gestion des fichiers par default dans TmpDir 
-//.... CMV a gerer mais pas forcement OK ... voir avec Rz
-//NamedObjMgr omg;
-//string tmpdir = omg.GetTmpDir();
-//if(tmpdir.size()>1) mDefTmp = tmpdir;
+NamedObjMgr omg;
+string tmpdir = omg.GetTmpDir();
+if(tmpdir.size()>1) mDefTmp = tmpdir;
 
 // On enregistre les nouvelles commandes 
@@ -49,12 +50,12 @@
 
 kw = "c++create";
-usage = "c++create: create a file to be used by spiapp\n";
+usage = "c++create: create a file \"file.cc\" to be used by spiapp\n";
 usage+= "Usage: c++create file.cc func c++ user code...\n";
 mpiac->RegisterCommand(kw, usage, this, hgrp);
 
 kw = "c++createfrf";
-usage = "c++createfrf: create a file \"file.cc\"to be used by spiapp\n";
-usage+= "              with a user file code \"fileuser.cc\"\n";
-usage+= "             and an optional user function code \"fileuserfct.cc\"\n";
+usage = "c++createfrf: create a file \"file.cc\" to be used by spiapp\n";
+usage+= "        with a user file code \"fileuser.cc\"\n";
+usage+= "        and an optional user function code \"fileuserfct.cc\"\n";
 usage+= "Usage: c++createfrf file.cc func fileuser.cc [fileuserfct.cc]\n";
 mpiac->RegisterCommand(kw, usage, this, hgrp);
@@ -130,4 +131,6 @@
   rc = FillUserCode(tokens[0]); if(rc) return(1);
   if(tokens.size()>1) rc = FillUserFctFrF(tokens[1]);
+    else              rc = FillUserFctFrF();
+  if(rc) return(1);
   rc = CrFile();   if(rc) return(1);
   rc = Compile();  if(rc) return(1);
@@ -145,6 +148,7 @@
     return(1);
   }
-  rc = FillUserCode(toks,2);       if(rc) return(1);
-  rc = CrFile(tokens[0],tokens[1]);  if(rc) return(1);
+  rc = FillUserCode(toks,2);        if(rc) return(1);
+  rc = FillUserFctFrS();            if(rc) return(1);
+  rc = CrFile(tokens[0],tokens[1]); if(rc) return(1);
 
 } else if(kw == "c++createfrf") {
@@ -154,5 +158,7 @@
   }
   rc = FillUserCode(tokens[2]); if(rc) return(1);
-  if(tokens.size()>3) FillUserFctFrF(tokens[3]);
+  if(tokens.size()>3) rc = FillUserFctFrF(tokens[3]);
+    else              rc = FillUserFctFrF(tokens[3]);
+  if(rc) return(1);
   rc = CrFile(tokens[0],tokens[1]); if(rc) return(1);
 
@@ -197,5 +203,5 @@
 int rc=0;
 rc = FillUserCode(usercode,0); if(rc) return(1);
-rc = FillUserFctFrS(userfct);
+rc = FillUserFctFrS(userfct);  if(rc) return(1);
 rc = CrFile();   if(rc) return(1);
 rc = Compile();  if(rc) return(1);
@@ -207,6 +213,8 @@
 /* --Methode-- */
 int CxxExecutor::CrFile(string cfilename,string func)
+// Si un nom n'est pas precise alors TmpDir/cxx_spiapp.cc
 {
 if(cfilename.size()<1) cfilename = mDefTmp + mDefRoot + ".cc";
+
 if(func.size()<1) func = mDefFunc;
 
@@ -370,6 +378,7 @@
 /* --Methode-- */
 int CxxExecutor::FillUserCode(string& usercode,uint_4 first)
+// User code is read from input.
 // - first is the first position in the "string" where the code starts
-// User code is read from input. It is put into file "TmpDir/cxx_spiapp.h".
+// - Code is put into file "TmpDir/cxx_spiapp.h".
 {
 mUserCodeFn = "";
@@ -405,15 +414,15 @@
 
 /* --Methode-- */
-int CxxExecutor::FillUserFctFrS(string userfct)
+int CxxExecutor::FillUserFctFrS(string userfctcode)
 // - Fill user Fonction code from string "userfct"
-// It is put into file "TmpDir/cxx_spiapp_fct.h".
+// - Code is put into file "TmpDir/cxx_spiapp_fct.h".
 {
 mUserFctFn  = "";
-if(userfct.size()<1) return 0;
+if(userfctcode.size()<1) return 0;
 mUserFctFn  = mDefTmp + mDefRoot + "_fct.h";
 ofstream os(mUserFctFn.c_str(),ios::out);
 if(!os) {cout<<"CxxExecutor::FillUserFctFrS: unable to open "
              <<mUserFctFn<<endl;  mUserFctFn = ""; return 1;}
-os<<userfct<<endl;
+os<<userfctcode<<endl;
 if(mPrtLevel)
   cout<<"User Function code filled from standard input into "<<mUserFctFn<<endl;
@@ -433,4 +442,5 @@
 /* --Methode-- */
 int CxxExecutor::FillUserFctFrF(string filefctname)
+// User function code is read from "filefctname".
 {
 mUserFctFn = filefctname;
@@ -442,62 +452,104 @@
 /* --Methode-- */
 int CxxExecutor::Compile(string rootfilename)
-{
-if(rootfilename.size()<1) rootfilename = mDefRoot;
-if(mPrtLevel) cout<<"Compile: "<<rootfilename<<endl;
-int rc = 0;
-rc = CrMakefile();
-if(rc) return(1);
-string make  = "";
-make += "make -f " + mDefRoot + "_Makefile";
-make += " CXXFLAGS=\"" + mCompOpt + "\"";
-make += " LDFLAGS=\""  + mLinkOpt + "\"";
-make += " MYLIBS=\""   + mMyLibs  + "\"";
-make += " " + rootfilename;
-rc = system(make.c_str());
-if(rc)
-  {cout<<"CxxExecutor::Compile : \n"<<make<<" Failed"<<endl;
-   return 1000+rc;}
-return 0;
-}
-
-/* --Methode-- */
-int CxxExecutor::CrMakefile(void)
-{
-string makename = mDefTmp + mDefRoot + "_Makefile";
-ofstream os(makename.c_str(),ios::out);
-if(!os)
-  {cout<<"CxxExecutor::CrMakefile: unable to open file for Makefile"<<endl;
-   return 1;}
+//--------------------------------------------------------//
+// rootfilename = | name           | "" ou (default)      //
+//--------------------------------------------------------//
+// fichier .cc    | name.cc        | TmpDir/cxx_spiapp.cc //
+//                | ../dir/name.cc |                      //
+// fichier .o     | TmpDir/name.o  | TmpDir/cxx_spiapp.o  //
+// fichier .so    | TmpDir/name.so | TmpDir/cxx_spiapp.so //
+//--------------------------------------------------------//
+{
+if(rootfilename.size()<1) rootfilename = mDefTmp + mDefRoot;
+if(mPrtLevel) cout<<"Compile "<<rootfilename<<endl;
+
+int rc;
+CxxCompilerLinker cxx;
+if(mDefTmp.size()>0) cxx.SetTmpDir(mDefTmp);
+cxx.SetVerbose(true);
+
+// Compilation
+string fcc = rootfilename + ".cc";
+string fo  = "";
+cxx.AddCompileOptions(mCompOpt);
+rc = cxx.Compile(fcc,fo);
+if(mPrtLevel) cout << "Compilation rc = "<<rc<< endl;
+if(rc) return 1;
+
+// Fabrication Shared Lib.
+string fso = "";
+cxx.AddLinkOptions(mLinkOpt);
+ string sophlib = "-lPI";
+cxx.AddLinkOptions(sophlib);
+cxx.AddLinkOptions(mMyLibs);
+rc = cxx.BuildSO(fo,fso);
+if(mPrtLevel) cout << "Shared Library rc = "<<rc<< endl;
+if(rc) return 2;
+
+return 0;
+}
+
+/* --Methode-- */
+//int CxxExecutor::Compile(string rootfilename)
+// Ne marche pas si TmpDir != ""
+//{
+//if(rootfilename.size()<1) rootfilename = mDefRoot;
+//if(mPrtLevel) cout<<"Compile: "<<rootfilename<<endl;
+//int rc = 0;
+//rc = CrMakefile();
+//if(rc) return(1);
+//string make  = "";
+//make += "make -f " + mDefRoot + "_Makefile";
+//make += " CXXFLAGS=\"" + mCompOpt + "\"";
+//make += " LDFLAGS=\""  + mLinkOpt + "\"";
+//make += " MYLIBS=\""   + mMyLibs  + "\"";
+//make += " " + rootfilename;
+//rc = system(make.c_str());
+//if(rc)
+//  {cout<<"CxxExecutor::Compile : \n"<<make<<" Failed"<<endl;
+//   return 1000+rc;}
+//return 0;
+//}
+
+/* --Methode-- */
+//int CxxExecutor::CrMakefile(void)
+// Ne marche pas si TmpDir != ""
+//{
+//string makename = mDefTmp + mDefRoot + "_Makefile";
+//ofstream os(makename.c_str(),ios::out);
+//if(!os)
+//  {cout<<"CxxExecutor::CrMakefile: unable to open file for Makefile"<<endl;
+//   return 1;}
 //---------------------------------------------------------------------
-os<<"MODULEDECCXXFLAGS := -msg_quiet"<<endl;
-os<<"include $(DPCBASEREP)/Include/MakefileUser.h"<<endl;
-os<<"MYLIBS ="<<endl;
-os<<"LIBS = -L$(SLB) -lPI -lextsophya -lsophya -lm"<<endl;
-os<<"ifeq ($(MACHEROS),OSF1)"<<endl;
-os<<"LIBS := $(LIBS) -lfor"<<endl;
-os<<"endif"<<endl;
-os<<"ifeq ($(MACHEROS),Linux)"<<endl;
-os<<"LIBS := $(LIBS) -ldl -lf2c"<<endl;
-os<<"endif"<<endl;
-os<<"%.so:%.o"<<endl;
-os<<"%:%.cc"<<endl;
-os<<"%:%.o"<<endl;
-os<<"%.o:%.cc"<<endl;
-os<<"%.o:%.c"<<endl;
-os<<"%:%.c"<<endl;
-os<<endl;
-os<<".PRECIOUS: %.so"<<endl;
-os<<endl;
-os<<"%:%.so"<<endl;
-os<<"\t"<<"echo $@ \" made (.so) \""<<endl;
-os<<"%.so:%.o"<<endl;
-os<<"\t"<<"$(LINK.cc) -shared -o $@ $< $(LIBS) $(MYLIBS)"<<endl;
-os<<"%.o:%.cc"<<endl;
-os<<"\t"<<"$(COMPILE.cc) -o $@ $<"<<endl;
-os<<"%.o:%.c"<<endl;
-os<<"\t"<<"$(COMPILE.c) -c $(CFLAGS) $(USERFLAGS) -o $@ $<"<<endl;
+//os<<"MODULEDECCXXFLAGS := -msg_quiet"<<endl;
+//os<<"include $(DPCBASEREP)/Include/MakefileUser.h"<<endl;
+//os<<"MYLIBS ="<<endl;
+//os<<"LIBS = -L$(SLB) -lPI -lextsophya -lsophya -lm"<<endl;
+//os<<"ifeq ($(MACHEROS),OSF1)"<<endl;
+//os<<"LIBS := $(LIBS) -lfor"<<endl;
+//os<<"endif"<<endl;
+//os<<"ifeq ($(MACHEROS),Linux)"<<endl;
+//os<<"LIBS := $(LIBS) -ldl -lf2c"<<endl;
+//os<<"endif"<<endl;
+//os<<"%.so:%.o"<<endl;
+//os<<"%:%.cc"<<endl;
+//os<<"%:%.o"<<endl;
+//os<<"%.o:%.cc"<<endl;
+//os<<"%.o:%.c"<<endl;
+//os<<"%:%.c"<<endl;
+//os<<endl;
+//os<<".PRECIOUS: %.so"<<endl;
+//os<<endl;
+//os<<"%:%.so"<<endl;
+//os<<"\t"<<"echo $@ \" made (.so) \""<<endl;
+//os<<"%.so:%.o"<<endl;
+//os<<"\t"<<"$(LINK.cc) -shared -o $@ $< $(LIBS) $(MYLIBS)"<<endl;
+//os<<"%.o:%.cc"<<endl;
+//os<<"\t"<<"$(COMPILE.cc) -o $@ $<"<<endl;
+//os<<"%.o:%.c"<<endl;
+//os<<"\t"<<"$(COMPILE.c) -c $(CFLAGS) $(USERFLAGS) -o $@ $<"<<endl;
 //---------------------------------------------------------------------
-return 0;
-}
+//return 0;
+//}
 
 /* --Methode-- */
@@ -505,8 +557,10 @@
 {
 if(libname.size()<1) libname = mDefTmp + mDefRoot + ".so";
+  else               libname = mDefTmp + libname;
 if(func.size()<1) func = mDefFunc;
 
 NamedObjMgr omg;
 PIACmd* mpiac = omg.GetImgApp()->CmdInterpreter();
+
 string key("linkff2");
 vector<string> arg; arg.push_back(libname); arg.push_back(func);
@@ -514,5 +568,5 @@
 int rc = mpiac->ExecuteCommand(key,arg,toks);
 if(mPrtLevel) cout<<"Link from "<<libname<<" for function "<<func
-                 <<" (rc="<<rc<<")"<<endl;
+                  <<" (rc="<<rc<<")"<<endl;
 return 0;
 }
@@ -525,4 +579,5 @@
 NamedObjMgr omg;
 PIACmd* mpiac = omg.GetImgApp()->CmdInterpreter();
+
 string key("call");
 vector<string> arg; arg.push_back(func);
