Index: /pyyaml/trunk/setup.py
===================================================================
--- /pyyaml/trunk/setup.py	(revision 298)
+++ /pyyaml/trunk/setup.py	(revision 301)
@@ -58,4 +58,5 @@
 from distutils.dir_util import mkpath
 from distutils.command.build_ext import build_ext as _build_ext
+from distutils.command.bdist_rpm import bdist_rpm as _bdist_rpm
 from distutils.errors import CompileError, LinkError, DistutilsPlatformError
 
@@ -95,4 +96,20 @@
             self.negative_opt = self.negative_opt.copy()
             self.negative_opt[ext.neg_option_name] = ext.option_name
+
+    def has_ext_modules(self):
+        if not self.ext_modules:
+            return False
+        for ext in self.ext_modules:
+            with_ext = self.ext_status(ext)
+            if with_ext is None or with_ext:
+                return True
+        return False
+
+    def ext_status(self, ext):
+        if isinstance(ext, Extension):
+            with_ext = getattr(self, ext.attr_name)
+            return with_ext
+        else:
+            return True
 
 
@@ -122,12 +139,8 @@
         disabled = True
         for ext in self.extensions:
-            if isinstance(ext, Extension):
-                with_ext = getattr(self.distribution, ext.attr_name)
-                if with_ext is None:
-                    disabled = False
-                elif with_ext:
-                    optional = False
-                    disabled = False
-            else:
+            with_ext = self.distribution.ext_status(ext)
+            if with_ext is None:
+                disabled = False
+            elif with_ext:
                 optional = False
                 disabled = False
@@ -159,13 +172,23 @@
         return filenames
 
+    def get_outputs(self):
+        self.check_extensions_list(self.extensions)
+        outputs = []
+        for ext in self.extensions:
+            fullname = self.get_ext_fullname(ext.name)
+            filename = os.path.join(self.build_lib,
+                                    self.get_ext_filename(fullname))
+            if os.path.isfile(filename):
+                outputs.append(filename)
+        return outputs
+
     def build_extensions(self):
         self.check_extensions_list(self.extensions)
         for ext in self.extensions:
-            if isinstance(ext, Extension):
-                with_ext = getattr(self.distribution, ext.attr_name)
-                if with_ext is None:
-                    with_ext = self.check_extension_availability(ext)
-                if not with_ext:
-                    continue
+            with_ext = self.distribution.ext_status(ext)
+            if with_ext is None:
+                with_ext = self.check_extension_availability(ext)
+            if not with_ext:
+                continue
             if with_pyrex:
                 ext.sources = self.pyrex_sources(ext.sources, ext)
@@ -183,5 +206,5 @@
         src = os.path.join(self.build_temp, 'check_%s.c' % ext.feature_name)
         open(src, 'w').write(ext.feature_check)
-        log.info("checking if %s compiles" % ext.feature_name)
+        log.info("checking if %s is compilable" % ext.feature_name)
         try:
             [obj] = self.compiler.compile([src],
@@ -199,5 +222,5 @@
             return False
         prog = 'check_%s' % ext.feature_name
-        log.info("checking if %s links" % ext.feature_name)
+        log.info("checking if %s is linkable" % ext.feature_name)
         try:
             self.compiler.link_executable([obj], prog,
@@ -219,21 +242,23 @@
 
 
-class test(Command):
-
-    user_options = []
-
-    def initialize_options(self):
-        pass
-
-    def finalize_options(self):
-        pass
-
-    def run(self):
-        build_cmd = self.get_finalized_command('build')
-        build_cmd.run()
-        sys.path.insert(0, build_cmd.build_lib)
-        sys.path.insert(0, 'tests')
-        import test_all
-        test_all.main()
+class bdist_rpm(_bdist_rpm):
+
+    def _make_spec_file(self):
+        argv0 = sys.argv[0]
+        features = []
+        for ext in self.distribution.ext_modules:
+            if not isinstance(ext, Extension):
+                continue
+            with_ext = getattr(self.distribution, ext.attr_name)
+            if with_ext is None:
+                continue
+            if with_ext:
+                features.append('--'+ext.option_name)
+            else:
+                features.append('--'+ext.neg_option_name)
+        sys.argv[0] = ' '.join([argv0]+features)
+        spec_file = _bdist_rpm._make_spec_file(self)
+        sys.argv[0] = argv0
+        return spec_file
 
 
@@ -264,5 +289,5 @@
         cmdclass={
             'build_ext': build_ext,
-#            'test': test,
+            'bdist_rpm': bdist_rpm,
         },
     )
