# Maintainer: surefire@cryptomile.net
pkgname=cpu_ctrl
pkgver=0+1f41c24+
pkgrel=1
pkgdesc="ipmi cpu fan control with core sensor"
arch=('i686' 'x86_64')
url="https://amuz.es/src/infra/cpu_ctrl"
license=('GPL')
conflicts=('cpu_ctrl')
provides=('cpu_ctrl')
replaces=('cpu_ctrl')
options=('!buildflags')
makedepends=('go' 'git')
source=('git+https://amuz.es/src/infra/cpu_ctrl.git'
        'cpu_ctrl.service'
)
md5sums=('SKIP'
        '979850d8d2adb3ef068c4c08b351ecef')

prepare() {
	
	export GOPATH="${srcdir}/gopath"
	export GOBIN="$GOPATH/bin"
	export PATH=$GOBIN:$PATH
	mkdir -p "$GOPATH/src/amuz.es/src/infra"

	go get -u github.com/kardianos/govendor

	ln -sfT "$srcdir/$pkgname" "$GOPATH/src/amuz.es/src/infra/$pkgname"
}

pkgver() {
	cd "${srcdir}/${pkgname}"
	printf '%s+%s+%s' \
		$(sed -e 's,/,+,g; s, ,,g' templates/.VERSION) \
		$(git rev-list --count HEAD...$(git log --pretty=format:%H -n 1 -- templates/.VERSION)) \
		$(git rev-parse --short HEAD) \
	;
}

build() {
	cd "${GOPATH}/src/amuz.es/src/infra/$pkgname"

	rm -rf vendor
	mkdir vendor
	govendor init	
	govendor fetch -v +missing

	BINARY=cpu_ctrl
	VERSION=`git describe --always`
	BUILD=`date +%FT%T%z`
	export LDFLAGS=
	export CGO_ENABLED=0 

	go build  -o ${BINARY}
	strip -x ${BINARY}
}

package() {
	cd "${GOPATH}/src/amuz.es/src/infra/$pkgname"

	install -Dm0755 -t "$pkgdir/usr/bin"                 ./cpu_ctrl
	install -Dm0644 -t "$pkgdir/usr/lib/systemd/system"  "$srcdir/cpu_ctrl.service"
}
