app-dicts/fcitx-pinyin-moegirl: add 20241109, drop 20241009
[gentoo-zh.git] / app-i18n / mozc / mozc-2.28.5029.102-r1.ebuild
blob8c04e8f50d0ef6b3b58ddfa71d572f1d921beab0
1 # Copyright 2010-2024 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
4 EAPI="8"
6 PYTHON_COMPAT=( python3_{10..12} )
8 inherit desktop edo elisp-common multiprocessing python-any-r1 savedconfig toolchain-funcs xdg
10 DESCRIPTION="Mozc - Japanese input method editor"
11 HOMEPAGE="https://github.com/google/mozc"
13 if [[ "${PV}" == "9999" ]]; then
14 inherit git-r3
16 EGIT_REPO_URI="https://github.com/google/mozc"
17 EGIT_SUBMODULES=(src/third_party/japanese_usage_dictionary)
18 else
19 MOZC_GIT_REVISION="305e9a7374254148474d067c46d55a4ee6081837"
20 MOZC_DATE="${PV#*_p}"
21 MOZC_DATE="${MOZC_DATE%%_p*}"
23 FCITX_MOZC_GIT_REVISION="242b4f703cba27d4ff4dc123c713a478f964e001"
24 FCITX_MOZC_DATE="${PV#*_p}"
25 FCITX_MOZC_DATE="${FCITX_MOZC_DATE#*_p}"
26 FCITX_MOZC_DATE="${FCITX_MOZC_DATE%%_p*}"
28 JAPANESE_USAGE_DICTIONARY_GIT_REVISION="a4a66772e33746b91e99caceecced9a28507e925"
29 JAPANESE_USAGE_DICTIONARY_DATE="20180701040110"
31 SRC_URI="
32 https://github.com/google/${PN}/archive/${MOZC_GIT_REVISION}.tar.gz -> ${PN}-${PV%%_p*}-${MOZC_DATE}.tar.gz
33 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
34 https://dev.gentoo.org/~sam/distfiles/${CATEGORY}/${PN}/${PN}-2.28.5029.102-patches.tar.xz
35 fcitx4? ( https://github.com/fcitx/${PN}/archive/${FCITX_MOZC_GIT_REVISION}.tar.gz -> fcitx-${PN}-${PV%%_p*}-${FCITX_MOZC_DATE}.tar.gz )
36 fcitx5? ( https://github.com/fcitx/${PN}/archive/${FCITX_MOZC_GIT_REVISION}.tar.gz -> fcitx-${PN}-${PV%%_p*}-${FCITX_MOZC_DATE}.tar.gz )
40 # Mozc: BSD
41 # src/data/dictionary_oss: ipadic, public-domain
42 # src/data/unicode: unicode
43 # japanese-usage-dictionary: BSD-2
44 LICENSE="BSD BSD-2 ipadic public-domain unicode"
45 SLOT="0"
46 KEYWORDS="~amd64 ~x86"
47 IUSE="debug emacs fcitx4 fcitx5 +gui ibus renderer test"
48 REQUIRED_USE="|| ( emacs fcitx4 fcitx5 ibus )"
49 RESTRICT="!test? ( test )"
51 BDEPEND="
52 $(python_gen_any_dep 'dev-python/six[${PYTHON_USEDEP}]')
53 >=dev-libs/protobuf-3.0.0
54 dev-build/gyp
55 app-alternatives/ninja
56 virtual/pkgconfig
57 emacs? ( app-editors/emacs:* )
58 fcitx4? ( sys-devel/gettext )
59 fcitx5? ( sys-devel/gettext )
61 DEPEND="
62 >=dev-cpp/abseil-cpp-20230802.0:=[cxx17(+)]
63 >=dev-libs/protobuf-3.0.0:=
64 fcitx4? (
65 app-i18n/fcitx:4
66 virtual/libintl
68 fcitx5? (
69 app-i18n/fcitx:5
70 app-i18n/libime
71 sys-devel/gettext
72 virtual/libintl
74 gui? (
75 dev-qt/qtcore:5
76 dev-qt/qtgui:5
77 dev-qt/qtwidgets:5
79 ibus? (
80 >=app-i18n/ibus-1.4.1
81 dev-libs/glib:2
82 x11-libs/libxcb
84 renderer? (
85 dev-libs/glib:2
86 x11-libs/cairo
87 x11-libs/gtk+:2
88 x11-libs/pango
90 test? (
91 >=dev-cpp/gtest-1.8.0
92 dev-libs/jsoncpp
94 RDEPEND="
95 >=dev-cpp/abseil-cpp-20230802.0:=[cxx17(+)]
96 >=dev-libs/protobuf-3.0.0:=
97 emacs? ( app-editors/emacs:* )
98 fcitx4? (
99 app-i18n/fcitx:4
100 virtual/libintl
102 fcitx5? (
103 app-i18n/fcitx:5
104 app-i18n/libime
105 sys-devel/gettext
106 virtual/libintl
108 gui? (
109 dev-qt/qtcore:5
110 dev-qt/qtgui:5
111 dev-qt/qtwidgets:5
113 ibus? (
114 >=app-i18n/ibus-1.4.1
115 dev-libs/glib:2
116 x11-libs/libxcb
118 renderer? (
119 dev-libs/glib:2
120 x11-libs/cairo
121 x11-libs/gtk+:2
122 x11-libs/pango
126 S="${WORKDIR}/${P}/src"
128 SITEFILE="50${PN}-gentoo.el"
130 PATCHES=(
131 "${WORKDIR}"/mozc-2.28.5029.102-patches
132 "${FILESDIR}"/mozc-2.28.5029.102-abseil.patch
133 "${FILESDIR}"/mozc-2.28.5029.102-abseil-20230802.0.patch
136 python_check_deps() {
137 python_has_version "dev-python/six[${PYTHON_USEDEP}]"
140 src_unpack() {
141 if [[ "${PV}" == "9999" ]]; then
142 git-r3_src_unpack
144 if use fcitx4 || use fcitx5; then
145 local EGIT_SUBMODULES=()
146 git-r3_fetch https://github.com/fcitx/mozc refs/heads/fcitx
147 git-r3_checkout https://github.com/fcitx/mozc "${WORKDIR}/fcitx-mozc"
149 if use fcitx5; then
150 cp -pr "${WORKDIR}"/fcitx{,5}-mozc || die
152 else
153 unpack ${PN}-${PV%%_p*}-${MOZC_DATE}.tar.gz
154 mv mozc-${MOZC_GIT_REVISION} ${P} || die
156 unpack ${PN}-2.28.5029.102-patches.tar.xz
158 unpack japanese-usage-dictionary-${JAPANESE_USAGE_DICTIONARY_DATE}.tar.gz
159 cp -p japanese-usage-dictionary-${JAPANESE_USAGE_DICTIONARY_GIT_REVISION}/usage_dict.txt ${P}/src/third_party/japanese_usage_dictionary || die
161 if use fcitx4 || use fcitx5; then
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
169 rm -r mozc-${FCITX_MOZC_GIT_REVISION} || die
174 src_prepare() {
175 if use fcitx4; then
176 cp -pr "${WORKDIR}/fcitx-mozc/src/unix/fcitx" unix || die
177 PATCHES+=( "${FILESDIR}"/mozc-2.28.5029.102-abseil-20230802.0-fcitx4.patch )
179 if use fcitx5; then
180 cp -pr "${WORKDIR}/fcitx5-mozc/src/unix/fcitx5" unix || die
181 PATCHES+=( "${FILESDIR}"/mozc-2.28.5029.102-abseil-20230802.0-fcitx5.patch )
184 pushd "${WORKDIR}/${P}" > /dev/null || die
185 default
186 popd > /dev/null || die
188 sed \
189 -e "s/def GypMain(options, unused_args):/def GypMain(options, gyp_args):/" \
190 -e "s/RunOrDie(gyp_command + gyp_options)/RunOrDie(gyp_command + gyp_options + gyp_args)/" \
191 -e "s/RunOrDie(\[ninja/&, '-j$(makeopts_jobs "${MAKEOPTS}" 999)', '-l$(makeopts_loadavg "${MAKEOPTS}" 0)', '-v'/" \
192 -i build_mozc.py || die
194 local ar=($(tc-getAR))
195 local cc=($(tc-getCC))
196 local cxx=($(tc-getCXX))
197 local ld=($(tc-getLD))
198 local nm=($(tc-getNM))
199 local readelf=($(tc-getREADELF))
201 # Use absolute paths. Non-absolute paths are mishandled by GYP.
202 ar[0]=$(type -P ${ar[0]})
203 cc[0]=$(type -P ${cc[0]})
204 cxx[0]=$(type -P ${cxx[0]})
205 ld[0]=$(type -P ${ld[0]})
206 nm[0]=$(type -P ${nm[0]})
207 readelf[0]=$(type -P ${readelf[0]})
209 sed \
210 -e "s:<!(which ar):${ar[@]}:" \
211 -e "s:<!(which clang):${cc[@]}:" \
212 -e "s:<!(which clang++):${cxx[@]}:" \
213 -e "s:<!(which ld):${ld[@]}:" \
214 -e "s:<!(which nm):${nm[@]}:" \
215 -e "s:<!(which readelf):${readelf[@]}:" \
216 -i gyp/common.gypi || die
218 # https://github.com/google/mozc/issues/489
219 sed \
220 -e "/'-lc++'/d" \
221 -e "/'-stdlib=libc++'/d" \
222 -i gyp/common.gypi || die
224 # bug #877765
225 restore_config mozcdic-ut.txt
226 if [[ -f /mozcdic-ut.txt && -s mozcdic-ut.txt ]]; then
227 einfo "mozcdic-ut.txt found. Adding to mozc dictionary..."
228 cat mozcdic-ut.txt >> "${WORKDIR}/${P}/src/data/dictionary_oss/dictionary00.txt" || die
232 src_configure() {
233 if use debug; then
234 BUILD_TYPE="Debug"
235 else
236 BUILD_TYPE="Release"
239 local gyp_arguments=()
241 if tc-is-gcc; then
242 gyp_arguments+=(-D compiler_host=gcc -D compiler_target=gcc)
243 elif tc-is-clang; then
244 gyp_arguments+=(-D compiler_host=clang -D compiler_target=clang)
245 else
246 gyp_arguments+=(-D compiler_host=unknown -D compiler_target=unknown)
249 gyp_arguments+=(-D debug_extra_cflags=)
250 gyp_arguments+=(-D release_extra_cflags=)
252 gyp_arguments+=(-D use_fcitx=$(usex fcitx4 YES NO))
253 gyp_arguments+=(-D use_fcitx5=$(usex fcitx5 YES NO))
254 gyp_arguments+=(-D use_libibus=$(usex ibus 1 0))
255 gyp_arguments+=(-D use_libprotobuf=1)
256 gyp_arguments+=(-D use_system_abseil_cpp=1)
257 gyp_arguments+=(-D use_system_gtest=$(usex test 1 0))
258 gyp_arguments+=(-D use_system_jsoncpp=$(usex test 1 0))
259 gyp_arguments+=(-D enable_gtk_renderer=$(usex renderer 1 0))
261 gyp_arguments+=(-D server_dir="${EPREFIX}/usr/libexec/mozc")
262 gyp_arguments+=(-D document_dir="${EPREFIX}/usr/libexec/mozc/documents")
264 if use ibus; then
265 gyp_arguments+=(-D ibus_mozc_path="${EPREFIX}/usr/libexec/ibus-engine-mozc")
266 gyp_arguments+=(-D ibus_mozc_icon_path="${EPREFIX}/usr/share/ibus-mozc/product_icon.png")
269 unset AR CC CXX LD NM READELF
271 edo "${PYTHON}" build_mozc.py gyp \
272 --gypdir="${EPREFIX}/usr/bin" \
273 --server_dir="${EPREFIX}/usr/libexec/mozc" \
274 --verbose \
275 $(usex gui "" --noqt) \
276 -- "${gyp_arguments[@]}"
279 src_compile() {
280 local targets=(server/server.gyp:mozc_server)
281 if use emacs; then
282 targets+=(unix/emacs/emacs.gyp:mozc_emacs_helper)
284 if use fcitx4; then
285 targets+=(unix/fcitx/fcitx.gyp:fcitx-mozc)
287 if use fcitx5; then
288 targets+=(unix/fcitx5/fcitx5.gyp:fcitx5-mozc)
290 if use gui; then
291 targets+=(gui/gui.gyp:mozc_tool)
293 if use ibus; then
294 targets+=(unix/ibus/ibus.gyp:ibus_mozc)
296 if use renderer; then
297 targets+=(renderer/renderer.gyp:mozc_renderer)
299 if use test; then
300 targets+=(gyp/tests.gyp:unittests)
303 if use ibus; then
304 GYP_IBUS_FLAG="--use_gyp_for_ibus_build"
307 edo "${PYTHON}" build_mozc.py build -c ${BUILD_TYPE} ${GYP_IBUS_FLAG} -v "${targets[@]}"
309 if use emacs; then
310 elisp-compile unix/emacs/*.el
314 src_test() {
315 edo "${PYTHON}" build_mozc.py runtests -c ${BUILD_TYPE} --test_jobs 1
318 src_install() {
319 exeinto /usr/libexec/mozc
320 doexe out_linux/${BUILD_TYPE}/mozc_server
322 [[ -s mozcdic-ut.txt ]] && save_config mozcdic-ut.txt
324 if use gui; then
325 doexe out_linux/${BUILD_TYPE}/mozc_tool
328 if use renderer; then
329 doexe out_linux/${BUILD_TYPE}/mozc_renderer
332 insinto /usr/libexec/mozc/documents
333 doins data/installer/credits_en.html
335 if use emacs; then
336 dobin out_linux/${BUILD_TYPE}/mozc_emacs_helper
337 elisp-install ${PN} unix/emacs/*.{el,elc}
338 elisp-site-file-install "${FILESDIR}/${SITEFILE}" ${PN}
341 if use fcitx4; then
342 exeinto /usr/$(get_libdir)/fcitx
343 doexe out_linux/${BUILD_TYPE}/fcitx-mozc.so
345 insinto /usr/share/fcitx/addon
346 doins unix/fcitx/fcitx-mozc.conf
348 insinto /usr/share/fcitx/inputmethod
349 doins unix/fcitx/mozc.conf
351 insinto /usr/share/fcitx/mozc/icon
352 newins data/images/product_icon_32bpp-128.png mozc.png
353 local image
354 for image in ../../fcitx-${PN}/src/data/images/unix/ui-*.png; do
355 newins "${image}" "mozc-${image#../../fcitx-${PN}/src/data/images/unix/ui-}"
356 done
358 local locale mo_file
359 for mo_file in out_linux/${BUILD_TYPE}/gen/unix/fcitx/po/*.mo; do
360 locale="${mo_file##*/}"
361 locale="${locale%.mo}"
362 insinto /usr/share/locale/${locale}/LC_MESSAGES
363 newins "${mo_file}" fcitx-mozc.mo
364 done
367 if use fcitx5; then
368 exeinto /usr/$(get_libdir)/fcitx5
369 doexe out_linux/${BUILD_TYPE}/fcitx5-mozc.so
371 insinto /usr/share/fcitx5/addon
372 newins unix/fcitx5/mozc-addon.conf mozc.conf
374 insinto /usr/share/fcitx5/inputmethod
375 doins unix/fcitx5/mozc.conf
377 local orgfcitx5="org.fcitx.Fcitx5.fcitx-mozc"
378 newicon -s 128 data/images/product_icon_32bpp-128.png ${orgfcitx5}.png
379 newicon -s 128 data/images/product_icon_32bpp-128.png fcitx-mozc.png
380 newicon -s 32 data/images/unix/ime_product_icon_opensource-32.png ${orgfcitx5}.png
381 newicon -s 32 data/images/unix/ime_product_icon_opensource-32.png fcitx-mozc.png
382 for uiimg in ../../fcitx5-mozc/scripts/icons/ui-*.png; do
383 dimg=${uiimg#*ui-}
384 newicon -s 48 ${uiimg} ${orgfcitx5}-${dimg/_/-}
385 newicon -s 48 ${uiimg} fcitx-mozc-${dimg/_/-}
386 done
388 local locale mo_file
389 for mo_file in unix/fcitx5/po/*.po; do
390 locale="${mo_file##*/}"
391 locale="${locale%.po}"
392 msgfmt ${mo_file} -o ${mo_file/.po/.mo} || die
393 insinto /usr/share/locale/${locale}/LC_MESSAGES
394 newins "${mo_file/.po/.mo}" fcitx5-mozc.mo
395 done
396 msgfmt --xml -d unix/fcitx5/po/ --template unix/fcitx5/org.fcitx.Fcitx5.Addon.Mozc.metainfo.xml.in -o \
397 unix/fcitx5/org.fcitx.Fcitx5.Addon.Mozc.metainfo.xml || die
398 insinto /usr/share/metainfo
399 doins unix/fcitx5/org.fcitx.Fcitx5.Addon.Mozc.metainfo.xml
402 if use ibus; then
403 exeinto /usr/libexec
404 newexe out_linux/${BUILD_TYPE}/ibus_mozc ibus-engine-mozc
406 insinto /usr/share/ibus/component
407 doins out_linux/${BUILD_TYPE}/gen/unix/ibus/mozc.xml
409 insinto /usr/share/ibus-mozc
410 newins data/images/unix/ime_product_icon_opensource-32.png product_icon.png
411 local image
412 for image in data/images/unix/ui-*.png; do
413 newins "${image}" "${image#data/images/unix/ui-}"
414 done
418 pkg_postinst() {
419 elog
420 elog "ENVIRONMENTAL VARIABLES"
421 elog
422 elog "MOZC_SERVER_DIRECTORY"
423 elog " Mozc server directory"
424 elog " Value used by default: \"${EPREFIX}/usr/libexec/mozc\""
425 elog "MOZC_DOCUMENTS_DIRECTORY"
426 elog " Mozc documents directory"
427 elog " Value used by default: \"${EPREFIX}/usr/libexec/mozc/documents\""
428 elog "MOZC_CONFIGURATION_DIRECTORY"
429 elog " Mozc configuration directory"
430 elog " Value used by default: \"~/.mozc\""
431 elog
432 if use emacs; then
433 elog
434 elog "USAGE IN EMACS"
435 elog
436 elog "mozc-mode is minor mode to input Japanese text using Mozc server."
437 elog "mozc-mode can be used via LEIM (Library of Emacs Input Method)."
438 elog
439 elog "In order to use mozc-mode by default, the following settings should be added to"
440 elog "Emacs init file (~/.emacs.d/init.el or ~/.emacs):"
441 elog
442 elog " (require 'mozc)"
443 elog " (set-language-environment \"Japanese\")"
444 elog " (setq default-input-method \"japanese-mozc\")"
445 elog
446 elog "With the above settings, typing C-\\ (which is bound to \"toggle-input-method\""
447 elog "by default) will enable mozc-mode."
448 elog
449 elog "Alternatively, at run time, after loading mozc.el, mozc-mode can be activated by"
450 elog "calling \"set-input-method\" and entering \"japanese-mozc\"."
451 elog
453 elisp-site-regen
455 xdg_pkg_postinst
458 pkg_postrm() {
459 if use emacs; then
460 elisp-site-regen
462 xdg_pkg_postrm