# Makefile for GtkDict package.
# 
# Send problems/code hacks to GtkDict@extra.hu 

CC = gcc
CFLAGS = -Wall -o
INSTALLDIR = /usr/local/bin
DATADIR = /usr/share/
NAME = gtkdict
FILES= main.c convert.c io_actions.c dictionary.c interface.c

all:
		@echo "Usage:		make linux"
		@echo "Install:	make install"
		@echo "Install data files:	make install-data"
		@echo "Uninstall:	make uninstall"
		@echo "Clean:		make clean"
		@echo "" 
		@echo "Edit the makefile if you wish to change paths or flags." 
		@echo "Any existing files will be overwritten !"
		@echo "" 

clean:		
		@if [ -f gtkdict ]; then /bin/rm ./gtkdict ; fi
		@if [ -f *.o ]; then /bin/rm ./*.o ; fi

uninstall:	
		@echo "Deleting binary"
		@if [ -f $(INSTALLDIR)/$(NAME) ]; then /bin/rm $(INSTALLDIR)/$(NAME) ; fi
		@echo "Deleting data directory"
		@/bin/rm $(DATADIR)$(NAME)/*
		@if [ -d $(DATADIR)$(NAME) ]; then /bin/rmdir $(DATADIR)$(NAME) ; fi
		@echo "GtkDict has been uninstalled"
		@echo ""

install:	
		@echo "Creating directory : $(INSTALLDIR)"
		@if [ ! -d $(INSTALLDIR) ]; then /bin/mkdir $(INSTALLDIR); fi
		@echo "Setting permissions : $(NAME)"
		@chmod 555 $(NAME)
		@if [ -f $(INSTALLDIR)$(NAME) ]; then /bin/rm $(INSTALLDIR)$(NAME); fi
		@echo "Copying file : $(NAME)"
		@cp ./$(NAME) $(INSTALLDIR)
		@echo "$(NAME) has been installed to $(INSTALLDIR)"
		@echo ""

install-data:	
		@echo "Creating shared directory $(DATADIR)$(NAME)"
		@if [ ! -d $(DATADIR)$(NAME) ]; then /bin/mkdir $(DATADIR)$(NAME); fi
		@echo "Unpacking and copying tables"
		@bunzip2 -k ./data/angol_torzs.tar.bz2
		@tar -xvf ./data/angol_torzs.tar
		@mv ./angol_torzs.dat $(DATADIR)$(NAME)
		@mv ./angol_torzs.idx $(DATADIR)$(NAME)
		@bunzip2 -k ./data/angol_to_torzs.tar.bz2
		@tar -xvf ./data/angol_to_torzs.tar
		@mv ./angol_to_torzs.dat $(DATADIR)$(NAME)
		@mv ./angol_to_torzs.idx $(DATADIR)$(NAME)
		@bunzip2 -k ./data/magyar_torzs.tar.bz2
		@tar -xvf ./data/magyar_torzs.tar
		@rm ./data/*.tar
		@mv ./magyar_torzs.dat $(DATADIR)$(NAME)
		@mv ./magyar_torzs.idx $(DATADIR)$(NAME)
		@echo "Unpacking and copying data files"
		@bunzip2 -k ./data/ang_szotar.dat.bz2
		@mv ./data/ang_szotar.dat $(DATADIR)$(NAME)
		@bunzip2 -k ./data/hun_szotar.dat.bz2
		@mv ./data/hun_szotar.dat $(DATADIR)$(NAME)
		@echo ""


linux:		
		@echo "Making linux"
		$(CC) $(CFLAGS) $(NAME) $(FILES) `gtk-config --cflags` `gtk-config --libs`
		@echo ""
		