gnu: Add python-click-log.
[jackhill/guix/guix.git] / gnu / packages / llvm.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014 Eric Bavier <bavier@member.fsf.org>
3 ;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
4 ;;; Copyright © 2015 Ludovic Courtès <ludo@gnu.org>
5 ;;;
6 ;;; This file is part of GNU Guix.
7 ;;;
8 ;;; GNU Guix is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
12 ;;;
13 ;;; GNU Guix is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
17 ;;;
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20
21 (define-module (gnu packages llvm)
22 #:use-module (guix packages)
23 #:use-module (guix licenses)
24 #:use-module (guix download)
25 #:use-module (guix utils)
26 #:use-module (guix build-system gnu)
27 #:use-module (guix build-system cmake)
28 #:use-module (gnu packages)
29 #:use-module (gnu packages gcc)
30 #:use-module (gnu packages bootstrap) ;glibc-dynamic-linker
31 #:use-module (gnu packages perl)
32 #:use-module (gnu packages python)
33 #:use-module (gnu packages xml))
34
35 (define-public llvm
36 (package
37 (name "llvm")
38 (version "3.6.2")
39 (source
40 (origin
41 (method url-fetch)
42 (uri (string-append "http://llvm.org/releases/"
43 version "/llvm-" version ".src.tar.xz"))
44 (sha256
45 (base32
46 "153vcvj8gvgwakzr4j0kndc0b7wn91c2g1vy2vg24s6spxcc23gn"))))
47 (build-system cmake-build-system)
48 (native-inputs
49 `(("python" ,python-wrapper)
50 ("perl" ,perl)))
51 (arguments
52 `(#:configure-flags '("-DCMAKE_SKIP_BUILD_RPATH=FALSE"
53 "-DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE")))
54 (home-page "http://www.llvm.org")
55 (synopsis "Optimizing compiler infrastructure")
56 (description
57 "LLVM is a compiler infrastructure designed for compile-time, link-time,
58 runtime, and idle-time optimization of programs from arbitrary programming
59 languages. It currently supports compilation of C and C++ programs, using
60 front-ends derived from GCC 4.0.1. A new front-end for the C family of
61 languages is in development. The compiler infrastructure includes mirror sets
62 of programming tools as well as libraries with equivalent functionality.")
63 (license ncsa)))
64
65 (define (clang-runtime-from-llvm llvm hash)
66 (package
67 (name "clang-runtime")
68 (version (package-version llvm))
69 (source
70 (origin
71 (method url-fetch)
72 (uri (string-append "http://llvm.org/releases/"
73 version "/compiler-rt-" version ".src.tar.xz"))
74 (sha256 (base32 hash))))
75 (build-system cmake-build-system)
76 (native-inputs (package-native-inputs llvm))
77 (inputs
78 `(("llvm" ,llvm)))
79 (arguments
80 `(;; Don't use '-g' during the build to save space.
81 #:build-type "Release"))
82
83 (home-page "http://compiler-rt.llvm.org")
84 (synopsis "Runtime library for Clang/LLVM")
85 (description
86 "The \"clang-runtime\" library provides the implementations of run-time
87 functions for C and C++ programs. It also provides header files that allow C
88 and C++ source code to interface with the \"sanitization\" passes of the clang
89 compiler. In LLVM this library is called \"compiler-rt\".")
90 (license ncsa)
91
92 ;; <http://compiler-rt.llvm.org/> doesn't list MIPS as supported.
93 (supported-systems (delete "mips64el-linux" %supported-systems))))
94
95 (define (clang-from-llvm llvm clang-runtime hash)
96 (package
97 (name "clang")
98 (version (package-version llvm))
99 (source
100 (origin
101 (method url-fetch)
102 (uri (string-append "http://llvm.org/releases/"
103 version "/cfe-" version ".src.tar.xz"))
104 (sha256 (base32 hash))
105 (patches (list (search-patch "clang-libc-search-path.patch")))))
106 ;; Using cmake allows us to treat llvm as an external library. There
107 ;; doesn't seem to be any way to do this with clang's autotools-based
108 ;; build system.
109 (build-system cmake-build-system)
110 (native-inputs (package-native-inputs llvm))
111 (inputs
112 `(("libxml2" ,libxml2)
113 ("gcc-lib" ,gcc "lib")
114 ,@(package-inputs llvm)))
115 (propagated-inputs
116 `(("llvm" ,llvm)
117 ("clang-runtime" ,clang-runtime)))
118 (arguments
119 `(#:configure-flags
120 (list "-DCLANG_INCLUDE_TESTS=True"
121
122 ;; Find libgcc_s, crtbegin.o, and crtend.o.
123 (string-append "-DGCC_INSTALL_PREFIX="
124 (assoc-ref %build-inputs "gcc-lib"))
125
126 ;; Use a sane default include directory.
127 (string-append "-DC_INCLUDE_DIRS="
128 (assoc-ref %build-inputs "libc")
129 "/include"))
130
131 ;; Don't use '-g' during the build to save space.
132 #:build-type "Release"
133
134 #:phases (modify-phases %standard-phases
135 (add-after
136 'unpack 'set-glibc-file-names
137 (lambda* (#:key inputs #:allow-other-keys)
138 (let ((libc (assoc-ref inputs "libc"))
139 (compiler-rt (assoc-ref inputs "clang-runtime")))
140 (substitute* "lib/Driver/Tools.cpp"
141 ;; Patch the 'getLinuxDynamicLinker' function to that
142 ;; it uses the right dynamic linker file name.
143 (("/lib64/ld-linux-x86-64.so.2")
144 (string-append libc
145 ,(glibc-dynamic-linker)))
146
147 ;; Link to libclang_rt files from clang-runtime.
148 (("TC\\.getDriver\\(\\)\\.ResourceDir")
149 (string-append "\"" compiler-rt "\"")))
150
151 ;; Same for libc's libdir, to allow crt1.o & co. to be
152 ;; found.
153 (substitute* "lib/Driver/ToolChains.cpp"
154 (("@GLIBC_LIBDIR@")
155 (string-append libc "/lib")))))))))
156
157 ;; Clang supports the same environment variables as GCC.
158 (native-search-paths
159 (list (search-path-specification
160 (variable "CPATH")
161 (files '("include")))
162 (search-path-specification
163 (variable "LIBRARY_PATH")
164 (files '("lib" "lib64")))))
165
166 (home-page "http://clang.llvm.org")
167 (synopsis "C language family frontend for LLVM")
168 (description
169 "Clang is a compiler front end for the C, C++, Objective-C and
170 Objective-C++ programming languages. It uses LLVM as its back end. The Clang
171 project includes the Clang front end, the Clang static analyzer, and several
172 code analysis tools.")
173 (license ncsa)))
174
175 (define-public clang-runtime
176 (clang-runtime-from-llvm
177 llvm
178 "11qx8d3pbfqjaj2x207pvlvzihbs1z2xbw4crpz7aid6h1yz6bqg"))
179
180 (define-public clang
181 (clang-from-llvm llvm clang-runtime
182 "1wwr8s6lzr324hv4s1k6na4j5zv6n9kdhi14s4kb9b13d93814df"))
183
184 (define-public llvm-3.5
185 (package (inherit llvm)
186 (version "3.5.0")
187 (source
188 (origin
189 (method url-fetch)
190 (uri (string-append "http://llvm.org/releases/"
191 version "/llvm-" version ".src.tar.xz"))
192 (sha256
193 (base32
194 "00swb43mzlvda8306arlg2jw7g6k3acwfccgf1k4c2pgd3rrkq98"))))))
195
196 (define-public clang-runtime-3.5
197 (clang-runtime-from-llvm
198 llvm-3.5
199 "0dl1kbrhz96djsxqr61iw5h788s7ncfpfb7aayixky1bhdaydcx4"))
200
201 (define-public clang-3.5
202 (clang-from-llvm llvm-3.5 clang-runtime-3.5
203 "12yv3jwdjcbkrx7zjm8wh4jrvb59v8fdw4mnmz3zc1jb00p9k07w"))