1. SCons
  2. Core
  3. SCons

Commits

Steven Knight  committed 8711d2a

Make shared/static objects less irritating. (Anthony Roach)

  • Participants
  • Parent commits 42811ac
  • Branches default

Comments (0)

Files changed (10)

File doc/man/scons.1

View file
 .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

File src/CHANGES.txt

View file
   - 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

File src/RELEASE.txt

View file
   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
     - 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

File src/engine/SCons/Defaults.py

View file
             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)

File src/engine/SCons/Tool/gcc.py

View file
     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'
 

File src/engine/SCons/Tool/mingw.py

View file
     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'] = ''

File src/engine/SCons/Tool/msvc.py

View file
     env['INCPREFIX']  = '/I'
     env['INCSUFFIX']  = ''
     env['OBJEMITTER'] = object_emitter
+    env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
 
     env['RC'] = 'rc'
     env['RCFLAGS'] = ''

File test/SHF77.py

View file
 if sys.platform == 'win32':
     _obj = '.obj'
 else:
-    _obj = '.o'
+    _obj = '.os'
 
 test = TestSCons.TestSCons()
 

File test/SHF77FLAGS.py

View file
 if sys.platform == 'win32':
     _obj = '.obj'
 else:
-    _obj = '.o'
+    _obj = '.os'
 
 test = TestSCons.TestSCons()
 

File test/SharedLibrary.py

View file
 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')
 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