
###############################################################################
#									      #
# 		 Makefile for UNIX Interactive Tools 4.3.1		      #
# 	   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_ULTRIX	===>	running on Ultrix operating system
#  HAVE_HPUX	===>	running on HP-UX operating system
#  HAVE_OSF1	===>	running on OSF/1 operating system
#  HAVE_SUNOS	===>	running on SunOS operating system
#  HAVE_SYSTEMV	===>	running on System V operating system

#  HAVE_CONST	===>	the C compiler supports the 'const' keyword
#  HAVE_STATFS	===>	the kernel supports the 'statfs()' system call

#  USE_TERMCAP	===>	compile/link using the termcap library
#  USE_TERMINFO	===>	compile/link using the terminfo library


#
# Note: replace -DUSE_TERMCAP with -DUSE_TERMINFO if you want to use
# terminfo instead of termcap. Use the appropriate SYSLDFLAG line.
#


# For Linux systems: (actually tested with SLACKWARE Linux 1.2.0 / 2.0.0)

SYSTEM       =   Linux
SYSCFLAGS    =   -DHAVE_LINUX -DHAVE_CONST -DHAVE_STATFS -DUSE_TERMCAP
SYSLDFLAGS   =   -ltermcap    # if USE_TERMCAP  is defined (default)
# SYSLDFLAGS   =   -lncurses    # if USE_TERMINFO is defined
FNMATCHOBJ   =                # Linux has fnmatch() in the C library
ALLOCAOBJ    =                # Linux (gcc) supports alloca()


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

# SYSTEM       =   Ultrix
# SYSCFLAGS    =   -DHAVE_ULTRIX -Olimit 1000 -DUSE_TERMCAP
# SYSLDFLAGS   =   -ltermcap    # if USE_TERMCAP  is defined (default)
# SYSLDFLAGS   =   -lcurses     # if USE_TERMINFO is defined
# FNMATCHOBJ   =   fnmatch.o    # we need fnmatch() under ULTRIX
# ALLOCAOBJ    =                # Ultrix supports alloca()


# For DEC OSF/1 systems: (actually tested with DEC OSF/1 2.0)

# SYSTEM       =   OSF1
# SYSCFLAGS    =   -DHAVE_OSF1 -Olimit 1000 -DUSE_TERMCAP
# SYSLDFLAGS   =   -ltermcap    # if USE_TERMCAP  is defined (default)
# SYSLDFLAGS   =   -lcurses     # if USE_TERMINFO is defined
# FNMATCHOBJ   =                # DEC OSF/1 has fnmatch() in the C library
# ALLOCAOBJ    =                # DEC OSF/1 supports alloca()


# For HP-UX systems: (actually tested with HP-UX 9.x using gcc)

# SYSTEM       =   HP-UX
# SYSCFLAGS    =   -DHAVE_HPUX -DHAVE_CONST -DUSE_TERMINFO
# SYSLDFLAGS   =   -ltermcap    # if USE_TERMCAP  is defined
# SYSLDFLAGS   =   -lcurses     # if USE_TERMINFO is defined (default)
# FNMATCHOBJ   =                # HP-UX has fnmatch() in the C library
# ALLOCAOBJ    =                # HP-UX supports alloca()


# For SunOS systems: (actually not tested)

# SYSTEM       =   SunOS
# SYSCFLAGS    =   -DHAVE_SUNOS -DUSE_TERMCAP
# SYSLDFLAGS   =   -ltermcap    # if USE_TERMCAP  is defined (default)
# SYSLDFLAGS   =   -lcurses     # if USE_TERMINFO is defined
# FNMATCHOBJ   =   fnmatch.o    # I don't know if we need fnmatch() on SunOS
# ALLOCAOBJ    =                # SunOS supports alloca() (not tested) 


# For SYSTEM V systems: (actually not tested)

# SYSTEM       =   System V
# SYSCFLAGS    =   -DHAVE_SYSTEMV -DUSG -DHAVE_CONST -DUSE_TERMINFO
# SYSLDFLAGS   =   -lcurses
# FNMATCHOBJ   =   fnmatch.o    # I don't know if we need fnmatch() on SYSTEM V
# ALLOCAOBJ    =   alloca.o     # I don't know if alloca() works on System V


#
# 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 $(SYSCFLAGS) -DLIB_DIRECTORY=\"$(libdir)\"
LDFLAGS	     =  $(SYSLDFLAGS)

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

CC           =  cc
CPP          =  $(CC) -E $(SYSCFLAGS)
LD           =  ld
STRIP        =  strip
CP	     =  cp
MV	     =  mv
RM	     =  rm -f
LN	     =  ln
MKDIR	     =  mkdir
CHMOD        =  chmod
SED	     =  sed
NROFF	     =  nroff -man
MAKEINFO     =  makeinfo
TAR	     =  tar
GZIP	     =  gzip
PWD	     =  pwd
BASENAME     =  basename
SHELL	     =  /bin/sh


UITVERSION   =  4.3.1
UITOBJS      =	tty.o window.o edit.o status.o panel.o uit.o config.o misc.o\
		signals.o history.o tilde.o xmalloc.o
UITCMPOBJS   =	uitcmp.o
UITMATCHOBJS =  uitmatch.o
UITKEYSOBJS  =  uitkeys.o
UITPSOBJS    =	tty.o window.o config.o uitps.o misc.o tilde.o xmalloc.o
UITVIEWOBJS  =	tty.o window.o config.o uitview.o misc.o tilde.o xmalloc.o
UITBINS      =  uit uitps uitview uitcmp uitkeys uitmatch
UITSCRIPTS   =  uitmount uitaction
UITMANUALS   =  uit.man.1 uitmatch.man.1 uitaction.man.1 uitmount.man.1\
		uitcmp.man.1 uitkeys.man.1
UITFMANUALS  =  uit.1 uitmatch.1 uitaction.1 uitmount.1	uitcmp.1 uitkeys.1
UITINFO      =  uit.info
UITCINFO     =  uit.info.1 
UITCONFIGS   =  .uitrc.console .uitrc.vt100 .uitrc.vt102\
		.uitrc.xterm .uitrc.hpterm .uitaction


all:            allmsg $(UITBINS) alldone

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

man:		manmsg  $(UITMANUALS) mandone

manmsg:
		@(\
		    echo "Formatting the UNIX Interactive Tools" $(UITVERSION) "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/uitps/uitview manual page ...";\
		    $(NROFF) uit.man > uit.man.1;\
		    if [ $$? != 0 ];\
		    then\
			$(RM) uit.man.1;\
			exit 1;\
		    else\
			exit 0;\
		    fi\
		)

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

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

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

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

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

mandone:
		@(\
		    echo "Manual pages successfully formatted.";\
		    echo "The new manual pages have been formatted as uit*.man.1, preserving the";\
		    echo "original pre-formatted versions, uit*.1.";\
		    echo "done.";\
		)

info:		infomsg $(UITINFO) infodone

infomsg:	
		@(\
		    echo "Compiling the UNIX Interactive Tools" $(UITVERSION) "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;\
		    else\
			exit 0;\
		    fi\
		)

infodone:
		@(\
		    echo "Info documentation successfully compiled.";\
		    echo "done.";\
		)

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

uit:		$(UITOBJS) $(FNMATCHOBJ) $(ALLOCAOBJ)
		@(\
		    echo "Linking uit ...";\
		    $(CC) -o uit $(UITOBJS) $(FNMATCHOBJ) $(ALLOCAOBJ) $(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;\
		)

uitkeys:	$(UITKEYSOBJS)
		@(\
		    echo  "Linking uitkeys ...";\
		    $(CC) -o uitkeys $(UITKEYSOBJS) $(LDFLAGS);\
		    echo "Stripping uitkeys ...";\
		    $(STRIP) uitkeys;\
		)

uitmatch:	$(UITMATCHOBJS) $(FNMATCHOBJ)
		@(\
		    echo  "Linking uitmatch ...";\
		    $(CC) -o uitmatch $(UITMATCHOBJS) $(FNMATCHOBJ) $(LDFLAGS);\
		    echo "Stripping uitmatch ...";\
		    $(STRIP) uitmatch;\
		)

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

install:
		@(\
		    echo "Installing UNIX Interactive Tools" $(UITVERSION) "...";\
		    echo "Target system:" $(SYSTEM);\
		    \
		    for i in $(prefix) $(bindir) $(libdir) $(infodir)\
			     $(mandir) $(man1dir);\
		    do\
			if [ ! -d $$i ];\
			then\
			    echo "Creating directory" $$i "...";\
				$(MKDIR) $$i;\
				if [ $$? != 0 ];\
				then\
				    exit 1;\
				fi;\
				$(CHMOD) 755 $$i;\
				if [ $$? != 0 ];\
				then\
				    exit 1;\
				fi;\
		        fi;\
		    done;\
		    \
		    for i in $(UITBINS) $(UITSCRIPTS);\
		    do\
			$(RM) $(bindir)/$$i;\
			if [ $$? != 0 ];\
			then\
			    exit 1;\
			fi;\
			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);\
			if [ $$? != 0 ];\
			then\
			    exit 1;\
			fi;\
			$(CHMOD) 755 $(bindir)/$$i;\
			if [ $$? != 0 ];\
			then\
			    exit 1;\
			fi;\
			done;\
		    \
		    for i in $(UITFMANUALS) uitps.1 uitview.1;\
		    do\
			$(RM) $(man1dir)/$$i;\
			if [ $$? != 0 ];\
			then\
			    exit 1;\
			fi;\
			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 uitkeys;\
		    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);\
			    if [ $$? != 0 ];\
			    then\
				exit 1;\
			    fi;\
			fi;\
			$(CHMOD) 644 $(man1dir)/$$i.1;\
			if [ $$? != 0 ];\
			then\
			    exit 1;\
			fi;\
		    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;\
			if [ $$? != 0 ];\
			then\
			    exit 1;\
			fi;\
		    done;\
		    \
		    if [ -f uit.info ];\
		    then\
			echo  "Copying uit.info to" $(infodir) "...";\
			$(CP) uit.info $(infodir);\
			if [ $$? != 0 ];\
			then\
			    exit 1;\
			fi;\
		    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;\
			if [ $$? != 0 ];\
			then\
			    exit 1;\
			fi;\
		    fi;\
		    \
		    $(CHMOD) 644 $(infodir)/uit.info;\
		    if [ $$? != 0 ];\
		    then\
			exit 1;\
		    fi;\
		    \
		    for i in $(UITCONFIGS);\
		    do\
			echo "Copying" $$i "to" $(libdir) "...";\
			$(CP) $$i $(libdir);\
			if [ $$? != 0 ];\
			then\
			    exit 1;\
		        fi;\
			$(CHMOD) 644 $(libdir)/$$i;\
			if [ $$? != 0 ];\
			then\
			    exit 1;\
		        fi;\
		    done;\
		    \
		    echo ;\
		    echo "************************************* HINTS ***********************************";\
		    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 can copy .uitrc.TERM 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 .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.";\
		)

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

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

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

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

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

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

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

distmsg:		
		@(\
		    echo "Making UNIX Interactive Tools" $(UITVERSION) "distribution package ...";\
		)

distdone:
		@(\
		    dir=`$(PWD)`;\
		    echo "Building the compressed archive" `$(BASENAME) $$dir`.tar.gz "...";\
		    cd ..;\
		    $(TAR) cf - `$(BASENAME) $$dir` | $(GZIP) -9c > `$(BASENAME) $$dir`.tar.gz;\
		    if [ $$? != 0 ];\
		    then\
			exit 1;\
		    fi;\
		    echo "done.";\
		)

dist:		distmsg $(UITFMANUALS) $(UITCINFO) clean distdone

uninstall:
		@(\
		    echo "Uninstalling the UNIX Interactive Tools" $(UITVERSION) "...";\
		    \
		    echo "Removing binaries ...";\
		    cd $(bindir);\
		    $(RM) $(UITBINS) $(UITSCRIPTS);\
		)
		@(\
		    echo "Removing configuration files ...";\
		    cd $(libdir);\
		    $(RM) $(UITCONFIGS);\
		)
		@(\
		    echo "Removing manuals ...";\
		    cd $(man1dir);\
		    $(RM) $(UITFMANUALS);\
		)
		@(\
		    echo "Removing the info documentation ...";\
		    cd $(infodir);\
		    $(RM) $(UITINFO);\
		    \
		    echo "Please remove the UIT entry from the Info dir file.";\
		    echo "done.";\
		)

clean:
		@(\
		    echo  "Cleaning ...";\
		    $(RM) *.o *~ core* $(UITBINS);\
		    $(RM) $(UITMANUALS) $(UITINFO);\
		    echo "done.";\
		)


### Dependencies
alloca.o   : alloca.c
config.o   : config.c tty.h config.h misc.h
edit.o     : edit.c xmalloc.h config.h history.h tty.h window.h edit.h tilde.h misc.h
fnmatch.o  : fnmatch.c fnmatch.h
history.o  : history.c xmalloc.h history.h
misc.o     : misc.c xmalloc.h config.h misc.h
panel.o    : panel.c xmalloc.h window.h status.h tty.h panel.h edit.h fnmatch.h config.h misc.h
signals.o  : signals.c signals.h edit.h window.h tty.h misc.h
status.o   : status.c tty.h xmalloc.h window.h status.h config.h misc.h
tilde.o    : tilde.c xmalloc.h
tty.o      : tty.c xmalloc.h tty.h misc.h
uit.o      : uit.c xmalloc.h tty.h window.h edit.h status.h panel.h config.h signals.h tilde.h misc.h
uitcmp.o   : uitcmp.c
uitkeys.o  : uitkeys.c
uitmatch.o : uitmatch.c fnmatch.h
uitps.o    : uitps.c xmalloc.h tty.h window.h config.h tilde.h misc.h
uitview.o  : uitview.c xmalloc.h tty.h window.h config.h tilde.h misc.h
window.o   : window.c xmalloc.h tty.h window.h
xmalloc.o  : xmalloc.c xmalloc.h
