My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes    
 
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
#include "Builders.h"

#include <coff/binobj/binobj.h>

void OwcBuilder::AddFlags(Index<String>& cfg)
{

}

bool OwcBuilder::BuildPackage(const String& package, Vector<String>& linkfile, String& linkoptions, const Vector<String>& all_uses, const Vector<String>& all_libraries, int opt)
{
String packagepath = PackagePath(package);
Package pkg;
pkg.Load(packagepath);
String packagedir = GetFileFolder(packagepath);
ChDir(packagedir);
PutVerbose("cd " + packagedir);
IdeConsoleBeginGroup(package);
Vector<String> obj;

bool is_shared = HasFlag("SO");

String cc = CmdLine(package, pkg),
clc = CompilerName(false), clcpp = CompilerName(true);

if (HasFlag("MT"))
cc << " -bm";

if (HasFlag("WIN32"))
cc << " -bt=nt";

String ccoptions = Gather(pkg.option, config.GetKeys());
if (!ccoptions.IsEmpty())
cc << ' ' << ccoptions;

String cc_speed = cc;
bool release = false;

if (HasFlag("DEBUG"))
cc << " -d_DEBUG " << debug_options;
else {
release = true;
cc << ' ' << release_size_options;
cc_speed << ' ' << release_options;
if (opt == R_SPEED || pkg.optimize_speed)
cc = cc_speed;
}

Vector<String> sfile, isfile;
Vector<String> soptions, isoptions;
Vector<bool> optimize, ioptimize;
bool error = false;

for (int i = 0; i < pkg.GetCount(); i++) {
if (!IdeIsBuilding())
return false;
if (!pkg[i].separator) {
String gop = Gather(pkg[i].option, config.GetKeys());
Vector<String> srcfile = CustomStep(pkg[i], package, error);
if (srcfile.GetCount() == 0)
error = true;
for (int j = 0; j < srcfile.GetCount(); j++) {
String fn = srcfile[j];
String ext = ToLower(GetFileExt(fn));
if (ext == ".c" || ext == ".cpp" || ext == ".cc" || ext == ".cxx" || ext == ".rc" || ext == ".brc") {
sfile.Add(fn);
soptions.Add(gop);
optimize.Add(release && pkg[i].optimize_speed && opt == R_OPTIMAL);
}
else
if (ext == ".icpp") {
isfile.Add(fn);
isoptions.Add(gop);
ioptimize.Add(release && pkg[i].optimize_speed && opt == R_OPTIMAL);
}
else
if (ext == ".obj")
obj.Add(fn);
else
if (ext == ".lib")
linkfile.Add(fn);
}
}
}

if (HasFlag("BLITZ")) {
Blitz b = BlitzStep(sfile, soptions, obj, ".obj", optimize);
if (b.build) {
PutConsole("BLITZ:" + b.info);
int slot = AllocSlot();
if (slot < 0 || !Run(String().Cat() << clcpp << cc << ' '
<< GetHostPathQ(b.path) << " -fo=" << GetHostPathQ(b.object), slot, GetHostPath(b.object), b.count))
error = true;
}
}

int first_ifile = sfile.GetCount();
sfile.AppendPick(isfile);
soptions.AppendPick(isoptions);
optimize.AppendPick(ioptimize);

int ccount = 0;

for (int i = 0; i < sfile.GetCount(); ++i) {
if (!IdeIsBuilding())
return false;
String fn = sfile[i];
String ext = ToLower(GetFileExt(fn));
bool rc = (ext == ".rc");
bool brc = (ext == ".brc");
bool init = (i >= first_ifile);
String objfile = CatAnyPath(outdir, GetFileName(fn) + ".obj");
if (HdependFileTime(fn) > GetFileTime(objfile)) {
PutConsole(GetFileNamePos(fn));
int time = GetTickCount();
bool execerr = false;
if (rc) {
objfile = ForceExt(objfile, ".res");
int slot = AllocSlot();
if (slot < 0 || !Run("wrc -q -r -x -fo=" + GetHostPathQ(objfile) + Includes(" -i=", package, pkg)
+ ' ' + GetHostPathQ(fn), slot, GetHostPath(objfile), 1))
execerr = true;
}
else
if (brc) {
try {
String hfn = GetHostPath(fn);
String brcdata = LoadFile(hfn);
if(brcdata.IsVoid())
throw Exc(NFormat("error reading file '%s'", hfn));
CParser parser(brcdata, hfn);
BinaryToObject(GetHostPath(objfile), parser, GetFileDirectory(hfn), THISBACK(BinObjConsole));
}
catch (Exc e) {
PutConsole(e);
execerr = true;
}
}
else {
String c = cc;
if (optimize[i])
c = cc_speed;
int slot = AllocSlot();

if (slot < 0 || !Run((ext == ".c" ? clc : clcpp + " -xr -xs") + c + soptions[i] + ' '
+ GetHostPathQ(fn) + " -fo=" + GetHostPathQ(objfile), slot, GetHostPath(objfile), 1))
execerr = true;
}

if (execerr)
DeleteFile(objfile);
error |= execerr;
PutVerbose("compiled in " + GetPrintTime(time));
ccount++;
}
if (init)
linkfile.Add(objfile);
else
obj.Add(objfile);
}

if (error) {
IdeConsoleEndGroup();
return false;
}

Vector<String> libs = Split(Gather(pkg.library, config.GetKeys()), ' ');
for (int i = 0, n = libs.GetCount(); i < n; ++i)
linkfile.Add(AppendExt(libs[i], ".lib"));

linkoptions << Gather(pkg.link, config.GetKeys());

int linktime = GetTickCount();
if (!HasFlag("MAIN")) {
if (HasFlag("BLITZ") || HasFlag("NOLIB")) {
obj.Append(linkfile);
linkfile = obj;
IdeConsoleEndGroup();
return true;
}

String product;
if (is_shared)
product = GetSharedLibPath(package);
else
product = CatAnyPath(outdir, GetAnyFileName(package) + ".lib");

Time producttime = GetFileTime(product);
linkfile.Add(ForceExt(product, ".lib"));

Vector<String> files, res;
for (int i = 0, n = obj.GetCount(); i < n; ++i)
if (obj[i].EndsWith("j")) // ".obj"
files.Add(obj[i]);
else // ".res"
res.Add(obj[i]);

if (!is_shared && !res.IsEmpty())
linkfile.Append(res);

if (!Wait()) {
IdeConsoleEndGroup();
return false;
}

for (int i = 0, n = obj.GetCount(); i < n; ++i)
if (GetFileTime(obj[i]) > producttime) {
String lib;

if (is_shared) {
lib << LinkerName() << " option quiet";

if (HasFlag("DEBUG"))
lib << " debug all option incremental";

if (HasFlag("WIN32"))
lib << " system nt_dll";

if (!linkoptions.IsEmpty())
lib << ' ' << linkoptions;

if (!libpath.IsEmpty())
lib << " libpath \"" << Join(libpath, "\";\"") << '\"';

if (!files.IsEmpty())
lib << " file '" << Join(files, "', '") << '\'';

if (!res.IsEmpty())
lib << " resource '" << Join(res, "', '") << '\'';

const int all_usesCount = all_uses.GetCount(),
all_librariesCount = all_libraries.GetCount();

if (all_usesCount > 0 || all_librariesCount > 0) {
lib << " library ";

for (int j = 0, k = all_usesCount - 1; j < all_usesCount; ++j) {
lib << '\'' << GetHostPath(ForceExt(GetSharedLibPath(all_uses[j]), ".lib")) << '\'';

if (j < k)
lib << ", ";
}

if (all_usesCount > 0 && all_librariesCount > 0)
lib << ", ";

for (int j = 0, k = all_librariesCount - 1; j < all_librariesCount; ++j) {
lib << '\'' << AppendExt(all_libraries[j], ".lib") << '\'';

if (j < k)
lib << ", ";
}
}

lib << " name '" << product << '\'';
}
else {
lib << "wlib -q -b -n -pa ";

if (!linkoptions.IsEmpty())
lib << linkoptions;

lib << '\'' << product << '\'';

for (int j = 0, m = files.GetCount(); j < m; ++j)
lib << " '" << GetHostPath(files[j]) << '\'';
}

PutConsole("Creating library...");
IdeConsoleEndGroup();
DeleteFile(product);

if (Execute(lib)) {
DeleteFile(product);
return false;
}

PutConsole(String().Cat() << product << " (" << GetFileInfo(product).length
<< " B) created in " << GetPrintTime(linktime));

break;
}

return true;
}

obj.Append(linkfile);
linkfile = obj;
return true;
}

bool OwcBuilder::Link(const Vector<String>& linkfile, const String& linkoptions, bool createmap)
{
int time = GetTickCount();
if (!Wait())
return false;

const int linkfileCount = linkfile.GetCount();

for (int i = 0; i < linkfileCount; i++)
if (GetFileTime(linkfile[i]) >= targettime) {
String link;
link << LinkerName() << " option quiet";

if (HasFlag("DEBUG"))
link << " debug all option incremental";

if (HasFlag("WIN32"))
if (HasFlag("GUI"))
link << " system nt_win";
else if (HasFlag("DLL"))
link << " system nt_dll";
else link << " system nt";

if (createmap)
link << " option map";

if (!linkoptions.IsEmpty())
link << ' ' << linkoptions;

if (!libpath.IsEmpty())
link << " libpath \"" << Join(libpath, "\";\"") << '\"';

Vector<String> files, libs, res;

for (int j = 0; j < linkfileCount; ++j) {
const String ext(linkfile[j].Right(1));
if (ext == "j") // ".obj"
files.Add(linkfile[j]);
else if (ext == "b") // ".lib"
libs.Add(linkfile[j]);
else // ".res"
res.Add(linkfile[j]);
}

if (!files.IsEmpty())
link << " file '" << Join(files, "', '") << '\'';

if (!res.IsEmpty())
link << " resource '" << Join(res, "', '") << '\'';

if (!libs.IsEmpty())
link << " library '" << Join(libs, "', '") << '\'';

link << " name '" << GetHostPath(target) << '\'';

PutConsole("Linking...");
bool error = false;
CustomStep(".pre-link", Null, error);
if (!error && Execute(link) == 0) {
CustomStep(".post-link", Null, error);
PutConsole(String().Cat() << GetHostPath(target) << " (" << GetFileInfo(target).length
<< " B) linked in " << GetPrintTime(time));
return !error;
}
else {
DeleteFile(target);
return false;
}
}

PutConsole(String().Cat() << GetHostPath(target) << " (" << GetFileInfo(target).length
<< " B) is up to date.");
return true;
}

bool OwcBuilder::Preprocess(const String& package, const String& file, const String& target, bool asmout)
{
FileOut out(target);
const String packagepath = PackagePath(package);
Package pkg;
pkg.Load(packagepath);

return Execute((GetFileExt(file) == ".c" ? CompilerName(false) : CompilerName(true)) + CmdLine(package, pkg) + " -pl " + file, out);
}

String OwcBuilder::IncludesDefinesTargetTime(const String& package, const Package& pkg)
{
String cc = Includes(" -i=", package, pkg);

for (int i = 0; i < config.GetCount(); i++)
cc << " -Dflag" << config[i];

Time t = GetSysTime();
cc << " -DbmYEAR=" << (int)t.year;
cc << " -DbmMONTH=" << (int)t.month;
cc << " -DbmDAY=" << (int)t.day;
cc << " -DbmHOUR=" << (int)t.hour;
cc << " -DbmMINUTE=" << (int)t.minute;
cc << " -DbmSECOND=" << (int)t.second;
targettime = GetFileTime(target);

return cc;
}

String OwcBuilder::CompilerName(bool isCpp) const
{
if (!IsNull(compiler)) return compiler;
return isCpp ? "wpp386" : "wcc386"; // C++ or C compiler
}

String OwcBuilder::LinkerName() const
{
return "wlink";
}

String OwcBuilder::CmdLine(const String& package, const Package& pkg)
{
return String().Cat() << " -zq -fr=" << IncludesDefinesTargetTime(package, pkg);
// "-fr=" - do not create error files
}

Builder *CreateOwcBuilder()
{
return new OwcBuilder;
}

INITBLOCK
{
RegisterBuilder("OWC", CreateOwcBuilder);
}

Change log

r4934 by cxl on May 12, 2012   Diff
.ide: OWC builder console cosmetics
Go to: 
Project members, sign in to write a code review

Older revisions

r4457 by cxl on Jan 21, 2012   Diff
*uppsrc: Fixed many GCC warnings
r4203 by cxl on Nov 25, 2011   Diff
ide: Custom build steps refresh
r3968 by cxl on Oct 8, 2011   Diff
.ide: OWC builder fix (thanks sender
ghost)
All revisions of this file

File info

Size: 10703 bytes, 421 lines
Powered by Google Project Hosting