2021-01-22 11:25:31 +00:00
|
|
|
{ lib, stdenv, fetch, cmake, libxml2, llvm, version, clang-tools-extra_src, python3
|
2018-01-31 14:09:24 +00:00
|
|
|
, fixDarwinDylibNames
|
|
|
|
, enableManpages ? false
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
self = stdenv.mkDerivation ({
|
2019-08-16 14:57:51 +01:00
|
|
|
pname = "clang";
|
2019-06-24 01:49:25 +01:00
|
|
|
inherit version;
|
2018-01-31 14:09:24 +00:00
|
|
|
|
2019-07-12 01:09:55 +01:00
|
|
|
src = fetch "cfe" "0rxn4rh7rrnsqbdgp4gzc8ishbkryhpl1kd3mpnxzpxxhla3y93w";
|
|
|
|
|
2018-01-31 14:09:24 +00:00
|
|
|
unpackPhase = ''
|
2019-07-12 01:09:55 +01:00
|
|
|
unpackFile $src
|
2018-01-31 14:09:24 +00:00
|
|
|
mv cfe-${version}* clang
|
|
|
|
sourceRoot=$PWD/clang
|
|
|
|
unpackFile ${clang-tools-extra_src}
|
|
|
|
mv clang-tools-extra-* $sourceRoot/tools/extra
|
|
|
|
'';
|
|
|
|
|
2020-01-12 20:22:29 +00:00
|
|
|
nativeBuildInputs = [ cmake python3 ]
|
2021-01-22 11:25:31 +00:00
|
|
|
++ lib.optional enableManpages python3.pkgs.sphinx
|
|
|
|
++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames;
|
2018-01-31 14:09:24 +00:00
|
|
|
|
2020-10-26 07:17:14 +00:00
|
|
|
buildInputs = [ libxml2 llvm ];
|
2018-01-31 14:09:24 +00:00
|
|
|
|
|
|
|
cmakeFlags = [
|
|
|
|
"-DCMAKE_CXX_FLAGS=-std=c++11"
|
2020-06-27 19:27:50 +01:00
|
|
|
"-DLLVM_ENABLE_RTTI=ON"
|
2021-01-22 11:25:31 +00:00
|
|
|
] ++ lib.optionals enableManpages [
|
2018-01-31 14:09:24 +00:00
|
|
|
"-DCLANG_INCLUDE_DOCS=ON"
|
|
|
|
"-DLLVM_ENABLE_SPHINX=ON"
|
|
|
|
"-DSPHINX_OUTPUT_MAN=ON"
|
|
|
|
"-DSPHINX_OUTPUT_HTML=OFF"
|
|
|
|
"-DSPHINX_WARNINGS_AS_ERRORS=OFF"
|
2018-04-29 23:06:35 +01:00
|
|
|
];
|
2018-01-31 14:09:24 +00:00
|
|
|
|
|
|
|
patches = [ ./purity.patch ];
|
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
sed -i -e 's/DriverArgs.hasArg(options::OPT_nostdlibinc)/true/' \
|
|
|
|
-e 's/Args.hasArg(options::OPT_nostdlibinc)/true/' \
|
|
|
|
lib/Driver/ToolChains/*.cpp
|
|
|
|
|
|
|
|
# Patch for standalone doc building
|
|
|
|
sed -i '1s,^,find_package(Sphinx REQUIRED)\n,' docs/CMakeLists.txt
|
2021-01-22 11:25:31 +00:00
|
|
|
'' + lib.optionalString stdenv.hostPlatform.isMusl ''
|
2018-02-20 01:17:34 +00:00
|
|
|
sed -i -e 's/lgcc_s/lgcc_eh/' lib/Driver/ToolChains/*.cpp
|
2018-01-31 14:09:24 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
outputs = [ "out" "lib" "python" ];
|
|
|
|
|
|
|
|
# Clang expects to find LLVMgold in its own prefix
|
|
|
|
postInstall = ''
|
2018-04-17 15:50:21 +01:00
|
|
|
if [ -e ${llvm}/lib/LLVMgold.so ]; then
|
|
|
|
ln -sv ${llvm}/lib/LLVMgold.so $out/lib
|
|
|
|
fi
|
|
|
|
|
2018-01-31 14:09:24 +00:00
|
|
|
ln -sv $out/bin/clang $out/bin/cpp
|
|
|
|
|
|
|
|
# Move libclang to 'lib' output
|
|
|
|
moveToOutput "lib/libclang.*" "$lib"
|
|
|
|
substituteInPlace $out/lib/cmake/clang/ClangTargets-release.cmake \
|
|
|
|
--replace "\''${_IMPORT_PREFIX}/lib/libclang." "$lib/lib/libclang."
|
|
|
|
|
|
|
|
mkdir -p $python/bin $python/share/clang/
|
|
|
|
mv $out/bin/{git-clang-format,scan-view} $python/bin
|
|
|
|
if [ -e $out/bin/set-xcode-analyzer ]; then
|
|
|
|
mv $out/bin/set-xcode-analyzer $python/bin
|
|
|
|
fi
|
|
|
|
mv $out/share/clang/*.py $python/share/clang
|
|
|
|
rm $out/bin/c-index-test
|
|
|
|
'';
|
|
|
|
|
|
|
|
passthru = {
|
|
|
|
isClang = true;
|
|
|
|
inherit llvm;
|
|
|
|
};
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
description = "A c, c++, objective-c, and objective-c++ frontend for the llvm compiler";
|
2020-04-13 17:50:35 +01:00
|
|
|
homepage = "https://llvm.org/";
|
2021-01-22 11:25:31 +00:00
|
|
|
license = lib.licenses.ncsa;
|
|
|
|
platforms = lib.platforms.all;
|
2018-01-31 14:09:24 +00:00
|
|
|
};
|
2021-01-22 11:25:31 +00:00
|
|
|
} // lib.optionalAttrs enableManpages {
|
2019-08-14 15:07:30 +01:00
|
|
|
pname = "clang-manpages";
|
2018-01-31 14:09:24 +00:00
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
make docs-clang-man
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/share/man/man1
|
|
|
|
# Manually install clang manpage
|
|
|
|
cp docs/man/*.1 $out/share/man/man1/
|
|
|
|
'';
|
|
|
|
|
|
|
|
outputs = [ "out" ];
|
|
|
|
|
|
|
|
doCheck = false;
|
|
|
|
|
|
|
|
meta.description = "man page for Clang ${version}";
|
|
|
|
});
|
|
|
|
in self
|