Cygwin fixes: use -fPIC and .dll for shared libraries, 'rm' to remove files. (Chad...
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Fri, 11 Apr 2003 13:55:35 +0000 (13:55 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Fri, 11 Apr 2003 13:55:35 +0000 (13:55 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@640 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/CHANGES.txt
src/engine/SCons/Platform/win32.py
src/engine/SCons/Tool/ToolTests.py
src/engine/SCons/Tool/g++.py
src/engine/SCons/Tool/gcc.py
src/engine/SCons/Util.py
src/engine/SCons/UtilTests.py
test/long-lines.py

index d3221acec087db5a28d6ea7b685f60b82ab513b1..83c5613d1d1bfa351f4bbe10bf50612077f319ca 100644 (file)
@@ -12,7 +12,10 @@ RELEASE 0.14 - XXX
 
   From Chad Austin:
 
-  - Use .dll (not .so) for shared libraries on Cygwin.
+  - Use .dll (not .so) for shared libraries on Cygwin; use -fPIC
+    when compiling them.
+
+  - Use 'rm' to remove files under Cygwin.
 
   - Add a PLATFORM variable to construction environments.
 
index 3591ac68f68e8afdc5331e0900452c04ed38fcbd..4286e246c5e36afc2321b2ae9c3adf777895d812 100644 (file)
@@ -58,14 +58,27 @@ class TempFileMunge:
             return self.cmd
         else:
             import tempfile
+
+            # In Cygwin, we want to use rm to delete the temporary file,
+            # because del does not exist in the sh shell.
+            rm = env.Detect('rm') or 'del'
+
             # We do a normpath because mktemp() has what appears to be
             # a bug in Win32 that will use a forward slash as a path
             # delimiter.  Win32's link mistakes that for a command line
             # switch and barfs.
             tmp = os.path.normpath(tempfile.mktemp())
+            native_tmp = SCons.Util.get_native_path(tmp)
+
+            # The sh shell will try to escape the backslashes in the
+            # path, so unescape them.
+            if env['SHELL'] and env['SHELL'] == 'sh':
+                native_tmp = string.replace(native_tmp, '\\', r'\\\\')
+
+
             args = map(SCons.Util.quote_spaces, cmd[1:])
             open(tmp, 'w').write(string.join(args, " ") + "\n")
-            return [ cmd[0], '@' + tmp + '\ndel', tmp ]
+            return [ cmd[0], '@' + native_tmp + '\n' + rm, native_tmp ]
 
 # The upshot of all this is that, if you are using Python 1.5.2,
 # you had better have cmd or command.com in your PATH when you run
index 72aab353974ce82de4c21534104a2e4a4675ca6f..c53ada387b49ebf16951e5f005c57886ae811042 100644 (file)
@@ -46,6 +46,7 @@ class ToolTestCase(unittest.TestCase):
         env = Environment()
         env['BUILDERS'] = {}
         env['ENV'] = {}
+        env['PLATFORM'] = 'test'
         t = SCons.Tool.Tool('g++')
         t(env)
         assert (env['CXX'] == 'c++' or env['CXX'] == 'g++'), env['CXX']
index c13f9865bcfc3b0850c04a3557866c7b315e70f1..6beca1cfc2fe6f5e8d7ce735064e768df776b2b0 100644 (file)
@@ -57,7 +57,10 @@ def generate(env):
     env['CXXFLAGS']   = '$CCFLAGS'
     env['CXXCOM']     = '$CXX $CXXFLAGS $CPPFLAGS $_CPPINCFLAGS -c -o $TARGET $SOURCES'
     env['SHCXX']      = '$CXX'
-    env['SHCXXFLAGS'] = '$CXXFLAGS -fPIC'
+    if env['PLATFORM'] == 'cygwin':
+        env['SHCXXFLAGS'] = '$CXXFLAGS'
+    else:
+        env['SHCXXFLAGS'] = '$CXXFLAGS -fPIC'
     env['SHCXXCOM']   = '$SHCXX $SHCXXFLAGS $CPPFLAGS $_CPPINCFLAGS -c -o $TARGET $SOURCES'
     env['INCPREFIX']  = '-I'
     env['INCSUFFIX']  = ''
index 5b6befa1b32f35e5edcbd400a7471025df21a6a9..5caf1fba9ef2f618843997ab4abac6f8b1f7cdf5 100644 (file)
@@ -57,7 +57,10 @@ def generate(env):
     env['CCFLAGS']   = ''
     env['CCCOM']     = '$CC $CCFLAGS $CPPFLAGS $_CPPINCFLAGS -c -o $TARGET $SOURCES'
     env['SHCC']      = '$CC'
-    env['SHCCFLAGS'] = '$CCFLAGS -fPIC'
+    if env['PLATFORM'] == 'cygwin':
+        env['SHCCFLAGS'] = '$CCFLAGS'
+    else:
+        env['SHCCFLAGS'] = '$CCFLAGS -fPIC'
     env['SHCCCOM']   = '$SHCC $SHCCFLAGS $CPPFLAGS $_CPPINCFLAGS -c -o $TARGET $SOURCES'
     env['SHOBJSUFFIX'] = '.os'
     env['INCPREFIX']  = '-I'
index b1a86798a935a2b5ddc8f2711e462192e58b7e55..3a9d3b729218c436a45d1db9f22d254ae2d316ca 100644 (file)
@@ -854,4 +854,15 @@ def fs_delete(path, remove=1):
     except OSError, e:
         print "scons: Could not remove '%s':" % str(path), e.strerror
 
+if sys.platform == 'cygwin':
+    def get_native_path(path):
+        """Transforms an absolute path into a native path for the system.  In
+        Cygwin, this converts from a Cygwin path to a Win32 one."""
+        return string.replace(os.popen('cygpath -w ' + path).read(), '\n', '')
+else:
+    def get_native_path(path):
+        """Transforms an absolute path into a native path for the system.
+        Non-Cygwin version, just leave the path alone."""
+        return path
+
 display = DisplayEngine()
index a1760130f095f8b621247dad31cfa2e7a9d5e920..e0788da19cac0c9d35b7a88212ddf189c73d78ab 100644 (file)
@@ -644,6 +644,14 @@ class UtilTestCase(unittest.TestCase):
         test._dirlist = None
         sys.stdout = old_stdout
 
+    def test_get_native_path(self):
+        """Test the get_native_path() function."""
+        import tempfile
+        filename = tempfile.mktemp()
+        str = '1234567890 ' + filename
+        open(filename, 'w').write(str)
+        assert open(SCons.Util.get_native_path(filename)).read() == str
+
     def test_subst_dict(self):
         """Test substituting dictionary values in an Action
         """
index cde06837aca4009f3d72df168a183d8d8dea50f7..3999f621f50880bc2988452bb0337eeb7b0a0ab2 100644 (file)
@@ -32,7 +32,7 @@ import TestSCons
 
 test = TestSCons.TestSCons()
 
-if sys.platform == 'win32':
+if sys.platform in ['win32', 'cygwin']:
     lib_static_lib = 'static.lib'
     lib_shared_dll ='shared.dll'
     arflag_init = '/LIBPATH:' + test.workpath()