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

Last change on this file since 1451 was 1450, checked in by ansari, 24 years ago

Compil PIext pour PEIDA ... Reza 6/4/2001

  • Property svn:executable set to *
File size: 24.1 KB
RevLine 
[1224]1#include "cxxexecutor.h"
2
3#include <typeinfo>
4
[1237]5#include "strutilxx.h"
[1224]6#include "dvlist.h"
[1287]7#include "cxxcmplnk.h"
[1224]8
9#include "nomgadapter.h"
10#include "pistdimgapp.h"
11
12
13/* --Methode-- */
14CxxExecutor::CxxExecutor(PIACmd *mpiac, PIStdImgApp* /* app */)
[1287]15 : mUserCodeFn(""), mUserFctFn("")
16 , mCompOpt(""), mLinkOpt(""), mMyLibs("")
[1289]17 , mDefTmp(""), mDefRoot("cxx_spiapp"), mDefFunc("usercxx"), mPrtLevel(2)
[1224]18{
19mIncList.resize(0);
20mCallArgs.resize(0);
21
[1297]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");
[1319]29mModuleImportDefaultList.push_back("SkyT");
30mModuleImportDefaultList.push_back("FitsIOServer");
31mModuleImportDefaultList.push_back("IFFTW");
32mModuleImportDefaultList.push_back("LinAlg");
[1297]33
[1268]34// Gestion des fichiers par default dans TmpDir
[1287]35NamedObjMgr omg;
36string tmpdir = omg.GetTmpDir();
37if(tmpdir.size()>1) mDefTmp = tmpdir;
[1268]38
[1224]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";
[1237]45usage+= "Usage: c++exec c++ user code\n";
[1268]46usage+= "Warning: c++ user code can be found in \"TmpDir/"+mDefRoot+".h\"\n";
47usage+= " total generated code can be found in \"TmpDir/"+mDefRoot+".cc\"";
[1224]48mpiac->RegisterCommand(kw, usage, this, hgrp);
49
50kw = "c++execfrf";
[1268]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\"";
[1224]54mpiac->RegisterCommand(kw, usage, this, hgrp);
55
56kw = "c++args";
[1237]57usage = "c++args: Define user function arguments for c++exec and c++execfrf\n";
[1230]58usage+= "Usage: c++args arg1 arg2 arg3 ...\n";
59usage+= " c++args -? : give current arguments\n";
60usage+= " c++args : reset current arguments";
[1224]61mpiac->RegisterCommand(kw, usage, this, hgrp);
62
63kw = "c++create";
[1287]64usage = "c++create: create a file \"file.cc\" to be used by spiapp\n";
[1224]65usage+= "Usage: c++create file.cc func c++ user code...\n";
66mpiac->RegisterCommand(kw, usage, this, hgrp);
67
68kw = "c++createfrf";
[1287]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";
[1268]72usage+= "Usage: c++createfrf file.cc func fileuser.cc [fileuserfct.cc]\n";
[1224]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";
[1297]88usage = "c++include: add personnal includes to be used by executor\n";
[1224]89usage+= "Usage: c++include myinc1.h myinc2.h ...\n";
[1297]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...";
[1224]93mpiac->RegisterCommand(kw, usage, this, hgrp);
94
95kw = "c++compileopt";
[1297]96usage = "c++compileopt: add personnal compile options\n";
[1224]97usage+= "Usage: c++compileopt -g -O5 -IMy_Inc_Dir ...\n";
[1297]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 ...";
[1224]101mpiac->RegisterCommand(kw, usage, this, hgrp);
102
103kw = "c++linkopt";
[1297]104usage = "c++linkopt: add personnal link options\n";
[1230]105usage+= "Usage: c++linkopt -g -O5 ...\n";
[1297]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 ...";
[1224]109mpiac->RegisterCommand(kw, usage, this, hgrp);
110
111kw = "c++mylibs";
[1297]112usage = "c++mylibs: add personnal libraries\n";
[1230]113usage+= "Usage: c++mylibs -LMy_Lib_Dir -lmylib1 -lmylib2 ...\n";
[1297]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 ...";
[1224]117mpiac->RegisterCommand(kw, usage, this, hgrp);
118
[1297]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);
[1230]128
[1289]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
[1224]137}
138
139/* --Methode-- */
140CxxExecutor::~CxxExecutor()
141{
142}
143
144/* --Methode-- */
[1268]145int CxxExecutor::Execute(string& kw, vector<string>& tokens, string& toks)
[1224]146{
147int rc=0;
[1268]148if(kw == "c++exec") {
[1224]149 if(tokens.size()<1) {
150 cout<<"Usage: c++exec c++ user code"<<endl;
151 return(1);
152 }
[1269]153 rc = ExecuteCXX(toks); if(rc) return(1);
[1268]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 }
[1269]160 rc = FillUserCode(tokens[0]); if(rc) return(1);
161 if(tokens.size()>1) rc = FillUserFctFrF(tokens[1]);
[1287]162 else rc = FillUserFctFrF();
163 if(rc) return(1);
[1224]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") {
[1233]170 if(tokens.size()==1) if(tokens[0]=="-?")
171 {cout<<"c++args "<<GetArgs()<<endl; return(0);}
[1230]172 FillArgs(tokens);
[1224]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 }
[1287]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);
[1224]182
183} else if(kw == "c++createfrf") {
184 if(tokens.size()<3) {
[1268]185 cout<<"Usage: c++createfrf file.cc func fileuser.cc [fileuserfct.cc]"<<endl;
[1224]186 return(1);
187 }
[1269]188 rc = FillUserCode(tokens[2]); if(rc) return(1);
[1287]189 if(tokens.size()>3) rc = FillUserFctFrF(tokens[3]);
190 else rc = FillUserFctFrF(tokens[3]);
191 if(rc) return(1);
[1224]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") {
[1233]206 if(tokens.size()==1) if(tokens[0]=="-?")
207 {cout<<"c++include "<<GetInclude()<<endl; return(0);}
[1230]208 FillInclude(tokens);
[1224]209
210} else if(kw == "c++compileopt") {
[1233]211 if(tokens.size()==1) if(tokens[0]=="-?")
212 {cout<<"c++compileopt "<<GetCompileOpt()<<endl; return(0);}
[1230]213 FillCompileOpt(tokens);
[1224]214
215} else if(kw == "c++linkopt") {
[1233]216 if(tokens.size()==1) if(tokens[0]=="-?")
217 {cout<<"c++linkopt "<<GetLinkOpt()<<endl; return(0);}
[1230]218 FillLinkOpt(tokens);
[1224]219
220} else if(kw == "c++mylibs") {
[1233]221 if(tokens.size()==1) if(tokens[0]=="-?")
222 {cout<<"c++mylibs "<<GetLinkLibs()<<endl; return(0);}
[1230]223 FillLinkLibs(tokens);
[1289]224
[1297]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
[1289]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
[1224]249}
250
251return(0);
252}
253
254/* --Methode-- */
[1269]255int CxxExecutor::ExecuteCXX(string usercode,string userfct)
256{
257int rc=0;
258rc = FillUserCode(usercode,0); if(rc) return(1);
[1287]259rc = FillUserFctFrS(userfct); if(rc) return(1);
[1269]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-- */
[1268]268int CxxExecutor::CrFile(string cfilename,string func)
[1287]269// Si un nom n'est pas precise alors TmpDir/cxx_spiapp.cc
[1262]270{
[1268]271if(cfilename.size()<1) cfilename = mDefTmp + mDefRoot + ".cc";
[1287]272
[1268]273if(func.size()<1) func = mDefFunc;
[1262]274
[1224]275ofstream os(cfilename.c_str(),ios::out);
[1237]276if(!os)
277 {cout<<"CxxExecutor::CrFile: unable to open "<<cfilename<<endl;
278 return 1;}
[1224]279
280PutInclude(os);
281os<<endl;
282
283PutIncludeUser(os);
284os<<endl;
285
[1268]286os<<"//-------------------------------------------------//"<<endl;
[1269]287os<<"//----------------- User Functions ----------------//"<<endl;
[1268]288os<<"//-------------------------------------------------//"<<endl;
289if(mUserFctFn.size()>0) os<<"#include \""<<mUserFctFn<<"\""<<endl;
290os<<endl;
291
292
[1224]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
[1237]309os<<"//--------------------------------------------//"<<endl;
[1269]310os<<"//----------------- User Code ----------------//"<<endl;
[1237]311os<<"//--------------------------------------------//"<<endl;
[1269]312if(mUserCodeFn.size()>0) os<<"#include \""<<mUserCodeFn<<"\""<<endl;
[1224]313os<<endl;
314
315os<<"return 0;"<<endl;
316os<<"}"<<endl;
317
[1289]318if(mPrtLevel>1)
[1269]319 cout<<"File "<<cfilename<<" for function "<<func<<" created :"<<endl;
[1289]320if(mPrtLevel>1 && mUserCodeFn.size()>0)
[1269]321 cout<<" User code was in file "<<mUserCodeFn<<endl;
[1289]322if(mPrtLevel>1 && mUserFctFn.size()>0)
[1269]323 cout<<" User function code was in file "<<mUserFctFn<<endl;
[1224]324return 0;
325}
326
327/* --Methode-- */
328void CxxExecutor::PutInclude(ofstream& os)
329{
[1297]330os<<"#include \"machdefs.h\""<<endl<<endl;
[1224]331
[1297]332os<<"//---- System et stdc++ include files"<<endl
[1224]333 <<"#include <stdio.h>"<<endl
334 <<"#include <stdlib.h>"<<endl
335 <<"#include <math.h>"<<endl
336 <<"#include <ctype.h>"<<endl
337 <<"#include <string.h>"<<endl
338 <<"#include <iostream.h>"<<endl
339 <<"#include <fstream.h>"<<endl
340 <<"#include <complex>"<<endl
341 <<endl
342
343 <<"#include <typeinfo>"<<endl
344 <<"#include <string>"<<endl
345 <<"#include <vector>"<<endl
346 <<"#include <map>"<<endl
347 <<"#include <functional>"<<endl
348 <<"#include <list>"<<endl
349 <<endl
350
351 <<"//---- Sophya include files"<<endl
352 <<"#include \"systools.h\""<<endl
353 <<"#include \"ntools.h\""<<endl
354 <<"#include \"array.h\""<<endl
355 <<"#include \"histats.h\""<<endl
356 <<endl
357
358 <<"//---- Spiapp include files"<<endl
359 <<"#include \"nobjmgr.h\""<<endl
360 <<"#include \"servnobjm.h\""<<endl
[1297]361 <<endl;
[1224]362
[1297]363os<<"//---- Include files from additionnal modules"<<endl;
364if(mIncImportList.size()>0)
365 for(uint_4 i=0;i<mIncImportList.size();i++)
366 os<<"#include \""<<mIncImportList[i]<<"\""<<endl;
367os<<endl;
368
[1319]369os<<"//---- function for Adding and displaying Objects " << endl;
370os<<"void Keep_Object(AnyDataObj & obj, string const & nom) \n{ \n"
371 <<" string name = nom; \n NamedObjMgr om; \n"
372 <<" if (om.GetObj(name)) \n"
373 <<" cerr << \"KeepObj()/Warning Already kept object \" << endl; \n"
374 <<" else om.AddObj(obj, name); \n"
375 <<"} \n" << endl;
376os<<"void Display_Object(AnyDataObj & obj, string const & opt, string const & nom) \n { \n"
377 <<" string name = nom; \n NamedObjMgr om; \n"
378 <<" if (!om.GetObj(name)) \n"
379 <<" om.AddObj(obj, name); \n"
380 <<" om.DisplayObj(name, opt); \n"
381 <<"} \n" << endl;
382
[1297]383os<<"//---- Objects and variables saving"<<endl
[1319]384 <<"#define KeepObj(obj) Keep_Object(obj, #obj);"<<endl
[1224]385 <<"#define KeepVar(var) ___nomobj = #var; omg.GetVarList().Get(___nomobj) = var ;"<<endl
386 <<endl;
387
[1319]388os<<"//---- Displaying objects and command execution"<<endl;
389os<<"#define DisplayObj(obj, att) Display_Object(obj, att, #obj); \n" << endl;
390os<<"#define ExecuteCommand(cmd) srvo.ExecuteCommand(cmd); \n" << endl;
391
[1224]392return;
393}
394
395/* --Methode-- */
396void CxxExecutor::PutIncludeUser(ofstream& os)
397{
398if(mIncList.size()<1) return;
399for(uint_4 i=0;i<mIncList.size();i++)
400 os<<"#include \""<<mIncList[i]<<"\""<<endl;
401}
402
403/* --Methode-- */
404void CxxExecutor::PutObject(ofstream& os)
405{
406NamedObjMgr omg;
407NObjMgrAdapter* objmgrad;
408vector<string> objlist;
409string patt = "*";
410omg.GetObjList(patt,objlist);
411int nobjs = objlist.size();
412
413os<<"//-------------- Object List --------------"<<endl;
414os<<"//Number of objects = "<<nobjs<<endl;
415os<<"string ___nomobj;"<<endl<<endl;
416if(nobjs<=0) return;
417
418string dir,nobj,stmp,obtype;
419for(int i=0;i<nobjs;i++) {
420 objmgrad = omg.GetObjAdapter(objlist[i]);
421 omg.ParseObjectName(objlist[i],dir,nobj);
422 obtype = objmgrad->GetDataObjType();
423 stmp = "___" + nobj;
424
425 os<<"___nomobj = \""<<nobj<<"\";"<<endl;
426 os<<obtype<<"* "<<stmp
427 <<" = dynamic_cast< "<<obtype<<" * >(omg.GetObj(___nomobj));"<<endl;
[1450]428#ifdef SANS_EVOLPLANCK
429 os<<"if("<<stmp<<"==NULL) { \n"
430 <<" cerr << \"CxxExecutor::PutObject: Non existing object "
431 <<" ... please update file \\n \" ;"
432 <<" throw nullPtrErr ; \n } "<<endl;
433#else
[1224]434 os<<"if("<<stmp<<"==NULL) throw NullPtrError"
435 <<"(\"CxxExecutor::PutObject: Non existing object "<<nobj
436 <<"... please update file\");"<<endl;
[1450]437#endif
[1224]438 os<<obtype<<"& "<<nobj<<" = (*"<<stmp<<");"<<endl<<endl;
439}
440
441return;
442}
443
444/* --Methode-- */
445void CxxExecutor::PutVar(ofstream& os)
446{
447os<<"//-------------- Variable List --------------"<<endl;
448NamedObjMgr omg;
449DVList& varlist = omg.GetVarList();
450// varlist.Show(); varlist.Print();
451DVList::ValList::const_iterator it;
452for(it=varlist.Begin(); it!=varlist.End(); it++) {
453 string key = (*it).first;
[1262]454 if (isalpha(key[0]) ) {
455 os<<"___nomobj = \""<<key<<"\";"<<endl;
456 os<<"MuTyV & $"<<key<<" = omg.GetVarList().Get(___nomobj);"<<endl;
457 }
[1224]458}
459
[1237]460return;
[1224]461}
462
463/* --Methode-- */
[1268]464int CxxExecutor::FillUserCode(string& usercode,uint_4 first)
[1287]465// User code is read from input.
[1268]466// - first is the first position in the "string" where the code starts
[1287]467// - Code is put into file "TmpDir/cxx_spiapp.h".
[1224]468{
[1237]469mUserCodeFn = "";
[1268]470
471// get the string part which is after word "first"
472string code = usercode;
473if(code.size()<=0) {cout<<"CxxExecutor::FillUserCode: no user code"<<endl;
474 return 1;}
475size_t q;
476for(uint_4 i=0;i<=first;i++) {
477 q = code.find_first_not_of(" \t");
478 if(q>=code.size()) {code=""; break;}
479 code = code.substr(q);
480 if(i==first) break;
481 q = code.find_first_of(" \t");
482 if(q>=code.size()) {code=""; break;}
483 code = code.substr(q);
484}
485if(code.size()<=0)
486 {cout<<"CxxExecutor::FillUserCode: no user code after "<<first<<endl;
487 return 1;}
488
489// Fill the file with user code
490mUserCodeFn = mDefTmp + mDefRoot + ".h";
[1237]491ofstream os(mUserCodeFn.c_str(),ios::out);
492if(!os) {cout<<"CxxExecutor::FillUserCode: unable to open "
493 <<mUserCodeFn<<endl; mUserCodeFn = ""; return 1;}
[1269]494os<<code<<endl;
[1289]495if(mPrtLevel>1)
[1269]496 cout<<"User code filled from standard input into "<<mUserCodeFn<<endl;
[1224]497return 0;
498}
499
500/* --Methode-- */
[1287]501int CxxExecutor::FillUserFctFrS(string userfctcode)
[1269]502// - Fill user Fonction code from string "userfct"
[1287]503// - Code is put into file "TmpDir/cxx_spiapp_fct.h".
[1224]504{
[1269]505mUserFctFn = "";
[1287]506if(userfctcode.size()<1) return 0;
[1269]507mUserFctFn = mDefTmp + mDefRoot + "_fct.h";
508ofstream os(mUserFctFn.c_str(),ios::out);
509if(!os) {cout<<"CxxExecutor::FillUserFctFrS: unable to open "
510 <<mUserFctFn<<endl; mUserFctFn = ""; return 1;}
[1287]511os<<userfctcode<<endl;
[1289]512if(mPrtLevel>1)
[1269]513 cout<<"User Function code filled from standard input into "<<mUserFctFn<<endl;
514return 0;
515}
516
517/* --Methode-- */
518int CxxExecutor::FillUserCode(string filename)
519// User code is read from "filename".
520{
[1237]521mUserCodeFn = filename;
[1289]522if(mPrtLevel>1 && mUserCodeFn.size()>0)
[1269]523 cout<<"User code filled from file "<<mUserCodeFn<<endl;
[1224]524return 0;
525}
526
527/* --Methode-- */
[1270]528int CxxExecutor::FillUserFctFrF(string filefctname)
[1287]529// User function code is read from "filefctname".
[1269]530{
531mUserFctFn = filefctname;
[1289]532if(mPrtLevel>1 && mUserFctFn.size()>0)
[1269]533 cout<<"User Function code filled from file "<<mUserFctFn<<endl;
534return 0;
535}
536
537/* --Methode-- */
[1224]538int CxxExecutor::Compile(string rootfilename)
[1287]539//--------------------------------------------------------//
540// rootfilename = | name | "" ou (default) //
541//--------------------------------------------------------//
542// fichier .cc | name.cc | TmpDir/cxx_spiapp.cc //
543// | ../dir/name.cc | //
544// fichier .o | TmpDir/name.o | TmpDir/cxx_spiapp.o //
545// fichier .so | TmpDir/name.so | TmpDir/cxx_spiapp.so //
546//--------------------------------------------------------//
[1224]547{
[1287]548if(rootfilename.size()<1) rootfilename = mDefTmp + mDefRoot;
[1289]549if(mPrtLevel>1) cout<<"Compile "<<rootfilename<<endl;
[1287]550
551int rc;
552CxxCompilerLinker cxx;
553if(mDefTmp.size()>0) cxx.SetTmpDir(mDefTmp);
[1289]554if(mPrtLevel>0) cxx.SetVerbose(true);
555 else cxx.SetVerbose(false);
[1287]556
557// Compilation
558string fcc = rootfilename + ".cc";
559string fo = "";
560cxx.AddCompileOptions(mCompOpt);
561rc = cxx.Compile(fcc,fo);
[1289]562if(mPrtLevel>1) cout << "Compilation rc = "<<rc<< endl;
[1287]563if(rc) return 1;
564
565// Fabrication Shared Lib.
566string fso = "";
567cxx.AddLinkOptions(mLinkOpt);
[1291]568#ifdef SANS_EVOLPLANCK
569 string sophlib = "-lPIE";
570#else
571 string sophlib = "-lPI";
572#endif
[1287]573cxx.AddLinkOptions(sophlib);
574cxx.AddLinkOptions(mMyLibs);
575rc = cxx.BuildSO(fo,fso);
[1289]576if(mPrtLevel>1) cout << "Shared Library rc = "<<rc<< endl;
[1287]577if(rc) return 2;
578
[1224]579return 0;
580}
581
582/* --Methode-- */
[1287]583//int CxxExecutor::Compile(string rootfilename)
584// Ne marche pas si TmpDir != ""
585//{
586//if(rootfilename.size()<1) rootfilename = mDefRoot;
[1289]587//if(mPrtLevel>1) cout<<"Compile: "<<rootfilename<<endl;
[1287]588//int rc = 0;
589//rc = CrMakefile();
590//if(rc) return(1);
591//string make = "";
592//make += "make -f " + mDefRoot + "_Makefile";
593//make += " CXXFLAGS=\"" + mCompOpt + "\"";
594//make += " LDFLAGS=\"" + mLinkOpt + "\"";
595//make += " MYLIBS=\"" + mMyLibs + "\"";
596//make += " " + rootfilename;
597//rc = system(make.c_str());
598//if(rc)
599// {cout<<"CxxExecutor::Compile : \n"<<make<<" Failed"<<endl;
600// return 1000+rc;}
601//return 0;
602//}
603
604/* --Methode-- */
605//int CxxExecutor::CrMakefile(void)
606// Ne marche pas si TmpDir != ""
607//{
608//string makename = mDefTmp + mDefRoot + "_Makefile";
609//ofstream os(makename.c_str(),ios::out);
610//if(!os)
611// {cout<<"CxxExecutor::CrMakefile: unable to open file for Makefile"<<endl;
612// return 1;}
[1224]613//---------------------------------------------------------------------
[1287]614//os<<"MODULEDECCXXFLAGS := -msg_quiet"<<endl;
615//os<<"include $(DPCBASEREP)/Include/MakefileUser.h"<<endl;
616//os<<"MYLIBS ="<<endl;
617//os<<"LIBS = -L$(SLB) -lPI -lextsophya -lsophya -lm"<<endl;
618//os<<"ifeq ($(MACHEROS),OSF1)"<<endl;
619//os<<"LIBS := $(LIBS) -lfor"<<endl;
620//os<<"endif"<<endl;
621//os<<"ifeq ($(MACHEROS),Linux)"<<endl;
622//os<<"LIBS := $(LIBS) -ldl -lf2c"<<endl;
623//os<<"endif"<<endl;
624//os<<"%.so:%.o"<<endl;
625//os<<"%:%.cc"<<endl;
626//os<<"%:%.o"<<endl;
627//os<<"%.o:%.cc"<<endl;
628//os<<"%.o:%.c"<<endl;
629//os<<"%:%.c"<<endl;
630//os<<endl;
631//os<<".PRECIOUS: %.so"<<endl;
632//os<<endl;
633//os<<"%:%.so"<<endl;
634//os<<"\t"<<"echo $@ \" made (.so) \""<<endl;
635//os<<"%.so:%.o"<<endl;
636//os<<"\t"<<"$(LINK.cc) -shared -o $@ $< $(LIBS) $(MYLIBS)"<<endl;
637//os<<"%.o:%.cc"<<endl;
638//os<<"\t"<<"$(COMPILE.cc) -o $@ $<"<<endl;
639//os<<"%.o:%.c"<<endl;
640//os<<"\t"<<"$(COMPILE.c) -c $(CFLAGS) $(USERFLAGS) -o $@ $<"<<endl;
[1224]641//---------------------------------------------------------------------
[1287]642//return 0;
643//}
[1224]644
645/* --Methode-- */
646int CxxExecutor::Link(string libname,string func)
647{
[1268]648if(libname.size()<1) libname = mDefTmp + mDefRoot + ".so";
[1287]649 else libname = mDefTmp + libname;
[1268]650if(func.size()<1) func = mDefFunc;
651
[1224]652NamedObjMgr omg;
653PIACmd* mpiac = omg.GetImgApp()->CmdInterpreter();
[1287]654
[1276]655string key("linkff2");
[1224]656vector<string> arg; arg.push_back(libname); arg.push_back(func);
[1268]657string toks = libname + " " + func;
658int rc = mpiac->ExecuteCommand(key,arg,toks);
[1289]659if(mPrtLevel>1) cout<<"Link from "<<libname<<" for function "<<func
[1287]660 <<" (rc="<<rc<<")"<<endl;
[1224]661return 0;
662}
663
664/* --Methode-- */
665int CxxExecutor::Call(string func)
666{
[1268]667if(func.size()<1) func = mDefFunc;
668
[1224]669NamedObjMgr omg;
670PIACmd* mpiac = omg.GetImgApp()->CmdInterpreter();
[1287]671
[1224]672string key("call");
673vector<string> arg; arg.push_back(func);
[1268]674string toks = func;
[1224]675if(mCallArgs.size()>0)
[1237]676 for(uint_4 i=0;i<mCallArgs.size();i++) arg.push_back(mCallArgs[i]);
[1268]677mpiac->ExecuteCommand(key,arg,toks);
[1224]678return 0;
679}
680
[1230]681/* --Methode-- */
682void CxxExecutor::FillArgs(vector<string>& args)
683{
684mCallArgs.resize(0);
685if(args.size()<1) return;
686for(uint_4 i=0;i<args.size();i++) mCallArgs.push_back(args[i]);
687}
688
689void CxxExecutor::FillArgs(string& args)
690{
691mCallArgs.resize(0);
692FillVStringFrString(args,mCallArgs,' ');
693}
694
695string CxxExecutor::GetArgs(void)
696{
697string dum = "";
698if(mCallArgs.size()<1) return dum;
699for(uint_4 i=0;i<mCallArgs.size();i++) dum += mCallArgs[i] + " ";
700return dum;
701}
702
703/* --Methode-- */
704void CxxExecutor::FillInclude(vector<string>& inc)
705{
706mIncList.resize(0);
707if(inc.size()<1) return;
708for(uint_4 i=0;i<inc.size();i++) mIncList.push_back(inc[i]);
709}
710
711void CxxExecutor::FillInclude(string& inc)
712{
713mIncList.resize(0);
714FillVStringFrString(inc,mIncList,' ');
715}
716
717string CxxExecutor::GetInclude(void)
718{
719string dum = "";
720if(mIncList.size()<1) return dum;
721for(uint_4 i=0;i<mIncList.size();i++) dum += mIncList[i] + " ";
722return dum;
723}
724
725/* --Methode-- */
726void CxxExecutor::FillCompileOpt(vector<string>& copt)
727{
728mCompOpt = "";
729if(copt.size()<1) return;
730for(uint_4 i=0;i<copt.size();i++) mCompOpt += copt[i] + " ";
731}
732
733void CxxExecutor::FillCompileOpt(string& copt)
734{
735mCompOpt = copt;
736}
737
738string CxxExecutor::GetCompileOpt(void)
739{
740return mCompOpt;
741}
742
743/* --Methode-- */
744void CxxExecutor::FillLinkOpt(vector<string>& lopt)
745{
746mLinkOpt = "";
747if(lopt.size()<1) return;
748for(uint_4 i=0;i<lopt.size();i++) mLinkOpt += lopt[i] + " ";
749}
750
751void CxxExecutor::FillLinkOpt(string& lopt)
752{
753mLinkOpt = lopt;
754}
755
756string CxxExecutor::GetLinkOpt(void)
757{
758return mLinkOpt;
759}
760
761/* --Methode-- */
762void CxxExecutor::FillLinkLibs(vector<string>& llibs)
763{
764mMyLibs = "";
765if(llibs.size()<1) return;
766for(uint_4 i=0;i<llibs.size();i++) mMyLibs += llibs[i] + " ";
767}
768
769void CxxExecutor::FillLinkLibs(string& llibs)
770{
771mMyLibs = llibs;
772}
773
774string CxxExecutor::GetLinkLibs(void)
775{
776return mMyLibs;
777}
[1297]778
779/* --Methode-- */
780void CxxExecutor::FillModuleImport(vector<string>& import)
781{
782mModuleImportList.resize(0);
783mIncImportList.resize(0);
784if(import.size()<1) return;
785
786if(import[0]=="all" || import[0]=="All" || import[0]=="ALL") {
787 mModuleImportList = mModuleImportDefaultList;
788} else {
789 for(uint_4 i=0;i<import.size();i++) mModuleImportList.push_back(import[i]);
790}
791
792// Set additionnal Includes
793if(mModuleImportList.size()>0)
794 for(uint_4 i=0;i<mModuleImportList.size();i++) {
795 if( mModuleImportList[i]=="Samba") mIncImportList.push_back("samba.h");
796 else if(mModuleImportList[i]=="SkyMap") mIncImportList.push_back("skymap.h");
[1319]797 else if(mModuleImportList[i]=="SkyT") mIncImportList.push_back("skyt.h");
798 else if(mModuleImportList[i]=="FitsIOServer") mIncImportList.push_back("fitsautoreader.h");
799 else if(mModuleImportList[i]=="IFFTW") mIncImportList.push_back("fftwserver.h");
800 else if(mModuleImportList[i]=="LinAlg") mIncImportList.push_back("intflapack.h");
[1297]801}
802
803return;
804}
805
806void CxxExecutor::FillModuleImport(string& import)
807{
808mModuleImportList.resize(0);
809vector<string> vsimport;
810FillVStringFrString(import,vsimport,' ');
811FillModuleImport(vsimport);
812}
813
814string CxxExecutor::GetModuleImport(void)
815{
816string dum = "";
817if(mModuleImportList.size()<1) return dum;
818for(uint_4 i=0;i<mModuleImportList.size();i++) dum += mModuleImportList[i] + " ";
819return dum;
820}
Note: See TracBrowser for help on using the repository browser.