1 | // Gestionnaire de compilation-linker C++ - R. Ansari 10/2000
|
---|
2 | // LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA
|
---|
3 |
|
---|
4 | #include "cxxcmplnk.h"
|
---|
5 | #include <iostream.h>
|
---|
6 |
|
---|
7 | /*!
|
---|
8 | \class SOPHYA::CxxCompilerLinker
|
---|
9 | \ingroup SysTools
|
---|
10 | This classes handles the compilation of a C++ source code and
|
---|
11 | building of a shared library.
|
---|
12 | The present version has been adapted for different compilers:
|
---|
13 | g++ , Compaq/Digital cxx , SGI CC , KCC .
|
---|
14 | \sa SOPHYA::PDynLinkMgr
|
---|
15 | \code
|
---|
16 | #include ""cxxcmplnk.h"
|
---|
17 | CxxCompilerLinker cxx;
|
---|
18 | string name = "toto.cc";
|
---|
19 | string oname = "toto.o";
|
---|
20 | string soname = "toto.so";
|
---|
21 | int rc;
|
---|
22 | // compiling file
|
---|
23 | rc = cxx.Compile(name, oname);
|
---|
24 | // linking and building the shared object
|
---|
25 | rc = cxx.BuildSO(oname, soname);
|
---|
26 | \endcode
|
---|
27 | */
|
---|
28 |
|
---|
29 | static char * gcxx_opt =
|
---|
30 | "-O -Wall -Wpointer-arith -Wmissing-prototypes -Wsynth -fdollars-in-identifiers";
|
---|
31 | static char * KCC_opt =
|
---|
32 | "-O --exceptions --rtti --auto_instantiation --one_instantiation_per_object -D__KCC__";
|
---|
33 | static char * cxx_opt =
|
---|
34 | "-O -no_implicit_include ";
|
---|
35 | static char * SGICC_opt = "-O -prelink -D__SGICC__ ";
|
---|
36 |
|
---|
37 | /* --Methode-- */
|
---|
38 | CxxCompilerLinker::CxxCompilerLinker()
|
---|
39 | : verbose(false)
|
---|
40 | {
|
---|
41 |
|
---|
42 | string syscomp = "";
|
---|
43 |
|
---|
44 | #if defined(OSF1)
|
---|
45 | cppFlags += "-DOSF1" ;
|
---|
46 | syscomp = "OSF1-";
|
---|
47 | #elif defined(Linux)
|
---|
48 | cppFlags += "-DLinux" ;
|
---|
49 | syscomp = "Linux-";
|
---|
50 | #elif defined(SunOS)
|
---|
51 | cppFlags += "-DSunOS" ;
|
---|
52 | syscomp = "SunOS-";
|
---|
53 | #elif defined(IRIX64)
|
---|
54 | cppFlags += "-DIRIX64" ;
|
---|
55 | syscomp = "IRIX64-";
|
---|
56 | #elif defined(AIX)
|
---|
57 | cppFlags += "-DAIX" ;
|
---|
58 | syscomp = "AIX-";
|
---|
59 | #elif defined(HPUX)
|
---|
60 | cppFlags += "-DHPUX" ;
|
---|
61 | syscomp = "HPUX-";
|
---|
62 | #endif
|
---|
63 |
|
---|
64 |
|
---|
65 | #if defined( __GNUG__ )
|
---|
66 | compCmd = "g++ ";
|
---|
67 | compOptions = gcxx_opt;
|
---|
68 | linkOptions = "-O -shared";
|
---|
69 | syscomp += "g++/";
|
---|
70 | #elif defined( __DECCXX )
|
---|
71 | compCmd = "cxx ";
|
---|
72 | compOptions = cxx_opt;
|
---|
73 | linkOptions = cxx_opt + "-shared";
|
---|
74 | syscomp += "cxx/";
|
---|
75 | #elif defined( __KCC__ )
|
---|
76 | compCmd = "KCC ";
|
---|
77 | compOptions = KCC_opt;
|
---|
78 | linkOptions = KCC_opt;
|
---|
79 | syscomp += "KCC/";
|
---|
80 | #elif defined( __SGICC__ )
|
---|
81 | compCmd = "CC ";
|
---|
82 | compOptions = SGICC_opt;
|
---|
83 | linkOptions = SGICC_opt;
|
---|
84 | syscomp += "CC/";
|
---|
85 | #ifdef SGI_ARCH64
|
---|
86 | compOptions += " -64 -DSGI_ARCH64 ";
|
---|
87 | linkOptions += " -64 ";
|
---|
88 | #endif
|
---|
89 | #endif
|
---|
90 |
|
---|
91 | cppFlags += " -I. ";
|
---|
92 | compOptions += " -c ";
|
---|
93 |
|
---|
94 | string dpcbase;
|
---|
95 | char* varenv=NULL;
|
---|
96 | varenv=getenv("DPCBASEREP");
|
---|
97 | if (varenv) {
|
---|
98 | dpcbase = varenv;
|
---|
99 | if (dpcbase[dpcbase.length()-1] != '/') dpcbase += '/';
|
---|
100 | cppFlags += ( " -I" + dpcbase + "Include/ ");
|
---|
101 | linkOptions += " -L" + dpcbase + syscomp + "ShLibs/ ";
|
---|
102 | }
|
---|
103 |
|
---|
104 | string extlib;
|
---|
105 | varenv=getenv("EXTLIBDIR");
|
---|
106 | if (varenv) {
|
---|
107 | extlib = varenv;
|
---|
108 | if (extlib[extlib.length()-1] != '/') extlib += '/';
|
---|
109 | cppFlags += ( " -I" + extlib +"Include/ ");
|
---|
110 | }
|
---|
111 |
|
---|
112 | }
|
---|
113 |
|
---|
114 | /* --Methode-- */
|
---|
115 | CxxCompilerLinker::~CxxCompilerLinker()
|
---|
116 | {
|
---|
117 | }
|
---|
118 |
|
---|
119 | /* --Methode-- */
|
---|
120 | int CxxCompilerLinker::Compile(string const & name, string & objname)
|
---|
121 | {
|
---|
122 | if (objname.length() < 1) {
|
---|
123 | // A completer
|
---|
124 | objname = tmpDir + "xxx.o";
|
---|
125 | }
|
---|
126 | string cmd;
|
---|
127 | cmd = compCmd + cppFlags + compOptions + "-o " + objname + " " + name ;
|
---|
128 | if (verbose)
|
---|
129 | cout << "CxxCompilerLinker::Compile() - Executing \n" << cmd << endl;
|
---|
130 | int rc = system(cmd.c_str());
|
---|
131 | if (rc != 0)
|
---|
132 | cerr << "CxxCompilerLinker::Compile() Error Rc(" << cmd <<")= "<< rc << endl;
|
---|
133 |
|
---|
134 | return(rc);
|
---|
135 | }
|
---|
136 |
|
---|
137 | /* --Methode-- */
|
---|
138 | int CxxCompilerLinker::BuildSO(string const & objname, string & soname)
|
---|
139 | {
|
---|
140 | if (soname.length() < 1) {
|
---|
141 | // A completer
|
---|
142 | soname = tmpDir + "xxx.so";
|
---|
143 | }
|
---|
144 | string cmd;
|
---|
145 | cmd = compCmd + linkOptions + "-o " + soname + " " + objname ;
|
---|
146 | if (verbose)
|
---|
147 | cout << "CxxCompilerLinker::BuildSO() - Executing \n" << cmd << endl;
|
---|
148 | int rc = system(cmd.c_str());
|
---|
149 | if (rc != 0)
|
---|
150 | cerr << "CxxCompilerLinker::BuildSO() Error Rc(" << cmd <<")= "<< rc << endl;
|
---|
151 |
|
---|
152 | return(rc);
|
---|
153 | }
|
---|
154 |
|
---|