# -*-Makefile-*-

DESTDIR =

prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@

XGETTEXT = @xgettext@
USE_NLS = @USE_NLS@

PYTHON = @PYTHON@
INSTALL = @INSTALL@
SO = @SO@

MODULE_PATH = $(DESTDIR)@pyexecdir@
MODULE_DIR = $(MODULE_PATH)/Pyrite

INSTALL_DIRS = glue Application Conduit Connector Filter Platform Store test util

BINARIES = glue/*$(SO)

MAKE_SYMLINKS = no
COMPILE_PYTHON = @compile_python@
INSTALL_SULFUR = @install_sulfur@
INSTALL_BINARIES = @install_binaries@

EXE = util/install.py util/sync.py util/info.py util/fetchusa.py util/runapp.py

APPLICATIONS = run sync install user product

all:
	cd glue; $(MAKE)
	if [ "$(INSTALL_SULFUR)" = "yes" ]; then \
	    cd Sulfur; ./configure; $(MAKE) ;\
	fi ;


install:
	if [ "$(INSTALL_SULFUR)" = "yes" ]; then \
	    cd Sulfur; $(MAKE) install ;\
	fi ;

	$(INSTALL) -m 755 -d $(MODULE_DIR)
	for i in $(INSTALL_DIRS) ; do \
	    if [ ! -d $(MODULE_DIR)/$$i ]; then \
	        mkdir $(MODULE_DIR)/$$i ; \
	    fi ; \
	done ;

	for i in `find . -path './Sulfur' -prune -o -name '*.py' -print` ; do \
	    cp $$i $(MODULE_DIR)/$$i ; \
	    chmod 644 $(MODULE_DIR)/$$i ; \
	done ;

	for i in `ls $(BINARIES)` ; do \
	    cp $$i $(MODULE_DIR)/$$i ; \
	    chmod 755 $(MODULE_DIR)/$$i ; \
	done ;

	for i in $(EXE) ; do \
	    chmod 755 $(MODULE_DIR)/$$i ; \
	done;

	if [ "$(COMPILE_PYTHON)" = "yes" ]; then \
	    $(PYTHON)    @pythonlib@/compileall.py $(MODULE_DIR) ; \
	    $(PYTHON) -O @pythonlib@/compileall.py $(MODULE_DIR) ; \
	fi ;

	cd i18n ; $(MAKE) install DESTDIR=$(DESTDIR)

	if [ "$(INSTALL_BINARIES)" = "yes" ]; then \
	  for i in $(APPLICATIONS) ; do \
	    ln -s $(MODULE_DIR)/util/runapp.py $(bindir)/pyrite-$$i ; \
	  done ; \
	fi ;

uninstall:
	@echo "***"
	@echo "Warning: uninstallation is not yet complete."
	@echo "***"
	if [ "$(INSTALL_SULFUR)" = "yes" ]; then \
	    cd Sulfur; $(MAKE) uninstall ;\
	fi ;

	rm -rf $(MODULE_DIR)

	if [ "$(INSTALL_BINARIES)" = "yes" ]; then \
	  for i in $(APPLICATIONS) ; do \
	    rm -f $(bindir)/pyrite-$$i ; \
	  done ; \
	fi ;

messages:
	if [ "$(USE_NLS)" = "yes" ]; then \
	    $(XGETTEXT) -L c -d pyrite --keyword=_ -o i18n/pyrite.pox \
	      *.py Application/*.py Conduit/*.py Connector/*.py Filter/*.py \
	      Platform/*.py Store/*.py util/*.py ; \
	fi ;

test:
	cd test; python regrtest.py

clean:
	rm -f config.cache config.log config.status
	cd glue; $(MAKE) clean
	cd i18n; $(MAKE) clean
	rm -f __init__.py Makefile glue/Makefile i18n/Makefile

.PHONY: test
