VERSION = $(shell git describe --tags)
GUIVERSION = $(shell git describe --tags)
BUILDTIME = $(shell date +%Y.%m.%d)

all: verbose
	-fixup --gui-check-plugin ../../../toolkits/gocui/gocui.so
	fixup --gui gocui --gui-verbose --gui-file ../../toolkits/gocui/gocui.so drives

go-build: goimports
	GO111MODULE=off go build \
		-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"

verbose: goimports
	-cp -a ../../../toolkits/gocui/gocui.so resources/
	GO111MODULE=off go install -v -x \
		-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"

install: goimports
	GO111MODULE=off go install \
		-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"

vet:
	GO111MODULE=off go vet

stderr: go-build
	echo "writing to /tmp/wit-test.log"
	./wit-test >/tmp/wit-test.log 2>&1

goimports:
	goimports -w *.go
	# // to globally reset paths:
	# // gofmt -w -r '"go.wit.com/gui/gadgets" -> "go.wit.com/lib/gadgets"' *.go

clean:
	rm -f go.*

gpl:
	wit-test --witcom

check-git-clean:
	@git diff-index --quiet HEAD -- || (echo "Git repository is dirty, please commit your changes first"; exit 1)

old-debian-release: install
	wit-test debian --dry-run --verbose --release

debian-release: install
	forge dirty
	rm -f ~/incoming/*.deb
	rm -f ~/go/lib/go-gui/*
	forge --install go.wit.com/apps/go-deb
	go-deb -h # check to make sure go-deb builds
	wit-test debian --verbose
	ls -hl ~/incoming/
	do-aptly

debian-release-force: install
	forge dirty
	rm -f ~/incoming/*.deb
	rm -f ~/go/lib/go-gui/*
	forge --install go.wit.com/apps/go-deb
	go-deb -h # check to make sure go-deb builds
	wit-test debian --force --verbose
	ls -hl ~/incoming/
	-dpkg-deb -c ~/incoming/go-gui-toolkits*.deb
	do-aptly

debian-release-build-only: install
	wit-test debian --verbose --release
