-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
69 lines (49 loc) · 2.27 KB
/
Makefile
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
# ch: container-helper
# using makefile template from: https://gist.github.com/cjbarker/5ce66fcca74a1928a155cfb3fea8fac4
# Check for required command tools to build or stop immediately
EXECUTABLES = git go find pwd
K := $(foreach exec,$(EXECUTABLES),\
$(if $(shell which $(exec)),some string,$(error "No $(exec) in PATH")))
ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
BINARY=ch
VERSION=`git tag --points-at HEAD`
BUILD=`git rev-parse HEAD`
PLATFORMS=darwin linux windows
# removing 386 as a target architecture
ARCHITECTURES=amd64 arm64
PACKAGE=github.com/camerondurham/ch/version
# Setup linker flags option for build that interoperate with variable names in src code
LDFLAGS=-ldflags "-X ${PACKAGE}.PkgVersion=${VERSION} -X ${PACKAGE}.GitRevision=${BUILD}"
default: build
all: clean build_all install
build:
go build ${LDFLAGS} -o ${BINARY}
build_all:
$(foreach GOOS, $(PLATFORMS),\
$(foreach GOARCH, $(ARCHITECTURES), $(shell mkdir -p dist/$(BINARY)-$(GOOS)-$(GOARCH); GOOS=$(GOOS) GOARCH=$(GOARCH) go build -v $(LDFLAGS) -o dist/$(BINARY)-$(GOOS)-$(GOARCH))))
test: build
go test ./...
linux:
$(foreach GOARCH, $(ARCHITECTURES), $(shell mkdir -p dist/$(BINARY)-linux-$(GOARCH); GOOS=linux GOARCH=$(GOARCH) go build -v $(LDFLAGS) -o dist/$(BINARY)-linux-$(GOARCH)))
windows:
mkdir -p dist/$(BINARY)-windows-amd64
GOOS=windows GOARCH=amd64 go build -v $(LDFLAGS) -o dist/$(BINARY)-windows-amd64
macos:
$(foreach GOARCH, $(ARCHITECTURES), $(shell mkdir -p dist/$(BINARY)-darwin-$(GOARCH); GOOS=darwin GOARCH=$(GOARCH) go build -v $(LDFLAGS) -o dist/$(BINARY)-darwin-$(GOARCH)))
TO_ZIP_DIRS = $(filter %/, $(wildcard dist/*/)) # Find all directories in static/projects
TO_ZIP_NAMES = $(patsubst %/,%,$(TO_ZIP_DIRS)) # Remove trailing /
ZIP_TARGETS = $(addsuffix .zip,$(TO_ZIP_NAMES)) # Add .zip
debug: build_all
@echo $(TO_ZIP_DIRS)
@echo $(TO_ZIP_NAMES)
@echo $(ZIP_TARGETS)
$(ZIP_TARGETS):
cd $(basename $@)/.. && zip -FSr $(notdir $@) $(notdir $(basename $@))
# edit .github/workflows/release.yml if this name changes
zip_exe: $(ZIP_TARGETS)
install:
go install ${LDFLAGS}
# Remove only what we've created
clean:
find ${ROOT_DIR} -name '${BINARY}[-?][a-zA-Z0-9]*[-?][a-zA-Z0-9]*' | xargs rm -rf
.PHONY: check clean install build_all all zip_exe