This repository has been archived by the owner on Apr 21, 2021. It is now read-only.
forked from ghostunnel/ghostunnel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.dist
64 lines (55 loc) · 2.55 KB
/
Makefile.dist
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
# Metadata about this makefile and position
MKFILE_PATH := $(lastword $(MAKEFILE_LIST))
CURRENT_DIR := $(patsubst %/,%,$(dir $(realpath $(MKFILE_PATH))))
GO_VERSION ?= 1.13.1
XGO_BASE_IMAGE ?= cssx/xgo-${GO_VERSION}
# Current system information
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
# Default os-arch combination to build
XC_OS ?= darwin linux windows
XC_ARCH ?= 386 amd64 arm64
XC_EXCLUDE ?= darwin/386 linux/386 darwin/arm64 windows/arm64
# External linkers for Windows (to get a static exe)
WINDOWS_EXTLD_amd64 = x86_64-w64-mingw32-gcc
WINDOWS_EXTLD_386 = i686-w64-mingw32-gcc
WINDOWS_API_LEVEL = 5.1
PROJECT := $(CURRENT_DIR:$(GOPATH)/src/%=%)
NAME := $(notdir $(PROJECT))
GIT_COMMIT ?= $(shell git rev-parse --short HEAD)
VERSION ?= $(shell git describe --always)
LD_FLAGS := -X main.version=${VERSION}
# Create a cross-compile target for every os-arch pairing. This will generate
# a make target for each os/arch like "make linux/amd64" as well as generate a
# meta target (build) for compiling everything.
define make-xc-target
$1/$2:
ifneq (,$(findstring ${1}/${2},$(XC_EXCLUDE)))
@printf "%s%20s %s\n" "-->" "${1}/${2}:" "${PROJECT} (excluded)"
else ifeq (${1},windows)
@printf "%s%20s %s\n" "-->" "${1}/${2}:" "${PROJECT} (-w -extldflags "-static" -extld ${WINDOWS_EXTLD_${2}})"
@xgo -go ${GO_VERSION} -image ${XGO_BASE_IMAGE} -targets '${1}-${WINDOWS_API_LEVEL}/${2}' \
-ldflags '${LD_FLAGS} -w -extldflags "-static" -extld ${WINDOWS_EXTLD_${2}}' .
@mv ghostunnel-${1}-${WINDOWS_API_LEVEL}-${2}.exe dist/ghostunnel-${VERSION}-${1}-${2}-with-pkcs11.exe
@sha256sum dist/ghostunnel-${VERSION}-${1}-${2}-with-pkcs11.exe > dist/ghostunnel-${VERSION}-${1}-${2}-with-pkcs11.exe.sha256sum
else
@printf "%s%20s %s\n" "-->" "${1}/${2}:" "${PROJECT}"
@xgo -go ${GO_VERSION} -image ${XGO_BASE_IMAGE} -ldflags "${LD_FLAGS}" -targets '${1}/${2}' .
@mv ghostunnel-${1}*-${2} dist/ghostunnel-${VERSION}-${1}-${2}-with-pkcs11
@sha256sum dist/ghostunnel-${VERSION}-${1}-${2}-with-pkcs11 > dist/ghostunnel-${VERSION}-${1}-${2}-with-pkcs11.sha256sum
endif
.PHONY: $1/$2
$1:: $1/$2
.PHONY: $1
build:: $1/$2
.PHONY: build
endef
$(foreach goarch,$(XC_ARCH),$(foreach goos,$(XC_OS),$(eval $(call make-xc-target,$(goos),$(goarch),$(if $(findstring windows,$(goos)),.exe,)))))
# dist builds the binaries for distribution
dist:
@rm -rf "${CURRENT_DIR}/dist/"
@mkdir -p "${CURRENT_DIR}/dist/"
@$(MAKE) -f Makefile ghostunnel.man
@mv ghostunnel.man "${CURRENT_DIR}/dist/ghostunnel-${VERSION}.man"
@$(MAKE) -f "${MKFILE_PATH}" -j1 build
.PHONY: dist