-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
59 lines (46 loc) · 1.5 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
NAME = kf2-antiddos
VERSION := $(shell git describe)
GOCMD = go
LDFLAGS := "$(LDFLAGS) -s -w -X 'main.AppVersion=$(VERSION)'"
GOBUILD = $(GOCMD) build -ldflags=$(LDFLAGS)
SRCMAIN = ./cmd/$(NAME)
SRCDOC = ./doc
BINDIR = bin
BIN = $(BINDIR)/$(NAME)
README = $(SRCDOC)/README
LICENSE = LICENSE
PREFIX = /usr
.PHONY: all prep doc build check-build linux-amd64 windows-amd64 compile install check-install uninstall clean
all: build
prep: clean
go mod init $(NAME); go mod tidy
mkdir $(BINDIR)
doc: check-build
test -d $(SRCDOC) || mkdir $(SRCDOC)
$(BIN) --help > $(README)
build: prep
$(GOBUILD) -o $(BIN) $(SRCMAIN)
check-build:
test -e $(BIN)
linux-amd64: prep
GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(BIN)-linux-amd64 $(SRCMAIN)
windows-amd64: prep
GOOS=windows GOARCH=amd64 $(GOBUILD) -o $(BIN)-windows-amd64.exe $(SRCMAIN)
compile: linux-amd64 windows-amd64
install: check-build doc
install -m 755 -d $(PREFIX)/bin/
install -m 755 $(BIN) $(PREFIX)/bin/
install -m 755 -d $(PREFIX)/share/licenses/$(NAME)/
install -m 644 $(LICENSE) $(PREFIX)/share/licenses/$(NAME)/
install -m 755 -d $(PREFIX)/share/doc/$(NAME)/
install -m 644 $(README) $(PREFIX)/share/doc/$(NAME)/
check-install:
test -e $(PREFIX)/bin/$(NAME) || \
test -d $(PREFIX)/share/licenses/$(NAME) || \
test -d $(PREFIX)/share/doc/$(NAME)
uninstall: check-install
rm -f $(PREFIX)/bin/$(NAME)
rm -rf $(PREFIX)/share/licenses/$(NAME)
rm -rf $(PREFIX)/share/doc/$(NAME)
clean:
rm -rf $(BINDIR)