# Template file for 'chromium'
pkgname=chromium
version=17.0.963.56
wrksrc=$pkgname
create_wrksrc=yes
distfiles="
http://commondatastorage.googleapis.com/chromium-browser-official/$pkgname-$version.tar.bz2
http://commondatastorage.googleapis.com/nativeclient-mirror/nacl/nacl_sdk/nacl_sdk.zip"
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"
checksum="
270be138d499c6c2092644af69acab8310cb05c3d06c3afe7891e488c29b020f
964fe3a5ec56f2505649aba00f900abe4205674b7fdaa16772647d347173bb01"
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."

gtk_iconcache_dirs="/usr/share/icons/hicolor"

Add_dependency run desktop-file-utils
Add_dependency run hicolor-icon-theme

Add_dependency build pkg-config
Add_dependency build unzip
Add_dependency build yasm
Add_dependency build flex
Add_dependency build gperf
Add_dependency build perl ">=0"
Add_dependency build python ">=0"
Add_dependency build mit-krb5-devel
Add_dependency build libXrender-devel
Add_dependency build libXScrnSaver-devel
Add_dependency build libXcomposite-devel
Add_dependency build gtk+-devel
Add_dependency build libevent-devel
Add_dependency build icu-devel
Add_dependency build nss-devel
Add_dependency build libxslt-devel
Add_dependency build alsa-lib-devel
Add_dependency build libflac-devel
Add_dependency build dbus-glib-devel
Add_dependency build libXdamage-devel
Add_dependency build libXtst-devel
Add_dependency build pam-devel
Add_dependency build libgnome-keyring-devel
Add_dependency build libvpx-devel
Add_dependency build speex-devel
Add_dependency build libwebp-devel
Add_dependency build pulseaudio-devel
if [ "$XBPS_MACHINE" = "x86_64" ]; then
	Add_dependency build zlib32
	Add_dependency build libstdc++32
fi

pre_configure() {
	# Build NaCL.
	cd $wrksrc/nacl_sdk
	./naclsdk update pepper_16

	ln -s $wrksrc/nacl_sdk/pepper_16/toolchain/linux_x86_newlib \
		$wrksrc/$pkgname-$version/native_client/toolchain/linux_x86_newlib

	cd $wrksrc/$pkgname-$version
	patch -Np0 -i ${FILESDIR}/gcc-4.6.patch
}

do_configure() {
	cd $wrksrc/$pkgname-$version

	# We need to disable system_ssl until "next protocol negotiation" support is
	# available in our nss package.
	# (See https://bugzilla.mozilla.org/show_bug.cgi?id=547312)
	#
	# XXX: Disable CUPS until a package exists.
	build/gyp_chromium -f make build/all.gyp --depth=. \
		-Dwerror= \
		-Dlinux_sandbox_path=/usr/lib/chromium/chromium-sandbox \
		-Drelease_extra_cflags="$CFLAGS" \
		-Dffmpeg_branding=Chrome \
		-Dproprietary_codecs=1 \
		-Duse_system_libjpeg=1 \
		-Duse_system_libxslt=1 \
		-Duse_system_libxml=1 \
		-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_flac=1 \
		-Duse_system_icu=1 \
		-Duse_system_xdg_utils=1 \
		-Duse_system_vpx=1 \
		-Duse_system_speex=1 \
		-Duse_system_libwebp=1 \
		-Duse_gconf=0 \
		-Duse_cups=0
}

do_build() {
	cd $wrksrc/$pkgname-$version
	make BUILDTYPE=Release ${makejobs} chrome chrome_sandbox
}

do_install() {
	cd $wrksrc/$pkgname-$version

	vinstall out/Release/chrome 755 usr/lib/${pkgname} ${pkgname}
	vinstall out/Release/chrome_sandbox 4755 usr/lib/${pkgname} ${pkgname}-sandbox
	vinstall out/Release/chrome.pak 644 usr/lib/${pkgname}
	vinstall out/Release/resources.pak 644 usr/lib/${pkgname}
	vinstall out/Release/libffmpegsumo.so 755 usr/lib/${pkgname}
	vinstall out/Release/libppGoogleNaClPluginChrome.so 755 usr/lib/${pkgname}
	vcopy "out/Release/nacl_irt_x86_*.nexe" usr/lib/${pkgname}

	for f in locales resources; do
		vcopy out/Release/${f} usr/lib/chromium
	done
	find ${DESTDIR}/usr/lib/chromium/ -name '*.d' -type f -delete
	vinstall out/Release/chrome.1 644 usr/share/man/man1 chromium.1
	vinstall ${FILESDIR}/chromium.desktop 644 usr/share/applications
	for size in 16 22 24 32 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
	vinstall ${FILESDIR}/chromium.sh 755 usr/bin chromium
	vinstall LICENSE 644 usr/share/licenses/${pkgname}
}
