summaryrefslogtreecommitdiff
path: root/giscanner/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'giscanner/utils.py')
-rw-r--r--giscanner/utils.py49
1 files changed, 46 insertions, 3 deletions
diff --git a/giscanner/utils.py b/giscanner/utils.py
index 642da362..abd1a266 100644
--- a/giscanner/utils.py
+++ b/giscanner/utils.py
@@ -21,8 +21,12 @@
import re
import os
import subprocess
+import platform
+
_debugflags = None
+
+
def have_debug_flag(flag):
"""Check for whether a specific debugging feature is enabled.
Well-known flags:
@@ -38,6 +42,7 @@ Well-known flags:
_debugflags.remove('')
return flag in _debugflags
+
def break_on_debug_flag(flag):
if have_debug_flag(flag):
import pdb
@@ -69,8 +74,10 @@ def to_underscores_noprefix(name):
name = _upperstr_pat2.sub(r'\1_\2', name)
return name
+
_libtool_pat = re.compile("dlname='([A-z0-9\.\-\+]+)'\n")
+
def _extract_dlname_field(la_file):
f = open(la_file)
data = f.read()
@@ -81,6 +88,21 @@ def _extract_dlname_field(la_file):
else:
return None
+
+_libtool_libdir_pat = re.compile("libdir='([^']+)'")
+
+
+def _extract_libdir_field(la_file):
+ f = open(la_file)
+ data = f.read()
+ f.close()
+ m = _libtool_libdir_pat.search(data)
+ if m:
+ return m.groups()[0]
+ else:
+ return None
+
+
# Returns the name that we would pass to dlopen() the library
# corresponding to this .la file
def extract_libtool_shlib(la_file):
@@ -88,10 +110,19 @@ def extract_libtool_shlib(la_file):
if dlname is None:
return None
+ # Darwin uses absolute paths where possible; since the libtool files never
+ # contain absolute paths, use the libdir field
+ if platform.system() == 'Darwin':
+ dlbasename = os.path.basename(dlname)
+ libdir = _extract_libdir_field(la_file)
+ if libdir is None:
+ return dlbasename
+ return libdir + '/' + dlbasename
# From the comments in extract_libtool(), older libtools had
# a path rather than the raw dlname
return os.path.basename(dlname)
+
def extract_libtool(la_file):
dlname = _extract_dlname_field(la_file)
if dlname is None:
@@ -104,6 +135,7 @@ def extract_libtool(la_file):
libname = libname.replace('.libs/.libs', '.libs')
return libname
+
# Returns arguments for invoking libtool, if applicable, otherwise None
def get_libtool_command(options):
libtool_infection = not options.nolibtool
@@ -118,14 +150,18 @@ def get_libtool_command(options):
# we simply split().
return libtool_path.split(' ')
+ libtool_cmd = 'libtool'
+ if platform.system() == 'Darwin':
+ # libtool on OS X is a completely different program written by Apple
+ libtool_cmd = 'glibtool'
try:
- subprocess.check_call(['libtool', '--version'],
+ subprocess.check_call([libtool_cmd, '--version'],
stdout=open(os.devnull))
- except (subprocess.CalledProcessError, OSError), e:
+ except (subprocess.CalledProcessError, OSError):
# If libtool's not installed, assume we don't need it
return None
- return ['libtool']
+ return [libtool_cmd]
def files_are_identical(path1, path2):
@@ -139,3 +175,10 @@ def files_are_identical(path1, path2):
f1.close()
f2.close()
return buf1 == buf2
+
+
+def cflag_real_include_path(cflag):
+ if not cflag.startswith("-I"):
+ return cflag
+
+ return "-I" + os.path.realpath(cflag[2:])