dev-qt/qttest: stable 5.14.2 for ppc, bug #719732
[gentoo.git] / eclass / cannadic.eclass
1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: cannadic.eclass
5 # @MAINTAINER:
6 # cjk@gentoo.org
7 # @AUTHOR:
8 # Mamoru KOMACHI <usata@gentoo.org>
9 # @BLURB: Function for Canna compatible dictionaries
10 # @DESCRIPTION:
11 # The cannadic eclass is used for installation and setup of Canna
12 # compatible dictionaries within the Portage system.
13
14 inherit eutils
15
16 EXPORT_FUNCTIONS pkg_setup pkg_postinst pkg_postrm src_install
17
18 HOMEPAGE="http://canna.osdn.jp/"                # you need to change this!
19 SRC_URI="mirror://gentoo/${P}.tar.gz"
20
21 DICSDIRFILE="${FILESDIR}/*.dics.dir"
22 CANNADICS="${CANNADICS}"                        # (optional)
23
24 # You don't need to modify these
25 CANNADIC_CANNA_DIR="${EROOT:-${ROOT}}"var/lib/canna/dic/canna
26 CANNADIC_DICS_DIR="${EROOT:-${ROOT}}"var/lib/canna/dic/dics.d
27 readonly CANNADIC_CANNA_DIR CANNADIC_DICS_DIR
28
29 # @FUNCTION: cannadic_pkg_setup
30 # @DESCRIPTION:
31 # Sets up ${CANNADIC_CANNA_DIR}
32 cannadic_pkg_setup() {
33         keepdir "${CANNADIC_CANNA_DIR}"
34         fowners bin:bin "${CANNADIC_CANNA_DIR}"
35         fperms 0775 "${CANNADIC_CANNA_DIR}"
36 }
37
38 # @FUNCTION: cannadic-install
39 # @DESCRIPTION:
40 # Installs dictionaries to ${CANNADIC_CANNA_DIR}
41 cannadic-install() {
42         insinto "${CANNADIC_CANNA_DIR}"
43         insopts -m 0664 -o bin -g bin
44         doins "${@}"
45 }
46
47 # @FUNCTION: dicsdir-install
48 # @DESCRIPTION:
49 # Installs dics.dir from ${DICSDIRFILE}
50 dicsdir-install() {
51         insinto "${CANNADIC_DICS_DIR}"
52         doins "${DICSDIRFILE}"
53 }
54
55 # @FUNCTION: cannadic_src_install
56 # @DESCRIPTION:
57 # Installs all dictionaries under ${WORKDIR}
58 # plus dics.dir and docs
59 cannadic_src_install() {
60         local f
61         for f in *.c[btl]d *.t; do
62                 if [[ -s "${f}" ]]; then
63                         cannadic-install "${f}"
64                 fi
65         done 2> /dev/null
66
67         dicsdir-install || die
68
69         einstalldocs
70 }
71
72 # @FUNCTION: update-cannadic-dir
73 # @DESCRIPTION:
74 # Updates dics.dir for Canna Server, script for this part taken from Debian GNU/Linux
75 #
76 #  compiles dics.dir files for Canna Server
77 #  Copyright 2001 ISHIKAWA Mutsumi
78 #  Licensed under the GNU General Public License, version 2.  See the file
79 #  /usr/portage/license/GPL-2 or <http://www.gnu.org/copyleft/gpl.txt>.
80 update-cannadic-dir() {
81         einfo
82         einfo "Updating dics.dir for Canna ..."
83         einfo
84
85         # write new dics.dir file in case we are interrupted
86         cat <<-EOF > "${CANNADIC_CANNA_DIR}"/dics.dir.update-new
87         # dics.dir -- automatically generated file by Portage.
88         # DO NOT EDIT BY HAND.
89         EOF
90
91         local f
92         for f in "${CANNADIC_DICS_DIR}"/*.dics.dir; do
93                 echo "# ${f}" >> "${CANNADIC_CANNA_DIR}"/dics.dir.update-new
94                 cat "${f}" >> "${CANNADIC_CANNA_DIR}"/dics.dir.update-new
95                 einfo "Added ${f}."
96         done
97
98         mv "${CANNADIC_CANNA_DIR}"/dics.dir.update-new "${CANNADIC_CANNA_DIR}"/dics.dir
99
100         einfo
101         einfo "Done."
102         einfo
103 }
104
105 # @FUNCTION: cannadic_pkg_postinst
106 # @DESCRIPTION:
107 # Updates dics.dir and print out notice after install
108 cannadic_pkg_postinst() {
109         update-cannadic-dir
110
111         einfo
112         einfo "Please restart cannaserver to fit the changes."
113         einfo "You need to modify your config file (~/.canna) to enable dictionaries."
114
115         if [[ -n "${CANNADICS}" ]]; then
116                 einfo "e.g) add $(for d in ${CANNADICS}; do echo -n "\"${d}\" "; done)to section use-dictionary()."
117                 einfo "For details, see documents under /usr/share/doc/${PF}."
118         fi
119
120         einfo "If you do not have ~/.canna, you can find sample files in /usr/share/canna."
121         ewarn "If you are upgrading from existing dictionary, you may need to recreate"
122         ewarn "user dictionary if you have one."
123         einfo
124 }
125
126 # @FUNCTION: cannadic_pkg_postrm
127 # @DESCRIPTION:
128 # Updates dics.dir and print out notice after uninstall
129 cannadic_pkg_postrm() {
130         update-cannadic-dir
131
132         einfo
133         einfo "Please restart cannaserver to fit changes."
134         einfo "and modify your config file (~/.canna) to disable dictionary."
135
136         if [[ -n "${CANNADICS}" ]]; then
137                 einfo "e.g) delete $(for d in ${CANNADICS}; do echo -n "\"${d}\" "; done)from section use-dictionary()."
138         fi
139
140         einfo
141 }