#-------------------------------------------------------------------------------
#  universal-applets-extras - (c) 2008 by Ketil W. Aanensen <ketil.w.aanensen@gmail.com>
#-------------------------------------------------------------------------------
#
# only a simple makefile to allow installing screenlets-pack-all (and performing some
# other actions like creating a source-package or the documentation)
#
UA_PATH := /etc/universal-applets/prefix
SCREENLETS_PATH := /etc/screenlets/prefix
INSTALL_LOG := install.log
# try to get PREFIX from $(UA_PATH), if it failed take PREFIX from $(SCREENLETS_PATH)
PREFIX := $(shell cat $(UA_PATH) 2>/dev/null || cat $(SCREENLETS_PATH) 2>/dev/null )
DIR_LIST := $(shell find $(PREFIX)/share/screenlets/screenlets-pack-all/* $(PREFIX)/share/screenlets/screenlets-pack-basic/* -type d -print 2>/dev/null)
FILE_LIST := $(shell cat $(INSTALL_LOG) 2>/dev/null)

# default target (do nothing)
all:
	@echo "Please run 'make install' to install universal-applets-extras."  

# install into the same prefix as core
install:
	@if test $(PREFIX); then \
		python setup.py install --record=$(INSTALL_LOG) --prefix=$(PREFIX); \
		cat $(INSTALL_LOG) | grep Screenlet.py | sed 's:Screenlet.py:Screenlet.pyc:' >> $(INSTALL_LOG); \
	else \
		echo "File "$(UA_PATH)" doesn't exist. Please install Universal Applets or Screenlets."; \
	fi

# uninstall all previously installed files
uninstall:
	@echo "Uninstalling. Please wait..."
	@for p in $(FILE_LIST); do \
	rm -rf $$p; \
	done
	@rm -f $(INSTALL_LOG)
	@for p in $(DIR_LIST); do \
	test -d $$p && rmdir --parents --ignore-fail-on-non-empty $$p; \
	done

# remove all temporary files created by install
clean:
	python setup.py clean
#	rm -r dist
	rm -r build
#	rm MANIFEST
	@echo "Makefile: Temporary files have been removed."

# build a source-release
source_package:
	python setup.py sdist --formats=bztar
	@echo "Makefile: Source-package is ready and waiting in ./dist ..."

