Menu

[r13158]: / trunk / src / sdk / compiletargetbase.cpp  Maximize  Restore  History

Download this file

548 lines (475 with data), 16.0 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
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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
/*
* This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
* http://www.gnu.org/licenses/lgpl-3.0.html
*
* $Revision$
* $Id$
* $HeadURL$
*/
#include "sdk_precomp.h"
#ifndef CB_PRECOMP
#include <wx/filename.h>
#include "compiletargetbase.h"
#include "compilerfactory.h"
#include "globals.h"
#include "logmanager.h" // Manager::Get()->GetLogManager()->DebugLog(F())
#endif
#include "filefilters.h"
CompileTargetBase::CompileTargetBase()
: m_TargetType(ttExecutable),
m_RunHostApplicationInTerminal(false),
m_PrefixGenerationPolicy(tgfpPlatformDefault),
m_ExtensionGenerationPolicy(tgfpPlatformDefault)
{
//ctor
for (int i = 0; i < static_cast<int>(ortLast); ++i)
{
m_OptionsRelation[i] = orAppendToParentOptions;
}
// default "make" commands
m_MakeCommands[mcBuild] = _T("$make -f $makefile $target");
m_MakeCommands[mcCompileFile] = _T("$make -f $makefile $file");
m_MakeCommands[mcClean] = _T("$make -f $makefile clean$target");
m_MakeCommands[mcDistClean] = _T("$make -f $makefile distclean$target");
m_MakeCommands[mcAskRebuildNeeded] = _T("$make -q -f $makefile $target");
// m_MakeCommands[mcSilentBuild] = _T("$make -s -f $makefile $target");
m_MakeCommands[mcSilentBuild] = m_MakeCommands[mcBuild] + _T(" > $(CMD_NULL)");
m_MakeCommandsModified = false;
}
CompileTargetBase::~CompileTargetBase()
{
//dtor
}
void CompileTargetBase::SetTargetFilenameGenerationPolicy(TargetFilenameGenerationPolicy prefix,
TargetFilenameGenerationPolicy extension)
{
m_PrefixGenerationPolicy = prefix;
m_ExtensionGenerationPolicy = extension;
SetModified(true);
}
void CompileTargetBase::GetTargetFilenameGenerationPolicy(TargetFilenameGenerationPolicy& prefixOut,
TargetFilenameGenerationPolicy& extensionOut) const
{
prefixOut = m_PrefixGenerationPolicy;
extensionOut = m_ExtensionGenerationPolicy;
}
const wxString& CompileTargetBase::GetFilename() const
{
return m_Filename;
}
const wxString& CompileTargetBase::GetTitle() const
{
return m_Title;
}
void CompileTargetBase::SetTitle(const wxString& title)
{
if (m_Title == title)
return;
m_Title = title;
SetModified(true);
}
void CompileTargetBase::SetOutputFilename(const wxString& filename)
{
if (filename.IsEmpty())
{
m_OutputFilename = SuggestOutputFilename();
SetModified(true);
return;
}
else if (m_OutputFilename == filename)
return;
m_OutputFilename = UnixFilename(filename);
GenerateTargetFilename(m_OutputFilename);
SetModified(true);
}
void CompileTargetBase::SetImportLibraryFilename(const wxString& filename)
{
if (filename.IsEmpty())
{
m_ImportLibraryFilename = _T("$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME)");
SetModified(true);
return;
}
else if (m_ImportLibraryFilename == filename)
return;
m_ImportLibraryFilename = UnixFilename(filename);
}
void CompileTargetBase::SetDefinitionFileFilename(const wxString& filename)
{
if (filename.IsEmpty())
{
m_DefinitionFileFilename = _T("$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME)");
SetModified(true);
return;
}
else if (m_DefinitionFileFilename == filename)
return;
m_DefinitionFileFilename = UnixFilename(filename);
}
void CompileTargetBase::SetWorkingDir(const wxString& dirname)
{
if (m_WorkingDir == dirname)
return;
m_WorkingDir = UnixFilename(dirname);
SetModified(true);
}
void CompileTargetBase::SetObjectOutput(const wxString& dirname)
{
if (m_ObjectOutput == dirname)
return;
m_ObjectOutput = UnixFilename(dirname);
SetModified(true);
}
void CompileTargetBase::SetDepsOutput(const wxString& dirname)
{
if (m_DepsOutput == dirname)
return;
m_DepsOutput = UnixFilename(dirname);
SetModified(true);
}
OptionsRelation CompileTargetBase::GetOptionRelation(OptionsRelationType type) const
{
return m_OptionsRelation[type];
}
void CompileTargetBase::SetOptionRelation(OptionsRelationType type, OptionsRelation rel)
{
if (m_OptionsRelation[type] == rel)
return;
m_OptionsRelation[type] = rel;
SetModified(true);
}
wxString CompileTargetBase::GetOutputFilename() const
{
if (m_TargetType == ttCommandsOnly)
return wxEmptyString;
if (m_OutputFilename.IsEmpty())
m_OutputFilename = SuggestOutputFilename();
return m_OutputFilename;
}
wxString CompileTargetBase::SuggestOutputFilename() const
{
wxString suggestion;
switch (m_TargetType)
{
case ttConsoleOnly: // fall through
case ttExecutable: suggestion = GetExecutableFilename(); break;
case ttDynamicLib: suggestion = GetDynamicLibFilename(); break;
case ttStaticLib: suggestion = GetStaticLibFilename(); break;
case ttNative: suggestion = GetNativeFilename(); break;
case ttCommandsOnly: // fall through
default:
suggestion.Clear();
break;
}
wxFileName fname(suggestion);
return UnixFilename(fname.GetFullName());
}
wxString CompileTargetBase::GetWorkingDir()
{
if (m_TargetType != ttConsoleOnly && m_TargetType != ttExecutable && m_TargetType != ttDynamicLib)
return wxEmptyString;
wxString out;
if (m_WorkingDir.IsEmpty())
{
out = GetOutputFilename();
return wxFileName(out).GetPath(wxPATH_GET_VOLUME);
}
return m_WorkingDir;
}
wxString CompileTargetBase::GetObjectOutput() const
{
if (m_TargetType == ttCommandsOnly)
return wxEmptyString;
wxString out;
if (m_ObjectOutput.IsEmpty())
{
out = GetBasePath();
if (out.IsEmpty() || out.Matches(_T(".")))
return _T(".objs");
else
return out + wxFileName::GetPathSeparator() + _T(".objs");
}
return m_ObjectOutput;
}
wxString CompileTargetBase::GetDepsOutput() const
{
if (m_TargetType == ttCommandsOnly)
return wxEmptyString;
wxString out;
if (m_DepsOutput.IsEmpty())
{
out = GetBasePath();
if (out.IsEmpty() || out.Matches(_T(".")))
return _T(".deps");
else
return out + wxFileName::GetPathSeparator() + _T(".deps");
}
return m_DepsOutput;
}
void CompileTargetBase::GenerateTargetFilename(wxString& filename) const
{
// nothing to do if no auto-generation
if ( m_PrefixGenerationPolicy == tgfpNone
&& m_ExtensionGenerationPolicy == tgfpNone )
return;
wxFileName fname(filename);
filename.Clear();
// path with volume and separator
filename << fname.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
// prefix + name + extension
switch (m_TargetType)
{
case ttConsoleOnly:
case ttExecutable:
{
if (m_ExtensionGenerationPolicy == tgfpPlatformDefault)
{
filename << fname.GetName();
filename << FileFilters::EXECUTABLE_DOT_EXT;
}
else
filename << fname.GetFullName();
break;
}
case ttDynamicLib:
{
if (m_PrefixGenerationPolicy == tgfpPlatformDefault)
{
wxString prefix = wxEmptyString;
// On linux, "lib" is the common prefix for this platform
if (platform::Linux)
prefix = wxT("lib");
// FIXME (Morten#5#): What about Mac (Windows is OK)?!
// avoid adding the prefix, if there is no prefix, or already its there
if (!prefix.IsEmpty() && !fname.GetName().StartsWith(prefix))
filename << prefix;
}
if (m_ExtensionGenerationPolicy == tgfpPlatformDefault)
filename << fname.GetName() << FileFilters::DYNAMICLIB_DOT_EXT;
else
filename << fname.GetFullName();
break;
}
case ttNative:
{
if (m_ExtensionGenerationPolicy == tgfpPlatformDefault)
filename << fname.GetName() << FileFilters::NATIVE_DOT_EXT;
else
filename << fname.GetFullName();
break;
}
case ttStaticLib:
{
if (m_PrefixGenerationPolicy == tgfpPlatformDefault)
{
Compiler* compiler = CompilerFactory::GetCompiler(m_CompilerId);
wxString prefix = compiler ? compiler->GetSwitches().libPrefix : _T("");
// avoid adding the prefix, if already there
if (!prefix.IsEmpty() && !fname.GetName().StartsWith(prefix))
filename << prefix;
}
if (m_ExtensionGenerationPolicy == tgfpPlatformDefault)
{
Compiler* compiler = CompilerFactory::GetCompiler(m_CompilerId);
wxString Ext = compiler ? compiler->GetSwitches().libExtension : FileFilters::STATICLIB_EXT;
filename << fname.GetName() << _T(".") << Ext;
}
else
filename << fname.GetFullName();
break;
}
case ttCommandsOnly: // fall through
default:
filename.Clear();
break;
}
#ifdef command_line_generation
Manager::Get()->GetLogManager()->DebugLog(wxString::Format("CompileTargetBase::GenerateTargetFilename got %s and returns: '%s'", fname.GetFullPath(), filename));
#endif
}
wxString CompileTargetBase::GetExecutableFilename() const
{
if (m_TargetType == ttCommandsOnly)
return wxEmptyString;
if (m_PrefixGenerationPolicy != tgfpNone || m_ExtensionGenerationPolicy != tgfpNone)
{
wxString out = m_Filename;
GenerateTargetFilename(out);
return out;
}
wxFileName fname(m_Filename);
#ifdef __WXMSW__
fname.SetExt(FileFilters::EXECUTABLE_EXT);
#else
fname.SetExt(_T(""));
#endif
return fname.GetFullPath();
}
wxString CompileTargetBase::GetNativeFilename() const
{
if (m_TargetType == ttCommandsOnly)
return wxEmptyString;
if (m_Filename.IsEmpty())
m_Filename = m_OutputFilename;
if (m_PrefixGenerationPolicy != tgfpNone || m_ExtensionGenerationPolicy != tgfpNone)
{
wxString out = m_Filename;
GenerateTargetFilename(out);
return out;
}
wxFileName fname(m_Filename);
fname.SetName(fname.GetName());
fname.SetExt(FileFilters::NATIVE_EXT);
return fname.GetFullPath();
}
wxString CompileTargetBase::GetDynamicLibFilename() const
{
if (m_TargetType == ttCommandsOnly)
return wxEmptyString;
if (m_Filename.IsEmpty())
m_Filename = m_OutputFilename;
if (m_PrefixGenerationPolicy != tgfpNone || m_ExtensionGenerationPolicy != tgfpNone)
{
wxString out = m_Filename;
GenerateTargetFilename(out);
#ifdef command_line_generation
Manager::Get()->GetLogManager()->DebugLog(wxString::Format("CompileTargetBase::GetDynamicLibFilename [0] returns: '%s'", out));
#endif
return out;
}
wxFileName fname(m_Filename);
fname.SetName(fname.GetName());
fname.SetExt(FileFilters::DYNAMICLIB_EXT);
#ifdef command_line_generation
Manager::Get()->GetLogManager()->DebugLog(wxString::Format("CompileTargetBase::GetDynamicLibFilename [1] returns: '%s'", fname.GetFullPath()));
#endif
return fname.GetFullPath();
}
wxString CompileTargetBase::GetDynamicLibImportFilename()
{
if (m_TargetType == ttCommandsOnly)
return wxEmptyString;
if (m_ImportLibraryFilename.IsEmpty())
m_ImportLibraryFilename = _T("$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME)");
wxFileName fname(m_ImportLibraryFilename);
#ifdef command_line_generation
Manager::Get()->GetLogManager()->DebugLog(wxString::Format("CompileTargetBase::GetDynamicLibImportFilename returns: '%s'", fname.GetFullPath()));
#endif
return fname.GetFullPath();
}
wxString CompileTargetBase::GetDynamicLibDefFilename()
{
if (m_TargetType == ttCommandsOnly)
return wxEmptyString;
if (m_DefinitionFileFilename.IsEmpty())
m_DefinitionFileFilename = _T("$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME)");
wxFileName fname(m_DefinitionFileFilename);
#ifdef command_line_generation
Manager::Get()->GetLogManager()->DebugLog(wxString::Format("CompileTargetBase::GetDynamicLibDefFilename returns: '%s'", fname.GetFullPath()));
#endif
return fname.GetFullPath();
}
wxString CompileTargetBase::GetStaticLibFilename() const
{
if (m_TargetType == ttCommandsOnly)
return wxEmptyString;
if (m_Filename.IsEmpty())
m_Filename = m_OutputFilename;
/* NOTE: There is no need to check for Generation policy for import library
if target type is ttDynamicLib. */
if ( (m_TargetType == ttStaticLib)
&& ( m_PrefixGenerationPolicy != tgfpNone
|| m_ExtensionGenerationPolicy != tgfpNone) )
{
wxString out = m_Filename;
GenerateTargetFilename(out);
#ifdef command_line_generation
Manager::Get()->GetLogManager()->DebugLog(wxString::Format("CompileTargetBase::GetStaticLibFilename [0] returns: '%s'", out));
#endif
return out;
}
wxFileName fname(m_Filename);
wxString prefix = _T("lib");
wxString suffix = FileFilters::STATICLIB_EXT;
Compiler* compiler = CompilerFactory::GetCompiler(m_CompilerId);
if (compiler)
{
prefix = compiler->GetSwitches().libPrefix;
suffix = compiler->GetSwitches().libExtension;
}
if (!fname.GetName().StartsWith(prefix))
fname.SetName(prefix + fname.GetName());
fname.SetExt(suffix);
#ifdef command_line_generation
Manager::Get()->GetLogManager()->DebugLog(wxString::Format("CompileTargetBase::GetStaticLibFilename [1] returns: '%s'", fname.GetFullPath()));
#endif
return fname.GetFullPath();
}
wxString CompileTargetBase::GetBasePath() const
{
if (m_Filename.IsEmpty())
return _T(".");
wxFileName basePath(m_Filename);
wxString base = basePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
return !base.IsEmpty() ? base : _T(".");
}
void CompileTargetBase::SetTargetType(TargetType pt)
{
if (m_TargetType == pt)
return;
m_TargetType = pt;
m_OutputFilename = SuggestOutputFilename();
SetModified(true);
}
TargetType CompileTargetBase::GetTargetType() const
{
return m_TargetType;
}
const wxString& CompileTargetBase::GetExecutionParameters() const
{
return m_ExecutionParameters;
}
void CompileTargetBase::SetExecutionParameters(const wxString& params)
{
if (m_ExecutionParameters == params)
return;
m_ExecutionParameters = params;
SetModified(true);
}
const wxString& CompileTargetBase::GetHostApplication() const
{
return m_HostApplication;
}
void CompileTargetBase::SetHostApplication(const wxString& app)
{
if (m_HostApplication == app)
return;
m_HostApplication = app;
SetModified(true);
}
bool CompileTargetBase::GetRunHostApplicationInTerminal() const
{
return m_RunHostApplicationInTerminal;
}
void CompileTargetBase::SetRunHostApplicationInTerminal(bool in_terminal)
{
if (m_RunHostApplicationInTerminal == in_terminal)
return;
m_RunHostApplicationInTerminal = in_terminal;
SetModified(true);
}
void CompileTargetBase::SetCompilerID(const wxString& id)
{
if (id == m_CompilerId)
return;
m_CompilerId = id;
SetModified(true);
}
void CompileTargetBase::SetMakeCommandFor(MakeCommand cmd, const wxString& make)
{
if (m_MakeCommands[cmd] == make)
return;
m_MakeCommands[cmd] = make;
m_MakeCommandsModified = true;
SetModified(true);
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.