Add build, install and uninstall targets to Makefile
This commit is contained in:
+1
-1
@@ -32,4 +32,4 @@ go.work.sum
|
|||||||
# .vscode/
|
# .vscode/
|
||||||
|
|
||||||
# Binary output
|
# Binary output
|
||||||
/declpac
|
bin/
|
||||||
|
|||||||
@@ -1,8 +1,19 @@
|
|||||||
.PHONY: fmt vet check githook
|
.PHONY: build fmt vet check githook install uninstall
|
||||||
|
|
||||||
|
PKG := github.com/Riyyi/declpac
|
||||||
|
BIN := declpac
|
||||||
|
BUILD_DIR := bin
|
||||||
|
BUILD := $(BUILD_DIR)/$(BIN)
|
||||||
|
PREFIX ?= /usr/local
|
||||||
|
DESTDIR ?=
|
||||||
|
|
||||||
STAGED_GO := $(shell git diff --cached --name-only --diff-filter=ACM | grep '\.go$$')
|
STAGED_GO := $(shell git diff --cached --name-only --diff-filter=ACM | grep '\.go$$')
|
||||||
STAGED_PKGS := $(shell echo "$(STAGED_GO)" | tr ' ' '\n' | xargs -I{} dirname {} | sort -u | sed 's|^|./|')
|
STAGED_PKGS := $(shell echo "$(STAGED_GO)" | tr ' ' '\n' | xargs -I{} dirname {} | sort -u | sed 's|^|./|')
|
||||||
|
|
||||||
|
build:
|
||||||
|
@mkdir -p $(BUILD_DIR)
|
||||||
|
go build -o $(BUILD) ./cmd/declpac
|
||||||
|
|
||||||
fmt:
|
fmt:
|
||||||
@if [ -z "$(STAGED_GO)" ]; then exit 0; fi; \
|
@if [ -z "$(STAGED_GO)" ]; then exit 0; fi; \
|
||||||
unformatted=$$(gofmt -l $(STAGED_GO)); \
|
unformatted=$$(gofmt -l $(STAGED_GO)); \
|
||||||
@@ -23,3 +34,10 @@ githook:
|
|||||||
@echo 'make check' >> .git/hooks/pre-commit
|
@echo 'make check' >> .git/hooks/pre-commit
|
||||||
@chmod +x .git/hooks/pre-commit
|
@chmod +x .git/hooks/pre-commit
|
||||||
@echo "Installed pre-commit hook: .git/hooks/pre-commit"
|
@echo "Installed pre-commit hook: .git/hooks/pre-commit"
|
||||||
|
|
||||||
|
install: build
|
||||||
|
@mkdir -p $(DESTDIR)$(PREFIX)/bin
|
||||||
|
@install -m 0755 $(BUILD) $(DESTDIR)$(PREFIX)/bin/$(BIN)
|
||||||
|
|
||||||
|
uninstall:
|
||||||
|
@rm -f $(DESTDIR)$(PREFIX)/bin/$(BIN)
|
||||||
|
|||||||
Reference in New Issue
Block a user