summaryrefslogtreecommitdiffstats
path: root/setup.py
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2004-12-31 08:11:21 (GMT)
committerBrett Cannon <bcannon@gmail.com>2004-12-31 08:11:21 (GMT)
commit4810eb9a0852bc428a46d5590aafbe9b50f3370c (patch)
tree7f3583399ee2c32c488215c9c663cfc42468a79d /setup.py
parent79e0531aefebe5413b67d0ebaa73610aa58e8de9 (diff)
downloadcpython-4810eb9a0852bc428a46d5590aafbe9b50f3370c.zip
cpython-4810eb9a0852bc428a46d5590aafbe9b50f3370c.tar.gz
cpython-4810eb9a0852bc428a46d5590aafbe9b50f3370c.tar.bz2
Strip out double dashes and dashes for options not used during parsing of
LDFLAGS and CPPFLAGS for library and include directories, respectively. Solves issue of either env var containing other options that do not pertain to the directories being searched for.
Diffstat (limited to 'setup.py')
-rw-r--r--setup.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/setup.py b/setup.py
index 61cf811..c8d9aa0 100644
--- a/setup.py
+++ b/setup.py
@@ -243,17 +243,31 @@ class PyBuildExt(build_ext):
add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
# Add paths specified in the environment variables LDFLAGS and
- # CPPFLAGS.
+ # CPPFLAGS for header and library files.
# We must get the values from the Makefile and not the environment
# directly since an inconsistently reproducible issue comes up where
# the environment variable is not set even though the value were passed
- # into configure and stored in the Makefile.
+ # into configure and stored in the Makefile (issue found on OS X 10.3).
for env_var, arg_name, dir_list in (
('LDFLAGS', '-L', self.compiler.library_dirs),
('CPPFLAGS', '-I', self.compiler.include_dirs)):
env_val = sysconfig.get_config_var(env_var)
if env_val:
+ # To prevent optparse from raising an exception about any
+ # options in env_val that is doesn't know about we strip out
+ # all double dashes and any dashes followed by a character
+ # that is not for the option we are dealing with.
+ #
+ # Please note that order of the regex is important! We must
+ # strip out double-dashes first so that we don't end up with
+ # substituting "--Long" to "-Long" and thus lead to "ong" being
+ # used for a library directory.
+ env_val = re.sub(r'(^|\s+)-(-|(?!%s))' % arg_name[1], '', env_val)
parser = optparse.OptionParser()
+ # Make sure that allowing args interspersed with options is
+ # allowed
+ parser.allow_interspersed_args = True
+ parser.error = lambda msg: None
parser.add_option(arg_name, dest="dirs", action="append")
options = parser.parse_args(env_val.split())[0]
for directory in options.dirs: