forked from imgproxy/imgproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
116 lines (97 loc) · 2.42 KB
/
Makefile
File metadata and controls
116 lines (97 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# 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) -v -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
# Upgrade direct Go dependencies
.PHONY: upgrade
upgrade:
@$(GOCMD) mod tidy
@$(GOCMD) get $$($(GOCMD) list -f '{{if not (or .Main .Indirect)}}{{.Path}}{{end}}' -m all)
@$(GOCMD) mod tidy
# Make any unknown target do nothing to avoid "up to date" messages
.PHONY: FORCE
%: FORCE
@: