# Makefile to install/uninstall the DiskSearch tool.
# Stefan Saring & Mathias Obst, 2007/03/05

# specify the directory for installation
prefix = /usr/local

bindir  = $(prefix)/bin
datadir = $(prefix)/share

i18ndir = $(datadir)/locale

ds_datadir = $(datadir)/disksearch

po_dir = ./po

TEST           = test
TEST_DIR       = $(TEST) -d

INSTALL        = install
INSTALL_DIR    = $(INSTALL) -d -m 755
INSTALL_FILE   = $(INSTALL) -c -m 644
INSTALL_SCRIPT = $(INSTALL) -c -m 755

REMOVE         = rm
REMOVE_FILE    = $(REMOVE) -f
REMOVE_DIR     = $(REMOVE) -r -f


# Install DiskSearch
install: uninstall_disksearch uninstall_cdsearch install_disksearch

install_disksearch: install_echo install_i18n
	@$(TEST_DIR) $(ds_datadir)/libdisksearch || $(INSTALL_DIR) $(ds_datadir)/libdisksearch
	@$(INSTALL_FILE) ./libdisksearch/*.py* $(ds_datadir)/libdisksearch
	@$(TEST_DIR) $(ds_datadir)/resource || $(INSTALL_DIR) $(ds_datadir)/resource
	@$(INSTALL_FILE) ./resource/*.* $(ds_datadir)/resource
	@$(INSTALL_SCRIPT) ./disksearch.py $(ds_datadir)
	@$(TEST_DIR) $(bindir) || $(INSTALL_DIR) $(bindir)
	@$(INSTALL_SCRIPT) ./disksearch $(bindir)

install_echo:
	@echo "Installing DiskSearch to '$(prefix)' ..."

install_i18n:
	@$(TEST_DIR) $(i18ndir)/de/LC_MESSAGES || $(INSTALL_DIR) $(i18ndir)/de/LC_MESSAGES
	@$(TEST_DIR) $(i18ndir)/es/LC_MESSAGES || $(INSTALL_DIR) $(i18ndir)/es/LC_MESSAGES
	@$(TEST_DIR) $(i18ndir)/it/LC_MESSAGES || $(INSTALL_DIR) $(i18ndir)/it/LC_MESSAGES
	@$(TEST_DIR) $(i18ndir)/fr/LC_MESSAGES || $(INSTALL_DIR) $(i18ndir)/fr/LC_MESSAGES
	@$(TEST_DIR) $(i18ndir)/pl/LC_MESSAGES || $(INSTALL_DIR) $(i18ndir)/pl/LC_MESSAGES
	@$(INSTALL_FILE) $(po_dir)/de.gmo $(i18ndir)/de/LC_MESSAGES/disksearch.mo
	@$(INSTALL_FILE) $(po_dir)/es.gmo $(i18ndir)/es/LC_MESSAGES/disksearch.mo
	@$(INSTALL_FILE) $(po_dir)/it.gmo $(i18ndir)/it/LC_MESSAGES/disksearch.mo
	@$(INSTALL_FILE) $(po_dir)/fr.gmo $(i18ndir)/fr/LC_MESSAGES/disksearch.mo
	@$(INSTALL_FILE) $(po_dir)/pl.gmo $(i18ndir)/pl/LC_MESSAGES/disksearch.mo

# Uninstall DiskSearch (and CDSearch)
uninstall: uninstall_echo uninstall_disksearch uninstall_cdsearch 

uninstall_echo:
	@echo "Uninstalling DiskSearch ..."

uninstall_disksearch: uninstall_i18n
	@$(REMOVE_DIR) $(ds_datadir)
	@$(REMOVE_FILE) $(bindir)/disksearch

uninstall_cdsearch:
	@$(REMOVE_DIR) $(datadir)/cdsearch
	@$(REMOVE_FILE) $(bindir)/cdsearch

uninstall_i18n:
	@$(REMOVE_FILE) $(i18ndir)/de/LC_MESSAGES/disksearch.mo
	@$(REMOVE_FILE) $(i18ndir)/es/LC_MESSAGES/disksearch.mo
	@$(REMOVE_FILE) $(i18ndir)/it/LC_MESSAGES/disksearch.mo
	@$(REMOVE_FILE) $(i18ndir)/fr/LC_MESSAGES/disksearch.mo
	@$(REMOVE_FILE) $(i18ndir)/pl/LC_MESSAGES/disksearch.mo

# For internal use - i18n
pot:
	xgettext *.py libdisksearch/*.py resource/*.glade -o po/disksearch.pot
	msgmerge -U po/de.po po/disksearch.pot
	msgmerge -U po/es.po po/disksearch.pot
	msgmerge -U po/it.po po/disksearch.pot
	msgmerge -U po/fr.po po/disksearch.pot
	msgmerge -U po/pl.po po/disksearch.pot

gmo:
	msgfmt $(po_dir)/de.po -o $(po_dir)/de.gmo
	msgfmt $(po_dir)/es.po -o $(po_dir)/es.gmo
	msgfmt $(po_dir)/it.po -o $(po_dir)/it.gmo
	msgfmt $(po_dir)/fr.po -o $(po_dir)/fr.gmo
	msgfmt $(po_dir)/pl.po -o $(po_dir)/pl.gmo
