#Maintainer: George Vlahavas (vlahavas~at~gmail~dot~com)

pkgname=p7zip
pkgver=9.13
pkgrel=1gv
source=(http://downloads.sourceforge.net/project/p7zip/p7zip/${pkgver}/p7zip_${pkgver}_src_all.tar.bz2)
url=http://p7zip.sourceforge.net

slackdesc=\
(
#|-----handy-ruler------------------------------------------------------|
"p7zip (a file archiver with the highest compression ratio)"
"p7zip is a quick port of 7z.exe and 7za.exe (command line version of"
"7zip, see www.7-zip.org) for Unix."
"7-Zip is a file archiver with the highest compression ratio."
"Since 4.10, p7zip (like 7-zip) supports little-endian and big-endian"
"machines."
)


build() {
	cd $startdir/src/${pkgname}_$pkgver
	cp makefile.linux_x86_ppc_alpha_gcc_4.X makefile.machine
	# "Stolen" from gentoo
	sed -i -e "s:OPTFLAGS=-O:OPTFLAGS=${CXXFLAGS}:" -e 's:-s ::' makefile* 
	make all3 || return 1
	mkdir -p $startdir/pkg/usr/bin
	mkdir -p $startdir/pkg/usr/man/man1
	mkdir -p $startdir/pkg/usr/libexec/$PRGNAM
	cp -ap bin/* $startdir/pkg/usr/libexec/$PRGNAM
	cp -ap man1/* $startdir/pkg/usr/man/man1
	mv contrib/gzip-like_CLI_wrapper_for_7z/p7zip contrib/gzip-like_CLI_wrapper_for_7z/7zg
	cp contrib/gzip-like_CLI_wrapper_for_7z/7zg $startdir/pkg/usr/bin
	# Create the wrapper scripts
	cat > $startdir/pkg/usr/bin/7za <<EOF
#!/bin/sh
exec /usr/libexec/7za "\$@"
EOF

	cat > $startdir/pkg/usr/bin/7z <<EOF
#!/bin/sh
exec /usr/libexec/7z "\$@"
EOF
	# Using the docs it would copy more that it should, this is one of those times, manually is preferable ... :)
        mkdir -p $startdir/pkg/usr/doc/$pkgname-$pkgver
	mv DOCS/MANUAL DOCS/html
	cp -a ChangeLog DOCS/* README TODO $startdir/pkg/usr/doc/$pkgname-$pkgver
	# Fix
	chown -R root:root $startdir/pkg/
	chmod 755 $startdir/pkg/usr/bin/*
}