#
# prototype installation Makefile
#
# Copyright (C) 1999-2000, by
#
#   Carlo Wood, Run on IRC <carlo@alinoe.com>
#   RSA-1024 0x624ACAD5 1997-01-26                    Sign & Encrypt
#   Fingerprint16 = 32 EC A7 B6 AC DB 65 A6  F6 F6 55 DD 1C DC FF 61
#
# All rights reserved.
#
# See the file LICENSE for copyright information.
#
# This file may be distributed under the terms of the Q Public License 1.0
# as defined by Troll Tech AS of Norway and appearing in the file LICENSE.QPL
# included in the packaging of this file.
#

prefix=@prefix@
datadir=@datarootdir@
install=@INSTALL@

dirs=base main lib sub test templ-inst

export PROTODIR

.PHONY: all install uninstall test

all:
	@(if [ -z "$PROTODIR" -o "$(PROTODIR)" != "$(datadir)/prototype" ]; then \
	  echo "Read INSTALL and fix your environment variables."; \
	  echo; \
        fi )
	@echo "The following targets are supported:"
	@echo "	make install	: install this package."
	@echo "	make uninstall	: uninstall everything."
	@echo "	make test	: test succesful installation."

configure: configure.in
	autoconf

Makefile: Makefile.in configure
	./configure --prefix=$(prefix) --datadir=$(datadir)

install: Makefile
	@( if [ ! -w "$(datadir)" ]; then \
	  echo "You need root to instal in $(datadir)."; \
	  exit 1; \
	fi; \
	if [ ! -w "$(prefix)" ]; then \
	  echo "You need root to install in $(prefix)."; \
	  exit 1; \
	fi; \
	if [ -e "$(datadir)/prototype/Makefile" ]; then \
	  echo "Warning: You can't install prototype on top of itself!"; \
	  echo "Use a different install directory than `pwd`."; \
	  exit 1; \
	fi )
	$(install) -m 755 -d $(datadir)/prototype
	( for i in $(dirs); do \
	  $(install) -m 755 -d $(datadir)/prototype/$$i; \
	  $(install) -m 644 $$i/PTMakefile $(datadir)/prototype/$$i/PTMakefile; \
	  $(install) -m 644 $$i/Makefile $(datadir)/prototype/$$i/Makefile; \
	done )
	$(install) -m 755 -d $(datadir)/prototype/common
	$(install) -m 644 common/PTMakefile $(datadir)/prototype/common/PTMakefile
	$(install) -m 755 -d $(datadir)/prototype/maintainer
	$(install) -m 644 maintainer/PTmakefile $(datadir)/prototype/maintainer/PTmakefile
	$(install) -m 644 maintainer/makefile $(datadir)/prototype/maintainer/makefile
	$(install) -m 644 base/Makedefs.h $(datadir)/prototype/base/Makedefs.h
	$(install) -m 755 templ-inst/inst-all-templ $(datadir)/prototype/templ-inst/inst-all-templ
	$(install) -m 755 templ-inst/inst-templ $(datadir)/prototype/templ-inst/inst-templ
	( if [ -e Makedefs.h ]; then \
	  $(install) -m 644 Makedefs.h $(datadir)/prototype/Makedefs.h; \
        else \
	  $(install) -m 644 Makedefs.h.dist $(datadir)/prototype/Makedefs.h; \
	fi )
	$(install) -m 755 -d $(prefix)/bin
	$(install) -m 755 scripts/makeproto $(prefix)/bin/makeproto
	@echo
	@echo "Now run \`$(MAKE) test' to test the installation."

uninstall:
	@(if [ -f "$(datadir)/prototype/Makedefs.h" ]; then \
	  diff -c "Makedefs.h.dist" "$(datadir)/prototype/Makedefs.h"; \
	  if [ "$$?" = "1" ]; then \
	    cp "$(datadir)/prototype/Makedefs.h" /tmp/Makedefs.h; \
	    echo "A backup of \"$(datadir)/prototype/Makedefs.h\" has been written"; \
	    echo "to \"/tmp/Makedefs.h\""; \
	  fi; \
	fi)
	rm -rf $(datadir)/prototype $(prefix)/bin/makeproto

test:
	@( if [ -O "/" ]; then \
	  echo "Don't run the test as root please."; \
	  exit 0; \
	fi; \
	if [ -z "$(PROTODIR)" ]; then \
	  echo "Environment variable \$$PROTODIR not set."; \
	  exit 1; \
	fi; \
	if [ "$(PROTODIR)" != "$(datadir)/prototype" ]; then \
	  echo "Environment variable \$$PROTODIR not set correctly,"; \
	  echo "it must be set to \"$(datadir)/prototype\"."; \
	  exit 1; \
	fi; \
	if [ ! -d "$(PROTODIR)" -o ! -e "$(PROTODIR)/Makedefs.h" -o ! -e $(prefix)/bin/makeproto ]; then \
	  echo 'Package prototype not installed correctly.  Did you run `make install'"'"'?'; \
	  exit 1; \
	fi; \
	echo "Current date/time is : " `date`; \
	if [ -e /usr/bin/stat ]; then \
	  echo "Testing installation of" `/usr/bin/stat $(PROTODIR)/Makedefs.h | grep Modify | cut -d \  -f2-6 | sed -e 's/(.*$$//'`; \
	elif [ -e /usr/compat/linux/usr/bin/stat ]; then \
	  echo "Testing installation of" `/usr/compat/linux/usr/bin/stat $(PROTODIR)/Makedefs.h | grep Modify | cut -d \  -f2-6 | sed -e 's/(.*$$//'`; \
        else \
	  echo "Running test... (hopefully you did 'make install' before)"; \
	fi; \
	MAKE=$(MAKE) scripts/test > /dev/null; \
	)


syntax highlighted by Code2HTML, v. 0.9.1