From 2293db1039874583c4b8fe3f5c37af7b339efbd1 Mon Sep 17 00:00:00 2001 From: Katy248 Date: Wed, 10 Jul 2024 14:34:35 +0300 Subject: [PATCH] Updated Makefile --- Makefile | 51 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index ff9d46e..d4709c9 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,47 @@ -PREFIX ?= /usr/local +NAME := alr GIT_VERSION = $(shell git describe --tags ) -alr: - CGO_ENABLED=0 go build -ldflags="-X 'gitverse.ru/Xpamych/ALR/internal/config.Version=$(GIT_VERSION)'" +DESTDIR ?= +PREFIX ?= /usr/local +BIN := ./$(NAME) +INSTALED_BIN := $(DESTDIR)$(PREFIX)/bin/$(NAME) +COMPLETIONS_DIR := ./scripts/completion +BASH_COMPLETION := $(COMPLETIONS_DIR)/bash +ZSH_COMPLETION := $(COMPLETIONS_DIR)/zsh +INSTALLED_BASH_COMPLETION := $(DESTDIR)$(PREFIX)/share/bash-completion/completions/$(NAME) +INSTALLED_ZSH_COMPLETION := $(DESTDIR)$(PREFIX)/share/zsh/site-functions/_$(NAME) -clean: - rm -f alr +.PHONY: install clean clear uninstall check-no-root -install: alr installmisc - install -Dm755 alr $(DESTDIR)$(PREFIX)/bin/alr +export CGO_ENABLED := 0 +$(BIN): check-no-root + go build \ + -ldflags="-X 'gitverse.ru/Xpamych/ALR/internal/config.Version=$(GIT_VERSION)'" \ + -o $@ -installmisc: - install -Dm755 scripts/completion/bash $(DESTDIR)$(PREFIX)/share/bash-completion/completions/alr - install -Dm755 scripts/completion/zsh $(DESTDIR)$(PREFIX)/share/zsh/site-functions/_alr +check-no-root: + @if [[ "$$(whoami)" == 'root' ]]; then \ + echo "This target shouldn't run as root" 1>&2; \ + exit 1; \ + fi + +install: $(INSTALED_BIN) $(INSTALLED_BASH_COMPLETION) $(INSTALLED_ZSH_COMPLETION) + @echo "Installation done!" + +$(INSTALED_BIN): $(BIN) + install -Dm755 $< $@ + +$(INSTALLED_BASH_COMPLETION): $(BASH_COMPLETION) + install -Dm755 $< $@ + +$(INSTALLED_ZSH_COMPLETION): $(ZSH_COMPLETION) + install -Dm755 $< $@ uninstall: - rm -f /usr/local/bin/alr + rm -f \ + $(INSTALED_BIN) \ + $(INSTALLED_BASH_COMPLETION) \ + $(INSTALLED_ZSH_COMPLETION) -.PHONY: install clean uninstall installmisc alr \ No newline at end of file +clean clear: + rm -f $(BIN)