# Makefile for instaling dictionaries to bgOfficeAssistant
# Radostin Radnev radnev@yahoo.com
# http://bgoffice.sourceforge.net
#


DATA_DIR1:=$(shell kbgoffice --dump-data-dir 2> /dev/null)
DATA_DIR2:=$(shell gbgoffice --dump-data-dir 2> /dev/null)
DATA_DIR3:=$(shell cbgoffice --dump-data-dir 2> /dev/null)

DATA_DIR:=
DATA_DIR:=$(if ${DATA_DIR},${DATA_DIR},${DATA_DIR1})
DATA_DIR:=$(if ${DATA_DIR},${DATA_DIR},${DATA_DIR2})
DATA_DIR:=$(if ${DATA_DIR},${DATA_DIR},${DATA_DIR3})

DATA_DIR:=$(shell echo ${DATA_DIR} | sed 's/\/$$//')


DATA_FILES:=$(shell ls data/)



all: check
	@echo "Nothing to build."
	@echo "Type 'make install' to install data files in proper directory."
	@echo "To execute this command you must be root (su)."
	@echo ""


install: check
	@for file in ${DATA_FILES}; do \
		echo "install -D -m 644 data/$$file ${DATA_DIR}/$$file"; \
		install -D -m 644 data/$$file ${DATA_DIR}/$$file; \
	done


uninstall: check
	@for file in ${DATA_FILES}; do \
		echo "rm -f ${DATA_DIR}/$$file"; \
		rm -f ${DATA_DIR}/$$file; \
	done


check:
	@echo ""
	@if (test -z "${DATA_DIR1}"); then \
		if (test -z "${DATA_DIR2}"); then \
			if (test -z "${DATA_DIR3}"); then \
				echo "Application 'kbgoffice' (or 'gbgoffice', or 'cbgoffice') is not installed."; \
				echo "You need to install at least one of them first."; \
				echo "For more info visit http://bgoffice.sourceforge.net/"; \
				echo ""; \
				exit 1; \
			else \
				echo "Found cbgoffice."; \
			fi \
		else \
			echo "Found gbgoffice."; \
		fi \
	else \
		echo "Found kbgoffice."; \
	fi
	@echo ""
