dev-ml/lablgtk: version bump to 2.18.10
[gentoo.git] / dev-ml / llvm-ocaml / llvm-ocaml-8.0.1.ebuild
1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5
6 : ${CMAKE_MAKEFILE_GENERATOR:=ninja}
7 # (needed due to CMAKE_BUILD_TYPE != Gentoo)
8 CMAKE_MIN_VERSION=3.7.0-r1
9 PYTHON_COMPAT=( python2_7 )
10
11 inherit cmake-utils llvm multiprocessing python-any-r1
12
13 MY_P=llvm-${PV/_/}.src
14 DESCRIPTION="OCaml bindings for LLVM"
15 HOMEPAGE="https://llvm.org/"
16 SRC_URI="https://github.com/llvm/llvm-project/releases/download/llvmorg-${PV}/${MY_P}.tar.xz"
17
18 # Keep in sync with sys-devel/llvm
19 ALL_LLVM_TARGETS=( AArch64 AMDGPU ARM BPF Hexagon Lanai Mips MSP430
20         NVPTX PowerPC Sparc SystemZ WebAssembly X86 XCore )
21 ALL_LLVM_TARGETS=( "${ALL_LLVM_TARGETS[@]/#/llvm_targets_}" )
22 LLVM_TARGET_USEDEPS=${ALL_LLVM_TARGETS[@]/%/?}
23
24 LICENSE="UoI-NCSA"
25 SLOT="0/${PV}"
26 KEYWORDS="~amd64 ~arm ~x86"
27 IUSE="debug test ${ALL_LLVM_TARGETS[*]}"
28 RESTRICT="!test? ( test )"
29
30 RDEPEND="
31         >=dev-lang/ocaml-4.00.0:0=
32         dev-ml/ocaml-ctypes:=
33         ~sys-devel/llvm-${PV}:=[${LLVM_TARGET_USEDEPS// /,},debug?]
34         !sys-devel/llvm[ocaml(-)]"
35 DEPEND="${RDEPEND}
36         dev-lang/perl
37         dev-ml/findlib
38         test? ( dev-ml/ounit )
39         ${PYTHON_DEPS}"
40
41 REQUIRED_USE="|| ( ${ALL_LLVM_TARGETS[*]} )"
42
43 S=${WORKDIR}/${MY_P}
44
45 # least intrusive of all
46 CMAKE_BUILD_TYPE=RelWithDebInfo
47
48 pkg_setup() {
49         LLVM_MAX_SLOT=${PV%%.*} llvm_pkg_setup
50         python-any-r1_pkg_setup
51 }
52
53 src_prepare() {
54         # Python is needed to run tests using lit
55         python_setup
56
57         cmake-utils_src_prepare
58 }
59
60 src_configure() {
61         local libdir=$(get_libdir)
62         local mycmakeargs=(
63                 -DLLVM_LIBDIR_SUFFIX=${libdir#lib}
64
65                 -DBUILD_SHARED_LIBS=ON
66                 -DLLVM_OCAML_OUT_OF_TREE=ON
67                 -DLLVM_TARGETS_TO_BUILD="${LLVM_TARGETS// /;}"
68                 -DLLVM_BUILD_TESTS=$(usex test)
69
70                 # disable various irrelevant deps and settings
71                 -DLLVM_ENABLE_FFI=OFF
72                 -DLLVM_ENABLE_TERMINFO=OFF
73                 -DHAVE_HISTEDIT_H=NO
74                 -DWITH_POLLY=OFF
75                 -DLLVM_ENABLE_ASSERTIONS=$(usex debug)
76                 -DLLVM_ENABLE_EH=ON
77                 -DLLVM_ENABLE_RTTI=ON
78
79                 -DLLVM_HOST_TRIPLE="${CHOST}"
80
81                 # disable go bindings
82                 -DGO_EXECUTABLE=GO_EXECUTABLE-NOTFOUND
83
84                 # TODO: ocamldoc
85         )
86
87         use test && mycmakeargs+=(
88                 -DLLVM_LIT_ARGS="-vv;-j;${LIT_JOBS:-$(makeopts_jobs "${MAKEOPTS}" "$(get_nproc)")}"
89         )
90
91         # LLVM_ENABLE_ASSERTIONS=NO does not guarantee this for us, #614844
92         # also: custom rules for OCaml do not work for CPPFLAGS
93         use debug || local -x CFLAGS="${CFLAGS} -DNDEBUG"
94         cmake-utils_src_configure
95
96         local llvm_libdir=$(llvm-config --libdir)
97         # an ugly hack; TODO: figure out a way to pass -L to ocaml...
98         cd "${BUILD_DIR}/${libdir}" || die
99         ln -s "${llvm_libdir}"/*.so . || die
100
101         if use test; then
102                 local llvm_bindir=$(llvm-config --bindir)
103                 # Force using system-installed tools.
104                 sed -i -e "/llvm_tools_dir/s@\".*\"@\"${llvm_bindir}\"@" \
105                         "${BUILD_DIR}"/test/lit.site.cfg.py || die
106         fi
107 }
108
109 src_compile() {
110         cmake-utils_src_compile ocaml_all
111 }
112
113 src_test() {
114         # respect TMPDIR!
115         local -x LIT_PRESERVES_TMP=1
116         cmake-utils_src_make check-llvm-bindings-ocaml
117 }
118
119 src_install() {
120         DESTDIR="${D}" \
121         cmake -P "${BUILD_DIR}"/bindings/ocaml/cmake_install.cmake || die
122
123         dodoc bindings/ocaml/README.txt
124 }