mailr23638 - /trunk/sconstruct


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on June 04, 2014 - 18:05:
Author: bugman
Date: Wed Jun  4 18:05:35 2014
New Revision: 23638

URL: http://svn.gna.org/viewcvs/relax?rev=23638&view=rev
Log:
Large improvements for the detection of cross-compilation on Mac OS X systems.

The tests for different architecture support now follows the ideas discussed 
in the post
http://thread.gmane.org/gmane.science.nmr.relax.devel/5785/focus=5820.

In summary, for each architecture a simple C file is created, compiled with 
'gcc -arch xyz', and the
resultant binary file tested.  To support 64-bit compilation on 32-bit 
systems, all previously
successful architectures are also included in the gcc command.

The change allows the 'ppc64' architecture to be reintroduced.


Modified:
    trunk/sconstruct

Modified: trunk/sconstruct
URL: 
http://svn.gna.org/viewcvs/relax/trunk/sconstruct?rev=23638&r1=23637&r2=23638&view=diff
==============================================================================
--- trunk/sconstruct    (original)
+++ trunk/sconstruct    Wed Jun  4 18:05:35 2014
@@ -4,7 +4,7 @@
 
 
###############################################################################
 #                                                                            
 #
-# Copyright (C) 2006-2013 Edward d'Auvergne                                  
 #
+# Copyright (C) 2006-2014 Edward d'Auvergne                                  
 #
 #                                                                            
 #
 # This file is part of the program relax (http://www.nmr-relax.com).         
 #
 #                                                                            
 #
@@ -25,12 +25,13 @@
 
 
 # Import statements.
-from os import getcwd, path, remove, rmdir, sep, walk
+from os import F_OK, access, getcwd, path, remove, rmdir, sep, walk
 import platform
 from re import search
 from shutil import rmtree
 from subprocess import PIPE, Popen
 import sys
+from tempfile import mkdtemp
 
 # Scons modules.
 from scons.distrib import package, gpg_sign
@@ -449,22 +450,58 @@
         @rtype:     list of str
         """
 
+        # Printout.
+        print("\nDetermining which architectures can be cross compiled for.")
+
+        # Create a temporary directory for compilation tests.
+        tempdir = mkdtemp()
+
         # The list of archectures to try.
-        archs = ['i386', 'ppc', 'x86_64']
+        archs = ['i386', 'ppc', 'x86_64', 'ppc64']
         allowed = []
 
-        # Loop over each arch and test it.
-        for arch in archs:
-            # Run gcc.
-            pipe = Popen('gcc -arch %s' % arch, shell=True, stdin=PIPE, 
stdout=PIPE, stderr=PIPE, close_fds=False)
-
-            # Loop over the error lines.
-            for line in pipe.stderr.readlines():
-                # Successful arch.
-                if search("no input files", line):
-                    allowed.append(arch)
+        # Safely loop over each arch and test it.
+        try:
+            for arch in archs:
+                # Create a C file to compile.
+                base_name = tempdir + sep + 'test'
+                file = open(base_name + '.c', 'w')
+                file.write("#include<stdio.h>\n\n")
+                file.write("main() {\n")
+                file.write("    printf(\"Compilation with arch '%s' 
successful.\\n\");\n" % arch)
+                file.write("}\n")
+                file.close()
+
+                # Run gcc.
+                arch_test = ''
+                for name in allowed:
+                    arch_test += '-arch %s ' % name
+                pipe = Popen('gcc %s -arch %s %s.c -o %s' % (arch_test, 
arch, base_name, base_name), shell=True, stdin=PIPE, stdout=PIPE, 
stderr=PIPE, close_fds=False)
+                for line in pipe.stdout.readlines():
+                    pass
+
+                # Execute the file.
+                pipe = Popen('%s' % base_name, shell=True, stdin=PIPE, 
stdout=PIPE, stderr=PIPE, close_fds=False)
+
+                # Check the output.
+                for line in pipe.stdout.readlines():
+                    # Printout.
+                    print("    %s" % line[:-1])
+
+                    # Successful arch.
+                    if search("successful", line):
+                        allowed.append(arch)
+
+                # Delete the compiled file, if it exists.
+                if access(base_name, F_OK):
+                    remove(base_name)
+
+        # Clean up.
+        finally:
+            rmtree(tempdir)
 
         # Return the list.
+        print("\n")
         return allowed
 
 
@@ -542,8 +579,9 @@
         # Relaxation curve fitting build environment.
         env = Environment()
 
-        # Determine the build architectures.
-        archs = self.det_arch()
+        # Determine the cross-compilation architectures for Mac systems.
+        if env['PLATFORM'] == 'darwin':
+            archs = self.det_arch()
 
         # C flags.
         if SYSTEM == 'Windows':




Related Messages


Powered by MHonArc, Updated Wed Jun 04 18:40:02 2014