summaryrefslogtreecommitdiff
blob: 5d965090b067c8e98d06702a3bb7164212411b92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# Copyright 1999-2016 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$

EAPI=6

: ${CMAKE_MAKEFILE_GENERATOR:=ninja}
CMAKE_MIN_VERSION=3.4.3
PYTHON_COMPAT=( python2_7 )

inherit check-reqs cmake-utils flag-o-matic git-r3 multilib-minimal \
	python-single-r1 toolchain-funcs pax-utils

DESCRIPTION="C language family frontend for LLVM"
HOMEPAGE="http://llvm.org/"
SRC_URI=""
EGIT_REPO_URI="http://llvm.org/git/clang.git
	https://github.com/llvm-mirror/clang.git"

LICENSE="UoI-NCSA"
SLOT="0/${PV%.*}"
KEYWORDS=""
IUSE="debug default-compiler-rt default-libcxx +doc multitarget python
	+static-analyzer test xml video_cards_radeon elibc_musl kernel_FreeBSD"

RDEPEND="
	~sys-devel/llvm-${PV}:=[debug=,multitarget?,video_cards_radeon?,${MULTILIB_USEDEP}]
	static-analyzer? ( dev-lang/perl:* )
	xml? ( dev-libs/libxml2:2=[${MULTILIB_USEDEP}] )
	!<sys-devel/llvm-${PV}
	${PYTHON_DEPS}"
# configparser-3.2 breaks the build (3.3 or none at all are fine)
DEPEND="${RDEPEND}
	doc? ( dev-python/sphinx )
	xml? ( virtual/pkgconfig )
	!!<dev-python/configparser-3.3.0.2
	${PYTHON_DEPS}"
PDEPEND="
	default-compiler-rt? ( sys-libs/compiler-rt )
	default-libcxx? ( sys-libs/libcxx )"

REQUIRED_USE="${PYTHON_REQUIRED_USE}"

pkg_pretend() {
	local build_size=650

	if use debug; then
		ewarn "USE=debug is known to increase the size of package considerably"
		ewarn "and cause the tests to fail."
		ewarn

		(( build_size *= 14 ))
	elif is-flagq '-g?(gdb)?([1-9])'; then
		ewarn "The C++ compiler -g option is known to increase the size of the package"
		ewarn "considerably. If you run out of space, please consider removing it."
		ewarn

		(( build_size *= 10 ))
	fi

	# Multiply by number of ABIs :).
	local abis=( $(multilib_get_enabled_abis) )
	(( build_size *= ${#abis[@]} ))

	local CHECKREQS_DISK_BUILD=${build_size}M
	check-reqs_pkg_pretend
}

pkg_setup() {
	pkg_pretend

	python-single-r1_pkg_setup
}

src_unpack() {
	git-r3_fetch "http://llvm.org/git/clang-tools-extra.git
		https://github.com/llvm-mirror/clang-tools-extra.git"
	git-r3_fetch

	git-r3_checkout http://llvm.org/git/clang-tools-extra.git \
		"${S}"/tools/clang/tools/extra
	git-r3_checkout
}

src_prepare() {
	python_setup

	# fix race condition between sphinx targets
	eapply "${FILESDIR}"/9999/0001-cmake-Add-ordering-dep-between-HTML-Sphinx-docs-and-.patch
	# automatically select active system GCC's libraries, bugs #406163 and #417913
	# TODO: cross-linux tests broken by this one
	eapply "${FILESDIR}"/9999/0002-driver-Support-obtaining-active-toolchain-from-gcc-c.patch
	# adjust llvm-lit search to match LLVM cmake macros
	eapply "${FILESDIR}"/9999/0004-cmake-Adjust-llvm-lit-search-to-match-the-one-in-LLV.patch
	# support overriding clang runtime install directory
	eapply "${FILESDIR}"/9999/0005-cmake-Supporting-overriding-runtime-libdir-via-CLANG.patch
	# support overriding LLVMgold.so plugin directory
	eapply "${FILESDIR}"/9999/0006-cmake-Add-CLANG_GOLD_LIBDIR_SUFFIX-to-specify-loc-of.patch
	# fix stand-alone doc build
	eapply "${FILESDIR}"/9999/0007-cmake-Support-stand-alone-Sphinx-doxygen-doc-build.patch

	# User patches
	eapply_user

	# Native libdir is used to hold LLVMgold.so
	NATIVE_LIBDIR=$(get_libdir)
}

multilib_src_configure() {
	local targets
	if use multitarget; then
		targets=all
	else
		targets='host;BPF'
		use video_cards_radeon && targets+=';AMDGPU'
	fi

	local libdir=$(get_libdir)
	local mycmakeargs=(
		-DLLVM_LIBDIR_SUFFIX=${libdir#lib}
		# install clang runtime straight into /usr/lib
		-DCLANG_LIBDIR_SUFFIX=""
		# specify host's binutils gold plugin path
		-DCLANG_GOLD_LIBDIR_SUFFIX="${NATIVE_LIBDIR#lib}"

		-DBUILD_SHARED_LIBS=ON
		-DLLVM_TARGETS_TO_BUILD="${targets}"
		# TODO: get them properly conditional
		#-DLLVM_BUILD_TESTS=$(usex test)

		-DCMAKE_DISABLE_FIND_PACKAGE_LibXml2=$(usex !xml)
		# libgomp support fails to find headers without explicit -I
		# furthermore, it provides only syntax checking
		-DCLANG_DEFAULT_OPENMP_RUNTIME=libomp

		# override default stdlib and rtlib
		-DCLANG_DEFAULT_CXX_STDLIB=$(usex default-libcxx libc++ "")
		-DCLANG_DEFAULT_RTLIB=$(usex default-compiler-rt compiler-rt "")

		-DCLANG_ENABLE_ARCMT=$(usex static-analyzer)
		-DCLANG_ENABLE_STATIC_ANALYZER=$(usex static-analyzer)
	)

	if multilib_is_native_abi; then
		mycmakeargs+=(
			# TODO: docs don't work out-of-llvm
			-DLLVM_BUILD_DOCS=$(usex doc)
			-DLLVM_ENABLE_SPHINX=$(usex doc)
			-DLLVM_ENABLE_DOXYGEN=OFF
			-DCLANG_INSTALL_HTML="${EPREFIX}/usr/share/doc/${PF}/clang"
			-DSPHINX_WARNINGS_AS_ERRORS=OFF
		)
	else
		mycmakeargs+=(
			-DLLVM_EXTERNAL_CLANG_TOOLS_EXTRA_BUILD=OFF
		)
	fi

	if tc-is-cross-compiler; then
		[[ -x "/usr/bin/clang-tblgen" ]] \
			|| die "/usr/bin/clang-tblgen not found or usable"
		mycmakeargs+=(
			-DCMAKE_CROSSCOMPILING=ON
			-DCLANG_TABLEGEN=/usr/bin/clang-tblgen
		)
	fi

	cmake-utils_src_configure
}

multilib_src_compile() {
	cmake-utils_src_compile
}

multilib_src_test() {
	# respect TMPDIR!
	local -x LIT_PRESERVES_TMP=1
	cmake-utils_src_make check-clang
}

src_install() {
	# note: magic applied in multilib_src_install()!
	CLANG_VERSION=4.0

	MULTILIB_CHOST_TOOLS=(
		/usr/bin/clang
		/usr/bin/clang++
		/usr/bin/clang-cl
		/usr/bin/clang-${CLANG_VERSION}
		/usr/bin/clang++-${CLANG_VERSION}
		/usr/bin/clang-cl-${CLANG_VERSION}
	)

	MULTILIB_WRAPPED_HEADERS=(
		/usr/include/clang/Config/config.h
	)

	multilib-minimal_src_install

	# Remove unnecessary headers on FreeBSD, bug #417171
	if use kernel_FreeBSD && use clang; then
		rm "${ED}"usr/lib/clang/${PV}/include/{std,float,iso,limits,tgmath,varargs}*.h || die
	fi
}

multilib_src_install() {
	cmake-utils_src_install

	# apply CHOST and CLANG_VERSION to clang executables
	# they're statically linked so we don't have to worry about the lib
	local clang_tools=( clang clang++ clang-cl )
	local i

	# cmake gives us:
	# - clang-X.Y
	# - clang -> clang-X.Y
	# - clang++, clang-cl -> clang
	# we want to have:
	# - clang-X.Y
	# - clang++-X.Y, clang-cl-X.Y -> clang-X.Y
	# - clang, clang++, clang-cl -> clang*-X.Y
	# so we need to fix the two tools
	for i in "${clang_tools[@]:1}"; do
		rm "${ED%/}/usr/bin/${i}" || die
		dosym "clang-${CLANG_VERSION}" "/usr/bin/${i}-${CLANG_VERSION}"
		dosym "${i}-${CLANG_VERSION}" "/usr/bin/${i}"
	done

	# now prepend ${CHOST} and let the multilib-build.eclass symlink it
	if ! multilib_is_native_abi; then
		# non-native? let's replace it with a simple wrapper
		for i in "${clang_tools[@]}"; do
			rm "${ED%/}/usr/bin/${i}-${CLANG_VERSION}" || die
			cat > "${T}"/wrapper.tmp <<-_EOF_
				#!${EPREFIX}/bin/sh
				exec "${i}-${CLANG_VERSION}" $(get_abi_CFLAGS) "\${@}"
			_EOF_
			newbin "${T}"/wrapper.tmp "${i}-${CLANG_VERSION}"
		done
	fi
}

multilib_src_install_all() {
	if use python ; then
		pushd bindings/python/clang >/dev/null || die

		python_moduleinto clang
		python_domodule *.py

		popd >/dev/null || die
	fi

	python_fix_shebang "${ED}"
	if use static-analyzer; then
		python_optimize "${ED}"usr/share/scan-view
	fi
}

pkg_postinst() {
	if ! has_version 'sys-libs/libomp'; then
		elog "To enable OpenMP support in clang, install sys-libs/libomp."
	fi
}