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

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

corr. bug c++import Samba cmv 1/8/01

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