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