anchor.diff:      substituteInPlace unittests/Support/CMakeLists.txt \
         --replace "Path.cpp" ""
       rm unittests/Support/Path.cpp
  -  '' + stdenv.lib.optionalString stdenv.hostPlatform.isMusl ''
  +  '' + optionalString stdenv.hostPlatform.isMusl ''
       patch -p1 -i ${../TLI-musl.patch}
       substituteInPlace unittests/Support/CMakeLists.txt \
         --replace "add_subdirectory(DynamicLibrary)" ""
  
positive.code:     "-DLLVM_BUILD_TESTS=ON"
      "-DLLVM_ENABLE_FFI=ON"
      "-DLLVM_ENABLE_RTTI=ON"
  
      "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}"
      "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}"
      "-DTARGET_TRIPLE=${stdenv.hostPlatform.config}"
  
      "-DLLVM_ENABLE_DUMP=ON"
    ]
    ++ stdenv.lib.optional enableSharedLibraries
      "-DLLVM_LINK_LLVM_DYLIB=ON"
    ++ stdenv.lib.optionals enableManpages [
      "-DLLVM_BUILD_DOCS=ON"
      "-DLLVM_ENABLE_SPHINX=ON"
      "-DSPHINX_OUTPUT_MAN=ON"
      "-DSPHINX_OUTPUT_HTML=OFF"
      "-DSPHINX_WARNINGS_AS_ERRORS=OFF"
    ]
    ++ stdenv.lib.optional (!isDarwin)
      "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include"
    ++ stdenv.lib.optionals (isDarwin) [
      "-DLLVM_ENABLE_LIBCXX=ON"
      "-DCAN_TARGET_i386=false"
    ]
    ++ stdenv.lib.optional enableWasm
     "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly"
    ;
  
    postBuild = ''
      rm -fR $out
  
negative.code:   '';
  
    outputs = [ "out" "python" ]
      ++ optional enableSharedLibraries "lib";
  
    nativeBuildInputs = [ cmake python ]
      ++ optional enableManpages python.pkgs.sphinx;
  
    buildInputs = [ libxml2 libffi ];
  
    propagatedBuildInputs = [ ncurses zlib ];
  
    patches = [
      # fixes tests, included in llvm_7
      (fetchpatch {
        url = "https://github.com/llvm-mirror/llvm/commit/737553be0c9c25c497b45a241689994f177d5a5d.patch";
        sha256 = "0hnaxnkx7zy5yg98f1ggv8a9l0r6g19n6ygqsv26masrnlcbccli";
      })
    ];
  
    postPatch = 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}.
    + optionalString (enableSharedLibraries) ''
      substitute '${./llvm-outputs.patch}' ./llvm-outputs.patch --subst-var lib
      patch -p1 < ./llvm-outputs.patch
    '' + ''
  