Author: bugman Date: Wed Jun 13 17:06:56 2012 New Revision: 16900 URL: http://svn.gna.org/viewcvs/relax?rev=16900&view=rev Log: Hack for the relax_fit C module compilation to detect supported CPUs for Mac OS X cross compilation. Modified: trunk/sconstruct Modified: trunk/sconstruct URL: http://svn.gna.org/viewcvs/relax/trunk/sconstruct?rev=16900&r1=16899&r2=16900&view=diff ============================================================================== --- trunk/sconstruct (original) +++ trunk/sconstruct Wed Jun 13 17:06:56 2012 @@ -31,6 +31,7 @@ import platform from re import search from shutil import rmtree +from subprocess import PIPE, Popen import sys # Scons modules. @@ -165,7 +166,7 @@ class Main: def __init__(self): """Initialise the main building targets. - + This function sets up the Scons build Environments, sets custom Builders, sets the build targets, and sets the build dependancies. """ @@ -431,6 +432,32 @@ # Final printout. print("\n\n\n") + + + def det_arch(self): + """Nasty hack to make Scons behave properly with cross-compilation on Mac OS X! + + @return: The list of CPU architects to cross compile. + @rtype: list of str + """ + + # The list of archectures to try. + archs = ['i386', 'ppc', 'x86_64'] + 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) + + # Return the list. + return allowed def dummy(self, target, source, env): @@ -510,13 +537,16 @@ # Relaxation curve fitting build environment. env = Environment() + # Determine the build architectures. + archs = self.det_arch() + # C flags. if SYSTEM == 'Windows': cflags = '/nologo /I\"' + py_include_minpath + '\" /I\"' + numpy_path + '\"' else: cflags = '-I' + py_include_fullpath + ' -I' + numpy_path if env['PLATFORM'] == 'darwin': - for arch in ['i386', 'ppc', 'x86_64']: + for arch in archs: cflags += ' -arch %s' % arch # Python library path. @@ -538,7 +568,7 @@ ] # Force all architectures. - for arch in ['i386', 'ppc', 'x86_64']: + for arch in archs: lnflags.append('-arch') lnflags.append(arch)