# Makefile for installing Vim on NeXTstep
#
# This Makefile is loosely based on the GNU Makefile conventions found in
# standards.info.
#
# Installing Vim, summary:
#
#	just type -->  make install
#

### Name of the targets and the source
INSTALL		= install
VIMSOURCE	= bin/vim
VIMTARGET	= vim
GVIMTARGET	= gvim
EXTARGET	= ex
VIEWTARGET	= view

### Names of the tools that are also made
TOOLS = bin/ctags bin/xxd

### Installation directories.  The defaults come from configure.
### EXEC_PREFIX is for the executable   (default "/usr/local")
### MANDIR      is for the manual pages (default "/usr/local/man")
### DATADIR     is for the other files  (default "/usr/local/lib" or
###						"/usr/local/share")
### They may be different when using different architectures for the
### executable and a common directory for the other files.
###
EXEC_PREFIX = /usr/local
MANDIR      = /usr/local/man
DATADIR     = /usr/local/share

### Location of executables
BINLOC = $(EXEC_PREFIX)/bin

### Location of man pages
MANSUBDIR = $(MANDIR)/man1

### Location of Vim files (should not need to be changed)
VIMDIR = /vim
HELPSUBDIR = /doc
SYNSUBDIR = /syntax

### VIMLOC      common root of the Vim files
### VIMRCLOC    location for system-wide vimrc file
### HELPSUBLOC  location for help files
### SYNSUBLOC   location for syntax files
### MENULOC	location for menu file
VIMLOC     = $(DATADIR)$(VIMDIR)
VIMRCLOC   = $(VIMLOC)
HELPSUBLOC = $(VIMLOC)$(HELPSUBDIR)
MENULOC    = $(VIMLOC)
SYS_MENU_FILE = $(VIMLOC)/menu.vim
SYNSUBLOC  = $(VIMLOC)$(SYNSUBDIR)

### Program to run on installed binary
STRIP = strip

### Permissions for vim binary
BINMOD = 755

### Permissions for man page
MANMOD = 644

### Permissions for help files
HELPMOD = 644

### Permission for menu file
MENUMOD = 644

### Permissions for bin/man/help directories that are created
DIRMOD = 755

# Where to copy the man and help files from
HELPSOURCE = ./doc

# Where to copy the menu file from
MENUSOURCE = ./doc

# Where to copy the syntax files from
SYNSOURCE = ./syntax


#
# Avoid overwriting an existing executable, somebody might be running it and
# overwriting it could cause it to crash.  Deleting it is OK, it won't be
# really deleted until all running processes for it have exited.  It is
# renamed first, in case the deleting doesn't work.
#
# If you want to keep an older version, rename it before running "make
# install".
#
all:	$(install)

install: installvim installtools

installvim: installvimbin installvimhelp installinks

installvimbin: $(EXEC_PREFIX) $(BINLOC)
	-mv -f $(BINLOC)/$(VIMTARGET) $(BINLOC)/$(VIMTARGET).old
	-rm -f $(BINLOC)/$(VIMTARGET).old
	cp $(VIMSOURCE) $(BINLOC)
	$(STRIP) $(BINLOC)/$(VIMTARGET)
	chmod $(BINMOD) $(BINLOC)/$(VIMTARGET)

# install the help files; first adjust the contents for the location
installvimhelp: $(MANSUBDIR) $(VIMLOC) $(HELPSUBLOC) $(SYNSUBLOC)
	sed -e s+/usr/local/lib/vim+$(HELPENDLOC)+ $(HELPSOURCE)/vim.1 > $(MANSUBDIR)/$(VIMTARGET).1
	chmod $(MANMOD) $(MANSUBDIR)/$(VIMTARGET).1
	cp $(HELPSOURCE)/*.txt $(HELPSUBLOC)
	cp $(HELPSOURCE)/tags $(HELPSUBLOC)
	chmod $(HELPMOD) $(HELPSUBLOC)/*.txt $(HELPSUBLOC)/tags
# install the menu file
	cp $(MENUSOURCE)/menu.vim $(MENULOC)
	chmod $(MENUMOD) $(SYS_MENU_FILE)
# install the resource file
	cp $(HELPSOURCE)/vimrc $(VIMRCLOC)
	chmod $(MENUMOD) $(VIMRCLOC)/vimrc
# install the syntax files
	cp $(SYNSOURCE)/*.vim $(SYNSUBLOC)
	chmod $(HELPMOD) $(SYNSUBLOC)/*.vim

# install helper programs ctags and xxd
installtools: $(TOOLS) $(EXEC_PREFIX) $(BINLOC) $(MANSUBDIR)
	-mv -f $(BINLOC)/xxd $(BINLOC)/xxd.old
	-rm -f $(BINLOC)/xxd.old
	-mv -f $(BINLOC)/ctags $(BINLOC)/ctags.old
	-rm -f $(BINLOC)/ctags.old
	cp bin/xxd $(BINLOC)
	cp bin/ctags $(BINLOC)/ctags
	$(STRIP) $(BINLOC)/xxd
	$(STRIP) $(BINLOC)/ctags
	chmod $(BINMOD) $(BINLOC)/xxd
	chmod $(BINMOD) $(BINLOC)/ctags
	cp $(HELPSOURCE)/xxd.1 $(MANSUBDIR)
	cp $(HELPSOURCE)/ctags.1 $(MANSUBDIR)/ctags.1
	chmod $(MANMOD) $(MANSUBDIR)/xxd.1
	chmod $(MANMOD) $(MANSUBDIR)/ctags.1

$(EXEC_PREFIX) $(BINLOC) $(MANSUBDIR) $(VIMLOC) $(HELPSUBLOC) $(SYNSUBLOC):
	-mkinstalldirs $@
	-chmod $(DIRMOD) $@

# create links from various names to vim.  This is only done when the links
# (or executables with the same name) don't exist yet.
installinks: $(BINLOC)/$(GVIMTARGET) $(BINLOC)/$(EXTARGET) $(BINLOC)/$(VIEWTARGET)

$(BINLOC)/$(GVIMTARGET):
	cd $(BINLOC); ln -s $(VIMTARGET) $(GVIMTARGET)

$(BINLOC)/$(EXTARGET):
	cd $(BINLOC); ln -s $(VIMTARGET) $(EXTARGET)

$(BINLOC)/$(VIEWTARGET):
	cd $(BINLOC); ln -s $(VIMTARGET) $(VIEWTARGET)

uninstall:
	rm -f $(BINLOC)/$(GVIMTARGET)
	rm -f $(BINLOC)/$(EXTARGET) $(BINLOC)/$(VIEWTARGET)
	rm -f $(BINLOC)/$(VIMTARGET) $(MANSUBDIR)/$(VIMTARGET).1
	rm -f $(BINLOC)/xxd $(MANSUBDIR)/xxd.1
	rm -f $(BINLOC)/ctags $(MANSUBDIR)/ctags.1
	rm -f $(HELPSUBLOC)/*.txt $(HELPSUBLOC)/tags
	rm -r -f $(VIMLOC)
