From 6c7a243ecd29ddea45fb88e49f9a1a7f7230374c Mon Sep 17 00:00:00 2001 From: Michael Panzlaff Date: Mon, 25 Nov 2024 14:04:12 +0000 Subject: [PATCH] Move RPM and DEB targets to separate scripts --- Makefile | 65 +++++----------------------------------- packaging/deb/package.sh | 41 +++++++++++++++++++++++++ packaging/rpm/package.sh | 38 +++++++++++++++++++++++ 3 files changed, 86 insertions(+), 58 deletions(-) create mode 100755 packaging/deb/package.sh create mode 100755 packaging/rpm/package.sh diff --git a/Makefile b/Makefile index feeda121c..7c038af68 100644 --- a/Makefile +++ b/Makefile @@ -846,63 +846,12 @@ help: @echo "If PREFIX and INSTALLED_PREFIX differ, you have to move anything after 'make install' to" @echo "the INSTALLED_PREFIX. You can also use 'make move' which does the job for you." -.PHONY: RPM +.PHONY: rpm RPM +rpm: RPM RPM: packaging/rpm/likwid.spec - @WORKSPACE="$${PWD}" - @SPECFILE="$${WORKSPACE}/packaging/rpm/likwid.spec" - # Setup RPM build tree - @eval $$(rpm --eval "ARCH='%{_arch}' RPMDIR='%{_rpmdir}' SOURCEDIR='%{_sourcedir}' SPECDIR='%{_specdir}' SRPMDIR='%{_srcrpmdir}' BUILDDIR='%{_builddir}'") - @mkdir --parents --verbose "$${RPMDIR}" "$${SOURCEDIR}" "$${SPECDIR}" "$${SRPMDIR}" "$${BUILDDIR}" - # Create source tarball - @COMMITISH="HEAD" - @VERS=$$(git describe --tags --abbrev=0 $${COMMITISH}) - @VERS=$${VERS#v} - @VERS=$$(echo $$VERS | sed -e s#'-'#'_'#g) - @if [ "$${VERS}" = "" ]; then VERS="$(VERSION).$(RELEASE).$(MINOR)"; fi - @eval $$(rpmspec --query --queryformat "NAME='%{name}' VERSION='%{version}' RELEASE='%{release}' NVR='%{NVR}' NVRA='%{NVRA}'" --define="VERS $${VERS}" "$${SPECFILE}") - @PREFIX="$${NAME}-$${VERSION}" - @FORMAT="tar.gz" - @SRCFILE="$${SOURCEDIR}/$${PREFIX}.$${FORMAT}" - @git archive --verbose --format "$${FORMAT}" --prefix="$${PREFIX}/" --output="$${SRCFILE}" $${COMMITISH} - # Build RPM and SRPM - @rpmbuild -ba --define="VERS $${VERS}" --rmsource --clean "$${SPECFILE}" - # Report RPMs and SRPMs when in GitHub Workflow - @if [[ "$${GITHUB_ACTIONS}" == true ]]; then - @ RPMFILE="$${RPMDIR}/$${ARCH}/$${NVRA}.rpm" - @ SRPMFILE="$${SRPMDIR}/$${NVR}.src.rpm" - @ echo "RPM: $${RPMFILE}" - @ echo "SRPM: $${SRPMFILE}" - @ echo "::set-output name=SRPM::$${SRPMFILE}" - @ echo "::set-output name=RPM::$${RPMFILE}" - @fi - -.PHONY: DEB + $(BASE_DIR)/packaging/deb/package.sh + +.PHONY: deb DEB +deb: DEB DEB: packaging/deb/likwid.deb.control - @BASEDIR=$${PWD} - @WORKSPACE=$${PWD}/.dpkgbuild - @DEBIANDIR=$${WORKSPACE}/debian - @DEBIANBINDIR=$${WORKSPACE}/DEBIAN - @mkdir --parents --verbose $$WORKSPACE $$DEBIANBINDIR - @make PREFIX=$$WORKSPACE INSTALLED_PREFIX=$(PREFIX) - #@mkdir --parents --verbose $$DEBIANDIR - @CONTROLFILE="$${BASEDIR}/packaging/deb/likwid.deb.control" - @COMMITISH="HEAD" - @VERS=$$(git describe --tags --abbrev=0 $${COMMITISH}) - @VERS=$${VERS#v} - @VERS=$$(echo $$VERS | sed -e s#'-'#'_'#g) - @ARCH=$$(uname -m) - @ARCH=$$(echo $$ARCH | sed -e s#'_'#'-'#g) - @if [ "$${ARCH}" = "x86-64" ]; then ARCH=amd64; fi - @if [ "$${VERS}" = "" ]; then VERS="$(VERSION).$(RELEASE).$(MINOR)"; fi - @PREFIX="$${NAME}-$${VERSION}_$${ARCH}" - @SIZE_BYTES=$$(du -bcs --exclude=.dpkgbuild "$$WORKSPACE"/ | awk '{print $$1}' | head -1 | sed -e 's#^0\+##') - @SIZE="$$(awk -v size="$$SIZE_BYTES" 'BEGIN {print (size/1024)+1}' | awk '{print int($$0)}')" - #@sed -e s#"{VERSION}"#"$$VERS"#g -e s#"{INSTALLED_SIZE}"#"$$SIZE"#g -e s#"{ARCH}"#"$$ARCH"#g $$CONTROLFILE > $${DEBIANDIR}/control - @sed -e s#"{VERSION}"#"$$VERS"#g -e s#"{INSTALLED_SIZE}"#"$$SIZE"#g -e s#"{ARCH}"#"$$ARCH"#g $$CONTROLFILE > $${DEBIANBINDIR}/control - @sudo make PREFIX=$$WORKSPACE INSTALLED_PREFIX=$(PREFIX) install - @DEB_FILE="likwid_$${VERS}_$${ARCH}.deb" - @dpkg-deb -b $${WORKSPACE} "$$DEB_FILE" - @sudo rm -r "$${WORKSPACE}" - @if [ "$${GITHUB_ACTIONS}" = "true" ]; then - @ echo "::set-output name=DEB::$${DEB_FILE}" - @fi + $(BASE_DIR)/packaging/rpm/package.sh diff --git a/packaging/deb/package.sh b/packaging/deb/package.sh new file mode 100755 index 000000000..c2ee08a4f --- /dev/null +++ b/packaging/deb/package.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +set -eu + +if [ -z ${FROM_MAKEFILE+1} ]; then + echo "$0 is not intended to be run manually. Please run 'make RPM' instead." + exit 1 +fi + +BASEDIR=${PWD} +WORKSPACE=${PWD}/.dpkgbuild +DEBIANDIR=${WORKSPACE}/debian +DEBIANBINDIR=${WORKSPACE}/DEBIAN +mkdir --parents --verbose ${WORKSPACE} ${DEBIANBINDIR} +make PREFIX=${WORKSPACE} INSTALLED_PREFIX=${PREFIX} +#mkdir --parents --verbose ${DEBIANDIR} +CONTROLFILE="${BASEDIR}/packaging/deb/likwid.deb.control" +COMMITISH="HEAD" +VERS=$(git describe --tags --abbrev=0 ${COMMITISH}) +VERS=${VERS#v} +VERS=$(echo ${VERS} | sed -e s/-/_/g) +ARCH=$(uname -m) +ARCH=$(echo ${ARCH} | sed -e s/-/_/g) +if [ "${ARCH}" = "x86-64" ]; then + ARCH=amd64 +fi +if [ "${VERS}" = "" ]; then + VERS="$(VERSION).$(RELEASE).$(MINOR)" +fi +PREFIX="${NAME}-${VERSION}_${ARCH}" +SIZE_BYTES=$(du -bcs --exclude=.dpkgbuild "$WORKSPACE"/ | awk '{print $1}' | head -1 | sed -e 's#^0\+##') +SIZE="$(awk -v size="${SIZE_BYTES}" 'BEGIN {print (size/1024)+1}' | awk '{print int($0)}')" +#sed -e s#"{VERSION}"#"$VERS"#g -e s#"{INSTALLED_SIZE}"#"$SIZE"#g -e s#"{ARCH}"#"$ARCH"#g ${CONTROLFILE} > ${DEBIANDIR}/control +sed -e s#"{VERSION}"#"${VERS}"#g -e s#"{INSTALLED_SIZE}"#"${SIZE}"#g -e s#"{ARCH}"#"${ARCH}"#g ${CONTROLFILE} > ${DEBIANBINDIR}/control +sudo make PREFIX=${WORKSPACE} INSTALLED_PREFIX=${PREFIX} install +DEB_FILE="likwid_${VERS}_${ARCH}.deb" +dpkg-deb -b ${WORKSPACE} "${DEB_FILE}" +sudo rm -r "${WORKSPACE}" +if [ "${GITHUB_ACTIONS}" = "true" ]; then + echo "::set-output name=DEB::${DEB_FILE}" +fi diff --git a/packaging/rpm/package.sh b/packaging/rpm/package.sh new file mode 100755 index 000000000..45048140b --- /dev/null +++ b/packaging/rpm/package.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +set -eu + +if [ -z ${FROM_MAKEFILE+1} ]; then + echo "$0 is not intended to be run manually. Please run 'make RPM' instead." + exit 1 +fi + +# pwd matters, so only call from Makefile directory +SPECFILE="packaging/rpm/likwid.spec" +# Setup RPM build tree +eval $(rpm --eval "ARCH='%{_arch}' RPMDIR='%{_rpmdir}' SOURCEDIR='%{_sourcedir}' SPECDIR='%{_specdir}' SRPMDIR='%{_srcrpmdir}' BUILDDIR='%{_builddir}'") +mkdir --parents --verbose "${RPMDIR}" "${SOURCEDIR}" "${SPECDIR}" "${SRPMDIR}" "${BUILDDIR}" +# Create source tarball +COMMITISH="HEAD" +VERS=$(git describe --tags --abbrev=0 ${COMMITISH}) +VERS=${VERS#v} +VERS=$(echo ${VERS} | sed -e s/-/_/g) +if [ "${VERS}" = "" ]; then + VERS="$(VERSION).$(RELEASE).$(MINOR)" +fi +eval $(rpmspec --query --queryformat "NAME='%{name}' VERSION='%{version}' RELEASE='%{release}' NVR='%{NVR}' NVRA='%{NVRA}'" --define="VERS ${VERS}" "${SPECFILE}") +PREFIX="${NAME}-${VERSION}" +FORMAT="tar.gz" +SRCFILE="${SOURCEDIR}/${PREFIX}.${FORMAT}" +git archive --verbose --format "${FORMAT}" --prefix="${PREFIX}/" --output="${SRCFILE}" ${COMMITISH} +# Build RPM and SRPM +rpmbuild -ba --define="VERS ${VERS}" --rmsource --clean "${SPECFILE}" +# Report RPMs and SRPMs when in GitHub Workflow +if [[ "${GITHUB_ACTIONS}" == true ]]; then + RPMFILE="${RPMDIR}/${ARCH}/${NVRA}.rpm" + SRPMFILE="${SRPMDIR}/${NVR}.src.rpm" + echo "RPM: ${RPMFILE}" + echo "SRPM: ${SRPMFILE}" + echo "::set-output name=SRPM::${SRPMFILE}" + echo "::set-output name=RPM::${RPMFILE}" +fi