From e5d528d60a2126ad4c77c5d80ecb27a9c0458694 Mon Sep 17 00:00:00 2001 From: DarthSim Date: Wed, 10 Sep 2025 17:28:38 +0300 Subject: [PATCH] Add Makefile --- .gitignore | 1 + Makefile | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 Makefile diff --git a/.gitignore b/.gitignore index 5cfa542b..ce723208 100644 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,6 @@ tmp/ docker-base docs/sitemap.txt .env +.imgproxyrc .devcontainer/* k6/*.json diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..30c0006a --- /dev/null +++ b/Makefile @@ -0,0 +1,109 @@ +# imgproxy Makefile + +BINARY := ./imgproxy + +GOCMD := go +GOBUILD := $(GOCMD) build +GOCLEAN := $(GOCMD) clean +GOTEST := $(GOCMD) test +GOFMT := gofmt +GOLINT := golangci-lint +GOTESTSUM := gotestsum +SRCDIR := . +RCFILE := ./.imgproxyrc +BREW_PREFIX := + +# Common environment setup for CGO builds +ifneq ($(shell which brew),) + BREW_PREFIX := $(shell brew --prefix) +endif + +# Export CGO environment variables +export CGO_LDFLAGS_ALLOW := -s|-w + +# Library paths for Homebrew-installed libraries on macOS +ifdef BREW_PREFIX + export PKG_CONFIG_PATH := $(PKG_CONFIG_PATH):$(shell brew --prefix libffi)/lib/pkgconfig + export PKG_CONFIG_PATH := $(PKG_CONFIG_PATH):$(shell brew --prefix libarchive)/lib/pkgconfig + export PKG_CONFIG_PATH := $(PKG_CONFIG_PATH):$(shell brew --prefix cfitsio)/lib/pkgconfig + + export CGO_LDFLAGS := $(CGO_LDFLAGS) -Wl,-no_warn_duplicate_libraries +endif + +# Get build arguments +ifeq (build,$(firstword $(MAKECMDGOALS))) + BUILD_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) +endif + +# Get run arguments +ifeq (run,$(firstword $(MAKECMDGOALS))) + RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) +endif +ifeq (build-and-run,$(firstword $(MAKECMDGOALS))) + RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) +endif + +# Default target +.PHONY: all +all: build + +# Build the binary. If -o is not provided, it defaults to $(BINARY). +# +# Usage: +# make build -- -o output_name +.PHONY: build +build: + @$(GOBUILD) -o $(BINARY) $(BUILD_ARGS) $(SRCDIR) + +# Clean +.PHONY: clean +clean: + echo $$PKG_CONFIG_PATH + @$(GOCLEAN) + rm -f $(BINARY) + + +# Run imgproxy binary +# +# Usage: +# make run -- arg1 arg2 +# +# If .imgproxyrc exists, it will be sourced before running the binary. +.PHONY: run +run: SHELL := bash +run: +ifneq (,$(wildcard $(RCFILE))) + @source $(RCFILE) && $(BINARY) $(RUN_ARGS) +else + @$(BINARY) $(RUN_ARGS) +endif + +.PHONY: build-and-run +build-and-run: build run + +# Run tests +# +# Usage: +# make test -- -run FooTest +.PHONY: test +test: +ifneq ($(shell which $(GOTESTSUM)),) + @$(GOTESTSUM) ./... +else + @$(GOTEST) -v ./... +endif + +# Format code +.PHONY: fmt +fmt: + @$(GOFMT) -s -w . + +# Lint code (requires golangci-lint installed) +.PHONY: lint +lint: + @$(GOLINT) run + +# Make any unknown target do nothing to avoid "up to date" messages +.PHONY: FORCE +%: FORCE + @: