# Template file for 'chromium-unstable'
__pkgname=chromium
pkgname=${__pkgname}-unstable
version=19.0.1049.0
distfiles="http://commondatastorage.googleapis.com/chromium-browser-official/${__pkgname}-$version.tar.bz2"
short_desc="Google's attempt at creating a safer, faster, and more stable browser"
maintainer="davehome <davehome@redthumb.info.tm>"
homepage="http://www.chromium.org/"
license="BSD"
checksum=3bcf210fd3140700b7b3fd07796e0932e50bb55a6b13cd0ad55810322da43cce
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 (unstable build)."

replaces="chromium>=0"
provides="chromium-$version"
build_requires=11

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 yasm
Add_dependency build flex
Add_dependency build gperf
Add_dependency build libXrender-devel
Add_dependency build libXScrnSaver-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 GConf-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
Add_dependency build v8-devel
Add_dependency build libxml2-devel
Add_dependency build zlib-devel
Add_dependency build expat-devel
Add_dependency build libpng-devel
Add_dependency build jpeg-devel
Add_dependency build mit-krb5-devel
Add_dependency build libXcomposite-devel

Add_dependency full xdg-utils

wrksrc=chromium-$version

pre_configure()
{
	# Use external V8
	find v8 -type f \! -iname '*.gyp*' -delete
	rmdir v8/include
	ln -s /usr/include v8/include

	# zlib-1.2.5.1-r1 renames the OF macro in zconf.h
	# bug #383371 (Gentoo).
	sed -i '1i#define OF(x) x' \
		third_party/zlib/contrib/minizip/{ioapi,{,un}zip}.c \
		chrome/common/zip*.cc

	# Don't use type 'settings' in gyp files: http://crbug.com/96629
	find third_party -type f -path '*.gyp' -print0 | \
		xargs -0 sed -i "s|'type': 'settings',|'type': 'none',|g"
}

do_configure()
{
	# 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.
	GYP_DEFINES="\
		gcc_version=46 \
		werror= \
		no_strict_aliasing=1 \
		linux_sandbox_path=/usr/lib/chromium/chromium-sandbox \
		linux_sandbox_chrome_path=/usr/lib/chromium/chromium \
		release_extra_cflags="-fno-ipa-cp" \
		use_system_ffmpeg=0 \
		_build_ffmpegsumo=1 \
		ffmpeg_branding=Chrome \
		proprietary_codecs=1 \
		use_system_vpx=1 \
		use_system_speex=1 \
		use_system_flac=1 \
		use_system_libwebp=1 \
		use_system_libxslt=1 \
		use_system_libxml=1 \
		use_system_bzip2=1 \
		use_system_zlib=1 \
		use_system_libexpat=1 \
		use_system_v8=1 \
		use_system_sqlite=0 \
		use_system_libpng=1 \
		use_system_libjpeg=1 \
		use_system_yasm=1 \
		use_system_libevent=1 \
		use_system_icu=1 \
		use_system_xdg_utils=1 \
		use_system_ssl=0 \
		use_system_hunspell=0 \
		use_pulseaudio=1 \
		use_gconf=1 \
		use_cups=0 \
		use_gnome_keyring=1 \
		linux_link_gnome_keyring=1 \
		disable_nacl=1 \
		linux_strip_binary=1 \
		remove_webcore_debug_symbols=1 "
	export GYP_DEFINES
	python build/gyp_chromium -f make --depth=. build/all.gyp
}

do_build()
{
	make ${makejobs} BUILDTYPE=Release 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
	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}
}