summaryrefslogtreecommitdiff
path: root/numpy/distutils/npy_pkg_config.py
diff options
context:
space:
mode:
authorDavid Cournapeau <cournape@gmail.com>2009-07-26 11:13:06 +0000
committerDavid Cournapeau <cournape@gmail.com>2009-07-26 11:13:06 +0000
commit14202898c93289f14f0e2c7094bb819a47c4fd8a (patch)
tree570cfc668317b00924e22c67521631c19ead0d7f /numpy/distutils/npy_pkg_config.py
parent67182cd9bf33504ddd87f5edb6dcf51a0b8fee8e (diff)
downloadnumpy-14202898c93289f14f0e2c7094bb819a47c4fd8a.tar.gz
Add parse_flags function + some unit tests.
Diffstat (limited to 'numpy/distutils/npy_pkg_config.py')
-rw-r--r--numpy/distutils/npy_pkg_config.py36
1 files changed, 35 insertions, 1 deletions
diff --git a/numpy/distutils/npy_pkg_config.py b/numpy/distutils/npy_pkg_config.py
index b63222036..70084ecff 100644
--- a/numpy/distutils/npy_pkg_config.py
+++ b/numpy/distutils/npy_pkg_config.py
@@ -1,8 +1,9 @@
from ConfigParser import SafeConfigParser, NoOptionError
import re
import os
+import shlex
-__all__ = ['FormatError', 'LibraryInfo', 'VariablesSet', 'get_info']
+__all__ = ['FormatError', 'LibraryInfo', 'VariablesSet', 'get_info', 'parse_flags']
_VAR = re.compile('\$\{([a-zA-Z0-9_-]+)\}')
@@ -13,6 +14,39 @@ class FormatError(IOError):
def __str__(self):
return self.msg
+def parse_flags(line):
+ lexer = shlex.shlex(line)
+ lexer.whitespace_split = True
+
+ d = {'include_dirs': [], 'library_dirs': [], 'libs': [], 'include': [],
+ 'macros': [], 'libs': [], 'ignored': []}
+ def next_token(t):
+ if t.startswith('-I'):
+ if len(t) > 2:
+ d['include_dirs'].append(t[2:])
+ else:
+ t = lexer.get_token()
+ d['include_dirs'].append(t)
+ elif t.startswith('-L'):
+ if len(t) > 2:
+ d['library_dirs'].append(t[2:])
+ else:
+ t = lexer.get_token()
+ d['library_dirs'].append(t)
+ elif t.startswith('-l'):
+ d['libs'].append(t[2:])
+ elif t.startswith('-D'):
+ d['macros'].append(t[2:])
+ else:
+ d['ignored'].append(t)
+ return lexer.get_token()
+
+ t = lexer.get_token()
+ while t:
+ t = next_token(t)
+
+ return d
+
class LibraryInfo(object):
def __init__(self, name, description, version, sections, vars, requires=None):
self.name = name