code: def build_mupdf_unix(mupdf_local, env, build_type):
      """
      Builds MuPDF.
  
      Args:
          mupdf_local:
              Path of MuPDF directory or None if we are using system MuPDF.
  
      Returns the absolute path of build directory within MuPDF, e.g.
      `.../mupdf/build/pymupdf-shared-release`, or `None` if we are using the
      system MuPDF.
      """
      if not mupdf_local:
          log(f"Using system mupdf.")
          return None
  
      env = env.copy()
      if openbsd or freebsd:
          env_add(env, "CXX", "c++", " ")
  
      # Add extra flags for MacOS cross-compilation, where ARCHFLAGS can be
      # '-arch arm64'.
      #
      archflags = os.environ.get("ARCHFLAGS")
      if archflags:
          env_add(env, "XCFLAGS", archflags)
          env_add(env, "XLIBS", archflags)
  
      # We specify a build directory path containing 'pymupdf' so that we
      # coexist with non-PyMuPDF builds (because PyMuPDF builds have a
      # different config.h).
      #
      # We also append further text to try to allow different builds to
      # work if they reuse the mupdf directory.
      #
      # Using platform.machine() (e.g. 'amd64') ensures that different
      # builds of mupdf on a shared filesystem can coexist. Using
      # $_PYTHON_HOST_PLATFORM allows cross-compiled cibuildwheel builds
      # to coexist, e.g. on github.
      #
      build_prefix = f"PyMuPDF-"
      if pyodide:
          build_prefix += "pyodide-"
      else:
          build_prefix += f"{platform.machine()}-"
      build_prefix_extra = os.environ.get("_PYTHON_HOST_PLATFORM")
      if build_prefix_extra:
          build_prefix += f"{build_prefix_extra}-"
      build_prefix += "shared-"
      if os.environ.get("PYMUPDF_SETUP_MUPDF_TESSERACT") != "0":
          build_prefix += "tesseract-"
      unix_build_dir = f"{mupdf_local}/build/{build_prefix}{build_type}"
      # We need MuPDF's Python bindings, so we build MuPDF with
      # `mupdf/scripts/mupdfwrap.py` instead of running `make`.
      #
      env_string = ""
      for n, v in env.items():
          env_string += f" {n}={shlex.quote(v)}"
      command = f"cd {mupdf_local} &&{env_string} {sys.executable} ./scripts/mupdfwrap.py -d build/{build_prefix}{build_type} -b "
      if "b" in _implementations() and "p" in g_flavour:
          command += "all"
      else:
          command += "m01"  # No need for C++/Python bindings.
      command += f" && echo {unix_build_dir}:"
      command += f" && ls -l {unix_build_dir}"
  
      if os.environ.get("PYMUPDF_SETUP_MUPDF_REBUILD") == "0":
          log(
              f'PYMUPDF_SETUP_MUPDF_REBUILD is "0" so not building MuPDF; would have run: {command}'
          )
      else:
          log(f"Building MuPDF by running: {command}")
          subprocess.run(command, shell=True, check=True)
          log(f"Finished building mupdf.")
  
      return unix_build_dir
  
imports: import glob
  import io
  import os
  import textwrap
  import time
  import platform
  import shlex
  import shutil
  import stat
  import subprocess
  import sys
  import tarfile
  import urllib.request
  import zipfile
  import pipcl
  import sys
label_desc: Use image node_id 15 for calling a global function with example usage: build_mupdf_unix(mupdf_local, env, build_type) and returns: unix_build_dir, None