summaryrefslogtreecommitdiffstats
path: root/redhat/build/build_rpm_package.sh
blob: 9d8611dee0c52a3e98454c92a34d1c8c9f28e06d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash -ex

# Usage: build_rpm_package.sh <TDE_PACKAGE> [TDE_VERSION]
# Example: build_rpm_package.sh tdebase 14.0.0


PKGNAME="${1##*/}"
TDE_VERSION="${2:-14.0.0}"

SPECFILE=$(get_specfile.sh ${PKGNAME} ${TDE_VERSION})
SOURCES=$(get_source_files.sh ${PKGNAME} ${TDE_VERSION})
TARBALL=$(get_latest_tarball_filename.sh ${PKGNAME} ${TDE_VERSION} || :)
VERSION=$(get_latest_tarball_version.sh ${PKGNAME} ${TDE_VERSION} || :)
case "${VERSION}" in *~pre*) PREVERSION="${VERSION#*~}";; esac

DIST="$(rpmdist.sh --dist)"
BUILDDIR="/dev/shm/BUILD${DIST}.$(uname -i)"
BUILDROOTDIR="/dev/shm/BUILDROOT${DIST}.$(uname -i)"
LOGFILE=/tmp/log.${COMP##*/}

TEMPDIR="$(mktemp -d)"
cp -f ${SPECFILE} ${SOURCES} ${TARBALL} "${TEMPDIR}"

# Check if there are patches
PATCHDIR="${SPECFILE%/*}/patches/${TDE_VERSION}"
PATCHLIST="${PATCHDIR}/patches"
if [ -r "${PATCHLIST}" ]; then
  while read l; do
    case "${l}" in
      ""|"#"*);;
      *)
        if [ -r "${PATCHDIR}/${l}" ]; then
          echo "Applying patch '${l}'..."
          cat "${PATCHDIR}/${l}" >>"${TEMPDIR}/one.patch"
        fi
      ;;
    esac
  done < "${PATCHLIST}"
fi

if [ -r "${TEMPDIR}/one.patch" ]; then
  sed -i "${TEMPDIR}/"*.spec \
      -e "/^Source0:/ s/$/\nPatch0: one.patch/" \
      -e "/%setup/ s/$/\n%patch0 -p1/"
fi

# Determines if we are running an i386 or x86_64 distro
if [ "$(rpm -q --qf '%{arch}\n' kernel | tail -n 1)" = "i686" ]; then
	ARGS="${ARGS} --target=i686"
fi

[ -d "${BUILDDIR}" ] || mkdir -p "${BUILDDIR}"

RPMDIR="$(rpm -E %{_rpmdir}.tde-${TDE_VERSION})"
SRPMDIR="$(rpm -E %{_srcrpmdir}.tde-${TDE_VERSION})"

rpmbuild -ba \
  --define "_specdir ${TEMPDIR}" \
  --define "_sourcedir ${TEMPDIR}" \
  --define "_builddir ${BUILDDIR}" \
  --define "_buildrootdir ${BUILDROOTDIR}" \
  --define "_rpmdir ${RPMDIR}" \
  --define "_srcrpmdir ${SRPMDIR}" \
  --define '_build_create_debug 1' \
  --define "vendor Trinity\ Desktop" \
  --define "packager Francois\ Andriot\ <francois.andriot@free.fr>" \
  --define "tde_version ${TDE_VERSION}" \
  --define "tde_prefix /opt/trinity" \
  --define "preversion ${PREVERSION:-}" \
  --define "with_jack 1" \
  --define "with_xscreensaver 1" \
  ${ARGS} \
  "${TEMPDIR}/${SPECFILE##*/}"
RET=$?

# Removes BUILDDIR if build succeeded
if [ ${RET} -eq 0 ]; then
  rm -rf "${BUILDDIR}/"*${PKGNAME}-${VERSION}*
fi

rm -rf "${TEMPDIR}"

exit $RET