#   Do not use this Makefile directly! It is intended to be called
#   by another Makefile.
#
#   Note, the following parameters must be already defined by
#   the calling Makefile:
#
#	BIN
#	PREFIX
#

INSTALL      = install
INSTBINFLAGS = -m 0755 -s
INSTUIDFLAGS = -m 4755
INSTLIBFLAGS = -m 0755 -s
INSTINCFLAGS = -m 0644
INSTMANFLAGS = -m 0644
INSTCFGFLAGS = -m 0644
INSTDATFLAGS = -m 0644

LINK        = ln
LINKFLAGS   = -f -s
MOVE        = mv
MOVEFLAGS   = -f
COPY        = cp
COPYFLAGS   = -f
MKDIR       = mkdir
MKDIRFLAGS  = -p -m 0755
REMOVE      = rm
REMOVEFLAGS = -f

MAN = $(BIN).1.bz2

BIN_DIR         = $(PREFIX)/bin
EDV_BIN_DIR     = $(PREFIX)/lib/endeavour2/bin
MAN_DIR         = $(PREFIX)/man/man1
DATA_DIR        = $(PREFIX)/share/endeavour2/$(BIN)
HELP_DIR        = $(PREFIX)/share/endeavour2/help/$(BIN)
ICONS_DIR       = $(PREFIX)/share/icons
EDV_ICONS_DIR   = $(PREFIX)/share/endeavour2/icons

ICONS = images/icon_avscan_48x48.xpm				\
        images/icon_avscan_32x32.xpm				\
        images/icon_avscan_20x20.xpm				\
        images/icon_biohazard_48x48.xpm				\
        images/icon_biohazard_32x32.xpm				\
        images/icon_biohazard_20x20.xpm				\
        images/icon_virus_db_20x20.xpm				\
        images/icon_virus_db_32x32.xpm				\
        images/icon_virus_pattern_20x20.xpm			\
        images/icon_virus_pattern_32x32.xpm


HR = "-------------------------------------------------------------------------"

install: preinstall install_bin install_data postinstall

install_bin:
	@echo "Installing $(BIN) -> $(EDV_BIN_DIR)"
	@$(MKDIR) $(MKDIRFLAGS) $(EDV_BIN_DIR)
	@-$(INSTALL) $(INSTBINFLAGS) $(BIN) $(EDV_BIN_DIR)
	@echo "Linking $(BIN_DIR)/$(BIN) -> $(EDV_BIN_DIR)/$(BIN)"
	@-$(LINK) $(LINKFLAGS) $(EDV_BIN_DIR)/$(BIN) $(BIN_DIR)/$(BIN)

install_data:
	@echo "Installing $(MAN) -> $(MAN_DIR)"
	@$(MKDIR) $(MKDIRFLAGS) $(MAN_DIR)
	@-$(INSTALL) $(INSTMANFLAGS) $(MAN) $(MAN_DIR)
	@-for xpm_file in $(ICONS); do \
            echo "Installing $$xpm_file -> $(EDV_ICONS_DIR)"; \
            $(INSTALL) $(INSTDATFLAGS) $$xpm_file $(EDV_ICONS_DIR); \
        done
	@echo "Installing Help -> $(HELP_DIR)"
	@$(MKDIR) $(MKDIRFLAGS) $(HELP_DIR)
	@-$(COPY) $(COPYFLAGS) help/* $(HELP_DIR)
	@-$(COPY) $(COPYFLAGS) ../LICENSE $(HELP_DIR)

preinstall:
	@echo "Installing \"$(BIN)\"..."

postinstall:
	@echo "Install done."
	@echo $(HR)
	@echo "Program $(BIN) installed in:"
	@echo " "
	@echo "        $(EDV_BIN_DIR)"
	@echo " "
	@echo "Manual page $(MAN) installed in:"
	@echo " "
	@echo "        $(MAN_DIR)"
	@echo " "
	@echo "Icons installed in:"
	@echo " "
	@echo "        $(EDV_ICONS_DIR)"
	@echo " "
	@echo "Help installed in:"
	@echo " "
	@echo "        $(HELP_DIR)"
	@echo " "
	@echo $(HR)
	@echo " "
	@echo "To run the application, use the command \"$(BIN) &\""
	@echo " "
