# Copyright 1999-2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v3

EAPI=8

inherit desktop unpacker xdg

DESCRIPTION="A web browser rendering engine written in Rust, with WebGL and WebGPU support."
HOMEPAGE="https://servo.org/"

SRC_URI="fetch+https://github.com/servo/servo/releases/download/v${PV}/${PN%-bin}-x86_64-linux-gnu.tar.gz -> ${P}.tar.gz"

S="${WORKDIR}"

LICENSE="MPL-2.0"
SLOT="0"
KEYWORDS="-* amd64"

QA_PREBUILT="*"

src_install() {
	newicon servo/resources/servo.svg servo-bin.svg
	local x
	for x in 64 1024; do
		newicon -s ${x} servo/resources/servo_${x}.png servo-bin.png
	done

	sed -e '/^Exec=/ { s|SERVO_SRC_PATH/target/release/servo|/usr/bin/servo-bin| }' \
			-i servo/resources/org.servo.Servo.desktop || die
	sed -e '/^Icon=/ { s|servo|servo-bin| }' -i servo/resources/org.servo.Servo.desktop || die
	sed -e '/^#/d' -i servo/resources/org.servo.Servo.desktop || die
	newmenu servo/resources/org.servo.Servo.desktop servo-bin.desktop

	rm -f servo/resources/servo_*.png servo/resources/servo.svg servo/resources/org.servo.Servo.desktop || die

	insinto /opt
	doins -r servo

	fperms +x /opt/servo/servo
	dosym ../../opt/servo/servo /usr/bin/servo-bin
}