#
# Typist v2.0 - 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.0
#
# 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
CPP         = g++
CFLAGS      = -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 c_typist manpages install

# SCO OpenServer values
# CC          = cc
# CPP         = 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 c_typist manpages install

# SCO UnixWare 7 values
# CC          = cc
# CPP         = 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 c_typist 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 = d.typ m.typ n.typ q.typ r.typ s.typ t.typ u.typ v.typ \
            combined.typ demo.typ
DEF_FILE  = combined.typ

 
# default make target
default:	$(T_DEFAULT)

# do everything useful
all:	Makefile c_typist cpp_typist manpages install demo

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

# rules to build the C++ binary
curses.o:	curses.cpp curses.h
	$(CPP) -c $(CFLAGS) $(CURS_CFLAGS) curses.cpp

getopts.o:	getopts.cpp getopts.h
	$(CPP) -c $(CFLAGS) getopts.cpp

label.o:	label.cpp lesson.h lessonf.h label.h
	$(CPP) -c $(CFLAGS) label.cpp

lesson.o:	lesson.cpp lesson.h
	$(CPP) -c $(CFLAGS) lesson.cpp

lessonf.o:	lessonf.cpp lesson.h lessonf.h
	$(CPP) -c $(CFLAGS) lessonf.cpp

interp.o:	interp.cpp curses.h lesson.h lessonf.h label.h interp.h
	$(CPP) -c $(CFLAGS) interp.cpp

main.o:		main.cpp getopts.h curses.h lesson.h lessonf.h label.h interp.h
	$(CPP) -c $(CFLAGS) main.cpp

cpp_typist:	curses.o getopts.o label.o lesson.o lessonf.o interp.o main.o
	$(CPP) -o cpp_typist main.o getopts.o curses.o label.o lesson.o \
			lessonf.o interp.o $(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 binaries and man pages
install:	$(T_INSTALL)

linux_install:
	test -x c_typist -o -x cpp_typist
	-mkdir -p $(BINDIR)
	-mkdir -p $(LIBDIR)
	-mkdir -p $(MANDIR)/$(MANCAT)
	-[ -f c_typist ] && cp c_typist $(BINDIR)
	-[ -f c_typist ] && chown $(OWNER) $(BINDIR)/c_typist
	-[ -f c_typist ] && chmod $(MODE) $(BINDIR)/c_typist
	-[ -f cpp_typist ] && cp cpp_typist $(BINDIR)
	-[ -f cpp_typist ] && chown $(OWNER) $(BINDIR)/cpp_typist
	-[ -f cpp_typist ] && chmod $(MODE) $(BINDIR)/cpp_typist
	-[ -x $(BINDIR)/c_typist ] && \
			ln -f $(BINDIR)/c_typist $(BINDIR)/typist
	-[ -x $(BINDIR)/cpp_typist ] && \
			ln -f $(BINDIR)/cpp_typist $(BINDIR)/typist
	( 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:
	test -x c_typist -o -x cpp_typist
	-mkdir -p $(BINDIR)
	-mkdir -p $(LIBDIR)
	-[ -f c_typist ] && cp c_typist $(BINDIR)
	-[ -f c_typist ] && chown $(OWNER) $(BINDIR)/c_typist
	-[ -f c_typist ] && chmod $(MODE) $(BINDIR)/c_typist
	-[ -f cpp_typist ] && cp cpp_typist $(BINDIR)
	-[ -f cpp_typist ] && chown $(OWNER) $(BINDIR)/cpp_typist
	-[ -f cpp_typist ] && chmod $(MODE) $(BINDIR)/cpp_typist
	-[ -x $(BINDIR)/c_typist ] && \
			ln -f $(BINDIR)/c_typist $(BINDIR)/typist
	-[ -x $(BINDIR)/cpp_typist ] && \
			ln -f $(BINDIR)/cpp_typist $(BINDIR)/typist
	( 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 $(BINDIR)/c_typist $(BINDIR)/cpp_typist
	-rmdir $(BINDIR)
	-rm -rf $(LIBDIR)
	-rm $(MANDIR)/$(MANCAT)/typist.1.gz
	-rmdir $(MANDIR)/$(MANCAT)
	-rmdir $(MANDIR)

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

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

# completely remove
clobber:	clean uninstall

