2024-09-30 21:53:53 +00:00
|
|
|
# ==============================================================================
|
|
|
|
|
|
|
|
COMMON_SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
|
|
|
|
ROOT_DIR := $(abspath $(shell cd $(COMMON_SELF_DIR)/ && pwd -P))
|
|
|
|
OUTPUT_DIR := $(ROOT_DIR)/_output
|
|
|
|
|
2024-10-02 20:21:09 +00:00
|
|
|
# ==============================================================================
|
|
|
|
# Version
|
|
|
|
|
|
|
|
VERSION_PACKAGE=git.vinchent.xyz/vinchent/howmuch/pkg/version
|
|
|
|
|
|
|
|
ifeq ($(origin VERSION), undefined)
|
|
|
|
VERSION:=$(shell git describe --tags --always --match='v*')
|
|
|
|
endif
|
|
|
|
|
|
|
|
GIT_TREE_STATE="dirty"
|
|
|
|
ifeq (, $(shell git status --porcelain 2>/dev/null))
|
|
|
|
GIT_TREE_STATE ="clean"
|
|
|
|
endif
|
|
|
|
|
|
|
|
GIT_COMMIT:=$(shell git rev-parse HEAD)
|
|
|
|
|
|
|
|
GO_LDFLAGS += \
|
|
|
|
-X $(VERSION_PACKAGE).GitVersion=$(VERSION) \
|
|
|
|
-X $(VERSION_PACKAGE).GitCommit=$(GIT_COMMIT) \
|
|
|
|
-X $(VERSION_PACKAGE).GitTreeState=$(GIT_TREE_STATE) \
|
|
|
|
-X $(VERSION_PACKAGE).BuildDate=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
|
|
|
|
|
2024-09-30 21:53:53 +00:00
|
|
|
# ==============================================================================
|
|
|
|
.PHONY: all
|
|
|
|
all: add-copyright format build
|
2024-10-08 21:22:00 +00:00
|
|
|
web: web-all
|
2024-09-30 21:53:53 +00:00
|
|
|
# ==============================================================================
|
|
|
|
|
|
|
|
.PHONY: build
|
2024-10-06 11:18:21 +00:00
|
|
|
build: tidy sqlc # build.
|
2024-10-02 20:48:27 +00:00
|
|
|
@go build -v -ldflags "$(GO_LDFLAGS)" -o $(OUTPUT_DIR)/howmuch $(ROOT_DIR)/cmd/howmuch/main.go 2>/dev/null
|
2024-09-30 21:53:53 +00:00
|
|
|
|
2024-10-06 11:18:21 +00:00
|
|
|
.PHONY: sqlc
|
2024-10-12 16:31:18 +00:00
|
|
|
sqlc:
|
2024-10-06 11:18:21 +00:00
|
|
|
@sqlc generate
|
|
|
|
|
2024-09-30 21:53:53 +00:00
|
|
|
.PHONY: format
|
|
|
|
format: # format code.
|
|
|
|
@gofmt -s -w ./
|
|
|
|
|
|
|
|
.PHONY: add-copyright
|
|
|
|
add-copyright: # add license to file headers.
|
2024-10-08 21:22:00 +00:00
|
|
|
@addlicense -v -f $(ROOT_DIR)/LICENSE $(ROOT_DIR) --skip-files=database.yml --skip-dirs=$(OUTPUT_DIR),deployment,migrations,configs,sqlc,web
|
2024-10-02 20:48:27 +00:00
|
|
|
|
2024-09-30 21:53:53 +00:00
|
|
|
.PHONY: swagger
|
|
|
|
swagger: # Run swagger.
|
|
|
|
@swagger serve -F=swagger --no-open --port 65534 $(ROOT_DIR)/api/openapi/openapi.yaml
|
|
|
|
|
|
|
|
.PHONY: tidy
|
|
|
|
tidy: # Handle packkages.
|
|
|
|
@go mod tidy
|
|
|
|
|
2024-10-08 21:22:00 +00:00
|
|
|
.PHONY: test
|
|
|
|
test:
|
|
|
|
@go test ./...
|
|
|
|
|
2024-09-30 21:53:53 +00:00
|
|
|
.PHONY: clean
|
|
|
|
clean: # Clean up.
|
|
|
|
@-rm -vrf $(OUTPUT_DIR)
|
2024-10-08 21:22:00 +00:00
|
|
|
|
|
|
|
.PHONY: web-build
|
|
|
|
web-build:
|
|
|
|
$(MAKE) -C web build
|
|
|
|
|
|
|
|
.PHONY: web-test
|
|
|
|
web-test:
|
|
|
|
$(MAKE) -C web test
|
|
|
|
|
|
|
|
.PHONY: web-all
|
|
|
|
web-all:
|
|
|
|
$(MAKE) -C web all
|