#!/bin/sh

mkdir -p opk
cp ./sms_sdl opk/sms_sdl
cp ./sms_sdl.png opk/sms.png
cp ./docs/license opk/COPYING

# https://unix.stackexchange.com/questions/219268/how-to-add-new-lines-when-using-echo
print()
	case    ${IFS- } in
	(\ *)   printf  %b\\n "$*";;
	(*)     IFS=\ $IFS
	printf  %b\\n "$*"
	IFS=${IFS#?}
esac

# Create GmenuNx entry file plus other things

print '[Desktop Entry]
Type=Application
Name=SMS Plus GX
Comment=SMS/GG/SG emulator
Exec=sms_sdl %f
Icon=sms
Terminal=false
Type=Application
Categories=emulators;
X-OD-NeedsDownscaling=true' > opk/default."$1".desktop

mksquashfs ./opk smsplus_"$1".opk -all-root -noappend -no-exports -no-xattrs

rm -r opk
