From 09625ca7153420c4b2238f68ef6baf81c4ba6d68 Mon Sep 17 00:00:00 2001
From: Joe Garcia <joe.garcia@ssec.wisc.edu>
Date: Mon, 29 Mar 2021 12:13:36 -0500
Subject: [PATCH] sysroot shared

---
 ShellB3/sb3bin/thosewhohuntelfs.py | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/ShellB3/sb3bin/thosewhohuntelfs.py b/ShellB3/sb3bin/thosewhohuntelfs.py
index c02df35b..251dafb5 100755
--- a/ShellB3/sb3bin/thosewhohuntelfs.py
+++ b/ShellB3/sb3bin/thosewhohuntelfs.py
@@ -24,6 +24,7 @@ import platform
 import shutil
 
 LOG = logging.getLogger(__name__)
+sysroot = "/"
 
 # options go here as attributes
 OPTS = None
@@ -162,7 +163,7 @@ def fullrealpath(path,rpaths,loader,executable=None):
         return fullrealpath_single(path,rpaths,os.path.dirname(loader),executable)
     if len(rpaths)==0:
         rpaths=[os.getcwd()]
-    for p in rpaths+[os.getenv('SYSROOT','/'),os.getcwd()]:
+    for p in rpaths+[sysroot,os.getcwd()]:
         r=fullrealpath_single(path,asUnicode(p),os.path.dirname(loader),executable)
         if os.path.exists(r):
             return r
@@ -441,7 +442,7 @@ def probe(base,forbiddenlibs=''):
                 forbiddenlibs.append(f)
         printerr('Forbidden libs are {}'.format(','.join(forbiddenlibs)))
     fullbase=os.path.realpath(base)
-    sysroot=os.getenv('SYSROOT','')
+    usesysroot=sysroot#os.getenv('SYSROOT','')
     for path in hunt_elfs(base,elvish=elvish):
         if elvish:
             print(path + " => {}".format(printable_rpath(path))),
@@ -463,8 +464,8 @@ def probe(base,forbiddenlibs=''):
                 elif lib.startswith('/'):
                     li=lib
                     dli=li
-                    if len(sysroot)>1:
-                        li=sysroot+li
+                    if len(usesysroot)>1:
+                        li=usesysroot+li
                         dli=li
                         if int(os.getenv("SDKDARWINVERNUMBER"))>=15: #these SDKs don't store dylibs but "tdb" files
                             if li.endswith('.dylib'):
@@ -475,7 +476,7 @@ def probe(base,forbiddenlibs=''):
                     dli=li
                 if dli.startswith(fullbase):
                     dli=dli.replace(fullbase,'[ShellB3]:')
-                if len(sysroot)>1 and dli.startswith(sysroot):
+                if len(usesysroot)>1 and dli.startswith(usesysroot):
                     def macVer(v):
                         vparts=v.replace('*','').split('.')
                         vv=int(vparts[0])
@@ -487,7 +488,7 @@ def probe(base,forbiddenlibs=''):
                         if iv<=11:
                             return "OS X "+v
                         return "macOS "+v
-                    dli=dli.replace(sysroot,'['+macVer(os.getenv('MACOSX_DEPLOYMENT_TARGET'))+']:')
+                    dli=dli.replace(usesysroot,'['+macVer(os.getenv('MACOSX_DEPLOYMENT_TARGET'))+']:')
                 if os.access(li,os.R_OK):
                     print('{} => {}'.format(lib,dli))
                     for l in forbiddenlibs:
@@ -644,6 +645,8 @@ python thosewhohuntelfs.py . common/lib lib --exclude='.*?build/.*' --dry-run --
                     help='comma-separated library prefixes (e.g. "libxxx,libyyy") that are absolutely forbidden to be linked to (for legacy or known incompatibility)')
     parser.add_option('--rpaths', dest='list_rpaths', default=False, action="store_true",
                     help='just list rpaths of named files')
+    parser.add_option('--sysroot', dest="sysroot",default=os.getenv('SYSROOT','/'),
+                    help="set the system root, to match up system libraries")
     # parser.add_option('-I', '--include-path', dest="includes",
     #                 action="append", help="include path to append to GCCXML call")                           
 
@@ -674,6 +677,9 @@ python thosewhohuntelfs.py . common/lib lib --exclude='.*?build/.*' --dry-run --
         OPTS.install_name_tool = os.path.abspath(OPTS.install_name_tool)
         assert(os.path.exists(OPTS.install_name_tool))
 
+    global sysroot
+    sysroot=options.sysroot
+
     if not args:
         parser.error( 'incorrect arguments, try -h or --help.' )
         return 9
-- 
GitLab