blob: 448a0327f2a269d9b4f348c6fef3ed4d68f0d481 [file] [log] [blame]
Austin Schuh745610d2015-09-06 18:19:50 -07001#!/bin/sh -e
2
3# Run this from the 'packages' directory, just under rootdir
4
5# We can only build rpm packages, if the rpm build tools are installed
6if [ \! -x /usr/bin/rpmbuild ]
7then
8 echo "Cannot find /usr/bin/rpmbuild. Not building an rpm." 1>&2
9 exit 0
10fi
11
12# Check the commandline flags
13PACKAGE="$1"
14VERSION="$2"
15fullname="${PACKAGE}-${VERSION}"
16archive=../$fullname.tar.gz
17
18if [ -z "$1" -o -z "$2" ]
19then
20 echo "Usage: $0 <package name> <package version>" 1>&2
21 exit 0
22fi
23
24# Double-check we're in the packages directory, just under rootdir
25if [ \! -r ../Makefile -a \! -r ../INSTALL ]
26then
27 echo "Must run $0 in the 'packages' directory, under the root directory." 1>&2
28 echo "Also, you must run \"make dist\" before running this script." 1>&2
29 exit 0
30fi
31
32if [ \! -r "$archive" ]
33then
34 echo "Cannot find $archive. Run \"make dist\" first." 1>&2
35 exit 0
36fi
37
38# Create the directory where the input lives, and where the output should live
39RPM_SOURCE_DIR="/tmp/rpmsource-$fullname"
40RPM_BUILD_DIR="/tmp/rpmbuild-$fullname"
41
42trap 'rm -rf $RPM_SOURCE_DIR $RPM_BUILD_DIR; exit $?' EXIT SIGHUP SIGINT SIGTERM
43
44rm -rf "$RPM_SOURCE_DIR" "$RPM_BUILD_DIR"
45mkdir "$RPM_SOURCE_DIR"
46mkdir "$RPM_BUILD_DIR"
47
48cp "$archive" "$RPM_SOURCE_DIR"
49
50# rpmbuild -- as far as I can tell -- asks the OS what CPU it has.
51# This may differ from what kind of binaries gcc produces. dpkg
52# does a better job of this, so if we can run 'dpkg --print-architecture'
53# to get the build CPU, we use that in preference of the rpmbuild
54# default.
55target=`dpkg --print-architecture 2>/dev/null || echo ""`
56if [ -n "$target" ]
57then
58 target=" --target $target"
59fi
60
61rpmbuild -bb rpm/rpm.spec $target \
62 --define "NAME $PACKAGE" \
63 --define "VERSION $VERSION" \
64 --define "_sourcedir $RPM_SOURCE_DIR" \
65 --define "_builddir $RPM_BUILD_DIR" \
66 --define "_rpmdir $RPM_SOURCE_DIR"
67
68# We put the output in a directory based on what system we've built for
69destdir=rpm-unknown
70if [ -r /etc/issue ]
71then
72 grep "Red Hat.*release 7" /etc/issue >/dev/null 2>&1 && destdir=rh7
73 grep "Red Hat.*release 8" /etc/issue >/dev/null 2>&1 && destdir=rh8
74 grep "Red Hat.*release 9" /etc/issue >/dev/null 2>&1 && destdir=rh9
75 grep "Fedora Core.*release 1" /etc/issue >/dev/null 2>&1 && destdir=fc1
76 grep "Fedora Core.*release 2" /etc/issue >/dev/null 2>&1 && destdir=fc2
77 grep "Fedora Core.*release 3" /etc/issue >/dev/null 2>&1 && destdir=fc3
78fi
79
80rm -rf "$destdir"
81mkdir -p "$destdir"
82# We want to get not only the main package but devel etc, hence the middle *
83mv "$RPM_SOURCE_DIR"/*/"${PACKAGE}"-*"${VERSION}"*.rpm "$destdir"
84
85echo
86echo "The rpm package file(s) are located in $PWD/$destdir"