#
# Typist v2.2 - improved typing tutor program for UNIX systems
# Copyright (C) 1998  Simon Baldwin (simonb@sco.com)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#
# Makefile for typist v2.2
#
# The following UNIX variants are available:
#
#   Linux: IBM PC running Linux.
#   OSR5:  IBM PC running SCO OpenServer release 5.
#   UW:    IBM PC running SCO UnixWare 7.
#

# C compiler, flags, targets and so on
# Linux values
CC          = gcc
CFLAGS      = -static -O -DLONG_OPTIONS
CURS_CFLAGS = -DNCURSES -I/usr/include/ncurses
CURS_LIBS   = -lncurses
MANCAT      = man1
T_MAN       = linux_manpages
T_INSTALL   = linux_install
T_UNINSTALL = linux_uninstall
T_DEFAULT   = Makefile typist_bin manpages install

# SCO OpenServer values
# CC          = cc
# CFLAGS      = -O
# CURS_CFLAGS =
# CURS_LIBS   = -lcurses
# MANCAT      = cat.LOCAL
# T_MAN       = nonlinux_manpages
# T_INSTALL   = nonlinux_install
# T_UNINSTALL = nonlinux_uninstall
# T_DEFAULT   = Makefile typist_bin manpages install

# SCO UnixWare 7 values
# CC          = cc
# CFLAGS      = -O
# CURS_CFLAGS =
# CURS_LIBS   = -lcurses
# MANCAT      = cat.LOCAL
# T_MAN       = nonlinux_manpages
# T_INSTALL   = nonlinux_install
# T_UNINSTALL = nonlinux_uninstall
# T_DEFAULT   = Makefile typist_bin manpages install

# C++ objects, and information for the installation
BINDIR    = /usr/local/bin
LIBDIR    = /usr/local/lib/typist
MANDIR    = /usr/local/man
OWNER     = root:root
MODE      = 755
DMODE     = 644
DATAFILES = combined.typ demo.typ \
		d.typ m.typ n.typ q.typ r.typ s.typ t.typ u.typ v.typ
DEF_FILE  = combined.typ

 
# default make target
default:	$(T_DEFAULT)

# do everything useful
all:	Makefile typist_bin manpages install demo

# rule to build the binary
typist_bin:	Makefile typist.c
	$(CC) $(CFLAGS) $(CURS_CFLAGS) -o typist_bin typist.c $(CURS_LIBS)

# build manpages in different formats
manpages:	$(T_MAN)

linux_manpages:	typist.1.ps typist.1.cat

typist.1.cat:	typist.1
	-man ./typist.1 >typist.1.cat

typist.1.ps:	typist.1
	-man -t ./typist.1 >|typist.1.ps

nonlinux_manpages:
	echo "Make for manpages not available for non-Linux platforms"

# install the shell wrapper, binary and man pages
install:	$(T_INSTALL)

linux_install:
	test -x typist_bin
	-mkdir -p $(BINDIR)
	-mkdir -p $(LIBDIR)
	-mkdir -p $(MANDIR)/$(MANCAT)
	cp typist $(BINDIR)
	chown $(OWNER) $(BINDIR)/typist
	chmod $(MODE) $(BINDIR)/typist
	cp typist_bin $(BINDIR)
	chown $(OWNER) $(BINDIR)/typist_bin
	chmod $(MODE) $(BINDIR)/typist_bin
	( cd lessons; cp $(DATAFILES) $(LIBDIR) )
	chown $(OWNER) $(LIBDIR)/*
	chmod $(DMODE) $(LIBDIR)/*
	ln -f $(LIBDIR)/$(DEF_FILE) $(LIBDIR)/typist.typ
	gzip -c typist.1 >$(MANDIR)/$(MANCAT)/typist.1.gz
	chown $(OWNER) $(MANDIR)/$(MANCAT)/typist.1.gz
	chmod $(MODE) $(MANDIR)/$(MANCAT)/typist.1.gz

nonlinux_install:
	-mkdir -p $(BINDIR)
	-mkdir -p $(LIBDIR)
	cp typist $(BINDIR)
	chown $(OWNER) $(BINDIR)/typist
	chmod $(MODE) $(BINDIR)/typist
	cp typist_bin $(BINDIR)
	chown $(OWNER) $(BINDIR)/typist_bin
	chmod $(MODE) $(BINDIR)/typist_bin
	( cd lessons; cp $(DATAFILES) $(LIBDIR) )
	chown $(OWNER) $(LIBDIR)/*
	chmod $(DMODE) $(LIBDIR)/*
	ln -f $(LIBDIR)/$(DEF_FILE) $(LIBDIR)/typist.typ

# run the demonstration
demo:	install
	$(BINDIR)/typist $(LIBDIR)/demo.typ

# uninstall the binaries and man pages
uninstall:	$(T_UNINSTALL)

linux_uninstall:
	-rm $(BINDIR)/typist
	-rm $(BINDIR)/typist_bin
	-rmdir $(BINDIR)
	-rm -rf $(LIBDIR)
	-rm $(MANDIR)/$(MANCAT)/typist.1.gz
	-rmdir $(MANDIR)/$(MANCAT)
	-rmdir $(MANDIR)

nonlinux_uninstall:
	-rm $(BINDIR)/typist
	-rm $(BINDIR)/typist_bin
	-rmdir $(BINDIR)
	-rm -rf $(LIBDIR)

# clear up for a rebuild
clean:	Makefile
	rm -f *.o typist_bin typist.1.cat typist.1.ps

# completely remove
clobber:	clean uninstall

