[NumPy-Tickets] [NumPy] #527: fortran linking flag option...

NumPy Trac numpy-tickets@scipy....
Tue Apr 19 08:34:00 CDT 2011


#527: fortran linking flag option...
-------------------------+--------------------------------------------------
 Reporter:  fred         |       Owner:  pearu      
     Type:  enhancement  |      Status:  new        
 Priority:  normal       |   Milestone:  Unscheduled
Component:  numpy.f2py   |     Version:  devel      
 Keywords:               |  
-------------------------+--------------------------------------------------

Comment(by lorenz):

 I also frequently have to set custom LDFLAGS - even CFLAGS! - when running
 "f2py -c". For example "-mcmodel=medium"

 I use the following small patch to add two new f2py command line options,
 namely

   --cflags=
   --ldflags=

 with obvious meaning to specify distutils "extra_compile_args" and
 "extra_link_args":

 {{{
 diff --git a/numpy/f2py/f2py2e.py b/numpy/f2py/f2py2e.py
 index 86c4b31..dbf0c4a 100755
 --- a/numpy/f2py/f2py2e.py
 +++ b/numpy/f2py/f2py2e.py
 @@ -428,6 +428,26 @@ def run_compile():
          remove_build_dir = 1
          build_dir = os.path.join(tempfile.mktemp())

 +    cflags = filter(lambda a : a.startswith("--cflags="), sys.argv)
 +    if cflags:
 +        assert(len(cflags) == 1)
 +        cflags = cflags[0]
 +        extra_compile_args = cflags[len("--cflags="):].split()
 +        i = sys.argv.index(cflags)
 +        del sys.argv[i]
 +    else:
 +        extra_compile_args = None
 +
 +    ldflags = filter(lambda a : a.startswith("--ldflags="), sys.argv)
 +    if cflags:
 +        assert(len(ldflags) == 1)
 +        ldflags = ldflags[0]
 +        extra_link_args = ldflags[len("--ldflags="):].split()
 +        i = sys.argv.index(ldflags)
 +        del sys.argv[i]
 +    else:
 +        extra_link_args = None
 +
      sysinfo_flags =
 filter(re.compile(r'[-][-]link[-]').match,sys.argv[1:])
      sys.argv = filter(lambda a,flags=sysinfo_flags:a not in
 flags,sys.argv)
      if sysinfo_flags:
 @@ -539,6 +559,8 @@ def run_compile():
                  'undef_macros': undef_macros,
                  'extra_objects': extra_objects,
                  'f2py_options': f2py_flags,
 +                'extra_compile_args' : extra_compile_args,
 +                'extra_link_args' : extra_link_args,
                  }

      if sysinfo_flags:
 }}}

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/527#comment:5>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list