Files
PixivFE/Makefile
T
perennial d977ae7d62 Improve version and revision info handling
Modify the REVISION variable to include both commit date and hash.
Update config package to parse and store revision components separately.
Modify about page and routes to display more detailed revision information.
2024-09-22 20:57:28 +10:00

57 lines
1.6 KiB
Makefile

# Makefile for PixivFE
# Variables
BINARY_NAME=pixivfe
TARGETOS ?= $(shell go env GOOS)
TARGETARCH ?= $(shell go env GOARCH)
GIT_COMMIT_DATE := $(shell git show -s --format=%cd --date=format:"%Y.%m.%d")
GIT_COMMIT_HASH := $(shell git rev-parse --short HEAD)
REVISION := $(GIT_COMMIT_DATE)-$(GIT_COMMIT_HASH)
# Include environment variables from .env if it exists
-include .env
.PHONY: all fmt build test run clean install-pre-commit help
all: fmt build test
fmt:
@echo "Formatting Go code..."
go fmt ./...
build:
@echo "Building $(BINARY_NAME)..."
go mod download
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -v -ldflags="-extldflags=-static -X codeberg.org/vnpower/pixivfe/v2/config.REVISION=$(REVISION)" -tags netgo -o $(BINARY_NAME)
test:
@echo "Running tests..."
go test ./server/template
run: build
@echo "Running $(BINARY_NAME)..."
./$(BINARY_NAME)
clean:
@echo "Cleaning up..."
rm -f $(BINARY_NAME)
# Additional target to install test script as pre-commit hook
install-pre-commit:
@echo "Installing pre-commit hook..."
echo '#!/bin/sh' > .git/hooks/pre-commit
echo 'go test ./server/template' >> .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
# Help target
help:
@echo "Available targets:"
@echo " all - Run fmt, build, and test"
@echo " fmt - Format Go code"
@echo " build - Build the binary"
@echo " test - Run tests"
@echo " run - Build and run the binary"
@echo " clean - Remove the binary"
@echo " install-pre-commit - Install testing pre-commit hook"
@echo " help - Show this help message"