-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
71 lines (62 loc) · 2.41 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
# Copyright (C) 2022 xaxys. All rights reserved.
PACKAGE_NAME := maintainman
ifeq ($(OS),Windows_NT) # is Windows_NT on XP, 2000, 7, Vista, 10...
GO ?= go.exe
PWD := ${CURDIR}
TARGET := $(PACKAGE_NAME).exe
BUILD_TAGS := $(shell git describe --tags --always --dirty="-dev")
BUILD_TIME := $(shell echo %date% %time%)
GIT_COMMIT := $(shell git rev-parse --short HEAD)
GO_VERSION := $(shell go version)
GOPATH := $(subst ;,,$(shell go env GOPATH))
RM_CMD_1 := del /s /q
RM_CMD_2 :=
EXPORT := set
else
GO ?= go
PWD := ${CURDIR}
TARGET := $(PACKAGE_NAME)
BUILD_TAGS := $(shell git describe --tags --always --dirty="-dev")
BUILD_TIME := $(shell date --utc)
GIT_COMMIT := $(shell git rev-parse --short HEAD)
GO_VERSION := $(shell go version)
GOPATH := $(shell go env GOPATH)
RM_CMD_1 := find . -type f -name
RM_CMD_2 := -delete
EXPORT := export
endif
all: build
build:
@echo Building $(PACKAGE_NAME) ...
@$(GO) env -w CGO_ENABLED="1"
@$(GO) build \
-ldflags="-X 'main.BuildTags=$(BUILD_TAGS)' -X 'main.BuildTime=$(BUILD_TIME)' -X 'main.GitCommit=$(GIT_COMMIT)' -X 'main.GoVersion=$(GO_VERSION)'" \
-o $(TARGET) $(PWD)/main.go
test: test-short
test-ci: clean
@echo Testing $(PACKAGE_NAME) ...
@$(GO) env -w CGO_ENABLED="1"
@$(GO) test \
-ldflags="-X 'main.BuildTags=$(BUILD_TAGS)' -X 'main.BuildTime=$(BUILD_TIME)' -X 'main.GitCommit=$(GIT_COMMIT)' -X 'main.GoVersion=$(GO_VERSION)'" \
-timeout=30m -coverprofile=coverage.out ./...
test-full: clean
@echo Testing $(PACKAGE_NAME) ...
@$(GO) env -w CGO_ENABLED="1"
@$(GO) test \
-ldflags="-X 'main.BuildTags=$(BUILD_TAGS)' -X 'main.BuildTime=$(BUILD_TIME)' -X 'main.GitCommit=$(GIT_COMMIT)' -X 'main.GoVersion=$(GO_VERSION)'" \
-timeout=30m -race -coverprofile=coverage.out ./...
test-short: clean
@echo Testing $(PACKAGE_NAME) ...
@$(GO) env -w CGO_ENABLED="1"
@$(GO) test \
-ldflags="-X 'main.BuildTags=$(BUILD_TAGS)' -X 'main.BuildTime=$(BUILD_TIME)' -X 'main.GitCommit=$(GIT_COMMIT)' -X 'main.GoVersion=$(GO_VERSION)'" \
-timeout=30m -race -short -coverprofile=coverage.out ./...
clean:
@echo Cleaning $(PACKAGE_NAME) ...
@$(RM_CMD_1) $(TARGET) $(RM_CMD_2)
@$(RM_CMD_1) coverage.out $(RM_CMD_2)
@$(RM_CMD_1) "*.db" $(RM_CMD_2)
@$(RM_CMD_1) "*.exe" $(RM_CMD_2)
@$(RM_CMD_1) "*.out" $(RM_CMD_2)
@$(RM_CMD_1) "*.yaml" $(RM_CMD_2)
.PHONY: all test test-full test-short clean