#Packager: Frédéric Galusik <fredg~at~salixos~dot~org>

pkgname=go
pkgver=1.0.3
pkgrel=1fg
#arch=noarch
source=("http://go.googlecode.com/files/go${pkgver}.src.tar.gz"
"go.sh"
"go.csh")
sourcetemplate=http://people.salixos.org/fredg/packages/$pkgname/$pkgver
docs=("authors" "contributors" "license" "patents" "readme" "version")
url=http://golang.org/

slackdesc=\
(
#|-----handy-ruler------------------------------------------------------|
"go (The Go Programming Language)"
"Go is an open source programming environment that makes "
"it easy to build simple, reliable, and efficient software."
)


build() {
	export GOOS=linux
	if [ "$ARCH" == 'x86_64' ]; then
		export GOARCH=amd64
	fi
	if [ "$ARCH" == 'i686' ]; then
		export GOARCH=386
	fi

	export GOROOT=$SRC/go
	export GOROOT_FINAL=$PKG/usr/share/go
	export GOBIN=$GOROOT_FINAL/bin
	
	cd $SRC
	mkdir -p $PKG/usr/share
	cp -Rf go $PKG/usr/share
	
	cd $GOROOT_FINAL/src
	./make.bash
	
	# docs
	mkdir -p $PKG/usr/doc/$pkgname-$pkgver
	mv $GOROOT_FINAL/doc $PKG/usr/doc/$pkgname-$pkgver/
	(
	cd $PKG/usr/share/go
	ln -sf ../../doc/$pkgname-$pkgver/doc .
	)
	
	# misc
	install -Dm 644 $GOROOT_FINAL/misc/bash/go \
		$PKG/usr/share/bash-completion/completions/go
	install -Dm 644 $GOROOT_FINAL/misc/emacs/go-mode-load.el \
		$PKG/usr/share/emacs/site-lisp/go-mode-load.el
	install -Dm 644 $GOROOT_FINAL/misc/emacs/go-mode.el \
		$PKG/usr/share/emacs/site-lisp/go-mode.el
	install -Dm 644 $GOROOT_FINAL/misc/zsh/go \
        	$PKG/usr/share/zsh/site-functions/_go
        
        # vim files	        
        for f in ftdetect/gofiletype.vim \
        	autoload/go/complete.vim \
        	indent/go.vim \
         	ftplugin/go/fmt.vim \
         	ftplugin/go/godoc.vim \
         	ftplugin/go/import.vim \
         	syntax/go.vim \
         	syntax/godoc.vim \
         	plugin/godoc.vim ;
        do
        	install -Dm 644 $GOROOT_FINAL/misc/vim/$f \
        		$PKG/usr/share/vim/vimfiles/$f
        done
                
        # Remove object files from target src dir
        find $PKG/usr/share/go/src/ -type f -name '*.[ao]' -delete
        find $PKG/usr/share/go/src/pkg -type f -executable -delete
                	        	
        # go $PATH & uniform $GOPATH for programmers.
        mkdir -p $PKG/usr/share/go/site
        install -Dm 755 $SRC/go.sh $PKG/etc/profile.d/go.sh
        install -Dm 755 $SRC/go.csh $PKG/etc/profile.d/go.csh
}
