-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
60 lines (49 loc) · 1.96 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
60
VERSION := $(or $(AppVersion), "v0.0.0")
COMMIT := $(or $(shell git rev-parse --short HEAD), "unknown")
BUILDDATE := $(shell date +%Y-%m-%d)
LDFLAGS := -X 'main.AppVersion=$(VERSION)' -X 'main.CommitHash=$(COMMIT)' -X 'main.BuildDate=$(BUILDDATE)'
PLATFORMS = linux darwin windows
ARCHITECTURES = amd64 arm64 arm
all: build
tidy:
go mod tidy
test:
go test -v ./... -race -coverprofile=coverage.out -covermode=atomic
run: build
./chatz "This is test."
install: build
@cp man/chatz.1 man/chatz.old
@sed -e "s|BUILDDATE|$(BUILDDATE)|g" -e "s|VERSION|$(VERSION)|g" man/chatz.old > man/chatz.1
@cp chatz /usr/local/bin/chatz
@cp man/chatz.1 /usr/local/share/man/man1/chatz.1
@mv man/chatz.old man/chatz.1
@echo "chatz successfully installed."
uninstall:
@rm /usr/local/bin/chatz
@rm /usr/local/share/man/man1/chatz.1
@echo "chatz successfully uninstalled."
build:
go build -ldflags="$(LDFLAGS)" -o chatz .
dist:
@cp man/chatz.1 man/chatz.old
@sed -e "s|BUILDDATE|$(BUILDDATE)|g" -e "s|VERSION|$(VERSION)|g" man/chatz.old > man/chatz.1
@for platform in $(PLATFORMS); do \
for arch in $(ARCHITECTURES); do \
if [ "$$platform" = "darwin" ] && [ "$$arch" = "arm" ]; then continue; fi; \
extension=""; if [ "$$platform" = "windows" ]; then extension=".exe"; fi; \
CGO_ENABLED=0 GOOS=$$platform GOARCH=$$arch go build -ldflags="$(LDFLAGS)" -o build/chatz-$$platform-$$arch$$extension; \
if [ ! -f build/chatz-$$platform-$$arch ]; then continue; fi; \
if [ "$$platform" = "windows" ]; then continue; fi; \
cp build/chatz-$$platform-$$arch build/chatz; \
tar -zcvf build/chatz-$$platform-$$arch.tar.gz build/chatz man/chatz.1; \
done \
done
@rm build/chatz
@mv man/chatz.old man/chatz.1
# Generating checksum
@cd build && sha256sum * > ../checksum-sha256sum.txt
@cd build && md5sum * > checksum-md5sum.txt
@cd build && mv ../checksum-sha256sum.txt checksum-sha256sum.txt
@echo "Checksum generated successfully."
clean:
rm -rf chatz build