
###############################################################################
#									      #
# 		 Makefile for UNIX Interactive Tools 4.3		      #
# 	   Copyright (c) 1993, 1994 Tudor Hulubei & Andrei Pitis              #
#									      #
#				 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    =   -Olimit 1000

# For DEC OSF/1 systems: (actually tested with DEC OSF/1 2.0)
# SYSTEM       =   OSF1
# SYSCONFIG    =   -Olimit 1000

# 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


CFLAGS	     =	-O2 $(SYSCONFIG)
LDFLAGS	     =

#
# If you want to use gcc instead of cc or flex instead of lex,
# just change here.
#

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
SHELL	     =  /bin/sh


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

UITCMPOBJS   =	uitcmp.o
UITMATCHOBJS =  fnmatch.o uitmatch.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 uitmatch alldone

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

man:		manmsg uit.man.1 uitmatch.man.1 uitaction.man.1 uitmount.man.1\
		uitcmp.man.1 mandone

manmsg:
		@echo   "Formatting the UNIX Interactive Tools 4.3 manual pages ..."
		@echo   "Target system:" $(SYSTEM)
		@echo   "WARNING: this will fail if your system doesn't have the nroff utility !"
		@echo	"The files uit*.1 contains the pre-formatted versions of the manual pages."
		@echo	"(just in case ...)"

uit.man.1:	uit.man
		@echo	"Formatting the uit manual page ..."
		@(\
		    $(NROFF) -man uit.man > uit.man.1;\
		    if [ $$? != 0 ];\
		    then\
			$(RM) uit.man.1;\
			exit 1;\
		    fi\
		)

uitmatch.man.1:	uitmatch.man
		@echo	"Formatting the uitmatch manual page ..."
		@(\
		    $(NROFF) -man uitmatch.man > uitmatch.man.1;\
		    if [ $$? != 0 ];\
		    then\
			$(RM) uitmatch.man.1;\
			exit 1;\
		    fi\
		)

uitaction.man.1:	uitaction.man
		@echo	"Formatting the uitaction manual page ..."
		@(\
		    $(NROFF) -man uitaction.man > uitaction.man.1;\
		    if [ $$? != 0 ];\
		    then\
			$(RM) uitaction.man.1;\
			exit 1;\
		    fi\
		)

uitmount.man.1:	uitmount.man
		@echo	"Formatting the uitmount manual page ..."
		@(\
		    $(NROFF) -man uitmount.man > uitmount.man.1;\
		    if [ $$? != 0 ];\
		    then\
			$(RM) uitmount.man.1;\
			exit 1;\
		    fi\
		)

uitcmp.man.1:	uitcmp.man
		@echo	"Formatting the uitcmp manual page ..."
		@(\
		    $(NROFF) -man uitcmp.man > uitcmp.man.1;\
		    if [ $$? != 0 ];\
		    then\
			$(RM) uitcmp.man.1;\
			exit 1;\
		    fi\
		)

mandone:
		@echo	"UIT 4.3 manual pages successfully formatted."
		@echo	"The new manual pages where put in the files uit*.man.1, preserving the"
		@echo	"original pre-formatted versions, uit*.1."
		@echo	"done."

info:		infomsg uit.info infodone

infomsg:	
		@echo   "Compiling the UNIX Interactive Tools 4.3 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 ...)"

uit.info:	uit.texi
		@(\
		    $(MAKEINFO) uit.texi;\
		    if [ $$? != 0 ];\
		    then\
			$(RM) uit.info;\
			exit 1;\
		    fi\
		)

infodone:
		@echo	"UIT 4.3 info documentation successfully compiled."
		@echo	"done."

termcap.c:	termcap.l termcap.h
		@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

uitmatch:	$(UITMATCHOBJS)
		@echo  "Linking uitmatch ... "
		@$(CC) -o uitmatch $(UITMATCHOBJS) $(LDFLAGS)

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

alldone:
		@echo  "Please configure the .uitrc.TERM [Setup] section !"
		@echo  "done."

install:
		@echo "Installing UIT 4.3 ..."
		@echo "Target system:" $(SYSTEM)
#
		@(for i in $(prefix) $(bindir) $(libdir) $(infodir)\
			   $(mandir) $(man1dir);\
		do\
		    if [ ! -d $$i ];\
		    then\
			echo "Creating directory" $$i "... ";\
			$(MKDIR) $$i;\
			$(CHMOD) 755 $$i;\
		    fi;\
		done)
#
		@(for i in uit uitps uitview uitcmp uitmatch\
			   uitmount uitaction;\
		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)
#
		@(for i in uit.1 uitps.1 uitview.1 uitcmp.1 uitmount.1\
			   uitmatch.1 uitaction.1;\
		do\
		    $(RM) $(man1dir)/$$i;\
		    if [ -f $(man1dir)/$$i ];\
		    then\
			echo "Can't remove the old version of" $(man1dir)/$$i ".";\
			exit 1;\
		    fi;\
		done)
#
		@(for i in uit uitmatch uitaction uitmount uitcmp;\
		do\
		    if [ -f $$i.man.1 ];\
		    then\
			echo  "Copying" $$i.man.1 "to" $(man1dir) "... ";\
			$(CP) $$i.man.1 $(man1dir)/$$i.1;\
		    else\
			echo $$i "manual page not build. Installing the pre-formated version ...";\
			echo "Copying" $$i.1 "to" $(man1dir) "... ";\
			$(CP) $$i.1 $(man1dir);\
		    fi;\
		    $(CHMOD) 644 $(man1dir)/$$i.1;\
		done)
#
		@(for i in uitps.1 uitview.1;\
		do\
		    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;\
#
		@(for i in .uitrc.console .uitrc.vt100 .uitrc.vt102\
			   .uitrc.xterm .uittermcap .uitaction;\
		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 uit.dir ];\
		then\
		    echo "***************  BTW, I can't find your uit.dir file !";\
		fi
		@if [ ! -f $(infodir)/dir ];\
		then\
		    echo "***************  BTW, I can't find your" $(infodir)/dir "file !";\
		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 "5 - In order to use a local .uitaction script you should copy the .uitaction"
		@echo "    example in the current directory and then modify it."
		@echo "    The file .uitaction example 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 uitmatch uit
		@$(RM)	uit.man.1 uitcmp.man.1 uitmatch.man.1 uitmount.man.1
		@$(RM)  uitaction.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
uitmatch.o : uitmatch.c fnmatch.h
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
