#Packager: Panagiotis Papasotiriou <p~dot~papasot~at~yandex~dot~com>

pkgname=vice-sdl2
pkgver=3.6.1
pkgrel=1pp
source=("https://sourceforge.net/projects/vice-emu/files/releases/vice-$pkgver.tar.gz"
        "vice-icons.tgz" "vice.desktop" "vice" "disable-fc-cache.patch"
)
sourcetemplate=https://people.salixos.org/papasot/salix/$pkgname
url="https://vice-emu.sourceforge.io"
docs=("COPYING" "README" "NEWS")

slackdesc=\
(
#|-----handy-ruler------------------------------------------------------|
"vice (the Versatile Commodore Emulator)"
"VICE is an emulator collection which emulates the C64, the C64-DTV,"
"the C128, the VIC20, practically all PET models, the PLUS4 and the"
"CBM-II (aka C610/C510). An extra emulator is provided for C64 expanded"
"with the CMD SuperCPU."
"This is the SDL2 version of VICE."
""
"HomePage: https://vice-emu.sourceforge.io"
)

build() {
	cd $startdir/src/vice-$pkgver
	rm -rf src/lib/{liblame,libx264,libffmpeg} || return 1
	patch -p1 -i "$startdir/src/disable-fc-cache.patch" || return 1
	sed -i 's/lib64/lib/g' configure.ac
	autoreconf -fi
	CFLAGS="$SLKCFLAGS"
	CXXFLAGS="$SLKCFLAGS"
        
	./configure --prefix=/usr \
	            --libdir=/usr/lib${LIBDIRSUFFIX} \
	            --sysconfdir=/etc \
	            --enable-x64 \
	            --enable-ethernet \
	            --enable-external-ffmpeg \
	            --enable-sdlui2
	make -j $numjobs || return 1
	make install DESTDIR=$startdir/pkg

	mkdir -p $startdir/pkg/usr/bin
	cp $startdir/src/vice $startdir/pkg/usr/bin
	chmod a+x $startdir/pkg/usr/bin/vice

	mkdir -p $startdir/pkg/usr/share/applications
	cp $startdir/src/vice.desktop $startdir/pkg/usr/share/applications/

	# Copy icons to the right place
	for size in "16" "24" "32" "48" "64"; do
		mkdir -p $startdir/pkg/usr/share/icons/hicolor/$size\x$size/apps
		mv $startdir/src/vice-$size.png \
		   $startdir/pkg/usr/share/icons/hicolor/$size\x$size/apps/vice.png
	done

	# Remove unwanted files
	rm -rf $startdir/pkg/usr/share/info/dir
}
