ENH: add a virtual CreateMakeVariable to shorten makefile variables for borland make

This commit is contained in:
Bill Hoffman 2002-02-21 15:55:20 -05:00
parent 49fa9d8b61
commit 3c748ec5ad
5 changed files with 122 additions and 58 deletions

View File

@ -23,7 +23,7 @@
#include "cmCacheManager.h"
#include "cmGeneratedFileStream.h"
#include "windows.h"
#include <stdio.h>
cmBorlandMakefileGenerator::cmBorlandMakefileGenerator()
{
@ -235,8 +235,8 @@ void cmBorlandMakefileGenerator::OutputSharedLibraryRule(std::ostream& fout,
target = cmSystemTools::EscapeSpaces(target.c_str());
libpath = cmSystemTools::EscapeSpaces(libpath.c_str());
std::string depend = "$(";
depend += name;
depend += "_SRC_OBJS) $(" + std::string(name) + "_DEPEND_LIBS)";
depend += this->CreateMakeVariable(name, "_SRC_OBJS");
depend += ") $(" + this->CreateMakeVariable(name, "_DEPEND_LIBS") + ")";
std::string command = "$(CMAKE_CXX_COMPILER) -tWD $(CMAKE_SHLIB_CFLAGS) $(CMAKE_LINKER_FLAGS) @&&|\n";
// must be executable name
command += "-e";
@ -248,8 +248,8 @@ void cmBorlandMakefileGenerator::OutputSharedLibraryRule(std::ostream& fout,
// then the linker options -L and libraries (any other order will fail!)
command += linklibs.str();
delete [] linklibs.str();
// then list of object files
command += " $(" + std::string(name) + "_SRC_OBJS) ";
// then list of object files
command += " $(" + this->CreateMakeVariable(name, "_SRC_OBJS") + ") ";
std::string command2 = "implib -w ";
command2 += libpath + " " + target;
const std::vector<cmSourceFile>& sources = t.GetSourceFiles();
@ -293,7 +293,7 @@ void cmBorlandMakefileGenerator::OutputStaticLibraryRule(std::ostream& fout,
cmSystemTools::ConvertToWindowsSlashes(target);
target = cmSystemTools::EscapeSpaces(target.c_str());
std::string depend = "$(";
depend += std::string(name) + "_SRC_OBJS)";
depend += this->CreateMakeVariable(name, "_SRC_OBJS") + ") ";
std::string command = "tlib @&&|\n\t /p512 /a ";
command += target;
command += " ";
@ -303,7 +303,7 @@ void cmBorlandMakefileGenerator::OutputStaticLibraryRule(std::ostream& fout,
deleteCommand += target;
command += " $(";
command += std::string(name) + "_SRC_OBJS_QUOTED)";
command += this->CreateMakeVariable(name, "_SRC_OBJS_QUOTED") + ")";
command += "\n|\n";
std::string comment = "rule to build static library: ";
comment += name;
@ -329,7 +329,8 @@ void cmBorlandMakefileGenerator::OutputExecutableRule(std::ostream& fout,
cmSystemTools::ConvertToWindowsSlashes(target);
target = cmSystemTools::EscapeSpaces(target.c_str());
std::string depend = "$(";
depend += std::string(name) + "_SRC_OBJS) $(" + std::string(name) + "_DEPEND_LIBS)";
depend += this->CreateMakeVariable(name, "_SRC_OBJS") + ") $(" +
this->CreateMakeVariable(name, "_DEPEND_LIBS") + ")";
std::string command =
"$(CMAKE_CXX_COMPILER) ";
command += " $(CMAKE_LINKER_FLAGS) -e" + target;
@ -350,7 +351,7 @@ void cmBorlandMakefileGenerator::OutputExecutableRule(std::ostream& fout,
linklibs << std::ends;
command += linklibs.str();
delete [] linklibs.str();
command += " $(" + std::string(name) + "_SRC_OBJS) ";
command += " $(" + this->CreateMakeVariable(name, "_SRC_OBJS") + ")";
std::string comment = "rule to build executable: ";
comment += name;
@ -404,3 +405,54 @@ bool cmBorlandMakefileGenerator::SamePath(const char* path1, const char* path2)
}
// borland make does not support variables that are longer than 32
// so use this function to rename any long ones
std::string cmBorlandMakefileGenerator::CreateMakeVariable(const char* s, const char* s2)
{
std::string unmodified = s;
unmodified += s2;
// see if th
if(m_MakeVariableMap.count(unmodified))
{
return m_MakeVariableMap[unmodified];
}
std::string ret = unmodified;
// if the string is greater the 32 chars it is an invalid vairable name
// for borland make
if(ret.size() > 32)
{
std::string str1 = s;
std::string str2 = s2;
// we must shorten the combined string by 4 charactors
// keep no more than 24 charactors from the second string
if(str2.size() > 24)
{
str2 = str2.substr(0, 24);
}
if(str1.size() + str2.size() > 27)
{
str1 = str1.substr(0, 27 - str2.size());
}
char buffer[5];
int i = 0;
sprintf(buffer, "%04d", i);
ret = str1 + str2 + buffer;
while(m_ShortMakeVariableMap.count(ret) && i < 1000)
{
++i;
sprintf(buffer, "%04d", i);
ret = str1 + str2 + buffer;
}
if(i == 1000)
{
cmSystemTools::Error("Borland makefile varible length too long");
return unmodified;
}
// once an unused variable is found
m_ShortMakeVariableMap[ret] = "1";
}
// always make an entry into the unmodified to varible map
m_MakeVariableMap[unmodified] = ret;
return ret;
}

View File

@ -61,6 +61,9 @@ protected:
virtual std::string GetOutputExtension(const char* sourceExtension);
///! return true if the two paths are the same (checks short paths)
virtual bool SamePath(const char* path1, const char* path2);
virtual std::string CreateMakeVariable(const char* s, const char* s2);
std::map<cmStdString, cmStdString> m_MakeVariableMap;
std::map<cmStdString, cmStdString> m_ShortMakeVariableMap;
};
#endif

View File

@ -420,8 +420,8 @@ void cmNMakeMakefileGenerator::OutputSharedLibraryRule(std::ostream& fout,
{
std::string target = m_LibraryOutputPath + name + m_SharedLibraryExtension;
std::string depend = "$(";
depend += name;
depend += "_SRC_OBJS) $(" + std::string(name) + "_DEPEND_LIBS)";
depend += this->CreateMakeVariable(name, "_SRC_OBJS");
depend += ") $(" + this->CreateMakeVariable(name, "_DEPEND_LIBS") + ")";
// Need to get the definition here because this value might have
// trailing space (since it is directly prepended to the filename)
@ -442,7 +442,7 @@ void cmNMakeMakefileGenerator::OutputSharedLibraryRule(std::ostream& fout,
std::string dllpath = m_LibraryOutputPath + std::string(name) + m_SharedLibraryExtension;
command += cmSystemTools::EscapeSpaces(dllpath.c_str());
command += " $(" + std::string(name) + "_SRC_OBJS) ";
command += " $(" + this->CreateMakeVariable(name, "_SRC_OBJS") + ") ";
std::strstream linklibs;
this->OutputLinkLibraries(linklibs, name, t);
@ -492,7 +492,7 @@ void cmNMakeMakefileGenerator::OutputStaticLibraryRule(std::ostream& fout,
{
std::string target = m_LibraryOutputPath + std::string(name) + m_StaticLibraryExtension;
std::string depend = "$(";
depend += std::string(name) + "_SRC_OBJS)";
depend += this->CreateMakeVariable(name, "_SRC_OBJS") + ") ";
// Need to get the definition here because this value might have
// trailing space (since it is directly prepended to the filename)
@ -506,7 +506,7 @@ void cmNMakeMakefileGenerator::OutputStaticLibraryRule(std::ostream& fout,
command += cmSystemTools::EscapeSpaces(libpath.c_str());
command += " $(";
command += std::string(name) + "_SRC_OBJS)";
command += this->CreateMakeVariable(name, "_SRC_OBJS") + ")";
command += "\n<<\n";
std::string comment = "rule to build static library: ";
@ -532,10 +532,11 @@ void cmNMakeMakefileGenerator::OutputExecutableRule(std::ostream& fout,
std::string target = m_ExecutableOutputPath + name;
target += m_ExecutableExtension;
std::string depend = "$(";
depend += std::string(name) + "_SRC_OBJS) $(" + std::string(name) + "_DEPEND_LIBS)";
depend += this->CreateMakeVariable(name, "_SRC_OBJS") + ") $(" +
this->CreateMakeVariable(name, "_DEPEND_LIBS") + ")";
std::string command =
"$(CMAKE_CXX_COMPILER) $(CMAKE_CXX_FLAGS) ";
command += "$(" + std::string(name) + "_SRC_OBJS) ";
command += "$(" + this->CreateMakeVariable(name, "_SRC_OBJS") + ") ";
std::string path = m_ExecutableOutputPath + name + m_ExecutableExtension;
// Need to get the definition here because this value might have

View File

@ -363,36 +363,36 @@ void cmUnixMakefileGenerator::OutputTargetRules(std::ostream& fout)
std::vector<cmSourceFile> classes = l->second.GetSourceFiles();
if (classes.begin() != classes.end())
{
fout << l->first << "_SRC_OBJS = ";
for(std::vector<cmSourceFile>::iterator i = classes.begin();
i != classes.end(); i++)
{
if(!i->IsAHeaderFileOnly())
{
std::string outExt(this->GetOutputExtension(i->GetSourceExtension().c_str()));
if(outExt.size())
{
fout << "\\\n" << this->ConvertToNativePath(i->GetSourceName().c_str())
<< outExt.c_str() << " ";
}
}
}
fout << "\n\n";
fout << l->first << "_SRC_OBJS_QUOTED = ";
for(std::vector<cmSourceFile>::iterator i = classes.begin();
i != classes.end(); i++)
{
if(!i->IsAHeaderFileOnly())
{
std::string outExt(this->GetOutputExtension(i->GetSourceExtension().c_str()));
if(outExt.size())
{
fout << "\\\n\"" << this->ConvertToNativePath(i->GetSourceName().c_str())
<< outExt.c_str() << "\" ";
}
}
}
fout << "\n\n";
fout << this->CreateMakeVariable(l->first.c_str(), "_SRC_OBJS") << " = ";
for(std::vector<cmSourceFile>::iterator i = classes.begin();
i != classes.end(); i++)
{
if(!i->IsAHeaderFileOnly())
{
std::string outExt(this->GetOutputExtension(i->GetSourceExtension().c_str()));
if(outExt.size())
{
fout << "\\\n" << this->ConvertToNativePath(i->GetSourceName().c_str())
<< outExt.c_str() << " ";
}
}
}
fout << "\n\n";
fout << this->CreateMakeVariable(l->first.c_str(), "_SRC_OBJS_QUOTED") << " = ";
for(std::vector<cmSourceFile>::iterator i = classes.begin();
i != classes.end(); i++)
{
if(!i->IsAHeaderFileOnly())
{
std::string outExt(this->GetOutputExtension(i->GetSourceExtension().c_str()));
if(outExt.size())
{
fout << "\\\n\"" << this->ConvertToNativePath(i->GetSourceName().c_str())
<< outExt.c_str() << "\" ";
}
}
}
fout << "\n\n";
}
}
fout << "CLEAN_OBJECT_FILES = ";
@ -402,7 +402,8 @@ void cmUnixMakefileGenerator::OutputTargetRules(std::ostream& fout)
std::vector<cmSourceFile> classes = l->second.GetSourceFiles();
if (classes.begin() != classes.end())
{
fout << "$(" << l->first << "_SRC_OBJS) ";
fout << "$(" << this->CreateMakeVariable(l->first.c_str(), "_SRC_OBJS")
<< ") ";
}
}
fout << "\n\n";
@ -600,8 +601,8 @@ void cmUnixMakefileGenerator::OutputSharedLibraryRule(std::ostream& fout,
{
std::string target = m_LibraryOutputPath + "lib" + name + "$(SHLIB_SUFFIX)";
std::string depend = "$(";
depend += name;
depend += "_SRC_OBJS) $(" + std::string(name) + "_DEPEND_LIBS)";
depend += this->CreateMakeVariable(name, "_SRC_OBJS");
depend += ") $(" + this->CreateMakeVariable(name, "_DEPEND_LIBS") + ")";
std::string command = "$(RM) lib";
command += name;
command += "$(SHLIB_SUFFIX)";
@ -609,7 +610,7 @@ void cmUnixMakefileGenerator::OutputSharedLibraryRule(std::ostream& fout,
"$(CMAKE_SHLIB_BUILD_FLAGS) $(CMAKE_CXX_FLAGS) -o \\\n";
command2 += "\t ";
command2 += m_LibraryOutputPath + "lib" + std::string(name) + "$(SHLIB_SUFFIX) \\\n";
command2 += "\t $(" + std::string(name) + "_SRC_OBJS) ";
command2 += "\t $(" + this->CreateMakeVariable(name, "_SRC_OBJS") + ") ";
std::strstream linklibs;
this->OutputLinkLibraries(linklibs, name, t);
linklibs << std::ends;
@ -635,13 +636,14 @@ void cmUnixMakefileGenerator::OutputModuleLibraryRule(std::ostream& fout,
{
std::string target = m_LibraryOutputPath + "lib" + std::string(name) + "$(MODULE_SUFFIX)";
std::string depend = "$(";
depend += std::string(name) + "_SRC_OBJS) $(" + std::string(name) + "_DEPEND_LIBS)";
depend += this->CreateMakeVariable(name, "_SRC_OBJS")
+ ") $(" + this->CreateMakeVariable(name, "_DEPEND_LIBS") + ")";
std::string command = "$(RM) lib" + std::string(name) + "$(MODULE_SUFFIX)";
std::string command2 = "$(CMAKE_CXX_COMPILER) $(CMAKE_MODULE_LINK_FLAGS) "
"$(CMAKE_MODULE_BUILD_FLAGS) $(CMAKE_CXX_FLAGS) -o \\\n";
command2 += "\t ";
command2 += m_LibraryOutputPath + "lib" + std::string(name) + "$(MODULE_SUFFIX) \\\n";
command2 += "\t $(" + std::string(name) + "_SRC_OBJS) ";
command2 += "\t $(" + this->CreateMakeVariable(name, "_SRC_OBJS") + ") ";
std::strstream linklibs;
this->OutputLinkLibraries(linklibs, std::string(name).c_str(), t);
linklibs << std::ends;
@ -668,13 +670,13 @@ void cmUnixMakefileGenerator::OutputStaticLibraryRule(std::ostream& fout,
{
std::string target = m_LibraryOutputPath + "lib" + std::string(name) + ".a";
std::string depend = "$(";
depend += std::string(name) + "_SRC_OBJS)";
depend += this->CreateMakeVariable(name, "_SRC_OBJS") + ")";
std::string command = "$(CMAKE_AR) $(CMAKE_AR_ARGS) ";
command += m_LibraryOutputPath;
command += "lib";
command += name;
command += ".a $(";
command += std::string(name) + "_SRC_OBJS)";
command += this->CreateMakeVariable(name, "_SRC_OBJS") + ")";
std::string command2 = "$(CMAKE_RANLIB) ";
command2 += m_LibraryOutputPath;
command2 += "lib";
@ -702,10 +704,11 @@ void cmUnixMakefileGenerator::OutputExecutableRule(std::ostream& fout,
{
std::string target = m_ExecutableOutputPath + name;
std::string depend = "$(";
depend += std::string(name) + "_SRC_OBJS) $(" + std::string(name) + "_DEPEND_LIBS)";
depend += this->CreateMakeVariable(name, "_SRC_OBJS")
+ ") $(" + this->CreateMakeVariable(name, "_DEPEND_LIBS") + ")";
std::string command =
"$(CMAKE_CXX_COMPILER) $(CMAKE_SHLIB_LINK_FLAGS) $(CMAKE_CXX_FLAGS) ";
command += "$(" + std::string(name) + "_SRC_OBJS) ";
command += "$(" + this->CreateMakeVariable(name, "_SRC_OBJS") + ") ";
std::strstream linklibs;
this->OutputLinkLibraries(linklibs, 0, t);
linklibs << std::ends;
@ -785,7 +788,7 @@ void cmUnixMakefileGenerator::OutputDependLibs(std::ostream& fout)
|| (l->second.GetType() == cmTarget::EXECUTABLE)
|| (l->second.GetType() == cmTarget::WIN32_EXECUTABLE))
{
fout << l->first << "_DEPEND_LIBS = ";
fout << this->CreateMakeVariable(l->first.c_str(), "_DEPEND_LIBS") << " = ";
// A library should not depend on itself!
emitted.insert(l->first);

View File

@ -155,7 +155,12 @@ protected:
void SetLibraryPrefix(const char* e) { m_LibraryPrefix = e;}
virtual std::string ConvertToNativePath(const char* s) { return s; }
std::string CreateTargetRules(const cmTarget &target,
const char* targetName);
const char* targetName);
virtual std::string CreateMakeVariable(const char* s, const char* s2)
{
return std::string(s) + std::string(s2);
}
protected:
std::string m_ExecutableOutputPath;
std::string m_LibraryOutputPath;