2020-09-02 13:51:48 -04:00
|
|
|
GIT_EXISTS := $(shell git status > /dev/null 2>&1 ; echo $$?)
|
|
|
|
|
|
|
|
ifeq ($(GIT_EXISTS), 0)
|
|
|
|
ifeq ($(shell git tag --points-at HEAD),)
|
|
|
|
# Not currently on a tag
|
2020-09-06 14:00:23 -04:00
|
|
|
VERSION := $(shell git describe --tags | sed 's/^v//; s/-.*/-next/') # 1.2.3-next
|
2020-09-02 13:51:48 -04:00
|
|
|
else
|
|
|
|
# On a tag
|
|
|
|
VERSION := $(shell git tag --points-at HEAD)
|
|
|
|
endif
|
|
|
|
|
|
|
|
COMMIT := $(shell git rev-parse --verify HEAD)
|
2020-09-02 11:05:14 -04:00
|
|
|
endif
|
|
|
|
|
2020-09-07 12:55:32 -04:00
|
|
|
ROOT_INSTALL := install -o root -g 0
|
2020-09-02 11:05:14 -04:00
|
|
|
INSTALL_DIR := /usr/local/bin
|
2020-09-07 12:55:32 -04:00
|
|
|
DESKTOP_DIR := ~/.local/share/applications/
|
2020-09-02 11:05:14 -04:00
|
|
|
|
|
|
|
.PHONY: all build install desktop clean uninstall fmt
|
|
|
|
|
|
|
|
all: build
|
|
|
|
|
|
|
|
build:
|
2020-09-02 13:51:48 -04:00
|
|
|
ifneq ($(GIT_EXISTS), 0)
|
|
|
|
# No Git repo
|
|
|
|
$(error No Git repo was found, which is needed to compile the commit and version)
|
|
|
|
endif
|
2020-09-02 11:05:14 -04:00
|
|
|
@echo "Downloading dependencies"
|
|
|
|
@go env -w GO111MODULE=on ; go mod download
|
|
|
|
@echo "Building binary"
|
|
|
|
@go env -w GO111MODULE=on CGO_ENABLED=0 ; go build -ldflags="-s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.builtBy=Makefile"
|
|
|
|
|
|
|
|
install:
|
|
|
|
@echo "Installing Amfora to $(INSTALL_DIR)"
|
2020-09-07 12:55:32 -04:00
|
|
|
@$(ROOT_INSTALL) -m 755 amfora $(INSTALL_DIR)
|
2020-09-02 11:05:14 -04:00
|
|
|
|
|
|
|
desktop:
|
|
|
|
@echo "Setting up desktop file"
|
2020-09-07 12:55:32 -04:00
|
|
|
@install -m 644 amfora.desktop $(DESKTOP_DIR)
|
2020-09-02 11:05:14 -04:00
|
|
|
@update-desktop-database $(DESKTOP_DIR)
|
|
|
|
|
|
|
|
clean:
|
|
|
|
@echo "Removing Amfora binary in local directory"
|
|
|
|
@$(RM) amfora
|
|
|
|
|
|
|
|
uninstall:
|
|
|
|
@echo "Removing Amfora from $(INSTALL_DIR)"
|
|
|
|
@$(RM) $(INSTALL_DIR)/amfora
|
|
|
|
@echo "Removing desktop file"
|
|
|
|
-@$(RM) $(DESKTOP_DIR)/amfora.desktop
|
|
|
|
-@update-desktop-database $(DESKTOP_DIR)
|
|
|
|
|
|
|
|
fmt:
|
|
|
|
go fmt ./...
|