-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
72 lines (57 loc) · 1.7 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
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/make -fv
.ONESHELL:
SHELLFLAGS := -u nounset -ec
APPNAME := unmarked
MODNAME := github.com/shalomb/$(APPNAME)
VERSION := $(shell git describe --tags --long --always)
GO := $(shell command -v go)
GOVERSION := $(shell go version | awk '{ print $$3 }')
GOOS := $(shell go version | awk '{ split($$4, a, "/"); print a[1] }' )
GOARCH := $(shell go version | awk '{ split($$4, a, "/"); print a[2] }' )
GITBRANCH := $(shell git branch --show-current)
BUILDTIME := $(shell date -u '+%Y-%m-%dT%H:%M:%S%z')
BUILDHOST := $(shell hostname -f)
THIS_MAKEFILE := $(realpath $(lastword $(MAKEFILE_LIST)))
THIS_DIR := $(shell dirname $(THIS_MAKEFILE))
THIS_PROJECT := $(APPNAME)
GOLDFLAGS += -X main.AppName=$(APPNAME)
GOLDFLAGS += -X main.Branch=$(GITBRANCH)
GOLDFLAGS += -X main.BuildHost=$(BUILDHOST)
GOLDFLAGS += -X main.BuildTime=$(BUILDTIME)
GOLDFLAGS += -X main.Version=$(VERSION)
GOLDFLAGS += -X main.GoVersion=$(GOVERSION)
GOLDFLAGS += -X main.GoOS=$(GOOS)
GOLDFLAGS += -X main.GoArch=$(GOARCH)
GOFLAGS = -ldflags "$(GOLDFLAGS)"
UNAME_S := $(shell uname -s)
TARGET :=
ifeq ($(UNAME_S),Linux)
TARGET := "$(APPNAME)-linux"
endif
ifeq ($(UNAME_S),Darwin)
TARGET := "$(APPNAME)"
endif
.PHONY: build build-env serve watch run
build: build-env
echo $(GO) build $(GOFLAGS)
for os in darwin linux; do
GOOS=$${os} GOARCH=$(GOARCH) go build $(GOFLAGS) -o $(APPNAME)-$${os}-$(GOARCH)
done
clean: build-env tidy
rm -vf "$(APPNAME)"-*
tidy:
go get -u ./... # Upgrade all packages
go mod tidy
build-env:
go mod init $(APPNAME)
go mod download
run: build
./$(APPNAME)
deploy:
scp ./unmarked-darwin-arm64 host:~/.bin/unmarked
serve:
./$(APPNAME)
watch:
watcher
version:
./$(APPNAME) version