kde-apps/ksirk: x86 stable (bug #661810)
[gentoo.git] / eclass / oasis.eclass
1 # Copyright 1999-2012 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: oasis.eclass
5 # @MAINTAINER:
6 # ml@gentoo.org
7 # @AUTHOR:
8 # Original Author: Alexis Ballier <aballier@gentoo.org>
9 # @BLURB: Provides common ebuild phases for oasis-based packages.
10 # @DESCRIPTION:
11 # Provides common ebuild phases for oasis-based packages.
12 # Most of these packages will just have to inherit the eclass, set their
13 # dependencies and the DOCS variable for base.eclass to install it and be done.
14 #
15 # It inherits multilib, findlib, eutils and base eclasses.
16 # Ebuilds using oasis.eclass must be EAPI>=3.
17
18 # @ECLASS-VARIABLE: OASIS_BUILD_DOCS
19 # @DESCRIPTION:
20 # Will make oasis_src_compile build the documentation if this variable is
21 # defined and the doc useflag is enabled.
22 # The eclass takes care of setting doc in IUSE but the ebuild should take care
23 # of the extra dependencies it may need.
24 # Set before inheriting the eclass.
25
26 # @ECLASS-VARIABLE: OASIS_BUILD_TESTS
27 # @DESCRIPTION:
28 # Will make oasis_src_configure enable building the tests if the test useflag is
29 # enabled. oasis_src_test will then run them.
30 # Note that you sometimes need to enable this for src_test to be useful,
31 # sometimes not. It has to be enabled on a per-case basis.
32 # The eclass takes care of setting test in IUSE but the ebuild should take care
33 # of the extra dependencies it may need.
34 # Set before inheriting the eclass.
35
36
37 # @ECLASS-VARIABLE: OASIS_NO_DEBUG
38 # @DESCRIPTION:
39 # Disable debug useflag usage. Old oasis versions did not support it so we allow
40 # disabling it in those cases.
41 # The eclass takes care of setting debug in IUSE.
42 # Set before inheriting the eclass.
43
44 # @ECLASS-VARIABLE: OASIS_DOC_DIR
45 # @DESCRIPTION:
46 # Specify where to install documentation. Default is for ocamldoc HTML.
47 # Change it before inherit if this is not what you want.
48 # EPREFIX is automatically prepended.
49 : ${OASIS_DOC_DIR:="/usr/share/doc/${PF}/html"}
50
51 inherit multilib findlib eutils base
52
53 case ${EAPI:-0} in
54         0|1|2) die "You need at least EAPI-3 to use oasis.eclass";;
55         3|4) RDEPEND=">=dev-lang/ocaml-3.12[ocamlopt?]";;
56         *) RDEPEND=">=dev-lang/ocaml-3.12:=[ocamlopt?]";;
57 esac
58
59 IUSE="+ocamlopt"
60 [ -n "${OASIS_NO_DEBUG}" ]   || IUSE="${IUSE} debug"
61 [ -n "${OASIS_BUILD_DOCS}" ] && IUSE="${IUSE} doc"
62 [ -n "${OASIS_BUILD_TESTS}" ] && IUSE="${IUSE} test"
63
64 DEPEND="${RDEPEND}
65         dev-ml/ocamlbuild"
66
67 # @FUNCTION: oasis_use_enable
68 # @USAGE: < useflag > < variable >
69 # @DESCRIPTION:
70 # A use_enable-like function for oasis configure variables.
71 # Outputs '--override variable (true|false)', whether useflag is enabled or
72 # not.
73 # Typical usage: $(oasis_use_enable ocamlopt is_native) as an oasis configure
74 # argument.
75 oasis_use_enable() {
76         echo "--override $2 $(usex $1 true false)"
77 }
78
79 # @FUNCTION: oasis_src_configure
80 # @DESCRIPTION:
81 # src_configure phase shared by oasis-based packages.
82 # Extra arguments may be passed via oasis_configure_opts.
83 oasis_src_configure() {
84         local confargs=""
85         [ -n "${OASIS_BUILD_TESTS}" ] && confargs="${confargs} $(use_enable test tests)"
86         [ -n "${OASIS_NO_DEBUG}"    ] || confargs="${confargs} $(oasis_use_enable debug debug)"
87         ${OASIS_SETUP_COMMAND:-ocaml setup.ml} -configure \
88                 --prefix "${ED}/usr" \
89                 --libdir "${ED}/usr/$(get_libdir)" \
90                 --docdir "${ED}${OASIS_DOC_DIR}" \
91                 $(oasis_use_enable ocamlopt is_native) \
92                 ${confargs} \
93                 ${oasis_configure_opts} \
94                 || die
95 }
96
97 # @FUNCTION: oasis_src_compile
98 # @DESCRIPTION:
99 # Builds an oasis-based package.
100 # Will build documentation if OASIS_BUILD_DOCS is defined and the doc useflag is
101 # enabled.
102 oasis_src_compile() {
103         ${OASIS_SETUP_COMMAND:-ocaml setup.ml} -build || die
104         if [ -n "${OASIS_BUILD_DOCS}" ] && use doc; then
105                 ocaml setup.ml -doc || die
106         fi
107 }
108
109 # @FUNCTION: oasis_src_test
110 # @DESCRIPTION:
111 # Runs the testsuite of an oasis-based package.
112 oasis_src_test() {
113          LD_LIBRARY_PATH="${S}/_build/lib" ${OASIS_SETUP_COMMAND:-ocaml setup.ml} -test || die
114 }
115
116 # @FUNCTION: oasis_src_install
117 # @DESCRIPTION:
118 # Installs an oasis-based package.
119 # It calls base_src_install_docs, so will install documentation declared in the
120 # DOCS variable.
121 oasis_src_install() {
122         findlib_src_preinst
123         ${OASIS_SETUP_COMMAND:-ocaml setup.ml} -install || die
124         base_src_install_docs
125 }
126
127 EXPORT_FUNCTIONS src_configure src_compile src_test src_install