ENH: Support for spaces in paths during make install.

This commit is contained in:
Brad King 2003-01-17 18:01:05 -05:00
parent 94a8d00199
commit 5bb1a79c9f
3 changed files with 98 additions and 97 deletions

View File

@ -319,26 +319,14 @@ std::string cmLocalUnixMakefileGenerator::GetOutputExtension(const char*)
}
#endif
// Output the rules for any targets
void cmLocalUnixMakefileGenerator::OutputTargetRules(std::ostream& fout)
std::string cmLocalUnixMakefileGenerator::GetFullTargetName(const char* n,
const cmTarget& t)
{
// for each target add to the list of targets
fout << "TARGETS = ";
const cmTargets &tgts = m_Makefile->GetTargets();
// list libraries first
for(cmTargets::const_iterator l = tgts.begin();
l != tgts.end(); l++)
{
if (l->second.IsInAll())
{
const char* targetPrefix = l->second.GetProperty("PREFIX");
const char* targetSuffix = l->second.GetProperty("SUFFIX");
std::string path = m_LibraryOutputPath;
const char* targetPrefix = t.GetProperty("PREFIX");
const char* targetSuffix = t.GetProperty("SUFFIX");
const char* prefixVar = 0;
const char* suffixVar = 0;
switch(l->second.GetType())
switch(t.GetType())
{
case cmTarget::STATIC_LIBRARY:
prefixVar = "CMAKE_STATIC_LIBRARY_PREFIX";
@ -354,26 +342,46 @@ void cmLocalUnixMakefileGenerator::OutputTargetRules(std::ostream& fout)
break;
case cmTarget::EXECUTABLE:
case cmTarget::WIN32_EXECUTABLE:
targetSuffix = cmSystemTools::GetExecutableExtension();
case cmTarget::UTILITY:
case cmTarget::INSTALL_FILES:
case cmTarget::INSTALL_PROGRAMS:
break;
}
// if it is a library this will be set
if(prefixVar)
{
// if there is no prefix on the target use the cmake definition
if(!targetPrefix)
if(!targetPrefix && prefixVar)
{
targetPrefix = this->GetSafeDefinition(prefixVar);
}
// if there is no suffix on the target use the cmake definition
if(!targetSuffix)
if(!targetSuffix && suffixVar)
{
targetSuffix = this->GetSafeDefinition(suffixVar);
}
path +=
targetPrefix + l->first + targetSuffix;
std::string name = targetPrefix?targetPrefix:"";
name += n;
name += targetSuffix?targetSuffix:"";
return name;
}
// Output the rules for any targets
void cmLocalUnixMakefileGenerator::OutputTargetRules(std::ostream& fout)
{
// for each target add to the list of targets
fout << "TARGETS = ";
const cmTargets &tgts = m_Makefile->GetTargets();
// list libraries first
for(cmTargets::const_iterator l = tgts.begin();
l != tgts.end(); l++)
{
if (l->second.IsInAll())
{
if((l->second.GetType() == cmTarget::STATIC_LIBRARY) ||
(l->second.GetType() == cmTarget::SHARED_LIBRARY) ||
(l->second.GetType() == cmTarget::MODULE_LIBRARY))
{
std::string path = m_LibraryOutputPath;
path += this->GetFullTargetName(l->first.c_str(), l->second);
fout << " \\\n"
<< cmSystemTools::ConvertToOutputPath(path.c_str());
}
@ -387,8 +395,8 @@ void cmLocalUnixMakefileGenerator::OutputTargetRules(std::ostream& fout)
l->second.GetType() == cmTarget::WIN32_EXECUTABLE) &&
l->second.IsInAll())
{
std::string path = m_ExecutableOutputPath + l->first +
cmSystemTools::GetExecutableExtension();
std::string path = m_ExecutableOutputPath;
path += this->GetFullTargetName(l->first.c_str(), l->second);
fout << " \\\n" << cmSystemTools::ConvertToOutputPath(path.c_str());
}
}
@ -2052,45 +2060,34 @@ void cmLocalUnixMakefileGenerator::OutputInstallRules(std::ostream& fout)
if (l->second.GetInstallPath() != "")
{
// first make the directories for each target
fout << "\t@if [ ! -d $(DESTDIR)" << prefix << l->second.GetInstallPath() <<
fout << "\t@if [ ! -d \"$(DESTDIR)\"" << prefix << l->second.GetInstallPath() <<
" ] ; then \\\n";
fout << "\t echo \"Making directory $(DESTDIR)" << prefix
fout << "\t echo \"Making directory \"$(DESTDIR)\"" << prefix
<< l->second.GetInstallPath() << " \"; \\\n";
fout << "\t mkdir -p $(DESTDIR)" << prefix << l->second.GetInstallPath()
fout << "\t mkdir -p \"$(DESTDIR)\"" << prefix << l->second.GetInstallPath()
<< "; \\\n";
fout << "\t chmod 755 $(DESTDIR)" << prefix << l->second.GetInstallPath()
fout << "\t chmod 755 \"$(DESTDIR)\"" << prefix << l->second.GetInstallPath()
<< "; \\\n";
fout << "\t else true; \\\n";
fout << "\t fi\n";
std::string fname;
// now install the target
switch (l->second.GetType())
{
case cmTarget::STATIC_LIBRARY:
fout << "\t$(INSTALL_DATA) " << m_LibraryOutputPath << "lib"
<< l->first;
fout << ".a";
fout << " $(DESTDIR)" << prefix << l->second.GetInstallPath() << "\n";
break;
case cmTarget::SHARED_LIBRARY:
fout << "\t$(INSTALL_DATA) " << m_LibraryOutputPath
<< this->GetSafeDefinition("CMAKE_SHARED_LIBRARY_PREFIX")
<< l->first;
fout << this->GetSafeDefinition("CMAKE_SHARED_LIBRARY_SUFFIX");
fout << " $(DESTDIR)" << prefix << l->second.GetInstallPath() << "\n";
break;
case cmTarget::MODULE_LIBRARY:
fout << "\t$(INSTALL_DATA) " << m_LibraryOutputPath
<< this->GetSafeDefinition("CMAKE_SHARED_MODULE_PREFIX")
<< l->first;
fout << this->GetSafeDefinition("CMAKE_SHARED_MODULE_SUFFIX");
fout << " $(DESTDIR)" << prefix << l->second.GetInstallPath() << "\n";
fname = m_LibraryOutputPath;
fname += this->GetFullTargetName(l->first.c_str(), l->second);
fout << "\t$(INSTALL_DATA) " << cmSystemTools::ConvertToOutputPath(fname.c_str())
<< " \"$(DESTDIR)" << prefix << l->second.GetInstallPath() << "\"\n";
break;
case cmTarget::WIN32_EXECUTABLE:
case cmTarget::EXECUTABLE:
fout << "\t$(INSTALL_PROGRAM) " << m_ExecutableOutputPath
<< l->first
<< cmSystemTools::GetExecutableExtension()
<< " $(DESTDIR)" << prefix << l->second.GetInstallPath() << "\n";
fname = m_ExecutableOutputPath;
fname += this->GetFullTargetName(l->first.c_str(), l->second);
fout << "\t$(INSTALL_PROGRAM) " << cmSystemTools::ConvertToOutputPath(fname.c_str())
<< " \"$(DESTDIR)" << prefix << l->second.GetInstallPath() << "\"\n";
break;
case cmTarget::INSTALL_FILES:
{
@ -2122,8 +2119,9 @@ void cmLocalUnixMakefileGenerator::OutputInstallRules(std::ostream& fout)
{
fout << "\t @$(INSTALL_DATA) ";
}
fout << *i
<< " $(DESTDIR)" << prefix << l->second.GetInstallPath() << "\n";
fout << cmSystemTools::ConvertToOutputPath(i->c_str())
<< " \"$(DESTDIR)" << prefix << l->second.GetInstallPath() << "\"\n";
}
}
break;
@ -2157,8 +2155,8 @@ void cmLocalUnixMakefileGenerator::OutputInstallRules(std::ostream& fout)
{
fout << "\t @$(INSTALL_PROGRAM) ";
}
fout << *i
<< " $(DESTDIR)" << prefix << l->second.GetInstallPath() << "\n";
fout << cmSystemTools::ConvertToOutputPath(i->c_str())
<< " \"$(DESTDIR)" << prefix << l->second.GetInstallPath() << "\"\n";
}
}
break;

View File

@ -196,6 +196,9 @@ protected:
///! for existing files convert to output path and short path if spaces
std::string ConvertToOutputForExisting(const char*);
/** Get the full name of the target's file, without path. */
std::string GetFullTargetName(const char* n, const cmTarget& t);
protected:
int m_MakefileVariableSize;
std::map<cmStdString, cmStdString> m_MakeVariableMap;

View File

@ -113,10 +113,10 @@ else
fi
if [ x"$dir_arg" != x ]; then
dst=$src
dst="$src"
src=""
if [ -d $dst ]; then
if [ -d "$dst" ]; then
instcmd=:
chmodcmd=""
else
@ -128,7 +128,7 @@ else
# might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'.
if [ -f $src -o -d $src ]
if [ -f "$src" -o -d "$src" ]
then
true
else
@ -147,16 +147,16 @@ else
# If destination is a directory, append the input filename; if your system
# does not like double slashes in filenames, you may need to add some logic
if [ -d $dst ]
if [ -d "$dst" ]
then
dst="$dst"/`basename $src`
dst="$dst"/`basename "$src"`
else
true
fi
fi
## this sed command emulates the dirname command
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
# Make sure that the destination directory exists.
# this part is taken from Noah Friedman's mkinstalldirs script
@ -192,42 +192,42 @@ fi
if [ x"$dir_arg" != x ]
then
$doit $instcmd $dst &&
$doit $instcmd "$dst" &&
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dst"; else true ; fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dst"; else true ; fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dst"; else true ; fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dst"; else true ; fi
else
# If we're going to rename the final executable, determine the name now.
if [ x"$transformarg" = x ]
then
dstfile=`basename $dst`
dstfile=`basename "$dst"`
else
dstfile=`basename $dst $transformbasename |
sed $transformarg`$transformbasename
dstfile=`basename "$dst" "$transformbasename" |
sed "$transformarg"`"$transformbasename"
fi
# don't allow the sed command to completely eliminate the filename
if [ x"$dstfile" = x ]
then
dstfile=`basename $dst`
dstfile=`basename "$dst"`
else
true
fi
# Make a temp file name in the proper directory.
dsttmp=$dstdir/#inst.$$#
dsttmp="$dstdir/#inst.$$#"
# Move or copy the file name to the temp name
$doit $instcmd $src $dsttmp &&
$doit $instcmd "$src" "$dsttmp" &&
trap "rm -f ${dsttmp}" 0 &&
trap "rm -f \"${dsttmp}\"" 0 &&
# and set any options; do chmod last to preserve setuid bits
@ -235,15 +235,15 @@ else
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $instcmd $src $dsttmp" command.
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; else true;fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; else true;fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dsttmp"; else true;fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; else true;fi &&
# Now rename the file to the real destination.
$doit $rmcmd -f $dstdir/$dstfile &&
$doit $mvcmd $dsttmp $dstdir/$dstfile
$doit $rmcmd -f "$dstdir/$dstfile" &&
$doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
fi &&