Skip to content

Commit

Permalink
common: rpm spec refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
wlemkows committed Aug 16, 2017
1 parent c22a2de commit 4ad9134
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 81 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ RPM_BUILDDIR=rpmbuild
DPKG_BUILDDIR=dpkgbuild
EXPERIMENTAL ?= n
BUILD_PACKAGE_CHECK ?= y
TEST_CONFIG_FILE ?=$(CURDIR)/src/test/testconfig.sh

rpm : override DESTDIR=$(CURDIR)/$(RPM_BUILDDIR)
dpkg: override DESTDIR=$(CURDIR)/$(DPKG_BUILDDIR)
rpm dpkg: override prefix=/usr
Expand Down Expand Up @@ -121,12 +123,10 @@ check-license:
sparse:
$(MAKE) -C src sparse

# XXX: restore before commit
# $(if $(shell git status --porcelain), $(error Working directory is dirty: $(shell git status --porcelain)))

source:
$(if $(shell git rev-parse 2>&1), $(error Not a git repository))
$(if $(DESTDIR), , $(error Please provide DESTDIR variable))
$(if $(shell git status --porcelain), $(error Working directory is dirty: $(shell git status --porcelain)))
mkdir -p $(DESTDIR)/nvml
echo -n $(SRCVERSION) > $(DESTDIR)/nvml/.version
git archive HEAD | tar -x -C $(DESTDIR)/nvml
Expand All @@ -136,7 +136,7 @@ pkg-clean:

rpm dpkg: pkg-clean source
+utils/build-$@.sh $(SRCVERSION) $(DESTDIR)/nvml $(DESTDIR) $(CURDIR)/$@\
${EXPERIMENTAL} ${BUILD_PACKAGE_CHECK} $(CURDIR)/src/test/testconfig.sh
${EXPERIMENTAL} ${BUILD_PACKAGE_CHECK} ${BUILD_RPMEM} ${TEST_CONFIG_FILE} ${DISTRO}

install uninstall:
$(MAKE) -C src $@
Expand Down
8 changes: 5 additions & 3 deletions utils/build-dpkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@
SCRIPT_DIR=$(dirname $0)
source $SCRIPT_DIR/pkg-common.sh

if [ $# -lt 6 -o $# -gt 7 ]
# two arguments - BUILD_RPMEM and DISTRO are defined
# and used only for build-rpm and they are ignored here
if [ $# -lt 6 -o $# -gt 9 ]
then
echo "Usage: $(basename $0) VERSION_TAG SOURCE_DIR WORKING_DIR"\
"OUT_DIR EXPERIMENTAL RUN_CHECK"\
"[TEST_CONFIG_FILE] "
"BUILD_RPMEM [TEST_CONFIG_FILE] [DISTRO] "
exit 1
fi

Expand All @@ -51,7 +53,7 @@ WORKING_DIR=$3
OUT_DIR=$4
EXPERIMENTAL=$5
BUILD_PACKAGE_CHECK=$6
TEST_CONFIG_FILE=$7
TEST_CONFIG_FILE=$8
PREFIX=usr
LIB_DIR=$PREFIX/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)
INC_DIR=$PREFIX/include
Expand Down
119 changes: 74 additions & 45 deletions utils/build-rpm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,24 @@
#

SCRIPT_DIR=$(dirname $0)

source $SCRIPT_DIR/pkg-common.sh

check_tool rpmbuild

check_file $SCRIPT_DIR/pkg-config.sh
source $SCRIPT_DIR/pkg-config.sh


if [ $# -lt 6 -o $# -gt 7 ]
if [ $# -lt 7 -o $# -gt 9 ]
then
echo "Usage: $(basename $0) VERSION_TAG SOURCE_DIR WORKING_DIR"\
"OUT_DIR EXPERIMENTAL RUN_CHECK"\
"[TEST_CONFIG_FILE] "
exit 1
echo "Usage: $(basename $0) VERSION_TAG"\
"SOURCE_DIR"\
"WORKING_DIR"\
"OUT_DIR"\
"EXPERIMENTAL"\
"RUN_CHECK"\
"BUILD_RPMEM"\
"[TEST_CONFIG_FILE]"\
"[DISTRO] "
exit 1
fi

PACKAGE_VERSION_TAG=$1
Expand All @@ -58,15 +61,32 @@ WORKING_DIR=$3
OUT_DIR=$4
EXPERIMENTAL=$5
BUILD_PACKAGE_CHECK=$6
TEST_CONFIG_FILE=$7
BUILD_RPMEM=$7
TEST_CONFIG_FILE=$8
DISTRO=$9


# detected distro or defined in cmd
if [ -z "${DISTRO}" ]
then
OS=$(get_os)
if [ "$OS" != "1" ]
then
echo "Detected OS: $OS"
DISTRO=$OS
else
error "Unknown distribution"
exit 1
fi
fi


if [ "$EXTRA_CFLAGS_RELEASE" = "" ]; then
export EXTRA_CFLAGS_RELEASE="-ggdb -fno-omit-frame-pointer"
fi

LIBFABRIC_MIN_VERSION=1.4.2

RPMBUILD_OPTS=""

PACKAGE_VERSION=$(get_version $PACKAGE_VERSION_TAG)

if [ -z "$PACKAGE_VERSION" ]
Expand All @@ -90,51 +110,49 @@ OLDPWD=$PWD
cd $WORKING_DIR

check_dir $SOURCE

mv $SOURCE $PACKAGE_SOURCE


# XXX: add comdline arg to specify distro
if [ "$DISTRO" == "suse" ]
if [ "$DISTRO" = "SLES" ]
then
RPM_LICENSE="BSD-3-Clause"
RPM_GROUP_SYS_BASE="System\/Base"
RPM_GROUP_SYS_LIBS="System\/Libraries"
RPM_GROUP_DEV_LIBS="Development\/Libraries\/C and C++"
RPM_PKG_NAME_SUFFIX="1"
RPM_MAKE_FLAGS="BINDIR=""%_bindir"" NORPATH=1"
RPM_MAKE_INSTALL="%fdupes %{buildroot}/%{_prefix}"
RPM_MAKE_INSTALL="%fdupes %{buildroot}\/%{_prefix}"
sed -i '/^#.*bugzilla.redhat/d' \
$OLDPWD/$SCRIPT_DIR/nvml.spec.in
else
RPM_LICENSE="BSD"
RPM_GROUP_SYS_BASE="System Environment\/Base"
RPM_GROUP_SYS_LIBS="System Environment\/Libraries"
RPM_GROUP_DEV_LIBS="Development\/Libraries"
RPM_PKG_NAME_SUFFIX=""
RPM_MAKE_FLAGS="NORPATH=1" # XXX
RPM_MAKE_FLAGS="NORPATH=1"
RPM_MAKE_INSTALL=""
fi

#
# Create parametrized spec file required by rpmbuild.
# Most of variables are set in config.sh file in order to
# Most of variables are set in pkg-config.sh file in order to
# keep descriptive values separately from this script.
#
sed -e "s/__VERSION__/$PACKAGE_VERSION/g" \
-e "s/__LICENSE__/$RPM_LICENSE/g" \
-e "s/__GROUP_SYS_BASE__/$RPM_GROUP_SYS_BASE/g" \
-e "s/__GROUP_SYS_LIBS__/$RPM_GROUP_SYS_LIBS/g" \
-e "s/__GROUP_DEV_LIBS__/$RPM_GROUP_DEV_LIBS/g" \
-e "s/__PKG_NAME_SUFFIX__/$RPM_PKG_NAME_SUFFIX/g" \
-e "s/__MAKE_FLAGS__/$RPM_MAKE_FLAGS/g" \
-e "s/__MAKE_INSTALL_FDUPES__/$RPM_MAKE_INSTALL/g" \
-e "s/__LIBFABRIC_MIN_VER__/$LIBFABRIC_MIN_VERSION/g" \
$OLDPWD/$SCRIPT_DIR/nvml.spec.in > $RPM_SPEC_FILE


#Source0: $PACKAGE_TARBALL


# Experimental features
sed -e "s/__VERSION__/$PACKAGE_VERSION/g" \
-e "s/__LICENSE__/$RPM_LICENSE/g" \
-e "s/__PACKAGE_MAINTAINER__/$PACKAGE_MAINTAINER/g" \
-e "s/__PACKAGE_SUMMARY__/$PACKAGE_SUMMARY/g" \
-e "s/__GROUP_SYS_BASE__/$RPM_GROUP_SYS_BASE/g" \
-e "s/__GROUP_SYS_LIBS__/$RPM_GROUP_SYS_LIBS/g" \
-e "s/__GROUP_DEV_LIBS__/$RPM_GROUP_DEV_LIBS/g" \
-e "s/__PKG_NAME_SUFFIX__/$RPM_PKG_NAME_SUFFIX/g" \
-e "s/__MAKE_FLAGS__/$RPM_MAKE_FLAGS/g" \
-e "s/__MAKE_INSTALL_FDUPES__/$RPM_MAKE_INSTALL/g" \
-e "s/__LIBFABRIC_MIN_VER__/$LIBFABRIC_MIN_VERSION/g" \
$OLDPWD/$SCRIPT_DIR/nvml.spec.in > $RPM_SPEC_FILE

# experimental features
if [ "${EXPERIMENTAL}" = "y" ]
then
# no experimental features for now
Expand All @@ -147,29 +165,40 @@ then
RPMBUILD_OPTS+="--with rpmem "
fi

if [ "${BUILD_PACKAGE_CHECK}" != "y" ]
# use specified testconfig file or default
if [[( -n "${TEST_CONFIG_FILE}") && ( -f "$TEST_CONFIG_FILE" ) ]]
then
RPMBUILD_OPTS+="--nocheck "
echo "Test config file: $TEST_CONFIG_FILE"
TEST_CONFIG_VAL=${TEST_CONFIG_FILE}
else
echo -e "Test config file $TEST_CONFIG_FILE does not exist.\n"\
"Default test config will be used."
TEST_CONFIG_VAL="default"
fi

#if [ -f $TEST_CONFIG_FILE ]
#then
# RPMBUILD_OPTS+="--define '_testconfig ""$TEST_CONFIG_FILE"" ' "
#fi

# run make check or not
if [ "${BUILD_PACKAGE_CHECK}" = "y" ]
then
CHECK=1
else
CHECK=0
fi

tar zcf $PACKAGE_TARBALL $PACKAGE_SOURCE

# Create directory structure for rpmbuild
mkdir -v BUILD SPECS

echo "opts: $RPMBUILD_OPTS"
echo "opts: $RPMBUILD_OPTS --define _testconfig ${TEST_CONFIG_VAL} --define _check ${CHECK}"


rpmbuild --define "_topdir `pwd`"\
--define "_rpmdir ${OUT_DIR}"\
--define "_srcrpmdir ${OUT_DIR}"\
$RPMBUILD_OPTS\
-ta $PACKAGE_TARBALL
--define "_rpmdir ${OUT_DIR}"\
--define "_srcrpmdir ${OUT_DIR}"\
--define "_testconfig ${TEST_CONFIG_VAL}"\
--define "_check ${CHECK}"\
-ta $PACKAGE_TARBALL \
$RPMEMBUILD_OPTS

echo "Building rpm packages done"

Expand Down
64 changes: 36 additions & 28 deletions utils/nvml.spec.in
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@

# rpmbuild options:
# --with | --without rpmem
# --define '_testconfig <path to custom testconfig.sh>'
# --define "_testconfig <path to custom testconfig.sh or 'default'>"
# --define "_check <1|0>" - run make check or not
#

# do not terminate build if files in the $RPM_BUILD_ROOT
# directory are not found in the %files (without rpmem case)
%define _unpackaged_files_terminate_build 0

# default definition
%bcond_with rpmem

# disable 'make check' on suse
%if %{defined suse_version}
%define _with_check 0
%else
%define _with_check 1
%define _check 0
%define dist .suse%{suse_version}
%endif

# default definitions
%{!?_with_rpmem: %{?_without_rpmem: %define _with_rpmem 0}}

# XXX: fix that
#%if 0%{?_with_rpmem:1} || 0%{?suse_version} > 1315 || 0%{?fedora} >= 27 || 0%{?rhel} >= 7
#%define with_fabric 1
#%endif
%if %{with rpmem} || (0%{?suse_version} > 1315) || (0%{?fedora} >= 27) || (0%{?rhel} >= 7)
%define with_fabric 1
%endif

%define min_libfabric_ver __LIBFABRIC_MIN_VER__

Name: nvml
Version: __VERSION__
Release: 1%{?dist}
Summary: Non-Volatile Memory Library
Summary: __PACKAGE_SUMMARY__
Packager: __PACKAGE_MAINTAINER__
Group: __GROUP_SYS_LIBS__
License: __LICENSE__
URL: http://pmem.io/nvml
# XXX: for local builds, use local tarball
Source0: https://github.com/pmem/%{name}/archive/%{version}.tar.gz#/%{name}-%{version}.tar.gz

Source0: %{name}-%{version}.tar.gz

BuildRequires: gcc
BuildRequires: make
BuildRequires: glibc-devel
BuildRequires: autoconf
BuildRequires: automake
Expand All @@ -38,7 +45,7 @@ BuildRequires: pkgconfig
BuildRequires: doxygen
BuildRequires: gdb

%if 0%{?_with_rpmem:1}
%if %{with rpmem}
BuildRequires: libfabric-devel >= %{min_libfabric_ver}
%endif

Expand All @@ -54,12 +61,11 @@ BuildRequires: libfabric-devel >= %{min_libfabric_ver}
# implementation of the low-level routines for flushing to persistent
# memory.

# XXX: cut it off for suse

# https://bugzilla.redhat.com/show_bug.cgi?id=1340634
# https://bugzilla.redhat.com/show_bug.cgi?id=1340635
# https://bugzilla.redhat.com/show_bug.cgi?id=1340636
# https://bugzilla.redhat.com/show_bug.cgi?id=1340637

ExclusiveArch: x86_64

%description
Expand Down Expand Up @@ -528,8 +534,7 @@ debug version is to set the environment variable LD_LIBRARY_PATH to
%doc ChangeLog CONTRIBUTING.md README.md


%if 0%{?_with_rpmem:1}

%if %{with rpmem} && 0%{?with_fabric:1}
%package -n librpmem__PKG_NAME_SUFFIX__
Summary: Remote Access to Persistent Memory library
Group: __GROUP_SYS_LIBS__
Expand Down Expand Up @@ -604,7 +609,7 @@ and facilitates access to persistent memory over RDMA.
%{_bindir}/rpmemd
%{_mandir}/man1/rpmemd.1.gz

%endif # _with_rpmem
%endif # _with_rpmem && libfabric


%package tools
Expand Down Expand Up @@ -666,14 +671,17 @@ __MAKE_INSTALL_FDUPES__


%check
%if 0%{?_with_check:1}
%if 0%{?_testconfig:1}
cp %{_testconfig} src/test/testconfig.sh
%if "%{_check}" == "1"
%if "%{_testconfig}" != "default"
cp %{_testconfig} src/test/testconfig.sh
%else
cp src/test/testconfig.sh.example src/test/testconfig.sh
echo "PMEM_FS_DIR=/tmp" >> src/test/testconfig.sh
echo "PMEM_FS_DIR_FORCE_PMEM=1" >> src/test/testconfig.sh
%endif
make check
%else
echo "PMEM_FS_DIR=/tmp" > src/test/testconfig.sh
echo "PMEM_FS_DIR_FORCE_PMEM=1" >> src/test/testconfig.sh
%endif
make check
echo "Check skipped"
%endif

%post -n libpmem__PKG_NAME_SUFFIX__ -p /sbin/ldconfig
Expand All @@ -691,7 +699,7 @@ make check
%post -n libpmempool__PKG_NAME_SUFFIX__ -p /sbin/ldconfig
%postun -n libpmempool__PKG_NAME_SUFFIX__ -p /sbin/ldconfig

%if 0%{?_with_rpmem:1}
%if %{with rpmem}
%post -n librpmem__PKG_NAME_SUFFIX__ -p /sbin/ldconfig
%postun -n librpmem__PKG_NAME_SUFFIX__ -p /sbin/ldconfig
%endif
Expand Down
Loading

0 comments on commit 4ad9134

Please sign in to comment.