Skip to content

Commit

Permalink
build: remove hardcoded package name
Browse files Browse the repository at this point in the history
  • Loading branch information
dekobon committed Dec 22, 2022
1 parent 110d153 commit bb60418
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
13 changes: 7 additions & 6 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ VERSION ?= $(shell $(GREP) -Po '^version\s+=\s+"\K.*?(?=")' $(CURDIR)/
DEFAULT_TARGET ?= $(shell $(RUSTUP) toolchain list | $(GREP) '(default)' | cut -d' ' -f1 | cut -d- -f2-)
SHELL := /bin/bash
OUTPUT_BINARY ?= bunyan
PACKAGE_NAME ?= bunyan-view
CARGO ?= cargo
DOCKER ?= docker
CHECKSUM ?= sha256sum
Expand Down Expand Up @@ -91,19 +92,19 @@ target/release/$(OUTPUT_BINARY):
test: ## Run tests
$Q $(CARGO) test --features dumb_terminal

.ONESHELL: target/man/bunyan.1.gz
target/man/bunyan.1.gz:
.ONESHELL: target/man/$(OUTPUT_BINARY).1.gz
target/man/$(OUTPUT_BINARY).1.gz:
$Q $(info $(M) building distributable manpage)
mkdir -p target/man
cp man/bunyan.1 target/man/bunyan.1
$(SED) -i 's/%%VERSION%%/$(VERSION)/' target/man/bunyan.1
gzip target/man/bunyan.1
cp man/$(OUTPUT_BINARY).1 target/man/$(OUTPUT_BINARY).1
$(SED) -i 's/%%VERSION%%/$(VERSION)/' target/man/$(OUTPUT_BINARY).1
gzip target/man/$(OUTPUT_BINARY).1

target/gz:
$Q mkdir -p target/gz

.PHONY: manpage
manpage: target/man/bunyan.1.gz ## Builds man page
manpage: target/man/$(OUTPUT_BINARY).1.gz ## Builds man page

include $(CURDIR)/build/package.mk
include $(CURDIR)/build/container.mk
18 changes: 9 additions & 9 deletions build/container.mk
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
.PHONY: container-debian-build-image
container-debian-build-image: ## Builds a container image for building on Debian Linux
$Q if [ "$$($(DOCKER) images --quiet --filter=reference=bunyan_view_debian_builder)" = "" ]; then \
$Q if [ "$$($(DOCKER) images --quiet --filter=reference=debian_builder)" = "" ]; then \
echo "$(M) building debian linux docker build image: $(@)"; \
$(DOCKER) build -t bunyan_view_debian_builder -f Containerfile.debian .; \
$(DOCKER) build -t debian_builder -f Containerfile.debian .; \
fi

.PHONY: container-deb-packages
container-deb-packages: container-debian-build-image ## Builds deb packages using a container image
$Q $(DOCKER) run --rm --tty --interactive --volume "$(CURDIR):/project" --workdir /project bunyan_view_debian_builder make deb-packages
$Q $(DOCKER) run --rm --tty --interactive --volume "$(CURDIR):/project" --workdir /project debian_builder make deb-packages
# Reset permissions on the target directory to the current user
if command -v id > /dev/null; then \
$(DOCKER) run --rm --tty --interactive --volume "$(CURDIR):/project" --workdir /project bunyan_view_debian_builder chown --recursive "$(shell id -u):$(shell id -g)" /project/target
$(DOCKER) run --rm --tty --interactive --volume "$(CURDIR):/project" --workdir /project debian_builder chown --recursive "$(shell id -u):$(shell id -g)" /project/target
fi

.PHONY: container-rpm-packages
container-rpm-packages: container-debian-build-image ## Builds a rpm packages using a container image
$Q $(DOCKER) run --rm --tty --interactive --volume "$(CURDIR):/project" --workdir /project bunyan_view_debian_builder make rpm-packages
$Q $(DOCKER) run --rm --tty --interactive --volume "$(CURDIR):/project" --workdir /project debian_builder make rpm-packages
# Reset permissions on the target directory to the current user
if command -v id > /dev/null; then \
$(DOCKER) run --rm --tty --interactive --volume "$(CURDIR):/project" --workdir /project bunyan_view_debian_builder chown --recursive "$(shell id -u):$(shell id -g)" /project/target
$(DOCKER) run --rm --tty --interactive --volume "$(CURDIR):/project" --workdir /project debian_builder chown --recursive "$(shell id -u):$(shell id -g)" /project/target
fi

.PHONY: container-all-packages
container-all-packages: container-debian-build-image ## Builds all packages using a container image
$Q $(DOCKER) run --rm --tty --interactive --volume "$(CURDIR):/project" --workdir /project bunyan_view_debian_builder make all-packages
$Q $(DOCKER) run --rm --tty --interactive --volume "$(CURDIR):/project" --workdir /project debian_builder make all-packages
# Reset permissions on the target directory to the current user
if command -v id > /dev/null; then \
$(DOCKER) run --rm --tty --interactive --volume "$(CURDIR):/project" --workdir /project bunyan_view_debian_builder chown --recursive "$(shell id -u):$(shell id -g)" /project/target
$(DOCKER) run --rm --tty --interactive --volume "$(CURDIR):/project" --workdir /project debian_builder chown --recursive "$(shell id -u):$(shell id -g)" /project/target
fi

.PHONY: container-test
container-test: container-debian-build-image ## Run tests inside container
$Q $(DOCKER) run --rm --tty --interactive --volume "$(CURDIR):/project" --workdir /project bunyan_view_rocky_builder make test
$Q $(DOCKER) run --rm --tty --interactive --volume "$(CURDIR):/project" --workdir /project debian_builder make test
20 changes: 10 additions & 10 deletions build/package.mk
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ checksums: target/dist/SHA256SUMS ## Generates checksums for all packages
######################################################################################################################

to_debian_arch = $(shell echo $(1) | $(SED) -e 's/x86_64/amd64/' -e 's/aarch64/arm64/' -e 's/armv7/armhf/')
DEBIAN_PACKAGE_TARGETS := $(foreach t, $(TARGETS), target/$(t)/debian/bunyan-view_$(VERSION)_$(call to_debian_arch, $(firstword $(subst -, , $(t)))).deb)
DEBIAN_PACKAGE_TARGETS := $(foreach t, $(TARGETS), target/$(t)/debian/$(PACKAGE_NAME)_$(VERSION)_$(call to_debian_arch, $(firstword $(subst -, , $(t)))).deb)

.ONESHELL: $(DEBIAN_PACKAGE_TARGETS)
$(DEBIAN_PACKAGE_TARGETS): $(TARGETS) target/man/bunyan.1.gz target/dist
$(DEBIAN_PACKAGE_TARGETS): $(TARGETS) target/man/$(OUTPUT_BINARY).1.gz target/dist
$Q TARGET="$(word 2, $(subst /, , $(dir $@)))"
# Skip building debs for musl targets
if echo "$(@)" | grep -q 'musl\|apple'; then \
Expand All @@ -53,11 +53,11 @@ deb-packages: install-packaging-deb $(TARGETS) manpage $(DEBIAN_PACKAGE_TARGETS)
### RPM Packages
######################################################################################################################

RPM_PACKAGE_TARGETS := $(foreach t, $(TARGETS), target/$(t)/generate-rpm/bunyan-view_$(VERSION)_$(firstword $(subst -, , $(t))).rpm)
RPM_PACKAGE_TARGETS := $(foreach t, $(TARGETS), target/$(t)/generate-rpm/$(PACKAGE_NAME)_$(VERSION)_$(firstword $(subst -, , $(t))).rpm)

.ONESHELL: $(RPM_PACKAGE_TARGETS)
.NOTPARALLEL: $(RPM_PACKAGE_TARGETS)
$(RPM_PACKAGE_TARGETS): $(TARGETS) target/man/bunyan.1.gz target/dist
$(RPM_PACKAGE_TARGETS): $(TARGETS) target/man/$(OUTPUT_BINARY).1.gz target/dist
$Q TARGET="$(word 2, $(subst /, , $(dir $@)))"
ARCH="$(firstword $(subst -, , $(word 2, $(subst /, , $(dir $@)))))"
# Skip building rpms for musl targets
Expand Down Expand Up @@ -88,24 +88,24 @@ rpm-packages: install-packaging-rpm $(TARGETS) manpage $(RPM_PACKAGE_TARGETS) ##
.ONESHELL: homebrew-packages
homebrew-packages: target/dist/SHA256SUMS
$Q VERSION="$(VERSION)" \
AARCH64_UNKNOWN_LINUX_GNU_SHA256="$$($(GREP) bunyan-view_v$(VERSION)_aarch64-unknown-linux-gnu.tar.gz $(CURDIR)/target/dist/SHA256SUMS | cut -d ' ' -f 1)" \
X86_64_UNKNOWN_LINUX_GNU_SHA256="$$($(GREP) bunyan-view_v$(VERSION)_x86_64-unknown-linux-gnu.tar.gz $(CURDIR)/target/dist/SHA256SUMS | cut -d ' ' -f 1)" \
X86_64_APPLE_DARWIN_SHA256="$$($(GREP) bunyan-view_v$(VERSION)_x86_64-apple-darwin.tar.gz $(CURDIR)/target/dist/SHA256SUMS | cut -d ' ' -f 1)" \
AARCH64_APPLE_DARWIN_SHA256="$$($(GREP) bunyan-view_v$(VERSION)_aarch64-apple-darwin.tar.gz $(CURDIR)/target/dist/SHA256SUMS | cut -d ' ' -f 1)" \
AARCH64_UNKNOWN_LINUX_GNU_SHA256="$$($(GREP) $(PACKAGE_NAME)_v$(VERSION)_aarch64-unknown-linux-gnu.tar.gz $(CURDIR)/target/dist/SHA256SUMS | cut -d ' ' -f 1)" \
X86_64_UNKNOWN_LINUX_GNU_SHA256="$$($(GREP) $(PACKAGE_NAME)_v$(VERSION)_x86_64-unknown-linux-gnu.tar.gz $(CURDIR)/target/dist/SHA256SUMS | cut -d ' ' -f 1)" \
X86_64_APPLE_DARWIN_SHA256="$$($(GREP) $(PACKAGE_NAME)_v$(VERSION)_x86_64-apple-darwin.tar.gz $(CURDIR)/target/dist/SHA256SUMS | cut -d ' ' -f 1)" \
AARCH64_APPLE_DARWIN_SHA256="$$($(GREP) $(PACKAGE_NAME)_v$(VERSION)_aarch64-apple-darwin.tar.gz $(CURDIR)/target/dist/SHA256SUMS | cut -d ' ' -f 1)" \
envsubst < pkg/brew/bunyan-bin.rb.template > $(CURDIR)/pkg/brew/bunyan-bin.rb


######################################################################################################################
### Tarball Packages
######################################################################################################################

GZ_PACKAGE_TARGETS = $(foreach t, $(TARGETS), target/gz/$(t)/bunyan-view_$(VERSION)_$(firstword $(subst -, , $(t))).tar.gz)
GZ_PACKAGE_TARGETS = $(foreach t, $(TARGETS), target/gz/$(t)/$(PACKAGE_NAME)_$(VERSION)_$(firstword $(subst -, , $(t))).tar.gz)

.ONESHELL: $(GZ_PACKAGE_TARGETS)
$(GZ_PACKAGE_TARGETS): $(TARGETS) target/man/bunyan.1.gz target/dist
$Q mkdir -p "$(CURDIR)/target/gz"
TARGET="$(word 3, $(subst /, , $(dir $@)))"
PACKAGE="$(CURDIR)/target/gz/bunyan-view_v$(VERSION)_$${TARGET}.tar.gz"
PACKAGE="$(CURDIR)/target/gz/$(PACKAGE_NAME)_v$(VERSION)_$${TARGET}.tar.gz"
if [ ! -f "$${PACKAGE}}" ]; then
tar -cz -f $${PACKAGE} \
-C $(CURDIR)/target/man bunyan.1.gz \
Expand Down

0 comments on commit bb60418

Please sign in to comment.