@@ -0,0 +1,80 @@
1+{ stdenv
2+, fetch
3+, perl
4+, groff
5+, cmake
6+, python
7+, libffi
8+, binutils
9+, libxml2
10+, valgrind
11+, ncurses
12+, version
13+, zlib
14+, compiler-rt_src
15+, libcxxabi
16+, debugVersion ? false
17+, enableSharedLibraries ? !stdenv.isDarwin
18+}:
19+
20+let
21+ src = fetch "llvm" "0ikfq0gxac8xpvxj23l4hk8f12ydx48fljgrz1gl9xp0ks704nsm";
22+in stdenv.mkDerivation rec {
23+ name = "llvm-${version}";
24+
25+ unpackPhase = ''
26+ unpackFile ${src}
27+ mv llvm-${version}.src llvm
28+ sourceRoot=$PWD/llvm
29+ unpackFile ${compiler-rt_src}
30+ mv compiler-rt-* $sourceRoot/projects/compiler-rt
31+ '';
32+
33+ buildInputs = [ perl groff cmake libxml2 python libffi ]
34+ ++ stdenv.lib.optional stdenv.isDarwin libcxxabi;
35+
36+ propagatedBuildInputs = [ ncurses zlib ];
37+
38+ # hacky fix: created binaries need to be run before installation
39+ preBuild = ''
40+ mkdir -p $out/
41+ ln -sv $PWD/lib $out
42+ '';
43+
44+ cmakeFlags = with stdenv; [
45+ "-DCMAKE_BUILD_TYPE=${if debugVersion then "Debug" else "Release"}"
46+ "-DLLVM_INSTALL_UTILS=ON" # Needed by rustc
47+ "-DLLVM_BUILD_TESTS=ON"
48+ "-DLLVM_ENABLE_FFI=ON"
49+ "-DLLVM_ENABLE_RTTI=ON"
50+ ] ++ stdenv.lib.optional enableSharedLibraries [
51+ "-DLLVM_LINK_LLVM_DYLIB=ON"
52+ ] ++ stdenv.lib.optional (!isDarwin)
53+ "-DLLVM_BINUTILS_INCDIR=${binutils}/include"
54+ ++ stdenv.lib.optionals ( isDarwin) [
55+ "-DLLVM_ENABLE_LIBCXX=ON"
56+ "-DCAN_TARGET_i386=false"
57+ ];
58+
59+ postBuild = ''
60+ rm -fR $out
61+
62+ paxmark m bin/{lli,llvm-rtdyld}
63+
64+ paxmark m unittests/ExecutionEngine/JIT/JITTests
65+ paxmark m unittests/ExecutionEngine/MCJIT/MCJITTests
66+ paxmark m unittests/Support/SupportTests
67+ '';
68+
69+ enableParallelBuilding = true;
70+
71+ passthru.src = src;
72+
73+ meta = {
74+ description = "Collection of modular and reusable compiler and toolchain technologies";
75+ homepage = http://llvm.org/;
76+ license = stdenv.lib.licenses.bsd3;
77+ maintainers = with stdenv.lib.maintainers; [ lovek323 raskin viric ];
78+ platforms = stdenv.lib.platforms.all;
79+ };
80+}