Whamcloud - gitweb
LU-15682 build: add AlmaLinux rpm support
[tools/e2fsprogs.git] / contrib / build-rpm
index 9eca504..95c2a50 100644 (file)
@@ -1,5 +1,10 @@
 #!/bin/sh
 
+# enable xtrace output if requested
+if [ -n ${ENABLE_XTRACE:-''} ]; then
+    set -x
+fi
+
 # Build an e2fsprogs RPM from cvs
 
 pwd=`pwd`
@@ -8,8 +13,11 @@ pkgname=`grep Name: e2fsprogs.spec | awk '{print $2;}'`
 pkgvers=`grep Version: e2fsprogs.spec | awk '{print $2;}'`
 builddir=${pkgname}-${pkgvers}
 
+# ensure that $TMP is set to something
+TMP=${TMP:-'/tmp'}
+
 cd ..
-tmpdir=`mktemp -d rpmtmp.XXXXXX`
+tmpdir=`mktemp -d ${RPM_TMPDIR:-$TMP}/rpmtmp.XXXXXX`
 
 # We need to build a tarball for the SRPM using $builddir as the 
 # directory name (since that's what RPM will expect it to unpack
@@ -21,7 +29,71 @@ cp -sR `pwd`/$currdir $tmpdir/$builddir || exit 1
 # Remove any build files from the temporary tarball directory
 [ -f $tmpdir/$builddir/Makefile ] && make -C $tmpdir/$builddir distclean
 
-(cd $tmpdir && tar czfh ${builddir}.tar.gz $builddir)
+EXCLUDE="--exclude .hg* --exclude .pc* --exclude .git*"
+(cd $tmpdir && tar czfh ${builddir}.tar.gz $EXCLUDE $builddir)
 
 [ "`rpmbuild --version 2> /dev/null`" ] && RPM=rpmbuild || RPM=rpm
-$RPM --define "_sourcedir `pwd`/$tmpdir" -ba $currdir/e2fsprogs.spec || exit $?
+
+# which distro and release
+DISTRO=$(lsb_release -is)
+RELEASE=$(lsb_release -rs)
+# now the hacks in case either is empty
+if [ -z "$DISTRO" ]; then
+    echo "You really ought to install the lsb_release binary for this distro"
+    if grep "Fedora " /etc/issue; then
+        DISTRO="Fedora"
+    fi
+    if grep "SUSE Linux Enterprise Server " /etc/issue; then
+        DISTRO="SUSE LINUX"
+    fi
+fi
+if [ -z "$DISTRO" ]; then
+    echo "Could not determine the distribution.  Please install the lsb_release binary"
+    exit 1
+fi
+if [ -z "$RELEASE" ]; then
+    echo "You really ought to install the lsb_release binary for this distro"
+    case "$DISTRO" in
+        Fedora)
+            RELEASE=$(grep Fedora /etc/issue | sed -e 's/Fedora release //' -e 's/ .*//')
+        ;;
+        SUSE\ LINUX)
+            RELEASE=$(grep SUSE /etc/issue | sed -e 's/SUSE Linux Enterprise Server //' -e 's/ .*//')
+        ;;
+    esac
+fi
+if [ -z "$RELEASE" ]; then
+    echo "Could not determine the release.  Please install the lsb_release binary"
+    exit 1
+fi
+case "$DISTRO-$RELEASE" in
+    Scientific-6*) DISTRO=RHEL; RELEASE=6;;
+    Scientific-7*) DISTRO=RHEL; RELEASE=7+8;;
+    RedHatEnterpriseServer-6*) DISTRO=RHEL; RELEASE=6;;
+    RedHatEnterpriseServer-7*) DISTRO=RHEL; RELEASE=7+8;;
+    RedHatEnterprise-8*) DISTRO=RHEL; RELEASE=7+8;;
+    CentOS-6*) DISTRO=RHEL; RELEASE=6;;
+    CentOS-7*) DISTRO=RHEL; RELEASE=7+8;;
+    CentOS-8*) DISTRO=RHEL; RELEASE=7+8;;
+    Rocky-8*) DISTRO=RHEL; RELEASE=7+8;;
+    AlmaLinux-8*) DISTRO=RHEL; RELEASE=7+8;;
+    Fedora-1[1-4]) DISTRO=RHEL; RELEASE=6;;    # use the same .spec for now
+    Fedora-1[5-9]) DISTRO=RHEL; RELEASE=7+8;;
+    Fedora-2[0-9]) DISTRO=RHEL; RELEASE=7+8;;
+    Fedora-3[0-9]) DISTRO=RHEL; RELEASE=7+8;;
+    SUSE\ LINUX-1[1-5]* | SUSE-12* | SUSE-15*) DISTRO=SUSE_LINUX; RELEASE=11+12+15;;
+esac
+
+SPECFILE="$currdir/e2fsprogs-${DISTRO// /_}-$RELEASE.spec"
+if [ ! -f "$SPECFILE" ]; then
+    SPECFILE="$currdir/e2fsprogs.spec"
+fi
+$RPM --define "_sourcedir $tmpdir" \
+     --define "_topdir ${RPM_TOPDIR:-$(rpm -E %_topdir)}" \
+     --define "_tmpdir ${RPM_TMPDIR:-$TMP}" \
+     --define "extra_config_flags ${EXTRA_CONFIG_FLAGS:-''}" \
+     -ba $SPECFILE
+
+rpm_exit=$?
+rm -rf $tmpdir
+exit $rpm_exit