# Template file for 'chromium'
pkgname=chromium
version=21.0.1180.79
_naclsdkver=20.0.1132.47
patch_args="-lNp0"
revision=1
wrksrc=$pkgname
create_wrksrc=yes
create_srcdir=yes
build_wrksrc=${pkgname}-${version}
depends="desktop-file-utils hicolor-icon-theme"
makedepends="pkg-config which unzip yasm flex gperf perl python
libudev-devel>=138 libpng-devel>=1.5.10 libgcrypt-devel libelf-devel
mit-krb5-devel libXrender-devel libXScrnSaver-devel libXcomposite-devel
libX11-devel libXi-devel gtk+-devel libevent-devel nss-devel alsa-lib-devel
dbus-glib-devel libXdamage-devel libXtst-devel pam-devel libgnome-keyring-devel
libvpx-devel speex-devel libwebp-devel>=0.2.0 pulseaudio-devel cups-devel
hunspell-devel libflac-devel subversion"
if [ "$XBPS_MACHINE" = "x86_64" ]; then
	makedepends="${makedepends} gcc-multilib"
fi

short_desc="Google's attempt at creating a safer, faster, and more stable browser"
maintainer="Juan RP <xtraeme@gmail.com>"
homepage="http://www.chromium.org/"
license="BSD"
_url_base="http://commondatastorage.googleapis.com"
distfiles="
${_url_base}/chromium-browser-official/$pkgname-$version.tar.bz2
${_url_base}/nativeclient-mirror/nacl/nacl_sdk/${_naclsdkver}/naclsdk_linux.bz2"
checksum="
880971f3958fc586be5ed8ddaa3a8308731c1ae84c3623d9c5fe0ab057bc4ccb
ac371e9e8312f01856e892b29c788acfa03cbb79aaabe0b5a3ae0cd2f8399a91"
long_desc="
 Chromium is an open-source browser project that aims to build a safer,
 faster, and more stable way for all Internet users to experience the web.

 Chromium serves as a base for Google Chrome, which is Chromium rebranded
 (name and logo) with very few additions such as usage tracking and an
 auto-updater system.

 This package contains the Chromium browser."

pre_configure() {
	# http://code.google.com/p/chromium/issues/detail?id=109527
	sed -i 's|glib/gutils.h|glib.h|' ui/base/l10n/l10n_util.cc

	# Unpack nacl, its a POSIX tar archive compressed with bzip2.
	if [ "${XBPS_MACHINE}" != "i686" ]; then
		tar xf ${wrksrc}/naclsdk_linux -C ${wrksrc}
		ln -s ${wrksrc}/pepper_${_naclsdkver%%.*}/toolchain/linux_x86_newlib \
			native_client/toolchain/linux_x86_newlib
	fi
}

do_configure() {
	if [ "${XBPS_MACHINE}" = "i686" ]; then
		_nacl="-Ddisable_nacl=1"
	fi

	build/gyp_chromium -f make build/all.gyp --depth=. \
		-Dwerror= -Dlinux_sandbox_path=/usr/lib/chromium/chromium-sandbox \
		-Drelease_extra_cflags="$CFLAGS" -Dlinux_use_gold_binary=0 \
		-Dlinux_use_gold_flags=0 -Dffmpeg_branding=Chrome \
		-Dproprietary_codecs=1 -Duse_system_libjpeg=1 \
		-Duse_system_libxml=0 -Duse_system_bzip2=1 \
		-Duse_system_zlib=1 -Duse_system_libpng=1 \
		-Duse_system_ffmpeg=0 -Duse_system_yasm=1 \
		-Duse_system_libevent=1 -Duse_system_ssl=0 \
		-Duse_system_xdg_utils=1 -Duse_system_vpx=1 \
		-Duse_system_speex=1 -Duse_system_libwebp=1 \
		-Duse_hunspell=1 -Duse_system_flac=1 \
		-Duse_gconf=0 -Ddisable_glibc=1 ${_nacl}
}

do_build() {
	make BUILDTYPE=Release ${makejobs} chrome chrome_sandbox
}

do_install() {
	vinstall out/Release/chrome 755 usr/lib/${pkgname} ${pkgname}
	vinstall out/Release/chrome_sandbox 4755 usr/lib/${pkgname} ${pkgname}-sandbox

	cp out/Release/{*.pak,libffmpegsumo.so} ${DESTDIR}/usr/lib/chromium

	if [ "${XBPS_MACHINE}" != "i686" ]; then
		cp out/Release/{nacl_helper{,_bootstrap}} \
			out/Release/{libppGoogleNaClPluginChrome.so,nacl_irt_*.nexe} \
			${DESTDIR}/usr/lib/chromium
	fi

	cp -a out/Release/locales ${DESTDIR}/usr/lib/chromium

	vinstall out/Release/chrome.1 644 usr/share/man/man1 chromium.1
	vinstall ${FILESDIR}/chromium.desktop 644 usr/share/applications

	for size in 22 24 48 64 128 256; do
		install -Dm644 "chrome/app/theme/chromium/product_logo_${size}.png" \
		${DESTDIR}/usr/share/icons/hicolor/${size}x${size}/apps/chromium.png
	done
	for size in 16 32; do
		install -Dm644 "chrome/app/theme/default_100_percent/chromium/product_logo_${size}.png" \
		${DESTDIR}/usr/share/icons/hicolor/${size}x${size}/apps/chromium.png
	done

	vinstall ${FILESDIR}/chromium.sh 755 usr/bin chromium
	vinstall LICENSE 644 usr/share/licenses/${pkgname}
}
