#
# Makefile
# LGDCommunicationKit, Release 1.0
#
# Copyright (c) 1993, Looking Glass Design, Inc.
# All rights reserved.
#
# Project Manager:  Paul Girone
# Original Author:  Mike Gobbi
# Creation Date:    June 28, 1993
# $Revision: 1.1 $
#

target:: install

install:: documentation_in headers_in libraries_in palettes_in examples_in
deinstall:: documentation_out headers_out libraries_out palettes_out examples_out directories_out
chown:: change_ownerships
help::
	@echo "This makefile has four targets"
	@echo ""
	@echo "  help      - display this message"
	@echo ""
	@echo "  install   - installs the palette, library, etc."
	@echo "              The installation will affect the following directories:"
	@echo "              $(DOC_ROOT)
	@echo "              $(HDR_ROOT)
	@echo "              $(LIB_ROOT)
	@echo "              $(PAL_ROOT)
	@echo "              $(EXM_ROOT)
	@echo ""
	@echo "  chown     - changes owner of installed files/directories to $(OWNER)"
	@echo ""
	@echo "  deinstall - removes the palette, library, etc. from the directories"
	@echo "              listed above"

################################################################
############ BEGINNING OF USER-EDITABLE DEFINITIONS ############
################################################################

# Tools
#
# Changing these definition will change the unix tools used by
# the makefile when installing the package.

MKDIRS = /bin/mkdirs
CP     = /bin/cp
RANLIB = /bin/ranlib
TAR    = /bin/tar
CHOWN  = /etc/chown

# Target owner
#
# You should change this if you want the files to be owned by
# someone other than root

OWNER = root

# Basic Installation Locations
#
# You should the following definitions if you want the package
# to be installed in locations other than those specified.

DOC_ROOT = /LocalLibrary/Documentation
HDR_ROOT = /usr/local/include
LIB_ROOT = /usr/local/lib
PAL_ROOT = /LocalDeveloper/Palettes
EXM_ROOT = /LocalDeveloper/Examples

# Specific locations (Changing these definition is not recommended)
#
# Editing these definition will determine  what subdirectories
# within the basic locations defined above will be created for
# the package.

DOC_DIR = $(DOC_ROOT)/LGDCommunicationKit
HDR_DIR = $(HDR_ROOT)/lgd/commkit
LIB_DIR = $(LIB_ROOT)
PAL_DIR = $(PAL_ROOT)
EXM_DIR = $(EXM_ROOT)/LGDCommunicationKit

# Kit-Specific directories
#
# These are the directories which are specific to this
# kit.  They will be removed when the kit is de-installed.
# Any directories which are extensions of the root
# directories should be in this list.

REMOVABLE_DIRECTORIES = $(DOC_DIR) $(HDR_DIR) $(EXM_DIR)

################################################################
############### END OF USER-EDITABLE DEFINITIONS ###############
################################################################

# Files
DOCS = IntroLGDCommunicationKit.rtf LGDBasicPortProtocol.rtf LGDSerialPort.rtf LGDAppSerialPort.rtf
HEADERS = LGDBasicPortProtocol.h LGDSerialPort.h LGDAppSerialPort.h commkit.h
LIBRARIES = libLGDcommkit.a
PALETTES = LGDCommunicationKit.palette
EXAMPLES = self-test connect SimplePort

documentation_in:
	@echo ""
	@echo installing documentation
	$(MKDIRS) $(DOC_DIR)
	@(cd Documentation ; \
	for x in $(DOCS) none ; do \
	  if [ $$x = "none" ] ; then break; fi ; \
	  echo  $(CP) $$x $(DOC_DIR)/$$x ; \
	 $(CP) $$x $(DOC_DIR) ; \
	done )
documentation_out:
	(if [ -d $(DOC_DIR) ] ; then cd $(DOC_DIR) ; rm -f $(DOCS) ; fi)

headers_in:
	@echo ""
	@echo installing headers
	$(MKDIRS) $(HDR_DIR)
	@(cd HeaderFiles ; \
	for x in $(HEADERS) none ; do \
	  if [ $$x = "none" ] ; then break; fi ; \
	  echo  $(CP) $$x $(HDR_DIR)/$$x ; \
	 $(CP) $$x $(HDR_DIR) ; \
	done )
headers_out:
	(if [ -d $(HDR_DIR) ] ; then cd $(HDR_DIR) ; rm -f $(HEADERS) ; fi)

libraries_in:
	@echo ""
	@echo installing libraries
	$(MKDIRS) $(LIB_DIR)
	@(cd Libraries ; \
	for x in $(LIBRARIES) none ; do \
	  if [ $$x = "none" ] ; then break; fi ; \
	  echo  $(CP) $$x $(LIB_DIR)/$$x ';' $(RANLIB) $(LIB_DIR)/$$x ; \
	 $(CP) $$x $(LIB_DIR)/$$x ; $(RANLIB) $(LIB_DIR)/$$x ; \
	done )
libraries_out:
	(if [ -d $(LIB_DIR) ] ; then cd $(LIB_DIR) ; rm -f $(LIBRARIES) ; fi)

palettes_in:
	@echo ""
	@echo installing palettes
	$(MKDIRS) $(PAL_DIR)
	@(cd Palettes ; \
	for x in $(PALETTES) none ; do \
	  if [ $$x = "none" ] ; then break; fi ; \
	  echo  $(TAR) cf - $$x '| (cd $(PAL_DIR) ; $(TAR) xf -)' ; \
	  $(TAR) cf - $$x | (cd $(PAL_DIR) ; $(TAR) xf -) ; \
	done )
palettes_out:
	(if [ -d $(PAL_DIR) ] ; then cd $(PAL_DIR) ; rm -rf $(PALETTES) ; fi)

examples_in:
	@echo ""
	@echo installing examples
	$(MKDIRS) $(EXM_DIR)
	@(cd Examples ; \
	for x in $(EXAMPLES) none ; do \
	  if [ $$x = "none" ] ; then break; fi ; \
	  echo  $(TAR) cf - $$x '| (cd $(EXM_DIR) ; $(TAR) xf -)' ; \
	  $(TAR) cf - $$x | (cd $(EXM_DIR) ; $(TAR) xf -) ; \
	done )
examples_out:
	(if [ -d $(EXM_DIR) ] ; then cd $(EXM_DIR) ; rm -rf $(EXAMPLES) ; fi)

directories_out:
	@echo ""
	@echo removing unneeded directories
	@(for x in $(REMOVABLE_DIRECTORIES) none ; do \
	  if [ $$x = "none" ] ; then break; fi ; \
	  echo  rmdir $$x ; \
	  rmdir $$x ; \
	done )

change_owners:
	$(CHOWN) -R $(OWNER) $(DOC_DIR)
	$(CHOWN) -R $(OWNER) $(HDR_DIR)
	$(CHOWN) -R $(OWNER) $(EXM_DIR)
	@(for x in $(PALETTES) none ; do \
	  if [ $$x = "none" ] ; then break; fi ; \
	  echo $(CHOWN) -R $(OWNER) $(PAL_DIR)/$$x; \
	  $(CHOWN) -R $(OWNER) $(PAL_DIR)/$$x.palette ; \
	done )
	@(for x in $(LIBRARIES) none ; do \
	  if [ $$x = "none" ] ; then break; fi ; \
	  echo $(CHOWN) -R $(OWNER) $(LIB_DIR)/$$x; \
	  $(CHOWN) -R $(OWNER) $(LIB_DIR)/$$x; \
	done )
	