📄 makefilegenerator.cpp
字号:
return;
if (useGlobalOptions)
obj = m_CompilerSet;
else
obj = target ? (CompileOptionsBase*)target : (m_Project ? (CompileOptionsBase*)m_Project : m_CompilerSet);
wxArrayString opts = obj->GetLinkerOptions();
for (unsigned int x = 0; x < opts.GetCount(); ++x)
{
if (!m_GeneratingMakefile)
Manager::Get()->GetMacrosManager()->ReplaceEnvVars(opts[x]);
cmd << _T(" ") << opts[x];
}
}
void MakefileGenerator::DoAppendLinkerLibs(wxString& cmd, ProjectBuildTarget* target, bool useGlobalOptions)
{
if (!m_CompilerSet)
return;
CompileOptionsBase* obj;
if (useGlobalOptions)
obj = m_CompilerSet;
else
{
obj = target ? (CompileOptionsBase*)target : (m_Project ? (CompileOptionsBase*)m_Project : m_CompilerSet);
int index = target ? target->GetCompilerIndex() : (m_Project ? m_Project->GetCompilerIndex() : CompilerFactory::GetDefaultCompilerIndex());
m_CompilerSet = CompilerFactory::Compilers[index];
}
wxArrayString libs = obj->GetLinkLibs();
for (unsigned int x = 0; x < libs.GetCount(); ++x)
{
if (libs[x].IsEmpty())
continue;
// construct linker option for each lib, based on compiler's settings
wxString libPrefix = m_CompilerSet->GetSwitches().libPrefix;
wxString libExt = m_CompilerSet->GetSwitches().libExtension;
wxString lib = libs[x];
QuoteStringIfNeeded(lib);
// run replacements on libs only if no slashes in name (which means it's a relative or absolute path)
if (lib.Find('/') == -1 && lib.Find('\\') == -1)
{
// 'lib' prefix
bool hadLibPrefix = false;
if (!m_CompilerSet->GetSwitches().linkerNeedsLibPrefix &&
!libPrefix.IsEmpty() &&
lib.StartsWith(libPrefix))
{
lib.Remove(0, libPrefix.Length());
hadLibPrefix = true;
}
// extension
if (!m_CompilerSet->GetSwitches().linkerNeedsLibExtension &&
lib.Length() > libExt.Length() &&
lib.Right(libExt.Length() + 1) == _T(".") + libExt)
{
// remove the extension only if we had a lib prefix
if (hadLibPrefix)
lib.RemoveLast(libExt.Length() + 1);
}
else if (m_CompilerSet->GetSwitches().linkerNeedsLibExtension &&
!libExt.IsEmpty())
{
if (lib.Length() <= libExt.Length() ||
lib.Right(libExt.Length() + 1) != _T(".") + libExt)
{
lib << _T(".") << libExt;
}
}
lib = m_CompilerSet->GetSwitches().linkLibs + lib;
}
if (!m_GeneratingMakefile)
Manager::Get()->GetMacrosManager()->ReplaceEnvVars(lib);
cmd << _T(" ") << lib;
}
}
void MakefileGenerator::DoAppendIncludeDirs(wxString& cmd, ProjectBuildTarget* target, const wxString& prefix, bool useGlobalOptions)
{
wxArrayString opts;
if (!m_CompilerSet)
return;
if (useGlobalOptions)
opts = m_CompilerSet->GetIncludeDirs();
else
{
if (target)
opts = target->GetIncludeDirs();
else
opts = m_Project ? m_Project->GetIncludeDirs() : m_CompilerSet->GetIncludeDirs();
}
for (unsigned int x = 0; x < opts.GetCount(); ++x)
{
if (opts[x].IsEmpty())
continue;
wxString out = UnixFilename(opts[x]);
if (!m_GeneratingMakefile)
Manager::Get()->GetMacrosManager()->ReplaceEnvVars(out);
ConvertToMakefileFriendly(out);
QuoteStringIfNeeded(out);
cmd << _T(" ") << prefix << out;
}
}
void MakefileGenerator::DoAppendResourceIncludeDirs(wxString& cmd, ProjectBuildTarget* target, const wxString& prefix, bool useGlobalOptions)
{
wxArrayString opts;
if (!m_CompilerSet)
return;
if (useGlobalOptions)
opts = m_CompilerSet->GetResourceIncludeDirs();
else
{
if (target)
opts = target->GetResourceIncludeDirs();
else
opts = m_Project ? m_Project->GetResourceIncludeDirs() : m_CompilerSet->GetResourceIncludeDirs();
}
for (unsigned int x = 0; x < opts.GetCount(); ++x)
{
if (opts[x].IsEmpty())
continue;
wxString out = UnixFilename(opts[x]);
if (!m_GeneratingMakefile)
Manager::Get()->GetMacrosManager()->ReplaceEnvVars(out);
ConvertToMakefileFriendly(out);
QuoteStringIfNeeded(out);
cmd << _T(" ") << prefix << out;
}
}
void MakefileGenerator::DoAppendLibDirs(wxString& cmd, ProjectBuildTarget* target, const wxString& prefix, bool useGlobalOptions)
{
wxArrayString opts;
if (!m_CompilerSet)
return;
if (useGlobalOptions)
opts = m_CompilerSet->GetLibDirs();
else
{
if (target)
opts = target->GetLibDirs();
else
opts = m_Project ? m_Project->GetLibDirs() : m_CompilerSet->GetLibDirs();
}
for (unsigned int x = 0; x < opts.GetCount(); ++x)
{
if (opts[x].IsEmpty())
continue;
wxString out = UnixFilename(opts[x]);
if (!m_GeneratingMakefile)
Manager::Get()->GetMacrosManager()->ReplaceEnvVars(out);
ConvertToMakefileFriendly(out);
QuoteStringIfNeeded(out);
cmd << _T(" ") << prefix << out;
}
}
void MakefileGenerator::DoGetMakefileIncludes(wxString& buffer, ProjectBuildTarget* target)
{
UpdateCompiler(target);
if (!m_CompilerSet || !target)
return;
wxString prefix = m_CompilerSet->GetSwitches().includeDirs;
OptionsRelation relation = target->GetOptionRelation(ortIncludeDirs);
switch (relation)
{
case orUseParentOptionsOnly:
buffer << _T(" $(") + target->GetTitle() + _T("_PROJECT_INCS)");
break;
case orUseTargetOptionsOnly:
DoAppendIncludeDirs(buffer, target, prefix);
break;
case orPrependToParentOptions:
DoAppendIncludeDirs(buffer, target, prefix);
buffer << _T(" $(") + target->GetTitle() + _T("_PROJECT_INCS)");
break;
case orAppendToParentOptions:
buffer << _T(" $(") + target->GetTitle() + _T("_PROJECT_INCS)");
DoAppendIncludeDirs(buffer, target, prefix);
break;
}
buffer << _T(" $(") + target->GetTitle() + _T("_GLOBAL_INCS)");
}
void MakefileGenerator::DoGetMakefileLibs(wxString& buffer, ProjectBuildTarget* target)
{
UpdateCompiler(target);
if (!m_CompilerSet || !target)
return;
OptionsRelation relation = target->GetOptionRelation(ortLinkerOptions);
switch (relation)
{
case orUseParentOptionsOnly:
buffer << _T(" $(") + target->GetTitle() + _T("_PROJECT_LIBS)");
break;
case orUseTargetOptionsOnly:
DoAppendLinkerLibs(buffer, target);
break;
case orPrependToParentOptions:
DoAppendLinkerLibs(buffer, target);
buffer << _T(" $(") + target->GetTitle() + _T("_PROJECT_LIBS)");
break;
case orAppendToParentOptions:
buffer << _T(" $(") + target->GetTitle() + _T("_PROJECT_LIBS)");
DoAppendLinkerLibs(buffer, target);
break;
}
buffer << _T(" $(") + target->GetTitle() + _T("_GLOBAL_LIBS)");
}
void MakefileGenerator::DoGetMakefileLibDirs(wxString& buffer, ProjectBuildTarget* target)
{
UpdateCompiler(target);
if (!m_CompilerSet || !target)
return;
wxString prefix = m_CompilerSet->GetSwitches().libDirs;
OptionsRelation relation = target->GetOptionRelation(ortLibDirs);
switch (relation)
{
case orUseParentOptionsOnly:
buffer << _T(" $(") + target->GetTitle() + _T("_PROJECT_LIBDIRS)");
break;
case orUseTargetOptionsOnly:
DoAppendLibDirs(buffer, target, prefix);
break;
case orPrependToParentOptions:
DoAppendLibDirs(buffer, target, prefix);
buffer << _T(" $(") + target->GetTitle() + _T("_PROJECT_LIBDIRS)");
break;
case orAppendToParentOptions:
buffer << _T(" $(") + target->GetTitle() + _T("_PROJECT_LIBDIRS)");
DoAppendLibDirs(buffer, target, prefix);
break;
}
buffer << _T(" $(") + target->GetTitle() + _T("_GLOBAL_LIBDIRS)");
}
void MakefileGenerator::DoGetMakefileCFlags(wxString& buffer, ProjectBuildTarget* target)
{
UpdateCompiler();
if (!m_CompilerSet || !target)
return;
OptionsRelation relation = target->GetOptionRelation(ortCompilerOptions);
switch (relation)
{
case orUseParentOptionsOnly:
buffer << _T(" $(") + target->GetTitle() + _T("_PROJECT_CFLAGS)");
break;
case orUseTargetOptionsOnly:
DoAppendCompilerOptions(buffer, target);
break;
case orPrependToParentOptions:
DoAppendCompilerOptions(buffer, target);
buffer << _T(" $(") + target->GetTitle() + _T("_PROJECT_CFLAGS)");
break;
case orAppendToParentOptions:
buffer << _T(" $(") + target->GetTitle() + _T("_PROJECT_CFLAGS)");
DoAppendCompilerOptions(buffer, target);
break;
}
buffer << _T(" $(") + target->GetTitle() + _T("_GLOBAL_CFLAGS)");
}
void MakefileGenerator::DoGetMakefileLDFlags(wxString& buffer, ProjectBuildTarget* target)
{
UpdateCompiler(target);
if (!m_CompilerSet || !target)
return;
OptionsRelation relation = target->GetOptionRelation(ortLinkerOptions);
switch (relation)
{
case orUseParentOptionsOnly:
buffer << _T(" $(") + target->GetTitle() + _T("_PROJECT_LDFLAGS)");
break;
case orUseTargetOptionsOnly:
DoAppendLinkerOptions(buffer, target);
break;
case orPrependToParentOptions:
DoAppendLinkerOptions(buffer, target);
buffer << _T(" $(") + target->GetTitle() + _T("_PROJECT_LDFLAGS)");
break;
case orAppendToParentOptions:
buffer << _T(" $(") + target->GetTitle() + _T("_PROJECT_LDFLAGS)");
DoAppendLinkerOptions(buffer, target);
break;
}
buffer << _T(" $(") + target->GetTitle() + _T("_GLOBAL_LDFLAGS)");
}
void MakefileGenerator::DoAddVarsSet(wxString& buffer, CustomVars& vars)
{
const VarsArray& v = vars.GetVars();
for (unsigned int i = 0; i < v.GetCount(); ++i)
{
wxString out = v[i].value;
Manager::Get()->GetMacrosManager()->ReplaceEnvVars(out);
ConvertToMakefileFriendly(out);
QuoteStringIfNeeded(out);
buffer << v[i].name << _T("=") << out << _T('\n');
}
}
void MakefileGenerator::DoAddMakefileVars(wxString& buffer)
{
buffer << _T("### Variables used in this Makefile") << _T('\n');
// compiler global vars
DoAddVarsSet(buffer, CompilerFactory::Compilers[m_Project->GetCompilerIndex()]->GetCustomVars());
// project vars
DoAddVarsSet(buffer, m_Project->GetCustomVars());
int targetsCount = m_Project->GetBuildTargetsCount();
for (int x = 0; x < targetsCount; ++x)
{
ProjectBuildTarget* target = m_Project->GetBuildTarget(x);
if (!IsTargetValid(target))
continue;
Compiler* compilerSet = CompilerFactory::Compilers[target->GetCompilerIndex()];
// target vars
DoAddVarsSet(buffer, compilerSet->GetCustomVars());
// compiler vars
// defined last so even if the user sets custom vars
// by these names, ours will have precedence...
buffer << target->GetTitle() << _T("_CC=") << compilerSet->GetPrograms().C << _T('\n');
buffer << target->GetTitle() << _T("_CPP=") << compilerSet->GetPrograms().CPP << _T('\n');
buffer << target->GetTitle() << _T("_LD=") << compilerSet->GetPrograms().LD << _T('\n');
buffer << target->GetTitle() << _T("_LIB=") << compilerSet->GetPrograms().LIB << _T('\n');
buffer << target->GetTitle() << _T("_RESCOMP=") << compilerSet->GetPrograms().WINDRES << _T('\n');
}
buffer << _T('\n');
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -