app-i18n/mozc: Initial commit - add fcitx5 support
[gentoo-zh.git] / app-i18n / mozc / mozc-9999.ebuild
blob7ba466701d0144407fa46b73edb85ea3663f520a
1 # Copyright 2010-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
4 EAPI="7"
5 PYTHON_COMPAT=(python{3_7,3_8,3_9})
7 inherit elisp-common multiprocessing python-any-r1 toolchain-funcs desktop xdg
9 if [[ "${PV}" == "9999" ]]; then
10 inherit git-r3
12 EGIT_REPO_URI="https://github.com/google/mozc"
13 EGIT_SUBMODULES=(src/third_party/japanese_usage_dictionary)
14 else
15 MOZC_GIT_REVISION=""
16 MOZC_DATE="${PV#*_p}"
17 MOZC_DATE="${MOZC_DATE%%_p*}"
19 FCITX_MOZC_GIT_REVISION=""
20 FCITX_MOZC_DATE="${PV#*_p}"
21 FCITX_MOZC_DATE="${FCITX_MOZC_DATE#*_p}"
22 FCITX_MOZC_DATE="${FCITX_MOZC_DATE%%_p*}"
24 JAPANESE_USAGE_DICTIONARY_GIT_REVISION=""
25 JAPANESE_USAGE_DICTIONARY_DATE=""
28 DESCRIPTION="Mozc - Japanese input method editor"
29 HOMEPAGE="https://github.com/google/mozc"
30 if [[ "${PV}" == "9999" ]]; then
31 SRC_URI=""
32 else
33 SRC_URI="https://github.com/google/${PN}/archive/${MOZC_GIT_REVISION}.tar.gz -> ${PN}-${PV%%_p*}-${MOZC_DATE}.tar.gz
34 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
35 https://github.com/fcitx/${PN}/archive/${FCITX_MOZC_GIT_REVISION}.tar.gz -> fcitx-${PN}-${PV%%_p*}-${FCITX_MOZC_DATE}.tar.gz"
38 # Mozc: BSD
39 # src/data/dictionary_oss: ipadic, public-domain
40 # src/data/unicode: unicode
41 # japanese-usage-dictionary: BSD-2
42 LICENSE="BSD BSD-2 ipadic public-domain unicode"
43 SLOT="0"
44 KEYWORDS=""
45 IUSE="debug emacs fcitx4 fcitx5 +gui ibus renderer test"
46 REQUIRED_USE="|| ( emacs fcitx4 fcitx5 ibus )"
47 RESTRICT="!test? ( test )"
49 BDEPEND="$(python_gen_any_dep 'dev-python/six[${PYTHON_USEDEP}]')
50 >=dev-libs/protobuf-3.0.0
51 dev-util/gyp
52 dev-util/ninja
53 virtual/pkgconfig
54 emacs? ( app-editors/emacs:* )
55 fcitx4? ( sys-devel/gettext )
56 fcitx5? ( sys-devel/gettext )"
57 DEPEND=">=dev-cpp/abseil-cpp-20200923[cxx17(+)]
58 >=dev-libs/protobuf-3.0.0:=
59 fcitx4? (
60 app-i18n/fcitx:4
61 virtual/libintl
63 fcitx5? (
64 app-i18n/fcitx5:5
65 app-i18n/libime
66 sys-devel/gettext
67 virtual/libintl
69 gui? (
70 dev-qt/qtcore:5
71 dev-qt/qtgui:5
72 dev-qt/qtwidgets:5
74 ibus? (
75 >=app-i18n/ibus-1.4.1
76 dev-libs/glib:2
77 x11-libs/libxcb
79 renderer? (
80 dev-libs/glib:2
81 x11-libs/cairo
82 x11-libs/gtk+:2
83 x11-libs/pango
85 test? (
86 >=dev-cpp/gtest-1.8.0
87 dev-libs/jsoncpp
89 RDEPEND=">=dev-cpp/abseil-cpp-20200923[cxx17(+)]
90 >=dev-libs/protobuf-3.0.0:=
91 emacs? ( app-editors/emacs:* )
92 fcitx4? (
93 app-i18n/fcitx:4
94 virtual/libintl
96 fcitx5? (
97 app-i18n/fcitx5:5
98 app-i18n/libime
99 sys-devel/gettext
100 virtual/libintl
102 gui? (
103 dev-qt/qtcore:5
104 dev-qt/qtgui:5
105 dev-qt/qtwidgets:5
107 ibus? (
108 >=app-i18n/ibus-1.4.1
109 dev-libs/glib:2
110 x11-libs/libxcb
112 renderer? (
113 dev-libs/glib:2
114 x11-libs/cairo
115 x11-libs/gtk+:2
116 x11-libs/pango
119 S="${WORKDIR}/${P}/src"
121 SITEFILE="50${PN}-gentoo.el"
123 execute() {
124 einfo "$@"
125 "$@"
128 python_check_deps() {
129 has_version -b "dev-python/six[${PYTHON_USEDEP}]"
132 src_unpack() {
133 if [[ "${PV}" == "9999" ]]; then
134 git-r3_src_unpack
136 if use fcitx4; then
137 local EGIT_SUBMODULES=()
138 git-r3_fetch https://github.com/fcitx/mozc refs/heads/fcitx
139 git-r3_checkout https://github.com/fcitx/mozc "${WORKDIR}/fcitx-mozc"
141 if use fcitx5; then
142 local EGIT_SUBMODULES=()
143 git-r3_fetch https://github.com/fcitx/mozc refs/heads/fcitx5
144 git-r3_checkout https://github.com/fcitx/mozc "${WORKDIR}/fcitx5-mozc"
146 else
147 unpack ${PN}-${PV%%_p*}-${MOZC_DATE}.tar.gz
148 mv mozc-${MOZC_GIT_REVISION} ${P} || die
150 unpack japanese-usage-dictionary-${JAPANESE_USAGE_DICTIONARY_DATE}.tar.gz
151 cp -p japanese-usage-dictionary-${JAPANESE_USAGE_DICTIONARY_GIT_REVISION}/usage_dict.txt ${P}/src/third_party/japanese_usage_dictionary || die
153 unpack fcitx-${PN}-${PV%%_p*}-${FCITX_MOZC_DATE}.tar.gz
154 if use fcitx4; then
155 cp -pr mozc-${FCITX_MOZC_GIT_REVISION} fcitx-${PN} || die
157 if use fcitx5; then
158 cp -pr mozc-${FCITX_MOZC_GIT_REVISION} fcitx5-${PN} || die
163 src_prepare() {
164 if use fcitx4; then
165 cp -pr "${WORKDIR}/fcitx-mozc/src/unix/fcitx" unix || die
167 if use fcitx5; then
168 cp -pr "${WORKDIR}/fcitx5-mozc/src/unix/fcitx5" unix || die
171 pushd "${WORKDIR}/${P}" > /dev/null || die
173 eapply "${FILESDIR}/${PN}-2.26.4220-system_abseil-cpp.patch"
174 eapply "${FILESDIR}/${PN}-2.26.4220-system_gtest.patch"
175 eapply "${FILESDIR}/${PN}-2.26.4220-system_jsoncpp.patch"
176 eapply "${FILESDIR}/${PN}-2.26.4220-environmental_variables.patch"
177 eapply "${FILESDIR}/${PN}-2.26.4220-server_path_check.patch"
179 eapply_user
181 popd > /dev/null || die
183 sed \
184 -e "s/def GypMain(options, unused_args):/def GypMain(options, gyp_args):/" \
185 -e "s/RunOrDie(gyp_command + gyp_options)/RunOrDie(gyp_command + gyp_options + gyp_args)/" \
186 -e "s/RunOrDie(\[ninja/&, '-j$(makeopts_jobs)', '-l$(makeopts_loadavg "${MAKEOPTS}" 0)', '-v'/" \
187 -i build_mozc.py || die
189 local ar=($(tc-getAR))
190 local cc=($(tc-getCC))
191 local cxx=($(tc-getCXX))
192 local ld=($(tc-getLD))
193 local nm=($(tc-getNM))
194 local readelf=($(tc-getREADELF))
196 # Use absolute paths. Non-absolute paths are mishandled by GYP.
197 ar[0]=$(type -P ${ar[0]})
198 cc[0]=$(type -P ${cc[0]})
199 cxx[0]=$(type -P ${cxx[0]})
200 ld[0]=$(type -P ${ld[0]})
201 nm[0]=$(type -P ${nm[0]})
202 readelf[0]=$(type -P ${readelf[0]})
204 sed \
205 -e "s:<!(which ar):${ar[@]}:" \
206 -e "s:<!(which clang):${cc[@]}:" \
207 -e "s:<!(which clang++):${cxx[@]}:" \
208 -e "s:<!(which ld):${ld[@]}:" \
209 -e "s:<!(which nm):${nm[@]}:" \
210 -e "s:<!(which readelf):${readelf[@]}:" \
211 -i gyp/common.gypi || die
213 # https://github.com/google/mozc/issues/489
214 sed \
215 -e "/'-lc++'/d" \
216 -e "/'-stdlib=libc++'/d" \
217 -i gyp/common.gypi || die
220 src_configure() {
221 if use debug; then
222 BUILD_TYPE="Debug"
223 else
224 BUILD_TYPE="Release"
227 local gyp_arguments=()
229 if tc-is-gcc; then
230 gyp_arguments+=(-D compiler_host=gcc -D compiler_target=gcc)
231 elif tc-is-clang; then
232 gyp_arguments+=(-D compiler_host=clang -D compiler_target=clang)
233 else
234 gyp_arguments+=(-D compiler_host=unknown -D compiler_target=unknown)
237 gyp_arguments+=(-D debug_extra_cflags=)
238 gyp_arguments+=(-D release_extra_cflags=)
240 gyp_arguments+=(-D use_fcitx=$(usex fcitx4 YES NO))
241 gyp_arguments+=(-D use_fcitx5=$(usex fcitx5 YES NO))
242 gyp_arguments+=(-D use_libibus=$(usex ibus 1 0))
243 gyp_arguments+=(-D use_libprotobuf=1)
244 gyp_arguments+=(-D use_system_abseil_cpp=1)
245 gyp_arguments+=(-D use_system_gtest=$(usex test 1 0))
246 gyp_arguments+=(-D use_system_jsoncpp=$(usex test 1 0))
247 gyp_arguments+=(-D enable_gtk_renderer=$(usex renderer 1 0))
249 gyp_arguments+=(-D server_dir="${EPREFIX}/usr/libexec/mozc")
250 gyp_arguments+=(-D document_dir="${EPREFIX}/usr/libexec/mozc/documents")
252 if use ibus; then
253 gyp_arguments+=(-D ibus_mozc_path="${EPREFIX}/usr/libexec/ibus-engine-mozc")
254 gyp_arguments+=(-D ibus_mozc_icon_path="${EPREFIX}/usr/share/ibus-mozc/product_icon.png")
257 unset AR CC CXX LD NM READELF
259 execute "${PYTHON}" build_mozc.py gyp \
260 --gypdir="${EPREFIX}/usr/bin" \
261 --server_dir="${EPREFIX}/usr/libexec/mozc" \
262 --verbose \
263 $(usex gui "" --noqt) \
264 -- "${gyp_arguments[@]}" || die "Configuration failed"
267 src_compile() {
268 local targets=(server/server.gyp:mozc_server)
269 if use emacs; then
270 targets+=(unix/emacs/emacs.gyp:mozc_emacs_helper)
272 if use fcitx4; then
273 targets+=(unix/fcitx/fcitx.gyp:fcitx-mozc)
275 if use fcitx5; then
276 targets+=(unix/fcitx5/fcitx5.gyp:fcitx5-mozc)
278 if use gui; then
279 targets+=(gui/gui.gyp:mozc_tool)
281 if use ibus; then
282 targets+=(unix/ibus/ibus.gyp:ibus_mozc)
284 if use renderer; then
285 targets+=(renderer/renderer.gyp:mozc_renderer)
287 if use test; then
288 targets+=(gyp/tests.gyp:unittests)
291 execute "${PYTHON}" build_mozc.py build -c ${BUILD_TYPE} -v "${targets[@]}" || die "Building failed"
293 if use emacs; then
294 elisp-compile unix/emacs/*.el
298 src_test() {
299 execute "${PYTHON}" build_mozc.py runtests -c ${BUILD_TYPE} --test_jobs 1 || die "Testing failed"
302 src_install() {
303 exeinto /usr/libexec/mozc
304 doexe out_linux/${BUILD_TYPE}/mozc_server
306 if use gui; then
307 doexe out_linux/${BUILD_TYPE}/mozc_tool
310 if use renderer; then
311 doexe out_linux/${BUILD_TYPE}/mozc_renderer
314 insinto /usr/libexec/mozc/documents
315 doins data/installer/credits_en.html
317 if use emacs; then
318 dobin out_linux/${BUILD_TYPE}/mozc_emacs_helper
319 elisp-install ${PN} unix/emacs/*.{el,elc}
320 elisp-site-file-install "${FILESDIR}/${SITEFILE}" ${PN}
323 if use fcitx4; then
324 exeinto /usr/$(get_libdir)/fcitx
325 doexe out_linux/${BUILD_TYPE}/fcitx-mozc.so
327 insinto /usr/share/fcitx/addon
328 doins unix/fcitx/fcitx-mozc.conf
330 insinto /usr/share/fcitx/inputmethod
331 doins unix/fcitx/mozc.conf
333 insinto /usr/share/fcitx/mozc/icon
334 newins data/images/product_icon_32bpp-128.png mozc.png
335 local image
336 for image in ../../fcitx-${PN}/src/data/images/unix/ui-*.png; do
337 newins "${image}" "mozc-${image#../../fcitx-${PN}/src/data/images/unix/ui-}"
338 done
340 local locale mo_file
341 for mo_file in out_linux/${BUILD_TYPE}/gen/unix/fcitx/po/*.mo; do
342 locale="${mo_file##*/}"
343 locale="${locale%.mo}"
344 insinto /usr/share/locale/${locale}/LC_MESSAGES
345 newins "${mo_file}" fcitx-mozc.mo
346 done
348 if use fcitx5; then
349 exeinto /usr/$(get_libdir)/fcitx5
350 doexe out_linux/${BUILD_TYPE}/fcitx5-mozc.so
352 insinto /usr/share/fcitx5/addon
353 newins unix/fcitx5/mozc-addon.conf mozc.conf
355 insinto /usr/share/fcitx5/inputmethod
356 doins unix/fcitx5/mozc.conf
358 local orgfcitx5="org.fcitx.Fcitx5.fcitx-mozc"
359 newicon -s 128 data/images/product_icon_32bpp-128.png ${orgfcitx5}.png
360 newicon -s 128 data/images/product_icon_32bpp-128.png fcitx-mozc.png
361 newicon -s 32 data/images/unix/ime_product_icon_opensource-32.png ${orgfcitx5}.png
362 newicon -s 32 data/images/unix/ime_product_icon_opensource-32.png fcitx-mozc.png
363 for uiimg in ../../fcitx5-mozc/scripts/icons/ui-*.png; do
364 dimg=${uiimg#*ui-}
365 newicon -s 48 ${uiimg} ${orgfcitx5}-${dimg/_/-}
366 newicon -s 48 ${uiimg} fcitx-mozc-${dimg/_/-}
367 done
369 local locale mo_file
370 for mo_file in unix/fcitx5/po/*.po; do
371 locale="${mo_file##*/}"
372 locale="${locale%.po}"
373 msgfmt ${mo_file} -o ${mo_file/.po/.mo} || die
374 insinto /usr/share/locale/${locale}/LC_MESSAGES
375 newins "${mo_file/.po/.mo}" fcitx5-mozc.mo
376 done
379 if use ibus; then
380 exeinto /usr/libexec
381 newexe out_linux/${BUILD_TYPE}/ibus_mozc ibus-engine-mozc
383 insinto /usr/share/ibus/component
384 doins out_linux/${BUILD_TYPE}/gen/unix/ibus/mozc.xml
386 insinto /usr/share/ibus-mozc
387 newins data/images/unix/ime_product_icon_opensource-32.png product_icon.png
388 local image
389 for image in data/images/unix/ui-*.png; do
390 newins "${image}" "${image#data/images/unix/ui-}"
391 done
395 pkg_postinst() {
396 elog
397 elog "ENVIRONMENTAL VARIABLES"
398 elog
399 elog "MOZC_SERVER_DIRECTORY"
400 elog " Mozc server directory"
401 elog " Value used by default: \"${EPREFIX}/usr/libexec/mozc\""
402 elog "MOZC_DOCUMENTS_DIRECTORY"
403 elog " Mozc documents directory"
404 elog " Value used by default: \"${EPREFIX}/usr/libexec/mozc/documents\""
405 elog "MOZC_CONFIGURATION_DIRECTORY"
406 elog " Mozc configuration directory"
407 elog " Value used by default: \"~/.mozc\""
408 elog
409 if use emacs; then
410 elog
411 elog "USAGE IN EMACS"
412 elog
413 elog "mozc-mode is minor mode to input Japanese text using Mozc server."
414 elog "mozc-mode can be used via LEIM (Library of Emacs Input Method)."
415 elog
416 elog "In order to use mozc-mode by default, the following settings should be added to"
417 elog "Emacs init file (~/.emacs.d/init.el or ~/.emacs):"
418 elog
419 elog " (require 'mozc)"
420 elog " (set-language-environment \"Japanese\")"
421 elog " (setq default-input-method \"japanese-mozc\")"
422 elog
423 elog "With the above settings, typing C-\\ (which is bound to \"toggle-input-method\""
424 elog "by default) will enable mozc-mode."
425 elog
426 elog "Alternatively, at run time, after loading mozc.el, mozc-mode can be activated by"
427 elog "calling \"set-input-method\" and entering \"japanese-mozc\"."
428 elog
430 elisp-site-regen
432 xdg_pkg_postinst
435 pkg_postrm() {
436 if use emacs; then
437 elisp-site-regen
439 xdg_pkg_postrm