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

Last change on this file since 1297 was 1297, checked in by ercodmgr, 25 years ago

1-/ complete color map in pihisto2d
2-/ introcution de la notion de module additionnel

dans le C++EXECUTOR cmv 7/11/2000

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