-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
70 lines (58 loc) · 1.92 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
#-------------------------------------------------------------------------------
#
# Makefile for building target binaries.
#
# Configuration
BUILD_ROOT = $(abspath ./)
BIN_DIR = ./bin
DST_DIR = /usr/local/bin
UNAME = $(shell uname)
GOBUILD = go build
GOTEST = go test
GOTOOL = go tool
GOMOD = go mod
GOBUILD_TAGS =
GOBUILD_ENVS = CGO_ENABLED=0 GO111MODULE=on
GOBUILD_LDFLAGS = -ldflags ""
GOBUILD_FLAGS = -mod= $(GOBUILD_TAGS) $(GOBUILD_LDFLAGS)
# Build flags
GL_VERSION ?= $(shell git describe --always --tags --dirty)
GL_TAG ?= latest
BUILD_INFO = tags($(GOBUILD_TAGS))-$(shell date '+%Y-%m-%d-%H:%M:%S')
# Build flags for each command
LDFLAGS = -ldflags "-X 'main.version=$(GL_VERSION)' -X 'main.build=$(BUILD_INFO)'"
BUILD_NAME = "rosetta-icon"
.DEFAULT_GOAL := all
all : clean build ## Build the tools for current OS
.PHONY: build linux darwin help
build :
$(eval GOBUILD_LDFLAGS=$(LDFLAGS))
@ echo "[#] go build main.go as $(BIN_DIR)/$(BUILD_NAME)"
$(GOBUILD_ENVS) $(GOBUILD) $(GOBUILD_FLAGS) -o $(BIN_DIR)/$(BUILD_NAME)
linux : ## Build the tools for linux
@ echo "[#] build for $@"
@ make GOBUILD_ENVS="$(GOBUILD_ENVS) GOOS=$@ GOARCH=amd64"
darwin : ## Build the tools for OS X
@ echo "[#] build for $@"
@ make GOBUILD_ENVS="$(GOBUILD_ENVS) GOOS=$@ GOARCH=amd64"
modules : ## Update modules in vendor/
$(GOMOD) tidy
$(GOMOD) vendor
clean : ## Remove generated files
@$(RM) -r $(BIN_DIR)
TARGET_MAX_CHAR_NUM=20
help : ## This help message
@echo ''
@echo 'Usage:'
@echo ' make <target>'
@echo ''
@echo 'Targets:'
@IFS=$$'\n' ; \
help_lines=(`fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//'`); \
for help_line in $${help_lines[@]}; do \
IFS=$$'#' ; \
help_split=($$help_line) ; \
help_command=`echo $${help_split[0]} | sed -e 's/:.*//' -e 's/^ *//' -e 's/ *$$//'` ; \
help_info=`echo $${help_split[2]} | sed -e 's/^ *//' -e 's/ *$$//'` ; \
printf " %-20s %s %s\n" $$help_command $$help_info; \
done