Whamcloud - gitweb
LU-17028 build: add support for openEuler 20.03 LTS
[tools/e2fsprogs.git] / contrib / build-rpm
1 #!/bin/sh
2
3 # enable xtrace output if requested
4 if [ -n ${ENABLE_XTRACE:-''} ]; then
5     set -x
6 fi
7
8 # Build an e2fsprogs RPM from cvs
9
10 pwd=`pwd`
11 currdir=`basename $pwd`
12 pkgname=`grep Name: e2fsprogs.spec | awk '{print $2;}'`
13 pkgvers=`grep Version: e2fsprogs.spec | awk '{print $2;}'`
14 builddir=${pkgname}-${pkgvers}
15
16 # ensure that $TMP is set to something
17 TMP=${TMP:-'/tmp'}
18
19 cd ..
20 tmpdir=`mktemp -d ${RPM_TMPDIR:-$TMP}/rpmtmp.XXXXXX`
21
22 # We need to build a tarball for the SRPM using $builddir as the 
23 # directory name (since that's what RPM will expect it to unpack
24 # into).  That may require a symlink.
25
26 # Make a recursive-symlink copy of the source dir
27 cp -sR `pwd`/$currdir $tmpdir/$builddir || exit 1
28
29 # Remove any build files from the temporary tarball directory
30 [ -f $tmpdir/$builddir/Makefile ] && make -C $tmpdir/$builddir distclean
31
32 EXCLUDE="--exclude .hg* --exclude .pc* --exclude .git*"
33 (cd $tmpdir && tar czfh ${builddir}.tar.gz $EXCLUDE $builddir)
34
35 [ "`rpmbuild --version 2> /dev/null`" ] && RPM=rpmbuild || RPM=rpm
36
37 # which distro and release
38 DISTRO=$(lsb_release -is)
39 RELEASE=$(lsb_release -rs)
40 # now the hacks in case either is empty
41 if [ -z "$DISTRO" ]; then
42     echo "You really ought to install the lsb_release binary for this distro"
43     if grep "Fedora " /etc/issue; then
44         DISTRO="Fedora"
45     fi
46     if grep "SUSE Linux Enterprise Server " /etc/issue; then
47         DISTRO="SUSE LINUX"
48     fi
49     if grep "Red Hat Enterprise Linux" /etc/system-release; then
50         DISTRO="RedHatEnterprise"
51     fi
52 fi
53 if [ -z "$DISTRO" ]; then
54     echo "Could not determine the distribution.  Please install the lsb_release binary"
55     exit 1
56 fi
57 if [ -z "$RELEASE" ]; then
58     echo "You really ought to install the lsb_release binary for this distro"
59     case "$DISTRO" in
60         Fedora)
61             RELEASE=$(grep Fedora /etc/issue | sed -e 's/Fedora release //' -e 's/ .*//')
62         ;;
63         SUSE\ LINUX)
64             RELEASE=$(grep SUSE /etc/issue | sed -e 's/SUSE Linux Enterprise Server //' -e 's/ .*//')
65         ;;
66         RedHatEnterprise)
67             RELEASE=$(grep 'Red Hat' /etc/system-release | sed -e 's/Red Hat Enterprise Linux release //' -e 's/ .*//')
68         ;;
69     esac
70 fi
71 if [ -z "$RELEASE" ]; then
72     echo "Could not determine the release.  Please install the lsb_release binary"
73     exit 1
74 fi
75 case "$DISTRO-$RELEASE" in
76     AlmaLinux*) DISTRO=RHEL; RELEASE=7+;;
77     openEuler-2[0-9]*) DISTRO=RHEL; RELEASE=7+;;
78     RedHatEnterpriseServer-6*|CentOS-6*|Fedora-1[1-4]) DISTRO=RHEL; RELEASE=6;;
79     RedHatEnterprise*|Fedora*|CentOS*) DISTRO=RHEL; RELEASE=7+;;
80     Rocky*) DISTRO=RHEL; RELEASE=7+;;
81     Scientific-6*) DISTRO=RHEL; RELEASE=6;;
82     Scientific*) DISTRO=RHEL; RELEASE=7+;;
83     SUSE\ LINUX-1[1-5]* | SUSE-1[2-5]*) DISTRO=SUSE_LINUX; RELEASE=11+;;
84 esac
85
86 SPECFILE="$currdir/e2fsprogs-${DISTRO// /_}-$RELEASE.spec"
87 if [ ! -f "$SPECFILE" ]; then
88     SPECFILE="$currdir/e2fsprogs.spec"
89 fi
90 echo "using SPECFILE=$SPECFILE"
91 grep VERSION $currdir/version.h
92 grep Version: $SPECFILE
93 grep Release: $SPECFILE
94
95 $RPM --define "_sourcedir $tmpdir" \
96      --define "_topdir ${RPM_TOPDIR:-$(rpm -E %_topdir)}" \
97      --define "_tmpdir ${RPM_TMPDIR:-$TMP}" \
98      --define "extra_config_flags ${EXTRA_CONFIG_FLAGS:-''}" \
99      -ba $SPECFILE
100
101 rpm_exit=$?
102 rm -rf $tmpdir
103 exit $rpm_exit