Skip to content

Commit

Permalink
feat(packaging): add deb packaging to makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
farzadghanei committed Jun 15, 2024
1 parent d598098 commit 701fb83
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,20 @@ PKG_DIST_DIR ?= $(abspath $(makefile_dir)/..)
PKG_TGZ_NAME = chkok-$(CHKOK_VERSION)-$(OS)-$(ARCH).tar.gz
PKG_TGZ_PATH = $(PKG_DIST_DIR)/$(PKG_TGZ_NAME)
PKG_CHECKSUM_NAME = chkok-$(CHKOK_VERSION)-SHA256SUMS
# PBUILDER_COMPONENTS ?= "main universe"
# PBUILDER_RC ?= $(makefile_dir)build/package/pbuilderrc
# PBUILDER_HOOKS_DIR ?= $(makefile_dir)build/package/pbuilder-hooks

PBUILDER_COMPONENTS ?= "main universe"
PBUILDER_RC ?= $(makefile_dir)build/package/pbuilderrc
PBUILDER_HOOKS_DIR ?= $(makefile_dir)build/package/pbuilder-hooks

RPM_DEV_TREE ?= $(HOME)/rpmbuild

# find Debian package version from the changelog file. latest version
# should be at the top, first matching 'chkok (0.1.0-1) ...' and sed clears chars not in version
# CHKOK_DEB_VERSION := $(shell grep --only-matching --max-count 1 --perl-regexp "^\s*chkok\s+\(.+\)\s*" build/package/debian/changelog | sed 's/[^0-9.-]//g')
# CHKOK_DEB_UPSTREAM_VERSION := $(shell echo $(CHKOK_DEB_VERSION) | grep --only-matching --perl-regexp '^[0-9.]+')
# CHKOK_DEB_UPSTREAM_TARBAL_PATH := $(abspath $(makefile_dir)/..)
# CHKOK_DEB_UPSTREAM_TARBAL := $(CHKOK_DEB_UPSTREAM_TARBAL_PATH)/chkok_$(CHKOK_DEB_UPSTREAM_VERSION).orig.tar.gz
# DEB_BUILD_GIT_BRANCH := pkg-deb-$(CHKOK_DEB_VERSION)-$(TIMESTAMP_MINUTE)
CHKOK_DEB_VERSION := $(shell grep --only-matching --max-count 1 --perl-regexp "^\s*chkok\s+\(.+\)\s*" build/package/debian/changelog | sed 's/[^0-9.-]//g')
CHKOK_DEB_UPSTREAM_VERSION := $(shell echo $(CHKOK_DEB_VERSION) | grep --only-matching --perl-regexp '^[0-9.]+')
CHKOK_DEB_UPSTREAM_TARBAL_PATH := $(abspath $(makefile_dir)/..)
CHKOK_DEB_UPSTREAM_TARBAL := $(CHKOK_DEB_UPSTREAM_TARBAL_PATH)/chkok_$(CHKOK_DEB_UPSTREAM_VERSION).orig.tar.gz
DEB_BUILD_GIT_BRANCH := pkg-deb-$(CHKOK_DEB_VERSION)-$(TIMESTAMP_MINUTE)

# find rpm version from the spec file. latest version
# should be in the top tags, first matching 'Version: 0.1.0' and sed clears chars not in version
Expand All @@ -74,7 +76,7 @@ RPM_DEV_SRC_TGZ = $(RPM_DEV_TREE)/SOURCES/chkok-$(CHKOK_RPM_VERSION).tar.gz
RPM_DEV_SPEC = $(RPM_DEV_TREE)/SPECS/chkok-$(CHKOK_RPM_VERSION).spec

# command aliases
# cowbuilder = env DISTRIBUTION=$(DIST) ARCH=$(ARCH) BASEPATH=/var/cache/pbuilder/base-$(DIST)-$(ARCH).cow cowbuilder
cowbuilder = env DISTRIBUTION=$(DIST) ARCH=$(ARCH) BASEPATH=/var/cache/pbuilder/base-$(DIST)-$(ARCH).cow cowbuilder


chkok:
Expand Down Expand Up @@ -109,27 +111,27 @@ distclean: clean
# override prefix so .deb package installs binaries to /usr/bin instead of /usr/local/bin
# pkg-deb: export prefix = /usr
# requires a cowbuilder environment. see pkg-deb-setup
# pkg-deb:
# git checkout -b $(DEB_BUILD_GIT_BRANCH)
# rm -f $(CHKOK_DEB_UPSTREAM_TARBAL); tar --exclude-backups --exclude-vcs -zcf $(CHKOK_DEB_UPSTREAM_TARBAL) .
# cp -r build/package/debian debian; git add debian; git commit -m 'add debian dir for packaging v$(CHKOK_DEB_VERSION)'
# gbp buildpackage --git-ignore-new --git-verbose --git-pbuilder \
# --git-no-create-orig --git-tarball-dir=$(CHKOK_DEB_UPSTREAM_TARBAL_PATH) \
# --git-hooks \
# --git-dist=$(DIST) --git-arch=$(ARCH) \
# --git-ignore-new --git-ignore-branch \
# --git-pbuilder-options='--configfile=$(PBUILDER_RC) --hookdir=$(PBUILDER_HOOKS_DIR) --buildresult=$(PKG_DIST_DIR)' \
# -b -us -uc -sa
# git checkout $(GIT_CURRENT_BRANCH)
# git branch -D $(DEB_BUILD_GIT_BRANCH)
pkg-deb:
git checkout -b $(DEB_BUILD_GIT_BRANCH)
rm -f $(CHKOK_DEB_UPSTREAM_TARBAL); tar --exclude-backups --exclude-vcs -zcf $(CHKOK_DEB_UPSTREAM_TARBAL) .
cp -r build/package/debian debian; git add debian; git commit -m 'add debian dir for packaging v$(CHKOK_DEB_VERSION)'
gbp buildpackage --git-ignore-new --git-verbose --git-pbuilder \
--git-no-create-orig --git-tarball-dir=$(CHKOK_DEB_UPSTREAM_TARBAL_PATH) \
--git-hooks \
--git-dist=$(DIST) --git-arch=$(ARCH) \
--git-ignore-new --git-ignore-branch \
--git-pbuilder-options='--configfile=$(PBUILDER_RC) --hookdir=$(PBUILDER_HOOKS_DIR) --buildresult=$(PKG_DIST_DIR)' \
-b -us -uc -sa
git checkout $(GIT_CURRENT_BRANCH)
git branch -D $(DEB_BUILD_GIT_BRANCH)

# required:
# sudo apt-get install build-essential debhelper pbuilder fakeroot cowbuilder git-buildpackage devscripts ubuntu-dev-tools
# pkg-deb-setup:
# echo "creating a git-pbuilder environment with apt repositories to install new go versions ..."
# DIST=$(DIST) ARCH=$(ARCH) git-pbuilder create --components=$(PBUILDER_COMPONENTS) \
# --extrapackages="cowdancer curl wget" --configfile=$(PBUILDER_RC) \
# --hookdir=$(PBUILDER_HOOKS_DIR)
pkg-deb-setup:
echo "creating a git-pbuilder environment with apt repositories to install new go versions ..."
DIST=$(DIST) ARCH=$(ARCH) git-pbuilder create --components=$(PBUILDER_COMPONENTS) \
--extrapackages="cowdancer curl wget" --configfile=$(PBUILDER_RC) \
--hookdir=$(PBUILDER_HOOKS_DIR)

pkg-tgz: build
tar --create --gzip --exclude-vcs --exclude=docs/man/*.rst --file $(PKG_TGZ_PATH) chkok \
Expand Down

0 comments on commit 701fb83

Please sign in to comment.