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

EAPI=8

inherit cmake desktop xdg

DESCRIPTION="Starbound source code leak, maintained by the community"
HOMEPAGE="https://github.com/OpenStarbound/OpenStarbound"
SRC_URI="https://github.com/OpenStarbound/OpenStarbound/archive/refs/tags/v${PV}.tar.gz -> ${P}.tar.gz"
S="${WORKDIR}/OpenStarbound-${PV}/source"

# OpenStarbound's license is uhh... ambiguous considering it's a source
# code leak maintained by the community. Let's go with all-rights-reserved
# to be safe.
LICENSE="all-rights-reserved"
SLOT="0"
KEYWORDS="~amd64"
RESTRICT="test"

DEPEND="
	app-arch/zstd:=
	dev-cpp/abseil-cpp
	dev-cpp/cpptrace
	dev-cpp/cpr
	dev-libs/jemalloc:=
	dev-libs/re2:=
	media-libs/freetype
	media-libs/glew:=
	media-libs/imgui:=[opengl,sdl3,truetype(-)]
	media-libs/libpng:=
	media-libs/libsdl3
	media-libs/libvorbis
	media-libs/opus
	sys-libs/zlib-ng
"
RDEPEND="${DEPEND}"

PATCHES=( "${FILESDIR}/${PN}-0.1.15.1-no-vcpkg.patch" )

src_configure() {
	local mycmakeargs=(
		-DSTAR_USE_JEMALLOC=ON
	)
	cmake_src_configure
}

src_compile() {
	# For some reason, something is adding -std=gnu++20 to CXXFLAGS erroniously.
	# Just sed it out.
	sed -i '/-std=gnu++20/d' "${BUILD_DIR}/build.ninja" || die
	cmake_src_compile
}

src_install() {
	einstalldocs

	dobin ../dist/starbound
	dobin ../dist/starbound_server
	insinto /usr/share/openstarbound/
	doins -r ../assets/opensb
	dobin "${FILESDIR}/openstarbound"

	doicon -s 256 client/openstarbound.png
	make_desktop_entry --eapi9 openstarbound -n OpenStarbound -i openstarbound
}