anchor.diff:  , version
   , release_version
   , zlib
  +, buildPackages
   , debugVersion ? false
   , enableManpages ? false
   , enableSharedLibraries ? true
  -, targets ? [ stdenv.hostPlatform stdenv.targetPlatform ]
  -, enableWasm ? true # TODO fold this into `targets` somehow
  +, enableTargets ? [ stdenv.hostPlatform stdenv.targetPlatform ]
   , enablePFM ? !stdenv.isDarwin
   }:
   
   let
  +  inherit (stdenv.lib) optional optionals optionalString;
  +
     src = fetch "llvm" "08p27wv1pr9ql2zc3f3qkkymci46q7myvh8r5ijippnbwr2gihcb";
   
     # Used when creating a version-suffixed symlink of libLLVM.dylib
  
positive.code:   '';
  
    outputs = [ "out" "python" ]
      ++ stdenv.lib.optional enableSharedLibraries "lib";
  
    nativeBuildInputs = [ cmake python ]
      ++ stdenv.lib.optional enableManpages python.pkgs.sphinx;
  
    buildInputs = [ libxml2 libffi ]
      ++ stdenv.lib.optional enablePFM libpfm; # exegesis
  
    propagatedBuildInputs = [ ncurses zlib ];
  
    postPatch = stdenv.lib.optionalString stdenv.isDarwin ''
      substituteInPlace cmake/modules/AddLLVM.cmake \
        --replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir INSTALL_NAME_DIR "$lib/lib")" \
        --replace 'set(_install_rpath "@loader_path/../lib" ''${extra_libdir})' ""
    ''
    # Patch llvm-config to return correct library path based on --link-{shared,static}.
    + stdenv.lib.optionalString (enableSharedLibraries) ''
      substitute '${./llvm-outputs.patch}' ./llvm-outputs.patch --subst-var lib
      patch -p1 < ./llvm-outputs.patch
    '' + ''
  
negative.code:     "-DLLVM_ENABLE_RTTI=ON"
      "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}"
      "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.targetPlatform.config}"
      "-DLLVM_TARGETS_TO_BUILD=${llvmBackendList enableTargets}"
      "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly"
      "-DLLVM_ENABLE_DUMP=ON"
    ] ++ optionals enableSharedLibraries [
      "-DLLVM_LINK_LLVM_DYLIB=ON"
    ] ++ optionals enableManpages [
      "-DLLVM_BUILD_DOCS=ON"
      "-DLLVM_ENABLE_SPHINX=ON"
      "-DSPHINX_OUTPUT_MAN=ON"
      "-DSPHINX_OUTPUT_HTML=OFF"
      "-DSPHINX_WARNINGS_AS_ERRORS=OFF"
    ] ++ optionals (!isDarwin) [
      "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include"
    ] ++ optionals (isDarwin) [
      "-DLLVM_ENABLE_LIBCXX=ON"
      "-DCAN_TARGET_i386=false"
    ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
      "-DCMAKE_CROSSCOMPILING=True"
      "-DLLVM_TABLEGEN=${buildPackages.llvm_7}/bin/llvm-tblgen"
    ];
  
    postBuild = ''
      rm -fR $out
  