Improve makefile

Created .go/src which symlinks to vendor/. Running `make` now builds
yay using the packages in vendor. This can still be overiden by running
`make GOPATH=$HOME/go`

Even though the makefile calls git to get the version, that can be
overiden using `make MAJORVERSION=5 MINORVERSION=400`, skipping the call to git. This
allows building yay/yay-bin using the makefile

The yay binary is now always yay instead of taking the name of the
parent directory.

Added vet and fmt checks to `make test` for more checking.

Reordered some stuff, made sure the dependency order is correct. Any
command such as `make package` can be ran at any point, even after a
`make clean` instead of having to execute the correct make commands in
order.

Changed install form using `go install` to a traditional install. The
pkgbuilds can now use `make DESTDIR=$PKGDIR install`. Added uninstall to match.

One thing this commit does not do is have proper recepies which depend
on files instead of phonies. The reason for this is that it does not
play that well with go's build system. Go is smart enough to only
recompile needed files anyway.
This commit is contained in:
morganamilo 2018-03-23 04:23:16 +00:00
parent 7274e7d31a
commit 67bd8cc9a2
No known key found for this signature in database
GPG key ID: 6FE9E7996B0B082E
2 changed files with 48 additions and 16 deletions

1
.go/src Symbolic link
View file

@ -0,0 +1 @@
../vendor

View file

@ -1,31 +1,62 @@
.PHONY: all default install test build release clean .PHONY: all default install uninstall test build release clean
VERSION := 5.$(shell git rev-list --count master)
LDFLAGS=-ldflags '-s -w -X main.version=${VERSION}'
GOFILES := $(shell ls *.go | grep -v /vendor/)
ARCH=$(shell uname -m)
PKGNAME=yay
PACKAGE=${PKGNAME}_${VERSION}_${ARCH} PREFIX := /usr
DESTDIR :=
ifndef VERSION
MAJORVERSION := 5
MINORVERSION ?= $(shell git rev-list --count master)
endif
VERSION := ${MAJORVERSION}.${MINORVERSION}
LDFLAGS := -ldflags '-s -w -X main.version=${VERSION}'
GOFILES := $(shell ls *.go | grep -v /vendor/)
ARCH := $(shell uname -m)
PKGNAME := yay
BINNAME := yay
PACKAGE := ${PKGNAME}_${VERSION}_${ARCH}
export GOPATH=$(shell pwd)/.go
export GOROOT=/usr/lib/go
default: build default: build
all: clean build release package all: | clean package
install: install:
go install -v ${LDFLAGS} ${GO_FILES} install -Dm755 ${BINNAME} $(DESTDIR)$(PREFIX)/bin/${BINNAME}
install -Dm644 doc/${PKGNAME}.8 $(DESTDIR)$(PREFIX)/share/man/man8/${PKGNAME}.8
install -Dm644 completions/bash $(DESTDIR)$(PREFIX)/share/bash-completion/completions/${PKGNAME}
install -Dm644 completions/zsh $(DESTDIR)$(PREFIX)/share/zsh/site-functions/_${PKGNAME}
install -Dm644 completions/fish $(DESTDIR)$(PREFIX)/share/fish/vendor_completions.d/${PKGNAME}.fish
uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/${BINNAME}
rm -f $(DESTDIR)$(PREFIX)/share/man/man8/${PKGNAME}.8
rm -f $(DESTDIR)$(PREFIX)/share/bash-completion/completions/${PKGNAME}
rm -f $(DESTDIR)$(PREFIX)/share/zsh/site-functions/_${PKGNAME}
rm -f $(DESTDIR)$(PREFIX)/share/fish/vendor_completions.d/${PKGNAME}.fish
test: test:
go test ./... gofmt -l *.go
@test -z "$$(gofmt -l *.go)" || (echo "Files need to be linted" && false)
go vet
go test -v
build: build:
go build -v ${LDFLAGS} go build -v ${LDFLAGS} -o ${BINNAME}
release:
release: | test build
mkdir ${PACKAGE} mkdir ${PACKAGE}
cp ./yay ${PACKAGE}/ cp ./${BINNAME} ${PACKAGE}/
cp ./doc/yay.8 ${PACKAGE}/ cp ./doc/${PKGNAME}.8 ${PACKAGE}/
cp ./completions/zsh ${PACKAGE}/ cp ./completions/zsh ${PACKAGE}/
cp ./completions/fish ${PACKAGE}/ cp ./completions/fish ${PACKAGE}/
cp ./completions/bash ${PACKAGE}/ cp ./completions/bash ${PACKAGE}/
package:
package: release
tar -czvf ${PACKAGE}.tar.gz ${PACKAGE} tar -czvf ${PACKAGE}.tar.gz ${PACKAGE}
clean: clean:
-rm -rf ${PKGNAME}_* rm -rf ${PKGNAME}_*
rm -f ${BINNAME}