summaryrefslogtreecommitdiff
path: root/app-i18n/opencc/opencc-1.1.9.ebuild
blob: 2a29f72c76d764bffd4d3b227420cb6184a4c60f (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
# Copyright 2010-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

PYTHON_COMPAT=( python3_{13..14} )
DISTUTILS_EXT=1
DISTUTILS_OPTIONAL=1
DISTUTILS_SINGLE_IMPL=1
DISTUTILS_USE_PEP517=setuptools

inherit cmake distutils-r1

DESCRIPTION="Library for conversion between Traditional and Simplified Chinese characters"
HOMEPAGE="https://github.com/BYVoid/OpenCC"
SRC_URI="https://github.com/BYVoid/OpenCC/archive/ver.${PV}.tar.gz -> ${P}.tar.gz"
S="${WORKDIR}/OpenCC-ver.${PV}"

LICENSE="Apache-2.0"
SLOT="0/1.1"
KEYWORDS="amd64 arm64 ~hppa ~loong ppc ppc64 ~riscv x86"
IUSE="doc python test"
REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
RESTRICT="!test? ( test )"

RDEPEND="dev-libs/marisa
	python? ( ${PYTHON_DEPS} )
"
DEPEND="${RDEPEND}
	dev-cpp/tclap
	dev-libs/darts
	dev-libs/rapidjson
"
BDEPEND="${PYTHON_DEPS}
	doc? ( app-text/doxygen )
	python? (
		${DISTUTILS_DEPS}
		app-admin/chrpath
		$(python_gen_cond_dep 'dev-python/pybind11[${PYTHON_USEDEP}]')
		test? ( $(python_gen_cond_dep 'dev-python/pytest[${PYTHON_USEDEP}]') )
	)
	test? (
		dev-cpp/gtest
		!hppa? ( !sparc? ( dev-cpp/benchmark ) )
	)
"

DOCS=( AUTHORS NEWS.md README.md )

PATCHES=(
	"${FILESDIR}/${PN}-1.1.7-fix-missing-cstdint-for-gcc-15.patch"
	"${FILESDIR}/${PN}-marisa-0.3.0-cxx17.patch"
)

pkg_setup() {
	use python && python-single-r1_pkg_setup
}

src_prepare() {
	# as of opencc 1.1.8 there is no clean way to disable duplicated building of the clib again.
	# plus, the installation is broken as well.
	# let's revert the offending commit for now.
	eapply -R "${FILESDIR}/${P}-python.patch"

	rm -r deps || die

	sed -e "s:\${DIR_SHARE_OPENCC}/doc:share/doc/${PF}:" -i doc/CMakeLists.txt || die

	cmake_src_prepare
	use python && distutils-r1_src_prepare
}

src_configure() {
	local mycmakeargs=(
		-DBUILD_DOCUMENTATION=$(usex doc)
		-DBUILD_PYTHON=$(usex python)
		-DENABLE_BENCHMARK=$(if use test && has_version -d dev-cpp/benchmark; then echo ON; else echo OFF; fi)
		-DENABLE_GTEST=$(usex test)
		-DUSE_SYSTEM_DARTS=ON
		-DUSE_SYSTEM_GOOGLE_BENCHMARK=ON
		-DUSE_SYSTEM_GTEST=ON
		-DUSE_SYSTEM_MARISA=ON
		-DUSE_SYSTEM_PYBIND11=ON
		-DUSE_SYSTEM_RAPIDJSON=ON
		-DUSE_SYSTEM_TCLAP=ON
	)

	cmake_src_configure
	use python && distutils-r1_src_configure
}

src_compile() {
	cmake_src_compile
	if use python; then
		cp "${BUILD_DIR}"/opencc_clib.*.so python/opencc/clib/
		distutils-r1_src_compile
	fi
}

python_test() {
	epytest
}

src_test() {
	cmake_src_test
	if use python; then
		cd "${BUILD_DIR}_${EPYTHON}/install/usr/lib/${EPYTHON}/site-packages/opencc/clib" || die
		mkdir -p share/opencc || die
		cp "${S}/data/config"/*.json share/opencc/ || die
		pushd "${S}" || die

		distutils-r1_src_test

		popd || die
		rm -r share/ || die
	fi
}

src_install() {
	cmake_src_install
	if use python; then
		distutils-r1_src_install

		# Hack to make opencc's python binding to use system opencc's configs
		dodir "/usr/lib/${EPYTHON}/site-packages/opencc/clib/share"
		dosym -r /usr/share/opencc "/usr/lib/${EPYTHON}/site-packages/opencc/clib/share/opencc"

		# Remove insecure RPATH
		chrpath --delete "${ED}/usr/lib/${EPYTHON}/site-packages/opencc/clib"/*.so || die
	fi
}