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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
#include "Builders.h"

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

String GccBuilder::CompilerName() const
{
if(!IsNull(compiler)) return compiler;
return HasFlag("GCC_ARM") ? "arm-wince-pe-c++" : "c++";
}

String GccBuilder::CmdLine(const String& package, const Package& pkg)
{
String cc = CompilerName();
cc << " -c ";
cc << IncludesDefinesTargetTime(package, pkg);
if(HasFlag("GCC32"))
cc << " -m32";
return cc;
}

void GccBuilder::BinaryToObject(String objfile, CParser& binscript, String basedir,
const String& package, const Package& pkg)
{
String fo = BrcToC(binscript, basedir);
String tmpfile = ForceExt(objfile, ".c");
SaveFile(tmpfile, fo);
String cc = CmdLine(package, pkg);
cc << " -c -o " << GetHostPathQ(objfile) << " -x c " << GetHostPathQ(tmpfile);
int slot = AllocSlot();
if(slot < 0 || !Run(cc, slot, objfile, 1))
throw Exc(NFormat("Error compiling binary object '%s'.", objfile));
}

bool GccBuilder::BuildPackage(const String& package, Vector<String>& linkfile,
String& linkoptions, const Vector<String>& all_uses, const Vector<String>& all_libraries,
int opt)
{
int i;
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 shared_ext = (HasFlag("WIN32") ? ".dll" : ".so");

String cc = CmdLine(package, pkg);
if(HasFlag("WIN32") && HasFlag("MT"))
cc << " -mthreads";
if(HasFlag("DEBUG_MINIMAL"))
cc << (HasFlag("WIN32") ? " -g1" : " -ggdb -g1");
if(HasFlag("DEBUG_FULL"))
cc << (HasFlag("WIN32") ? " -g2" : " -ggdb -g2");
String fuse_cxa_atexit;
if(is_shared /*&& !HasFlag("MAIN")*/) {
cc << " -shared -fPIC";
fuse_cxa_atexit = " -fuse-cxa-atexit";
}
if(!HasFlag("SHARED") && !is_shared)
cc << " -static ";
// else if(!HasFlag("WIN32")) // TRC 05/03/08: dynamic fPIC doesn't seem to work in MinGW
// cc << " -dynamic -fPIC "; // TRC 05/03/30: dynamic fPIC doesn't seem to work in GCC either :-)
cc << ' ' << Gather(pkg.option, config.GetKeys());
cc << " -fexceptions ";

if (HasFlag("OSX11")) {
if (HasFlag("POWERPC"))
cc << " -arch ppc";
if (HasFlag("X86"))
cc << " -arch i386";
}

if(HasFlag("SSE2"))
cc << " -msse2 -mfpmath=sse";

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(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 == ".m" || ext == ".mm"
|| ext == ".s" || ext == ".S"
|| ext == ".brc" || (ext == ".rc" && HasFlag("WIN32"))) {
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 == ".o")
obj.Add(fn);
else
if(ext == ".a" || ext == ".so")
linkfile.Add(fn);
}
}
}

if(HasFlag("BLITZ")) {
Blitz b = BlitzStep(sfile, soptions, obj, ".o", optimize);
if(b.build) {
PutConsole("BLITZ:" + b.info);
int slot = AllocSlot();
if(slot < 0 || !Run(String().Cat() << cc << ' '
<< GetHostPathQ(b.path) << " -o " << 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(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, GetFileTitle(fn) + (rc ? "$rc.o" : brc ? "$brc.o" : ".o"));
if(HdependFileTime(fn) > GetFileTime(GetHostPath(objfile))) {
PutConsole(GetFileName(fn));
int time = GetTickCount();
bool execerr = false;
if(rc) {
String exec;
exec << "windres -i " << GetHostPathQ(fn)
<< " -o " << GetHostPathQ(objfile) << IncludesShort(" --include-dir=", package, pkg);
PutVerbose(exec);
int slot = AllocSlot();
execerr = (slot < 0 || !Run(exec, slot, GetHostPath(objfile), 1));
}
else if(brc) {
try {
// String hfn = GetHostPath(fn);
String brcdata = LoadFile(fn);
if(brcdata.IsVoid())
throw Exc(NFormat("error reading file '%s'", fn));
CParser parser(brcdata, fn);
BinaryToObject(GetHostPath(objfile), parser, GetFileDirectory(fn), package, pkg);
}
catch(Exc e) {
PutConsole(e);
execerr = true;
}
}
else {
String exec = optimize[i] ? cc_speed : cc;
if(ext == ".c")
exec << " -x c ";
else if(ext == ".s" || ext == ".S")
exec << " -x assembler-with-cpp ";
else if (ext == ".m" || ext == ".mm")
exec << fuse_cxa_atexit << " -x objective-c++ ";
else
exec << fuse_cxa_atexit << " -x c++ ";
exec << GetHostPathQ(fn) << " " << soptions[i] << " -o " << GetHostPathQ(objfile);
PutVerbose(exec);
int slot = AllocSlot();
execerr = (slot < 0 || !Run(exec, slot, GetHostPath(objfile), 1));
}
if(execerr)
DeleteFile(objfile);
error |= execerr;
PutVerbose("compiled in " + GetPrintTime(time));
ccount++;
}
if(init)
linkfile.Add(objfile);
else
obj.Add(objfile);
}

if(error) {
// if(ccount)
// PutCompileTime(time, ccount);
IdeConsoleEndGroup();
return false;
}

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

Vector<String> libs = Split(Gather(pkg.library, config.GetKeys()), ' ');
linkfile.Append(libs);

int libtime = GetTickCount();
if(!HasFlag("MAIN")) {
if(HasFlag("BLITZ") || HasFlag("NOLIB")) {
linkfile.Append(obj);
IdeConsoleEndGroup();
// if(ccount)
// PutCompileTime(time, ccount);
return true;
}
IdeConsoleEndGroup();
if(!Wait())
return false;
String product;
if(is_shared)
product = GetSharedLibPath(package);
else
product = CatAnyPath(outdir, GetAnyFileName(package) + ".a");
String hproduct = GetHostPath(product);
Time producttime = GetFileTime(hproduct);
// LOG("hproduct = " << hproduct << ", time = " << producttime);
linkfile.Add(GetHostPath(product));
for(int i = 0; i < obj.GetCount(); i++)
if(GetFileTime(obj[i]) > producttime) {
String lib;
if(is_shared) {
lib = CompilerName();
lib << " -shared -fPIC -fuse-cxa-atexit";
if(!HasFlag("SHARED") && !is_shared)
lib << " -static";
// else if(!HasFlag("WIN32")) // TRC 05/03/08: dynamic fPIC causes trouble in MinGW
// lib << " -dynamic -fPIC"; // TRC 05/03/30: dynamic fPIC doesn't seem to work in GCC either :-)
if(HasFlag("GCC32"))
lib << " -m32";
Point p = ExtractVersion();
if(!IsNull(p.x)) {
lib << " -Xlinker --major-image-version -Xlinker " << p.x;
if(!IsNull(p.y))
lib << " -Xlinker --minor-image-version -Xlinker " << p.y;
}
lib << ' ' << Gather(pkg.link, config.GetKeys());
lib << " -o ";
}
else
lib = "ar -sr ";
lib << GetHostPathQ(product);
for(int i = 0; i < obj.GetCount(); i++)
lib << ' ' << GetHostPathQ(obj[i]);
PutConsole("Creating library...");
DeleteFile(hproduct);
if(is_shared) {
for(int i = 0; i < libpath.GetCount(); i++)
lib << " -L" << GetHostPathQ(libpath[i]);
for(int i = 0; i < all_uses.GetCount(); i++)
lib << ' ' << GetHostPathQ(GetSharedLibPath(all_uses[i]));
for(int i = 0; i < all_libraries.GetCount(); i++)
lib << " -l" << GetHostPathQ(all_libraries[i]);
}
if(!Execute(lib) == 0) {
DeleteFile(hproduct);
return false;
}
PutConsole(String().Cat() << hproduct << " (" << GetFileInfo(hproduct).length
<< " B) created in " << GetPrintTime(libtime));
break;
}
return true;
}

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


bool GccBuilder::Link(const Vector<String>& linkfile, const String& linkoptions, bool createmap)
{
if(!Wait())
return false;
int time = GetTickCount();
for(int i = 0; i < linkfile.GetCount(); i++)
if(GetFileTime(linkfile[i]) >= targettime) {
Vector<String> lib;
String lnk = CompilerName();
if(HasFlag("GCC32"))
lnk << " -m32";
if(HasFlag("DLL"))
lnk << " -shared";
if(!HasFlag("SHARED") && !HasFlag("SO"))
lnk << " -static";
// else if(!HasFlag("WIN32")) // TRC 05/03/08: see above
// lnk << " -dynamic -fPIC"; // TRC 05/03/30: dynamic fPIC doesn't seem to work in GCC either :-)
if(HasFlag("WINCE"))
lnk << " -mwindowsce";
else if(HasFlag("WIN32")) {
lnk << " -mwindows";
if(HasFlag("MT"))
lnk << " -mthreads";
if(!HasFlag("GUI"))
lnk << " -mconsole";
}
lnk << " -o " << GetHostPathQ(target);
if(createmap)
lnk << " -Wl,-Map," << GetHostPathQ(GetFileDirectory(target) + GetFileTitle(target) + ".map");
if(HasFlag("DEBUG") || HasFlag("DEBUG_MINIMAL") || HasFlag("DEBUG_FULL"))
lnk << " -ggdb";
else
lnk << (!HasFlag("OSX11") ? " -Wl,-s" : "");
for(i = 0; i < libpath.GetCount(); i++)
lnk << " -L" << GetHostPathQ(libpath[i]);
// lnk << " -Wl,--gc-sections,-O,2 ";
if(!HasFlag("OSX11"))
lnk << " -Wl,-O,2 ";
lnk << linkoptions;

if (HasFlag("OSX11")) {
if (HasFlag("POWERPC"))
lnk << " -arch ppc";
if (HasFlag("X86"))
lnk << " -arch i386";
}

String lfilename;
if(HasFlag("OBJC")) {
String lfilename;
String linklist;
for(i = 0; i < linkfile.GetCount(); i++)
if(ToLower(GetFileExt(linkfile[i])) == ".o" || ToLower(GetFileExt(linkfile[i])) == ".a")
linklist << GetHostPath(linkfile[i]) << '\n';

String linklistM = "Producing link file list ...\n";
String odir = GetFileDirectory(linkfile[0]);
lfilename << GetHostPath(GetFileFolder(linkfile[0])) << ".LinkFileList";

linklistM << lfilename;
UPP::SaveFile(lfilename, linklist);
lnk << " -L" << GetHostPathQ(odir)
<< " -F" << GetHostPathQ(odir)
<< " -filelist " << lfilename << " ";
PutConsole( linklistM );
}
else
for(i = 0; i < linkfile.GetCount(); i++)
if(ToLower(GetFileExt(linkfile[i])) == ".o")
lnk << ' ' << GetHostPathQ(linkfile[i]);
else
lib.Add(linkfile[i]);

if(!HasFlag("SOLARIS") && !HasFlag("OSX11") && !HasFlag("OBJC"))
lnk << " -Wl,--start-group ";
for(int pass = 0; pass < 2; pass++)
for(i = 0; i < lib.GetCount(); i++) {
String ln = lib[i];
String ext = ToLower(GetFileExt(ln));
if(pass == 0) {
if(ext == ".a")
lnk << ' ' << GetHostPathQ(FindInDirs(libpath, lib[i]));
}
else
if(ext != ".a")
if(ext == ".so" || ext == ".dll" || ext == ".lib")
lnk << ' ' << GetHostPathQ(FindInDirs(libpath, lib[i]));
else
lnk << " -l" << ln;
}
if(!HasFlag("SOLARIS") && !HasFlag("OSX11"))
lnk << " -Wl,--end-group";
PutConsole("Linking...");
bool error = false;
CustomStep(".pre-link", Null, error);
if(!error && Execute(lnk) == 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 GccBuilder::Preprocess(const String& package, const String& file, const String& target, bool asmout)
{
Package pkg;
String packagepath = PackagePath(package);
pkg.Load(packagepath);
String packagedir = GetFileFolder(packagepath);
ChDir(packagedir);
PutVerbose("cd " + packagedir);

String cmd = CmdLine(package, pkg);
cmd << " " << Gather(pkg.option, config.GetKeys());
cmd << " -o " << target;
cmd << (asmout ? " -S " : " -E ") << GetHostPathQ(file);
return Execute(cmd);
}

Builder *CreateGccBuilder()
{
return new GccBuilder;
}

INITBLOCK
{
RegisterBuilder("GCC", CreateGccBuilder);
RegisterBuilder("GCC32", CreateGccBuilder);
RegisterBuilder("GCC_ARM", CreateGccBuilder);
}

Change log

r4621 by cxl on Feb 25, 2012   Diff
ide: Export now properly manages brc files
Go to: 
Project members, sign in to write a code review

Older revisions

r4425 by cxl on Jan 16, 2012   Diff
*ide: MSC & GCC builders fixed issue
with compiler options (thanks Massimo)
r4203 by cxl on Nov 25, 2011   Diff
ide: Custom build steps refresh
r4171 by cxl on Nov 14, 2011   Diff
CtrlCore, ide: MacOSX patches
All revisions of this file

File info

Size: 13523 bytes, 439 lines
Powered by Google Project Hosting