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

# @ECLASS: dune.eclass
# @MAINTAINER:
# rkitover@gmail.com
# Mark Wright <gienah@gentoo.org>
# ML <ml@gentoo.org>
# @AUTHOR:
# Rafael Kitover <rkitover@gmail.com>
# @SUPPORTED_EAPIS: 7 8
# @BLURB: Provides functions for installing Dune packages.
# @DESCRIPTION:
# Provides dependencies on Dune and OCaml and default src_compile, src_test and
# src_install for Dune-based packages.

case ${EAPI} in
	7|8) ;;
	*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
esac

if [[ ! ${_DUNE_ECLASS} ]]; then
_DUNE_ECLASS=1

# @ECLASS_VARIABLE: DUNE_PKG_NAME
# @PRE_INHERIT
# @DESCRIPTION:
# Sets the actual Dune package name, if different from Gentoo package name.
# Set before inheriting the eclass.
: ${DUNE_PKG_NAME:=${PN}}

inherit multiprocessing

# Do not complain about CFLAGS etc since ml projects do not use them.
QA_FLAGS_IGNORED='.*'

RDEPEND="
	>=dev-lang/ocaml-4:=[ocamlopt?]
	dev-ml/dune:=
"
DEPEND="${RDEPEND}"
BDEPEND="
	dev-lang/ocaml
	dev-ml/dune
"

dune_src_compile() {
	ebegin "Building"
	dune build @install -j $(makeopts_jobs) --profile release
	eend $? || die
}

dune_src_test() {
	ebegin "Testing"
	dune runtest -j $(makeopts_jobs) --profile release
	eend $? || die
}

# @FUNCTION: dune-install
# @USAGE: <list of packages>
# @DESCRIPTION:
# Installs the dune packages given as arguments. For each "${pkg}" element in
# that list, "${pkg}.install" must be readable from "${PWD}/_build/default"
#
# Example use:
# @CODE
# dune-install menhir menhirLib menhirSdk
# @CODE
dune-install() {
	local -a pkgs=( "${@}" )

	[[ ${#pkgs[@]} -eq 0 ]] && pkgs=( "${DUNE_PKG_NAME}" )

	local -a myduneopts=(
		--prefix="${ED}/usr"
		--libdir="${D}$(ocamlc -where)"
		--mandir="${ED}/usr/share/man"
	)

	local pkg
	for pkg in "${pkgs[@]}" ; do
		ebegin "Installing ${pkg}"
		dune install ${myduneopts[@]} ${pkg}
		eend $? || die

		# Move docs to the appropriate place.
		if [[ -d "${ED}/usr/doc/${pkg}" ]] ; then
			mkdir -p "${ED}/usr/share/doc/${PF}/" || die
			mv "${ED}/usr/doc/${pkg}" "${ED}/usr/share/doc/${PF}/" || die
			rm -rf "${ED}/usr/doc" || die
		fi
	done
}

dune_src_install() {
	dune-install ${1:-${DUNE_PKG_NAME}}
}

fi

EXPORT_FUNCTIONS src_compile src_test src_install