Quellcode durchsuchen

ENH: Support for spaces in paths during make install.

Brad King vor 23 Jahren
Ursprung
Commit
5bb1a79c9f
3 geänderte Dateien mit 98 neuen und 97 gelöschten Zeilen
  1. 71 73
      Source/cmLocalUnixMakefileGenerator.cxx
  2. 3 0
      Source/cmLocalUnixMakefileGenerator.h
  3. 24 24
      Templates/install-sh

+ 71 - 73
Source/cmLocalUnixMakefileGenerator.cxx

@@ -319,7 +319,50 @@ std::string cmLocalUnixMakefileGenerator::GetOutputExtension(const char*)
 }
 }
 #endif
 #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
 // Output the rules for any targets
 void cmLocalUnixMakefileGenerator::OutputTargetRules(std::ostream& fout)
 void cmLocalUnixMakefileGenerator::OutputTargetRules(std::ostream& fout)
@@ -333,47 +376,12 @@ void cmLocalUnixMakefileGenerator::OutputTargetRules(std::ostream& fout)
     {
     {
     if (l->second.IsInAll())
     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" 
         fout << " \\\n" 
              << cmSystemTools::ConvertToOutputPath(path.c_str());
              << cmSystemTools::ConvertToOutputPath(path.c_str());
         }
         }
@@ -387,8 +395,8 @@ void cmLocalUnixMakefileGenerator::OutputTargetRules(std::ostream& fout)
          l->second.GetType() == cmTarget::WIN32_EXECUTABLE) &&
          l->second.GetType() == cmTarget::WIN32_EXECUTABLE) &&
         l->second.IsInAll())
         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());
       fout << " \\\n" << cmSystemTools::ConvertToOutputPath(path.c_str());
       }
       }
     }
     }
@@ -2052,45 +2060,34 @@ void cmLocalUnixMakefileGenerator::OutputInstallRules(std::ostream& fout)
     if (l->second.GetInstallPath() != "")
     if (l->second.GetInstallPath() != "")
       {
       {
       // first make the directories for each target 
       // 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";
         " ] ; then \\\n";
-      fout << "\t   echo \"Making directory $(DESTDIR)" << prefix 
+      fout << "\t   echo \"Making directory \"$(DESTDIR)\"" << prefix 
            << l->second.GetInstallPath() << " \"; \\\n";
            << l->second.GetInstallPath() << " \"; \\\n";
-      fout << "\t   mkdir -p $(DESTDIR)" << prefix << l->second.GetInstallPath() 
+      fout << "\t   mkdir -p \"$(DESTDIR)\"" << prefix << l->second.GetInstallPath() 
            << "; \\\n";
            << "; \\\n";
-      fout << "\t   chmod 755 $(DESTDIR)" <<  prefix << l->second.GetInstallPath() 
+      fout << "\t   chmod 755 \"$(DESTDIR)\"" <<  prefix << l->second.GetInstallPath() 
            << "; \\\n";
            << "; \\\n";
       fout << "\t else true; \\\n";
       fout << "\t else true; \\\n";
       fout << "\t fi\n";
       fout << "\t fi\n";
+      std::string fname;
       // now install the target
       // now install the target
       switch (l->second.GetType())
       switch (l->second.GetType())
         {
         {
         case cmTarget::STATIC_LIBRARY:
         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:
         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:
         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;
           break;
         case cmTarget::WIN32_EXECUTABLE:
         case cmTarget::WIN32_EXECUTABLE:
         case cmTarget::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;
           break;
         case cmTarget::INSTALL_FILES:
         case cmTarget::INSTALL_FILES:
           {
           {
@@ -2114,7 +2111,7 @@ void cmLocalUnixMakefileGenerator::OutputInstallRules(std::ostream& fout)
             fout << "\t@echo \"Installing " << f.c_str() << " \"\n"; 
             fout << "\t@echo \"Installing " << f.c_str() << " \"\n"; 
             // avoid using install-sh to install install-sh
             // avoid using install-sh to install install-sh
             // does not work on windows.... 
             // does not work on windows.... 
-           if(*i == "install-sh")
+            if(*i == "install-sh")
               {
               {
               fout << "\t   @cp ";
               fout << "\t   @cp ";
               }
               }
@@ -2122,8 +2119,9 @@ void cmLocalUnixMakefileGenerator::OutputInstallRules(std::ostream& fout)
               {
               {
               fout << "\t   @$(INSTALL_DATA) ";
               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;
           break;
@@ -2149,7 +2147,7 @@ void cmLocalUnixMakefileGenerator::OutputInstallRules(std::ostream& fout)
             fout << "\t@echo \"Installing " << f.c_str() << " \"\n"; 
             fout << "\t@echo \"Installing " << f.c_str() << " \"\n"; 
             // avoid using install-sh to install install-sh
             // avoid using install-sh to install install-sh
             // does not work on windows.... 
             // does not work on windows.... 
-           if(*i == "install-sh")
+            if(*i == "install-sh")
               {
               {
               fout << "\t   @cp ";
               fout << "\t   @cp ";
               }
               }
@@ -2157,8 +2155,8 @@ void cmLocalUnixMakefileGenerator::OutputInstallRules(std::ostream& fout)
               {
               {
               fout << "\t   @$(INSTALL_PROGRAM) ";
               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;
           break;

+ 3 - 0
Source/cmLocalUnixMakefileGenerator.h

@@ -196,6 +196,9 @@ protected:
 
 
   ///! for existing files convert to output path and short path if spaces
   ///! for existing files convert to output path and short path if spaces
   std::string ConvertToOutputForExisting(const char*);
   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:
 protected:
   int m_MakefileVariableSize;
   int m_MakefileVariableSize;
   std::map<cmStdString, cmStdString> m_MakeVariableMap;
   std::map<cmStdString, cmStdString> m_MakeVariableMap;

+ 24 - 24
Templates/install-sh

@@ -113,10 +113,10 @@ else
 fi
 fi
 
 
 if [ x"$dir_arg" != x ]; then
 if [ x"$dir_arg" != x ]; then
-	dst=$src
+	dst="$src"
 	src=""
 	src=""
 	
 	
-	if [ -d $dst ]; then
+	if [ -d "$dst" ]; then
 		instcmd=:
 		instcmd=:
 		chmodcmd=""
 		chmodcmd=""
 	else
 	else
@@ -128,7 +128,7 @@ else
 # might cause directories to be created, which would be especially bad 
 # might cause directories to be created, which would be especially bad 
 # if $src (and thus $dsttmp) contains '*'.
 # if $src (and thus $dsttmp) contains '*'.
 
 
-	if [ -f $src -o -d $src ]
+	if [ -f "$src" -o -d "$src" ]
 	then
 	then
 		true
 		true
 	else
 	else
@@ -147,16 +147,16 @@ else
 # If destination is a directory, append the input filename; if your system
 # 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
 # does not like double slashes in filenames, you may need to add some logic
 
 
-	if [ -d $dst ]
+	if [ -d "$dst" ]
 	then
 	then
-		dst="$dst"/`basename $src`
+		dst="$dst"/`basename "$src"`
 	else
 	else
 		true
 		true
 	fi
 	fi
 fi
 fi
 
 
 ## this sed command emulates the dirname command
 ## 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.
 # Make sure that the destination directory exists.
 #  this part is taken from Noah Friedman's mkinstalldirs script
 #  this part is taken from Noah Friedman's mkinstalldirs script
@@ -192,42 +192,42 @@ fi
 
 
 if [ x"$dir_arg" != x ]
 if [ x"$dir_arg" != x ]
 then
 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
 else
 
 
 # If we're going to rename the final executable, determine the name now.
 # If we're going to rename the final executable, determine the name now.
 
 
 	if [ x"$transformarg" = x ] 
 	if [ x"$transformarg" = x ] 
 	then
 	then
-		dstfile=`basename $dst`
+		dstfile=`basename "$dst"`
 	else
 	else
-		dstfile=`basename $dst $transformbasename | 
-			sed $transformarg`$transformbasename
+		dstfile=`basename "$dst" "$transformbasename" | 
+			sed "$transformarg"`"$transformbasename"
 	fi
 	fi
 
 
 # don't allow the sed command to completely eliminate the filename
 # don't allow the sed command to completely eliminate the filename
 
 
 	if [ x"$dstfile" = x ] 
 	if [ x"$dstfile" = x ] 
 	then
 	then
-		dstfile=`basename $dst`
+		dstfile=`basename "$dst"`
 	else
 	else
 		true
 		true
 	fi
 	fi
 
 
 # Make a temp file name in the proper directory.
 # 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
 # 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
 # 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
 # ignore errors from any of these, just make sure not to ignore
 # errors from the above "$doit $instcmd $src $dsttmp" command.
 # 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.
 # 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 &&
 fi &&