lol
1{ stdenv, fetch, cmake, libxml2, libedit, llvm, version, clang-tools-extra_src }:
2let
3 gcc = if stdenv.cc.isGNU then stdenv.cc.cc else stdenv.cc.cc.gcc;
4in stdenv.mkDerivation {
5 name = "clang-${version}";
6
7 unpackPhase = ''
8 unpackFile ${fetch "cfe" "0846h8vn3zlc00jkmvrmy88gc6ql6014c02l4jv78fpvfigmgssg"}
9 mv cfe-${version}.src clang
10 sourceRoot=$PWD/clang
11 unpackFile ${clang-tools-extra_src}
12 mv clang-tools-extra-* $sourceRoot/tools/extra
13 '';
14
15 buildInputs = [ cmake libedit libxml2 llvm ];
16
17 cmakeFlags = [
18 "-DCMAKE_BUILD_TYPE=Release"
19 "-DCMAKE_CXX_FLAGS=-std=c++11"
20 ] ++
21 # Maybe with compiler-rt this won't be needed?
22 (stdenv.lib.optional stdenv.isLinux "-DGCC_INSTALL_PREFIX=${gcc}") ++
23 (stdenv.lib.optional (stdenv.cc.libc != null) "-DC_INCLUDE_DIRS=${stdenv.cc.libc}/include");
24
25 patches = [ ./clang-purity.patch ];
26
27 postPatch = ''
28 sed -i -e 's/Args.hasArg(options::OPT_nostdlibinc)/true/' lib/Driver/Tools.cpp
29 sed -i -e 's/DriverArgs.hasArg(options::OPT_nostdlibinc)/true/' lib/Driver/ToolChains.cpp
30 '';
31
32 # Clang expects to find LLVMgold in its own prefix
33 # Clang expects to find sanitizer libraries in its own prefix
34 postInstall = ''
35 ln -sv ${llvm}/lib/LLVMgold.so $out/lib
36 ln -sv ${llvm}/lib/clang/${version}/lib $out/lib/clang/${version}/
37 ln -sv $out/bin/clang $out/bin/cpp
38 '';
39
40 enableParallelBuilding = true;
41
42 passthru = {
43 isClang = true;
44 } // stdenv.lib.optionalAttrs stdenv.isLinux {
45 inherit gcc;
46 };
47
48 meta = {
49 description = "A c, c++, objective-c, and objective-c++ frontend for the llvm compiler";
50 homepage = http://llvm.org/;
51 license = stdenv.lib.licenses.bsd3;
52 platforms = stdenv.lib.platforms.all;
53 };
54}