DEPTH = ../../../..

include $(DEPTH)/Makefile.os

PACKAGE?=freedoko-binary

TARGET_DIR?=/tmp/FreeDoko.packages
PACKAGE_DIR?=$(TARGET_DIR)/$(PACKAGE)-$(VERSION)

# Edited for Debian GNU/Linux.
DESTDIR = 

.PHONY: all release_directory package

all :

release_directory :
	-rm -rf $(PACKAGE_DIR)
	mkdir -p $(PACKAGE_DIR)
	cp -a . $(PACKAGE_DIR)/debian
	# copy some files from the base directory
	cp Makefile.install $(PACKAGE_DIR)/Makefile
	cp ../copyright $(PACKAGE_DIR)/copyright
	for f in Version ChangeLog AUTHORS Makefile.os README LIESMICH; do \
	  cp $(DEPTH)/$$f $(PACKAGE_DIR)/; \
	done
	# copy the documentation
	mkdir -p $(PACKAGE_DIR)/doc
	for f in Bugs ToDo Roadmap GPL hpux.required_libs.txt; do \
	  cp $(DEPTH)/doc/$$f $(PACKAGE_DIR)/doc/; \
	done
	cp -a $(DEPTH)/doc/Implementation $(PACKAGE_DIR)/doc/; \
	mkdir $(PACKAGE_DIR)/doc/de
	cd $(DEPTH)/doc/de \
	  && cp GPL.de LIESMICH* $(PACKAGE_DIR)/doc/de/
	mkdir $(PACKAGE_DIR)/doc/en
	cd $(DEPTH)/doc/en \
	  && cp README* $(PACKAGE_DIR)/doc/de/
	# copy the source
	cp -a $(DEPTH)/src $(PACKAGE_DIR)/
	cp $(PACKAGE_DIR)/src/constants.h $(PACKAGE_DIR)/src/constants.h.backup
	cat $(PACKAGE_DIR)/src/constants.h.backup \
	  | sed "s/^\/\/#define RELEASE/#define RELEASE/" \
	  >$(PACKAGE_DIR)/src/constants.h
	$(RM) $(PACKAGE_DIR)/src/Makefile.local
	echo "#override CPPFLAGS += -DPUBLIC_DATA_DIRECTORY_VALUE=\"\\\"../data\\\"\"" \
		> $(PACKAGE_DIR)/src/Makefile.local
	$(MAKE) -C $(PACKAGE_DIR)/src/ clean

package : release_directory
	cd $(PACKAGE_DIR) \
	  && debuild --preserve-envvar CXX
