Alexey Kim 6 months ago
parent
commit
edc5d93390
2 changed files with 45 additions and 0 deletions
  1. 1 0
      .gitignore
  2. 44 0
      Makefile

+ 1 - 0
.gitignore

@@ -1,2 +1,3 @@
 .idea
 .env
+strategy/*.so

+ 44 - 0
Makefile

@@ -0,0 +1,44 @@
+.DEFAULT_GOAL := all
+.DELETE_ON_ERROR:
+.SUFFIXES:
+
+include .env
+export
+
+PROJECT := $(shell cat go.mod | grep '^module\s' | cut -b 8-)
+export VERSION ?= $(shell date -u '+%F')-snapshot
+export DEBUG ?= 0
+
+BUILD_TIME := $(shell date -u '+%F_%T')
+COMMIT_HASH := $(shell git rev-parse --short HEAD)
+LDFLAGS := '-linkmode external -w -s -extldflags "-static" -X $(PROJECT).Version=$(VERSION)'
+GCFLAGS :=
+
+ifeq ($(DEBUG),1)
+	GCFLAGS = "all=-N -l"
+endif
+
+.PHONY: all
+all: gen deps fmt test
+
+.PHONY: gen
+gen:
+	-@echo "-> $@"
+	-@echo "=== Generate strategies"
+	$(foreach file, $(wildcard ./strategy/*.go), CGO_ENABLED=1 go build -ldflags=$(LDFLAGS) -buildmode=plugin -gcflags=$(GCFLAGS) -o $(file).so $(file);)
+
+.PHONY: deps
+deps:
+	-@echo "-> $@"
+	go mod tidy
+
+.PHONY: fmt
+fmt:
+	-@echo "-> $@"
+	-go fmt $(shell go list ./...)
+
+.PHONY: test
+test:
+	-@echo "-> $@"
+	CGO_ENABLED=1 go test $(shell go list ./...)
+	-go vet $(shell go list ./...)