@@ -0,0 +1,89 @@
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 ? true
18+}:
19+
20+let
21+ src = fetch "llvm" "0j49lkd5d7nnpdqzaybs2472bvcxyx0i4r3iccwf3kj2v9wk3iv6";
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: New LLVM releases require a newer OS X SDK than
39+ # 10.9. This is a temporary measure until nixpkgs darwin support is
40+ # updated.
41+ patchPhase = stdenv.lib.optionalString stdenv.isDarwin ''
42+ sed -i 's/os_trace(\(.*\)");$/printf(\1\\n");/g' ./projects/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc
43+ '';
44+
45+ # hacky fix: created binaries need to be run before installation
46+ preBuild = ''
47+ mkdir -p $out/
48+ ln -sv $PWD/lib $out
49+ '';
50+
51+ cmakeFlags = with stdenv; [
52+ "-DCMAKE_BUILD_TYPE=${if debugVersion then "Debug" else "Release"}"
53+ "-DLLVM_INSTALL_UTILS=ON" # Needed by rustc
54+ "-DLLVM_BUILD_TESTS=ON"
55+ "-DLLVM_ENABLE_FFI=ON"
56+ "-DLLVM_ENABLE_RTTI=ON"
57+ "-DCOMPILER_RT_INCLUDE_TESTS=OFF" # FIXME: requires clang source code
58+ ] ++ stdenv.lib.optional enableSharedLibraries [
59+ "-DLLVM_LINK_LLVM_DYLIB=ON"
60+ ] ++ stdenv.lib.optional (!isDarwin)
61+ "-DLLVM_BINUTILS_INCDIR=${binutils.dev}/include"
62+ ++ stdenv.lib.optionals ( isDarwin) [
63+ "-DLLVM_ENABLE_LIBCXX=ON"
64+ "-DCAN_TARGET_i386=false"
65+ ];
66+
67+ postBuild = ''
68+ rm -fR $out
69+
70+ paxmark m bin/{lli,llvm-rtdyld}
71+ '';
72+
73+ postInstall = stdenv.lib.optionalString (stdenv.isDarwin && enableSharedLibraries) ''
74+ install_name_tool -id $out/lib/libLLVM.dylib $out/lib/libLLVM.dylib
75+ ln -s $out/lib/libLLVM.dylib $out/lib/libLLVM-${version}.dylib
76+ '';
77+
78+ enableParallelBuilding = true;
79+
80+ passthru.src = src;
81+
82+ meta = {
83+ description = "Collection of modular and reusable compiler and toolchain technologies";
84+ homepage = http://llvm.org/;
85+ license = stdenv.lib.licenses.bsd3;
86+ maintainers = with stdenv.lib.maintainers; [ lovek323 raskin viric ];
87+ platforms = stdenv.lib.platforms.all;
88+ };
89+}