# Copyright 1999-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

inherit unpacker xdg

MY_PN="${PN%-bin}"
MY_ID="org.ladybird.Ladybird"

DESCRIPTION="Truly independent web browser, with a novel engine based on web standards"
HOMEPAGE="https://ladybird.org/ https://github.com/LadybirdBrowser/ladybird"
SRC_URI="
	amd64? (
		https://apt.ladybird.org/pool/main/l/${MY_PN}/${MY_PN}_${PV}-1~ubuntu26.04_amd64.deb
			-> ${P}-amd64.deb
	)
"
S="${WORKDIR}"

# Ladybird itself is BSD-2. /opt/ladybird/lib bundles ICU (Unicode-3.0),
# libidn2 and libunistring (GPL-2+ / LGPL-3+), FFmpeg (LGPL-2.1+), libdwarf
# (LGPL-2.1) and libdbus (AFL-2.1 or GPL-2+).
LICENSE="BSD-2 Unicode-3.0 || ( GPL-2+ LGPL-3+ ) LGPL-2.1+ LGPL-2.1 || ( AFL-2.1 GPL-2+ )"
SLOT="0"
KEYWORDS="~amd64"
RESTRICT="bindist mirror splitdebug strip"

QA_PREBUILT="opt/ladybird/*"

# Every system soname the shipped ELF objects import (scanelf over the .deb).
# ICU, FFmpeg, libidn2, libunistring, libdwarf and libdbus are bundled under
# /opt/ladybird/lib and found through RUNPATH=$ORIGIN:$ORIGIN/../lib, so they
# are deliberately absent. Qt needs a platform plugin: X11 or Wayland.
RDEPEND="
	>=dev-qt/qtbase-6.10.2:6[gui,widgets]
	|| (
		dev-qt/qtbase:6[X]
		dev-qt/qtbase:6[wayland]
	)
	>=dev-qt/qtpositioning-6.6.0:6
	dev-libs/glib:2
	dev-libs/wayland
	media-fonts/liberation-fonts
	media-libs/libglvnd
	media-libs/libpulse
	media-libs/vulkan-loader
	>=sys-libs/glibc-2.43
	sys-devel/gcc:*
	x11-libs/libdrm
	x11-libs/libxcb:=
	x11-libs/xcb-util-wm
"

src_install() {
	insinto /opt
	doins -r opt/${MY_PN}

	# doins drops the execute bit; restore it on the ELF executables only.
	fperms 0755 /opt/${MY_PN}/bin/{Ladybird,WebDriver}
	local helper
	for helper in opt/${MY_PN}/libexec/*; do
		fperms 0755 "/${helper}"
	done

	dosym -r /opt/${MY_PN}/bin/Ladybird /usr/bin/${MY_PN}

	insinto /usr/share
	doins -r usr/share/{applications,dbus-1,icons,metainfo}
}

pkg_postinst() {
	xdg_pkg_postinst

	ewarn "Ladybird is alpha software: some sites do not work, it crashes at times,"
	ewarn "and upstream makes no security promises yet. Do not rely on it for"
	ewarn "sensitive browsing."
}