2013-04-26 4 views
5

* NIXプラットフォームでソースコードをビルドする一般的な方法の1つは、configureスクリプトを使用することです。その中で、configureは一連のテストプログラムをビルドして、アクセス可能なライブラリを特定しようとします。次に、マクロに束縛されたマクロを定義するプロジェクトに含まれるヘッダファイルを生成します。これにより、特定の "依存関係"がない場合、プログラマが代替ライブラリを提供したり、ライブラリ/プログラムを削除することができます。 numpy.distutilsを使用して機能的に同等のものはありますか?一例として、numpy distutils - 失敗したら何かをコンパイルしてフラグを設定しよう

は、ここに私のsetup.pyです:

from numpy.distutils.misc_util import Configuration 

def configuration(parent_package='',top_path=None): 
    config = Configuration('pyggcm',parent_package,top_path) 

    #TODO: Currently, I have some macros to conditionally build the seek-code 
    #Unfortunately, that's not the best solution (by far). Perhaps if we 
    #changed to using stream access it would work better, without the need 
    #for these silly macros. 
    config.add_extension('_fortfile',sources=['_fortfile/_fortfile.F90'], 
         define_macros=[ 
          ('FSEEKABLE',1), #compiler provides fseek and ftell 
          ('HAVE_STREAM',1) #compiler provides access='stream' for opening files. (f2003 standard) 
          ]) 

    config.add_extension('jrrle',sources=['jrrle/jrrle.f90']) 
    config.add_scripts(['scripts/ggcm_timehist', 
         'scripts/ggcm_plasmasheet', 
         'scripts/ggcm_plot']) 
    return config 


from numpy.distutils.core import setup  
setup(configuration=configuration) 

これは無条件にFSEEKABLEコードを構築して、ユーザーのFortranコンパイラがそれをサポートしていない場合は、手動で編集する必要があります(マクロはfseekを包みますおよびftell GNU組み込み関数)。 Fortranコンパイラがこれらの組み込み関数を提供するかどうかを判断する方法はありますか?

答えて

0

ファイルにコードフラグメントを生成&これをコンパイルしようとすると、通常の方法で正常に動作するはずですが、AFAIKはdistutilsの一部としてこれを実行していません。私は、おそらく他のPythonベースのものが、これをサポートしているようなツールを作っていると考えています。私はあなたの最善の策はGNUの自動設定だと思います。

+0

欠落単語を:* ...のようなツールを構築することができますか... *? – Tshepang

1

これを試してみてください:

import os 
import shutil 
import tempfile 
from distutils.ccompiler import new_compiler 

def hasfunction(cc, funcname, include=None, extra_postargs=None): 
    tmpdir = tempfile.mkdtemp(prefix='hasfunction-') 
    devnull = oldstderr = None 
    try: 
     try: 
      fname = os.path.join(tmpdir, 'funcname.c') 
      f = open(fname, 'w') 
      if include is not None: 
       f.write('#include %s\n' % include) 
      f.write('int main(void) {\n') 
      f.write(' %s;\n' % funcname) 
      f.write('}\n') 
      f.close() 
      devnull = open(os.devnull, 'w') 
      oldstderr = os.dup(sys.stderr.fileno()) 
      os.dup2(devnull.fileno(), sys.stderr.fileno()) 
      objects = cc.compile([fname], output_dir=tmpdir, 
           extra_postargs=extra_postargs) 
      cc.link_executable(objects, os.path.join(tmpdir, 'a.out')) 
     except Exception as e: 
      return False 
     return True 
    finally: 
     if oldstderr is not None: 
      os.dup2(oldstderr, sys.stderr.fileno()) 
     if devnull is not None: 
      devnull.close() 
     shutil.rmtree(tmpdir) 

例:

def detect_sse3(): 
    "Does this compiler support SSE3 intrinsics?" 
    compiler = new_compiler() 
    return hasfunction(compiler, '__m128 v; _mm_hadd_ps(v,v)', 
         include='<pmmintrin.h>', 
         extra_postargs=['-msse3']) 
関連する問題