summaryrefslogtreecommitdiff
path: root/app-accessibility/espeak-ng/espeak-ng-9999.ebuild
blob: fe6458f011617b32b8c6e7db5a49452ef4ea7112 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# Copyright 1999-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

CMAKE_QA_COMPAT_SKIP=1 #android/jni/CMakeLists.txt
inherit cmake toolchain-funcs

MAN_VERS="1.51"
DESCRIPTION="Software speech synthesizer for English, and some other languages"
HOMEPAGE="https://github.com/espeak-ng/espeak-ng"

if [[ ${PV} == *9999* ]]; then
	EGIT_REPO_URI="https://github.com/espeak-ng/espeak-ng.git"
	inherit git-r3
elif [[ ${PV} == *_p* ]]; then
	HASH_COMMIT=""
	SRC_URI="https://github.com/espeak-ng/espeak-ng/archive/${HASH_COMMIT}.tar.gz -> ${P}.tar.gz"
	S="${WORKDIR}/${PN}-${HASH_COMMIT}"
else
	SRC_URI="https://github.com/espeak-ng/espeak-ng/archive/${PV}.tar.gz -> ${P}.tar.gz"
	KEYWORDS="~amd64 ~arm ~arm64 ~hppa ~loong ~ppc ~ppc64 ~riscv ~sparc ~x86"
fi

LICENSE="GPL-3+ unicode"
SLOT="0"
IUSE="+klatt mbrola sonic +sound test"
IUSE+=" l10n_ru l10n_zh"
RESTRICT="!test? ( test )"

DEPEND="
	mbrola? ( app-accessibility/mbrola )
	sonic? ( media-libs/sonic:= )
	sound? ( media-libs/pcaudiolib )
"
RDEPEND="${DEPEND}
	!app-accessibility/espeak
"
BDEPEND="virtual/pkgconfig"
if [[ ${PV} == *9999* ]]; then
	BDEPEND+=" app-text/ronn-ng"
fi

DOCS=( ChangeLog.md README.md docs )

src_prepare() {
	cmake_src_prepare

	if [[ ${PV} != *9999* ]]; then
		cp "${FILESDIR}"/${PN}.1-${MAN_VERS} "${S}"/docs/${PN}.1 || die
	fi

	if ! use klatt; then
		sed -e '/test_wav "en+klatt4"/d' -i tests/variants.test || die
	fi

	if ! use l10n_ru; then
		sed -e '/test_phon ru/d' -i tests/language-pronunciation.test || die
	fi

	if ! use l10n_zh; then
		sed -e '/test_phon cmn/d' -i tests/translate.test || die
	fi
}

src_configure() {
	_need_native() {
		if ! tc-is-cross-compiler; then
			return 1
		fi

		if ! has_version -b ">=${CATEGORY}/${P}"; then
			return 0
		fi

		if "${BROOT}"/usr/bin/espeak-ng --version &> /dev/null ; then
			return 2
		else
			return 0
		fi

		return 1
	}

	if _need_native; then
		einfo "Building native espeak-ng-bin for intonations..."

		BUILD_NATIVE="${WORKDIR}/${P}_build_native"
		local mycmakeargs=(
			-DCOMPILE_INTONATIONS=ON
			-DUSE_SPEECHPLAYER=OFF
			-DESPEAK_BUILD_MANPAGES=OFF
			-DSONIC_LIB=1
			-DSONIC_INC=1
			-DUSE_KLATT=OFF
			-DUSE_MBROLA=OFF
			-DUSE_LIBSONIC=OFF
			-DUSE_LIBPCAUDIO=OFF
			-DENABLE_TESTS=OFF
		)

		BUILD_DIR="${BUILD_NATIVE}" tc-env_build cmake_src_configure

		# create an empty program for now
		touch "${BUILD_NATIVE}"/src/espeak-ng || die
		# make it executable (CMP0109)
		chmod +x "${BUILD_NATIVE}"/src/espeak-ng || die
	fi

	# https://bugs.gentoo.org/836646
	export PULSE_SERVER=""

	local mycmakeargs=(
		-DBUILD_SHARED_LIBS=ON
		-DCOMPILE_INTONATIONS=ON
		# outdated, not packaged
		-DUSE_SPEECHPLAYER=OFF

		-DUSE_KLATT=$(usex klatt)
		-DUSE_MBROLA=$(usex mbrola)
		-DUSE_LIBSONIC=$(usex sonic)
		# or sonic will be fetched even if it's disabled
		# see also https://github.com/espeak-ng/espeak-ng/issues/2273
		$(usev !sonic '-DSONIC_LIB=1 -DSONIC_INC=1')
		-DUSE_LIBPCAUDIO=$(usex sound)
		-DENABLE_TESTS=$(usex test)

		# extended dictionaries
		-DEXTRA_ru=$(usex l10n_ru)
		-DEXTRA_cmn=$(usex l10n_zh)
		-DEXTRA_yue=$(usex l10n_zh)
	)

	if [[ ${PV} == *9999* ]]; then
		mycmakeargs+=( -DESPEAK_BUILD_MANPAGES=ON )
	else
		# use precompiled for releases
		mycmakeargs+=( -DESPEAK_BUILD_MANPAGES=OFF )
	fi

	_need_native
	case $? in
		0) mycmakeargs+=( -DNativeBuild_DIR="${BUILD_NATIVE}/src" ) ;;
		2) mycmakeargs+=( -DNativeBuild_DIR="${BROOT}/usr/bin" ) ;;
	esac

	cmake_src_configure
}

src_compile() {
	if _need_native; then
		BUILD_DIR="${BUILD_NATIVE}" tc-env_build cmake_build espeak-ng-bin
	fi

	cmake_src_compile
}

src_install() {
	cmake_src_install

	[[ ${PV} == *9999* ]] || doman docs/${PN}.1
}