Add support for "local" subdirectory of sysroot

Automatically add `sysroot/local/include` and `sysroot/local/lib` to the
include and library path.

Also, use this new local subdirectory by default in emscripten by
passing `--prefix=<sysroot>/local`.  This should make `emconfigure +
make install` work out of the box.

Also, add `sysroot/lib` to the library path which allows libraries
installed via `./configure --prefix=<sysroot>` and then `make install`
to be found automativally.

Fixes: #13753
diff --git a/emcc.py b/emcc.py
index 0caa899..7a8d2ac 100755
--- a/emcc.py
+++ b/emcc.py
@@ -663,8 +663,11 @@
   if os.environ.get('EMMAKEN_NO_SDK'):
     return []
 
+  sysroot = shared.Cache.get_sysroot_dir()
   library_paths = [
-     shared.Cache.get_lib_dir(absolute=True)
+     os.path.join(sysroot, 'local', 'lib'),
+     os.path.join(shared.Cache.dirname, shared.Cache.get_lib_dir()),
+     os.path.join(sysroot, 'lib'),
   ]
   ldflags = ['-L' + l for l in library_paths]
 
@@ -680,7 +683,7 @@
 
 
 def emsdk_cflags(user_args):
-  cflags = ['--sysroot=' + shared.Cache.get_sysroot_dir(absolute=True)]
+  cflags = ['--sysroot=' + shared.Cache.get_sysroot_dir()]
 
   def array_contains_any_of(hay, needles):
     for n in needles:
@@ -713,7 +716,14 @@
   if array_contains_any_of(user_args, SIMD_NEON_FLAGS):
     cflags += ['-D__ARM_NEON__=1']
 
-  return cflags + ['-Xclang', '-iwithsysroot' + os.path.join('/include', 'compat')]
+  include_paths = [
+    '/local/include',
+    '/include/compat',
+  ]
+  for p in include_paths:
+    cflags += ['-Xclang', '-iwithsysroot' + p]
+
+  return cflags
 
 
 def get_clang_flags():
diff --git a/tools/building.py b/tools/building.py
index f078c1e..4ba545b 100644
--- a/tools/building.py
+++ b/tools/building.py
@@ -319,6 +319,10 @@
     # compilation with emcc, but instead do builds natively with Clang. This
     # is a heuristic emulation that may or may not work.
     env['EMMAKEN_JUST_CONFIGURE'] = '1'
+    if not any(a.startswith('--prefix') for a in args):
+      sysroot = shared.Cache.get_sysroot_dir()
+      args.append('--prefix=' + os.path.join(sysroot, 'local'))
+
   if EM_BUILD_VERBOSE >= 2:
     stdout = None
   if EM_BUILD_VERBOSE >= 1:
diff --git a/tools/cache.py b/tools/cache.py
index 51ab2ff..dba0162 100644
--- a/tools/cache.py
+++ b/tools/cache.py
@@ -88,16 +88,14 @@
   def get_path(self, name):
     return os.path.join(self.dirname, name)
 
-  def get_sysroot_dir(self, absolute):
-    if absolute:
-      return os.path.join(self.dirname, 'sysroot')
-    return 'sysroot'
+  def get_sysroot_dir(self):
+    return os.path.join(self.dirname, 'sysroot')
 
   def get_include_dir(self):
-    return os.path.join(self.get_sysroot_dir(absolute=True), 'include')
+    return os.path.join(self.get_sysroot_dir(), 'include')
 
-  def get_lib_dir(self, absolute):
-    path = os.path.join(self.get_sysroot_dir(absolute=absolute), 'lib')
+  def get_lib_dir(self):
+    path = os.path.join('sysroot', 'lib')
     if shared.Settings.MEMORY64:
       path = os.path.join(path, 'wasm64-emscripten')
     else:
@@ -113,7 +111,7 @@
     return path
 
   def get_lib_name(self, name):
-    return os.path.join(self.get_lib_dir(absolute=False), name)
+    return os.path.join(self.get_lib_dir(), name)
 
   def erase_lib(self, name):
     self.erase_file(self.get_lib_name(name))