# Copyright 1999-2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
# $Header: $

EAPI=7

inherit eutils toolchain-funcs multilib

DESCRIPTION="It's a complete cross development package for 65(C)02 systems"
HOMEPAGE="http://www.cc65.org"
#SRC_URI="ftp://ftp.musoftware.de/pub/uz/cc65/snapshot/cc65-snapshot-sources-${PV}.tar.bz2"
#SRC_URI="ftp://ftp.musoftware.de/pub/uz/${PN}/${PN}-sources-${PV}.tar.bz2"
SRC_URI="https://github.com/${PN}/${PN}/archive/V${PV}.tar.gz -> ${PN}-sources-${PV}.tar.gz"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64 ~ppc ~sparc ~x86"
IUSE="doc"

DEPEND="doc? ( app-text/linuxdoc-tools )"
RDEPEND=""

#S="${WORKDIR}"/${PN}-snapshot-${PV}

#src_prepare() {
#	epatch "${FILESDIR}"/package-version.patch
#}

src_compile() {
	# the build needs to be split otherwise we can't specify CC
	# these makefiles are not parallel build aware
	emake -C src CC="$(tc-getCC)" AR="$(tc-getAR)" PREFIX="/usr" BUILD_ID="Gentoo ${PV}${PR}" || die "src build fail"
	emake -C libsrc CC="$(tc-getCC)" AR="$(tc-getAR)" PREFIX="/usr" BUILD_ID="Gentoo ${PV}${PR}" || die "libsrc build fail"
	use doc && emake -C doc html info
}

src_install() {
	emake -C src CC="$(tc-getCC)" AR="$(tc-getAR)" PREFIX="${D}/usr" BUILD_ID="Gentoo ${PV}${PR}" install || die "src install failed"
	emake -C libsrc CC="$(tc-getCC)" AR="$(tc-getAR)" PREFIX="${D}/usr" BUILD_ID="Gentoo ${PV}${PR}" install || die "libsrc install failed"
	use doc && emake CC="$(tc-getCC)" AR="$(tc-getAR)" PREFIX="${D}/usr" BUILD_ID="Gentoo ${PV}${PR}" doc html info
}