### this file is sourced not run
PKGVER=721.0 # the version as used in Fatdog64 721, aka 2017.12
PKGBUILD=1
PKGARCH=x86_64

# source: kirk & step
TARBALL=rox-filer-master-12102017.tar.xz
MD5SUM=6b42ac3d113bbe45a948231461048d02
SRC_URL=http://distro.ibiblio.org/fatdog/source/800/$TARBALL
BUNDLE=

DESTDIR=/usr/local/apps
ROXFILER=ROX-Filer-jun7

SLACKREQ='gtk2'
SLACKDESC="rox-filer-jun7: rox-filer-jun7 $PKGVER (GTK file and desktop manager)  
rox-filer-jun7:  
rox-filer-jun7: Fork of rox-filer by jun7, with advanced features.
rox-filer-jun7: A fast, lightweight, file and desktop manager based on GTK2.  
rox-filer-jun7: 
rox-filer-jun7: https://github.com/jun7/rox-filer
rox-filer-jun7: 
rox-filer-jun7: This is the version of rox-filer-jun7 in Fatdog64 721.
rox-filer-jun7: 
rox-filer-jun7: 
rox-filer-jun7: 
"

DEBUG= # "yes" to enable debugging

### default pkg_download
### prepare
pkg_prepare() {
	pkg_prepare_default &&
	cd tmp/rox* &&
	patch -Np1 -i ../pkg/rox-filer-i18n-desktop-comment.patch &&
	#patch -Np1 -i ../pkg/rox-filer-2013.6-comment.patch && # superseded by below
	patch -Np1 -i ../pkg/tip-from-comment-file.patch &&
	#patch -Np1 -i ../pkg/rox-filer-default-settings.patch &&
	patch -Np1 -i ../pkg/rox-filer-default-settings-2017.11.patch &&
	patch -Np1 -i ../pkg/remove-gethostbyname.patch &&
	patch -Np1 -i ../pkg/export-pinboard-click.patch &&
	patch -Np1 -i ../pkg/rpc-add-drive-icon.patch &&
	patch -Np1 -i ../pkg/export-panel-click.patch &&
	patch -Np1 -i ../pkg/minibuffer-settings.patch &&
	patch -Np1 -i ../pkg/select-last-dot-on-rename.patch &&	
	#patch -Np1 -i ../pkg/toolbar-icon-for-context-menu.patch &&
	echo "#include <math.h>" >> ROX-Filer/src/panel.h &&     # for "roundl" in panel export click
	echo "#include <math.h>" >> ROX-Filer/src/pinboard.h &&  # for "roundl" in pinboard export click
	echo "#include <locale.h>" >> ROX-Filer/src/i18n.h &&    # upstream bug - for setlocale in i18n.c
	sed -i -e 's|static const||' ROX-Filer/src/view_collection.c && # upstream bug
	sed -i -e 's|"gdb"|"gdb --args"|' ROX-Filer/AppRun && # always prefix debugger with args
	
	true
}

### default pkg_package
### build
pkg_build() {
	[ $DEBUG ] && CFLAGS="$CFLAGS -O0 -g"

	cd /tmp/rox*/ROX-Filer/src &&
	#autoconf && # automatically called
	sed -i -e "s@euid == 0 ||@@" main.c # remove root message

	export MAKE="make $MAKEFLAGS"
	cd /tmp/rox*/ROX-Filer &&
	
	# build
	./AppRun --compile &&
	# build docs
	cd src/Docs &&
	make MAN=/usr/share/man/man1 &&
	cd ../.. &&
	
	# cleanup
	rm -rf build &&
	if [ -z $DEBUG ]; then
		rm -rf ROX-Filer.dbg src
	else
		install -m755 /tmp/pkg/rox-debug /usr/bin
	fi &&
	cd .. &&
	rm -rf $DESTDIR &&	
	mkdir -p $DESTDIR &&
	mv ROX-Filer $DESTDIR/$ROXFILER &&
	rm -f /usr/bin/rox &&
	
	# helper script. Note: this is the only way to start ROX-Filer properly.
    # ln -s ROX-Filer won't work (missing icons)
    # ln -s AppRun also won't work (immediately quit)
    # BLFS can get away with ln -s ROX-Filer because it patches the source.
    # we don't want to patch the source
    sed -i -e "s|@DESTDIR|$DESTDIR/$ROXFILER|" /tmp/pkg/rox &&
    install -m755 /tmp/pkg/rox /usr/bin &&

    #  desktop file
	mkdir -p /usr/share/applications &&
	install -m644 /tmp/pkg/rox.desktop /usr/share/applications &&
	
	# fatdog icon theme
	cp -a /tmp/pkg/ROX/* $DESTDIR/$ROXFILER/ROX &&
	mkdir -p /usr/share/icons &&
	ln -s $DESTDIR/$ROXFILER/ROX /usr/share/icons/ROX &&
	
	# translations
	cp -a /tmp/pkg/Messages/* $DESTDIR/$ROXFILER/Messages &&

	# this is for lxqt-panel and qt5ct
	for p in audio-volume-high.png audio-volume-medium.png \
	         audio-volume-low.png   audio-volume-muted.png;
	do
		ln -s ../../../../../share/pixmaps/mini-icons/$p $DESTDIR/$ROXFILER/ROX/MIME || return 1
	done &&
	
	pkg_build_slackdesc
}
   
