mirror of
https://github.com/makew0rld/amfora.git
synced 2024-09-27 23:05:55 -04:00
🔨 New Makefile
Contributed by Chloe Kudryavtsev on mastodon with slight modification.
This commit is contained in:
parent
a7078c198c
commit
bf29ec2a97
69
Makefile
69
Makefile
@ -1,54 +1,35 @@
|
|||||||
GIT_EXISTS := $(shell git status > /dev/null 2>&1 ; echo $$?)
|
GITV != git describe --tags
|
||||||
|
GITC != git rev-parse --verify HEAD
|
||||||
|
SRC != find -type f -name '*.go' ! -name '*_test.go'
|
||||||
|
TEST != find -type f -name '*_test.go'
|
||||||
|
|
||||||
ifeq ($(GIT_EXISTS), 0)
|
PREFIX ?= /usr/local
|
||||||
ifeq ($(shell git tag --points-at HEAD),)
|
VERSION ?= $(GITV)
|
||||||
# Not currently on a tag
|
COMMIT ?= $(GITC)
|
||||||
VERSION := $(shell git describe --tags | sed 's/^v//; s/-.*/-next/') # 1.2.3-next
|
BUILDER ?= Makefile
|
||||||
else
|
|
||||||
# On a tag
|
|
||||||
VERSION := $(shell git tag --points-at HEAD)
|
|
||||||
endif
|
|
||||||
|
|
||||||
COMMIT := $(shell git rev-parse --verify HEAD)
|
GO := go
|
||||||
endif
|
INSTALL := install
|
||||||
|
RM := rm
|
||||||
|
|
||||||
ROOT_INSTALL := install -o root -g 0
|
amfora: go.mod go.sum $(SRC)
|
||||||
INSTALL_DIR := /usr/local/bin
|
go env -w GO111MODULE=on CGO_ENABLED=0 ; $(GO) build -o $@ -ldflags="-s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.builtBy=$(BUILDER)"
|
||||||
DESKTOP_DIR := ~/.local/share/applications/
|
|
||||||
|
|
||||||
.PHONY: all build install desktop clean uninstall fmt
|
|
||||||
|
|
||||||
all: build
|
|
||||||
|
|
||||||
build:
|
|
||||||
ifneq ($(GIT_EXISTS), 0)
|
|
||||||
# No Git repo
|
|
||||||
$(error No Git repo was found, which is needed to compile the commit and version)
|
|
||||||
endif
|
|
||||||
@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)"
|
|
||||||
@$(ROOT_INSTALL) -m 755 amfora $(INSTALL_DIR)
|
|
||||||
|
|
||||||
desktop:
|
|
||||||
@echo "Setting up desktop file"
|
|
||||||
@install -m 644 amfora.desktop $(DESKTOP_DIR)
|
|
||||||
@update-desktop-database $(DESKTOP_DIR)
|
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
@echo "Removing Amfora binary in local directory"
|
$(RM) -f amfora
|
||||||
@$(RM) amfora
|
|
||||||
|
|
||||||
|
.PHONY: install
|
||||||
|
install: amfora amfora.desktop
|
||||||
|
install -Dm 755 amfora $(PREFIX)/bin/amfora
|
||||||
|
install -Dm 644 amfora.desktop $(PREFIX)/share/applications/amfora.desktop
|
||||||
|
|
||||||
|
.PHONY: uninstall
|
||||||
uninstall:
|
uninstall:
|
||||||
@echo "Removing Amfora from $(INSTALL_DIR)"
|
$(RM) -f $(PREFIX)/bin/amfora
|
||||||
@$(RM) $(INSTALL_DIR)/amfora
|
$(RM) -f $(PREFIX)/share/applications/amfora.desktop
|
||||||
@echo "Removing desktop file"
|
|
||||||
-@$(RM) $(DESKTOP_DIR)/amfora.desktop
|
|
||||||
-@update-desktop-database $(DESKTOP_DIR)
|
|
||||||
|
|
||||||
|
# Development helpers
|
||||||
|
.PHONY: fmt
|
||||||
fmt:
|
fmt:
|
||||||
go fmt ./...
|
go fmt ./...
|
||||||
|
Loading…
Reference in New Issue
Block a user