From e7311129d841fe777bfe2d83c46033f34dac4709 Mon Sep 17 00:00:00 2001 From: Steven Knight Date: Sat, 18 Jan 2003 14:32:51 +0000 Subject: Make shared/static objects less irritating. (Anthony Roach) --- doc/man/scons.1 | 21 ++++++++++++------- src/CHANGES.txt | 8 +++++++ src/RELEASE.txt | 47 +++++++++++------------------------------- src/engine/SCons/Defaults.py | 12 +++++------ src/engine/SCons/Tool/gcc.py | 3 ++- src/engine/SCons/Tool/mingw.py | 2 ++ src/engine/SCons/Tool/msvc.py | 1 + test/SHF77.py | 2 +- test/SHF77FLAGS.py | 2 +- test/SharedLibrary.py | 18 +++++++++------- 10 files changed, 58 insertions(+), 58 deletions(-) diff --git a/doc/man/scons.1 b/doc/man/scons.1 index 441ef00..e01eb1e 100644 --- a/doc/man/scons.1 +++ b/doc/man/scons.1 @@ -988,19 +988,26 @@ env.StaticObject(target = 'ccc.obj', source = 'ccc.f') .EE .IP SharedObject Builds an object file for -inclusion in a shared library -(that is, built with the '-fPIC' option when using gcc). +inclusion in a shared library. Source files must have one of the same set of extensions specified above for the .B StaticObject -builder. -The target shared object file prefix +builder. On some platforms building a shared object requires additional +compiler options (e.g. -fPIC for gcc) in addition to those needed to build a +normal (static) object, but on some platforms there is no difference between a +shared object and a normal (static) one. When there is a difference, SCons +will only allow shared objects to be linked into a shared library, and will +use a different suffix for shared objects. On platforms where there is no +difference, SCons will allow both normal (static) +and shared objects to be linked into a +shared library, and will use the same suffix for shared and normal +(static) objects. +The target object file prefix (specified by the $SHOBJPREFIX construction variable; by default, the same as $OBJPREFIX) and suffix -(specified by the $SHOBJSUFFIX construction variable; -by default, the same as $OBJSUFFIX) -are automatically added to the target if not already present. +(specified by the $SHOBJSUFFIX construction variable) +are automatically added to the target if not already present. Examples: .ES diff --git a/src/CHANGES.txt b/src/CHANGES.txt index eeaaf94..ace0803 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -15,6 +15,14 @@ RELEASE 0.11 - XXX - Allow Python function Actions to specify a list of construction variables that should be included in the Action's signature. + From Anthony Roach: + + - Use a different static object suffix (.os) when using gcc so shared + and static objects can exist side-by-side in the same directory. + + - Allow the same object files on Win32 to be linked into either + shared or static libraries. + RELEASE 0.10 - Thu, 16 Jan 2003 04:11:46 -0600 diff --git a/src/RELEASE.txt b/src/RELEASE.txt index 6319b2e..5a4b5d0 100644 --- a/src/RELEASE.txt +++ b/src/RELEASE.txt @@ -25,6 +25,18 @@ RELEASE 0.10 - Thu, 16 Jan 2003 04:11:46 -0600 This is the tenth alpha release of SCons. Please consult the CHANGES.txt file for a list of specific changes since last release. + Please note the following important changes since release 0.10: + + - The default suffix for shared object files when using gcc has now + been changed to '.os'. This makes library builds more convenient + by allowing both static (compiled without -fPIC) and shared object + files (compiled with -fPIC) to exist side-by-side. If you want to + preserve the old behavior of using .o files for shared objects, + you must now explicitly reset the SHOBJSUFFIX value in your + construction environment as follows: + + env = Environment(SHOBJSUFFIX = '.o') + Please note the following important changes since release 0.09: - The Scanner interface has been changed to make it easier to @@ -67,41 +79,6 @@ RELEASE 0.10 - Thu, 16 Jan 2003 04:11:46 -0600 - SCons now prints a description of Python functions that are invoked to build a target. - Please note the following important changes since release 0.08: - - - The SetCommandHandler() function has been superceded - by the SPAWN, SHELL and ESCAPE construction variables. - - - SCons now exits with an error message if any source files or - implicit dependency files for a target do not exist and have - no Builder. SCons used to ignore these files, so builds that - formally succeeded despite the absence of a scanned file will now - fail unless the -k (keep going on error) flag is used. - - - The specification of the name for the 'lib' tool (the Microsoft - library archiver) has now been changed to 'mslib'. If you - previously used the Tool() method to fetch the 'lib' tool - explicitly, you will need to change the name in the call to - 'mslib': - - env = Environment(tools = [ Tool('mslib') ]) - - - In order to make it clear what SCons is doing when, SCons now - prints explicit messages: - - scons: Reading SConscript files ... - scons: done reading SConscript files. - scons: Building targets ... - scons: done building targets. - - These message might interfere with scripts that examine SCons - output. These messages may be suppressed with the new -Q option. - - - User defined build arguments passed into builder calls are no - longer given to emitters, generators, and function actions as - keyword arguments, but are instead passed as construction - variables. - SCons is developed with an extensive regression test suite, and a rigorous development methodology for continually improving that suite. Because of this, SCons is of sufficient quality that you can use it diff --git a/src/engine/SCons/Defaults.py b/src/engine/SCons/Defaults.py index 364798c..461d770 100644 --- a/src/engine/SCons/Defaults.py +++ b/src/engine/SCons/Defaults.py @@ -102,12 +102,12 @@ class SharedFlagChecker: for tgt in target: tgt.attributes.shared = self.shared - for src in source: - if hasattr(src.attributes, 'shared'): - if self.shared and not src.attributes.shared: - raise SCons.Errors.UserError, "Source file: %s is static and is not compatible with shared target: %s" % (src, target[0]) - elif not self.shared and src.attributes.shared: - raise SCons.Errors.UserError, "Source file: %s is shared and is not compatible with static target: %s" % (src, target[0]) + same = env.subst('$STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME') + if same == '0' or same == '' or same == 'False': + for src in source: + if hasattr(src.attributes, 'shared'): + if self.shared and not src.attributes.shared: + raise SCons.Errors.UserError, "Source file: %s is static and is not compatible with shared target: %s" % (src, target[0]) SharedCheck = SCons.Action.Action(SharedFlagChecker(1, 0), None) StaticCheck = SCons.Action.Action(SharedFlagChecker(0, 0), None) diff --git a/src/engine/SCons/Tool/gcc.py b/src/engine/SCons/Tool/gcc.py index 8649707..677c322 100644 --- a/src/engine/SCons/Tool/gcc.py +++ b/src/engine/SCons/Tool/gcc.py @@ -59,9 +59,10 @@ def generate(env, platform): env['SHCC'] = '$CC' env['SHCCFLAGS'] = '$CCFLAGS -fPIC' env['SHCCCOM'] = '$SHCC $SHCCFLAGS $CPPFLAGS $_CPPINCFLAGS -c -o $TARGET $SOURCES' - + env['SHOBJSUFFIX'] = '.os' env['INCPREFIX'] = '-I' env['INCSUFFIX'] = '' + env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 0 env['CFILESUFFIX'] = '.c' diff --git a/src/engine/SCons/Tool/mingw.py b/src/engine/SCons/Tool/mingw.py index d381910..2e2a2a5 100644 --- a/src/engine/SCons/Tool/mingw.py +++ b/src/engine/SCons/Tool/mingw.py @@ -128,6 +128,8 @@ def generate(env, platform): env['AS'] = 'as' env['WIN32DEFPREFIX'] = '' env['WIN32DEFSUFFIX'] = '.def' + env['SHOBJSUFFIX'] = '.o' + env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1 env['RC'] = 'windres' env['RCFLAGS'] = '' diff --git a/src/engine/SCons/Tool/msvc.py b/src/engine/SCons/Tool/msvc.py index cc4411d..533d84e 100644 --- a/src/engine/SCons/Tool/msvc.py +++ b/src/engine/SCons/Tool/msvc.py @@ -270,6 +270,7 @@ def generate(env, platform): env['INCPREFIX'] = '/I' env['INCSUFFIX'] = '' env['OBJEMITTER'] = object_emitter + env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1 env['RC'] = 'rc' env['RCFLAGS'] = '' diff --git a/test/SHF77.py b/test/SHF77.py index c415fd6..4406b48 100644 --- a/test/SHF77.py +++ b/test/SHF77.py @@ -34,7 +34,7 @@ python = TestSCons.python if sys.platform == 'win32': _obj = '.obj' else: - _obj = '.o' + _obj = '.os' test = TestSCons.TestSCons() diff --git a/test/SHF77FLAGS.py b/test/SHF77FLAGS.py index 5f83109..fa199cc 100644 --- a/test/SHF77FLAGS.py +++ b/test/SHF77FLAGS.py @@ -34,7 +34,7 @@ python = TestSCons.python if sys.platform == 'win32': _obj = '.obj' else: - _obj = '.o' + _obj = '.os' test = TestSCons.TestSCons() diff --git a/test/SharedLibrary.py b/test/SharedLibrary.py index aba088f..79c331c 100644 --- a/test/SharedLibrary.py +++ b/test/SharedLibrary.py @@ -34,10 +34,15 @@ import TestSCons test = TestSCons.TestSCons(match=TestCmd.match_re) test.write('SConstruct', """ +import sys env=Environment(WIN32_INSERT_DEF=1) env2 = Environment(LIBS = [ 'foo1', 'foo2', 'foo3' ], LIBPATH = [ '.' ]) env.SharedLibrary(target = 'foo1', source = 'f1.c') +if sys.platform == 'win32': + env.StaticLibrary(target = 'foo1-static', source = 'f1.c') +else: + env.StaticLibrary(target = 'foo1', source = 'f1.c') env.SharedLibrary(target = 'foo2', source = Split('f2a.c f2b.c f2c.c')) env.SharedLibrary(target = 'foo3', source = ['f3a.c', 'f3b.c', 'f3c.c']) env2.Program(target = 'prog', source = 'prog.c') @@ -191,15 +196,14 @@ if os.name == 'posix': test.run(program = test.workpath('prog'), stdout = "f1.c\nf2a.c\nf2b.c\nf2c.c\nf3a.c\nf3b.c\nf3c.c\nprog.c\n") -test.run(arguments = '-f SConstructFoo', status=2, stderr=''' +if sys.platform == 'win32': + test.run(arguments = '-f SConstructFoo') +else: + test.run(arguments = '-f SConstructFoo', status=2, stderr=''' scons: \*\*\* Source file: foo\..* is static and is not compatible with shared target: .* -''' -) +''') -test.run(arguments = '-f SConstructFoo2', status=2, stderr=''' -scons: \*\*\* Source file: bar\..* is shared and is not compatible with static target: .* -''' -) +test.run(arguments = '-f SConstructFoo2') if sys.platform == 'win32': # Make sure we don't insert a .def source file (when -- cgit v0.12