Changeset 1287 in Sophya for trunk/SophyaPI/PIext/cxxexecutor.cc


Ignore:
Timestamp:
Nov 2, 2000, 7:44:21 PM (25 years ago)
Author:
ercodmgr
Message:

utilisation du cxxcmplnk cmv 2/11/00

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PIext/cxxexecutor.cc

    r1276 r1287  
    55#include "strutilxx.h"
    66#include "dvlist.h"
     7#include "cxxcmplnk.h"
    78
    89#include "nomgadapter.h"
     
    1213/* --Methode-- */
    1314CxxExecutor::CxxExecutor(PIACmd *mpiac, PIStdImgApp* /* app */)
    14   : mUserCodeFn(""), mUserFctFn(""), mCompOpt(""), mLinkOpt(""), mMyLibs("")
     15  : mUserCodeFn(""), mUserFctFn("")
     16  , mCompOpt(""), mLinkOpt(""), mMyLibs("")
    1517  , mDefTmp(""), mDefRoot("cxx_spiapp"), mDefFunc("usercxx"), mPrtLevel(1)
    1618{
     
    1921
    2022// Gestion des fichiers par default dans TmpDir
    21 //.... CMV a gerer mais pas forcement OK ... voir avec Rz
    22 //NamedObjMgr omg;
    23 //string tmpdir = omg.GetTmpDir();
    24 //if(tmpdir.size()>1) mDefTmp = tmpdir;
     23NamedObjMgr omg;
     24string tmpdir = omg.GetTmpDir();
     25if(tmpdir.size()>1) mDefTmp = tmpdir;
    2526
    2627// On enregistre les nouvelles commandes
     
    4950
    5051kw = "c++create";
    51 usage = "c++create: create a file to be used by spiapp\n";
     52usage = "c++create: create a file \"file.cc\" to be used by spiapp\n";
    5253usage+= "Usage: c++create file.cc func c++ user code...\n";
    5354mpiac->RegisterCommand(kw, usage, this, hgrp);
    5455
    5556kw = "c++createfrf";
    56 usage = "c++createfrf: create a file \"file.cc\"to be used by spiapp\n";
    57 usage+= "              with a user file code \"fileuser.cc\"\n";
    58 usage+= "             and an optional user function code \"fileuserfct.cc\"\n";
     57usage = "c++createfrf: create a file \"file.cc\" to be used by spiapp\n";
     58usage+= "        with a user file code \"fileuser.cc\"\n";
     59usage+= "        and an optional user function code \"fileuserfct.cc\"\n";
    5960usage+= "Usage: c++createfrf file.cc func fileuser.cc [fileuserfct.cc]\n";
    6061mpiac->RegisterCommand(kw, usage, this, hgrp);
     
    130131  rc = FillUserCode(tokens[0]); if(rc) return(1);
    131132  if(tokens.size()>1) rc = FillUserFctFrF(tokens[1]);
     133    else              rc = FillUserFctFrF();
     134  if(rc) return(1);
    132135  rc = CrFile();   if(rc) return(1);
    133136  rc = Compile();  if(rc) return(1);
     
    145148    return(1);
    146149  }
    147   rc = FillUserCode(toks,2);       if(rc) return(1);
    148   rc = CrFile(tokens[0],tokens[1]);  if(rc) return(1);
     150  rc = FillUserCode(toks,2);        if(rc) return(1);
     151  rc = FillUserFctFrS();            if(rc) return(1);
     152  rc = CrFile(tokens[0],tokens[1]); if(rc) return(1);
    149153
    150154} else if(kw == "c++createfrf") {
     
    154158  }
    155159  rc = FillUserCode(tokens[2]); if(rc) return(1);
    156   if(tokens.size()>3) FillUserFctFrF(tokens[3]);
     160  if(tokens.size()>3) rc = FillUserFctFrF(tokens[3]);
     161    else              rc = FillUserFctFrF(tokens[3]);
     162  if(rc) return(1);
    157163  rc = CrFile(tokens[0],tokens[1]); if(rc) return(1);
    158164
     
    197203int rc=0;
    198204rc = FillUserCode(usercode,0); if(rc) return(1);
    199 rc = FillUserFctFrS(userfct);
     205rc = FillUserFctFrS(userfct);  if(rc) return(1);
    200206rc = CrFile();   if(rc) return(1);
    201207rc = Compile();  if(rc) return(1);
     
    207213/* --Methode-- */
    208214int CxxExecutor::CrFile(string cfilename,string func)
     215// Si un nom n'est pas precise alors TmpDir/cxx_spiapp.cc
    209216{
    210217if(cfilename.size()<1) cfilename = mDefTmp + mDefRoot + ".cc";
     218
    211219if(func.size()<1) func = mDefFunc;
    212220
     
    370378/* --Methode-- */
    371379int CxxExecutor::FillUserCode(string& usercode,uint_4 first)
     380// User code is read from input.
    372381// - first is the first position in the "string" where the code starts
    373 // User code is read from input. It is put into file "TmpDir/cxx_spiapp.h".
     382// - Code is put into file "TmpDir/cxx_spiapp.h".
    374383{
    375384mUserCodeFn = "";
     
    405414
    406415/* --Methode-- */
    407 int CxxExecutor::FillUserFctFrS(string userfct)
     416int CxxExecutor::FillUserFctFrS(string userfctcode)
    408417// - Fill user Fonction code from string "userfct"
    409 // It is put into file "TmpDir/cxx_spiapp_fct.h".
     418// - Code is put into file "TmpDir/cxx_spiapp_fct.h".
    410419{
    411420mUserFctFn  = "";
    412 if(userfct.size()<1) return 0;
     421if(userfctcode.size()<1) return 0;
    413422mUserFctFn  = mDefTmp + mDefRoot + "_fct.h";
    414423ofstream os(mUserFctFn.c_str(),ios::out);
    415424if(!os) {cout<<"CxxExecutor::FillUserFctFrS: unable to open "
    416425             <<mUserFctFn<<endl;  mUserFctFn = ""; return 1;}
    417 os<<userfct<<endl;
     426os<<userfctcode<<endl;
    418427if(mPrtLevel)
    419428  cout<<"User Function code filled from standard input into "<<mUserFctFn<<endl;
     
    433442/* --Methode-- */
    434443int CxxExecutor::FillUserFctFrF(string filefctname)
     444// User function code is read from "filefctname".
    435445{
    436446mUserFctFn = filefctname;
     
    442452/* --Methode-- */
    443453int CxxExecutor::Compile(string rootfilename)
    444 {
    445 if(rootfilename.size()<1) rootfilename = mDefRoot;
    446 if(mPrtLevel) cout<<"Compile: "<<rootfilename<<endl;
    447 int rc = 0;
    448 rc = CrMakefile();
    449 if(rc) return(1);
    450 string make  = "";
    451 make += "make -f " + mDefRoot + "_Makefile";
    452 make += " CXXFLAGS=\"" + mCompOpt + "\"";
    453 make += " LDFLAGS=\""  + mLinkOpt + "\"";
    454 make += " MYLIBS=\""   + mMyLibs  + "\"";
    455 make += " " + rootfilename;
    456 rc = system(make.c_str());
    457 if(rc)
    458   {cout<<"CxxExecutor::Compile : \n"<<make<<" Failed"<<endl;
    459    return 1000+rc;}
    460 return 0;
    461 }
    462 
    463 /* --Methode-- */
    464 int CxxExecutor::CrMakefile(void)
    465 {
    466 string makename = mDefTmp + mDefRoot + "_Makefile";
    467 ofstream os(makename.c_str(),ios::out);
    468 if(!os)
    469   {cout<<"CxxExecutor::CrMakefile: unable to open file for Makefile"<<endl;
    470    return 1;}
     454//--------------------------------------------------------//
     455// rootfilename = | name           | "" ou (default)      //
     456//--------------------------------------------------------//
     457// fichier .cc    | name.cc        | TmpDir/cxx_spiapp.cc //
     458//                | ../dir/name.cc |                      //
     459// fichier .o     | TmpDir/name.o  | TmpDir/cxx_spiapp.o  //
     460// fichier .so    | TmpDir/name.so | TmpDir/cxx_spiapp.so //
     461//--------------------------------------------------------//
     462{
     463if(rootfilename.size()<1) rootfilename = mDefTmp + mDefRoot;
     464if(mPrtLevel) cout<<"Compile "<<rootfilename<<endl;
     465
     466int rc;
     467CxxCompilerLinker cxx;
     468if(mDefTmp.size()>0) cxx.SetTmpDir(mDefTmp);
     469cxx.SetVerbose(true);
     470
     471// Compilation
     472string fcc = rootfilename + ".cc";
     473string fo  = "";
     474cxx.AddCompileOptions(mCompOpt);
     475rc = cxx.Compile(fcc,fo);
     476if(mPrtLevel) cout << "Compilation rc = "<<rc<< endl;
     477if(rc) return 1;
     478
     479// Fabrication Shared Lib.
     480string fso = "";
     481cxx.AddLinkOptions(mLinkOpt);
     482 string sophlib = "-lPI";
     483cxx.AddLinkOptions(sophlib);
     484cxx.AddLinkOptions(mMyLibs);
     485rc = cxx.BuildSO(fo,fso);
     486if(mPrtLevel) cout << "Shared Library rc = "<<rc<< endl;
     487if(rc) return 2;
     488
     489return 0;
     490}
     491
     492/* --Methode-- */
     493//int CxxExecutor::Compile(string rootfilename)
     494// Ne marche pas si TmpDir != ""
     495//{
     496//if(rootfilename.size()<1) rootfilename = mDefRoot;
     497//if(mPrtLevel) cout<<"Compile: "<<rootfilename<<endl;
     498//int rc = 0;
     499//rc = CrMakefile();
     500//if(rc) return(1);
     501//string make  = "";
     502//make += "make -f " + mDefRoot + "_Makefile";
     503//make += " CXXFLAGS=\"" + mCompOpt + "\"";
     504//make += " LDFLAGS=\""  + mLinkOpt + "\"";
     505//make += " MYLIBS=\""   + mMyLibs  + "\"";
     506//make += " " + rootfilename;
     507//rc = system(make.c_str());
     508//if(rc)
     509//  {cout<<"CxxExecutor::Compile : \n"<<make<<" Failed"<<endl;
     510//   return 1000+rc;}
     511//return 0;
     512//}
     513
     514/* --Methode-- */
     515//int CxxExecutor::CrMakefile(void)
     516// Ne marche pas si TmpDir != ""
     517//{
     518//string makename = mDefTmp + mDefRoot + "_Makefile";
     519//ofstream os(makename.c_str(),ios::out);
     520//if(!os)
     521//  {cout<<"CxxExecutor::CrMakefile: unable to open file for Makefile"<<endl;
     522//   return 1;}
    471523//---------------------------------------------------------------------
    472 os<<"MODULEDECCXXFLAGS := -msg_quiet"<<endl;
    473 os<<"include $(DPCBASEREP)/Include/MakefileUser.h"<<endl;
    474 os<<"MYLIBS ="<<endl;
    475 os<<"LIBS = -L$(SLB) -lPI -lextsophya -lsophya -lm"<<endl;
    476 os<<"ifeq ($(MACHEROS),OSF1)"<<endl;
    477 os<<"LIBS := $(LIBS) -lfor"<<endl;
    478 os<<"endif"<<endl;
    479 os<<"ifeq ($(MACHEROS),Linux)"<<endl;
    480 os<<"LIBS := $(LIBS) -ldl -lf2c"<<endl;
    481 os<<"endif"<<endl;
    482 os<<"%.so:%.o"<<endl;
    483 os<<"%:%.cc"<<endl;
    484 os<<"%:%.o"<<endl;
    485 os<<"%.o:%.cc"<<endl;
    486 os<<"%.o:%.c"<<endl;
    487 os<<"%:%.c"<<endl;
    488 os<<endl;
    489 os<<".PRECIOUS: %.so"<<endl;
    490 os<<endl;
    491 os<<"%:%.so"<<endl;
    492 os<<"\t"<<"echo $@ \" made (.so) \""<<endl;
    493 os<<"%.so:%.o"<<endl;
    494 os<<"\t"<<"$(LINK.cc) -shared -o $@ $< $(LIBS) $(MYLIBS)"<<endl;
    495 os<<"%.o:%.cc"<<endl;
    496 os<<"\t"<<"$(COMPILE.cc) -o $@ $<"<<endl;
    497 os<<"%.o:%.c"<<endl;
    498 os<<"\t"<<"$(COMPILE.c) -c $(CFLAGS) $(USERFLAGS) -o $@ $<"<<endl;
     524//os<<"MODULEDECCXXFLAGS := -msg_quiet"<<endl;
     525//os<<"include $(DPCBASEREP)/Include/MakefileUser.h"<<endl;
     526//os<<"MYLIBS ="<<endl;
     527//os<<"LIBS = -L$(SLB) -lPI -lextsophya -lsophya -lm"<<endl;
     528//os<<"ifeq ($(MACHEROS),OSF1)"<<endl;
     529//os<<"LIBS := $(LIBS) -lfor"<<endl;
     530//os<<"endif"<<endl;
     531//os<<"ifeq ($(MACHEROS),Linux)"<<endl;
     532//os<<"LIBS := $(LIBS) -ldl -lf2c"<<endl;
     533//os<<"endif"<<endl;
     534//os<<"%.so:%.o"<<endl;
     535//os<<"%:%.cc"<<endl;
     536//os<<"%:%.o"<<endl;
     537//os<<"%.o:%.cc"<<endl;
     538//os<<"%.o:%.c"<<endl;
     539//os<<"%:%.c"<<endl;
     540//os<<endl;
     541//os<<".PRECIOUS: %.so"<<endl;
     542//os<<endl;
     543//os<<"%:%.so"<<endl;
     544//os<<"\t"<<"echo $@ \" made (.so) \""<<endl;
     545//os<<"%.so:%.o"<<endl;
     546//os<<"\t"<<"$(LINK.cc) -shared -o $@ $< $(LIBS) $(MYLIBS)"<<endl;
     547//os<<"%.o:%.cc"<<endl;
     548//os<<"\t"<<"$(COMPILE.cc) -o $@ $<"<<endl;
     549//os<<"%.o:%.c"<<endl;
     550//os<<"\t"<<"$(COMPILE.c) -c $(CFLAGS) $(USERFLAGS) -o $@ $<"<<endl;
    499551//---------------------------------------------------------------------
    500 return 0;
    501 }
     552//return 0;
     553//}
    502554
    503555/* --Methode-- */
     
    505557{
    506558if(libname.size()<1) libname = mDefTmp + mDefRoot + ".so";
     559  else               libname = mDefTmp + libname;
    507560if(func.size()<1) func = mDefFunc;
    508561
    509562NamedObjMgr omg;
    510563PIACmd* mpiac = omg.GetImgApp()->CmdInterpreter();
     564
    511565string key("linkff2");
    512566vector<string> arg; arg.push_back(libname); arg.push_back(func);
     
    514568int rc = mpiac->ExecuteCommand(key,arg,toks);
    515569if(mPrtLevel) cout<<"Link from "<<libname<<" for function "<<func
    516                  <<" (rc="<<rc<<")"<<endl;
     570                  <<" (rc="<<rc<<")"<<endl;
    517571return 0;
    518572}
     
    525579NamedObjMgr omg;
    526580PIACmd* mpiac = omg.GetImgApp()->CmdInterpreter();
     581
    527582string key("call");
    528583vector<string> arg; arg.push_back(func);
Note: See TracChangeset for help on using the changeset viewer.