GITCOMMIT = $(shell git rev-list -1 HEAD)
GOVERSION = $(shell go version | cut -d' '  -f 3)
BUILDTIME = $(shell date -u --iso-8601=seconds)
VERSION = $(shell cat resources/VERSION)

# GO111MODULE=on

# try go get github.com/ahmetb/govvv
# this will add branch info & build RFC3339 date also

build:
	# shell things
	cd example-nohup;		go install	# minimum golang 'cmd'
	cd example-expect;		go install	# traditional 'expect' shell automation
	cd example-shell;		go install	# a tty wrapper
	cd example-gocui-mouse;		go install	# mouse interaction
	cd example-gocui-active;	go install	# ytalk
	cd example-gocui-colorstrue;	go install	# shell colors
	cd example-gocui-dynamic;	go install	# interactive movement

	# GUI things
	cd example-systray;		go install	# an example systray menu (cross platform)
	cd example-ui-splash;		go install	# an example GUI with drop down menus, etc
	cd example-ui-controlgallery;	go install	# an example GUI with drop down menus, etc
	cd example-ui-radiobutton;	go install	# slidebars, lists, radio buttons
	cd example-ui-table;		go install	# spreadsheet

	# misc
	cd example-lookupAAAA;		go install	# nslookup

	# golang things
	cd example-pprof;		go install	# dump out go process internals

prep:
	make -C example-nohup prep

sub-make:
	# shell things
	make -C example-expect			# traditional 'expect' shell automation
	make -C example-shell			# a tty wrapper
	make -C example-gocui-mouse		# mouse interaction

debug:
	go build -ldflags "-X main.GITCOMMIT=${GITCOMMIT} -X main.GOVERSION='${GOVERSION}' -X main.BUILDTIME='${BUILDTIME}' -X main.VERSION=${VERSION}"

gaper:
	# 'gaper' is a simple and smart golang tool that just rebuilds every time you change a file
	# go get -u github.com/maxcnunes/gaper
	gaper

#### NEVER DO THIS. THIS APPEARS TO INDUCE INSTABILITY IN GTK
bad-run:
	#### NEVER DO THIS. THIS APPEARS TO INDUCE INSTABILITY IN GTK
	# go run *.go

tag-version:
	# git push --delete origin v0.6.15 # to delete a tag upstream
	git diff --quiet 
	go build # just an extra check to make sure the damn thing builds
	git tag v${VERSION}
	git push --tags
	cp .git/refs/tags/v${VERSION} resources/tags/
	scp resources/VERSION root@mirrors.wit.com:/data/mirrors/cloud/control-panel/
	scp resources/VERSION root@mirrors.wit.com:/data/mirrors/cloud/control-panel/linux/

# should update every go dependancy (?)
update:
	git pull
	go get -v -t -u .

diff:
	git diff

# https://www.digitalocean.com/community/tutorials/how-to-build-go-executables-for-multiple-platforms-on-ubuntu-16-04
build-darwin:
	env GOOS=darwin GOARCH=amd64 go build

build-windows:
	env GOOS=windows GOARCH=amd64 go build
