1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
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 )
11 inherit cmake-utils llvm multiprocessing python-any-r1
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"
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[@]/%/?}
26 KEYWORDS="~amd64 ~arm ~x86"
27 IUSE="debug test ${ALL_LLVM_TARGETS[*]}"
28 RESTRICT="!test? ( test )"
31 >=dev-lang/ocaml-4.00.0:0=
33 ~sys-devel/llvm-${PV}:=[${LLVM_TARGET_USEDEPS// /,},debug?]
34 !sys-devel/llvm[ocaml(-)]"
35 # configparser-3.2 breaks the build (3.3 or none at all are fine)
39 test? ( dev-ml/ounit )
40 !!<dev-python/configparser-3.3.0.2
43 REQUIRED_USE="${PYTHON_REQUIRED_USE}
44 || ( ${ALL_LLVM_TARGETS[*]} )"
48 # least intrusive of all
49 CMAKE_BUILD_TYPE=RelWithDebInfo
52 LLVM_MAX_SLOT=${PV%%.*} llvm_pkg_setup
53 python-any-r1_pkg_setup
57 # Python is needed to run tests using lit
60 cmake-utils_src_prepare
64 local libdir=$(get_libdir)
66 -DLLVM_LIBDIR_SUFFIX=${libdir#lib}
68 -DBUILD_SHARED_LIBS=ON
69 -DLLVM_OCAML_OUT_OF_TREE=ON
70 -DLLVM_TARGETS_TO_BUILD="${LLVM_TARGETS// /;}"
71 -DLLVM_BUILD_TESTS=$(usex test)
73 # disable various irrelevant deps and settings
75 -DLLVM_ENABLE_TERMINFO=OFF
78 -DLLVM_ENABLE_ASSERTIONS=$(usex debug)
82 -DLLVM_HOST_TRIPLE="${CHOST}"
85 -DGO_EXECUTABLE=GO_EXECUTABLE-NOTFOUND
90 use test && mycmakeargs+=(
91 -DLLVM_LIT_ARGS="-vv;-j;${LIT_JOBS:-$(makeopts_jobs "${MAKEOPTS}" "$(get_nproc)")}"
94 # LLVM_ENABLE_ASSERTIONS=NO does not guarantee this for us, #614844
95 # also: custom rules for OCaml do not work for CPPFLAGS
96 use debug || local -x CFLAGS="${CFLAGS} -DNDEBUG"
97 cmake-utils_src_configure
99 local llvm_libdir=$(llvm-config --libdir)
100 # an ugly hack; TODO: figure out a way to pass -L to ocaml...
101 cd "${BUILD_DIR}/${libdir}" || die
102 ln -s "${llvm_libdir}"/*.so . || die
105 local llvm_bindir=$(llvm-config --bindir)
106 # Force using system-installed tools.
107 sed -i -e "/llvm_tools_dir/s@\".*\"@\"${llvm_bindir}\"@" \
108 "${BUILD_DIR}"/test/lit.site.cfg.py || die
113 cmake-utils_src_compile ocaml_all
118 local -x LIT_PRESERVES_TMP=1
119 cmake-utils_src_make check-llvm-bindings-ocaml
124 cmake -P "${BUILD_DIR}"/bindings/ocaml/cmake_install.cmake || die
126 dodoc bindings/ocaml/README.txt