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

Last change on this file since 2215 was 2182, checked in by ansari, 23 years ago

Suite correction exception Peida nullPtrError en long mExcErr , Reza 04/09/2002

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