aboutsummaryrefslogtreecommitdiff
blob: bf30bdfb0c0e84cc807e937b0c7b9c52172d0e13 (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-2010 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

#
# Original Author: Rafael G. Martins <rafaelmartins@gentoo.org>
# Purpose: g-octave helper eclass.
#

# @ECLASS-VARIABLE: G_OCTAVE_CAT
# @DESCRIPTION:
# the octave-forge category of the package.
G_OCTAVE_CAT="${G_OCTAVE_CAT:-main}"


REPO_URI="https://octave.svn.sourceforge.net/svnroot/octave/trunk/octave-forge"
if [[ ${PV} = 9999* ]]; then
	inherit base subversion autotools
	ESVN_REPO_URI="${REPO_URI}/${G_OCTAVE_CAT}/${PN}"
else
	inherit base autotools
	SRC_URI="mirror://sourceforge/octave/${P}.tar.gz"
fi

SRC_URI="${SRC_URI}
	${REPO_URI}/packages/package_Makefile.in -> g-octave_Makefile
	${REPO_URI}/packages/package_configure.in -> g-octave_configure"

HOMEPAGE="http://www.g-octave.org/"
SLOT="0"
LICENSE="GPL-2"
DESCRIPTION="Based on the ${ECLASS} eclass"
RESTRICT="mirror"

# defining some paths
OCT_ROOT="/usr/share/octave"
OCT_PKGDIR="${OCT_ROOT}/packages"
OCT_BIN="$(type -p octave)"

EXPORT_FUNCTIONS src_prepare src_install pkg_postinst pkg_prerm pkg_postrm

g-octave_src_prepare() {
	if [ ! -d "${WORKDIR}/${P}" ]; then
		S="${WORKDIR}/${PN}"
		cd "${S}"
	fi
	[[ ${PV} = 9999* ]] && subversion_src_prepare
	for filename in Makefile configure; do
		cp "${DISTDIR}/g-octave_${filename}" "${S}/${filename}"
	done
	chmod 0755 "${S}/configure"
	if [ -e "${S}"/src/autogen.sh ]; then
		cd "${S}"/src && ./autogen.sh || die 'failed to run autogen.sh'
	fi
	if [ -e ${S}/src/Makefile ]; then
		sed -i 's/ -s / /g' ${S}/src/Makefile || die 'sed failed.'
	fi
	base_src_prepare
}

g-octave_src_install() {
	emake DESTDIR="${D}" DISTPKG='Gentoo' install
	if [ -d doc/ ]; then
		insinto /usr/share/doc/${PF}
		doins -r doc/* || die 'failed to install the docs'
	fi
}

g-octave_pkg_postinst() {
	einfo "Registering ${CATEGORY}/${PF} on the Octave package database."
	[ -d ${OCT_PKGDIR} ] || mkdir -p ${OCT_PKGDIR}
	${OCT_BIN} -H -q --no-site-file --eval "pkg('rebuild');" \
		&> /dev/null || die 'failed to register the package.'
}

g-octave_pkg_prerm() {
	einfo 'Running on_uninstall routines to prepare the package to remove.'
	local pkgdir=$(
		${OCT_BIN} -H -q --no-site-file --eval "
			pkg('rebuild');
			l = pkg('list');
			disp(l{cellfun(@(x)strcmp(x.name,'${PN}'),l)}.dir);
		"
	)
	rm -f "${pkgdir}"/packinfo/on_uninstall.m
	if [ -e "${pkgdir}"/packinfo/on_uninstall.m.orig ]; then
		mv "$pkgdir"/packinfo/on_uninstall.m{.orig,}
		cd "$pkgdir"/packinfo
		${OCT_BIN} -H -q --no-site-file --eval "
			l = pkg('list');
			on_uninstall(l{cellfun(@(x)strcmp(x.name,'${PN}'), l)});
		" &> /dev/null || die 'failed to remove the package'
	fi
}

g-octave_pkg_postrm() {
	einfo 'Rebuilding the Octave package database.'
	[ -d ${OCT_PKGDIR} ] || mkdir -p ${OCT_PKGDIR}
	${OCT_BIN} -H --silent --eval 'pkg rebuild' \
		&> /dev/null || die 'failed to rebuild the package database'
}