.PHONY: distr release debug profile clean tools archive

include PROGNAME
include VERSION
export VERSION

TOPLEVELTOCOPY=COPYING FLAVORS gpl-2.0.txt LICENSE_1_0.txt Makefile PROGNAME README src VERSION
export TOPLEVELTOCOPY
dst=$(prog)-$(VERSION)
export dst
arc=$(dst).tar.bz2
export arc

default: release

distr: tools
	./build/tools/re-create-build.sh
	$(MAKE) debug
	$(MAKE) -C build/debug   clean
	$(MAKE) release
	$(MAKE) -C build/release clean
	$(MAKE) profile
	$(MAKE) -C build/profile clean

debug: tools
	./build/tools/check-build.sh debug
	$(MAKE) -C build/debug debug
	cp build/debug/$(prog) bin/$(prog).debug

release: tools
	./build/tools/check-build.sh release
	$(MAKE) -C build/release release
	cp build/release/$(prog) bin/$(prog)
	strip bin/$(prog)

profile: tools
	./build/tools/check-build.sh profile
	$(MAKE) -C build/profile profile
	cp build/profile/$(prog) bin/$(prog).profile

clean:
	test ! -d build/release || $(MAKE) -C build/release clean
	test ! -d build/release || $(MAKE) -C build/debug   clean
	test ! -d build/release || $(MAKE) -C build/profile clean
	rm -rf build/release build/debug build/profile build/tools
	rm -rf $(dst) $(arc)
	rm -f gmon.out *~

tools:
	cp -r src/tools build
	test ! -d build/tools/.svn || rm -rf build/tools/.svn
	$(MAKE) -C build/tools

archive:
	test ! -d $(dst) || false
	test ! -f $(arc) || false
	$(MAKE) clean
	$(MAKE) tools
	./build/tools/create-archive.sh
