2024-01-11 14:17:13 +00:00
|
|
|
# The targets cannot be run in parallel
|
|
|
|
.NOTPARALLEL:
|
|
|
|
|
2021-11-16 10:37:59 +00:00
|
|
|
VERSION := $(shell git describe --tags --always --match "[0-9][0-9][0-9][0-9].*.*")
|
2020-07-07 15:44:07 +00:00
|
|
|
MSI_VERSION := $(shell git tag -l --sort=v:refname | grep "w" | tail -1 | cut -c2-)
|
2020-09-22 21:56:23 +00:00
|
|
|
#MSI_VERSION expects the format of the tag to be: (wX.X.X). Starts with the w character to not break cfsetup.
|
2020-07-07 15:44:07 +00:00
|
|
|
#e.g. w3.0.1 or w4.2.10. It trims off the w character when creating the MSI.
|
2018-07-24 19:55:18 +00:00
|
|
|
|
2022-01-03 18:39:08 +00:00
|
|
|
ifeq ($(ORIGINAL_NAME), true)
|
|
|
|
# Used for builds that want FIPS compilation but want the artifacts generated to still have the original name.
|
|
|
|
BINARY_NAME := cloudflared
|
|
|
|
else ifeq ($(FIPS), true)
|
|
|
|
# Used for FIPS compliant builds that do not match the case above.
|
2021-11-09 11:37:51 +00:00
|
|
|
BINARY_NAME := cloudflared-fips
|
|
|
|
else
|
2022-01-03 18:39:08 +00:00
|
|
|
# Used for all other (non-FIPS) builds.
|
2021-11-09 11:37:51 +00:00
|
|
|
BINARY_NAME := cloudflared
|
2021-12-16 00:26:05 +00:00
|
|
|
endif
|
|
|
|
|
2021-07-14 19:45:29 +00:00
|
|
|
ifeq ($(NIGHTLY), true)
|
2022-01-03 18:39:08 +00:00
|
|
|
DEB_PACKAGE_NAME := $(BINARY_NAME)-nightly
|
2021-07-14 19:45:29 +00:00
|
|
|
NIGHTLY_FLAGS := --conflicts cloudflared --replaces cloudflared
|
|
|
|
else
|
2021-11-09 11:37:51 +00:00
|
|
|
DEB_PACKAGE_NAME := $(BINARY_NAME)
|
2021-07-14 19:45:29 +00:00
|
|
|
endif
|
|
|
|
|
2021-01-28 16:10:19 +00:00
|
|
|
DATE := $(shell date -u '+%Y-%m-%d-%H%M UTC')
|
2021-11-09 11:37:51 +00:00
|
|
|
VERSION_FLAGS := -X "main.Version=$(VERSION)" -X "main.BuildTime=$(DATE)"
|
2022-03-08 00:05:48 +00:00
|
|
|
ifdef PACKAGE_MANAGER
|
|
|
|
VERSION_FLAGS := $(VERSION_FLAGS) -X "github.com/cloudflare/cloudflared/cmd/cloudflared/updater.BuiltForPackageManager=$(PACKAGE_MANAGER)"
|
|
|
|
endif
|
2021-11-09 11:37:51 +00:00
|
|
|
|
|
|
|
LINK_FLAGS :=
|
|
|
|
ifeq ($(FIPS), true)
|
|
|
|
LINK_FLAGS := -linkmode=external -extldflags=-static $(LINK_FLAGS)
|
|
|
|
# Prevent linking with libc regardless of CGO enabled or not.
|
|
|
|
GO_BUILD_TAGS := $(GO_BUILD_TAGS) osusergo netgo fips
|
2021-12-27 19:05:14 +00:00
|
|
|
VERSION_FLAGS := $(VERSION_FLAGS) -X "main.BuildType=FIPS"
|
2021-11-09 11:37:51 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
LDFLAGS := -ldflags='$(VERSION_FLAGS) $(LINK_FLAGS)'
|
|
|
|
ifneq ($(GO_BUILD_TAGS),)
|
|
|
|
GO_BUILD_TAGS := -tags "$(GO_BUILD_TAGS)"
|
|
|
|
endif
|
2021-01-28 16:10:19 +00:00
|
|
|
|
2022-05-26 17:52:39 +00:00
|
|
|
ifeq ($(debug), 1)
|
|
|
|
GO_BUILD_TAGS += -gcflags="all=-N -l"
|
|
|
|
endif
|
|
|
|
|
2022-03-08 00:05:48 +00:00
|
|
|
IMPORT_PATH := github.com/cloudflare/cloudflared
|
|
|
|
PACKAGE_DIR := $(CURDIR)/packaging
|
2024-01-10 11:43:55 +00:00
|
|
|
PREFIX := /usr
|
2022-03-08 00:05:48 +00:00
|
|
|
INSTALL_BINDIR := $(PREFIX)/bin/
|
|
|
|
INSTALL_MANDIR := $(PREFIX)/share/man/man1/
|
2024-01-11 10:26:36 +00:00
|
|
|
CF_GO_PATH := /tmp/go
|
|
|
|
PATH := $(CF_GO_PATH)/bin:$(PATH)
|
2018-07-25 21:05:46 +00:00
|
|
|
|
2020-05-29 01:06:27 +00:00
|
|
|
LOCAL_ARCH ?= $(shell uname -m)
|
2020-06-30 19:46:05 +00:00
|
|
|
ifneq ($(GOARCH),)
|
|
|
|
TARGET_ARCH ?= $(GOARCH)
|
|
|
|
else ifeq ($(LOCAL_ARCH),x86_64)
|
2020-05-29 01:06:27 +00:00
|
|
|
TARGET_ARCH ?= amd64
|
2021-03-01 17:43:08 +00:00
|
|
|
else ifeq ($(LOCAL_ARCH),amd64)
|
|
|
|
TARGET_ARCH ?= amd64
|
2020-07-07 15:44:07 +00:00
|
|
|
else ifeq ($(LOCAL_ARCH),i686)
|
|
|
|
TARGET_ARCH ?= amd64
|
2020-05-29 01:06:27 +00:00
|
|
|
else ifeq ($(shell echo $(LOCAL_ARCH) | head -c 5),armv8)
|
|
|
|
TARGET_ARCH ?= arm64
|
|
|
|
else ifeq ($(LOCAL_ARCH),aarch64)
|
|
|
|
TARGET_ARCH ?= arm64
|
2021-08-10 02:24:34 +00:00
|
|
|
else ifeq ($(LOCAL_ARCH),arm64)
|
|
|
|
TARGET_ARCH ?= arm64
|
2020-05-29 01:06:27 +00:00
|
|
|
else ifeq ($(shell echo $(LOCAL_ARCH) | head -c 4),armv)
|
|
|
|
TARGET_ARCH ?= arm
|
2022-04-06 09:43:58 +00:00
|
|
|
else ifeq ($(LOCAL_ARCH),s390x)
|
|
|
|
TARGET_ARCH ?= s390x
|
2020-05-29 01:06:27 +00:00
|
|
|
else
|
|
|
|
$(error This system's architecture $(LOCAL_ARCH) isn't supported)
|
|
|
|
endif
|
|
|
|
|
|
|
|
LOCAL_OS ?= $(shell go env GOOS)
|
|
|
|
ifeq ($(LOCAL_OS),linux)
|
|
|
|
TARGET_OS ?= linux
|
|
|
|
else ifeq ($(LOCAL_OS),darwin)
|
|
|
|
TARGET_OS ?= darwin
|
2020-06-09 19:15:12 +00:00
|
|
|
else ifeq ($(LOCAL_OS),windows)
|
|
|
|
TARGET_OS ?= windows
|
2020-09-22 21:56:23 +00:00
|
|
|
else ifeq ($(LOCAL_OS),freebsd)
|
|
|
|
TARGET_OS ?= freebsd
|
2023-04-04 15:14:51 +00:00
|
|
|
else ifeq ($(LOCAL_OS),openbsd)
|
|
|
|
TARGET_OS ?= openbsd
|
2020-05-29 01:06:27 +00:00
|
|
|
else
|
|
|
|
$(error This system's OS $(LOCAL_OS) isn't supported)
|
2018-10-19 19:01:08 +00:00
|
|
|
endif
|
|
|
|
|
2020-06-23 21:23:40 +00:00
|
|
|
ifeq ($(TARGET_OS), windows)
|
2021-11-09 11:37:51 +00:00
|
|
|
EXECUTABLE_PATH=./$(BINARY_NAME).exe
|
2020-06-23 21:23:40 +00:00
|
|
|
else
|
2021-11-09 11:37:51 +00:00
|
|
|
EXECUTABLE_PATH=./$(BINARY_NAME)
|
2020-06-23 21:23:40 +00:00
|
|
|
endif
|
|
|
|
|
2020-07-06 19:44:39 +00:00
|
|
|
ifeq ($(FLAVOR), centos-7)
|
|
|
|
TARGET_PUBLIC_REPO ?= el7
|
|
|
|
else
|
|
|
|
TARGET_PUBLIC_REPO ?= $(FLAVOR)
|
|
|
|
endif
|
|
|
|
|
2022-06-20 11:05:03 +00:00
|
|
|
ifneq ($(TARGET_ARM), )
|
|
|
|
ARM_COMMAND := GOARM=$(TARGET_ARM)
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(TARGET_ARM), 7)
|
|
|
|
PACKAGE_ARCH := armhf
|
|
|
|
else
|
|
|
|
PACKAGE_ARCH := $(TARGET_ARCH)
|
|
|
|
endif
|
|
|
|
|
2023-01-10 10:37:45 +00:00
|
|
|
#for FIPS compliance, FPM defaults to MD5.
|
|
|
|
RPM_DIGEST := --rpm-digest sha256
|
|
|
|
|
2018-07-24 19:55:18 +00:00
|
|
|
.PHONY: all
|
|
|
|
all: cloudflared test
|
|
|
|
|
2018-10-18 22:26:21 +00:00
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
|
|
|
go clean
|
|
|
|
|
2018-07-24 19:55:18 +00:00
|
|
|
.PHONY: cloudflared
|
2021-11-09 11:37:51 +00:00
|
|
|
cloudflared:
|
2021-03-02 15:43:35 +00:00
|
|
|
ifeq ($(FIPS), true)
|
|
|
|
$(info Building cloudflared with go-fips)
|
2021-11-09 11:37:51 +00:00
|
|
|
cp -f fips/fips.go.linux-amd64 cmd/cloudflared/fips.go
|
2021-03-02 15:43:35 +00:00
|
|
|
endif
|
2023-12-11 11:58:19 +00:00
|
|
|
GOOS=$(TARGET_OS) GOARCH=$(TARGET_ARCH) $(ARM_COMMAND) go build -mod=vendor $(GO_BUILD_TAGS) $(LDFLAGS) $(IMPORT_PATH)/cmd/cloudflared
|
2021-03-02 15:43:35 +00:00
|
|
|
ifeq ($(FIPS), true)
|
2021-11-09 11:37:51 +00:00
|
|
|
rm -f cmd/cloudflared/fips.go
|
|
|
|
./check-fips.sh cloudflared
|
2021-03-02 15:43:35 +00:00
|
|
|
endif
|
|
|
|
|
2019-04-29 21:25:34 +00:00
|
|
|
.PHONY: container
|
|
|
|
container:
|
2020-05-29 01:06:27 +00:00
|
|
|
docker build --build-arg=TARGET_ARCH=$(TARGET_ARCH) --build-arg=TARGET_OS=$(TARGET_OS) -t cloudflare/cloudflared-$(TARGET_OS)-$(TARGET_ARCH):"$(VERSION)" .
|
2019-04-29 21:25:34 +00:00
|
|
|
|
2022-10-04 13:14:17 +00:00
|
|
|
.PHONY: generate-docker-version
|
|
|
|
generate-docker-version:
|
|
|
|
echo latest $(VERSION) > versions
|
|
|
|
|
2023-05-31 13:59:05 +00:00
|
|
|
|
2018-07-24 19:55:18 +00:00
|
|
|
.PHONY: test
|
2019-03-29 23:05:11 +00:00
|
|
|
test: vet
|
2021-02-08 21:31:51 +00:00
|
|
|
ifndef CI
|
2021-11-09 11:37:51 +00:00
|
|
|
go test -v -mod=vendor -race $(LDFLAGS) ./...
|
2021-02-08 21:31:51 +00:00
|
|
|
else
|
|
|
|
@mkdir -p .cover
|
2021-11-09 11:37:51 +00:00
|
|
|
go test -v -mod=vendor -race $(LDFLAGS) -coverprofile=".cover/c.out" ./...
|
2021-02-08 21:31:51 +00:00
|
|
|
endif
|
2018-07-25 21:05:46 +00:00
|
|
|
|
2023-05-31 13:59:05 +00:00
|
|
|
.PHONY: cover
|
|
|
|
cover:
|
|
|
|
@echo ""
|
|
|
|
@echo "=====> Total test coverage: <====="
|
|
|
|
@echo ""
|
|
|
|
# Print the overall coverage here for quick access.
|
|
|
|
$Q go tool cover -func ".cover/c.out" | grep "total:" | awk '{print $$3}'
|
|
|
|
# Generate the HTML report that can be viewed from the browser in CI.
|
|
|
|
$Q go tool cover -html ".cover/c.out" -o .cover/all.html
|
|
|
|
|
2024-01-09 17:47:26 +00:00
|
|
|
.PHONY: install-go
|
|
|
|
install-go:
|
2024-01-11 10:26:36 +00:00
|
|
|
rm -rf ${CF_GO_PATH}
|
2024-01-09 17:47:26 +00:00
|
|
|
./.teamcity/install-cloudflare-go.sh
|
|
|
|
|
|
|
|
.PHONY: cleanup-go
|
|
|
|
cleanup-go:
|
2024-01-11 10:26:36 +00:00
|
|
|
rm -rf ${CF_GO_PATH}
|
2024-01-09 17:47:26 +00:00
|
|
|
|
2022-03-08 00:05:48 +00:00
|
|
|
cloudflared.1: cloudflared_man_template
|
2022-07-18 06:36:57 +00:00
|
|
|
sed -e 's/\$${VERSION}/$(VERSION)/; s/\$${DATE}/$(DATE)/' cloudflared_man_template > cloudflared.1
|
2022-03-08 00:05:48 +00:00
|
|
|
|
2024-01-09 17:47:26 +00:00
|
|
|
install: install-go cloudflared cloudflared.1 cleanup-go
|
2022-03-08 00:05:48 +00:00
|
|
|
mkdir -p $(DESTDIR)$(INSTALL_BINDIR) $(DESTDIR)$(INSTALL_MANDIR)
|
|
|
|
install -m755 cloudflared $(DESTDIR)$(INSTALL_BINDIR)/cloudflared
|
|
|
|
install -m644 cloudflared.1 $(DESTDIR)$(INSTALL_MANDIR)/cloudflared.1
|
|
|
|
|
2021-11-09 11:37:51 +00:00
|
|
|
# When we build packages, the package name will be FIPS-aware.
|
|
|
|
# But we keep the binary installed by it to be named "cloudflared" regardless.
|
2020-07-02 18:23:54 +00:00
|
|
|
define build_package
|
2018-07-25 21:05:46 +00:00
|
|
|
mkdir -p $(PACKAGE_DIR)
|
|
|
|
cp cloudflared $(PACKAGE_DIR)/cloudflared
|
2022-03-08 00:05:48 +00:00
|
|
|
cp cloudflared.1 $(PACKAGE_DIR)/cloudflared.1
|
2023-01-10 10:37:45 +00:00
|
|
|
fpm -C $(PACKAGE_DIR) -s dir -t $(1) \
|
2021-09-28 07:39:40 +00:00
|
|
|
--description 'Cloudflare Tunnel daemon' \
|
2020-07-08 14:36:42 +00:00
|
|
|
--vendor 'Cloudflare' \
|
2022-03-08 14:59:53 +00:00
|
|
|
--license 'Apache License Version 2.0' \
|
2020-07-08 14:36:42 +00:00
|
|
|
--url 'https://github.com/cloudflare/cloudflared' \
|
|
|
|
-m 'Cloudflare <support@cloudflare.com>' \
|
2023-01-10 10:37:45 +00:00
|
|
|
-a $(PACKAGE_ARCH) -v $(VERSION) -n $(DEB_PACKAGE_NAME) $(RPM_DIGEST) $(NIGHTLY_FLAGS) --after-install postinst.sh --after-remove postrm.sh \
|
2022-03-08 00:05:48 +00:00
|
|
|
cloudflared=$(INSTALL_BINDIR) cloudflared.1=$(INSTALL_MANDIR)
|
2020-07-02 18:23:54 +00:00
|
|
|
endef
|
|
|
|
|
|
|
|
.PHONY: cloudflared-deb
|
2022-03-08 00:05:48 +00:00
|
|
|
cloudflared-deb: cloudflared cloudflared.1
|
2020-07-02 18:23:54 +00:00
|
|
|
$(call build_package,deb)
|
2018-07-26 20:45:18 +00:00
|
|
|
|
2020-06-30 15:43:54 +00:00
|
|
|
.PHONY: cloudflared-rpm
|
2022-03-08 00:05:48 +00:00
|
|
|
cloudflared-rpm: cloudflared cloudflared.1
|
2020-07-02 18:23:54 +00:00
|
|
|
$(call build_package,rpm)
|
2020-06-30 15:43:54 +00:00
|
|
|
|
2021-07-22 15:36:49 +00:00
|
|
|
.PHONY: cloudflared-pkg
|
2022-03-08 00:05:48 +00:00
|
|
|
cloudflared-pkg: cloudflared cloudflared.1
|
2021-07-22 15:36:49 +00:00
|
|
|
$(call build_package,osxpkg)
|
|
|
|
|
|
|
|
.PHONY: cloudflared-msi
|
2022-09-15 21:26:02 +00:00
|
|
|
cloudflared-msi:
|
2021-07-22 15:36:49 +00:00
|
|
|
wixl --define Version=$(VERSION) --define Path=$(EXECUTABLE_PATH) --output cloudflared-$(VERSION)-$(TARGET_ARCH).msi cloudflared.wxs
|
|
|
|
|
2024-08-01 15:26:45 +00:00
|
|
|
.PHONY: github-release-dryrun
|
|
|
|
github-release-dryrun:
|
|
|
|
python3 github_release.py --path $(PWD)/built_artifacts --release-version $(VERSION) --dry-run
|
|
|
|
|
2020-06-23 21:23:40 +00:00
|
|
|
.PHONY: github-release
|
2024-07-05 18:39:22 +00:00
|
|
|
github-release:
|
2021-07-26 12:49:17 +00:00
|
|
|
python3 github_release.py --path $(PWD)/built_artifacts --release-version $(VERSION)
|
2020-07-29 17:50:25 +00:00
|
|
|
python3 github_message.py --release-version $(VERSION)
|
|
|
|
|
2024-07-05 18:39:22 +00:00
|
|
|
.PHONY: r2-linux-release
|
|
|
|
r2-linux-release:
|
|
|
|
python3 ./release_pkgs.py
|
2022-09-15 21:26:02 +00:00
|
|
|
|
2024-05-14 04:22:06 +00:00
|
|
|
.PHONY: capnp
|
|
|
|
capnp:
|
2019-03-29 23:05:11 +00:00
|
|
|
which capnp # https://capnproto.org/install.html
|
2022-09-07 22:06:06 +00:00
|
|
|
which capnpc-go # go install zombiezen.com/go/capnproto2/capnpc-go@latest
|
2024-05-14 04:22:06 +00:00
|
|
|
capnp compile -ogo tunnelrpc/proto/tunnelrpc.capnp tunnelrpc/proto/quic_metadata_protocol.capnp
|
2021-07-08 09:29:49 +00:00
|
|
|
|
2019-03-29 23:05:11 +00:00
|
|
|
.PHONY: vet
|
|
|
|
vet:
|
2023-12-11 11:58:19 +00:00
|
|
|
go vet -mod=vendor github.com/cloudflare/cloudflared/...
|
2020-07-07 15:44:07 +00:00
|
|
|
|
2022-11-04 23:39:42 +00:00
|
|
|
.PHONY: fmt
|
|
|
|
fmt:
|
2024-05-14 04:22:06 +00:00
|
|
|
goimports -l -w -local github.com/cloudflare/cloudflared $$(go list -mod=vendor -f '{{.Dir}}' -a ./... | fgrep -v tunnelrpc/proto)
|