From 889cfc39c73fcd5cc0eac6d3e13c9dca14106fa9 Mon Sep 17 00:00:00 2001 From: stevenknight Date: Fri, 11 Apr 2003 13:55:35 +0000 Subject: [PATCH] Cygwin fixes: use -fPIC and .dll for shared libraries, 'rm' to remove files. (Chad Austin) git-svn-id: http://scons.tigris.org/svn/scons/trunk@640 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/CHANGES.txt | 5 ++++- src/engine/SCons/Platform/win32.py | 15 ++++++++++++++- src/engine/SCons/Tool/ToolTests.py | 1 + src/engine/SCons/Tool/g++.py | 5 ++++- src/engine/SCons/Tool/gcc.py | 5 ++++- src/engine/SCons/Util.py | 11 +++++++++++ src/engine/SCons/UtilTests.py | 8 ++++++++ test/long-lines.py | 2 +- 8 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index d3221ace..83c5613d 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -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. diff --git a/src/engine/SCons/Platform/win32.py b/src/engine/SCons/Platform/win32.py index 3591ac68..4286e246 100644 --- a/src/engine/SCons/Platform/win32.py +++ b/src/engine/SCons/Platform/win32.py @@ -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 diff --git a/src/engine/SCons/Tool/ToolTests.py b/src/engine/SCons/Tool/ToolTests.py index 72aab353..c53ada38 100644 --- a/src/engine/SCons/Tool/ToolTests.py +++ b/src/engine/SCons/Tool/ToolTests.py @@ -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'] diff --git a/src/engine/SCons/Tool/g++.py b/src/engine/SCons/Tool/g++.py index c13f9865..6beca1cf 100644 --- a/src/engine/SCons/Tool/g++.py +++ b/src/engine/SCons/Tool/g++.py @@ -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'] = '' diff --git a/src/engine/SCons/Tool/gcc.py b/src/engine/SCons/Tool/gcc.py index 5b6befa1..5caf1fba 100644 --- a/src/engine/SCons/Tool/gcc.py +++ b/src/engine/SCons/Tool/gcc.py @@ -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' diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index b1a86798..3a9d3b72 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -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() diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py index a1760130..e0788da1 100644 --- a/src/engine/SCons/UtilTests.py +++ b/src/engine/SCons/UtilTests.py @@ -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 """ diff --git a/test/long-lines.py b/test/long-lines.py index cde06837..3999f621 100644 --- a/test/long-lines.py +++ b/test/long-lines.py @@ -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() -- 2.26.2