# Main build script
# (C) Copyright IBM Corp. 2008-2009
# Licensed under the GPLv2.

include Rules.mk
SUBDIRS=data bin pwrkap docs man
ALL_SUBDIRS=$(addsuffix _all,$(SUBDIRS))
CLEAN_SUBDIRS=$(addsuffix _clean,$(SUBDIRS))
INSTALL_SUBDIRS=$(addsuffix _install,$(SUBDIRS))

.PHONY: $(SUBDIRS) $(ALL_SUBDIRS) $(CLEAN_SUBDIRS) $(INSTALL_SUBDIRS)

all: $(ALL_SUBDIRS)

$(ALL_SUBDIRS):
	$(MAKE) all -C $(subst _all,,$@)

clean: $(CLEAN_SUBDIRS)

$(CLEAN_SUBDIRS):
	$(MAKE) clean -C $(subst _clean,,$@)

install: $(INSTALL_SUBDIRS)

$(INSTALL_SUBDIRS):
	$(MAKE) install -C $(subst _install,,$@)

dist:
	@if test "`git describe`" != "$(PWRKAP_VERSION)" ; then \
		echo 'Update PWRKAP_VERSION in the Rules.mk file before running "make dist".' ; \
		exit 1 ; \
	fi
	git archive --format=tar --prefix=pwrkap-$(PWRKAP_VERSION)/ HEAD^{tree} | gzip -9 > pwrkap-$(PWRKAP_VERSION).tar.gz

