## Sample for building an rpm from a tarball.
##
## rpm uses something called a "buildroot" directory, which is where
## it looks for SOURCES and builds rpms.
## rpm v4.0.2 has a --buildroot option but it doesn't work,
## so this Makefile.am assumes that you have set buildroot some
## other way, eg,
## via a file in your home directory called ~/.rpmmacros, which contains:
##
##   %_topdir        wherever-you-have-untarred-serel/packages/buildroot-redhat
##
## The rpm -ba below references this buildroot-redhat directory.
##
## Once you've created ~/.rpmmacros, type:
##  cd  wherever-you-have-untarred-serel
##  make distcheck
##  cd packages
##	make rpm
##
## The .rpm and .src.rpm are created inside the buildroot-redhat directory.
##
rpm_root=buildroot-redhat
deb_root=buildroot-debian

EXTRA_DIST = rpm.spec.in
CLEANFILES=rpm.spec $(rpm_root)/SOURCES/* $(rpm_root)/SRPMS/* $(rpm_root)/RPMS/i386/*
MAINTAINERCLEANFILES = Makefile.in

rpm_source_names = redhat-serel-default.rdf redhat-rc-7.x.patch redhat-rc.serel.include \
                   serel.sysconfig serel.conf serel-local.rdf
rpm_source_files = $(rpm_source_names:%=../data/%)


debian : ../$(PACKAGE)-$(VERSION).tar.gz
	rm -rf $(deb_root) > /dev/null 2>&1
	mkdir -p $(deb_root)
	cd $(deb_root);                                         \
	tar xvzf ../../$(PACKAGE)-$(VERSION).tar.gz;            \
	cp -r ../debian-packaging $(PACKAGE)-$(VERSION)/debian; \
	cd $(PACKAGE)-$(VERSION);                               \
	./configure;                                            \
	dpkg-buildpackage -rfakeroot

rpm.spec : rpm.spec.in
	echo Summary: Software to help computers boot faster.  > rpm.spec
	echo Name: $(PACKAGE) >> rpm.spec
	echo Version: $(VERSION) >> rpm.spec
	cat rpm.spec.in >> rpm.spec

rpm : rpm.spec ../$(PACKAGE)-$(VERSION).tar.gz $(rpm_source_files)
	# -p below means no error if already existing
	mkdir -p $(rpm_root) $(rpm_root)/BUILD $(rpm_root)/RPMS $(rpm_root)/SOURCES $(rpm_root)/SPECS $(rpm_root)/SRPMS
	cp ../$(PACKAGE)-$(VERSION).tar.gz $(rpm_root)/SOURCES
	cp $(rpm_source_files) $(rpm_root)/SOURCES
	rpm -ba --clean rpm.spec
