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

Last change on this file since 1971 was 1646, checked in by cmv, 24 years ago

fitsioserver.h + module XAstroPack ds cxxexec cmv 29/08/01

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