Skip to content

Commit

Permalink
Move RPM and DEB targets to separate scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ipatix committed Nov 25, 2024
1 parent 164daf1 commit 6c7a243
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 58 deletions.
65 changes: 7 additions & 58 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
41 changes: 41 additions & 0 deletions packaging/deb/package.sh
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions packaging/rpm/package.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6c7a243

Please sign in to comment.