diff --git a/Source/cmLocalUnixMakefileGenerator.cxx b/Source/cmLocalUnixMakefileGenerator.cxx index 9da1eaf53..781064eab 100644 --- a/Source/cmLocalUnixMakefileGenerator.cxx +++ b/Source/cmLocalUnixMakefileGenerator.cxx @@ -319,7 +319,50 @@ std::string cmLocalUnixMakefileGenerator::GetOutputExtension(const char*) } #endif - +std::string cmLocalUnixMakefileGenerator::GetFullTargetName(const char* n, + const cmTarget& t) +{ + const char* targetPrefix = t.GetProperty("PREFIX"); + const char* targetSuffix = t.GetProperty("SUFFIX"); + const char* prefixVar = 0; + const char* suffixVar = 0; + switch(t.GetType()) + { + case cmTarget::STATIC_LIBRARY: + prefixVar = "CMAKE_STATIC_LIBRARY_PREFIX"; + suffixVar = "CMAKE_STATIC_LIBRARY_SUFFIX"; + break; + case cmTarget::SHARED_LIBRARY: + prefixVar = "CMAKE_SHARED_LIBRARY_PREFIX"; + suffixVar = "CMAKE_SHARED_LIBRARY_SUFFIX"; + break; + case cmTarget::MODULE_LIBRARY: + prefixVar = "CMAKE_SHARED_MODULE_PREFIX"; + suffixVar = "CMAKE_SHARED_MODULE_SUFFIX"; + break; + case cmTarget::EXECUTABLE: + case cmTarget::WIN32_EXECUTABLE: + targetSuffix = cmSystemTools::GetExecutableExtension(); + case cmTarget::UTILITY: + case cmTarget::INSTALL_FILES: + case cmTarget::INSTALL_PROGRAMS: + break; + } + // if there is no prefix on the target use the cmake definition + if(!targetPrefix && prefixVar) + { + targetPrefix = this->GetSafeDefinition(prefixVar); + } + // if there is no suffix on the target use the cmake definition + if(!targetSuffix && suffixVar) + { + targetSuffix = this->GetSafeDefinition(suffixVar); + } + std::string name = targetPrefix?targetPrefix:""; + name += n; + name += targetSuffix?targetSuffix:""; + return name; +} // Output the rules for any targets void cmLocalUnixMakefileGenerator::OutputTargetRules(std::ostream& fout) @@ -333,47 +376,12 @@ void cmLocalUnixMakefileGenerator::OutputTargetRules(std::ostream& fout) { 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* prefixVar = 0; - const char* suffixVar = 0; - switch(l->second.GetType()) + if((l->second.GetType() == cmTarget::STATIC_LIBRARY) || + (l->second.GetType() == cmTarget::SHARED_LIBRARY) || + (l->second.GetType() == cmTarget::MODULE_LIBRARY)) { - case cmTarget::STATIC_LIBRARY: - prefixVar = "CMAKE_STATIC_LIBRARY_PREFIX"; - suffixVar = "CMAKE_STATIC_LIBRARY_SUFFIX"; - break; - case cmTarget::SHARED_LIBRARY: - prefixVar = "CMAKE_SHARED_LIBRARY_PREFIX"; - suffixVar = "CMAKE_SHARED_LIBRARY_SUFFIX"; - break; - case cmTarget::MODULE_LIBRARY: - prefixVar = "CMAKE_SHARED_MODULE_PREFIX"; - suffixVar = "CMAKE_SHARED_MODULE_SUFFIX"; - break; - case cmTarget::EXECUTABLE: - case cmTarget::WIN32_EXECUTABLE: - 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) - { - targetPrefix = this->GetSafeDefinition(prefixVar); - } - // if there is no suffix on the target use the cmake definition - if(!targetSuffix) - { - targetSuffix = this->GetSafeDefinition(suffixVar); - } - path += - targetPrefix + l->first + targetSuffix; + 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: { @@ -2114,7 +2111,7 @@ void cmLocalUnixMakefileGenerator::OutputInstallRules(std::ostream& fout) fout << "\t@echo \"Installing " << f.c_str() << " \"\n"; // avoid using install-sh to install install-sh // does not work on windows.... - if(*i == "install-sh") + if(*i == "install-sh") { fout << "\t @cp "; } @@ -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; @@ -2149,7 +2147,7 @@ void cmLocalUnixMakefileGenerator::OutputInstallRules(std::ostream& fout) fout << "\t@echo \"Installing " << f.c_str() << " \"\n"; // avoid using install-sh to install install-sh // does not work on windows.... - if(*i == "install-sh") + if(*i == "install-sh") { fout << "\t @cp "; } @@ -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; diff --git a/Source/cmLocalUnixMakefileGenerator.h b/Source/cmLocalUnixMakefileGenerator.h index 7ba859887..f3ebd9e2d 100644 --- a/Source/cmLocalUnixMakefileGenerator.h +++ b/Source/cmLocalUnixMakefileGenerator.h @@ -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 m_MakeVariableMap; diff --git a/Templates/install-sh b/Templates/install-sh index e9de23842..f90a48ca6 100755 --- a/Templates/install-sh +++ b/Templates/install-sh @@ -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 &&