2020-04-25 22:22:45 +00:00
|
|
|
VERSION = $(shell git describe --dirty --tags --always)
|
2020-04-01 02:08:21 +00:00
|
|
|
DIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
|
2020-05-03 08:18:28 +00:00
|
|
|
SERVER_BUILD_PATH = github.com/baez90/inetmock/cmd/inetmock
|
|
|
|
CLI_BUILD_PATH = github.com/baez90/inetmock/cmd/imctl
|
2020-04-01 02:08:21 +00:00
|
|
|
PKGS = $(shell go list ./...)
|
2020-04-27 22:26:15 +00:00
|
|
|
TEST_PKGS = $(shell go list ./...)
|
|
|
|
PROTO_FILES = $(shell find $(DIR)api/ -type f -name "*.proto")
|
2020-04-01 02:08:21 +00:00
|
|
|
GOARGS = GOOS=linux GOARCH=amd64
|
2020-05-03 08:18:28 +00:00
|
|
|
GO_BUILD_ARGS = -ldflags='-w -s'
|
|
|
|
GO_CONTAINER_BUILD_ARGS = -ldflags='-w -s' -a -installsuffix cgo
|
2020-04-01 02:08:21 +00:00
|
|
|
GO_DEBUG_BUILD_ARGS = -gcflags "all=-N -l"
|
2020-05-03 08:18:28 +00:00
|
|
|
SERVER_BINARY_NAME = inetmock
|
|
|
|
CLI_BINARY_NAME = imctl
|
2020-04-01 02:08:21 +00:00
|
|
|
DEBUG_PORT = 2345
|
|
|
|
DEBUG_ARGS?= --development-logs=true
|
2020-04-25 22:22:45 +00:00
|
|
|
CONTAINER_BUILDER ?= podman
|
|
|
|
DOCKER_IMAGE ?= inetmock
|
2020-04-01 02:08:21 +00:00
|
|
|
|
2020-06-15 10:04:08 +00:00
|
|
|
.PHONY: clean all format deps update-deps compile compile-server compile-cli debug generate protoc snapshot-release test cli-cover-report html-cover-report $(GO_GEN_FILES)
|
|
|
|
all: clean format generate compile test
|
2020-04-01 02:08:21 +00:00
|
|
|
|
|
|
|
clean:
|
|
|
|
@find $(DIR) -type f \( -name "*.out" -or -name "*.so" \) -exec rm -f {} \;
|
2020-04-11 13:31:08 +00:00
|
|
|
@rm -rf $(DIR)*.so
|
2020-05-06 22:45:37 +00:00
|
|
|
@find $(DIR) -type f -name "*.pb.go" -exec rm -f {} \;
|
|
|
|
@find $(DIR) -type f -name "*.mock.go" -exec rm -f {} \;
|
2020-05-03 08:18:28 +00:00
|
|
|
@rm -f $(DIR)$(SERVER_BINARY_NAME) $(DIR)$(CLI_BINARY_NAME) $(DIR)main
|
2020-04-01 02:08:21 +00:00
|
|
|
|
|
|
|
format:
|
|
|
|
@go fmt $(PKGS)
|
|
|
|
|
|
|
|
deps:
|
2020-05-03 08:18:28 +00:00
|
|
|
@go build -v $(SERVER_BUILD_PATH)
|
2020-04-12 01:51:41 +00:00
|
|
|
|
|
|
|
update-deps:
|
2020-04-01 02:08:21 +00:00
|
|
|
@go mod tidy
|
2020-05-06 22:45:37 +00:00
|
|
|
@go get -u $(DIR)/...
|
2020-04-01 02:08:21 +00:00
|
|
|
|
2020-05-03 08:18:28 +00:00
|
|
|
compile-server: deps
|
2020-04-01 02:08:21 +00:00
|
|
|
ifdef DEBUG
|
|
|
|
@echo 'Compiling for debugging...'
|
2020-05-03 08:18:28 +00:00
|
|
|
@$(GOARGS) go build $(GO_DEBUG_BUILD_ARGS) -o $(DIR)$(SERVER_BINARY_NAME) $(SERVER_BUILD_PATH)
|
2020-04-01 02:08:21 +00:00
|
|
|
else ifdef CONTAINER
|
|
|
|
@echo 'Compiling for container usage...'
|
2020-05-03 08:18:28 +00:00
|
|
|
@$(GOARGS) go build $(GO_CONTAINER_BUILD_ARGS) -o $(DIR)$(SERVER_BINARY_NAME) $(SERVER_BUILD_PATH)
|
2020-04-01 02:08:21 +00:00
|
|
|
else
|
|
|
|
@echo 'Compiling for normal Linux env...'
|
2020-05-03 08:18:28 +00:00
|
|
|
@$(GOARGS) go build $(GO_BUILD_ARGS) -o $(DIR)$(SERVER_BINARY_NAME) $(SERVER_BUILD_PATH)
|
2020-04-01 02:08:21 +00:00
|
|
|
endif
|
|
|
|
|
2020-05-03 08:18:28 +00:00
|
|
|
compile-cli: deps
|
|
|
|
@$(GOARGS) go build $(GO_BUILD_ARGS) -o $(CLI_BINARY_NAME) $(CLI_BUILD_PATH)
|
|
|
|
|
|
|
|
compile: compile-server compile-cli
|
|
|
|
|
2020-04-01 02:08:21 +00:00
|
|
|
debug:
|
2020-04-25 22:22:45 +00:00
|
|
|
dlv debug $(DIR) \
|
2020-04-01 02:08:21 +00:00
|
|
|
--headless \
|
|
|
|
--listen=:2345 \
|
|
|
|
--api-version=2 \
|
|
|
|
-- $(DEBUG_ARGS)
|
2020-04-11 11:26:42 +00:00
|
|
|
|
2020-04-13 22:14:56 +00:00
|
|
|
generate:
|
2020-04-25 22:22:45 +00:00
|
|
|
@go generate ./...
|
2020-05-03 08:11:19 +00:00
|
|
|
@protoc --proto_path $(DIR)api/ --go_out=plugins=grpc:internal/rpc --go_opt=paths=source_relative $(shell find $(DIR)api/ -type f -name "*.proto")
|
2020-04-27 22:26:15 +00:00
|
|
|
|
2020-04-11 11:26:42 +00:00
|
|
|
snapshot-release:
|
|
|
|
@goreleaser release --snapshot --skip-publish --rm-dist
|
|
|
|
|
2020-04-25 22:22:45 +00:00
|
|
|
container:
|
|
|
|
@$(CONTAINER_BUILDER) build -t $(DOCKER_IMAGE):latest -f $(DIR)Dockerfile $(DIR)
|
|
|
|
|
2020-04-01 02:08:21 +00:00
|
|
|
test:
|
|
|
|
@go test -coverprofile=./cov-raw.out -v $(TEST_PKGS)
|
|
|
|
@cat ./cov-raw.out | grep -v "generated" > ./cov.out
|
|
|
|
|
2020-04-25 22:22:45 +00:00
|
|
|
cli-cover-report: test
|
2020-04-01 02:08:21 +00:00
|
|
|
@go tool cover -func=cov.out
|
|
|
|
|
2020-04-13 22:14:56 +00:00
|
|
|
html-cover-report: test
|
2020-04-01 02:08:21 +00:00
|
|
|
@go tool cover -html=cov.out -o .coverage.html
|