1 | #include "cxxexecutor.h"
|
---|
2 |
|
---|
3 | #include <typeinfo>
|
---|
4 |
|
---|
5 | #include "strutilxx.h"
|
---|
6 | #include "dvlist.h"
|
---|
7 |
|
---|
8 | #include "nomgadapter.h"
|
---|
9 | #include "pistdimgapp.h"
|
---|
10 |
|
---|
11 |
|
---|
12 | /* --Methode-- */
|
---|
13 | CxxExecutor::CxxExecutor(PIACmd *mpiac, PIStdImgApp* /* app */)
|
---|
14 | : mUserCodeFn(""), mUserFctFn(""), mCompOpt(""), mLinkOpt(""), mMyLibs("")
|
---|
15 | , mDefTmp(""), mDefRoot("cxx_spiapp"), mDefFunc("usercxx")
|
---|
16 | {
|
---|
17 | mIncList.resize(0);
|
---|
18 | mCallArgs.resize(0);
|
---|
19 |
|
---|
20 | // Gestion des fichiers par default dans TmpDir
|
---|
21 | //.... CMV a gerer mais pas forcement OK ... voir avec Rz
|
---|
22 | //NamedObjMgr omg;
|
---|
23 | //string tmpdir = omg.GetTmpDir();
|
---|
24 | //if(tmpdir.size()>1) mDefTmp = tmpdir;
|
---|
25 |
|
---|
26 | // On enregistre les nouvelles commandes
|
---|
27 | string hgrp = "CxxExecutorCmd";
|
---|
28 | string usage,kw;
|
---|
29 |
|
---|
30 | kw = "c++exec";
|
---|
31 | usage = "c++exec: Execute the following c++ user code\n";
|
---|
32 | usage+= "Usage: c++exec c++ user code\n";
|
---|
33 | usage+= "Warning: c++ user code can be found in \"TmpDir/"+mDefRoot+".h\"\n";
|
---|
34 | usage+= " total generated code can be found in \"TmpDir/"+mDefRoot+".cc\"";
|
---|
35 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
36 |
|
---|
37 | kw = "c++execfrf";
|
---|
38 | usage = "c++execfrf: Execute c++ user_code [user_function_code]\n";
|
---|
39 | usage+= "Usage: c++execfrf fileuser.cc [fileuserfct.cc]\n";
|
---|
40 | usage+= "Warning: total generated code can be found in \"TmpDir/"+mDefRoot+".cc\"";
|
---|
41 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
42 |
|
---|
43 | kw = "c++args";
|
---|
44 | usage = "c++args: Define user function arguments for c++exec and c++execfrf\n";
|
---|
45 | usage+= "Usage: c++args arg1 arg2 arg3 ...\n";
|
---|
46 | usage+= " c++args -? : give current arguments\n";
|
---|
47 | usage+= " c++args : reset current arguments";
|
---|
48 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
49 |
|
---|
50 | kw = "c++create";
|
---|
51 | usage = "c++create: create a file to be used by spiapp\n";
|
---|
52 | usage+= "Usage: c++create file.cc func c++ user code...\n";
|
---|
53 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
54 |
|
---|
55 | kw = "c++createfrf";
|
---|
56 | usage = "c++createfrf: create a file \"file.cc\"to be used by spiapp\n";
|
---|
57 | usage+= " with a user file code \"fileuser.cc\"\n";
|
---|
58 | usage+= " and an optional user function code \"fileuserfct.cc\"\n";
|
---|
59 | usage+= "Usage: c++createfrf file.cc func fileuser.cc [fileuserfct.cc]\n";
|
---|
60 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
61 |
|
---|
62 | kw = "c++compile";
|
---|
63 | usage = "c++compile: compile a file (file.cc -> file.so)\n";
|
---|
64 | usage+= "Usage: c++compile file\n";
|
---|
65 | usage+= "Warning: give \"file\" or \"file.so\" to create \"file.so\" from \"file.cc\"\n";
|
---|
66 | usage+= " : to be used before c++link";
|
---|
67 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
68 |
|
---|
69 | kw = "c++link";
|
---|
70 | usage = "c++link: link function \"func\" in file.so to spiapp\n";
|
---|
71 | usage+= "Usage: c++link file.so func";
|
---|
72 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
73 |
|
---|
74 | kw = "c++include";
|
---|
75 | usage = "c++include: give personnal includes to be used\n";
|
---|
76 | usage+= "Usage: c++include myinc1.h myinc2.h ...\n";
|
---|
77 | usage+= " c++include -? : give current include files\n";
|
---|
78 | usage+= " c++include : reset current include files\n";
|
---|
79 | usage+= "Warning: to be used before c++create... c++exec...";
|
---|
80 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
81 |
|
---|
82 | kw = "c++compileopt";
|
---|
83 | usage = "c++compileopt: give additionnal compile options\n";
|
---|
84 | usage+= "Usage: c++compileopt -g -O5 -IMy_Inc_Dir ...\n";
|
---|
85 | usage+= " c++compileopt -? : give current compile options\n";
|
---|
86 | usage+= " c++compileopt : reset current compile options\n";
|
---|
87 | usage+= "Warning: to be used before c++compile";
|
---|
88 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
89 |
|
---|
90 | kw = "c++linkopt";
|
---|
91 | usage = "c++linkopt: give additionnal link options\n";
|
---|
92 | usage+= "Usage: c++linkopt -g -O5 ...\n";
|
---|
93 | usage+= " c++linkopt -? : give current link options\n";
|
---|
94 | usage+= " c++linkopt : reset current link options\n";
|
---|
95 | usage+= "Warning: to be used before c++compile";
|
---|
96 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
97 |
|
---|
98 | kw = "c++mylibs";
|
---|
99 | usage = "c++mylibs: give additionnal libraries\n";
|
---|
100 | usage+= "Usage: c++mylibs -LMy_Lib_Dir -lmylib1 -lmylib2 ...\n";
|
---|
101 | usage+= " c++mylibs -? : give current additionnal libraries\n";
|
---|
102 | usage+= " c++mylibs : reset current additionnal libraries\n";
|
---|
103 | usage+= "Warning: to be used before c++compile";
|
---|
104 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
105 |
|
---|
106 |
|
---|
107 | }
|
---|
108 |
|
---|
109 | /* --Methode-- */
|
---|
110 | CxxExecutor::~CxxExecutor()
|
---|
111 | {
|
---|
112 | }
|
---|
113 |
|
---|
114 | /* --Methode-- */
|
---|
115 | int CxxExecutor::Execute(string& kw, vector<string>& tokens, string& toks)
|
---|
116 | {
|
---|
117 | int rc=0;
|
---|
118 | if(kw == "c++exec") {
|
---|
119 | if(tokens.size()<1) {
|
---|
120 | cout<<"Usage: c++exec c++ user code"<<endl;
|
---|
121 | return(1);
|
---|
122 | }
|
---|
123 | rc = FillUserCode(toks,0); if(rc) return(1);
|
---|
124 | rc = CrFile(); if(rc) return(1);
|
---|
125 | rc = Compile(); if(rc) return(1);
|
---|
126 | rc = Link(); if(rc) return(1);
|
---|
127 | rc = Call(); if(rc) return(1);
|
---|
128 |
|
---|
129 | } else if(kw == "c++execfrf") {
|
---|
130 | if(tokens.size()<1) {
|
---|
131 | cout<<"Usage: c++execfrf fileuser.cc [fileuserfct.cc]"<<endl;
|
---|
132 | return(1);
|
---|
133 | }
|
---|
134 | if(tokens.size()>1) rc = FillUserCode(tokens[0],tokens[1]);
|
---|
135 | else rc = FillUserCode(tokens[0]);
|
---|
136 | if(rc) return(1);
|
---|
137 | rc = CrFile(); if(rc) return(1);
|
---|
138 | rc = Compile(); if(rc) return(1);
|
---|
139 | rc = Link(); if(rc) return(1);
|
---|
140 | rc = Call(); if(rc) return(1);
|
---|
141 |
|
---|
142 | } else if(kw == "c++args") {
|
---|
143 | if(tokens.size()==1) if(tokens[0]=="-?")
|
---|
144 | {cout<<"c++args "<<GetArgs()<<endl; return(0);}
|
---|
145 | FillArgs(tokens);
|
---|
146 |
|
---|
147 | } else if(kw == "c++create") {
|
---|
148 | if(tokens.size()<3) {
|
---|
149 | cout<<"Usage: c++create file.cc func c++ user code ..."<<endl;
|
---|
150 | return(1);
|
---|
151 | }
|
---|
152 | rc = FillUserCode(toks,2); if(rc) return(1);
|
---|
153 | rc = CrFile(tokens[0],tokens[1]); if(rc) return(1);
|
---|
154 |
|
---|
155 | } else if(kw == "c++createfrf") {
|
---|
156 | if(tokens.size()<3) {
|
---|
157 | cout<<"Usage: c++createfrf file.cc func fileuser.cc [fileuserfct.cc]"<<endl;
|
---|
158 | return(1);
|
---|
159 | }
|
---|
160 | if(tokens.size()>3) rc = FillUserCode(tokens[2],tokens[3]);
|
---|
161 | else rc = FillUserCode(tokens[2]);
|
---|
162 | if(rc) return(1);
|
---|
163 | rc = CrFile(tokens[0],tokens[1]); if(rc) return(1);
|
---|
164 |
|
---|
165 | } else if(kw == "c++compile") {
|
---|
166 | if(tokens.size()>=1) rc = Compile(tokens[0]);
|
---|
167 | else rc = Compile();
|
---|
168 | if(rc) return(1);
|
---|
169 |
|
---|
170 | } else if(kw == "c++link") {
|
---|
171 | if(tokens.size()>=2) rc = Link(tokens[0],tokens[1]);
|
---|
172 | else if(tokens.size()>=1) rc = Link(tokens[0]);
|
---|
173 | else rc = Link();
|
---|
174 | if(rc) return(1);
|
---|
175 |
|
---|
176 | } else if(kw == "c++include") {
|
---|
177 | if(tokens.size()==1) if(tokens[0]=="-?")
|
---|
178 | {cout<<"c++include "<<GetInclude()<<endl; return(0);}
|
---|
179 | FillInclude(tokens);
|
---|
180 |
|
---|
181 | } else if(kw == "c++compileopt") {
|
---|
182 | if(tokens.size()==1) if(tokens[0]=="-?")
|
---|
183 | {cout<<"c++compileopt "<<GetCompileOpt()<<endl; return(0);}
|
---|
184 | FillCompileOpt(tokens);
|
---|
185 |
|
---|
186 | } else if(kw == "c++linkopt") {
|
---|
187 | if(tokens.size()==1) if(tokens[0]=="-?")
|
---|
188 | {cout<<"c++linkopt "<<GetLinkOpt()<<endl; return(0);}
|
---|
189 | FillLinkOpt(tokens);
|
---|
190 |
|
---|
191 | } else if(kw == "c++mylibs") {
|
---|
192 | if(tokens.size()==1) if(tokens[0]=="-?")
|
---|
193 | {cout<<"c++mylibs "<<GetLinkLibs()<<endl; return(0);}
|
---|
194 | FillLinkLibs(tokens);
|
---|
195 | }
|
---|
196 |
|
---|
197 | return(0);
|
---|
198 | }
|
---|
199 |
|
---|
200 | /* --Methode-- */
|
---|
201 | int CxxExecutor::CrFile(string cfilename,string func)
|
---|
202 | {
|
---|
203 | if(cfilename.size()<1) cfilename = mDefTmp + mDefRoot + ".cc";
|
---|
204 | if(func.size()<1) func = mDefFunc;
|
---|
205 |
|
---|
206 | ofstream os(cfilename.c_str(),ios::out);
|
---|
207 | if(!os)
|
---|
208 | {cout<<"CxxExecutor::CrFile: unable to open "<<cfilename<<endl;
|
---|
209 | return 1;}
|
---|
210 |
|
---|
211 | PutInclude(os);
|
---|
212 | os<<endl;
|
---|
213 |
|
---|
214 | PutIncludeUser(os);
|
---|
215 | os<<endl;
|
---|
216 |
|
---|
217 | os<<"//-------------------------------------------------//"<<endl;
|
---|
218 | os<<"//------------- Fonctions utilisateur -------------//"<<endl;
|
---|
219 | os<<"//-------------------------------------------------//"<<endl;
|
---|
220 | if(mUserFctFn.size()>0) os<<"#include \""<<mUserFctFn<<"\""<<endl;
|
---|
221 | os<<endl;
|
---|
222 |
|
---|
223 |
|
---|
224 | os<<"extern \"C\" {"<<endl;
|
---|
225 | os<<" int "<<func<<"( vector<string>& args );"<<endl;
|
---|
226 | os<<"}"<<endl<<endl;
|
---|
227 | os<<"int "<<func<<"( vector<string>& args )"<<endl;
|
---|
228 | os<<"{"<<endl;
|
---|
229 | os<<"// Some definitions to help using spiapp;"<<endl;
|
---|
230 | os<<"NamedObjMgr omg;"<<endl;
|
---|
231 | os<<"Services2NObjMgr& srvo = *omg.GetServiceObj();"<<endl;
|
---|
232 | os<<endl;
|
---|
233 |
|
---|
234 | PutObject(os);
|
---|
235 | os<<endl;
|
---|
236 |
|
---|
237 | PutVar(os);
|
---|
238 | os<<endl;
|
---|
239 |
|
---|
240 | os<<"//--------------------------------------------//"<<endl;
|
---|
241 | os<<"//------------- Code utilisateur -------------//"<<endl;
|
---|
242 | os<<"//--------------------------------------------//"<<endl;
|
---|
243 | os<<endl;
|
---|
244 | os<<"#include \""<<mUserCodeFn<<"\""<<endl;
|
---|
245 | os<<endl;
|
---|
246 |
|
---|
247 | os<<"return 0;"<<endl;
|
---|
248 | os<<"}"<<endl;
|
---|
249 |
|
---|
250 | cout<<"File "<<cfilename<<" for function "<<func<<" created"<<endl;
|
---|
251 | cout<<"User code is in file "<<mUserCodeFn<<" included in "<<cfilename<<endl;
|
---|
252 | return 0;
|
---|
253 | }
|
---|
254 |
|
---|
255 | /* --Methode-- */
|
---|
256 | void CxxExecutor::PutInclude(ofstream& os)
|
---|
257 | {
|
---|
258 | os<<"#include \"machdefs.h\""<<endl
|
---|
259 | <<endl
|
---|
260 |
|
---|
261 | <<"//---- System et stdc++ include files"<<endl
|
---|
262 | <<"#include <stdio.h>"<<endl
|
---|
263 | <<"#include <stdlib.h>"<<endl
|
---|
264 | <<"#include <math.h>"<<endl
|
---|
265 | <<"#include <ctype.h>"<<endl
|
---|
266 | <<"#include <string.h>"<<endl
|
---|
267 | <<"#include <iostream.h>"<<endl
|
---|
268 | <<"#include <fstream.h>"<<endl
|
---|
269 | <<"#include <complex>"<<endl
|
---|
270 | <<endl
|
---|
271 |
|
---|
272 | <<"#include <typeinfo>"<<endl
|
---|
273 | <<"#include <string>"<<endl
|
---|
274 | <<"#include <vector>"<<endl
|
---|
275 | <<"#include <map>"<<endl
|
---|
276 | <<"#include <functional>"<<endl
|
---|
277 | <<"#include <list>"<<endl
|
---|
278 | <<endl
|
---|
279 |
|
---|
280 | <<"//---- Sophya include files"<<endl
|
---|
281 | <<"#include \"systools.h\""<<endl
|
---|
282 | <<"#include \"ntools.h\""<<endl
|
---|
283 | <<"#include \"array.h\""<<endl
|
---|
284 | <<"#include \"histats.h\""<<endl
|
---|
285 | <<endl
|
---|
286 |
|
---|
287 | <<"//---- Spiapp include files"<<endl
|
---|
288 | <<"#include \"nobjmgr.h\""<<endl
|
---|
289 | <<"#include \"servnobjm.h\""<<endl
|
---|
290 | <<endl
|
---|
291 |
|
---|
292 | <<"#define KeepObj(obj) ___nomobj = #obj; omg.AddObj(obj,___nomobj);"<<endl
|
---|
293 | <<"#define KeepVar(var) ___nomobj = #var; omg.GetVarList().Get(___nomobj) = var ;"<<endl
|
---|
294 | <<endl;
|
---|
295 |
|
---|
296 | return;
|
---|
297 | }
|
---|
298 |
|
---|
299 | /* --Methode-- */
|
---|
300 | void CxxExecutor::PutIncludeUser(ofstream& os)
|
---|
301 | {
|
---|
302 | if(mIncList.size()<1) return;
|
---|
303 | for(uint_4 i=0;i<mIncList.size();i++)
|
---|
304 | os<<"#include \""<<mIncList[i]<<"\""<<endl;
|
---|
305 | }
|
---|
306 |
|
---|
307 | /* --Methode-- */
|
---|
308 | void CxxExecutor::PutObject(ofstream& os)
|
---|
309 | {
|
---|
310 | NamedObjMgr omg;
|
---|
311 | NObjMgrAdapter* objmgrad;
|
---|
312 | vector<string> objlist;
|
---|
313 | string patt = "*";
|
---|
314 | omg.GetObjList(patt,objlist);
|
---|
315 | int nobjs = objlist.size();
|
---|
316 |
|
---|
317 | os<<"//-------------- Object List --------------"<<endl;
|
---|
318 | os<<"//Number of objects = "<<nobjs<<endl;
|
---|
319 | os<<"string ___nomobj;"<<endl<<endl;
|
---|
320 | if(nobjs<=0) return;
|
---|
321 |
|
---|
322 | string dir,nobj,stmp,obtype;
|
---|
323 | for(int i=0;i<nobjs;i++) {
|
---|
324 | objmgrad = omg.GetObjAdapter(objlist[i]);
|
---|
325 | omg.ParseObjectName(objlist[i],dir,nobj);
|
---|
326 | obtype = objmgrad->GetDataObjType();
|
---|
327 | stmp = "___" + nobj;
|
---|
328 |
|
---|
329 | os<<"___nomobj = \""<<nobj<<"\";"<<endl;
|
---|
330 | os<<obtype<<"* "<<stmp
|
---|
331 | <<" = dynamic_cast< "<<obtype<<" * >(omg.GetObj(___nomobj));"<<endl;
|
---|
332 | os<<"if("<<stmp<<"==NULL) throw NullPtrError"
|
---|
333 | <<"(\"CxxExecutor::PutObject: Non existing object "<<nobj
|
---|
334 | <<"... please update file\");"<<endl;
|
---|
335 | os<<obtype<<"& "<<nobj<<" = (*"<<stmp<<");"<<endl<<endl;
|
---|
336 | }
|
---|
337 |
|
---|
338 | return;
|
---|
339 | }
|
---|
340 |
|
---|
341 | /* --Methode-- */
|
---|
342 | void CxxExecutor::PutVar(ofstream& os)
|
---|
343 | {
|
---|
344 | os<<"//-------------- Variable List --------------"<<endl;
|
---|
345 | NamedObjMgr omg;
|
---|
346 | DVList& varlist = omg.GetVarList();
|
---|
347 | // varlist.Show(); varlist.Print();
|
---|
348 | DVList::ValList::const_iterator it;
|
---|
349 | for(it=varlist.Begin(); it!=varlist.End(); it++) {
|
---|
350 | string key = (*it).first;
|
---|
351 | if (isalpha(key[0]) ) {
|
---|
352 | os<<"___nomobj = \""<<key<<"\";"<<endl;
|
---|
353 | os<<"MuTyV & $"<<key<<" = omg.GetVarList().Get(___nomobj);"<<endl;
|
---|
354 | }
|
---|
355 | }
|
---|
356 |
|
---|
357 | return;
|
---|
358 | }
|
---|
359 |
|
---|
360 | /* --Methode-- */
|
---|
361 | int CxxExecutor::FillUserCode(string& usercode,uint_4 first)
|
---|
362 | // - first is the first position in the "string" where the code starts
|
---|
363 | // User code is read from input. It is put into file "TmpDir/cxx_spiapp.h".
|
---|
364 | {
|
---|
365 | mUserCodeFn = "";
|
---|
366 | mUserFctFn = "";
|
---|
367 |
|
---|
368 | // get the string part which is after word "first"
|
---|
369 | string code = usercode;
|
---|
370 | if(code.size()<=0) {cout<<"CxxExecutor::FillUserCode: no user code"<<endl;
|
---|
371 | return 1;}
|
---|
372 | size_t q;
|
---|
373 | for(uint_4 i=0;i<=first;i++) {
|
---|
374 | q = code.find_first_not_of(" \t");
|
---|
375 | if(q>=code.size()) {code=""; break;}
|
---|
376 | code = code.substr(q);
|
---|
377 | if(i==first) break;
|
---|
378 | q = code.find_first_of(" \t");
|
---|
379 | if(q>=code.size()) {code=""; break;}
|
---|
380 | code = code.substr(q);
|
---|
381 | }
|
---|
382 | if(code.size()<=0)
|
---|
383 | {cout<<"CxxExecutor::FillUserCode: no user code after "<<first<<endl;
|
---|
384 | return 1;}
|
---|
385 |
|
---|
386 | // Fill the file with user code
|
---|
387 | mUserCodeFn = mDefTmp + mDefRoot + ".h";
|
---|
388 | ofstream os(mUserCodeFn.c_str(),ios::out);
|
---|
389 | if(!os) {cout<<"CxxExecutor::FillUserCode: unable to open "
|
---|
390 | <<mUserCodeFn<<endl; mUserCodeFn = ""; return 1;}
|
---|
391 | os<<" "<<code;
|
---|
392 | cout<<"User code filled from standard input into "<<mUserCodeFn<<endl;
|
---|
393 | return 0;
|
---|
394 | }
|
---|
395 |
|
---|
396 | /* --Methode-- */
|
---|
397 | int CxxExecutor::FillUserCode(string filename,string filefctname)
|
---|
398 | // User code is read from "filename" an optionally from filefctname.
|
---|
399 | {
|
---|
400 | mUserCodeFn = filename;
|
---|
401 | mUserFctFn = filefctname;
|
---|
402 | cout<<"User code filled from file "<<filename<<endl;
|
---|
403 | return 0;
|
---|
404 | }
|
---|
405 |
|
---|
406 | /* --Methode-- */
|
---|
407 | int CxxExecutor::Compile(string rootfilename)
|
---|
408 | {
|
---|
409 | if(rootfilename.size()<1) rootfilename = mDefRoot;
|
---|
410 | cout<<"Compile: "<<rootfilename<<endl;
|
---|
411 | int rc = 0;
|
---|
412 | rc = CrMakefile();
|
---|
413 | if(rc) return(1);
|
---|
414 | string make = "";
|
---|
415 | make += "make -f " + mDefRoot + "_Makefile";
|
---|
416 | make += " CXXFLAGS=\"" + mCompOpt + "\"";
|
---|
417 | make += " LDFLAGS=\"" + mLinkOpt + "\"";
|
---|
418 | make += " MYLIBS=\"" + mMyLibs + "\"";
|
---|
419 | make += " " + rootfilename;
|
---|
420 | rc = system(make.c_str());
|
---|
421 | if(rc)
|
---|
422 | {cout<<"CxxExecutor::Compile : \n"<<make<<" Failed"<<endl;
|
---|
423 | return 1000+rc;}
|
---|
424 | return 0;
|
---|
425 | }
|
---|
426 |
|
---|
427 | /* --Methode-- */
|
---|
428 | int CxxExecutor::CrMakefile(void)
|
---|
429 | {
|
---|
430 | string makename = mDefTmp + mDefRoot + "_Makefile";
|
---|
431 | ofstream os(makename.c_str(),ios::out);
|
---|
432 | if(!os)
|
---|
433 | {cout<<"CxxExecutor::CrMakefile: unable to open file for Makefile"<<endl;
|
---|
434 | return 1;}
|
---|
435 | //---------------------------------------------------------------------
|
---|
436 | os<<"MODULEDECCXXFLAGS := -msg_quiet"<<endl;
|
---|
437 | os<<"include $(DPCBASEREP)/Include/MakefileUser.h"<<endl;
|
---|
438 | os<<"MYLIBS ="<<endl;
|
---|
439 | os<<"LIBS = -L$(SLB) -lPI -lextsophya -lsophya -lm"<<endl;
|
---|
440 | os<<"ifeq ($(MACHEROS),OSF1)"<<endl;
|
---|
441 | os<<"LIBS := $(LIBS) -lfor"<<endl;
|
---|
442 | os<<"endif"<<endl;
|
---|
443 | os<<"ifeq ($(MACHEROS),Linux)"<<endl;
|
---|
444 | os<<"LIBS := $(LIBS) -ldl -lf2c"<<endl;
|
---|
445 | os<<"endif"<<endl;
|
---|
446 | os<<"%.so:%.o"<<endl;
|
---|
447 | os<<"%:%.cc"<<endl;
|
---|
448 | os<<"%:%.o"<<endl;
|
---|
449 | os<<"%.o:%.cc"<<endl;
|
---|
450 | os<<"%.o:%.c"<<endl;
|
---|
451 | os<<"%:%.c"<<endl;
|
---|
452 | os<<endl;
|
---|
453 | os<<".PRECIOUS: %.so"<<endl;
|
---|
454 | os<<endl;
|
---|
455 | os<<"%:%.so"<<endl;
|
---|
456 | os<<"\t"<<"echo $@ \" made (.so) \""<<endl;
|
---|
457 | os<<"%.so:%.o"<<endl;
|
---|
458 | os<<"\t"<<"$(LINK.cc) -shared -o $@ $< $(LIBS) $(MYLIBS)"<<endl;
|
---|
459 | os<<"%.o:%.cc"<<endl;
|
---|
460 | os<<"\t"<<"$(COMPILE.cc) -o $@ $<"<<endl;
|
---|
461 | os<<"%.o:%.c"<<endl;
|
---|
462 | os<<"\t"<<"$(COMPILE.c) -c $(CFLAGS) $(USERFLAGS) -o $@ $<"<<endl;
|
---|
463 | //---------------------------------------------------------------------
|
---|
464 | return 0;
|
---|
465 | }
|
---|
466 |
|
---|
467 | /* --Methode-- */
|
---|
468 | int CxxExecutor::Link(string libname,string func)
|
---|
469 | {
|
---|
470 | if(libname.size()<1) libname = mDefTmp + mDefRoot + ".so";
|
---|
471 | if(func.size()<1) func = mDefFunc;
|
---|
472 |
|
---|
473 | NamedObjMgr omg;
|
---|
474 | PIACmd* mpiac = omg.GetImgApp()->CmdInterpreter();
|
---|
475 | string key("link");
|
---|
476 | vector<string> arg; arg.push_back(libname); arg.push_back(func);
|
---|
477 | string toks = libname + " " + func;
|
---|
478 | int rc = mpiac->ExecuteCommand(key,arg,toks);
|
---|
479 | cout<<"Link from "<<libname<<" for function "<<func
|
---|
480 | <<" (rc="<<rc<<")"<<endl;
|
---|
481 | return 0;
|
---|
482 | }
|
---|
483 |
|
---|
484 | /* --Methode-- */
|
---|
485 | int CxxExecutor::Call(string func)
|
---|
486 | {
|
---|
487 | if(func.size()<1) func = mDefFunc;
|
---|
488 |
|
---|
489 | NamedObjMgr omg;
|
---|
490 | PIACmd* mpiac = omg.GetImgApp()->CmdInterpreter();
|
---|
491 | string key("call");
|
---|
492 | vector<string> arg; arg.push_back(func);
|
---|
493 | string toks = func;
|
---|
494 | if(mCallArgs.size()>0)
|
---|
495 | for(uint_4 i=0;i<mCallArgs.size();i++) arg.push_back(mCallArgs[i]);
|
---|
496 | mpiac->ExecuteCommand(key,arg,toks);
|
---|
497 | return 0;
|
---|
498 | }
|
---|
499 |
|
---|
500 | /* --Methode-- */
|
---|
501 | void CxxExecutor::FillArgs(vector<string>& args)
|
---|
502 | {
|
---|
503 | mCallArgs.resize(0);
|
---|
504 | if(args.size()<1) return;
|
---|
505 | for(uint_4 i=0;i<args.size();i++) mCallArgs.push_back(args[i]);
|
---|
506 | }
|
---|
507 |
|
---|
508 | void CxxExecutor::FillArgs(string& args)
|
---|
509 | {
|
---|
510 | mCallArgs.resize(0);
|
---|
511 | FillVStringFrString(args,mCallArgs,' ');
|
---|
512 | }
|
---|
513 |
|
---|
514 | string CxxExecutor::GetArgs(void)
|
---|
515 | {
|
---|
516 | string dum = "";
|
---|
517 | if(mCallArgs.size()<1) return dum;
|
---|
518 | for(uint_4 i=0;i<mCallArgs.size();i++) dum += mCallArgs[i] + " ";
|
---|
519 | return dum;
|
---|
520 | }
|
---|
521 |
|
---|
522 | /* --Methode-- */
|
---|
523 | void CxxExecutor::FillInclude(vector<string>& inc)
|
---|
524 | {
|
---|
525 | mIncList.resize(0);
|
---|
526 | if(inc.size()<1) return;
|
---|
527 | for(uint_4 i=0;i<inc.size();i++) mIncList.push_back(inc[i]);
|
---|
528 | }
|
---|
529 |
|
---|
530 | void CxxExecutor::FillInclude(string& inc)
|
---|
531 | {
|
---|
532 | mIncList.resize(0);
|
---|
533 | FillVStringFrString(inc,mIncList,' ');
|
---|
534 | }
|
---|
535 |
|
---|
536 | string CxxExecutor::GetInclude(void)
|
---|
537 | {
|
---|
538 | string dum = "";
|
---|
539 | if(mIncList.size()<1) return dum;
|
---|
540 | for(uint_4 i=0;i<mIncList.size();i++) dum += mIncList[i] + " ";
|
---|
541 | return dum;
|
---|
542 | }
|
---|
543 |
|
---|
544 | /* --Methode-- */
|
---|
545 | void CxxExecutor::FillCompileOpt(vector<string>& copt)
|
---|
546 | {
|
---|
547 | mCompOpt = "";
|
---|
548 | if(copt.size()<1) return;
|
---|
549 | for(uint_4 i=0;i<copt.size();i++) mCompOpt += copt[i] + " ";
|
---|
550 | }
|
---|
551 |
|
---|
552 | void CxxExecutor::FillCompileOpt(string& copt)
|
---|
553 | {
|
---|
554 | mCompOpt = copt;
|
---|
555 | }
|
---|
556 |
|
---|
557 | string CxxExecutor::GetCompileOpt(void)
|
---|
558 | {
|
---|
559 | return mCompOpt;
|
---|
560 | }
|
---|
561 |
|
---|
562 | /* --Methode-- */
|
---|
563 | void CxxExecutor::FillLinkOpt(vector<string>& lopt)
|
---|
564 | {
|
---|
565 | mLinkOpt = "";
|
---|
566 | if(lopt.size()<1) return;
|
---|
567 | for(uint_4 i=0;i<lopt.size();i++) mLinkOpt += lopt[i] + " ";
|
---|
568 | }
|
---|
569 |
|
---|
570 | void CxxExecutor::FillLinkOpt(string& lopt)
|
---|
571 | {
|
---|
572 | mLinkOpt = lopt;
|
---|
573 | }
|
---|
574 |
|
---|
575 | string CxxExecutor::GetLinkOpt(void)
|
---|
576 | {
|
---|
577 | return mLinkOpt;
|
---|
578 | }
|
---|
579 |
|
---|
580 | /* --Methode-- */
|
---|
581 | void CxxExecutor::FillLinkLibs(vector<string>& llibs)
|
---|
582 | {
|
---|
583 | mMyLibs = "";
|
---|
584 | if(llibs.size()<1) return;
|
---|
585 | for(uint_4 i=0;i<llibs.size();i++) mMyLibs += llibs[i] + " ";
|
---|
586 | }
|
---|
587 |
|
---|
588 | void CxxExecutor::FillLinkLibs(string& llibs)
|
---|
589 | {
|
---|
590 | mMyLibs = llibs;
|
---|
591 | }
|
---|
592 |
|
---|
593 | string CxxExecutor::GetLinkLibs(void)
|
---|
594 | {
|
---|
595 | return mMyLibs;
|
---|
596 | }
|
---|