1#!/bin/sh
2
3if [ ! -f /etc/redhat-release ]; then
4	echo "Red Hat (clone) required."
5	exit
6fi
7
8# Check for CMake
9#
10cmake --version 2> /dev/null
11if [ $? != 0 ]; then
12	echo "CMake is not installed but required for building Hiawatha."
13	exit
14fi
15
16# Checking for packages required for building a Red Hat package
17#
18echo "-- Checking for required packages"
19packages="make gcc glibc-devel rpm-build libxml2-devel libxslt-devel"
20missing=""
21for package in ${packages}; do
22	installed=`yum list installed | grep "^${package}\." | wc -l`
23	if [ "$installed" = "0" ]; then
24		missing="${missing} ${package}"
25	fi
26done
27if [ "${missing}" != "" ]; then
28	echo "The following packages are missing:${missing}"
29	exit
30fi
31
32# Get software version
33#
34cd `dirname $0`/..
35if [ -d build_redhat_package ]; then
36	rm -rf build_redhat_package
37fi
38mkdir build_redhat_package
39cd build_redhat_package
40cmake ..
41version=`grep VERSION config.h | cut -f2 -d'"'`
42cd ..
43
44# Prepare package building
45#
46rm -f ~/rpmbuild/SOURCES/hiawatha-${version}.tar.gz
47cd ..
48if [ ! -d "hiawatha-${version}" ]; then
49	echo -e "\n!! Invalid source directory name. Should be named 'hiawatha-${version}'."
50	exit
51fi
52mkdir -p ${HOME}/rpmbuild/SOURCES
53tar -czf ${HOME}/rpmbuild/SOURCES/hiawatha-${version}.tar.gz hiawatha-${version}
54cd hiawatha-${version}
55sed "s/VERSION/${version}/" extra/redhat/hiawatha.spec > build_redhat_package/hiawatha.spec
56cp extra/redhat/*.patch ${HOME}/rpmbuild/SOURCES
57
58# Make Red Hat package
59#
60rpmbuild -bb build_redhat_package/hiawatha.spec
61
62# Done
63#
64rm -rf build_redhat_package
65echo -e "\n-- Package located at ~/rpmbuild/RPMS/"
66