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

Last change on this file since 2154 was 2123, checked in by cmv, 23 years ago

add -lm et separ Peida/Sophya rz+cmv 19/7/2002

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