forked from Clement-Jean/grpc-go-course
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
88 lines (74 loc) · 3.36 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
BIN_DIR = bin
PROTO_DIR = proto
SERVER_DIR = server
CLIENT_DIR = client
ifeq ($(OS), Windows_NT)
SHELL := powershell.exe
.SHELLFLAGS := -NoProfile -Command
SHELL_VERSION = $(shell (Get-Host | Select-Object Version | Format-Table -HideTableHeaders | Out-String).Trim())
OS = $(shell "{0} {1}" -f "windows", (Get-ComputerInfo -Property OsVersion, OsArchitecture | Format-Table -HideTableHeaders | Out-String).Trim())
PACKAGE = $(shell (Get-Content go.mod -head 1).Split(" ")[1])
CHECK_DIR_CMD = if (!(Test-Path $@)) { $$e = [char]27; Write-Error "$$e[31mDirectory $@ doesn't exist$${e}[0m" }
HELP_CMD = Select-String "^[a-zA-Z_-]+:.*?\#\# .*$$" "./Makefile" | Foreach-Object { $$_data = $$_.matches -split ":.*?\#\# "; $$obj = New-Object PSCustomObject; Add-Member -InputObject $$obj -NotePropertyName ('Command') -NotePropertyValue $$_data[0]; Add-Member -InputObject $$obj -NotePropertyName ('Description') -NotePropertyValue $$_data[1]; $$obj } | Format-Table -HideTableHeaders @{Expression={ $$e = [char]27; "$$e[36m$$($$_.Command)$${e}[0m" }}, Description
RM_F_CMD = Remove-Item -erroraction silentlycontinue -Force
RM_RF_CMD = ${RM_F_CMD} -Recurse
SERVER_BIN = ${SERVER_DIR}.exe
CLIENT_BIN = ${CLIENT_DIR}.exe
else
SHELL := bash
SHELL_VERSION = $(shell echo $$BASH_VERSION)
UNAME := $(shell uname -s)
VERSION_AND_ARCH = $(shell uname -rm)
ifeq ($(UNAME),Darwin)
OS = macos ${VERSION_AND_ARCH}
else ifeq ($(UNAME),Linux)
OS = linux ${VERSION_AND_ARCH}
else
$(error OS not supported by this Makefile)
endif
PACKAGE = $(shell head -1 go.mod | awk '{print $$2}')
CHECK_DIR_CMD = test -d $@ || (echo "\033[31mDirectory $@ doesn't exist\033[0m" && false)
HELP_CMD = grep -E '^[a-zA-Z_-]+:.*?\#\# .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?\#\# "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
RM_F_CMD = rm -f
RM_RF_CMD = ${RM_F_CMD} -r
SERVER_BIN = ${SERVER_DIR}
CLIENT_BIN = ${CLIENT_DIR}
endif
.DEFAULT_GOAL := help
.PHONY: greet blog calculator help
project := greet calculator blog
all: $(project) ## Generate Pbs and build
greet: $@ ## Generate Pbs and build for greet
calculator: $@ ## Generate Pbs and build for calculator
blog: $@ ## Generate Pbs and build for blog
$(project):
@${CHECK_DIR_CMD}
protoc -I$@/${PROTO_DIR} --go_opt=module=${PACKAGE} --go_out=. --go-grpc_opt=module=${PACKAGE} --go-grpc_out=. $@/${PROTO_DIR}/*.proto
go build -o ${BIN_DIR}/$@/${SERVER_BIN} ./$@/${SERVER_DIR}
go build -o ${BIN_DIR}/$@/${CLIENT_BIN} ./$@/${CLIENT_DIR}
test: all ## Launch tests
go test ./...
clean: clean_greet clean_calculator clean_blog ## Clean generated files
${RM_F_CMD} ssl/*.crt
${RM_F_CMD} ssl/*.csr
${RM_F_CMD} ssl/*.key
${RM_F_CMD} ssl/*.pem
${RM_RF_CMD} ${BIN_DIR}
clean_greet: ## Clean generated files for greet
${RM_F_CMD} greet/${PROTO_DIR}/*.pb.go
clean_calculator: ## Clean generated files for calculator
${RM_F_CMD} calculator/${PROTO_DIR}/*.pb.go
clean_blog: ## Clean generated files for blog
${RM_F_CMD} blog/${PROTO_DIR}/*.pb.go
rebuild: clean all ## Rebuild the whole project
bump: all ## Update packages version
go get -u ./...
about: ## Display info related to the build
@echo "OS: ${OS}"
@echo "Shell: ${SHELL} ${SHELL_VERSION}"
@echo "Protoc version: $(shell protoc --version)"
@echo "Go version: $(shell go version)"
@echo "Go package: ${PACKAGE}"
@echo "Openssl version: $(shell openssl version)"
help: ## Show this help
@${HELP_CMD}