source: Sophya/trunk/SophyaPI/PIext/cxxexecutor.cc@ 1335

Last change on this file since 1335 was 1319, checked in by ercodmgr, 25 years ago

Amelioration cxxexecutor - Reza , 10/11/2000

  • Property svn:executable set to *
File size: 23.9 KB
Line 
1#include "cxxexecutor.h"
2
3#include <typeinfo>
4
5#include "strutilxx.h"
6#include "dvlist.h"
7#include "cxxcmplnk.h"
8
9#include "nomgadapter.h"
10#include "pistdimgapp.h"
11
12
13/* --Methode-- */
14CxxExecutor::CxxExecutor(PIACmd *mpiac, PIStdImgApp* /* app */)
15 : mUserCodeFn(""), mUserFctFn("")
16 , mCompOpt(""), mLinkOpt(""), mMyLibs("")
17 , mDefTmp(""), mDefRoot("cxx_spiapp"), mDefFunc("usercxx"), mPrtLevel(2)
18{
19mIncList.resize(0);
20mCallArgs.resize(0);
21
22mIncImportList.resize(0);
23mModuleImportList.resize(0);
24
25// La liste de tous les modules que l'on peut ajouter
26mModuleImportDefaultList.resize(0);
27mModuleImportDefaultList.push_back("Samba");
28mModuleImportDefaultList.push_back("SkyMap");
29mModuleImportDefaultList.push_back("SkyT");
30mModuleImportDefaultList.push_back("FitsIOServer");
31mModuleImportDefaultList.push_back("IFFTW");
32mModuleImportDefaultList.push_back("LinAlg");
33
34// Gestion des fichiers par default dans TmpDir
35NamedObjMgr omg;
36string tmpdir = omg.GetTmpDir();
37if(tmpdir.size()>1) mDefTmp = tmpdir;
38
39// On enregistre les nouvelles commandes
40string hgrp = "CxxExecutorCmd";
41string usage,kw;
42
43kw = "c++exec";
44usage = "c++exec: Execute the following c++ user code\n";
45usage+= "Usage: c++exec c++ user code\n";
46usage+= "Warning: c++ user code can be found in \"TmpDir/"+mDefRoot+".h\"\n";
47usage+= " total generated code can be found in \"TmpDir/"+mDefRoot+".cc\"";
48mpiac->RegisterCommand(kw, usage, this, hgrp);
49
50kw = "c++execfrf";
51usage = "c++execfrf: Execute c++ user_code [user_function_code]\n";
52usage+= "Usage: c++execfrf fileuser.cc [fileuserfct.cc]\n";
53usage+= "Warning: total generated code can be found in \"TmpDir/"+mDefRoot+".cc\"";
54mpiac->RegisterCommand(kw, usage, this, hgrp);
55
56kw = "c++args";
57usage = "c++args: Define user function arguments for c++exec and c++execfrf\n";
58usage+= "Usage: c++args arg1 arg2 arg3 ...\n";
59usage+= " c++args -? : give current arguments\n";
60usage+= " c++args : reset current arguments";
61mpiac->RegisterCommand(kw, usage, this, hgrp);
62
63kw = "c++create";
64usage = "c++create: create a file \"file.cc\" to be used by spiapp\n";
65usage+= "Usage: c++create file.cc func c++ user code...\n";
66mpiac->RegisterCommand(kw, usage, this, hgrp);
67
68kw = "c++createfrf";
69usage = "c++createfrf: create a file \"file.cc\" to be used by spiapp\n";
70usage+= " with a user file code \"fileuser.cc\"\n";
71usage+= " and an optional user function code \"fileuserfct.cc\"\n";
72usage+= "Usage: c++createfrf file.cc func fileuser.cc [fileuserfct.cc]\n";
73mpiac->RegisterCommand(kw, usage, this, hgrp);
74
75kw = "c++compile";
76usage = "c++compile: compile a file (file.cc -> file.so)\n";
77usage+= "Usage: c++compile file\n";
78usage+= "Warning: give \"file\" or \"file.so\" to create \"file.so\" from \"file.cc\"\n";
79usage+= " : to be used before c++link";
80mpiac->RegisterCommand(kw, usage, this, hgrp);
81
82kw = "c++link";
83usage = "c++link: link function \"func\" in file.so to spiapp\n";
84usage+= "Usage: c++link file.so func";
85mpiac->RegisterCommand(kw, usage, this, hgrp);
86
87kw = "c++include";
88usage = "c++include: add personnal includes to be used by executor\n";
89usage+= "Usage: c++include myinc1.h myinc2.h ...\n";
90usage+= " c++include -? : list current additionnal include files\n";
91usage+= " c++include : reset to no additionnal include files\n";
92usage+= "Warning: to be used before c++create c++compile c++exec...";
93mpiac->RegisterCommand(kw, usage, this, hgrp);
94
95kw = "c++compileopt";
96usage = "c++compileopt: add personnal compile options\n";
97usage+= "Usage: c++compileopt -g -O5 -IMy_Inc_Dir ...\n";
98usage+= " c++compileopt -? : list current additionnal compile options\n";
99usage+= " c++compileopt : reset to no additionnal compile options\n";
100usage+= "Warning: to be used before c++create c++compile c++exec ...";
101mpiac->RegisterCommand(kw, usage, this, hgrp);
102
103kw = "c++linkopt";
104usage = "c++linkopt: add personnal link options\n";
105usage+= "Usage: c++linkopt -g -O5 ...\n";
106usage+= " c++linkopt -? : list current additionnal link options\n";
107usage+= " c++linkopt : reset to no additionnal link options\n";
108usage+= "Warning: to be used before c++create c++compile c++exec ...";
109mpiac->RegisterCommand(kw, usage, this, hgrp);
110
111kw = "c++mylibs";
112usage = "c++mylibs: add personnal libraries\n";
113usage+= "Usage: c++mylibs -LMy_Lib_Dir -lmylib1 -lmylib2 ...\n";
114usage+= " c++mylibs -? : list current additionnal libraries\n";
115usage+= " c++mylibs : reset to no additionnal libraries\n";
116usage+= "Warning: to be used before c++create c++compile c++exec ...";
117mpiac->RegisterCommand(kw, usage, this, hgrp);
118
119kw = "c++import";
120usage = "c++import: Sophya additionnal modules to be use in C++ executor\n";
121usage+= "Usage: c++import module1 ... : set list of modules to be used by executor\n";
122usage+= " c++import all : set all modules known by executor\n";
123usage+= " c++import : reset to no additionnal module\n";
124usage+= " c++import -? : list modules currently used in executor\n";
125usage+= " c++import -?? : list of available modules for executor\n";
126usage+= "Warning: to be used before c++create c++compile c++exec ...";
127mpiac->RegisterCommand(kw, usage, this, hgrp);
128
129kw = "c++prtlevel";
130usage = "c++prtlevel: Print level\n";
131usage+= "Usage: c++prtlevel prtlevel\n";
132usage+= " prtlevel=0 : minimum printing\n";
133usage+= " prtlevel=1 : + compiler/linker output\n";
134usage+= " prtlevel=2 : + full infos (default)";
135mpiac->RegisterCommand(kw, usage, this, hgrp);
136
137}
138
139/* --Methode-- */
140CxxExecutor::~CxxExecutor()
141{
142}
143
144/* --Methode-- */
145int CxxExecutor::Execute(string& kw, vector<string>& tokens, string& toks)
146{
147int rc=0;
148if(kw == "c++exec") {
149 if(tokens.size()<1) {
150 cout<<"Usage: c++exec c++ user code"<<endl;
151 return(1);
152 }
153 rc = ExecuteCXX(toks); if(rc) return(1);
154
155} else if(kw == "c++execfrf") {
156 if(tokens.size()<1) {
157 cout<<"Usage: c++execfrf fileuser.cc [fileuserfct.cc]"<<endl;
158 return(1);
159 }
160 rc = FillUserCode(tokens[0]); if(rc) return(1);
161 if(tokens.size()>1) rc = FillUserFctFrF(tokens[1]);
162 else rc = FillUserFctFrF();
163 if(rc) return(1);
164 rc = CrFile(); if(rc) return(1);
165 rc = Compile(); if(rc) return(1);
166 rc = Link(); if(rc) return(1);
167 rc = Call(); if(rc) return(1);
168
169} else if(kw == "c++args") {
170 if(tokens.size()==1) if(tokens[0]=="-?")
171 {cout<<"c++args "<<GetArgs()<<endl; return(0);}
172 FillArgs(tokens);
173
174} else if(kw == "c++create") {
175 if(tokens.size()<3) {
176 cout<<"Usage: c++create file.cc func c++ user code ..."<<endl;
177 return(1);
178 }
179 rc = FillUserCode(toks,2); if(rc) return(1);
180 rc = FillUserFctFrS(); if(rc) return(1);
181 rc = CrFile(tokens[0],tokens[1]); if(rc) return(1);
182
183} else if(kw == "c++createfrf") {
184 if(tokens.size()<3) {
185 cout<<"Usage: c++createfrf file.cc func fileuser.cc [fileuserfct.cc]"<<endl;
186 return(1);
187 }
188 rc = FillUserCode(tokens[2]); if(rc) return(1);
189 if(tokens.size()>3) rc = FillUserFctFrF(tokens[3]);
190 else rc = FillUserFctFrF(tokens[3]);
191 if(rc) return(1);
192 rc = CrFile(tokens[0],tokens[1]); if(rc) return(1);
193
194} else if(kw == "c++compile") {
195 if(tokens.size()>=1) rc = Compile(tokens[0]);
196 else rc = Compile();
197 if(rc) return(1);
198
199} else if(kw == "c++link") {
200 if(tokens.size()>=2) rc = Link(tokens[0],tokens[1]);
201 else if(tokens.size()>=1) rc = Link(tokens[0]);
202 else rc = Link();
203 if(rc) return(1);
204
205} else if(kw == "c++include") {
206 if(tokens.size()==1) if(tokens[0]=="-?")
207 {cout<<"c++include "<<GetInclude()<<endl; return(0);}
208 FillInclude(tokens);
209
210} else if(kw == "c++compileopt") {
211 if(tokens.size()==1) if(tokens[0]=="-?")
212 {cout<<"c++compileopt "<<GetCompileOpt()<<endl; return(0);}
213 FillCompileOpt(tokens);
214
215} else if(kw == "c++linkopt") {
216 if(tokens.size()==1) if(tokens[0]=="-?")
217 {cout<<"c++linkopt "<<GetLinkOpt()<<endl; return(0);}
218 FillLinkOpt(tokens);
219
220} else if(kw == "c++mylibs") {
221 if(tokens.size()==1) if(tokens[0]=="-?")
222 {cout<<"c++mylibs "<<GetLinkLibs()<<endl; return(0);}
223 FillLinkLibs(tokens);
224
225} else if(kw == "c++import") {
226 if(tokens.size()==1) {
227 if(tokens[0]=="-?")
228 {cout<<"c++import "<<GetModuleImport()<<endl; return(0);}
229 if(tokens[0]=="-??") {
230 cout<<"c++import possibilities :"<<endl;
231 if(mModuleImportDefaultList.size()>0) {
232 for(uint_4 i=0;i<mModuleImportDefaultList.size();i++)
233 cout<<" "<<mModuleImportDefaultList[i];
234 cout<<endl;
235 }
236 return(0);
237 }
238 }
239 FillModuleImport(tokens);
240
241} else if(kw == "c++prtlevel") {
242 if(tokens.size()==1) if(tokens[0]=="-?")
243 {cout<<"c++prtlevel prtlevel = "<<mPrtLevel<<endl; return(0);}
244 if(tokens.size()>0) {
245 int lp=atoi(tokens[0].c_str()); if(lp<0) lp=0;
246 mPrtLevel=(uint_2) lp;
247 } else mPrtLevel=2;
248
249}
250
251return(0);
252}
253
254/* --Methode-- */
255int CxxExecutor::ExecuteCXX(string usercode,string userfct)
256{
257int rc=0;
258rc = FillUserCode(usercode,0); if(rc) return(1);
259rc = FillUserFctFrS(userfct); if(rc) return(1);
260rc = CrFile(); if(rc) return(1);
261rc = Compile(); if(rc) return(1);
262rc = Link(); if(rc) return(1);
263rc = Call(); if(rc) return(1);
264return 0;
265}
266
267/* --Methode-- */
268int CxxExecutor::CrFile(string cfilename,string func)
269// Si un nom n'est pas precise alors TmpDir/cxx_spiapp.cc
270{
271if(cfilename.size()<1) cfilename = mDefTmp + mDefRoot + ".cc";
272
273if(func.size()<1) func = mDefFunc;
274
275ofstream os(cfilename.c_str(),ios::out);
276if(!os)
277 {cout<<"CxxExecutor::CrFile: unable to open "<<cfilename<<endl;
278 return 1;}
279
280PutInclude(os);
281os<<endl;
282
283PutIncludeUser(os);
284os<<endl;
285
286os<<"//-------------------------------------------------//"<<endl;
287os<<"//----------------- User Functions ----------------//"<<endl;
288os<<"//-------------------------------------------------//"<<endl;
289if(mUserFctFn.size()>0) os<<"#include \""<<mUserFctFn<<"\""<<endl;
290os<<endl;
291
292
293os<<"extern \"C\" {"<<endl;
294os<<" int "<<func<<"( vector<string>& args );"<<endl;
295os<<"}"<<endl<<endl;
296os<<"int "<<func<<"( vector<string>& args )"<<endl;
297os<<"{"<<endl;
298os<<"// Some definitions to help using spiapp;"<<endl;
299os<<"NamedObjMgr omg;"<<endl;
300os<<"Services2NObjMgr& srvo = *omg.GetServiceObj();"<<endl;
301os<<endl;
302
303PutObject(os);
304os<<endl;
305
306PutVar(os);
307os<<endl;
308
309os<<"//--------------------------------------------//"<<endl;
310os<<"//----------------- User Code ----------------//"<<endl;
311os<<"//--------------------------------------------//"<<endl;
312if(mUserCodeFn.size()>0) os<<"#include \""<<mUserCodeFn<<"\""<<endl;
313os<<endl;
314
315os<<"return 0;"<<endl;
316os<<"}"<<endl;
317
318if(mPrtLevel>1)
319 cout<<"File "<<cfilename<<" for function "<<func<<" created :"<<endl;
320if(mPrtLevel>1 && mUserCodeFn.size()>0)
321 cout<<" User code was in file "<<mUserCodeFn<<endl;
322if(mPrtLevel>1 && mUserFctFn.size()>0)
323 cout<<" User function code was in file "<<mUserFctFn<<endl;
324return 0;
325}
326
327/* --Methode-- */
328void CxxExecutor::PutInclude(ofstream& os)
329{
330os<<"#include \"machdefs.h\""<<endl<<endl;
331
332os<<"//---- System et stdc++ include files"<<endl
333 <<"#include <stdio.h>"<<endl
334 <<"#include <stdlib.h>"<<endl
335 <<"#include <math.h>"<<endl
336 <<"#include <ctype.h>"<<endl
337 <<"#include <string.h>"<<endl
338 <<"#include <iostream.h>"<<endl
339 <<"#include <fstream.h>"<<endl
340 <<"#include <complex>"<<endl
341 <<endl
342
343 <<"#include <typeinfo>"<<endl
344 <<"#include <string>"<<endl
345 <<"#include <vector>"<<endl
346 <<"#include <map>"<<endl
347 <<"#include <functional>"<<endl
348 <<"#include <list>"<<endl
349 <<endl
350
351 <<"//---- Sophya include files"<<endl
352 <<"#include \"systools.h\""<<endl
353 <<"#include \"ntools.h\""<<endl
354 <<"#include \"array.h\""<<endl
355 <<"#include \"histats.h\""<<endl
356 <<endl
357
358 <<"//---- Spiapp include files"<<endl
359 <<"#include \"nobjmgr.h\""<<endl
360 <<"#include \"servnobjm.h\""<<endl
361 <<endl;
362
363os<<"//---- Include files from additionnal modules"<<endl;
364if(mIncImportList.size()>0)
365 for(uint_4 i=0;i<mIncImportList.size();i++)
366 os<<"#include \""<<mIncImportList[i]<<"\""<<endl;
367os<<endl;
368
369os<<"//---- function for Adding and displaying Objects " << endl;
370os<<"void Keep_Object(AnyDataObj & obj, string const & nom) \n{ \n"
371 <<" string name = nom; \n NamedObjMgr om; \n"
372 <<" if (om.GetObj(name)) \n"
373 <<" cerr << \"KeepObj()/Warning Already kept object \" << endl; \n"
374 <<" else om.AddObj(obj, name); \n"
375 <<"} \n" << endl;
376os<<"void Display_Object(AnyDataObj & obj, string const & opt, string const & nom) \n { \n"
377 <<" string name = nom; \n NamedObjMgr om; \n"
378 <<" if (!om.GetObj(name)) \n"
379 <<" om.AddObj(obj, name); \n"
380 <<" om.DisplayObj(name, opt); \n"
381 <<"} \n" << endl;
382
383os<<"//---- Objects and variables saving"<<endl
384 <<"#define KeepObj(obj) Keep_Object(obj, #obj);"<<endl
385 <<"#define KeepVar(var) ___nomobj = #var; omg.GetVarList().Get(___nomobj) = var ;"<<endl
386 <<endl;
387
388os<<"//---- Displaying objects and command execution"<<endl;
389os<<"#define DisplayObj(obj, att) Display_Object(obj, att, #obj); \n" << endl;
390os<<"#define ExecuteCommand(cmd) srvo.ExecuteCommand(cmd); \n" << endl;
391
392return;
393}
394
395/* --Methode-- */
396void CxxExecutor::PutIncludeUser(ofstream& os)
397{
398if(mIncList.size()<1) return;
399for(uint_4 i=0;i<mIncList.size();i++)
400 os<<"#include \""<<mIncList[i]<<"\""<<endl;
401}
402
403/* --Methode-- */
404void CxxExecutor::PutObject(ofstream& os)
405{
406NamedObjMgr omg;
407NObjMgrAdapter* objmgrad;
408vector<string> objlist;
409string patt = "*";
410omg.GetObjList(patt,objlist);
411int nobjs = objlist.size();
412
413os<<"//-------------- Object List --------------"<<endl;
414os<<"//Number of objects = "<<nobjs<<endl;
415os<<"string ___nomobj;"<<endl<<endl;
416if(nobjs<=0) return;
417
418string dir,nobj,stmp,obtype;
419for(int i=0;i<nobjs;i++) {
420 objmgrad = omg.GetObjAdapter(objlist[i]);
421 omg.ParseObjectName(objlist[i],dir,nobj);
422 obtype = objmgrad->GetDataObjType();
423 stmp = "___" + nobj;
424
425 os<<"___nomobj = \""<<nobj<<"\";"<<endl;
426 os<<obtype<<"* "<<stmp
427 <<" = dynamic_cast< "<<obtype<<" * >(omg.GetObj(___nomobj));"<<endl;
428 os<<"if("<<stmp<<"==NULL) throw NullPtrError"
429 <<"(\"CxxExecutor::PutObject: Non existing object "<<nobj
430 <<"... please update file\");"<<endl;
431 os<<obtype<<"& "<<nobj<<" = (*"<<stmp<<");"<<endl<<endl;
432}
433
434return;
435}
436
437/* --Methode-- */
438void CxxExecutor::PutVar(ofstream& os)
439{
440os<<"//-------------- Variable List --------------"<<endl;
441NamedObjMgr omg;
442DVList& varlist = omg.GetVarList();
443// varlist.Show(); varlist.Print();
444DVList::ValList::const_iterator it;
445for(it=varlist.Begin(); it!=varlist.End(); it++) {
446 string key = (*it).first;
447 if (isalpha(key[0]) ) {
448 os<<"___nomobj = \""<<key<<"\";"<<endl;
449 os<<"MuTyV & $"<<key<<" = omg.GetVarList().Get(___nomobj);"<<endl;
450 }
451}
452
453return;
454}
455
456/* --Methode-- */
457int CxxExecutor::FillUserCode(string& usercode,uint_4 first)
458// User code is read from input.
459// - first is the first position in the "string" where the code starts
460// - Code is put into file "TmpDir/cxx_spiapp.h".
461{
462mUserCodeFn = "";
463
464// get the string part which is after word "first"
465string code = usercode;
466if(code.size()<=0) {cout<<"CxxExecutor::FillUserCode: no user code"<<endl;
467 return 1;}
468size_t q;
469for(uint_4 i=0;i<=first;i++) {
470 q = code.find_first_not_of(" \t");
471 if(q>=code.size()) {code=""; break;}
472 code = code.substr(q);
473 if(i==first) break;
474 q = code.find_first_of(" \t");
475 if(q>=code.size()) {code=""; break;}
476 code = code.substr(q);
477}
478if(code.size()<=0)
479 {cout<<"CxxExecutor::FillUserCode: no user code after "<<first<<endl;
480 return 1;}
481
482// Fill the file with user code
483mUserCodeFn = mDefTmp + mDefRoot + ".h";
484ofstream os(mUserCodeFn.c_str(),ios::out);
485if(!os) {cout<<"CxxExecutor::FillUserCode: unable to open "
486 <<mUserCodeFn<<endl; mUserCodeFn = ""; return 1;}
487os<<code<<endl;
488if(mPrtLevel>1)
489 cout<<"User code filled from standard input into "<<mUserCodeFn<<endl;
490return 0;
491}
492
493/* --Methode-- */
494int CxxExecutor::FillUserFctFrS(string userfctcode)
495// - Fill user Fonction code from string "userfct"
496// - Code is put into file "TmpDir/cxx_spiapp_fct.h".
497{
498mUserFctFn = "";
499if(userfctcode.size()<1) return 0;
500mUserFctFn = mDefTmp + mDefRoot + "_fct.h";
501ofstream os(mUserFctFn.c_str(),ios::out);
502if(!os) {cout<<"CxxExecutor::FillUserFctFrS: unable to open "
503 <<mUserFctFn<<endl; mUserFctFn = ""; return 1;}
504os<<userfctcode<<endl;
505if(mPrtLevel>1)
506 cout<<"User Function code filled from standard input into "<<mUserFctFn<<endl;
507return 0;
508}
509
510/* --Methode-- */
511int CxxExecutor::FillUserCode(string filename)
512// User code is read from "filename".
513{
514mUserCodeFn = filename;
515if(mPrtLevel>1 && mUserCodeFn.size()>0)
516 cout<<"User code filled from file "<<mUserCodeFn<<endl;
517return 0;
518}
519
520/* --Methode-- */
521int CxxExecutor::FillUserFctFrF(string filefctname)
522// User function code is read from "filefctname".
523{
524mUserFctFn = filefctname;
525if(mPrtLevel>1 && mUserFctFn.size()>0)
526 cout<<"User Function code filled from file "<<mUserFctFn<<endl;
527return 0;
528}
529
530/* --Methode-- */
531int CxxExecutor::Compile(string rootfilename)
532//--------------------------------------------------------//
533// rootfilename = | name | "" ou (default) //
534//--------------------------------------------------------//
535// fichier .cc | name.cc | TmpDir/cxx_spiapp.cc //
536// | ../dir/name.cc | //
537// fichier .o | TmpDir/name.o | TmpDir/cxx_spiapp.o //
538// fichier .so | TmpDir/name.so | TmpDir/cxx_spiapp.so //
539//--------------------------------------------------------//
540{
541if(rootfilename.size()<1) rootfilename = mDefTmp + mDefRoot;
542if(mPrtLevel>1) cout<<"Compile "<<rootfilename<<endl;
543
544int rc;
545CxxCompilerLinker cxx;
546if(mDefTmp.size()>0) cxx.SetTmpDir(mDefTmp);
547if(mPrtLevel>0) cxx.SetVerbose(true);
548 else cxx.SetVerbose(false);
549
550// Compilation
551string fcc = rootfilename + ".cc";
552string fo = "";
553cxx.AddCompileOptions(mCompOpt);
554rc = cxx.Compile(fcc,fo);
555if(mPrtLevel>1) cout << "Compilation rc = "<<rc<< endl;
556if(rc) return 1;
557
558// Fabrication Shared Lib.
559string fso = "";
560cxx.AddLinkOptions(mLinkOpt);
561#ifdef SANS_EVOLPLANCK
562 string sophlib = "-lPIE";
563#else
564 string sophlib = "-lPI";
565#endif
566cxx.AddLinkOptions(sophlib);
567cxx.AddLinkOptions(mMyLibs);
568rc = cxx.BuildSO(fo,fso);
569if(mPrtLevel>1) cout << "Shared Library rc = "<<rc<< endl;
570if(rc) return 2;
571
572return 0;
573}
574
575/* --Methode-- */
576//int CxxExecutor::Compile(string rootfilename)
577// Ne marche pas si TmpDir != ""
578//{
579//if(rootfilename.size()<1) rootfilename = mDefRoot;
580//if(mPrtLevel>1) cout<<"Compile: "<<rootfilename<<endl;
581//int rc = 0;
582//rc = CrMakefile();
583//if(rc) return(1);
584//string make = "";
585//make += "make -f " + mDefRoot + "_Makefile";
586//make += " CXXFLAGS=\"" + mCompOpt + "\"";
587//make += " LDFLAGS=\"" + mLinkOpt + "\"";
588//make += " MYLIBS=\"" + mMyLibs + "\"";
589//make += " " + rootfilename;
590//rc = system(make.c_str());
591//if(rc)
592// {cout<<"CxxExecutor::Compile : \n"<<make<<" Failed"<<endl;
593// return 1000+rc;}
594//return 0;
595//}
596
597/* --Methode-- */
598//int CxxExecutor::CrMakefile(void)
599// Ne marche pas si TmpDir != ""
600//{
601//string makename = mDefTmp + mDefRoot + "_Makefile";
602//ofstream os(makename.c_str(),ios::out);
603//if(!os)
604// {cout<<"CxxExecutor::CrMakefile: unable to open file for Makefile"<<endl;
605// return 1;}
606//---------------------------------------------------------------------
607//os<<"MODULEDECCXXFLAGS := -msg_quiet"<<endl;
608//os<<"include $(DPCBASEREP)/Include/MakefileUser.h"<<endl;
609//os<<"MYLIBS ="<<endl;
610//os<<"LIBS = -L$(SLB) -lPI -lextsophya -lsophya -lm"<<endl;
611//os<<"ifeq ($(MACHEROS),OSF1)"<<endl;
612//os<<"LIBS := $(LIBS) -lfor"<<endl;
613//os<<"endif"<<endl;
614//os<<"ifeq ($(MACHEROS),Linux)"<<endl;
615//os<<"LIBS := $(LIBS) -ldl -lf2c"<<endl;
616//os<<"endif"<<endl;
617//os<<"%.so:%.o"<<endl;
618//os<<"%:%.cc"<<endl;
619//os<<"%:%.o"<<endl;
620//os<<"%.o:%.cc"<<endl;
621//os<<"%.o:%.c"<<endl;
622//os<<"%:%.c"<<endl;
623//os<<endl;
624//os<<".PRECIOUS: %.so"<<endl;
625//os<<endl;
626//os<<"%:%.so"<<endl;
627//os<<"\t"<<"echo $@ \" made (.so) \""<<endl;
628//os<<"%.so:%.o"<<endl;
629//os<<"\t"<<"$(LINK.cc) -shared -o $@ $< $(LIBS) $(MYLIBS)"<<endl;
630//os<<"%.o:%.cc"<<endl;
631//os<<"\t"<<"$(COMPILE.cc) -o $@ $<"<<endl;
632//os<<"%.o:%.c"<<endl;
633//os<<"\t"<<"$(COMPILE.c) -c $(CFLAGS) $(USERFLAGS) -o $@ $<"<<endl;
634//---------------------------------------------------------------------
635//return 0;
636//}
637
638/* --Methode-- */
639int CxxExecutor::Link(string libname,string func)
640{
641if(libname.size()<1) libname = mDefTmp + mDefRoot + ".so";
642 else libname = mDefTmp + libname;
643if(func.size()<1) func = mDefFunc;
644
645NamedObjMgr omg;
646PIACmd* mpiac = omg.GetImgApp()->CmdInterpreter();
647
648string key("linkff2");
649vector<string> arg; arg.push_back(libname); arg.push_back(func);
650string toks = libname + " " + func;
651int rc = mpiac->ExecuteCommand(key,arg,toks);
652if(mPrtLevel>1) cout<<"Link from "<<libname<<" for function "<<func
653 <<" (rc="<<rc<<")"<<endl;
654return 0;
655}
656
657/* --Methode-- */
658int CxxExecutor::Call(string func)
659{
660if(func.size()<1) func = mDefFunc;
661
662NamedObjMgr omg;
663PIACmd* mpiac = omg.GetImgApp()->CmdInterpreter();
664
665string key("call");
666vector<string> arg; arg.push_back(func);
667string toks = func;
668if(mCallArgs.size()>0)
669 for(uint_4 i=0;i<mCallArgs.size();i++) arg.push_back(mCallArgs[i]);
670mpiac->ExecuteCommand(key,arg,toks);
671return 0;
672}
673
674/* --Methode-- */
675void CxxExecutor::FillArgs(vector<string>& args)
676{
677mCallArgs.resize(0);
678if(args.size()<1) return;
679for(uint_4 i=0;i<args.size();i++) mCallArgs.push_back(args[i]);
680}
681
682void CxxExecutor::FillArgs(string& args)
683{
684mCallArgs.resize(0);
685FillVStringFrString(args,mCallArgs,' ');
686}
687
688string CxxExecutor::GetArgs(void)
689{
690string dum = "";
691if(mCallArgs.size()<1) return dum;
692for(uint_4 i=0;i<mCallArgs.size();i++) dum += mCallArgs[i] + " ";
693return dum;
694}
695
696/* --Methode-- */
697void CxxExecutor::FillInclude(vector<string>& inc)
698{
699mIncList.resize(0);
700if(inc.size()<1) return;
701for(uint_4 i=0;i<inc.size();i++) mIncList.push_back(inc[i]);
702}
703
704void CxxExecutor::FillInclude(string& inc)
705{
706mIncList.resize(0);
707FillVStringFrString(inc,mIncList,' ');
708}
709
710string CxxExecutor::GetInclude(void)
711{
712string dum = "";
713if(mIncList.size()<1) return dum;
714for(uint_4 i=0;i<mIncList.size();i++) dum += mIncList[i] + " ";
715return dum;
716}
717
718/* --Methode-- */
719void CxxExecutor::FillCompileOpt(vector<string>& copt)
720{
721mCompOpt = "";
722if(copt.size()<1) return;
723for(uint_4 i=0;i<copt.size();i++) mCompOpt += copt[i] + " ";
724}
725
726void CxxExecutor::FillCompileOpt(string& copt)
727{
728mCompOpt = copt;
729}
730
731string CxxExecutor::GetCompileOpt(void)
732{
733return mCompOpt;
734}
735
736/* --Methode-- */
737void CxxExecutor::FillLinkOpt(vector<string>& lopt)
738{
739mLinkOpt = "";
740if(lopt.size()<1) return;
741for(uint_4 i=0;i<lopt.size();i++) mLinkOpt += lopt[i] + " ";
742}
743
744void CxxExecutor::FillLinkOpt(string& lopt)
745{
746mLinkOpt = lopt;
747}
748
749string CxxExecutor::GetLinkOpt(void)
750{
751return mLinkOpt;
752}
753
754/* --Methode-- */
755void CxxExecutor::FillLinkLibs(vector<string>& llibs)
756{
757mMyLibs = "";
758if(llibs.size()<1) return;
759for(uint_4 i=0;i<llibs.size();i++) mMyLibs += llibs[i] + " ";
760}
761
762void CxxExecutor::FillLinkLibs(string& llibs)
763{
764mMyLibs = llibs;
765}
766
767string CxxExecutor::GetLinkLibs(void)
768{
769return mMyLibs;
770}
771
772/* --Methode-- */
773void CxxExecutor::FillModuleImport(vector<string>& import)
774{
775mModuleImportList.resize(0);
776mIncImportList.resize(0);
777if(import.size()<1) return;
778
779if(import[0]=="all" || import[0]=="All" || import[0]=="ALL") {
780 mModuleImportList = mModuleImportDefaultList;
781} else {
782 for(uint_4 i=0;i<import.size();i++) mModuleImportList.push_back(import[i]);
783}
784
785// Set additionnal Includes
786if(mModuleImportList.size()>0)
787 for(uint_4 i=0;i<mModuleImportList.size();i++) {
788 if( mModuleImportList[i]=="Samba") mIncImportList.push_back("samba.h");
789 else if(mModuleImportList[i]=="SkyMap") mIncImportList.push_back("skymap.h");
790 else if(mModuleImportList[i]=="SkyT") mIncImportList.push_back("skyt.h");
791 else if(mModuleImportList[i]=="FitsIOServer") mIncImportList.push_back("fitsautoreader.h");
792 else if(mModuleImportList[i]=="IFFTW") mIncImportList.push_back("fftwserver.h");
793 else if(mModuleImportList[i]=="LinAlg") mIncImportList.push_back("intflapack.h");
794}
795
796return;
797}
798
799void CxxExecutor::FillModuleImport(string& import)
800{
801mModuleImportList.resize(0);
802vector<string> vsimport;
803FillVStringFrString(import,vsimport,' ');
804FillModuleImport(vsimport);
805}
806
807string CxxExecutor::GetModuleImport(void)
808{
809string dum = "";
810if(mModuleImportList.size()<1) return dum;
811for(uint_4 i=0;i<mModuleImportList.size();i++) dum += mModuleImportList[i] + " ";
812return dum;
813}
Note: See TracBrowser for help on using the repository browser.