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

inherit eutils toolchain-funcs multilib linux-mod

DESCRIPTION="OpenCBM is a package to control and use serial devices as used by most Commodore (CBM) 8-bit mach"
HOMEPAGE="http://opencbm.trikaliotis.net/"
SRC_URI="mirror://sourceforge/${PN}/${P}-src.zip"

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

DEPEND="virtual/linux-sources
	dev-embedded/cc65
	app-text/linuxdoc-tools"

BUILD_PARAMS="KDIR=$KERNEL_DIR"
MODULE_NAMES="cbm(misc:${S}/sys/linux:${S}/sys/linux)"
BUILD_TARGETS="all"
MODULESD_NOVFS_ENABLED=""

src_unpack() {
	unpack ${A}
	cd ${S}
	# convert linefeed
	edos2unix `find . -name '*' -type f`
	# 6502 sources ar always up to date
	touch `find . -name '*.?65' -type f`
	# add debian patches no demo & doc & no kernel
	epatch ${FILESDIR}/${PV}/*
	# sed correct path
	sed -e 's,^PREFIX.*,PREFIX = /usr,' \
                -e 's,/man/man1,/share/man/man1,g' \
                -e 's,/info,/share/info,g' -i ${S}/LINUX/config.make
	# copy module makefile that don't itefer with gentoo kernel build system
	cp ${FILESDIR}/Makefile ${S}/sys/linux/Makefile
}

src_compile() {
	emake -f LINUX/Makefile CC="$(tc-getCC)" AR="$(tc-getAR)" showvars
	emake -f LINUX/Makefile CC="$(tc-getCC)" AR="$(tc-getAR)"
	linux-mod_src_compile
}

src_install() {
	emake -f LINUX/Makefile PREFIX="${D}/usr" install
	linux-mod_src_install
        generate_modulesd

}

pkg_postinst() {
        linux-mod_pkg_postinst
}

pkg_postrm() {
        linux-mod_pkg_postrm
}