summaryrefslogtreecommitdiff
blob: 5714ae9b7198f92c5e5715757f5978dd478f8f39 (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
# Copyright 1999-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=7

inherit cmake

DESCRIPTION="Radeon Open Compute llvm,lld,clang"
HOMEPAGE="https://github.com/RadeonOpenCompute/ROCm/"
SRC_URI="https://github.com/RadeonOpenCompute/llvm-project/archive/rocm-${PV}.tar.gz -> llvm-rocm-ocl-${PV}.tar.gz"

LICENSE="UoI-NCSA rc BSD public-domain"
SLOT="0"
KEYWORDS="~amd64"
IUSE="debug +runtime"

RDEPEND="virtual/cblas
	dev-libs/libxml2
	sys-libs/zlib
	sys-libs/ncurses:="
DEPEND="${RDEPEND}"
PDEPEND="dev-libs/rocr-runtime"

S="${WORKDIR}/llvm-project-rocm-${PV}/llvm"

PATCHES=(
	"${FILESDIR}/${PN}-3.7.0-current_pos.patch"
	"${FILESDIR}/${PN}-3.9.0-tensorflow.patch"
)

CMAKE_BUILD_TYPE=RelWithDebInfo

src_prepare() {
	cd "${WORKDIR}/llvm-project-rocm-${PV}" || die
	eapply "${FILESDIR}/${PN}-3.0.0-add_libraries.patch"
	eapply "${FILESDIR}/${PN}-4.0.0-remove-isystem-usr-include.patch"
	eapply "${FILESDIR}/${PN}-4.0.0-hip-location.patch"

	if [[ -n ${EPREFIX} ]]; then
		pushd "${S}"/../clang >/dev/null || die
		sed -i -e "s@DEFAULT_SYSROOT \"\"@DEFAULT_SYSROOT \"${EPREFIX}\"@" CMakeLists.txt
		eend $?
		ebegin "Use ${EPREFIX} as default sysroot"
		cd lib/Driver/ToolChains >/dev/null || die
		ebegin "Use dynamic linker from ${EPREFIX}"
		sed -i -e "/LibDir.*Loader/s@return \"\/\"@return \"${EPREFIX}/\"@" Linux.cpp
		eend $?

		ebegin "Remove --sysroot call on ld for native toolchain"
		sed -i -e "$(grep -n -B1 sysroot= Gnu.cpp | sed -ne '{1s/-.*//;1p}'),+1 d" Gnu.cpp
		eend $?
		popd >/dev/null || die
	fi

	# handled by sysroot, don't prefixify here.
	sed -e 's:/opt/rocm:/usr/lib/hip:' \
		-i "${S}"/../clang/lib/Driver/ToolChains/AMDGPU.cpp

	eapply_user
	cmake_src_prepare
}

src_configure() {
	PROJECTS="clang;lld"

	if usex runtime; then
		PROJECTS+=";compiler-rt"
	fi

	local mycmakeargs=(
		-DCMAKE_INSTALL_PREFIX="${EPREFIX}/usr/lib/llvm/roc"
		-DLLVM_ENABLE_PROJECTS="${PROJECTS}"
		-DLLVM_TARGETS_TO_BUILD="AMDGPU;X86"
		-DLLVM_BUILD_DOCS=NO
		-DLLVM_ENABLE_OCAMLDOC=OFF
		-DLLVM_ENABLE_SPHINX=NO
		-DLLVM_ENABLE_DOXYGEN=OFF
		-DLLVM_INSTALL_UTILS=ON
		-DLLVM_VERSION_SUFFIX=roc
		-DOCAMLFIND=NO
	)

	use debug || local -x CPPFLAGS="${CPPFLAGS} -DNDEBUG"

	cmake_src_configure
}

src_install() {
	cmake_src_install
	cat > "99${PN}" <<-EOF
		LDPATH="${EROOT}/usr/lib/llvm/roc/lib"
	EOF
	doenvd "99${PN}"
}