Skip to content

Commit

Permalink
chore: add new Makefile targets
Browse files Browse the repository at this point in the history
Add additional Makefile targets:
- vendor: to generate vendor tar file
- packlit-fix-spec-file: to modify the spec file in packit
- paclit-create-archive: to generate the source code tarball in packit
- packit-create-vendor: to generate vendor tar file in packit
  • Loading branch information
mmartinv committed Nov 28, 2024
1 parent dec67c7 commit 829681a
Showing 1 changed file with 57 additions and 20 deletions.
77 changes: 57 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
include /etc/os-release

SRCDIR ?= .
COMMIT = $(shell (cd "$(SRCDIR)" && git rev-parse HEAD))
VENDOR ?= false
VERSION = $(shell (cd "$(SRCDIR)" && git rev-parse HEAD))
PLATFORMS = $(shell (echo {x86_64,aarch64,powerpc64le,s390x}-unknown-linux-gnu))

#
# Generic Targets
Expand All @@ -24,8 +26,27 @@ help:
@echo
@echo " help: Print this usage information."
@echo " rpm: Generate RPM."
@echo " srpm: Generate SRPM."
@echo " vendor: Generate vendor tar file in the current directory."
@echo " man: Generate man pages."


VENDOR_TARBALL=fido-device-onboard-rs-$(VERSION)-vendor.tar.xz

.PHONY: vendor
vendor:
# We need v0.5.7 because of RHEL rust version
cargo install --quiet [email protected];
for platform in $(PLATFORMS); do \
args+="--platform $${platform} "; \
done
# https://issues.redhat.com/browse/RHEL-65521
args+="--exclude-crate-path idna#tests "
rm -rf vendor
cargo vendor-filterer $${args}
tar cJf $(VENDOR_TARBALL) vendor
rm -rf vendor

#
# Building packages
#
Expand All @@ -38,41 +59,57 @@ help:
# ./rpmbuild, using rpmbuild's usual directory structure.
#

RPM_SPECFILE=rpmbuild/SPECS/fido-device-onboard-rs-$(COMMIT).spec
RPM_TARBALL=rpmbuild/SOURCES/fido-device-onboard-rs-$(COMMIT).tar.gz
VENDOR_TARBALL=rpmbuild/SOURCES/fido-device-onboard-rs-$(COMMIT)-vendor-patched.tar.xz
RPM_TOP_DIR=$(CURDIR)/rpmbuild
RPMS_SPECS_DIR=$(RPM_TOP_DIR)/SPECS
RPMS_SOURCES_DIR=$(RPM_TOP_DIR)/SOURCES
RPM_SPECFILE=$(RPMS_SPECS_DIR)/fido-device-onboard-rs-$(VERSION).spec
RPM_TARBALL=$(RPMS_SOURCES_DIR)/fido-device-onboard-rs-$(VERSION).tar.gz
RPM_VENDOR_TARBALL=${RPMS_SOURCES_DIR}/$(VENDOR_TARBALL)

$(RPM_SPECFILE):
mkdir -p $(CURDIR)/rpmbuild/SPECS
sed -e "s/^Version:.*/Version: $(COMMIT)/;" fido-device-onboard.spec > $(RPM_SPECFILE)
if [ "$(ID)" = "fedora" ] && [ $(VARIANT_ID) != "eln" ]; then \
mkdir -p $(RPMS_SPECS_DIR)
sed -e "s/^Version:.*/Version: $(VERSION)/;" \
-e "s|%{url}/archive/v%{version}/||;" \
fido-device-onboard.spec > $(RPM_SPECFILE)
if [[ $(ID) = "fedora" ]] && [[ $(VARIANT_ID) != "eln" ]]; then \
sed -i "/Source1/d ; /^# See make-vendored-tarfile.sh in upstream repo/d ;" $(RPM_SPECFILE); \
fi

$(RPM_TARBALL):
mkdir -p $(CURDIR)/rpmbuild/SOURCES
cp ./patches/0001-Revert-chore-use-git-fork-for-aws-nitro-enclaves-cos.patch rpmbuild/SOURCES/;
git archive --prefix=fido-device-onboard-rs-$(COMMIT)/ --format=tar.gz HEAD > $(RPM_TARBALL)
mkdir -p $(RPMS_SOURCES_DIR)
git archive --prefix=fido-device-onboard-rs-$(VERSION)/ --format=tar.gz HEAD > $(RPM_TARBALL)

$(VENDOR_TARBALL):
[ "$(ID)" = "fedora" ] && [ $(VARIANT_ID) != "eln" ] || ( \
mkdir -p $(CURDIR)/rpmbuild/SOURCES ; \
./make-vendored-tarfile.sh $(COMMIT) ; \
mv fido-device-onboard-rs-$(COMMIT)-vendor-patched.tar.xz rpmbuild/SOURCES ;)
$(RPM_VENDOR_TARBALL): vendor
mkdir -p $(RPMS_SOURCES_DIR)
mv $(VENDOR_TARBALL) $(RPM_VENDOR_TARBALL)

.PHONY: srpm
srpm: $(RPM_SPECFILE) $(RPM_TARBALL) $(VENDOR_TARBALL)
srpm: $(RPM_SPECFILE) $(RPM_TARBALL) $(RPM_VENDOR_TARBALL)
rpmbuild -bs \
--define "_topdir $(CURDIR)/rpmbuild" \
--define "_topdir $(RPM_TOP_DIR)" \
$(RPM_SPECFILE)

.PHONY: rpm
rpm: $(RPM_SPECFILE) $(RPM_TARBALL) $(VENDOR_TARBALL)
sudo dnf builddep -y fido-device-onboard
rpm: $(RPM_SPECFILE) $(RPM_TARBALL) $(RPM_VENDOR_TARBALL)
sudo dnf builddep -y $(RPM_SPECFILE)
rpmbuild -bb \
--define "_topdir $(CURDIR)/rpmbuild" \
--define "_topdir $(RPM_TOP_DIR)" \
$(RPM_SPECFILE)

# Packit targets, do not use in local environments
.PHONY: packit-fix-spec-file
packit-fix-spec-file: $(RPM_SPECFILE)
mv $(RPM_SPECFILE) ./fido-device-onboard.spec

.PHONY: packit-create-archive
packit-create-archive: $(RPM_TARBALL)
mv $(RPM_TARBALL) .

.PHONY: packit-create-vendor
packit-create-vendor: $(RPM_VENDOR_TARBALL)
mv $(RPM_VENDOR_TARBALL) .


#
# Generating man pages
#
Expand Down

0 comments on commit 829681a

Please sign in to comment.