HTMLBINDIR  = ../../htmlbin
LIBDIR = ../lib

all:\
  ${HTMLBINDIR}/serv       \
  ${HTMLBINDIR}/dir        \
  ${HTMLBINDIR}/info

${HTMLBINDIR}/serv: serv.o ${LIBDIR}/jgofs.a
	-mkdir ${HTMLBINDIR}
	$(CC) ${CFLAGS} serv.o ${LIBDIR}/jgofs.a  -o $@
serv.o:serv.c
	$(CC) ${CFLAGS} -DOPTIONSERVER='"${OPTIONSERVER}"' -DJGOFSDIR='"${JGOFSDIR}"' -c serv.c

# Purpose:
#   builds dir, from PERL version, if PERL environment variable exists
#   else builds the csh version.  
#
# NOTE:  env $PERL contains location of perl interpreter on this machine.
#
##############
# Values used to replace variables in template (*.tmp) file are:
#
#  (PERL version only) PERL:  which, if any, perl to use
#                      Example:       /usr/local/bin/perl
#
#  (if any) DMONAME:  name of program for which this is DMO
#                      Example:     US BIO-PROJ
#
#  MYADDR:     this machine's alias on the WWW
#                      Example:     www.jgofs.org:80
#
#  JGOFSDIR:   top of the jgofs software tree; parent of OBJECTROOT
#                      Example:     /users/jgofs
#
#  OBJDIR:  below OBJECTROOT, where to begin looking for object defn's
#                      Example:      /jgofs
#
#  BUTTONIMAGESDIR:  directory where image files are located, relative to 
#                 MYADDR's DocumentRoot.  Intention is to find the GIF 
#                 used to indicate the current directory, 'youhere.gif'.
#
#  INFOSERVER:  by default, machine and program used to serve
#               documentation files
#                      Example:     www.jgofs.org:80/jg/info
#
#  The length of the string formed by appending "objects" to value of JGOFSDIR
#                      Example:     /users/jgofs/objects == 20
##############
#
# Where to place the custom 'dir'
#
LEN=`(echo "${JGOFSDIR}/objects" | ${NAWK} '{print length}')`

${HTMLBINDIR}/dir: dir_pl.tmp dir_csh.tmp
	if [ "$(PERL)" ]; \
	then \
		sed "s*perllocation*${PERL}*g;\
		     s*myaddr*${MYADDR}*g;\
		     s*dmoname*${DMONAME}*g;\
		     s*jgofsdir*${JGOFSDIR}*g;\
		     s*objectdir*${OBJDIR}*g;\
		     s*imagedirectory*${BUTTONIMAGESDIR}*g;\
		     s*informationserver*${INFOSERVER}*g" <dir_pl.tmp > $@; \
	else \
		sed "s*objectdir*${OBJDIR}*g;\
		     s*myaddr*${MYADDR}*g;\
		     s*dmoname*${DMONAME}*g;\
		     s*jgofsdir*${JGOFSDIR}*g;\
		     s*dirlength*${LEN}*g;\
		     s*NAWK*${NAWK}*g;\
		     s*informationserver*${INFOSERVER}*g" <dir_csh.tmp > $@; \
	fi
	chmod +x $@;

# Purpose:
#   builds info, from PERL version, if PERL environment variable exists
#   else builds the csh version.
#
# NOTE:  env $PERL contains location of perl interpreter on this machine.
#
##############
# Values used to replace variables in template (*.tmp) file are:
#
#  (PERL version only) PERL:  which, if any, perl to use
#                      Example:       /usr/local/bin/perl
#
#  (if any) DMONAME:  name of program for which this is DMO
#                      Example:     US BIO-PROJ
#
#  INFOSERVER:  by default, machine and program used to serve
#               documentation files
#                      Example:   www.jgofs.org:80/jg/info
#
#  BUTTONIMAGESDIR:  directory where image files are located, relative to 
#                 MYADDR's DocumentRoot.  Intention is to find the GIF 
#                 files used for the 'Directory' and 'Data display' buttons.
#
##############
#

${HTMLBINDIR}/info: info_pl.tmp info_csh.tmp
	if [ "$(PERL)" ]; \
	then \
		sed "s*perllocation*${PERL}*g;\
		     s*dmoname*${DMONAME}*g;\
                     s*imagedirectory*${BUTTONIMAGESDIR}*g;\
		     s*informationserver*${INFOSERVER}*g" < info_pl.tmp > $@; \
	else \
		sed "s*objectdir*${OBJDIR}*g;\
		     s*myaddr*${MYADDR}*g;\
		     s*dmoname*${DMONAME}*g;\
                     s*imagedirectory*${BUTTONIMAGESDIR}*g;\
		     s*jgofsdir*${JGOFSDIR}*g;\
		     s*informationserver*${INFOSERVER}*g" < info_csh.tmp > $@; \
	fi
	chmod +x $@;
