-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcexecutablewx.cpp
More file actions
203 lines (183 loc) · 8.1 KB
/
cexecutablewx.cpp
File metadata and controls
203 lines (183 loc) · 8.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
//
// Copyright 2023 Hans-Juergen Lange <hjl@simulated-universe.de>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the “Software”), to deal in the
// Software without restriction, including without limitation the rights to use, copy,
// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <helper.h>
#include "cpackagebase.h"
#include "cexecutablewx.h"
#include "mmodel.h"
#include "cmodel.h"
#include "cclassbase.h"
#include "path.h"
void CExecutableWx::Dump(std::shared_ptr<MModel> model) {
std::string path;
std::list<std::string> modules;
std::vector<std::shared_ptr<MClass>>::iterator i;
std::list<tConnector<MElement, MElement>> liblist;
std::list<eElementType> contenttypes;
std::list<std::shared_ptr<MClass>> content;
std::list<std::shared_ptr<MClass>>::iterator ci;
auto cmodel = std::dynamic_pointer_cast<CModel>(model);
DumpBase(cmodel);
path=cmodel->pathstack.back()+"/"+".Makefile";
cmodel->generatedfiles.push_back( tGenFile {path, id, "##", "mk"} );
OpenStream(makefile, path);
DumpMakefileHeader(makefile, OutputName);
//
// Get all content that is part of this package
contenttypes.push_back(eElementType::Enumeration);
contenttypes.push_back(eElementType::Union);
contenttypes.push_back(eElementType::CxxClass);
contenttypes.push_back(eElementType::CClass);
contenttypes.push_back(eElementType::Struct);
contenttypes.push_back(eElementType::InterfaceClass);
contenttypes.push_back(eElementType::WxFormsClass);
content = GetAllContent(contenttypes);
for (ci=content.begin(); ci!=content.end(); ci++) {
auto ccb = std::dynamic_pointer_cast<CClassBase>(*ci);
//
// If the class is in a different package it should be one of the subpackages.
if ( ((*ci)->parent) && ((*ci)->parent != sharedthis<MElement>()) && ((*ci)->parent->IsPackageBased())) {
std::string pathto = GetPathToPackage((*ci)->parent);
if (((*ci)->type == eElementType::SimObject) || ((*ci)->type == eElementType::CxxClass) ||
((*ci)->type == eElementType::CClass) || ((*ci)->type == eElementType::WxFormsClass)) {
modules.push_back(CPath("./"+pathto+"/"+ccb->getFileName()));
}
//
// Setup the directory for the subpackage.
std::dynamic_pointer_cast<CPackageBase>(*(*ci)->parent)->DumpBase(cmodel);
(*ci)->Dump(model);
//
// Remove last element from path-stack. Was for the subpackage.
cmodel->pathstack.pop_back();
} else {
if (((*ci)->type == eElementType::SimObject) || ((*ci)->type == eElementType::CxxClass) ||
((*ci)->type == eElementType::CClass) || ((*ci)->type == eElementType::WxFormsClass)) {
modules.push_back(CPath("./"+ccb->getFileName()));
}
(*ci)->Dump(model);
}
}
makefile << "PROJ=" << OutputName+"\n\n";
DumpMakefileSource(makefile, modules);
DumpMakefileObjects(makefile, modules);
//
// Find some CXX-Flags to generate into the Makefile.
std::string cxxFlags;
if (HasTaggedValue("CxxFlags")) {
cxxFlags = GetTaggedValue("CxxFlags");
}
makefile << "CXXFLAGS+=$(shell wx-config --debug=yes --cxxflags) -std=" << m_cxxstandard << " -fPIC -g $(INCLUDEPATH) " << cxxFlags.c_str() << "\n\n";
//
// Find some Linker-Flags to generate into the Makefile.
makefile << "LDFLAGS+=$(shell wx-config --debug=yes --libs std,richtext,aui,propgrid) ";
std::string ldFlags;
if (HasTaggedValue("LdFlags")) {
ldFlags = GetTaggedValue("LdFlags");
makefile << ldFlags;
}
makefile << std::endl << std::endl;
//
// First we add the libs.
liblist = GetLibraryDependency();
makefile << "STATICLIBS+=";
for (auto& di : liblist) {
if ((di.getConnector()->HasStereotype("static")) || (di.getConnector()->HasStereotype("StaticLinkage"))) {
if (di.getElement()) {
auto package = std::dynamic_pointer_cast<CPackageBase>(di.getElement());
if (di.getElement()->type == eElementType::LibraryPackage) {
makefile << "\\\n" << " -l" << package->OutputName;
}
else if (di.getElement()->type == eElementType::ExternPackage) {
makefile << "\\\n" << " -l" << package->OutputName;
}
}
}
}
makefile << "\n\n";
makefile << "DYNLIBS+=";
for (auto& di : liblist) {
if (!(di.getConnector()->HasStereotype("static")) && !(di.getConnector()->HasStereotype("StaticLinkage"))) {
if (di.getElement()) {
auto package = std::dynamic_pointer_cast<CPackageBase>(di.getElement());
if (di.getElement()->type == eElementType::LibraryPackage) {
makefile << "\\\n" << " -l" << package->OutputName;
}
else if (di.getElement()->type == eElementType::ExternPackage) {
makefile << "\\\n" << " -l" << package->OutputName;
}
}
}
}
makefile << "\n\n";
//
// Than we add the pathes.
makefile << "LIBPATH+=";
if (HasTaggedValue("LibPath")) {
makefile << "-L" << GetTaggedValue("LibPath") << "\\\n";
}
for (auto& di : liblist) {
if (di.getElement()) {
if (di.getElement()->type == eElementType::LibraryPackage) {
std::string libpath = GetPathToPackage(di.getElement());
if (!libpath.empty()) {
makefile << "\\\n" << " -L" << libpath;
}
}
}
}
makefile << "\n\n";
makefile << "INCLUDEPATH+=";
for (auto& di : liblist) {
if (di.getElement()) {
if (di.getElement()->type == eElementType::ExternPackage) {
auto package = std::dynamic_pointer_cast<CPackageBase>(di.getElement());
std::string dir = package->Directory;
if (dir != "./") {
makefile << "\\\n" << " -I" << dir;
} else {
if (!package->OutputPath.empty()) {
makefile << "\\\n" << " -I" << package->OutputPath;
}
}
}
}
}
makefile << "\n\n";
makefile << "all : $(PROJ)\n\n";
makefile << "$(PROJ) : $(OBJ) depend\n";
if (!modules.empty()) {
makefile << "\tg++ $(CXXFLAGS) $(LIBPATH) $(OBJ) -Wl,-Bstatic -Wl,--start-group $(STATICLIBS) -Wl,--end-group -Wl,-Bdynamic -Wl,--start-group $(DYNLIBS) -Wl,--end-group $(LDFLAGS) -o $@\n\n";
}
if (!modules.empty()) {
makefile << "depend : $(SRC)\n";
makefile << "\tg++ $(CXXFLAGS) -M $(SRC) > depend\n\n";
}
makefile << "clean:\n";
makefile << "\trm -f $(PROJ)\n";
makefile << "\trm -f depend\n";
makefile << "\trm -f $(OBJ)\n\n";
makefile << "install:\n"
"\trm -f $(BININSTALLDIR)/$(PROJ)\n"
"\tcp $(PROJ) $(BININSTALLDIR)\n\n";
makefile << "-include depend\n\n";
makefile.close();
//
// Remove last element from path-stack
cmodel->pathstack.pop_back();
}