Index: ChangeLog
===================================================================
--- ChangeLog	(revision 31d4e80320e31e79cde433f7f0de6d9172796cf8)
+++ ChangeLog	(revision faa8181015925ed91f39ea458636d41f12e2cf25)
@@ -1,2 +1,30 @@
+2011-02-22	Chris Johns <chrisj@rtems.org>
+
+	* specbuilder/sb-versions, specbuilder/specbuilder/version.py:
+	New. Print a suitable version message for automatic documentation
+	updating from the spec files in CVS.
+
+	* specbuilder/specbuilder/build.py: Add xz support. Add a function
+	to return the name of a package.
+	
+	* specbuilder/specbuilder/crossgcc.py: Use the build name in the
+	tmp path.
+	
+	* specbuilder/specbuilder/darwin.py: Add xz support.
+	
+	* specbuilder/specbuilder/defaults.py: Add xz support. Add Windows
+	and Linux support.
+	
+	* specbuilder/specbuilder/setup.py: Reference the correct shell
+	opts. Use the shell setup in the version probe command. Fix the
+	version check. Add autotools to the list of spec files to
+	install.
+	
+	* specbuilder/specbuilder/spec.py: Add changelog and configure
+	tests. Manage sub-packages better.
+	
+	* specbuilder/specbuilder/version.py,
+	specbuilder/specbuilder/windows.py: New.
+
 2010-08-31	Chris Johns <chrisj@rtems.org>
 
Index: specbuilder/sb-versions
===================================================================
--- specbuilder/sb-versions	(revision faa8181015925ed91f39ea458636d41f12e2cf25)
+++ specbuilder/sb-versions	(revision faa8181015925ed91f39ea458636d41f12e2cf25)
@@ -0,0 +1,33 @@
+#! /usr/bin/env python
+#
+# $Id$
+#
+# RTEMS Tools Project (http://www.rtems.org/)
+# Copyright 2010 Chris Johns (chrisj@rtems.org)
+# All rights reserved.
+#
+# This file is part of the RTEMS Tools package in 'rtems-tools'.
+#
+# RTEMS Tools is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# RTEMS Tools is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with RTEMS Tools.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+import sys, os
+base = os.path.dirname(sys.argv[0])
+sys.path.insert(0, base + '/specbuilder')
+try:
+    import version
+    version.run()
+except ImportError:
+    print >> sys.stderr, "Incorrect SpecBulder installation"
+    sys.exit(1)
Index: specbuilder/specbuilder/build.py
===================================================================
--- specbuilder/specbuilder/build.py	(revision 31d4e80320e31e79cde433f7f0de6d9172796cf8)
+++ specbuilder/specbuilder/build.py	(revision faa8181015925ed91f39ea458636d41f12e2cf25)
@@ -191,4 +191,6 @@
         elif esl[-1:][0] == 'bz2':
             source['compressed'] = '%{__zip} -u'
+        elif esl[-1:][0] == 'xz':
+            source['compressed'] = '%{__xz} -dc'
         source['script'] = ''
         return source
@@ -390,4 +392,9 @@
             self.cleanup()
 
+    def name(self):
+        packages = self.spec.packages()
+        package = packages['main']
+        return package.name() + '-' + package.version()
+
 def run(args):
     try:
Index: specbuilder/specbuilder/crossgcc.py
===================================================================
--- specbuilder/specbuilder/crossgcc.py	(revision 31d4e80320e31e79cde433f7f0de6d9172796cf8)
+++ specbuilder/specbuilder/crossgcc.py	(revision faa8181015925ed91f39ea458636d41f12e2cf25)
@@ -73,6 +73,6 @@
 
     def first_package(self, _build):
-        path = os.path.join(_build.spec.abspath('%{_tmppath}'),
-                            _build.spec.expand('crossgcc-%(%{__id_u} -n)'))
+        what = _build.spec.expand('crossgcc-%(%{__id_u} -n)-' + _build.name())
+        path = os.path.join(_build.spec.abspath('%{_tmppath}'), what)
         _build.rmdir(path)
         _build.mkdir(path)
Index: specbuilder/specbuilder/darwin.py
===================================================================
--- specbuilder/specbuilder/darwin.py	(revision 31d4e80320e31e79cde433f7f0de6d9172796cf8)
+++ specbuilder/specbuilder/darwin.py	(revision faa8181015925ed91f39ea458636d41f12e2cf25)
@@ -52,5 +52,6 @@
         '_var':                    '/opt/local/var',
         'optflags':                '-O2 -fasynchronous-unwind-tables',
-        '_smp_mflags':             smp_mflags
+        '_smp_mflags':             smp_mflags,
+        '__xz':                    '/usr/local/bin/xz',
         }
     return defines
Index: specbuilder/specbuilder/defaults.py
===================================================================
--- specbuilder/specbuilder/defaults.py	(revision 31d4e80320e31e79cde433f7f0de6d9172796cf8)
+++ specbuilder/specbuilder/defaults.py	(revision faa8181015925ed91f39ea458636d41f12e2cf25)
@@ -136,4 +136,5 @@
 '__tar_extract':       '%{__tar} -xvvf',
 '__unzip':             '/usr/bin/unzip',
+'__xz':                '/usr/bin/xz',
 '_datadir':            '%{_prefix}/share',
 '_defaultdocdir':      '%{_prefix}/share/doc',
@@ -416,11 +417,15 @@
     d = defaults
     overrides = None
-    uname = os.uname()
-    if uname[0] == 'Darwin':
-        import darwin
-        overrides = darwin.load()
-    elif uname[0] == 'Linux':
-        import linux 
-        overrides = linux.load()
+    if os.name == 'nt':
+        import windows
+        overrides = windows.load()
+    else:
+        uname = os.uname()
+        if uname[0] == 'Darwin':
+            import darwin
+            overrides = darwin.load()
+        elif uname[0] == 'Linux':
+            import linux 
+            overrides = linux.load()
     if overrides is None:
         raise error.general('no hosts defaults found; please add')
@@ -452,2 +457,4 @@
     sys.exit(0)
 
+
+
Index: specbuilder/specbuilder/setup.py
===================================================================
--- specbuilder/specbuilder/setup.py	(revision 31d4e80320e31e79cde433f7f0de6d9172796cf8)
+++ specbuilder/specbuilder/setup.py	(revision faa8181015925ed91f39ea458636d41f12e2cf25)
@@ -89,5 +89,6 @@
     def run(self, command, shell_opts = '', cwd = None):
         e = execute.capture_execution(log = log.default, dump = self.opts.quiet())
-        cmd = self.opts.expand('%{__setup_shell} -ex ' + shell_opts + ' ' + command, self.defaults)
+        cmd = self.opts.expand('%{___setup_shell} -ex ' + \
+                                   shell_opts + ' ' + command, self.defaults)
         self._output('run: ' + cmd)
         exit_code, proc, output = e.shell(cmd, cwd = cwd)
@@ -97,17 +98,20 @@
     def check_version(self, cmd, macro):
         vcmd = cmd + ' --version'
+        vcmd = self.opts.expand('%{___setup_shell} -e ' + vcmd, self.defaults)        
         e = execute.capture_execution()
         exit_code, proc, output = e.shell(vcmd)
         if exit_code != 0 and len(output) != 0:
             raise error.general('shell cmd failed: ' + vcmd)
-        version = output.split('\n')[0].split(' ')
+        version = output.split('\n')[0].split(' ')[-1:][0]
         need = self.opts.expand(macro, self.defaults)
         if version < need:
-            _notice(self.opts, 'warning: ' + cmd + ' version is invalid, need ' + need + ' or higher')
+            _notice(self.opts, 'warning: ' + cmd + \
+                        ' version is invalid, need ' + need + ' or higher, found ' + version)
             return False
         return True
 
     def get_specs(self, path):
-        return self._get_file_list(path, 'rtems', 'spec')
+        return self._get_file_list(path, 'autotools', 'spec') + \
+            self._get_file_list(path, 'rtems', 'spec')
 
     def get_patches(self, path):
@@ -128,5 +132,5 @@
                 self.mkdir(dst)
             except os.error, oerr:
-                if oerr[0] != errno.EEXIST:
+                if oerr[0] != errno.EEXIST and oerr[0] != 183:
                     raise error.general('OS error: ' + str(oerr))
             if d == 'RPMLIB':
@@ -142,5 +146,5 @@
             if not os.path.isdir(crossrpms):
                 raise error.general('no crossrpms directory found under: ' + crossrpms)
-            if 'rebuild' in self.opts.opts:
+            if self.opts.rebuild():
                 if self.check_version('autoconf', '%{__setup_autoconf}'):
                     self.run('../../bootstrap -c', '-c', crossrpms)
@@ -174,2 +178,4 @@
 if __name__ == "__main__":
     run()
+
+
Index: specbuilder/specbuilder/spec.py
===================================================================
--- specbuilder/specbuilder/spec.py	(revision 31d4e80320e31e79cde433f7f0de6d9172796cf8)
+++ specbuilder/specbuilder/spec.py	(revision faa8181015925ed91f39ea458636d41f12e2cf25)
@@ -77,5 +77,9 @@
         for i in self.infos:
             il = i.lower()
-            if il.startswith(label) and il[len(label):].isdigit():
+            if il.startswith(label):
+                if il == label:
+                    il = label + '0'
+                elif not il[len(label):].isdigit():
+                    continue
                 infos[il] = self.infos[i]
         return infos
@@ -147,4 +151,5 @@
 
     _directive = [ '%description',
+                   '%changelog',
                    '%prep',
                    '%build',
@@ -157,4 +162,5 @@
 
     _ignore = [ re.compile('%setup'),
+                re.compile('%configure'),
                 re.compile('%doc'),
                 re.compile('%dir'),
@@ -610,13 +616,5 @@
                         for d in self._directive:
                             if ls[0].strip() == d:
-                                if len(ls) == 1:
-                                    package = 'main'
-                                elif len(ls) == 2:
-                                    package = ls[1].strip()
-                                else:
-                                    if ls[1].strip() != '-n':
-                                        self._warning("unknown directive option: '" + ls[1] + "'")
-                                    package = ls[2].strip()
-                                return ('directive', ls[0].strip(), package)
+                                return ('directive', ls[0].strip(), ls[1:])
                         self._warning("unknown directive: '" + ls[0] + "'")
                         return ('data', [l])
@@ -680,9 +678,21 @@
                     self._warning("unexpected '" + r[1] + "'")
                 elif r[0] == 'directive':
-                    self._set_package(r[2])
+                    new_data = []
+                    if r[1] == '%description':
+                        new_data = [' '.join(r[2])]
+                    else:
+                        if len(r[2]) == 0:
+                            _package = 'main'
+                        elif len(r[2]) == 1:
+                            _package = r[2][0]
+                        else:
+                            if r[2][0].strip() != '-n':
+                                self._warning("unknown directive option: '" + ' '.join(r[2]) + "'")
+                            _package = r[2][1].strip()
+                        self._set_package(_package)
                     if dir and dir != r[1]:
                         self._directive_extend(dir, data)
                     dir = r[1]
-                    data = []
+                    data = new_data
                 elif r[0] == 'data':
                     for l in r[1]:
Index: specbuilder/specbuilder/version.py
===================================================================
--- specbuilder/specbuilder/version.py	(revision faa8181015925ed91f39ea458636d41f12e2cf25)
+++ specbuilder/specbuilder/version.py	(revision faa8181015925ed91f39ea458636d41f12e2cf25)
@@ -0,0 +1,95 @@
+#
+# $Id$
+#
+# RTEMS Tools Project (http://www.rtems.org/)
+# Copyright 2010 Chris Johns (chrisj@rtems.org)
+# All rights reserved.
+#
+# This file is part of the RTEMS Tools package in 'rtems-tools'.
+#
+# RTEMS Tools is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# RTEMS Tools is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with RTEMS Tools.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+#
+# Extract the status of the spec files found in the SPECS directory.
+# The status is the name, source and patches.
+#
+
+import os
+
+import defaults
+import error
+import spec
+
+class versions:
+    """Return the versions of packages given a spec file."""
+
+    def __init__(self, name, _defaults, opts):
+        self.opts = opts
+        self.spec = spec.file(name, _defaults = _defaults, opts = opts)
+
+    def __str__(self):
+
+        def str_package(package):
+            sources = package.sources()
+            patches = package.patches()
+            version = package.version()
+            release = package.release()
+            buildarch = package.buildarch()
+            s = '\nNAME="' + package.name() + '"'
+            if buildarch:
+                s += '\nARCH="' + buildarch + '"'
+            if version:
+                s += '\nVERSION="' + version + '"'
+            if release:
+                s += '\nRELEASE="' + release + '"'
+            if len(sources):
+                s += '\nSOURCES=%d' % (len(sources))
+                c = 1
+                for i in sources:
+                    s += '\nSOURCE%d="' % (c) + sources[i][0] + '"'
+                    c += 1
+                s += '\nPATCHES=%d' % (len(patches))
+                c = 1
+                for i in patches:
+                    s += '\nPATCH%d="' % (c) + patches[i][0] + '"'
+                    c += 1
+            return s
+
+        packages = self.spec.packages()
+        s = 'SPEC=' + os.path.basename(self.spec.name) + \
+            str_package(packages['main'])
+        for p in packages:
+            if p != 'main':
+                s += str_package(packages[p])
+        return s + '\n'
+
+def run():
+    import sys
+    try:
+        opts, _defaults = defaults.load(sys.argv)
+        for spec_file in opts.spec_files():
+            s = versions(spec_file, _defaults = _defaults, opts = opts)
+            print s
+            del s
+    except error.general, gerr:
+        print gerr
+        sys.exit(1)
+    except error.internal, ierr:
+        print ierr
+        sys.exit(1)
+    sys.exit(0)
+
+if __name__ == "__main__":
+    run()
Index: specbuilder/specbuilder/windows.py
===================================================================
--- specbuilder/specbuilder/windows.py	(revision faa8181015925ed91f39ea458636d41f12e2cf25)
+++ specbuilder/specbuilder/windows.py	(revision faa8181015925ed91f39ea458636d41f12e2cf25)
@@ -0,0 +1,67 @@
+#
+# $Id$
+#
+# RTEMS Tools Project (http://www.rtems.org/)
+# Copyright 2010 Chris Johns (chrisj@rtems.org)
+# All rights reserved.
+#
+# This file is part of the RTEMS Tools package in 'rtems-tools'.
+#
+# RTEMS Tools is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# RTEMS Tools is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with RTEMS Tools.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+#
+# Windows specific support and overrides.
+#
+
+import pprint
+import os
+
+import execute
+
+def load():
+    uname = 'win32'
+    if os.environ.has_key('NUMBER_OF_PROCESSORS'):
+        ncpus = int(os.environ['NUMBER_OF_PROCESSORS'])
+    else:
+        ncpus = 0
+    if ncpus > 1:
+        smp_mflags = '-j' + str(ncpus)
+    else:
+        smp_mflags = ''
+    if os.environ.has_key('HOSTTYPE'):
+        hosttype = os.environ['HOSTTYPE']
+    else:
+        hosttype = 'i686'
+    system = 'mingw32'
+    defines = { 
+        '_os':                     'win32',
+        '_host':                   hosttype + '-pc-' + system,
+        '_host_vendor':            'microsoft',
+        '_host_os':                'win32',
+        '_host_cpu':               hosttype,
+        '_host_alias':             '%{nil}',
+        '_host_arch':              hosttype,
+        '_usr':                    '/opt/local',
+        '_var':                    '/opt/local/var',
+        'optflags':                '-O2 -fasynchronous-unwind-tables',
+        '_smp_mflags':             smp_mflags,
+        '__sh':                    'sh',
+        '_buildshell':             '%{__sh}',
+        '___setup_shell':          '%{__sh}'
+        }
+    return defines
+
+if __name__ == '__main__':
+    pprint.pprint(load())
