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

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

BitCmp64(double,long long) cmv 18/4/01

  • Property svn:executable set to *
File size: 24.2 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 to compare bits on double \n"
370 <<"int_8 BitCmp64(double v,int_8 flg) \n"
371 <<"{return ((int_8)((v<0.) ? v-0.1 : v+0.1))&flg;} \n"
372 <<endl;
373
374os<<"//---- function for Adding and displaying Objects " << endl;
375os<<"void Keep_Object(AnyDataObj & obj, string const & nom) \n{ \n"
376 <<" string name = nom; \n NamedObjMgr om; \n"
377 <<" if (om.GetObj(name)) \n"
378 <<" cerr << \"KeepObj()/Warning Already kept object \" << endl; \n"
379 <<" else om.AddObj(obj, name); \n"
380 <<"} \n" << endl;
381os<<"void Display_Object(AnyDataObj & obj, string const & opt, string const & nom) \n { \n"
382 <<" string name = nom; \n NamedObjMgr om; \n"
383 <<" if (!om.GetObj(name)) \n"
384 <<" om.AddObj(obj, name); \n"
385 <<" om.DisplayObj(name, opt); \n"
386 <<"} \n" << endl;
387
388os<<"//---- Objects and variables saving"<<endl
389 <<"#define KeepObj(obj) Keep_Object(obj, #obj);"<<endl
390 <<"#define KeepVar(var) ___nomobj = #var; omg.GetVarList().Get(___nomobj) = var ;"<<endl
391 <<endl;
392
393os<<"//---- Displaying objects and command execution"<<endl;
394os<<"#define DisplayObj(obj, att) Display_Object(obj, att, #obj); \n" << endl;
395os<<"#define ExecuteCommand(cmd) srvo.ExecuteCommand(cmd); \n" << endl;
396
397return;
398}
399
400/* --Methode-- */
401void CxxExecutor::PutIncludeUser(ofstream& os)
402{
403if(mIncList.size()<1) return;
404for(uint_4 i=0;i<mIncList.size();i++)
405 os<<"#include \""<<mIncList[i]<<"\""<<endl;
406}
407
408/* --Methode-- */
409void CxxExecutor::PutObject(ofstream& os)
410{
411NamedObjMgr omg;
412NObjMgrAdapter* objmgrad;
413vector<string> objlist;
414string patt = "*";
415omg.GetObjList(patt,objlist);
416int nobjs = objlist.size();
417
418os<<"//-------------- Object List --------------"<<endl;
419os<<"//Number of objects = "<<nobjs<<endl;
420os<<"string ___nomobj;"<<endl<<endl;
421if(nobjs<=0) return;
422
423string dir,nobj,stmp,obtype;
424for(int i=0;i<nobjs;i++) {
425 objmgrad = omg.GetObjAdapter(objlist[i]);
426 omg.ParseObjectName(objlist[i],dir,nobj);
427 obtype = objmgrad->GetDataObjType();
428 stmp = "___" + nobj;
429
430 os<<"___nomobj = \""<<nobj<<"\";"<<endl;
431 os<<obtype<<"* "<<stmp
432 <<" = dynamic_cast< "<<obtype<<" * >(omg.GetObj(___nomobj));"<<endl;
433#ifdef SANS_EVOLPLANCK
434 os<<"if("<<stmp<<"==NULL) { \n"
435 <<" cerr << \"CxxExecutor::PutObject: Non existing object "
436 <<" ... please update file \\n \" ;"
437 <<" throw nullPtrErr ; \n } "<<endl;
438#else
439 os<<"if("<<stmp<<"==NULL) throw NullPtrError"
440 <<"(\"CxxExecutor::PutObject: Non existing object "<<nobj
441 <<"... please update file\");"<<endl;
442#endif
443 os<<obtype<<"& "<<nobj<<" = (*"<<stmp<<");"<<endl<<endl;
444}
445
446return;
447}
448
449/* --Methode-- */
450void CxxExecutor::PutVar(ofstream& os)
451{
452os<<"//-------------- Variable List --------------"<<endl;
453NamedObjMgr omg;
454DVList& varlist = omg.GetVarList();
455// varlist.Show(); varlist.Print();
456DVList::ValList::const_iterator it;
457for(it=varlist.Begin(); it!=varlist.End(); it++) {
458 string key = (*it).first;
459 if (isalpha(key[0]) ) {
460 os<<"___nomobj = \""<<key<<"\";"<<endl;
461 os<<"MuTyV & $"<<key<<" = omg.GetVarList().Get(___nomobj);"<<endl;
462 }
463}
464
465return;
466}
467
468/* --Methode-- */
469int CxxExecutor::FillUserCode(string& usercode,uint_4 first)
470// User code is read from input.
471// - first is the first position in the "string" where the code starts
472// - Code is put into file "TmpDir/cxx_spiapp.h".
473{
474mUserCodeFn = "";
475
476// get the string part which is after word "first"
477string code = usercode;
478if(code.size()<=0) {cout<<"CxxExecutor::FillUserCode: no user code"<<endl;
479 return 1;}
480size_t q;
481for(uint_4 i=0;i<=first;i++) {
482 q = code.find_first_not_of(" \t");
483 if(q>=code.size()) {code=""; break;}
484 code = code.substr(q);
485 if(i==first) break;
486 q = code.find_first_of(" \t");
487 if(q>=code.size()) {code=""; break;}
488 code = code.substr(q);
489}
490if(code.size()<=0)
491 {cout<<"CxxExecutor::FillUserCode: no user code after "<<first<<endl;
492 return 1;}
493
494// Fill the file with user code
495mUserCodeFn = mDefTmp + mDefRoot + ".h";
496ofstream os(mUserCodeFn.c_str(),ios::out);
497if(!os) {cout<<"CxxExecutor::FillUserCode: unable to open "
498 <<mUserCodeFn<<endl; mUserCodeFn = ""; return 1;}
499os<<code<<endl;
500if(mPrtLevel>1)
501 cout<<"User code filled from standard input into "<<mUserCodeFn<<endl;
502return 0;
503}
504
505/* --Methode-- */
506int CxxExecutor::FillUserFctFrS(string userfctcode)
507// - Fill user Fonction code from string "userfct"
508// - Code is put into file "TmpDir/cxx_spiapp_fct.h".
509{
510mUserFctFn = "";
511if(userfctcode.size()<1) return 0;
512mUserFctFn = mDefTmp + mDefRoot + "_fct.h";
513ofstream os(mUserFctFn.c_str(),ios::out);
514if(!os) {cout<<"CxxExecutor::FillUserFctFrS: unable to open "
515 <<mUserFctFn<<endl; mUserFctFn = ""; return 1;}
516os<<userfctcode<<endl;
517if(mPrtLevel>1)
518 cout<<"User Function code filled from standard input into "<<mUserFctFn<<endl;
519return 0;
520}
521
522/* --Methode-- */
523int CxxExecutor::FillUserCode(string filename)
524// User code is read from "filename".
525{
526mUserCodeFn = filename;
527if(mPrtLevel>1 && mUserCodeFn.size()>0)
528 cout<<"User code filled from file "<<mUserCodeFn<<endl;
529return 0;
530}
531
532/* --Methode-- */
533int CxxExecutor::FillUserFctFrF(string filefctname)
534// User function code is read from "filefctname".
535{
536mUserFctFn = filefctname;
537if(mPrtLevel>1 && mUserFctFn.size()>0)
538 cout<<"User Function code filled from file "<<mUserFctFn<<endl;
539return 0;
540}
541
542/* --Methode-- */
543int CxxExecutor::Compile(string rootfilename)
544//--------------------------------------------------------//
545// rootfilename = | name | "" ou (default) //
546//--------------------------------------------------------//
547// fichier .cc | name.cc | TmpDir/cxx_spiapp.cc //
548// | ../dir/name.cc | //
549// fichier .o | TmpDir/name.o | TmpDir/cxx_spiapp.o //
550// fichier .so | TmpDir/name.so | TmpDir/cxx_spiapp.so //
551//--------------------------------------------------------//
552{
553if(rootfilename.size()<1) rootfilename = mDefTmp + mDefRoot;
554if(mPrtLevel>1) cout<<"Compile "<<rootfilename<<endl;
555
556int rc;
557CxxCompilerLinker cxx;
558if(mDefTmp.size()>0) cxx.SetTmpDir(mDefTmp);
559if(mPrtLevel>0) cxx.SetVerbose(true);
560 else cxx.SetVerbose(false);
561
562// Compilation
563string fcc = rootfilename + ".cc";
564string fo = "";
565cxx.AddCompileOptions(mCompOpt);
566rc = cxx.Compile(fcc,fo);
567if(mPrtLevel>1) cout << "Compilation rc = "<<rc<< endl;
568if(rc) return 1;
569
570// Fabrication Shared Lib.
571string fso = "";
572cxx.AddLinkOptions(mLinkOpt);
573#ifdef SANS_EVOLPLANCK
574 string sophlib = "-lPIE";
575#else
576 string sophlib = "-lPI";
577#endif
578cxx.AddLinkOptions(sophlib);
579cxx.AddLinkOptions(mMyLibs);
580rc = cxx.BuildSO(fo,fso);
581if(mPrtLevel>1) cout << "Shared Library rc = "<<rc<< endl;
582if(rc) return 2;
583
584return 0;
585}
586
587/* --Methode-- */
588//int CxxExecutor::Compile(string rootfilename)
589// Ne marche pas si TmpDir != ""
590//{
591//if(rootfilename.size()<1) rootfilename = mDefRoot;
592//if(mPrtLevel>1) cout<<"Compile: "<<rootfilename<<endl;
593//int rc = 0;
594//rc = CrMakefile();
595//if(rc) return(1);
596//string make = "";
597//make += "make -f " + mDefRoot + "_Makefile";
598//make += " CXXFLAGS=\"" + mCompOpt + "\"";
599//make += " LDFLAGS=\"" + mLinkOpt + "\"";
600//make += " MYLIBS=\"" + mMyLibs + "\"";
601//make += " " + rootfilename;
602//rc = system(make.c_str());
603//if(rc)
604// {cout<<"CxxExecutor::Compile : \n"<<make<<" Failed"<<endl;
605// return 1000+rc;}
606//return 0;
607//}
608
609/* --Methode-- */
610//int CxxExecutor::CrMakefile(void)
611// Ne marche pas si TmpDir != ""
612//{
613//string makename = mDefTmp + mDefRoot + "_Makefile";
614//ofstream os(makename.c_str(),ios::out);
615//if(!os)
616// {cout<<"CxxExecutor::CrMakefile: unable to open file for Makefile"<<endl;
617// return 1;}
618//---------------------------------------------------------------------
619//os<<"MODULEDECCXXFLAGS := -msg_quiet"<<endl;
620//os<<"include $(DPCBASEREP)/Include/MakefileUser.h"<<endl;
621//os<<"MYLIBS ="<<endl;
622//os<<"LIBS = -L$(SLB) -lPI -lextsophya -lsophya -lm"<<endl;
623//os<<"ifeq ($(MACHEROS),OSF1)"<<endl;
624//os<<"LIBS := $(LIBS) -lfor"<<endl;
625//os<<"endif"<<endl;
626//os<<"ifeq ($(MACHEROS),Linux)"<<endl;
627//os<<"LIBS := $(LIBS) -ldl -lf2c"<<endl;
628//os<<"endif"<<endl;
629//os<<"%.so:%.o"<<endl;
630//os<<"%:%.cc"<<endl;
631//os<<"%:%.o"<<endl;
632//os<<"%.o:%.cc"<<endl;
633//os<<"%.o:%.c"<<endl;
634//os<<"%:%.c"<<endl;
635//os<<endl;
636//os<<".PRECIOUS: %.so"<<endl;
637//os<<endl;
638//os<<"%:%.so"<<endl;
639//os<<"\t"<<"echo $@ \" made (.so) \""<<endl;
640//os<<"%.so:%.o"<<endl;
641//os<<"\t"<<"$(LINK.cc) -shared -o $@ $< $(LIBS) $(MYLIBS)"<<endl;
642//os<<"%.o:%.cc"<<endl;
643//os<<"\t"<<"$(COMPILE.cc) -o $@ $<"<<endl;
644//os<<"%.o:%.c"<<endl;
645//os<<"\t"<<"$(COMPILE.c) -c $(CFLAGS) $(USERFLAGS) -o $@ $<"<<endl;
646//---------------------------------------------------------------------
647//return 0;
648//}
649
650/* --Methode-- */
651int CxxExecutor::Link(string libname,string func)
652{
653if(libname.size()<1) libname = mDefTmp + mDefRoot + ".so";
654 else libname = mDefTmp + libname;
655if(func.size()<1) func = mDefFunc;
656
657NamedObjMgr omg;
658PIACmd* mpiac = omg.GetImgApp()->CmdInterpreter();
659
660string key("linkff2");
661vector<string> arg; arg.push_back(libname); arg.push_back(func);
662string toks = libname + " " + func;
663int rc = mpiac->ExecuteCommand(key,arg,toks);
664if(mPrtLevel>1) cout<<"Link from "<<libname<<" for function "<<func
665 <<" (rc="<<rc<<")"<<endl;
666return 0;
667}
668
669/* --Methode-- */
670int CxxExecutor::Call(string func)
671{
672if(func.size()<1) func = mDefFunc;
673
674NamedObjMgr omg;
675PIACmd* mpiac = omg.GetImgApp()->CmdInterpreter();
676
677string key("call");
678vector<string> arg; arg.push_back(func);
679string toks = func;
680if(mCallArgs.size()>0)
681 for(uint_4 i=0;i<mCallArgs.size();i++) arg.push_back(mCallArgs[i]);
682mpiac->ExecuteCommand(key,arg,toks);
683return 0;
684}
685
686/* --Methode-- */
687void CxxExecutor::FillArgs(vector<string>& args)
688{
689mCallArgs.resize(0);
690if(args.size()<1) return;
691for(uint_4 i=0;i<args.size();i++) mCallArgs.push_back(args[i]);
692}
693
694void CxxExecutor::FillArgs(string& args)
695{
696mCallArgs.resize(0);
697FillVStringFrString(args,mCallArgs,' ');
698}
699
700string CxxExecutor::GetArgs(void)
701{
702string dum = "";
703if(mCallArgs.size()<1) return dum;
704for(uint_4 i=0;i<mCallArgs.size();i++) dum += mCallArgs[i] + " ";
705return dum;
706}
707
708/* --Methode-- */
709void CxxExecutor::FillInclude(vector<string>& inc)
710{
711mIncList.resize(0);
712if(inc.size()<1) return;
713for(uint_4 i=0;i<inc.size();i++) mIncList.push_back(inc[i]);
714}
715
716void CxxExecutor::FillInclude(string& inc)
717{
718mIncList.resize(0);
719FillVStringFrString(inc,mIncList,' ');
720}
721
722string CxxExecutor::GetInclude(void)
723{
724string dum = "";
725if(mIncList.size()<1) return dum;
726for(uint_4 i=0;i<mIncList.size();i++) dum += mIncList[i] + " ";
727return dum;
728}
729
730/* --Methode-- */
731void CxxExecutor::FillCompileOpt(vector<string>& copt)
732{
733mCompOpt = "";
734if(copt.size()<1) return;
735for(uint_4 i=0;i<copt.size();i++) mCompOpt += copt[i] + " ";
736}
737
738void CxxExecutor::FillCompileOpt(string& copt)
739{
740mCompOpt = copt;
741}
742
743string CxxExecutor::GetCompileOpt(void)
744{
745return mCompOpt;
746}
747
748/* --Methode-- */
749void CxxExecutor::FillLinkOpt(vector<string>& lopt)
750{
751mLinkOpt = "";
752if(lopt.size()<1) return;
753for(uint_4 i=0;i<lopt.size();i++) mLinkOpt += lopt[i] + " ";
754}
755
756void CxxExecutor::FillLinkOpt(string& lopt)
757{
758mLinkOpt = lopt;
759}
760
761string CxxExecutor::GetLinkOpt(void)
762{
763return mLinkOpt;
764}
765
766/* --Methode-- */
767void CxxExecutor::FillLinkLibs(vector<string>& llibs)
768{
769mMyLibs = "";
770if(llibs.size()<1) return;
771for(uint_4 i=0;i<llibs.size();i++) mMyLibs += llibs[i] + " ";
772}
773
774void CxxExecutor::FillLinkLibs(string& llibs)
775{
776mMyLibs = llibs;
777}
778
779string CxxExecutor::GetLinkLibs(void)
780{
781return mMyLibs;
782}
783
784/* --Methode-- */
785void CxxExecutor::FillModuleImport(vector<string>& import)
786{
787mModuleImportList.resize(0);
788mIncImportList.resize(0);
789if(import.size()<1) return;
790
791if(import[0]=="all" || import[0]=="All" || import[0]=="ALL") {
792 mModuleImportList = mModuleImportDefaultList;
793} else {
794 for(uint_4 i=0;i<import.size();i++) mModuleImportList.push_back(import[i]);
795}
796
797// Set additionnal Includes
798if(mModuleImportList.size()>0)
799 for(uint_4 i=0;i<mModuleImportList.size();i++) {
800 if( mModuleImportList[i]=="Samba") mIncImportList.push_back("samba.h");
801 else if(mModuleImportList[i]=="SkyMap") mIncImportList.push_back("skymap.h");
802 else if(mModuleImportList[i]=="SkyT") mIncImportList.push_back("skyt.h");
803 else if(mModuleImportList[i]=="FitsIOServer") mIncImportList.push_back("fitsautoreader.h");
804 else if(mModuleImportList[i]=="IFFTW") mIncImportList.push_back("fftwserver.h");
805 else if(mModuleImportList[i]=="LinAlg") mIncImportList.push_back("intflapack.h");
806}
807
808return;
809}
810
811void CxxExecutor::FillModuleImport(string& import)
812{
813mModuleImportList.resize(0);
814vector<string> vsimport;
815FillVStringFrString(import,vsimport,' ');
816FillModuleImport(vsimport);
817}
818
819string CxxExecutor::GetModuleImport(void)
820{
821string dum = "";
822if(mModuleImportList.size()<1) return dum;
823for(uint_4 i=0;i<mModuleImportList.size();i++) dum += mModuleImportList[i] + " ";
824return dum;
825}
Note: See TracBrowser for help on using the repository browser.