]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/gcc/mingw-gcc-build.py
BaseTools: Adjust the spaces around commas and colons
[mirror_edk2.git] / BaseTools / gcc / mingw-gcc-build.py
index 0edec75bc4d6cc5862a4a8ff229b5e2f1d2c5209..43f57af9036383026bff42a58c8ed3ac0e965e63 100755 (executable)
@@ -1,11 +1,23 @@
 #!/usr/bin/env python
 
+## @file
 #
 # Automation of instructions from:
 #   http://mingw-w64.svn.sourceforge.net/viewvc/mingw-w64/trunk/mingw-w64-doc/
 #     howto-build/mingw-w64-howto-build.txt?revision=216&view=markup
 #
+# Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution.    The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
 
+
+from __future__ import print_function\r
 from optparse import OptionParser
 import os
 import shutil
@@ -23,7 +35,7 @@ if sys.version_info < (2, 5):
     #
     # This script (and edk2 BaseTools) require Python 2.5 or newer
     #
-    print 'Python version 2.5 or later is required.'
+    print('Python version 2.5 or later is required.')\r
     sys.exit(-1)
 
 #
@@ -31,7 +43,7 @@ if sys.version_info < (2, 5):
 #
 VersionNumber = "0.01"
 __version__ = "%prog Version " + VersionNumber
-__copyright__ = "Copyright (c) 2008, Intel Corporation.  All rights reserved."
+__copyright__ = "Copyright (c) 2008 - 2010, Intel Corporation.  All rights reserved."
 
 class Config:
     """class Config
@@ -81,6 +93,18 @@ class Config:
             default = os.path.join(self.base_dir, 'install'),
             help = "Prefix to install binutils/gcc into"
             )
+        Parser.add_option(
+            "--skip-binutils",
+            action = "store_true", dest = "skip_binutils",
+            default = False,
+            help = "Will skip building binutils"
+            )
+        Parser.add_option(
+            "--skip-gcc",
+            action = "store_true", dest = "skip_gcc",
+            default = False,
+            help = "Will skip building GCC"
+            )
         Parser.add_option(
             "--symlinks",
             action = "store", type = "string", dest = "symlinks",
@@ -116,32 +140,44 @@ class Config:
         self.symlinks = os.path.realpath(os.path.expanduser(self.options.symlinks))
 
     def IsConfigOk(self):
-                
-        print "Current directory:"
-        print "   ", self.base_dir
-        print "Sources download/extraction:", self.Relative(self.src_dir)
-        print "Build directory            :", self.Relative(self.build_dir)
-        print "Prefix (install) directory :", self.Relative(self.prefix)
-        print "Create symlinks directory  :", self.Relative(self.symlinks)
-        print
+
+        building = []
+        if not self.options.skip_binutils:
+            building.append('binutils')
+        if not self.options.skip_gcc:
+            building.append('gcc')
+        if len(building) == 0:
+            print("Nothing will be built!")\r
+            print()\r
+            print("Please try using --help and then change the configuration.")\r
+            return False
+
+        print("Current directory:")\r
+        print("   ", self.base_dir)\r
+        print("Sources download/extraction:", self.Relative(self.src_dir))\r
+        print("Build directory            :", self.Relative(self.build_dir))\r
+        print("Prefix (install) directory :", self.Relative(self.prefix))\r
+        print("Create symlinks directory  :", self.Relative(self.symlinks))\r
+        print("Building                   :", ', '.join(building))\r
+        print()\r
         answer = raw_input("Is this configuration ok? (default = no): ")
         if (answer.lower() not in ('y', 'yes')):
-            print
-            print "Please try using --help and then change the configuration."
+            print()\r
+            print("Please try using --help and then change the configuration.")\r
             return False
 
         if self.arch.lower() == 'ipf':
-            print
-            print 'Please note that the IPF compiler built by this script has'
-            print 'not yet been validated!'
-            print
+            print()\r
+            print('Please note that the IPF compiler built by this script has')\r
+            print('not yet been validated!')\r
+            print()\r
             answer = raw_input("Are you sure you want to build it? (default = no): ")
             if (answer.lower() not in ('y', 'yes')):
-                print
-                print "Please try using --help and then change the configuration."
+                print()\r
+                print("Please try using --help and then change the configuration.")\r
                 return False
 
-        print
+        print()\r
         return True
 
     def Relative(self, path):
@@ -150,7 +186,7 @@ class Config:
         return path
 
     def MakeDirs(self):
-        for path in (self.src_dir, self.build_dir,self.prefix, self.symlinks):
+        for path in (self.src_dir, self.build_dir, self.prefix, self.symlinks):\r
             if not os.path.exists(path):
                 os.makedirs(path)
 
@@ -164,12 +200,19 @@ class SourceFiles:
         self.config = config
         self.source_files = self.source_files[config.arch]
 
+        if config.options.skip_binutils:
+            del self.source_files['binutils']
+
+        if config.options.skip_gcc:
+            del self.source_files['gcc']
+            del self.source_files['mingw_hdr']
+
     source_files_common = {
         'binutils': {
             'url': 'http://www.kernel.org/pub/linux/devel/binutils/' + \
                    'binutils-$version.tar.bz2',
-            'version': '2.18.50.0.5',
-            'md5': 'daee18dbbf0a6ccfc186141bee18bf62',
+            'version': '2.20.51.0.5',
+            'md5': '6d2de7cdf7a8389e70b124e3d73b4d37',
             },
         }
 
@@ -180,27 +223,10 @@ class SourceFiles:
             'version': '4.3.0',
             'md5': '197ed8468b38db1d3481c3111691d85b',
             },
-        'mingw_hdr': {
-            'url': 'http://sourceforge.net/projects/' + \
-                   'mingw-w64/files/mingw-w64/mingw-w64-snapshot/' + \
-                   'mingw-w64-snapshot-$version.tar.bz2/download',
-            'extract-dir': os.path.join('trunk', 'mingw-w64-headers'),
-            'version': '20090419',
-            'md5': '9146ecfabaf172e4cc427b88e8d218c1',
-            },
         }
 
     source_files_ia32 = {
         'gcc': source_files_x64['gcc'],
-        'mingw_hdr': {
-            'url': 'http://sourceforge.net/projects/' + \
-                   'mingw/files/MinGW%20Runtime/' + \
-                   'mingwrt-$version/' + \
-                   'mingwrt-$version-mingw32-src.tar.gz/download',
-            'extract-dir': 'mingwrt-$version-mingw32',
-            'version': '3.15.2',
-            'md5': '7bf0525f158213f3ac990ea68a5ec34d',
-            },
         }
 
     source_files_ipf = source_files_x64.copy()
@@ -250,7 +276,7 @@ class SourceFiles:
             wDots = (100 * received * blockSize) / fileSize / 10
             if wDots > self.dots:
                 for i in range(wDots - self.dots):
-                    print '.',
+                    print('.', end=' ')\r
                     sys.stdout.flush()
                     self.dots += 1
 
@@ -261,18 +287,18 @@ class SourceFiles:
                     self.dots = 0
                     local_file = os.path.join(self.config.src_dir, fdata['filename'])
                     url = fdata['url']
-                   print 'Downloading %s:' % fname,
+                    print('Downloading %s:' % fname, url)\r
                     if retries > 0:
-                        print '(retry)',
+                        print('(retry)', end=' ')\r
                     sys.stdout.flush()
 
                     completed = False
                     if os.path.exists(local_file):
                         md5_pass = self.checkHash(fdata)
                         if md5_pass:
-                            print '[md5 match]',
+                            print('[md5 match]', end=' ')\r
                         else:
-                            print '[md5 mismatch]',
+                            print('[md5 mismatch]', end=' ')\r
                         sys.stdout.flush()
                         completed = md5_pass
 
@@ -288,32 +314,32 @@ class SourceFiles:
                     if not completed and os.path.exists(local_file):
                         md5_pass = self.checkHash(fdata)
                         if md5_pass:
-                            print '[md5 match]',
+                            print('[md5 match]', end=' ')\r
                         else:
-                            print '[md5 mismatch]',
+                            print('[md5 mismatch]', end=' ')\r
                         sys.stdout.flush()
                         completed = md5_pass
 
                     if completed:
-                        print '[done]'
+                        print('[done]')\r
                         break
                     else:
-                        print '[failed]'
-                        print '  Tried to retrieve', url
-                        print '  to', local_file
-                        print 'Possible fixes:'
-                        print '* If you are behind a web-proxy, try setting the',
-                        print 'http_proxy environment variable'
-                        print '* You can try to download this file separately',
-                        print 'and rerun this script'
+                        print('[failed]')\r
+                        print('  Tried to retrieve', url)\r
+                        print('  to', local_file)\r
+                        print('Possible fixes:')\r
+                        print('* If you are behind a web-proxy, try setting the', end=' ')\r
+                        print('http_proxy environment variable')\r
+                        print('* You can try to download this file separately', end=' ')\r
+                        print('and rerun this script')\r
                         raise Exception()
                 
                 except KeyboardInterrupt:
-                    print '[KeyboardInterrupt]'
+                    print('[KeyboardInterrupt]')\r
                     return False
 
-                except:
-                    pass
+                except Exception as e:\r
+                    print(e)\r
 
             if not completed: return False
 
@@ -371,7 +397,7 @@ class Extracter:
             extractedMd5 = open(extracted).read()
 
         if extractedMd5 != moduleMd5:
-            print 'Extracting %s:' % self.config.Relative(local_file)
+            print('Extracting %s:' % self.config.Relative(local_file))\r
             tar = tarfile.open(local_file)
             tar.extractall(extractDst)
             open(extracted, 'w').write(moduleMd5)
@@ -394,10 +420,11 @@ class Builder:
         self.config = config
 
     def Build(self):
-        self.BuildModule('binutils')
-        self.CopyIncludeDirectory()
-        self.BuildModule('gcc')
-        self.MakeSymLinks()
+        if not self.config.options.skip_binutils:
+            self.BuildModule('binutils')
+        if not self.config.options.skip_gcc:
+            self.BuildModule('gcc')
+            self.MakeSymLinks()
 
     def IsBuildStepComplete(self, step):
         return \
@@ -415,24 +442,6 @@ class Builder:
             "w"
             ).close()
 
-    def CopyIncludeDirectory(self):
-        linkdst = os.path.join(self.config.prefix, 'mingw')
-        src = os.path.join(
-            self.config.src_dir,
-            self.config.arch,
-            self.source_files.GetExtractDirOf('mingw_hdr'),
-            'include'
-            )
-        dst_parent = os.path.join(self.config.prefix, self.config.target_combo)
-        dst = os.path.join(dst_parent, 'include')
-        if not os.path.exists(dst):
-            if not os.path.exists(dst_parent):
-                os.makedirs(dst_parent)
-            print 'Copying headers to', self.config.Relative(dst)
-            shutil.copytree(src, dst, True)
-        if not os.path.lexists(linkdst):
-            print 'Making symlink at', self.config.Relative(linkdst)
-            os.symlink(self.config.target_combo, linkdst)
 
     def BuildModule(self, module):
         base_dir = os.getcwd()
@@ -472,7 +481,7 @@ class Builder:
 
         os.chdir(base_dir)
 
-        print '%s module is now built and installed' % module
+        print('%s module is now built and installed' % module)\r
 
     def RunCommand(self, cmd, module, stage, skipable=False):
         if skipable:
@@ -487,21 +496,21 @@ class Builder:
                 stderr=subprocess.STDOUT
                 )
 
-        print '%s [%s] ...' % (module, stage),
+        print('%s [%s] ...' % (module, stage), end=' ')\r
         sys.stdout.flush()
         p = popen(cmd)
         output = p.stdout.read()
         p.wait()
         if p.returncode != 0:
-            print '[failed!]'
+            print('[failed!]')\r
             logFile = os.path.join(self.config.build_dir, 'log.txt')
             f = open(logFile, "w")
             f.write(output)
             f.close()
-            raise Exception, 'Failed to %s %s\n' % (stage, module) + \
-                'See output log at %s' % self.config.Relative(logFile)
+            raise Exception('Failed to %s %s\n' % (stage, module) + \\r
+                'See output log at %s' % self.config.Relative(logFile))\r
         else:
-            print '[done]'
+            print('[done]')\r
 
         if skipable:
             self.MarkBuildStepComplete('%s.%s' % (module, stage))
@@ -518,13 +527,13 @@ class Builder:
             linkdst = os.path.join(links_dir, link)
             if not os.path.lexists(linkdst):
                 if not startPrinted:
-                    print 'Making symlinks in %s:' % self.config.Relative(links_dir),
+                    print('Making symlinks in %s:' % self.config.Relative(links_dir), end=' ')\r
                     startPrinted = True
-                print link,
+                print(link, end=' ')\r
                 os.symlink(src, linkdst)
 
         if startPrinted:
-            print '[done]'
+            print('[done]')\r
 
 class App:
     """class App
@@ -543,9 +552,9 @@ class App:
         sources = SourceFiles(config)
         result = sources.GetAll()
         if result:
-            print 'All files have been downloaded & verified'
+            print('All files have been downloaded & verified')\r
         else:
-            print 'An error occured while downloading a file'
+            print('An error occured while downloading a file')\r
             return
 
         Extracter(sources, config).ExtractAll()