lol
1diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py
2index 89ec193..54f1d2e 100755
3--- a/giscanner/scannermain.py
4+++ b/giscanner/scannermain.py
5@@ -94,6 +94,39 @@ def get_windows_option_group(parser):
6 return group
7
8
9+def _get_default_fallback_libpath():
10+ # Newer multiple-output-optimized stdenv has an environment variable
11+ # $outputLib which in turn specifies another variable which then is used as
12+ # the destination for the library contents (${!outputLib}/lib).
13+ store_path = os.environ.get(os.environ.get("outputLib"))
14+ if store_path is None:
15+ outputs = os.environ.get("outputs", "out").split()
16+ if "lib" in outputs:
17+ # For multiple output derivations let's try whether there is a $lib
18+ # environment variable and use that as the base store path.
19+ store_path = os.environ.get("lib")
20+ elif "out" in outputs:
21+ # Otherwise we have a single output derivation, so the libraries
22+ # most certainly will end up in "$out/lib".
23+ store_path = os.environ.get("out")
24+
25+ if store_path is not None:
26+ # Even if we have a $lib as output, there still should be a $lib/lib
27+ # directory.
28+ return os.path.join(store_path, 'lib')
29+ else:
30+ # If we haven't found a possible scenario, let's return an empty string
31+ # so that the shared library won't be prepended with a path.
32+ #
33+ # Note that this doesn't mean that all hope is lost, because after all
34+ # we can still use --fallback-library-path to set one.
35+ #
36+ # Also, we're not returning None, because that would make it very
37+ # difficult to disable adding fallback paths altogether using something
38+ # like: --fallback-library-path=""
39+ return ""
40+
41+
42 def _get_option_parser():
43 parser = optparse.OptionParser('%prog [options] sources')
44 parser.add_option('', "--quiet",
45@@ -200,6 +233,10 @@ match the namespace prefix.""")
46 parser.add_option("", "--filelist",
47 action="store", dest="filelist", default=[],
48 help="file containing headers and sources to be scanned")
49+ parser.add_option("", "--fallback-library-path",
50+ action="store", dest="fallback_libpath",
51+ default=_get_default_fallback_libpath(),
52+ help="Path to prepend to unknown shared libraries")
53
54 group = get_preprocessor_option_group(parser)
55 parser.add_option_group(group)
56diff --git a/giscanner/shlibs.py b/giscanner/shlibs.py
57index 838d343..ca7fc0d 100644
58--- a/giscanner/shlibs.py
59+++ b/giscanner/shlibs.py
60@@ -53,10 +53,27 @@ def _resolve_libtool(options, binary, libraries):
61 # Match absolute paths on OS X to conform to how libraries are usually
62 # referenced on OS X systems.
63 def _ldd_library_pattern(library_name):
64+ nix_store_dir = re.escape('@nixStoreDir@'.rstrip('/'))
65 pattern = "(?<![A-Za-z0-9_-])(lib*%s[^A-Za-z0-9_-][^\s\(\)]*)"
66 if platform.system() == 'Darwin':
67 pattern = "([^\s]*lib*%s[^A-Za-z0-9_-][^\s\(\)]*)"
68- return re.compile(pattern % re.escape(library_name))
69+ return re.compile(pattern % re.escape(library_name))
70+ pattern = r'''
71+ (
72+ (?:
73+ # First match Nix store paths because they need to be absolute.
74+ (?:%s(?:/[^/]*)+)
75+ # Everything else not a store path remains relative, because we
76+ # would end up with temporary paths that are only valid during
77+ # build time in the resulting GIR file.
78+ | (?<=/)
79+ )
80+ # And finally the library itself:
81+ (?:lib%s[^A-Za-z0-9_-][^\s\(\)]*)
82+ )
83+ '''
84+ return re.compile(pattern % (nix_store_dir, re.escape(library_name)),
85+ re.VERBOSE)
86
87
88 # This is a what we do for non-la files. We assume that we are on an
89@@ -115,7 +132,11 @@ def _resolve_non_libtool(options, binary, libraries):
90 m = pattern.search(line)
91 if m:
92 del patterns[library]
93- shlibs.append(m.group(1))
94+ match = m.group(1)
95+ if not match.startswith('/') \
96+ and len(options.fallback_libpath) > 0:
97+ match = os.path.join(options.fallback_libpath, match)
98+ shlibs.append(match)
99 break
100
101 if len(patterns) > 0:
102diff --git a/giscanner/utils.py b/giscanner/utils.py
103index 660081e..c9c767a 100644
104--- a/giscanner/utils.py
105+++ b/giscanner/utils.py
106@@ -109,17 +109,11 @@ def extract_libtool_shlib(la_file):
107 if dlname is None:
108 return None
109
110- # Darwin uses absolute paths where possible; since the libtool files never
111- # contain absolute paths, use the libdir field
112- if platform.system() == 'Darwin':
113- dlbasename = os.path.basename(dlname)
114- libdir = _extract_libdir_field(la_file)
115- if libdir is None:
116- return dlbasename
117- return libdir + '/' + dlbasename
118- # From the comments in extract_libtool(), older libtools had
119- # a path rather than the raw dlname
120- return os.path.basename(dlname)
121+ dlbasename = os.path.basename(dlname)
122+ libdir = _extract_libdir_field(la_file)
123+ if libdir is None:
124+ return dlbasename
125+ return libdir + '/' + dlbasename
126
127
128 def extract_libtool(la_file):