# $Revision: 1.4 $
#
# This is TkPGP installation/uninstallation makefile.
# 'tkpgp' is a script, so there is no build targets.
#

AWK	= awk
ECHO	= echo
INSTALL	= install
RM	= rm

BINDIR		= /usr/local/bin
DOCDIR		= /usr/doc/TkPGP
XBITMAPDIR	= /usr/include/X11/bitmaps

BINARIES	= tkpgp
BITMAPS		= PGP-lock.icon
DESKTOPFILE	= tkpgp.desktop
PIXMAPS		= PGP-lock.xpm
DOCFILES	= CHANGES INSTALL README TODO Makefile tkpgp.spec

GNOMEDESKTOPDIR = /usr/share/gnome/apps
GNOMEMENU	= Internet
GNOMEPIXMAPDIR  = /usr/share/pixmaps

# Following macros should not need changes.

GNOMEDESKTOPMENUDIR = $(GNOMEDESKTOPDIR)/$(GNOMEMENU)
SRCTARFILE  = tkpgp-$(VERSION).tar
SOURCEFILES =                   \
            $(BINARIES)         \
            $(BITMAPS)          \
            $(DESKTOPFILE)      \
            $(DOCFILES)         \
            $(PIXMAPS)          \

# This automatically retrieves the version number (RCS, CVS)
# from the source file (we have only one) and forms the
# release number. This should change if I have more than one
# source file. In fact, I do - but let's assume that document
# files and such do not change on their own...

AWK_CMD = /Revision:/ {gsub(\"[^0-9]\",\"_\",\$$4); print \$$4}
VERSION	= $(shell $(AWK) -- "$(AWK_CMD)" tkpgp)

default:
	@$(ECHO) "Usage:"
	@$(ECHO) "make install   -- to install (as superuser)"
	@$(ECHO) "make uninstall -- to uninstall (as superuser)"

install:
	$(INSTALL) -d $(DOCDIR)
	$(INSTALL) -d $(GNOMEDESKTOPDIR)
	$(INSTALL) -d $(GNOMEPIXMAPDIR)
	$(INSTALL) -d $(XBITMAPDIR)
	$(INSTALL) --mode 0644 $(DOCFILES) $(DOCDIR)
	$(INSTALL) --mode 0644 $(DESKTOPFILE) $(GNOMEDESKTOPMENUDIR)
	$(INSTALL) --mode 0644 $(PIXMAPS) $(GNOMEPIXMAPDIR)
	$(INSTALL) --mode 0755 $(BINARIES) $(BINDIR)
	$(INSTALL) --mode 0644 $(BITMAPS) $(XBITMAPDIR)
	@$(ECHO)
	@$(ECHO) "TkPGP has been successfully installed"
	@$(ECHO) "-------------------------------------"
	@$(ECHO)
	@$(ECHO) "You can run TkPGP from command line as"
	@$(ECHO) "$(addprefix $(BINDIR)/,$(BINARIES))"
	@$(ECHO) "or (recommended) start it using GNOME".
	@$(ECHO) "TkPGP is installed in $(GNOMEMENU) submenu."
	@$(ECHO)
	@$(ECHO) "To uninstall TkPGP use following command:"
	@$(ECHO) "make -f /usr/doc/TkPGP/Makefile uninstall"
	@$(ECHO)

uninstall:
	$(RM) -rf $(DOCDIR)
	$(RM) -f $(GNOMEDESKTOPMENUDIR)/$(DESKTOPFILE)
	$(RM) -f $(addprefix $(GNOMEPIXMAPDIR)/,$(PIXMAPS))
	$(RM) -f $(addprefix $(BINDIR)/,$(BINARIES))
	@$(ECHO)
	@$(ECHO) "TkPGP has been successfully uninstalled"
	@$(ECHO) "---------------------------------------"
	@$(ECHO)
	@$(ECHO) "Files .tkpgp were NOT removed from user directories"
	@$(ECHO) "because they hold personalized settings. They will"
	@$(ECHO) "be preserved during upgrades. If this bothers you,"
	@$(ECHO) "simply delete .tkpgp files, though they do not"
	@$(ECHO) "contain any sensitive information."
	@$(ECHO)

#--------------------------------------
# These targets are for maintenance only
#--------------------------------------

dist:
	@$(ECHO) "Building the source distribution package..."
	tar cvf $(SRCTARFILE) -C .. $(addprefix tkpgp/,$(SOURCEFILES))
	gzip $(SRCTARFILE)
