-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
31 lines (24 loc) · 1.04 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
CMD=wsstat
PACKAGE_NAME=github.com/jakobilobi/${CMD}
OS_ARCH_PAIRS=linux/386 linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/386 windows/amd64 windows/arm64
VERSION := $(shell cat VERSION)
LDFLAGS=-ldflags "-X main.version=${VERSION}"
build:
go build ${LDFLAGS} -o bin/${CMD} $(PACKAGE_NAME)
build-all: TARGETS=$(OS_ARCH_PAIRS)
build-all: build-multi
build-multi:
$(foreach PAIR,$(TARGETS), $(MAKE) --no-print-directory build-os-arch OS_ARCH=$(PAIR);)
build-os-arch:
@GOOS=$(firstword $(subst /, ,$(OS_ARCH))) \
GOARCH=$(lastword $(subst /, ,$(OS_ARCH))) \
go build ${LDFLAGS} -o 'bin/$(CMD)-$(firstword $(subst /, ,$(OS_ARCH)))-$(lastword $(subst /, ,$(OS_ARCH)))' $(PACKAGE_NAME)
explain:
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@echo " build - Build the binary for the host OS/Arch."
@echo " build-all - Build binaries for all target OS/Arch pairs."
@echo " explain - Display this help message."
.PHONY: build build-all build-snapcraft build-multi build-os-arch explain
.DEFAULT_GOAL := explain