################################################################################
##
## Copyright (C) 2005-2008 Red Hat, Inc. All rights reserved.
##
## This copyrighted material is made available to anyone wishing to use,
## modify, copy, or redistribute it subject to the terms and conditions
## of the GNU General Public License v.2.
##
################################################################################

include make/version.in

TMP_DIR=..
CONGA_DIRNAME=conga-${VERSION}
CLUSTERMON_DIRNAME=clustermon-${VERSION}
RICCI_DIRNAME=ricci-${VERSION}

.PHONY: conga ricci clustermon

all: conga clustermon
	echo "Run 'make install' to install conga and clustermon"

conga: ricci
	echo "Run 'make install_conga' to install conga"

ricci:
	${MAKE} -C ricci ricci

clustermon:
	${MAKE} -C ricci clustermon
	echo "Run 'make install_clustermon' to install modcluster, cluster-cim and cluster-snmp"

install: install_conga install_clustermon

install_conga: install_ricci

install_ricci:
	${MAKE} -C ricci install_ricci

install_clustermon:
	${MAKE} -C ricci install_clustermon

clean: clean_ricci clean_clustermon

clean_ricci:
	${MAKE} -C ricci clean

clean_clustermon:
	${MAKE} -C ricci clean_clustermon

distclean:
	${MAKE} -C ricci distclean
	rm -f conga.spec conga.spec.in
	rm -f conga*.tar.gz conga*.src.rpm
	rm -f clustermon.spec clustermon.spec.in
	rm -f clustermon*.tar.gz clustermon*.src.rpm
	rm -f ricci.spec ricci.spec.in
	rm -f ricci*.tar.gz ricci*.src.rpm

rebuild: clean all

srpms: ricci_srpm clustermon_srpm

ricci_srpm: clean
	rm -rf ${TMP_DIR}/${RICCI_DIRNAME}
	mkdir ${TMP_DIR}/${RICCI_DIRNAME}
	cp -r ricci/* ricci.spec.* make ${TMP_DIR}/${RICCI_DIRNAME}
	find ${TMP_DIR}/${CLUSTERMON_DIRNAME} -type d -name CVS -print0 | xargs -0 rm -rf || true
	tar -zcf ${RICCI_DIRNAME}.tar.gz ${TMP_DIR}/${RICCI_DIRNAME}
	rm -rf ${TMP_DIR}/${RICCI_DIRNAME}
	if [ -n "${DISTRO}" ] ; then \
		rpmbuild --define "dist .${DISTRO}" --define "_sourcedir ." --define "_srcrpmdir ." --nodeps -bs ricci.spec ; \
	else \
		rpmbuild --define "_sourcedir ." --define "_srcrpmdir ." --nodeps -bs ricci.spec ; \
	fi

clustermon_srpm: clean
	rm -rf ${TMP_DIR}/${CLUSTERMON_DIRNAME}
	cp -r . ${TMP_DIR}/${CLUSTERMON_DIRNAME}
	rm -rf `find ${TMP_DIR}/${CLUSTERMON_DIRNAME} -name CVS`
	rm -f ${TMP_DIR}/${CLUSTERMON_DIRNAME}/conga.spec*
	rm -f ${TMP_DIR}/${CLUSTERMON_DIRNAME}/*gz
	rm -f ${TMP_DIR}/${CLUSTERMON_DIRNAME}/*.rpm
	tar -zcf ${CLUSTERMON_DIRNAME}.tar.gz ${TMP_DIR}/${CLUSTERMON_DIRNAME}
	rm -rf ${TMP_DIR}/${CLUSTERMON_DIRNAME}
	if [ -n "${DISTRO}" ] ; then \
		rpmbuild --define "dist .${DISTRO}" --define "_sourcedir ." --define "_srcrpmdir ." --nodeps -bs clustermon.spec ; \
	else \
		rpmbuild --define "_sourcedir ." --define "_srcrpmdir ." --nodeps -bs clustermon.spec ; \
	fi

rpms: conga_rpm clustermon_rpm

conga_rpm: conga_srpm
	if [ -n "${DISTRO}" ] ; then \
		rpmbuild --define "dist .${DISTRO}" --rebuild ${CONGA_DIRNAME}-${RELEASE}.${DISTRO}.src.rpm ; \
	else \
		rpmbuild --rebuild ${CONGA_DIRNAME}-${RELEASE}.src.rpm ; \
	fi

clustermon_rpm: clustermon_srpm
	if [ -n "${DISTRO}" ] ; then \
		rpmbuild --define "dist .${DISTRO}" --rebuild ${CLUSTERMON_DIRNAME}-${RELEASE}.${DISTRO}.src.rpm ; \
	else \
		rpmbuild --rebuild ${CLUSTERMON_DIRNAME}-${RELEASE}.src.rpm ; \
	fi
