#!/bin/sh

# $Id: makeMakefile,v 1.68 1997/04/17 19:24:25 svein Exp $

# IMPORTANT: Make is picky about tab stops. Every continuation line in a
#            rule must start with a tab stop.

#############################################################################
#
# Preprocessing
#
#############################################################################

prog=`basename $0`

tmpHosttype=""; help=0
while test "$#" -gt 0
do
	case $1 in
	-p)
		if test $# -le 1; then
		  echo "Argument missing for option $1." 1>&2; help=1; break
		fi
		shift
		tmpHosttype="$1"
		;;
	-h|-help)
		help=1; break
		;;
	-x)
		if test $# -le 1; then
		  echo "Argument missing for option $1." 1>&2; help=1; break
		fi
		shift
		XITE_HOME=$1
		;;
   	*)
		echo "Unknown argument $1." 1>&2;
		help=1; break
		;;
	esac
	shift
done

if test -z "$XITE_HOME"
then
  echo "$prog: XITE home directory is not known." 1>&2
  echo "Aborting $prog." 1>&2
  help=1
fi

if test "$help" -eq 1
then
  echo "usage: $prog [-x <XITE home-directory>] [-p <platform>] [-h(elp)]" 1>&2
  echo "       where default <platform> is the one you're using now" 1>&2
  echo "       and default XITE home-directory is given by the" 1>&2
  echo "       environment variable XITE_HOME." 1>&2
  exit 1
fi

utildir=$XITE_HOME/etc/.install
getPlatform=$utildir/getPlatform

if test -z "$tmpHosttype" -a -n "$XITE_HOSTTYPE"
then
	tmpHosttype=$XITE_HOSTTYPE
fi

XITE_HOSTTYPE=`$getPlatform "$tmpHosttype" "$utildir" stderr`

#############################################################################
#
# Start to generate Makefile.
#
#############################################################################

echo "# Makefile for XITE software, $XITE_HOSTTYPE"

cat <<\EOF_START
#
######################################################################
# Customization:
#
# You may want to change the definitions of
#     1) CC
#     2) X_INC_DIR
#     3) X_LIB_DIR
#     4) XITE_BIN_DEST
#     5) XITE_LIB_DEST
#     6) XITE_INC_DEST
#     7) XITE_MAN_DEST
#     8) XITE_DOC_DEST
#     9) CFLAGS
#    10) LFLAGS
#    11) XLIB
#    12) MATLAB_INC
#    13) MATLAB_LIB
#    14) MATLAB_MEX_DEST
#    15) TIFF_INC_DIR
#    16) TIFF_LIB_DIR
#    17) PNM_INC_DIR
#    18) PNM_LIB_DIR
#    19) FWF_INC_DIR
#    20) FWF_LIB_DIR
#    21) XPM_INC_DIR
#    22) XPM_LIB_DIR
# to reflect your particular needs.
######################################################################

.SUFFIXES:
.SUFFIXES: .dummy

SHELL = /bin/sh
EOF_START

echo "XITE_HOSTTYPE = $XITE_HOSTTYPE"

#############################################################################
#
# CC, X_INC_DIR, X_LIB_DIR, XITE_BIN_DEST, XITE_LIB_DEST, XITE_MAN_DEST,
# XITE_DOC_DEST, DEBUG
#
#############################################################################

cat <<\EOF_CC

# 1) Set CC to the C compiler you want to use, typcially cc or gcc.
#
CC      = gcc


# 2) Set X_INC_DIR equal to the directory path for X11 include files.
#
X_INC_DIR = /local/x11/include


# 3) Set X_LIB_DIR equal to the directory to search for X11 library files.
#
X_LIB_DIR = /local/x11/lib


# 4) Set XITE_BIN_DEST to determine where the XITE executables will
#    be placed
#
#TOP     = /local
TOP     = $$XITE_HOME
#XITE_BIN_DEST = .
#XITE_BIN_DEST = $(TOP)/bin
XITE_BIN_DEST = $(TOP)/bin/$(XITE_HOSTTYPE)


# 5) Set XITE_LIB_DEST to determine where the XITE object library will be
#    placed
#
#XITE_LIB_DEST = .
#XITE_LIB_DEST = $(TOP)/lib
XITE_LIB_DEST = $(TOP)/lib/$(XITE_HOSTTYPE)
XITE          = xite
XITE_LIB      = lib$(XITE).a
XITE_LIB_X    = lib$(XITE)X.a


# 6) Set XITE_INC_DEST to determine where the XITE header files will be put
#
#XITE_INC_DEST = .
XITE_INC_DEST = $(TOP)/include


# 7) Set XITE_MAN_DEST to determine where the XITE manual files will be put
#
#XITE_MAN_DEST = .
XITE_MAN_DEST = $(TOP)/man


# 8) Set XITE_DOC_DEST to determine where the XITE html files will be put
#
#XITE_DOC_DEST = .
XITE_DOC_DEST = $(TOP)/doc


# 9) Set CFLAGS
#
#DEBUG = -DDEBUG
DEBUG = 

EOF_CC

#############################################################################
#
# OPTIM, OPTIM_GNU, CFLAGS_ALWAYS, CFLAGS_PROD_CC, CFLAGS_DEV_CC, CFLAGS_CMEX
#
#############################################################################

  echo "MATLAB_HOSTTYPE = "

if test "$XITE_HOSTTYPE" = "AIX"
then

cat <<\EOF_AIX

OPTIM = -O
OPTIM_GNU = -O

CFLAGS_ALWAYS = -D$(XITE_HOSTTYPE) -DSYSTEM_V -DSYSV -Dvfork=fork \
        $(DEBUG) -DDEF_STRCASECMP

# The following is recommended for final production version with cc
#
CFLAGS_PROD_CC  = $(CFLAGS_ALWAYS) $(OPTIM)  -I$(XITE_INC_DEST)

# The following is recommended during software development with cc
#
CFLAGS_DEV_CC  = $(CFLAGS_ALWAYS) -g -I$(XITE_INC_DEST)

CFLAGS_CMEX = $(CFLAGS_ALWAYS) $(OPTIM) -I$(XITE_INC_DEST)

EOF_AIX

elif test "$XITE_HOSTTYPE" = "HP-UX"
then

cat <<\EOF_HP-UX

OPTIM = +O2
OPTIM_GNU = -O

CFLAGS_ALWAYS = -DHPUX -DSYSTEM_V -DSYSV -Drandom=rand -Dsrandom=srand \
        $(DEBUG)

# The following is recommended for the final production version with cc
#
CFLAGS_PROD_CC  = $(CFLAGS_ALWAYS) $(OPTIM) -I$(XITE_INC_DEST)

# The following is recommended during software development with cc
#
CFLAGS_DEV_CC  = $(CFLAGS_ALWAYS) -g -I$(XITE_INC_DEST)

CFLAGS_CMEX = $(CFLAGS_ALWAYS) $(OPTIM) -I$(XITE_INC_DEST)

EOF_HP-UX

elif test "$XITE_HOSTTYPE" = "IRIX"
then

cat <<\EOF_IRIX

OPTIM = -O2
OPTIM_GNU = -O

# The option -mips2 requires an R4000 family processor, or higher

CFLAGS_ALWAYS = -D$(XITE_HOSTTYPE) -DSYSTEM_V -DSYSV -D_BSD_SIGNALS \
        -Dvfork=fork -DGETPTY $(DEBUG)

# The following is recommended for the final production version with cc
#
CFLAGS_PROD_CC  = $(CFLAGS_ALWAYS) $(OPTIM) -signed -mips2 -I$(XITE_INC_DEST)

# The following is recommended during software development with cc
#
CFLAGS_DEV_CC = $(CFLAGS_ALWAYS) -signed -g -fullwarn -mips2 -I$(XITE_INC_DEST)

CFLAGS_CMEX = $(CFLAGS_ALWAYS) $(OPTIM) -I$(XITE_INC_DEST)

EOF_IRIX

elif test "$XITE_HOSTTYPE" = "IRIX64"
then

cat <<\EOF_IRIX64

OPTIM = -O2
OPTIM_GNU = -O

CFLAGS_ALWAYS = -D$(XITE_HOSTTYPE) -DSYSTEM_V -DSYSV -D_BSD_SIGNALS \
        -Dvfork=fork -DGETPTY $(DEBUG)

# The following is recommended for the final production version with cc
#
CFLAGS_PROD_CC  = $(CFLAGS_ALWAYS) $(OPTIM) -signed -I$(XITE_INC_DEST)

# The following is recommended during software development with cc
#
CFLAGS_DEV_CC = $(CFLAGS_ALWAYS) -signed -g -fullwarn -I$(XITE_INC_DEST)

CFLAGS_CMEX = $(CFLAGS_ALWAYS) $(OPTIM) -I$(XITE_INC_DEST)

EOF_IRIX64

elif test "$XITE_HOSTTYPE" = "Linux" -o "$XITE_HOSTTYPE" = "Linux486" -o \
  "$XITE_HOSTTYPE" = "Linux586"
then

cat <<\EOF_Linux

OPTIM = -O
OPTIM_GNU = -O

CFLAGS_ALWAYS = -D$(XITE_HOSTTYPE) $(DEBUG)

# The following is recommended for the final production version with cc
#
CFLAGS_PROD_CC  = $(CFLAGS_ALWAYS) $(OPTIM) -I$(XITE_INC_DEST)

# The following is recommended during software development with cc
#
CFLAGS_DEV_CC  = $(CFLAGS_ALWAYS) -g -I$(XITE_INC_DEST)

CFLAGS_CMEX = $(CFLAGS_ALWAYS) $(OPTIM) -I$(XITE_INC_DEST)

EOF_Linux

elif test "$XITE_HOSTTYPE" = "OSF1"
then

cat <<\EOF_OSF1

OPTIM = -O
OPTIM_GNU = -O

CFLAGS_ALWAYS = -D$(XITE_HOSTTYPE) -DSYSTEM_V -DSYSV -Dvfork=fork \
        $(DEBUG)

# The following is recommended for the final production version with cc
#
CFLAGS_PROD_CC = $(CFLAGS_ALWAYS) -std1 $(OPTIM) -I$(XITE_INC_DEST)

# The following is recommended during software development with cc
#
CFLAGS_DEV_CC = $(CFLAGS_ALWAYS) -std1 -g -verbose -I$(XITE_INC_DEST)

CFLAGS_CMEX = $(CFLAGS_ALWAYS) $(OPTIM) -I$(XITE_INC_DEST)

EOF_OSF1

elif test "$XITE_HOSTTYPE" = "SunOS"
then

cat <<\EOF_SunOS

OPTIM = -O
OPTIM_GNU = -O

CFLAGS_ALWAYS = -D$(XITE_HOSTTYPE) $(DEBUG) -DDEF_STRCASECMP

# The following is recommended for the final production version with cc
#
CFLAGS_PROD_CC  = $(CFLAGS_ALWAYS) $(OPTIM) -I$(XITE_INC_DEST)

# The following is recommended during software development with cc
#
CFLAGS_DEV_CC  = $(CFLAGS_ALWAYS) -g -I$(XITE_INC_DEST)

CFLAGS_CMEX = $(CFLAGS_ALWAYS) $(OPTIM) -I$(XITE_INC_DEST)

EOF_SunOS

elif test "$XITE_HOSTTYPE" = "SunOS5"
then

cat <<\EOF_SunOS5

OPTIM = -O
OPTIM_GNU = -O

CFLAGS_ALWAYS = -D$(XITE_HOSTTYPE) -DSYSTEM_V -DSYSV $(DEBUG) \
        -DNO_DIRENT -I/usr/ucbinclude

# The following is recommended for the final production version with cc
#
CFLAGS_PROD_CC  = $(CFLAGS_ALWAYS) $(OPTIM) -I$(XITE_INC_DEST)

# The following is recommended during software development with cc
#
CFLAGS_DEV_CC  = $(CFLAGS_ALWAYS) -g -I$(XITE_INC_DEST) -v

CFLAGS_CMEX  = $(CFLAGS_ALWAYS) $(OPTIM) -I$(XITE_INC_DEST)

EOF_SunOS5

elif test "$XITE_HOSTTYPE" = "ULTRIX"
then

cat <<\EOF_ULTRIX

OPTIM = -O
OPTIM_GNU = -O

CFLAGS_ALWAYS = -D$(XITE_HOSTTYPE) $(DEBUG)

# The following is recommended for the final production version with cc
#
CFLAGS_PROD_CC  = $(CFLAGS_ALWAYS) $(OPTIM) -I$(XITE_INC_DEST)

# The following is recommended during software development with cc
#
CFLAGS_DEV_CC  = $(CFLAGS_ALWAYS) -g -I$(XITE_INC_DEST)

CFLAGS_CMEX  = $(CFLAGS_ALWAYS) $(OPTIM) -I$(XITE_INC_DEST)

EOF_ULTRIX

elif test "$XITE_HOSTTYPE" = "Other"
then

cat <<\EOF_Other

OPTIM = -O
OPTIM_GNU = -O

CFLAGS_ALWAYS = -Dunknown $(DEBUG)

# The following is recommended for the final production version with cc
#
CFLAGS_PROD_CC  = $(CFLAGS_ALWAYS) $(OPTIM) -I$(XITE_INC_DEST)

# The following is recommended during software development with cc
#
CFLAGS_DEV_CC  = $(CFLAGS_ALWAYS) -g -I$(XITE_INC_DEST)

CFLAGS_CMEX = $(CFLAGS_ALWAYS) $(OPTIM) -I$(XITE_INC_DEST)

EOF_Other

fi

#############################################################################
#
# GNU_WARN, CFLAGS_PROD_GCC, CFLAGS_DEV_GCC
#
#############################################################################

cat <<\EOF_GNU_WARN

GNU_WARN = -Wall -Wmissing-prototypes -Wstrict-prototypes -Wtraditional \
           -Wnested-externs -Wpointer-arith
EOF_GNU_WARN

if test "$XITE_HOSTTYPE" = "AIX" -o "$XITE_HOSTTYPE" = "IRIX" -o \
  "$XITE_HOSTTYPE" = "IRIX64"
then

cat <<\EOF_GNU

# The following is recommended for the final production version with gcc
#
CFLAGS_PROD_GCC = $(CFLAGS_ALWAYS) -fsigned-char $(OPTIM_GNU) \
        -I$(XITE_INC_DEST)

# The following is recommended during software development with gcc
#
CFLAGS_DEV_GCC = $(CFLAGS_ALWAYS) -fsigned-char -g $(GNU_WARN) \
        -I$(XITE_INC_DEST)

EOF_GNU

else

cat <<\EOF_GNU

# The following is recommended for the final production version with gcc
#
CFLAGS_PROD_GCC = $(CFLAGS_ALWAYS) $(OPTIM_GNU) -I$(XITE_INC_DEST)

# The following is recommended during software development with gcc
#
CFLAGS_DEV_GCC = $(CFLAGS_ALWAYS) -g $(GNU_WARN) -I$(XITE_INC_DEST)

EOF_GNU

fi

#############################################################################
#
# CFLAGS
#
#############################################################################

cat <<\EOF_CFLAGS

CFLAGS = $(CFLAGS_PROD_GCC)

EOF_CFLAGS

#############################################################################
#
# LFLAGS, XLIB
#
#############################################################################

echo "# 10) Set LFLAGS"
echo "#"

if test "$XITE_HOSTTYPE" = "OSF1"
then

cat <<\EOF_LFLAGS
LFLAGS      = -L$(XITE_LIB_DEST)
LFLAGS_CMEX = $(LFLAGS)

# 11) Set extra libraries
#
XLIB = -ldnet_stub -lots

EOF_LFLAGS

elif test "$XITE_HOSTTYPE" = "SunOS5"
then

cat <<\EOF_LFLAGS
LFLAGS      = -L/usr/ucblib -L$(XITE_LIB_DEST) -R/usr/ucblib
LFLAGS_CMEX = -L/usr/ucblib -L$(XITE_LIB_DEST)

# 11) Set extra libraries
#
XLIB = -lucb

EOF_LFLAGS

else

cat <<\EOF_LFLAGS
LFLAGS      = -L$(XITE_LIB_DEST)
LFLAGS_CMEX = $(LFLAGS)

# 11) Set extra libraries
#
XLIB = 

EOF_LFLAGS

fi

#############################################################################
#
# MATLAB, MATLAB_INC, MATLAB_LIB, MATLAB_MEX_DEST
#
#############################################################################

cat <<\EOF_MATLAB
# 12) Set MATLAB_INC
#
MATLAB = /local/matlab
MATLAB_INC = $(MATLAB)/extern/include

# 13) Set MATLAB_LIB
#
MATLAB_LIB = $(MATLAB)/extern/lib/$(MATLAB_HOSTTYPE)

# 14) Set MATLAB_MEX_DEST
#
MATLAB_MEX_DEST = $(MATLAB)/toolbox/local

EOF_MATLAB

#############################################################################
#
# TIFF_INC_DIR, TIFF_LIB_DIR
#
#############################################################################

cat <<\EOF_TIFF
# 15) Set TIFF_INC_DIR
#
TIFF_INC_DIR = /usr/local/include

# 16) Set TIFF_LIB_DIR
#
TIFF_LIB_DIR = /usr/local/lib

EOF_TIFF

#############################################################################
#
# PNM_INC_DIR, PNM_LIB_DIR
#
#############################################################################

cat <<\EOF_PNM
# 17) Set PNM_INC_DIR
#
PNM_INC_DIR = /usr/local/include

# 18) Set PNM_LIB_DIR
#
PNM_LIB_DIR = /usr/local/lib

EOF_PNM

#############################################################################
#
# FWF_INC_DIR, FWF_LIB_DIR
#
#############################################################################

cat <<\EOF_FWF
# 19) Set FWF_INC_DIR
#
FWF_INC_DIR = $(XITE_INC_DEST)

# 20) Set FWF_LIB_DIR
#
FWF = fwf
FWF_LIB_DIR = $(XITE_LIB_DEST)
FWF_LIB = lib$(FWF).a

EOF_FWF

#############################################################################
#
# XPM_INC_DIR, XPM_LIB_DIR
#
#############################################################################

cat <<\EOF_XPM
# 21) Set XPM_INC_DIR
#
XPM_INC_DIR = $(XITE_INC_DEST)

# 22) Set XPM_LIB_DIR
#
XPM = xpm
XPM_LIB_DIR = $(XITE_LIB_DEST)
XPM_LIB = lib$(XPM).a

EOF_XPM

#############################################################################
#
# AR, RANLIB, SRC, WLIB
#
#############################################################################

cat <<\EOF_AR
######################################################################
#
# There should be no need to make changes below this point
#
######################################################################

AR      = ar
EOF_AR

if test "$XITE_HOSTTYPE" = "SunOS" -o \
	"$XITE_HOSTTYPE" = "ULTRIX" -o "$XITE_HOSTTYPE" = "Other"
then

cat <<\EOF_RANLIB
RANLIB  = ranlib
SRC     = .
EOF_RANLIB

else

cat <<\EOF_RANLIB
RANLIB  = echo
SRC     = .
EOF_RANLIB

fi

if test "$XITE_HOSTTYPE" = "AIX"
then

cat <<\EOF_WLIB
WLIB 	= -l$(FWF) -l$(XPM) -lXaw -lXmu -lXt -lXext -lX11 -liconv
EOF_WLIB

elif test "$XITE_HOSTTYPE" = "SunOS5"
then

cat <<\EOF_WLIB
WLIB 	= -R$(X_LIB_DIR) -l$(FWF) -l$(XPM) -lXaw -lXmu -lXt -lXext -lX11
EOF_WLIB

else

cat <<\EOF_WLIB
WLIB 	= -l$(FWF) -l$(XPM) -lXaw -lXmu -lXt -lXext -lX11
EOF_WLIB

fi

#############################################################################
#
# COMPILE, LINK, XLINK, DOC
#
#############################################################################

cat <<\EOF_COMPILE

# For plain XITE C source
#
COMPILE.c = $(CC) $(CFLAGS) -c
LINK.c    = $(CC) $(CFLAGS) -DMAIN -o $(XITE_BIN_DEST)/$@ $@.c \
            $(LFLAGS) -l$(XITE) $(XLIB) -lm

# C source with X11
#
COMPILE.x = $(COMPILE.c) -I$(X_INC_DIR)

# ... link with libraries
#
LINK.x    = $(CC) $(CFLAGS) -I$(X_INC_DIR) -DMAIN -o $(XITE_BIN_DEST)/$@.bin \
            $@.c $(LFLAGS) -L$(X_LIB_DIR) -l$(XITE)X -l$(XITE) $(WLIB) \
            $(XLIB) -lm

# ... link with libraries and object file dependencies
#
LINK.x.obj = $(CC) $(CFLAGS) -I$(X_INC_DIR) -DMAIN -o $(XITE_BIN_DEST)/$@.bin \
             $@.c $? $(LFLAGS) -L$(X_LIB_DIR) -l$(XITE)X -l$(XITE) $(WLIB) \
             $(XLIB) -lm

# C source with libtiff
#
COMPILE.t = $(COMPILE.c) -I$(TIFF_INC_DIR)
LINK.t    = $(CC) $(CFLAGS) -DMAIN -I$(TIFF_INC_DIR) -o $(XITE_BIN_DEST)/$@ \
            $@.c $(LFLAGS) -L$(TIFF_LIB_DIR) -ltiff -l$(XITE) $(XLIB) -lm

# C source with pnm
#
LINK.p    = $(CC) $(CFLAGS) -DMAIN -I$(PNM_INC_DIR) -o $(XITE_BIN_DEST)/$@ \
            $@.c $(LFLAGS) -L$(PNM_LIB_DIR) -lpnm -lppm -lpgm -lpbm -l$(XITE) \
            $(XLIB) -lm

# C source with MATLAB
#
COMPILE.m = $(COMPILE.c) -I$(MATLAB_INC)
LINK.m    = $(CC) $(CFLAGS) -I$(MATLAB_INC) -DMAIN -o $(XITE_BIN_DEST)/$@ \
            $@.c $(LFLAGS) -L$(MATLAB_LIB) -lmat -l$(XITE) $(XLIB) -lm
CMEX      = cmex CC=$(CC) $(CFLAGS_CMEX) $(LFLAGS_CMEX) -l$(XITE) -o \
            $(MATLAB_MEX_DEST)/$@ $@.c

# C source with X11, fwf and xpm
#
COMPILE.f = $(COMPILE.x) -I$(FWF_INC_DIR) -I$(XPM_INC_DIR)

# Documentation for C
#
MANDOC    = $(XITE_BIN_DEST)/cdoc -t
HTMLDOC   = $(XITE_BIN_DEST)/cdoc -h

# Make MATLAB .m-file for MATLAB help
#
MFILE   = awk '/%$(@:.m=) /,/\*\// {if (length==2) next; else print}'

# Initialize directory-specific variables to avoid errors from make.
#
OBJ       = "_OBJ_"
PROG      = "_PROG_"
MANP      = "_MANP_"
MANP_SH   = "_MANP_SH_"
ROFF3     = "_ROFF3_"
CINCL     = "_CINCL_"
SCRIPTS   = "_SCRIPTS_"
XOBJ      = "_XOBJ_"
XPROG     = "_XPROG_"
TIFFOBJ   = "_TIFFOBJ_"
TIFFPROG  = "_TIFFPROG_"
PNMPROG   = "_PNMPROG_"
MATOBJ    = "_MATOBJ_"
MATPROG   = "_MATPROG_"
MATMEX    = "_MATMEX_"
MATHELP   = "_MATHELP_"
FWFOBJ    = "_FWFOBJ_"
FWFPROG   = "_FWFPROG_"
FWFINCL   = "_FWFINCL_"
XPMOBJ    = "_XPMOBJ_"
XPMPROG   = "_XPMPROG_"
XPMINCL   = "_XPMINCL_"

all:	     include lib program doc

# Get directory-specific variables and define the targets object, lib and
# program
#
include Makefile.defs

EOF_COMPILE

#############################################################################
#
# Target rules
#
#############################################################################

cat <<\EOF_rules
# Overall rules
#
#include:     cincl fwfincl xpmincl
#object:      cobj xobj tiffobj matobj
#lib:	      clib xlib tifflib matlib
#program:     cprog xprog scripts tiffprog matprog pnmprog
#doc:         manpage roff3 mathelp
manpage:     $(MANP) $(MANP_SH)
roff3:       $(ROFF3)
scripts:     $(SCRIPTS)
clean:  
	     @rm -f *.o $(PROG) $(XPROG) $(TIFFPROG) $(PNMPROG) $(MATPROG) \
	          > /dev/null 2>&1

# Rules for plain XITE C source
#
c:           cincl clib cprog
cincl:       $(CINCL)
cobj:        $(OBJ)
cprog:       $(PROG)
clib:	     $(OBJ)
	     -@if test "$?" != "_OBJ_"; then \
	       echo "$(AR) r $(XITE_LIB_DEST)/$(XITE_LIB) $?"; \
	       $(AR) r $(XITE_LIB_DEST)/$(XITE_LIB) $?; \
	       chmod a+r $(XITE_LIB_DEST)/$(XITE_LIB) > /dev/null 2>&1; \
	       $(RANLIB) $(XITE_LIB_DEST)/$(XITE_LIB); \
	     fi
$(OBJ):      $(@:.o=.c)
	     $(COMPILE.c) $(@:.o=.c)
$(PROG):     $(@:=.c)
	     $(LINK.c)
	     -@chmod a+rx $(XITE_BIN_DEST)/$@ > /dev/null 2>&1
$(CINCL):    $(@:.i=.h)
#	     Install include files
	     -@if test "$(@:.i=.h)" != "_CINCL_"; then \
	       echo "cp $(@:.i=.h) $(XITE_INC_DEST)"; \
	       cp $(@:.i=.h) $(XITE_INC_DEST); \
	       chmod u+w $(XITE_INC_DEST)/$(@:.i=.h) > /dev/null 2>&1; \
	       chmod a+r $(XITE_INC_DEST)/$(@:.i=.h) > /dev/null 2>&1; \
	     fi

# Rules for C source using X11
#
x:	     xlib xprog
xobj:        $(XOBJ)
#xprog:       $(XPROG)
xlib:        $(XOBJ)
	     -@if test "$?" != "_XOBJ_"; then \
	       echo "$(AR) r $(XITE_LIB_DEST)/$(XITE_LIB_X) $?"; \
	       $(AR) r $(XITE_LIB_DEST)/$(XITE_LIB_X) $?; \
	       chmod a+r $(XITE_LIB_DEST)/$(XITE_LIB_X) > /dev/null 2>&1; \
	       $(RANLIB) $(XITE_LIB_DEST)/$(XITE_LIB_X); \
	     fi
$(XOBJ):     $(@:.o=.c)
	     $(COMPILE.x) $(@:.o=.c)
$(XPROG):    $(@:=.c)
	     $(LINK.x)
	     -@rm $(XITE_BIN_DEST)/$@ > /dev/null 2>&1
	     -@ln -s $(XITE_BIN_DEST)/startProg $(XITE_BIN_DEST)/$@ > \
	       /dev/null 2>&1
	     -@chmod a+rx $(XITE_BIN_DEST)/$@.bin $(XITE_BIN_DEST)/$@ > \
	       /dev/null 2>&1

# Rules for C source using TIFF
#
tiff:        tifflib tiffprog
tiffobj:     $(TIFFOBJ)
tiffprog:    $(TIFFPROG)
tifflib:     $(TIFFOBJ)
	     -@if test "$?" != "_TIFFOBJ_"; then \
	       echo "$(AR) r $(XITE_LIB_DEST)/$(XITE_LIB) $(?:.t=.o)"; \
	       $(AR) r $(XITE_LIB_DEST)/$(XITE_LIB) $(?:.t=.o); \
	       chmod a+r $(XITE_LIB_DEST)/$(XITE_LIB) > /dev/null 2>&1; \
	       $(RANLIB) $(XITE_LIB_DEST)/$(XITE_LIB); \
	     fi
$(TIFFOBJ):  $(@:.o=.c)
	     $(COMPILE.t) $(@:.o=.c)
$(TIFFPROG): $(@:=.c)
	     $(LINK.t)
	     -@chmod a+rx $(XITE_BIN_DEST)/$@ > /dev/null 2>&1

# Rules for C source using pnm
#
pnm:         pnmprog
pnmobj:
pnmprog:     $(PNMPROG)
$(PNMPROG): $(@:=.c)
	     $(LINK.p)
	     -@chmod a+rx $(XITE_BIN_DEST)/$@ > /dev/null 2>&1
pnmlib:

# Rules for C source using MATLAB
#
matlab:      matlib matprog matmex mathelp
matobj:      $(MATOBJ)
matprog:     $(MATPROG)
mathelp:     $(MATHELP)
matmex:      $(MATMEX)
matlib:      $(MATOBJ)
	     -@if test "$?" != "_MATOBJ_"; then \
	       echo "$(AR) r $(XITE_LIB_DEST)/$(XITE_LIB) $?"; \
	       $(AR) r $(XITE_LIB_DEST)/$(XITE_LIB) $?; \
	       chmod a+r $(XITE_LIB_DEST)/$(XITE_LIB) > /dev/null 2>&1; \
	       $(RANLIB) $(XITE_LIB_DEST)/$(XITE_LIB); \
	     fi
$(MATOBJ):   $(@:.o=.c)
	     $(COMPILE.m) $(@:.o=.c)
$(MATPROG):  $(@:=.c)
	     $(LINK.m)
	     -@chmod a+rx $(XITE_BIN_DEST)/$@ > /dev/null 2>&1
$(MATMEX):   $(@:=.c)
#	     Create MATLAB mex-files.
	     $(CMEX)
$(MATHELP):  $(@:.m=.c)
#            Make MATLAB .m-file for MATLAB help.
	     $(MFILE) $(@:.m=.c) > $(MATLAB_MEX_DEST)/$@
	     -@chmod a+r $(MATLAB_MEX_DEST)/$@ > /dev/null 2>&1

# Rules for C source using fwf
#
fwf:         fwflib fwfprog
fwfobj:      $(FWFOBJ)
fwfprog:     $(FWFPROG)
fwflib:      $(FWFOBJ)
	     -@if test "$?" != "_FWFOBJ_"; then \
	       echo "$(AR) r $(FWF_LIB_DIR)/$(FWF_LIB) $(?:.f=.o)"; \
	       $(AR) r $(FWF_LIB_DIR)/$(FWF_LIB) $(?:.f=.o); \
	       chmod a+r $(FWF_LIB_DIR)/$(FWF_LIB) > /dev/null 2>&1; \
	       $(RANLIB) $(FWF_LIB_DIR)/$(FWF_LIB); \
	     fi
fwfincl:     $(FWFINCL)
$(FWFOBJ):   $(@:.o=.c)
	     $(COMPILE.f) $(@:.o=.c)
$(FWFINCL): $(@:.i=.h)
#            Install include files
	     -@if test "$(@:.i=.h)" != "_FWFINCL_"; then \
	       echo "cp $(@:.i=.h) $(FWF_INC_DIR)"; \
	       cp $(@:.i=.h) $(FWF_INC_DIR); \
	       chmod u+w $(FWF_INC_DIR)/$(@:.i=.h) > /dev/null 2>&1; \
	       chmod a+r $(FWF_INC_DIR)/$(@:.i=.h) > /dev/null 2>&1; \
	     fi

# Rules for C source using xpm
#
xpm:         xpmlib xpmprog
xpmobj:      $(XPMOBJ)
xpmprog:     $(XPMPROG)
xpmlib:      $(XPMOBJ)
	     -@if test "$?" != "_XPMOBJ_"; then \
	       echo "$(AR) r $(XPM_LIB_DIR)/$(XPM_LIB) $(?:.f=.o)"; \
	       $(AR) r $(XPM_LIB_DIR)/$(XPM_LIB) $(?:.f=.o); \
	       chmod a+r $(XPM_LIB_DIR)/$(XPM_LIB) > /dev/null 2>&1; \
	       $(RANLIB) $(XPM_LIB_DIR)/$(XPM_LIB); \
	     fi
xpmincl:     $(XPMINCL)
$(XPMOBJ):   $(@:.o=.c)
	     $(COMPILE.f) $(@:.o=.c)
$(XPMINCL): $(@:.i=.h)
#            Install include files
	     -@if test "$(@:.i=.h)" != "_XPMINCL_"; then \
	       echo "cp $(@:.i=.h) $(XPM_INC_DIR)"; \
	       cp $(@:.i=.h) $(XPM_INC_DIR); \
	       chmod u+w $(XPM_INC_DIR)/$(@:.i=.h) > /dev/null 2>&1; \
	       chmod a+r $(XPM_INC_DIR)/$(@:.i=.h) > /dev/null 2>&1; \
	     fi

$(MANP):     $(@:.m=.c)
#	     Make manual-page descriptions
	     -@if test "$@" != "_MANP_"; then \
	       echo $(MANDOC) \
	       `grep "^#\{0,1\}\/\*[PFD]:" $(@:.m=.c) |\
	       sed 's/^#\{0,1\}../-e /' |\
	       sed 's/.[ 	]*$$//' |\
	       sed 's/=.*//' ` $(@:.m=.c) $(XITE_MAN_DEST)/ ; \
	       $(MANDOC) `grep "^#\{0,1\}\/\*[PFD]:" $(@:.m=.c) |\
	       sed 's/^#\{0,1\}../-e /' |\
	       sed 's/.[ 	]*$$//' |\
	       sed 's/=.*//' ` $(@:.m=.c) $(XITE_MAN_DEST)/ ; \
	       echo $(HTMLDOC) \
	       `grep "^#\{0,1\}\/\*[PFD]:" $(@:.m=.c) |\
	       sed 's/^#\{0,1\}../-e /' |\
	       sed 's/.[ 	]*$$//' | sed 's/=.*//' ` $(@:.m=.c) \
	       $(XITE_DOC_DEST)/ ; \
	       $(HTMLDOC) `grep "^#\{0,1\}\/\*[PFD]:" $(@:.m=.c) |\
	       sed 's/^#\{0,1\}../-e /' |\
	       sed 's/.[ 	]*$$//' | sed 's/=.*//' ` $(@:.m=.c) \
	       $(XITE_DOC_DEST)/ ; \
	     fi

$(MANP_SH):  $(@:.m=.sh)
#	     Make manual-page descriptions
	     -@if test "$@" != "_MANP_SH_"; then \
	       echo $(MANDOC) -s '*.sh' \
	       `grep "^#\{0,1\}\/\*[PFD]:" $(@:.m=.sh) |\
	       sed 's/^#\{0,1\}../-e /' |\
	       sed 's/.[ 	]*$$//' |\
	       sed 's/=.*//' ` $(@:.m=.sh) $(XITE_MAN_DEST)/ ; \
	       $(MANDOC) -s '*.sh' `grep "^#\{0,1\}\/\*[PFD]:" $(@:.m=.sh) |\
	       sed 's/^#\{0,1\}../-e /' |\
	       sed 's/.[ 	]*$$//' |\
	       sed 's/=.*//' ` $(@:.m=.sh) $(XITE_MAN_DEST)/ ; \
	       echo $(HTMLDOC) -s '*.sh' \
	       `grep "^#\{0,1\}\/\*[PFD]:" $(@:.m=.sh) |\
	       sed 's/^#\{0,1\}../-e /' |\
	       sed 's/.[ 	]*$$//' | sed 's/=.*//' ` $(@:.m=.sh) \
	       $(XITE_DOC_DEST)/ ; \
	       $(HTMLDOC) -s '*.sh' `grep "^#\{0,1\}\/\*[PFD]:" $(@:.m=.sh) |\
	       sed 's/^#\{0,1\}../-e /' |\
	       sed 's/.[ 	]*$$//' | sed 's/=.*//' ` $(@:.m=.sh) \
	       $(XITE_DOC_DEST)/ ; \
	     fi

$(ROFF3):    $(@:.man=.3)
#            Copy troff-files to manual page section 3 directory
#            and html files to html reference manual directory
	     cp $(@:.man=.3) $(XITE_MAN_DEST)/man3/$(@:.man=.3)
	     cp $(@:.man=_3.html) $(XITE_DOC_DEST)/$(@:.man=_3.html)

$(SCRIPTS):  $(@:=.sh)
#	     Install shell scripts
	     cp $@.sh $(XITE_BIN_DEST)/$@
	     -@chmod u+w $(XITE_BIN_DEST)/$@ > /dev/null 2>&1
	     -@chmod a+rx $(XITE_BIN_DEST)/$@ > /dev/null 2>&1
EOF_rules
