
###############################################################################
#									      #
# 		 Makefile for UNIX Interactive Tools 4.2c		      #
# 	   Copyright (c) Tudor Hulubei & Andrei Pitis, May 1994	              #
#									      #
#				 Politechnic University of Bucharest	      #
#									      #
###############################################################################


#
#   If you make changes in this file in order to compile UIT on a system not
# included here please send me a patch (tudor@ulise.cs.pub.ro). I'll include
# it in the next release. Thanks.
#


#  HAVE_LINUX	===> 	running on Linux operating system
#  HAVE_CONST	===>	the C compiler supports the 'const' keyword
#  HAVE_STATFS	===>	the kernel supports the 'statfs()' system call

# For Linux systems: (actually tested with SLACKWARE Linux 1.2.0)
SYSTEM      =   LINUX
SYSCONFIG   =   -DHAVE_LINUX -DHAVE_CONST -DHAVE_STATFS

# For Ultrix systems: (actually tested with ULTRIX V4.2A)
# SYSTEM      =   ULTRIX
# SYSCONFIG   =   

# For HP-UX systems: (actually tested with HP-UX 9.x using gcc)
# SYSTEM      =   HP-UX
# SYSCONFIG   =   -D_XPG2 -DHAVE_CONST

#
# UIT default install directory. You may change this if you want to install
# the UIT package in a different place.
#
prefix      =   /usr/local
bindir      =   $(prefix)/bin
libdir      =   $(prefix)/lib
infodir     =   $(prefix)/info
mandir      =   $(prefix)/man
man1dir     =   $(mandir)/man1
docdir      =   $(prefix)/doc


CFLAGS	    =	-O2 $(SYSCONFIG)
LDFLAGS	    =


CC          =	cc
CPP         =	$(CC) -E $(SYSCONFIG)
LD          =	ld
STRIP       =	strip
LEX	    =	lex
CP	    =   cp
MV	    =   mv
RM	    =   rm -f
LN	    =   ln
MKDIR	    =   mkdir
CHMOD       =   chmod
SED	    =   sed
NROFF	    =	nroff
MAKEINFO    =   makeinfo


UITOBJS     =	tty.o window.o edit.o status.o panel.o uit.o config.o\
		fnmatch.o termcap.o

UITCMPOBJS  =	uitcmp.o

UITPSOBJS   =	tty.o window.o config.o termcap.o uitps.o
UITVIEWOBJS =	tty.o window.o config.o termcap.o uitview.o


all:            allmsg uit uitps uitview\
		uitcmp uitdone uitps.c uitcmp.c\
		window.c tty.c edit.c status.c panel.c uit.c config.c\
		fnmatch.c termcap.l

allmsg:
		@echo   "Making UNIX Interactive Tools 4.2c ..."
		@echo   "Target system:" $(SYSTEM)

man:
		@echo   "Formatting the UNIX Interactive Tools 4.2c manual page ..."
		@echo   "Target system:" $(SYSTEM)
		@echo   "WARNING: this will fail if your system doesn't have the nroff utility !"
		@echo	"The file uit.1 contains a pre-formatted version of the manual page."
		@echo	"(just in case ...)"
		@$(NROFF) -man uit.man > uit.man.1
		@echo	"UIT 4.2c manual page successfully formatted."
		@echo	"The new manual page was put in the file uit.man.1, preserving the"
		@echo	"original pre-formatted version, uit.1."
		@echo	"done."

info:
		@echo   "Compiling the UNIX Interactive Tools 4.2c info documentation ..."
		@echo   "Target system:" $(SYSTEM)
		@echo   "WARNING: this will fail if your system doesn't have the makeinfo utility !"
		@echo	"The file uit.info.1 contains a pre-compiled version of the info documentation."
		@echo	"(just in case ...)"
		@$(MAKEINFO) uit.texi
		@echo	"UIT 4.2c info documentation successfully compiled."
		@echo	"done."

.l.c:
		@echo	"Generating termcap.c from" $*.l "... "
		@$(LEX) $*.l
		@$(MV) 	lex.yy.c termcap.c

.c.o:
		@echo  "Compiling" $*.c "... "
		@$(CC) -c $(CFLAGS) $*.c

uit:		$(UITOBJS)
		@echo  "Linking uit ... "
		@$(CC) -o uit $(UITOBJS) $(LDFLAGS)

		@echo "Stripping uit ... "
		@$(STRIP) uit

uitps:		$(UITPSOBJS)
		@echo  "Linking uitps ... "
		@$(CC) -o uitps $(UITPSOBJS) $(LDFLAGS)

		@echo "Stripping uitps ... "
		@$(STRIP) uitps

uitview:	$(UITVIEWOBJS)
		@echo  "Linking uitview ... "
		@$(CC) -o uitview $(UITVIEWOBJS) $(LDFLAGS)

		@echo "Stripping uitview ... "
		@$(STRIP) uitview

uitcmp:		$(UITCMPOBJS)
		@echo  "Linking uitcmp ... "
		@$(CC) -o uitcmp $(UITCMPOBJS) $(LDFLAGS)

		@echo "Stripping uitcmp ... "
		@$(STRIP) uitcmp

uitdone:
		@$(RM) termcap.c
		@echo  "Please configure the .uitrc.TERM [Setup] section !"
		@echo  "done."

install:
		@echo "Installing UIT 4.2c ..."
		@echo "Target system:" $(SYSTEM)
#
		@(for i in $(prefix) $(bindir) $(libdir) $(infodir) $(mandir) $(man1dir) $(docdir);\
		do\
		    if [ ! -d $$i ];\
		    then\
			echo "Creating directory" $$i "... ";\
			$(MKDIR) $$i;\
			$(CHMOD) 755 $$i;\
		    fi;\
		done)
#
		@(for i in uit uitps uitview uitcmp uitmount;\
		do\
		    $(RM) $(bindir)/$$i;\
		    if [ -f $(bindir)/$$i ];\
		    then\
			echo "Can't remove the old version of" $(bindir)/$$i ".";\
			echo "The executable is probably busy.";\
			echo "Try later or terminate all the instances of" $(bindir)/$$i ".";\
			exit 1;\
		    fi;\
		    echo "Copying" $$i "to" $(bindir) "... ";\
		    $(CP) $$i $(bindir);\
		    $(CHMOD) 755 $(bindir)/$$i;\
		done)
#
		@if [ -f uit.man.1 ];\
		then\
		    echo  "Copying" uit.man.1 "to" $(man1dir) "... ";\
		    $(CP) uit.man.1 $(man1dir)/uit.1;\
		else\
		    echo "Manual page not build. Installing the pre-formated version ...";\
		    echo "Copying" uit.1 "to" $(man1dir) "... ";\
		    $(CP) uit.1 $(man1dir);\
		fi
#
		@$(CHMOD) 644 $(man1dir)/uit.1
#
		@(for i in uitps.1 uitview.1 uitcmp.1 uitmount.1;\
		do\
		    $(RM) $(man1dir)/$$i;\
		    if [ -f $(man1dir)/$$i ];\
		    then\
			echo "Can't remove the old version of" $(man1dir)/$$i ".";\
			exit 1;\
		    fi;\
		    echo "Linking" $(man1dir)/uit.1 "to" $(man1dir)/$$i "... ";\
		    $(LN) $(man1dir)/uit.1 $(man1dir)/$$i;\
		done)
#
		@if [ -f uit.info ];\
		then\
		    echo  "Copying uit.info to" $(infodir) "... ";\
		    $(CP) uit.info $(infodir);\
		else\
		    echo "Info documentation not build. Installing the pre-compiled version ...";\
		    echo "Copying" uit.info.1 "to" $(infodir) "... ";\
		    $(CP) uit.info.1 $(infodir)/uit.info;\
		fi
#
		@$(CHMOD) 644 $(infodir)/uit.info;\
#
		@echo "Copying uit.doc to" $(docdir) "... "
#
		@$(CP) uit.doc $(docdir)
		@$(CHMOD) 644 $(docdir)/uit.doc
#
		@(for i in .uitrc.console .uitrc.vt100 .uitrc.vt102 .uitrc.xterm .uittermcap;\
		do\
		    echo "Copying" $$i "to" $(libdir) "... ";\
		    $(CP) $$i $(libdir);\
		    $(CHMOD) 644 $(libdir)/$$i;\
		done)
#
		@echo
		@echo "************************************ WARNINGS *********************************"
		@echo "1 - The file uit.dir should be appended to the file" $(infodir)/dir "."
		@if [ ! -f $(infodir)/dir ];\
		then\
		    echo "!!!!!!!!!!  BTW, I can't find your" $(infodir)/dir "!!!!!!!!!!";\
		fi
#
		@echo "2 -" $(bindir) "should be in the PATH in order to run UIT !"
		@echo "3 -" $(mandir) "should be in the MANPATH in order to read the manual page !"
#
		@echo "4 - Each user should copy .uitrc.TERM and .uittermcap in its home directory."
		@echo "    The files .uitrc.TERM can be found in the directory" $(libdir) "."
		@echo "*******************************************************************************"
#
		@echo
		@echo "done."

dep:
		@echo 	"Making dependencies ... "
		@$(SED)	'/\#\#\# Dependencies/q' <Makefile >tmp_make
		@(for i in *.c; do $(CPP) -MM $$i; done) >>tmp_make
		@$(MV) 	tmp_make Makefile
		@echo 	"done."

clean:
		@echo	"Cleaning ... "
		@$(RM) 	*.o *~ termcap.c core* uitps uitview uitcmp uit
		@$(RM)	uit.man.1 uit.info
		@echo 	"done."

### Dependencies
config.o  : config.c tty.h termcap.h config.h
edit.o    : edit.c tty.h termcap.h window.h edit.h config.h
fnmatch.o : fnmatch.c fnmatch.h
panel.o   : panel.c tty.h termcap.h window.h status.h config.h panel.h edit.h fnmatch.h
status.o  : status.c tty.h termcap.h window.h status.h config.h
tty.o     : tty.c tty.h termcap.h
uit.o     : uit.c tty.h termcap.h window.h edit.h config.h status.h panel.h
uitcmp.o  : uitcmp.c
uitps.o   : uitps.c tty.h termcap.h window.h config.h
uitview.o : uitview.c tty.h termcap.h window.h config.h
window.o  : window.c tty.h termcap.h window.h
