1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: chromium.eclass
7 # Chromium Herd <chromium@gentoo.org>
9 # Mike Gilbert <floppym@gentoo.org>
10 # @BLURB: Shared functions for chromium and google-chrome
12 inherit eutils fdo-mime gnome2-utils linux-info
14 if [[ ${CHROMIUM_EXPORT_PHASES} != no ]]; then
15 EXPORT_FUNCTIONS pkg_preinst pkg_postinst pkg_postrm
18 if [[ ${PN} == chromium ]]; then
19 IUSE+=" custom-cflags"
22 # @FUNCTION: chromium_suid_sandbox_check_kernel_config
25 # Ensures the system kernel supports features needed for SUID sandbox to work.
26 chromium_suid_sandbox_check_kernel_config() {
27 has "${EAPI:-0}" 0 1 2 3 && die "EAPI=${EAPI} is not supported"
29 if [[ "${MERGE_TYPE}" == "source" || "${MERGE_TYPE}" == "binary" ]]; then
30 # Warn if the kernel does not support features needed for sandboxing.
32 ERROR_PID_NS="PID_NS is required for sandbox to work"
33 ERROR_NET_NS="NET_NS is required for sandbox to work"
34 ERROR_USER_NS="USER_NS is required for sandbox to work"
35 ERROR_SECCOMP_FILTER="SECCOMP_FILTER is required for sandbox to work"
36 # Warn if the kernel does not support features needed for the browser to work
37 # (bug #552576, bug #556286).
38 ERROR_ADVISE_SYSCALLS="CONFIG_ADVISE_SYSCALLS is required for the renderer (bug #552576)"
39 ERROR_COMPAT_VDSO="CONFIG_COMPAT_VDSO causes segfaults (bug #556286)"
40 CONFIG_CHECK="~PID_NS ~NET_NS ~SECCOMP_FILTER ~USER_NS ~ADVISE_SYSCALLS ~!COMPAT_VDSO"
45 # @ECLASS-VARIABLE: CHROMIUM_LANGS
48 # List of language packs available for this package.
50 _chromium_set_linguas_IUSE() {
51 [[ ${EAPI:-0} == 0 ]] && die "EAPI=${EAPI} is not supported"
54 for lang in ${CHROMIUM_LANGS}; do
55 # Default to enabled since we bundle them anyway.
56 # USE-expansion will take care of disabling the langs the user has not
57 # selected via LINGUAS.
58 IUSE+=" +linguas_${lang}"
62 if [[ ${CHROMIUM_LANGS} ]]; then
63 _chromium_set_linguas_IUSE
86 _chromium_strip_pak() {
93 # @FUNCTION: chromium_remove_language_paks
96 # Removes pak files from the current directory for languages that the user has
97 # not selected via the LINGUAS variable.
98 # Also performs QA checks to ensure CHROMIUM_LANGS has been set correctly.
99 chromium_remove_language_paks() {
100 local crlangs=$(_chromium_crlang ${CHROMIUM_LANGS})
101 local present_crlangs=$(_chromium_strip_pak *.pak)
102 local present_langs=$(_chromium_syslang ${present_crlangs})
105 # Look for missing pak files.
106 for lang in ${crlangs}; do
107 if ! has ${lang} ${present_crlangs}; then
108 eqawarn "LINGUAS warning: no .pak file for ${lang} (${lang}.pak not found)"
112 # Look for extra pak files.
113 # Remove pak files that the user does not want.
114 for lang in ${present_langs}; do
115 if [[ ${lang} == en_US ]]; then
118 if ! has ${lang} ${CHROMIUM_LANGS}; then
119 eqawarn "LINGUAS warning: no ${lang} in LANGS"
122 if ! use linguas_${lang}; then
123 rm "$(_chromium_crlang ${lang}).pak" || die
128 chromium_pkg_preinst() {
132 chromium_pkg_postinst() {
133 fdo-mime_desktop_database_update
134 gnome2_icon_cache_update
136 # For more info see bug #292201, bug #352263, bug #361859.
137 if ! has_version x11-themes/gnome-icon-theme &&
138 ! has_version x11-themes/oxygen-icons ; then
140 elog "Depending on your desktop environment, you may need"
141 elog "to install additional packages to get icons on the Downloads page."
143 elog "For KDE, the required package is kde-apps/oxygen-icons."
145 elog "For other desktop environments, try one of the following:"
146 elog " - x11-themes/gnome-icon-theme"
147 elog " - x11-themes/tango-icon-theme"
150 # For more info see bug #359153.
152 elog "Some web pages may require additional fonts to display properly."
153 elog "Try installing some of the following packages if some characters"
154 elog "are not displayed properly:"
155 elog " - media-fonts/arphicfonts"
156 elog " - media-fonts/bitstream-cyberbit"
157 elog " - media-fonts/droid"
158 elog " - media-fonts/ipamonafont"
159 elog " - media-fonts/ja-ipafonts"
160 elog " - media-fonts/takao-fonts"
161 elog " - media-fonts/wqy-microhei"
162 elog " - media-fonts/wqy-zenhei"
165 chromium_pkg_postrm() {
166 gnome2_icon_cache_update
170 if [[ "${EBUILD_PHASE}" != "compile" ]]; then
174 # Prevent user problems like bug #348235.
175 eshopts_push -s extglob
176 if is-flagq '-g?(gdb)?([1-9])'; then
178 ewarn "You have enabled debug info (i.e. -g or -ggdb in your CFLAGS/CXXFLAGS)."
179 ewarn "This produces very large build files causes the linker to consume large"
180 ewarn "amounts of memory."
182 ewarn "Please try removing -g{,gdb} before reporting a bug."
187 # ccache often causes bogus compile failures, especially when the cache gets
189 if has ccache ${FEATURES}; then
191 ewarn "You have enabled ccache. Please try disabling ccache"
192 ewarn "before reporting a bug."
197 if use_if_iuse custom-cflags; then
199 ewarn "You have enabled the custom-cflags USE flag."
200 ewarn "Please disable it before reporting a bug."
204 # If the system doesn't have enough memory, the compilation is known to
205 # fail. Print info about memory to recognize this condition.
207 einfo "$(grep MemTotal /proc/meminfo)"
208 einfo "$(grep SwapTotal /proc/meminfo)"
212 # @VARIABLE: EGYP_CHROMIUM_COMMAND
214 # Path to the gyp_chromium script.
215 : ${EGYP_CHROMIUM_COMMAND:=build/gyp_chromium}
217 # @VARIABLE: EGYP_CHROMIUM_DEPTH
219 # Depth for egyp_chromium.
220 : ${EGYP_CHROMIUM_DEPTH:=.}
222 # @FUNCTION: egyp_chromium
223 # @USAGE: [gyp arguments]
225 # Calls EGYP_CHROMIUM_COMMAND with depth EGYP_CHROMIUM_DEPTH and given
226 # arguments. The full command line is echoed for logging.
228 set -- "${EGYP_CHROMIUM_COMMAND}" --depth="${EGYP_CHROMIUM_DEPTH}" "$@"
234 # @USAGE: <USE flag> [GYP flag] [true suffix] [false suffix]
236 # If USE flag is set, echo -D[GYP flag]=[true suffix].
238 # If USE flag is not set, echo -D[GYP flag]=[false suffix].
240 # [GYP flag] defaults to use_[USE flag] with hyphens converted to underscores.
242 # [true suffix] defaults to 1. [false suffix] defaults to 0.
244 local gypflag="-D${2:-use_${1//-/_}}="
245 usex "$1" "${gypflag}" "${gypflag}" "${3-1}" "${4-0}"
248 # @FUNCTION: chromium_bundled_v8_version
249 # @USAGE: [path to version.cc]
251 # Outputs the version of v8 parsed from a (bundled) copy of the source code.
252 chromium_bundled_v8_version() {
253 local vf=${1:-v8/src/version.cc}
254 local major minor build patch
255 major=$(sed -ne 's/#define MAJOR_VERSION *\([0-9]*\)/\1/p' "${vf}")
256 minor=$(sed -ne 's/#define MINOR_VERSION *\([0-9]*\)/\1/p' "${vf}")
257 build=$(sed -ne 's/#define BUILD_NUMBER *\([0-9]*\)/\1/p' "${vf}")
258 patch=$(sed -ne 's/#define PATCH_LEVEL *\([0-9]*\)/\1/p' "${vf}")
259 echo "${major}.${minor}.${build}.${patch}"
262 # @FUNCTION: chromium_installed_v8_version
265 # Outputs the version of dev-lang/v8 currently installed on the host system.
266 chromium_installed_v8_version() {
267 local cpf=$(best_version dev-lang/v8)
268 local pvr=${cpf#dev-lang/v8-}