-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
55 lines (44 loc) · 1.33 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
# Project directory structure
MODULE_NAME := $(shell go list -m)
PROJECT_PATH := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
PROJECT_NAME := $(shell basename $(PROJECT_PATH))
export PATH := ${PATH}:${GOPATH}/bin
# Artifacts
TARGET_DIR ?= ${PROJECT_PATH}/target
TARGET_BIN_DIR ?= ${TARGET_DIR}/bin
# Application environment
STAGE ?= development
VERSION := $(shell git describe --exact-match --tags HEAD 2>/dev/null || git rev-parse --abbrev-ref HEAD)
# Go environment
GOVERSION := $(shell go version | awk '{print $$3}')
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
LDFLAGS := -ldflags="-X ${MODULE_NAME}/tool.buildVersion=${VERSION}"
.PHONY: env init build run dev clean
env:
@echo "PROJECT_PATH:\t${PROJECT_PATH}"
@echo "PROJECT_NAME:\t${PROJECT_NAME}"
@echo "MODULE_NAME:\t${MODULE_NAME}"
@echo "GOVERSION:\t${GOVERSION}"
@echo "GOOS:\t\t${GOOS}"
@echo "GOARCH:\t\t${GOARCH}"
@echo "STAGE:\t\t${STAGE}"
@echo "VERSION:\t${VERSION}"
init:
go mod tidy
build-wam:
@echo "Building WAMs..."
cd ${PROJECT_PATH}/wam; \
yarn install; \
yarn build
build: init build-wam
GOOS=${GOOS} \
GOARCH=${GOARCH} \
go build ${LDFLAGS} \
-o ${TARGET_BIN_DIR}/${PROJECT_NAME}.${GOOS}.${GOARCH} \
${PROJECT_PATH}/cmd
run:
${TARGET_BIN_DIR}/${PROJECT_NAME}.${GOOS}.${GOARCH}
dev: build run
clean:
rm -rf ${TARGET_DIR}