--- cli/Makefile	2023-09-29 13:08:09.000000000 -0700
+++ debian/Makefile	2023-09-22 14:40:16.000000000 -0700
@@ -1,120 +1,130 @@
-SHELL := /bin/bash
-GORELEASER_VERSION := v1.17.2
+SHELL=/bin/bash
 
-# Compile natively based on the current system
-.PHONY: build 
-build:
-ifneq "" "$(findstring NT,$(shell uname))" # windows
-	CC=gcc CXX=g++ $(MAKE) cli-builder
-else ifneq (,$(findstring Linux,$(shell uname)))
-    ifneq (,$(findstring musl,$(shell ldd --version))) # linux (musl)
-		CC=gcc CXX=g++ TAGS=musl $(MAKE) cli-builder
-    else # linux (glibc)
-		CC=gcc CXX=g++ $(MAKE) cli-builder
-    endif
-else # darwin
-	$(MAKE) cli-builder
-endif
-
-# Cross-compile from darwin to any of the OS/Arch pairs below
-.PHONY: cross-build
-cross-build:
-ifeq ($(GOARCH),arm64)
-    ifeq ($(GOOS),linux) # linux/arm64
-		CGO_ENABLED=1 CC=aarch64-linux-musl-gcc CXX=aarch64-linux-musl-g++ CGO_LDFLAGS="-static" TAGS=musl $(MAKE) cli-builder
-    else # darwin/arm64
-		CGO_ENABLED=1 $(MAKE) cli-builder
-    endif
+ifndef VERSION
+	VERSION=$(CLI_VERSION)
+endif
+
+export PACKAGE_TITLE=cli
+export FULL_PACKAGE_TITLE=confluent-$(PACKAGE_TITLE)
+export PACKAGE_NAME=$(FULL_PACKAGE_TITLE)-$(VERSION)
+
+# Defaults that are likely to vary by platform. These are cleanly separated so
+# it should be easy to maintain altered values on platform-specific branches
+# when the values aren't overridden by the script invoking the Makefile
+
+APPLY_PATCHES?=yes
+
+# DESTDIR may be overridden by e.g. debian packaging
+ifeq ($(DESTDIR),)
+DESTDIR=$(CURDIR)/BUILD/
+endif
+
+ifeq ($(PACKAGE_TYPE),archive)
+PREFIX=$(PACKAGE_NAME)
+SYSCONFDIR=$(PREFIX)/etc/$(PACKAGE_TITLE)
 else
-    ifeq ($(GOOS),windows) # windows/amd64
-		CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ CGO_LDFLAGS="-static" $(MAKE) cli-builder
-    else ifeq ($(GOOS),linux) # linux/amd64
-		CGO_ENABLED=1 CC=x86_64-linux-musl-gcc CXX=x86_64-linux-musl-g++ CGO_LDFLAGS="-static" TAGS=musl $(MAKE) cli-builder
-    else # darwin/amd64
-		CGO_ENABLED=1 $(MAKE) cli-builder
-    endif
-endif
-
-.PHONY: cli-builder
-cli-builder:
-	GOOS="" GOARCH="" go install github.com/goreleaser/goreleaser@$(GORELEASER_VERSION) && \
-	TAGS=$(TAGS) CGO_ENABLED=$(CGO_ENABLED) CC=$(CC) CXX=$(CXX) CGO_LDFLAGS=$(CGO_LDFLAGS) GOEXPERIMENT=boringcrypto goreleaser build --config .goreleaser-build.yml --clean --single-target --snapshot
-
-include ./mk-files/semver.mk
-include ./mk-files/docs.mk
-include ./mk-files/dry-run.mk
-include ./mk-files/release.mk
-include ./mk-files/release-test.mk
-include ./mk-files/release-notes.mk
-include ./mk-files/unrelease.mk
-include ./mk-files/utils.mk
-
-REF := $(shell [ -d .git ] && git rev-parse --short HEAD || echo "none")
-DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
-
-S3_BUCKET_PATH=s3://confluent.cloud
-S3_STAG_FOLDER_NAME=cli-release-stag
-S3_STAG_PATH=s3://confluent.cloud/$(S3_STAG_FOLDER_NAME)
+PREFIX=/usr
+SYSCONFDIR=/etc/$(PACKAGE_TITLE)
+endif
 
-.PHONY: clean
-clean:
-	for dir in bin dist docs legal prebuilt release-notes; do \
-		[ -d $$dir ] && rm -r $$dir || true; \
+all: install
+
+archive: install
+	rm -f $(CURDIR)/$(PACKAGE_NAME).tar.gz && cd $(DESTDIR) && tar -czf $(CURDIR)/$(PACKAGE_NAME).tar.gz $(PREFIX)
+	rm -f $(CURDIR)/$(PACKAGE_NAME).zip && cd $(DESTDIR) && zip -r $(CURDIR)/$(PACKAGE_NAME).zip $(PREFIX)
+
+apply-patches: $(wildcard debian/patches/*)
+ifeq ($(APPLY_PATCHES),yes)
+	git reset --hard HEAD
+	cat debian/patches/series | xargs -iPATCH bash -c 'patch -p1 < debian/patches/PATCH'
+endif
+
+BINPATH=$(PREFIX)/bin
+LIBPATH=$(PREFIX)/libexec/$(PACKAGE_TITLE)
+DOCPATH=$(PREFIX)/share/doc/$(PACKAGE_TITLE)
+
+install: apply-patches
+	rm -rf $(DESTDIR)$(PREFIX)
+	mkdir -p $(DESTDIR)$(PREFIX)
+
+	mkdir -p $(DESTDIR)$(BINPATH)
+	mkdir -p $(DESTDIR)$(LIBPATH)
+	mkdir -p $(DESTDIR)$(DOCPATH)
+	mkdir -p $(DESTDIR)$(SYSCONFDIR)
+
+	cp packaging/confluent.sh $(DESTDIR)$(BINPATH)/confluent
+	chmod 755 $(DESTDIR)$(BINPATH)/confluent
+
+	cd $(DESTDIR)$(LIBPATH); \
+	for dir in darwin_amd64 darwin_arm64 linux_amd64 windows_amd64; do \
+		mkdir -p $${dir}; \
+		ext=""; if [[ $${dir} =~ windows_.+ ]]; then ext=".exe"; fi; \
+		filepath=$${dir}/confluent$${ext}; \
+		curl -f -s https://s3-us-west-2.amazonaws.com/confluent.cloud/confluent-cli/binaries/$(CLI_VERSION)/confluent_$(CLI_VERSION)_$${dir}$${ext} -o $${filepath}; \
+		chmod 755 $${filepath}; \
 	done
 
-.PHONY: lint
-lint: lint-go lint-cli
+	cp LICENSE $(DESTDIR)$(DOCPATH)/COPYRIGHT
+	$(DESTDIR)$(BINPATH)/confluent --version | awk -F' ' '{ print $3 }' > $(DESTDIR)$(DOCPATH)/version.txt
 
-.PHONY: lint-go
-lint-go:
-	go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.1 && \
-	golangci-lint run --timeout 10m
-	@echo "✅  golangci-lint"
-
-.PHONY: lint-cli
-lint-cli: cmd/lint/en_US.aff cmd/lint/en_US.dic
-	go run cmd/lint/main.go -aff-file $(word 1,$^) -dic-file $(word 2,$^) $(ARGS)
-	@echo "✅  cmd/lint/main.go"
-
-cmd/lint/en_US.aff:
-	curl -s "https://chromium.googlesource.com/chromium/deps/hunspell_dictionaries/+/master/en_US.aff?format=TEXT" | base64 -D > $@
-
-cmd/lint/en_US.dic:
-	curl -s "https://chromium.googlesource.com/chromium/deps/hunspell_dictionaries/+/master/en_US.dic?format=TEXT" | base64 -D > $@
-
-.PHONY: unit-test
-unit-test:
-ifdef CI
-	go install gotest.tools/gotestsum@v1.8.2 && \
-	gotestsum --junitfile unit-test-report.xml -- -timeout 0 -v -race -coverprofile coverage.out $$(go list ./... | grep -v github.com/confluentinc/cli/v3/test)
-else
-	go test -timeout 0 -v $$(go list ./... | grep -v github.com/confluentinc/cli/v3/test) $(UNIT_TEST_ARGS)
-endif
+	chown -R root:root $(DESTDIR)$(PREFIX)
 
-.PHONY: build-for-integration-test
-build-for-integration-test:
-ifdef CI
-	go build -cover -ldflags="-s -w -X main.commit=$(REF) -X main.date=$(DATE) -X main.version=$(VERSION) -X main.isTest=true" -o test/bin/confluent ./cmd/confluent
-else
-	go build -ldflags="-s -w -X main.commit=$(REF) -X main.date=$(DATE) -X main.version=$(VERSION) -X main.isTest=true" -o test/bin/confluent ./cmd/confluent
+clean:
+	rm -rf $(CURDIR)/$(PACKAGE_NAME)*
+	rm -rf $(FULL_PACKAGE_TITLE)-$(RPM_VERSION)*rpm
+	rm -rf RPM_BUILDING
+
+distclean: clean
+ifneq ($(PACKAGE_TYPE),deb)
+	git reset --hard HEAD
+	git status --ignored --porcelain | cut -d ' ' -f 2 | xargs rm -rf
 endif
 
-.PHONY: integration-test
-integration-test:
-ifdef CI
-	go install gotest.tools/gotestsum@v1.8.2 && \
-	export GOCOVERDIR=test/coverage && \
-	if [ -d $${GOCOVERDIR} ]; then rm -r $${GOCOVERDIR}; fi && \
-	mkdir $${GOCOVERDIR} && \
-	gotestsum --junitfile integration-test-report.xml -- -timeout 0 -v -race $$(go list ./... | grep github.com/confluentinc/cli/v3/test) && \
-	go tool covdata textfmt -i $${GOCOVERDIR} -o test/coverage.out
+RPM_VERSION=$(shell echo $(VERSION) | sed -e 's/-alpha[0-9]*//' -e 's/-beta[0-9]*//' -e 's/-rc[0-9]*//' -e 's/-SNAPSHOT//' -e 's/-cp[0-9]*//' -e 's/-hotfix[0-9]*//' -e 's/-[0-9]*//')
+
+# Get any -alpha, -beta (preview), -rc (release candidate), -SNAPSHOT (nightly), -cp (confluent patch), -hotfix piece that we need to put into the Release part of
+# the version since RPM versions don't support non-numeric
+# characters. Ultimately, for something like 0.8.2-beta, we want to end up with
+# Version=0.8.2 Release=0.X.beta
+# where X is the RPM release # of 0.8.2-beta (the prefix 0. forces this to be
+# considered earlier than any 0.8.2 final releases since those will start with
+# Version=0.8.2 Release=1)
+RPM_RELEASE_POSTFIX=$(subst -,,$(subst $(RPM_VERSION),,$(VERSION)))
+ifneq ($(RPM_RELEASE_POSTFIX),)
+	RPM_RELEASE_POSTFIX_UNDERSCORE=_$(RPM_RELEASE_POSTFIX)
+	RPM_RELEASE_ID=0.$(REVISION).$(RPM_RELEASE_POSTFIX)
 else
-	go test -timeout 0 -v $$(go list ./... | grep github.com/confluentinc/cli/v3/test) $(INTEGRATION_TEST_ARGS)
+	RPM_RELEASE_ID=$(REVISION)
 endif
 
-.PHONY: test
-test: unit-test integration-test
+rpm: RPM_BUILDING/SOURCES/$(FULL_PACKAGE_TITLE)-$(RPM_VERSION).tar.gz
+	echo "Building the RPM"
+	rpmbuild --define="_topdir `pwd`/RPM_BUILDING" --nodebuginfo -tb $< || rpmbuild --define="_topdir `pwd`/RPM_BUILDING" -tb $<
+	find RPM_BUILDING/{,S}RPMS/ -type f | xargs -n1 -iXXX mv XXX .
+	echo
+	echo "================================================="
+	echo "The RPMs have been created and can be found here:"
+	@ls -laF $(FULL_PACKAGE_TITLE)*rpm
+	echo "================================================="
+
+# Unfortunately, because of version naming issues and the way rpmbuild expects
+# the paths in the tar file to be named, we need to rearchive the package. So
+# instead of depending on archive, this target just uses the unarchived,
+# installed version to generate a new archive. Note that we always regenerate
+# the symlink because the RPM_VERSION doesn't include all the version info -- it
+# can leave of things like -beta, -rc1, etc.
+RPM_BUILDING/SOURCES/$(FULL_PACKAGE_TITLE)-$(RPM_VERSION).tar.gz: rpm-build-area install debian/$(FULL_PACKAGE_TITLE).spec.in RELEASE_$(RPM_VERSION)$(RPM_RELEASE_POSTFIX_UNDERSCORE)
+	rm -rf $(FULL_PACKAGE_TITLE)-$(RPM_VERSION)
+	mkdir $(FULL_PACKAGE_TITLE)-$(RPM_VERSION)
+	cp -R $(DESTDIR)/* $(FULL_PACKAGE_TITLE)-$(RPM_VERSION)
+	sed "s/##RPMVERSION##/$(RPM_VERSION)/g; s/##RPMRELEASE##/$(RPM_RELEASE_ID)/g" < debian/$(FULL_PACKAGE_TITLE).spec.in > $(FULL_PACKAGE_TITLE)-$(RPM_VERSION)/$(FULL_PACKAGE_TITLE).spec
+	rm -f $@ && tar -czf $@ $(FULL_PACKAGE_TITLE)-$(RPM_VERSION)
+	rm -rf $(FULL_PACKAGE_TITLE)-$(RPM_VERSION)
+
+rpm-build-area: RPM_BUILDING/BUILD RPM_BUILDING/RPMS RPM_BUILDING/SOURCES RPM_BUILDING/SPECS RPM_BUILDING/SRPMS
+
+RPM_BUILDING/%:
+	mkdir -p $@
 
-.PHONY: generate-packaging-patch
-generate-packaging-patch:
-	diff -u Makefile debian/Makefile | sed "1 s_Makefile_cli/Makefile_" > debian/patches/standard_build_layout.patch
+RELEASE_%:
+	echo 0 > $@
