net-misc/rustdesk: update deps
[gentoo-zh.git] / app-i18n / mozc / mozc-2.28.5029.102.ebuild
blobd3c942034e7b6a27767e3c869772b3e5215f5844
1 # Copyright 2010-2023 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
4 EAPI="8"
6 PYTHON_COMPAT=( python3_{10..11} )
8 inherit desktop edo elisp-common multiprocessing python-any-r1 savedconfig toolchain-funcs xdg
10 if [[ "${PV}" == "9999" ]]; then
11 inherit git-r3
13 EGIT_REPO_URI="https://github.com/google/mozc"
14 EGIT_SUBMODULES=(src/third_party/japanese_usage_dictionary)
15 else
16 MOZC_GIT_REVISION="305e9a7374254148474d067c46d55a4ee6081837"
17 MOZC_DATE="${PV#*_p}"
18 MOZC_DATE="${MOZC_DATE%%_p*}"
20 FCITX_MOZC_GIT_REVISION="242b4f703cba27d4ff4dc123c713a478f964e001"
21 FCITX_MOZC_DATE="${PV#*_p}"
22 FCITX_MOZC_DATE="${FCITX_MOZC_DATE#*_p}"
23 FCITX_MOZC_DATE="${FCITX_MOZC_DATE%%_p*}"
25 JAPANESE_USAGE_DICTIONARY_GIT_REVISION="a4a66772e33746b91e99caceecced9a28507e925"
26 JAPANESE_USAGE_DICTIONARY_DATE="20180701040110"
29 DESCRIPTION="Mozc - Japanese input method editor"
30 HOMEPAGE="https://github.com/google/mozc"
31 if [[ "${PV}" == "9999" ]]; then
32 SRC_URI=""
33 else
34 SRC_URI="
35 https://github.com/google/${PN}/archive/${MOZC_GIT_REVISION}.tar.gz -> ${PN}-${PV%%_p*}-${MOZC_DATE}.tar.gz
36 https://github.com/hiroyuki-komatsu/japanese-usage-dictionary/archive/${JAPANESE_USAGE_DICTIONARY_GIT_REVISION}.tar.gz -> japanese-usage-dictionary-${JAPANESE_USAGE_DICTIONARY_DATE}.tar.gz
37 https://dev.gentoo.org/~sam/distfiles/${CATEGORY}/${PN}/${PN}-2.28.5029.102-patches.tar.xz
38 https://github.com/fcitx/${PN}/archive/${FCITX_MOZC_GIT_REVISION}.tar.gz -> fcitx-${PN}-${PV%%_p*}-${FCITX_MOZC_DATE}.tar.gz
42 # Mozc: BSD
43 # src/data/dictionary_oss: ipadic, public-domain
44 # src/data/unicode: unicode
45 # japanese-usage-dictionary: BSD-2
46 LICENSE="BSD BSD-2 ipadic public-domain unicode"
47 SLOT="0"
48 KEYWORDS="~amd64 ~arm64 ~x86"
49 IUSE="debug emacs fcitx4 fcitx5 +gui ibus renderer test"
50 REQUIRED_USE="|| ( emacs fcitx4 fcitx5 ibus )"
51 RESTRICT="!test? ( test )"
53 BDEPEND="
54 $(python_gen_any_dep 'dev-python/six[${PYTHON_USEDEP}]')
55 >=dev-libs/protobuf-3.0.0
56 dev-util/gyp
57 dev-util/ninja
58 virtual/pkgconfig
59 emacs? ( app-editors/emacs:* )
60 fcitx4? ( sys-devel/gettext )
61 fcitx5? ( sys-devel/gettext )
63 DEPEND="
64 >=dev-cpp/abseil-cpp-20211102.0-r2:=[cxx17(+)]
65 >=dev-libs/protobuf-3.0.0:=
66 fcitx4? (
67 app-i18n/fcitx:4
68 virtual/libintl
70 fcitx5? (
71 app-i18n/fcitx:5
72 app-i18n/libime
73 sys-devel/gettext
74 virtual/libintl
76 gui? (
77 dev-qt/qtcore:5
78 dev-qt/qtgui:5
79 dev-qt/qtwidgets:5
81 ibus? (
82 >=app-i18n/ibus-1.4.1
83 dev-libs/glib:2
84 x11-libs/libxcb
86 renderer? (
87 dev-libs/glib:2
88 x11-libs/cairo
89 x11-libs/gtk+:2
90 x11-libs/pango
92 test? (
93 >=dev-cpp/gtest-1.8.0
94 dev-libs/jsoncpp
96 RDEPEND="
97 >=dev-cpp/abseil-cpp-20211102.0-r2:=[cxx17(+)]
98 >=dev-libs/protobuf-3.0.0:=
99 emacs? ( app-editors/emacs:* )
100 fcitx4? (
101 app-i18n/fcitx:4
102 virtual/libintl
104 fcitx5? (
105 app-i18n/fcitx:5
106 app-i18n/libime
107 sys-devel/gettext
108 virtual/libintl
110 gui? (
111 dev-qt/qtcore:5
112 dev-qt/qtgui:5
113 dev-qt/qtwidgets:5
115 ibus? (
116 >=app-i18n/ibus-1.4.1
117 dev-libs/glib:2
118 x11-libs/libxcb
120 renderer? (
121 dev-libs/glib:2
122 x11-libs/cairo
123 x11-libs/gtk+:2
124 x11-libs/pango
128 S="${WORKDIR}/${P}/src"
130 SITEFILE="50${PN}-gentoo.el"
132 PATCHES=(
133 "${WORKDIR}"/mozc-2.28.5029.102-patches
134 "${FILESDIR}"/mozc-2.28.5029.102-abseil.patch
137 python_check_deps() {
138 python_has_version "dev-python/six[${PYTHON_USEDEP}]"
141 src_unpack() {
142 if [[ "${PV}" == "9999" ]]; then
143 git-r3_src_unpack
145 if use fcitx4 || fcitx5; then
146 local EGIT_SUBMODULES=()
147 git-r3_fetch https://github.com/fcitx/mozc refs/heads/fcitx
148 git-r3_checkout https://github.com/fcitx/mozc "${WORKDIR}/fcitx-mozc"
150 if use fcitx5; then
151 cp -pr "${WORKDIR}/fcitx5-mozc/src/unix/fcitx5" unix || die
153 else
154 unpack ${PN}-${PV%%_p*}-${MOZC_DATE}.tar.gz
155 mv mozc-${MOZC_GIT_REVISION} ${P} || die
157 unpack ${PN}-2.28.5029.102-patches.tar.xz
159 unpack japanese-usage-dictionary-${JAPANESE_USAGE_DICTIONARY_DATE}.tar.gz
160 cp -p japanese-usage-dictionary-${JAPANESE_USAGE_DICTIONARY_GIT_REVISION}/usage_dict.txt ${P}/src/third_party/japanese_usage_dictionary || die
162 unpack fcitx-${PN}-${PV%%_p*}-${FCITX_MOZC_DATE}.tar.gz
163 if use fcitx4; then
164 cp -pr mozc-${FCITX_MOZC_GIT_REVISION} fcitx-${PN} || die
166 if use fcitx5; then
167 cp -pr mozc-${FCITX_MOZC_GIT_REVISION} fcitx5-${PN} || die
172 src_prepare() {
173 if use fcitx4; then
174 cp -pr "${WORKDIR}/fcitx-mozc/src/unix/fcitx" unix || die
176 if use fcitx5; then
177 cp -pr "${WORKDIR}/fcitx5-mozc/src/unix/fcitx5" unix || die
180 pushd "${WORKDIR}/${P}" > /dev/null || die
181 default
182 popd > /dev/null || die
184 sed \
185 -e "s/def GypMain(options, unused_args):/def GypMain(options, gyp_args):/" \
186 -e "s/RunOrDie(gyp_command + gyp_options)/RunOrDie(gyp_command + gyp_options + gyp_args)/" \
187 -e "s/RunOrDie(\[ninja/&, '-j$(makeopts_jobs "${MAKEOPTS}" 999)', '-l$(makeopts_loadavg "${MAKEOPTS}" 0)', '-v'/" \
188 -i build_mozc.py || die
190 local ar=($(tc-getAR))
191 local cc=($(tc-getCC))
192 local cxx=($(tc-getCXX))
193 local ld=($(tc-getLD))
194 local nm=($(tc-getNM))
195 local readelf=($(tc-getREADELF))
197 # Use absolute paths. Non-absolute paths are mishandled by GYP.
198 ar[0]=$(type -P ${ar[0]})
199 cc[0]=$(type -P ${cc[0]})
200 cxx[0]=$(type -P ${cxx[0]})
201 ld[0]=$(type -P ${ld[0]})
202 nm[0]=$(type -P ${nm[0]})
203 readelf[0]=$(type -P ${readelf[0]})
205 sed \
206 -e "s:<!(which ar):${ar[@]}:" \
207 -e "s:<!(which clang):${cc[@]}:" \
208 -e "s:<!(which clang++):${cxx[@]}:" \
209 -e "s:<!(which ld):${ld[@]}:" \
210 -e "s:<!(which nm):${nm[@]}:" \
211 -e "s:<!(which readelf):${readelf[@]}:" \
212 -i gyp/common.gypi || die
214 # https://github.com/google/mozc/issues/489
215 sed \
216 -e "/'-lc++'/d" \
217 -e "/'-stdlib=libc++'/d" \
218 -i gyp/common.gypi || die
220 # bug #877765
221 restore_config mozcdic-ut.txt
222 if [[ -f /mozcdic-ut.txt && -s mozcdic-ut.txt ]]; then
223 einfo "mozcdic-ut.txt found. Adding to mozc dictionary..."
224 cat mozcdic-ut.txt >> "${WORKDIR}/${P}/src/data/dictionary_oss/dictionary00.txt" || die
228 src_configure() {
229 if use debug; then
230 BUILD_TYPE="Debug"
231 else
232 BUILD_TYPE="Release"
235 local gyp_arguments=()
237 if tc-is-gcc; then
238 gyp_arguments+=(-D compiler_host=gcc -D compiler_target=gcc)
239 elif tc-is-clang; then
240 gyp_arguments+=(-D compiler_host=clang -D compiler_target=clang)
241 else
242 gyp_arguments+=(-D compiler_host=unknown -D compiler_target=unknown)
245 gyp_arguments+=(-D debug_extra_cflags=)
246 gyp_arguments+=(-D release_extra_cflags=)
248 gyp_arguments+=(-D use_fcitx=$(usex fcitx4 YES NO))
249 gyp_arguments+=(-D use_fcitx5=$(usex fcitx5 YES NO))
250 gyp_arguments+=(-D use_libibus=$(usex ibus 1 0))
251 gyp_arguments+=(-D use_libprotobuf=1)
252 gyp_arguments+=(-D use_system_abseil_cpp=1)
253 gyp_arguments+=(-D use_system_gtest=$(usex test 1 0))
254 gyp_arguments+=(-D use_system_jsoncpp=$(usex test 1 0))
255 gyp_arguments+=(-D enable_gtk_renderer=$(usex renderer 1 0))
257 gyp_arguments+=(-D server_dir="${EPREFIX}/usr/libexec/mozc")
258 gyp_arguments+=(-D document_dir="${EPREFIX}/usr/libexec/mozc/documents")
260 if use ibus; then
261 gyp_arguments+=(-D ibus_mozc_path="${EPREFIX}/usr/libexec/ibus-engine-mozc")
262 gyp_arguments+=(-D ibus_mozc_icon_path="${EPREFIX}/usr/share/ibus-mozc/product_icon.png")
265 unset AR CC CXX LD NM READELF
267 edo "${PYTHON}" build_mozc.py gyp \
268 --gypdir="${EPREFIX}/usr/bin" \
269 --server_dir="${EPREFIX}/usr/libexec/mozc" \
270 --verbose \
271 $(usex gui "" --noqt) \
272 -- "${gyp_arguments[@]}"
275 src_compile() {
276 local targets=(server/server.gyp:mozc_server)
277 if use emacs; then
278 targets+=(unix/emacs/emacs.gyp:mozc_emacs_helper)
280 if use fcitx4; then
281 targets+=(unix/fcitx/fcitx.gyp:fcitx-mozc)
283 if use fcitx5; then
284 targets+=(unix/fcitx5/fcitx5.gyp:fcitx5-mozc)
286 if use gui; then
287 targets+=(gui/gui.gyp:mozc_tool)
289 if use ibus; then
290 targets+=(unix/ibus/ibus.gyp:ibus_mozc)
292 if use renderer; then
293 targets+=(renderer/renderer.gyp:mozc_renderer)
295 if use test; then
296 targets+=(gyp/tests.gyp:unittests)
299 if use ibus; then
300 GYP_IBUS_FLAG="--use_gyp_for_ibus_build"
303 edo "${PYTHON}" build_mozc.py build -c ${BUILD_TYPE} ${GYP_IBUS_FLAG} -v "${targets[@]}"
305 if use emacs; then
306 elisp-compile unix/emacs/*.el
310 src_test() {
311 edo "${PYTHON}" build_mozc.py runtests -c ${BUILD_TYPE} --test_jobs 1
314 src_install() {
315 exeinto /usr/libexec/mozc
316 doexe out_linux/${BUILD_TYPE}/mozc_server
318 [[ -s mozcdic-ut.txt ]] && save_config mozcdic-ut.txt
320 if use gui; then
321 doexe out_linux/${BUILD_TYPE}/mozc_tool
324 if use renderer; then
325 doexe out_linux/${BUILD_TYPE}/mozc_renderer
328 insinto /usr/libexec/mozc/documents
329 doins data/installer/credits_en.html
331 if use emacs; then
332 dobin out_linux/${BUILD_TYPE}/mozc_emacs_helper
333 elisp-install ${PN} unix/emacs/*.{el,elc}
334 elisp-site-file-install "${FILESDIR}/${SITEFILE}" ${PN}
337 if use fcitx4; then
338 exeinto /usr/$(get_libdir)/fcitx
339 doexe out_linux/${BUILD_TYPE}/fcitx-mozc.so
341 insinto /usr/share/fcitx/addon
342 doins unix/fcitx/fcitx-mozc.conf
344 insinto /usr/share/fcitx/inputmethod
345 doins unix/fcitx/mozc.conf
347 insinto /usr/share/fcitx/mozc/icon
348 newins data/images/product_icon_32bpp-128.png mozc.png
349 local image
350 for image in ../../fcitx-${PN}/src/data/images/unix/ui-*.png; do
351 newins "${image}" "mozc-${image#../../fcitx-${PN}/src/data/images/unix/ui-}"
352 done
354 local locale mo_file
355 for mo_file in out_linux/${BUILD_TYPE}/gen/unix/fcitx/po/*.mo; do
356 locale="${mo_file##*/}"
357 locale="${locale%.mo}"
358 insinto /usr/share/locale/${locale}/LC_MESSAGES
359 newins "${mo_file}" fcitx-mozc.mo
360 done
363 if use fcitx5; then
364 exeinto /usr/$(get_libdir)/fcitx5
365 doexe out_linux/${BUILD_TYPE}/fcitx5-mozc.so
367 insinto /usr/share/fcitx5/addon
368 newins unix/fcitx5/mozc-addon.conf mozc.conf
370 insinto /usr/share/fcitx5/inputmethod
371 doins unix/fcitx5/mozc.conf
373 local orgfcitx5="org.fcitx.Fcitx5.fcitx-mozc"
374 newicon -s 128 data/images/product_icon_32bpp-128.png ${orgfcitx5}.png
375 newicon -s 128 data/images/product_icon_32bpp-128.png fcitx-mozc.png
376 newicon -s 32 data/images/unix/ime_product_icon_opensource-32.png ${orgfcitx5}.png
377 newicon -s 32 data/images/unix/ime_product_icon_opensource-32.png fcitx-mozc.png
378 for uiimg in ../../fcitx5-mozc/scripts/icons/ui-*.png; do
379 dimg=${uiimg#*ui-}
380 newicon -s 48 ${uiimg} ${orgfcitx5}-${dimg/_/-}
381 newicon -s 48 ${uiimg} fcitx-mozc-${dimg/_/-}
382 done
384 local locale mo_file
385 for mo_file in unix/fcitx5/po/*.po; do
386 locale="${mo_file##*/}"
387 locale="${locale%.po}"
388 msgfmt ${mo_file} -o ${mo_file/.po/.mo} || die
389 insinto /usr/share/locale/${locale}/LC_MESSAGES
390 newins "${mo_file/.po/.mo}" fcitx5-mozc.mo
391 done
392 msgfmt --xml -d unix/fcitx5/po/ --template unix/fcitx5/org.fcitx.Fcitx5.Addon.Mozc.metainfo.xml.in -o \
393 unix/fcitx5/org.fcitx.Fcitx5.Addon.Mozc.metainfo.xml || die
394 insinto /usr/share/metainfo
395 doins unix/fcitx5/org.fcitx.Fcitx5.Addon.Mozc.metainfo.xml
398 if use ibus; then
399 exeinto /usr/libexec
400 newexe out_linux/${BUILD_TYPE}/ibus_mozc ibus-engine-mozc
402 insinto /usr/share/ibus/component
403 doins out_linux/${BUILD_TYPE}/gen/unix/ibus/mozc.xml
405 insinto /usr/share/ibus-mozc
406 newins data/images/unix/ime_product_icon_opensource-32.png product_icon.png
407 local image
408 for image in data/images/unix/ui-*.png; do
409 newins "${image}" "${image#data/images/unix/ui-}"
410 done
414 pkg_postinst() {
415 elog
416 elog "ENVIRONMENTAL VARIABLES"
417 elog
418 elog "MOZC_SERVER_DIRECTORY"
419 elog " Mozc server directory"
420 elog " Value used by default: \"${EPREFIX}/usr/libexec/mozc\""
421 elog "MOZC_DOCUMENTS_DIRECTORY"
422 elog " Mozc documents directory"
423 elog " Value used by default: \"${EPREFIX}/usr/libexec/mozc/documents\""
424 elog "MOZC_CONFIGURATION_DIRECTORY"
425 elog " Mozc configuration directory"
426 elog " Value used by default: \"~/.mozc\""
427 elog
428 if use emacs; then
429 elog
430 elog "USAGE IN EMACS"
431 elog
432 elog "mozc-mode is minor mode to input Japanese text using Mozc server."
433 elog "mozc-mode can be used via LEIM (Library of Emacs Input Method)."
434 elog
435 elog "In order to use mozc-mode by default, the following settings should be added to"
436 elog "Emacs init file (~/.emacs.d/init.el or ~/.emacs):"
437 elog
438 elog " (require 'mozc)"
439 elog " (set-language-environment \"Japanese\")"
440 elog " (setq default-input-method \"japanese-mozc\")"
441 elog
442 elog "With the above settings, typing C-\\ (which is bound to \"toggle-input-method\""
443 elog "by default) will enable mozc-mode."
444 elog
445 elog "Alternatively, at run time, after loading mozc.el, mozc-mode can be activated by"
446 elog "calling \"set-input-method\" and entering \"japanese-mozc\"."
447 elog
449 elisp-site-regen
451 xdg_pkg_postinst
454 pkg_postrm() {
455 if use emacs; then
456 elisp-site-regen
458 xdg_pkg_postrm