Changeset 1287 in Sophya for trunk/SophyaPI/PIext/cxxexecutor.cc
- Timestamp:
- Nov 2, 2000, 7:44:21 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/cxxexecutor.cc
r1276 r1287 5 5 #include "strutilxx.h" 6 6 #include "dvlist.h" 7 #include "cxxcmplnk.h" 7 8 8 9 #include "nomgadapter.h" … … 12 13 /* --Methode-- */ 13 14 CxxExecutor::CxxExecutor(PIACmd *mpiac, PIStdImgApp* /* app */) 14 : mUserCodeFn(""), mUserFctFn(""), mCompOpt(""), mLinkOpt(""), mMyLibs("") 15 : mUserCodeFn(""), mUserFctFn("") 16 , mCompOpt(""), mLinkOpt(""), mMyLibs("") 15 17 , mDefTmp(""), mDefRoot("cxx_spiapp"), mDefFunc("usercxx"), mPrtLevel(1) 16 18 { … … 19 21 20 22 // 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; 23 NamedObjMgr omg; 24 string tmpdir = omg.GetTmpDir(); 25 if(tmpdir.size()>1) mDefTmp = tmpdir; 25 26 26 27 // On enregistre les nouvelles commandes … … 49 50 50 51 kw = "c++create"; 51 usage = "c++create: create a file to be used by spiapp\n";52 usage = "c++create: create a file \"file.cc\" to be used by spiapp\n"; 52 53 usage+= "Usage: c++create file.cc func c++ user code...\n"; 53 54 mpiac->RegisterCommand(kw, usage, this, hgrp); 54 55 55 56 kw = "c++createfrf"; 56 usage = "c++createfrf: create a file \"file.cc\" to be used by spiapp\n";57 usage+= " 58 usage+= " 57 usage = "c++createfrf: create a file \"file.cc\" to be used by spiapp\n"; 58 usage+= " with a user file code \"fileuser.cc\"\n"; 59 usage+= " and an optional user function code \"fileuserfct.cc\"\n"; 59 60 usage+= "Usage: c++createfrf file.cc func fileuser.cc [fileuserfct.cc]\n"; 60 61 mpiac->RegisterCommand(kw, usage, this, hgrp); … … 130 131 rc = FillUserCode(tokens[0]); if(rc) return(1); 131 132 if(tokens.size()>1) rc = FillUserFctFrF(tokens[1]); 133 else rc = FillUserFctFrF(); 134 if(rc) return(1); 132 135 rc = CrFile(); if(rc) return(1); 133 136 rc = Compile(); if(rc) return(1); … … 145 148 return(1); 146 149 } 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); 149 153 150 154 } else if(kw == "c++createfrf") { … … 154 158 } 155 159 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); 157 163 rc = CrFile(tokens[0],tokens[1]); if(rc) return(1); 158 164 … … 197 203 int rc=0; 198 204 rc = FillUserCode(usercode,0); if(rc) return(1); 199 rc = FillUserFctFrS(userfct); 205 rc = FillUserFctFrS(userfct); if(rc) return(1); 200 206 rc = CrFile(); if(rc) return(1); 201 207 rc = Compile(); if(rc) return(1); … … 207 213 /* --Methode-- */ 208 214 int CxxExecutor::CrFile(string cfilename,string func) 215 // Si un nom n'est pas precise alors TmpDir/cxx_spiapp.cc 209 216 { 210 217 if(cfilename.size()<1) cfilename = mDefTmp + mDefRoot + ".cc"; 218 211 219 if(func.size()<1) func = mDefFunc; 212 220 … … 370 378 /* --Methode-- */ 371 379 int CxxExecutor::FillUserCode(string& usercode,uint_4 first) 380 // User code is read from input. 372 381 // - first is the first position in the "string" where the code starts 373 // User code is read from input. Itis put into file "TmpDir/cxx_spiapp.h".382 // - Code is put into file "TmpDir/cxx_spiapp.h". 374 383 { 375 384 mUserCodeFn = ""; … … 405 414 406 415 /* --Methode-- */ 407 int CxxExecutor::FillUserFctFrS(string userfct )416 int CxxExecutor::FillUserFctFrS(string userfctcode) 408 417 // - Fill user Fonction code from string "userfct" 409 // Itis put into file "TmpDir/cxx_spiapp_fct.h".418 // - Code is put into file "TmpDir/cxx_spiapp_fct.h". 410 419 { 411 420 mUserFctFn = ""; 412 if(userfct .size()<1) return 0;421 if(userfctcode.size()<1) return 0; 413 422 mUserFctFn = mDefTmp + mDefRoot + "_fct.h"; 414 423 ofstream os(mUserFctFn.c_str(),ios::out); 415 424 if(!os) {cout<<"CxxExecutor::FillUserFctFrS: unable to open " 416 425 <<mUserFctFn<<endl; mUserFctFn = ""; return 1;} 417 os<<userfct <<endl;426 os<<userfctcode<<endl; 418 427 if(mPrtLevel) 419 428 cout<<"User Function code filled from standard input into "<<mUserFctFn<<endl; … … 433 442 /* --Methode-- */ 434 443 int CxxExecutor::FillUserFctFrF(string filefctname) 444 // User function code is read from "filefctname". 435 445 { 436 446 mUserFctFn = filefctname; … … 442 452 /* --Methode-- */ 443 453 int 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 { 463 if(rootfilename.size()<1) rootfilename = mDefTmp + mDefRoot; 464 if(mPrtLevel) cout<<"Compile "<<rootfilename<<endl; 465 466 int rc; 467 CxxCompilerLinker cxx; 468 if(mDefTmp.size()>0) cxx.SetTmpDir(mDefTmp); 469 cxx.SetVerbose(true); 470 471 // Compilation 472 string fcc = rootfilename + ".cc"; 473 string fo = ""; 474 cxx.AddCompileOptions(mCompOpt); 475 rc = cxx.Compile(fcc,fo); 476 if(mPrtLevel) cout << "Compilation rc = "<<rc<< endl; 477 if(rc) return 1; 478 479 // Fabrication Shared Lib. 480 string fso = ""; 481 cxx.AddLinkOptions(mLinkOpt); 482 string sophlib = "-lPI"; 483 cxx.AddLinkOptions(sophlib); 484 cxx.AddLinkOptions(mMyLibs); 485 rc = cxx.BuildSO(fo,fso); 486 if(mPrtLevel) cout << "Shared Library rc = "<<rc<< endl; 487 if(rc) return 2; 488 489 return 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;} 471 523 //--------------------------------------------------------------------- 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; 499 551 //--------------------------------------------------------------------- 500 return 0;501 }552 //return 0; 553 //} 502 554 503 555 /* --Methode-- */ … … 505 557 { 506 558 if(libname.size()<1) libname = mDefTmp + mDefRoot + ".so"; 559 else libname = mDefTmp + libname; 507 560 if(func.size()<1) func = mDefFunc; 508 561 509 562 NamedObjMgr omg; 510 563 PIACmd* mpiac = omg.GetImgApp()->CmdInterpreter(); 564 511 565 string key("linkff2"); 512 566 vector<string> arg; arg.push_back(libname); arg.push_back(func); … … 514 568 int rc = mpiac->ExecuteCommand(key,arg,toks); 515 569 if(mPrtLevel) cout<<"Link from "<<libname<<" for function "<<func 516 <<" (rc="<<rc<<")"<<endl;570 <<" (rc="<<rc<<")"<<endl; 517 571 return 0; 518 572 } … … 525 579 NamedObjMgr omg; 526 580 PIACmd* mpiac = omg.GetImgApp()->CmdInterpreter(); 581 527 582 string key("call"); 528 583 vector<string> arg; arg.push_back(func);
Note:
See TracChangeset
for help on using the changeset viewer.