#############################################################################
# You need to do a successful 'make' in the bsd_src directory first before
# trying to run 'make' in this directory.  The bsd_src directory contains
# several files derived from those found in the uunet.uu.net archive.
# Run "make install" to install binaries.
# Run "make installm" to install man pages.
# Run "make de-install" to remove installed binaries and man pages.

#############################################################################
# This is where you want to install the binary
#
#BIN=/usr/local/bin
BIN=../../bin.sun4/fsp

#############################################################################
# This is where you want to install the man pages
#
MAN=/usr/local/man/man1

#############################################################################
# If you want to provide FSP service, this should be set to the working
# directory of the FSP server.
#
DEF_FSP_HOME=/usr/tmp/fsp_home

#############################################################################
# If the server is to run on a machine with file name length limit, set the
# following variable to the length.  Otherwise, set it to something big.
FILE_NAME_LIMIT=99999

#############################################################################
# If you want to provide FSP service, this should be set to the UDP socket
# port number the FSP server should use.
#
DEF_FSP_PORT=21

#############################################################################
# This is where the version number string comes from:
#
VERSION_STR="Original Caltech version 2.5, April 1992"

#############################################################################
# FSP uses BSD random/srandom functions.  If your system does not have
# them, include them from the bsd_src directory.
#
#RANDOM=bsd_src/random.o

#############################################################################
# If your machine has either lockf or flock functions, you may be able to
# compile the client codes so that multiple client commands can be run
# concurrently.  Uncomment one of the following and set the LOCK_PREFIX
# string appropriately.  In most cases, they are prefixes used to create 
# a lock file in your file system.  There are some restrictions, for example
# on SunOS, lock files may not be on a file system of type tmp.  The most
# efficient locking choice is the one that uses SysV shared memory plus lockf.
#
#LOCK_FLAGS= -DUSE_SHAREMEM_AND_LOCKF -DKEY_PREFIX=\"/usr/tmp/.FL\"
LOCK_FLAGS= -DUSE_FLOCK -DKEY_PREFIX=\"/usr/tmp/.FL\"
#LOCK_FLAGS= -DUSE_LOCKF -DKEY_PREFIX=\"/usr/tmp/.FL\"
#LOCK_FLAGS= -DNOLOCKING

#############################################################################
# Include -DDIRENT in CFLAGS if you have /usr/include/dirent.h.
# Remove  -DDIRENT if you do not.
CFLAGS=-O -DDIRENT

PROGS=	fspd flscmd fcdcmd fgetcmd frmcmd frmdircmd fprocmd \
	fmkdir fput fver fcatcmd fgrabcmd

IPROGS=	${BIN}/fspd ${BIN}/flscmd ${BIN}/fcdcmd \
	${BIN}/fgetcmd ${BIN}/frmcmd ${BIN}/frmdircmd ${BIN}/fprocmd \
	${BIN}/fmkdir ${BIN}/fput ${BIN}/fver ${BIN}/fcatcmd ${BIN}/fgrabcmd

IMANS=	${MAN}/fcatcmd.1 ${MAN}/fcat.1 ${MAN}/fcdcmd.1 ${MAN}/fcd.1 \
	${MAN}/fgetcmd.1 ${MAN}/fget.1 ${MAN}/flscmd.1 ${MAN}/fls.1 \
	${MAN}/fmkdir.1 ${MAN}/fprocmd.1 ${MAN}/fpro.1 ${MAN}/fput.1 \
	${MAN}/frmcmd.1 ${MAN}/frm.1 ${MAN}/frmdircmd.1 ${MAN}/frmdir.1 \
	${MAN}/fspd.1 ${MAN}/fver.1 ${MAN}/fgrab.1 ${MAN}/fgrabcmd.1

all:
	@ cd bsd_src; make
	@ make all1

all1:	  ${PROGS}
install:  ${IPROGS}
installm: ${IMANS}

SERVER_OBJ= server_main.o server_lib.o server_host.o udp_io.o server_file.o
CLIENT_OBJ= client_lib.o udp_io.o client_util.o client_lock.o
GLOB_OBJ= bsd_src/glob.o
UTIL_LS_OBJ= bsd_src/cmp.o bsd_src/ls.o bsd_src/print.o bsd_src/util.o \
		${GLOB_OBJ}

#############################################################################

fspd: ${SERVER_OBJ} ${RANDOM}
	cc ${CFLAGS} -o fspd ${SERVER_OBJ} ${RANDOM} ${LIB}

fgetcmd: fgetcmd.o ${CLIENT_OBJ} ${GLOB_OBJ}
	cc ${CFLAGS} -o fgetcmd fgetcmd.o ${CLIENT_OBJ} ${GLOB_OBJ} ${LIB}

fgrabcmd: fgrabcmd.o ${CLIENT_OBJ} ${GLOB_OBJ}
	cc ${CFLAGS} -o fgrabcmd fgrabcmd.o ${CLIENT_OBJ} ${GLOB_OBJ} ${LIB}

fcatcmd: fcatcmd.o ${CLIENT_OBJ} ${GLOB_OBJ}
	cc ${CFLAGS} -o fcatcmd fcatcmd.o ${CLIENT_OBJ} ${GLOB_OBJ} ${LIB}

fput: fput.o ${CLIENT_OBJ}
	cc ${CFLAGS} -o fput fput.o ${CLIENT_OBJ} ${LIB}

frmcmd: frmcmd.o ${CLIENT_OBJ} ${GLOB_OBJ}
	cc ${CFLAGS} -o frmcmd frmcmd.o ${CLIENT_OBJ} ${GLOB_OBJ} ${LIB}

flscmd: flscmd.o ${CLIENT_OBJ} ${UTIL_LS_OBJ}
	cc ${CFLAGS} -o flscmd flscmd.o ${CLIENT_OBJ} ${UTIL_LS_OBJ} ${LIB}

fcdcmd: fcdcmd.o ${CLIENT_OBJ} ${GLOB_OBJ}
	cc ${CFLAGS} -o fcdcmd fcdcmd.o ${CLIENT_OBJ} ${GLOB_OBJ} ${LIB}

frmdircmd: frmdircmd.o ${CLIENT_OBJ} ${GLOB_OBJ}
	cc ${CFLAGS} -o frmdircmd frmdircmd.o ${CLIENT_OBJ} ${GLOB_OBJ} ${LIB}

fprocmd: fprocmd.o ${CLIENT_OBJ} ${GLOB_OBJ}
	cc ${CFLAGS} -o fprocmd fprocmd.o ${CLIENT_OBJ} ${GLOB_OBJ} ${LIB}

fmkdir: fmkdir.o ${CLIENT_OBJ}
	cc ${CFLAGS} -o fmkdir fmkdir.o ${CLIENT_OBJ} ${LIB}

fver: fver.o ${CLIENT_OBJ}
	cc ${CFLAGS} -o fver fver.o ${CLIENT_OBJ} ${LIB}

#############################################################################

${BIN}/fspd     : fspd      ; cp fspd      ${BIN}/fspd
${BIN}/fgetcmd  : fgetcmd   ; cp fgetcmd   ${BIN}/fgetcmd
${BIN}/fgrabcmd : fgrabcmd  ; cp fgrabcmd  ${BIN}/fgrabcmd
${BIN}/fcatcmd  : fcatcmd   ; cp fcatcmd   ${BIN}/fcatcmd
${BIN}/fput     : fput      ; cp fput      ${BIN}/fput
${BIN}/frmcmd   : frmcmd    ; cp frmcmd    ${BIN}/frmcmd
${BIN}/flscmd   : flscmd    ; cp flscmd    ${BIN}/flscmd
${BIN}/fcdcmd   : fcdcmd    ; cp fcdcmd    ${BIN}/fcdcmd
${BIN}/frmdircmd: frmdircmd ; cp frmdircmd ${BIN}/frmdircmd
${BIN}/fprocmd  : fprocmd   ; cp fprocmd   ${BIN}/fprocmd
${BIN}/fmkdir   : fmkdir    ; cp fmkdir    ${BIN}/fmkdir
${BIN}/fver     : fver      ; cp fver      ${BIN}/fver

#############################################################################

${MAN}/fcat.1     : fcatcmd.1  ; cp fcat.1      ${MAN}/fcat.1
${MAN}/fcatcmd.1  : fcatcmd.1  ; cp fcatcmd.1   ${MAN}/fcatcmd.1
${MAN}/fcd.1      : fcdcmd.1   ; cp fcd.1       ${MAN}/fcd.1
${MAN}/fcdcmd.1   : fcdcmd.1   ; cp fcdcmd.1    ${MAN}/fcdcmd.1
${MAN}/fget.1     : fgetcmd.1  ; cp fget.1      ${MAN}/fget.1
${MAN}/fgetcmd.1  : fgetcmd.1  ; cp fgetcmd.1   ${MAN}/fgetcmd.1
${MAN}/fgrab.1    : fgrabcmd.1 ; cp fgrab.1     ${MAN}/fgrab.1
${MAN}/fgrabcmd.1 : fgrabcmd.1 ; cp fgrabcmd.1  ${MAN}/fgrabcmd.1
${MAN}/fls.1      : flscmd.1   ; cp fls.1       ${MAN}/fls.1
${MAN}/flscmd.1   : flscmd.1   ; cp flscmd.1    ${MAN}/flscmd.1
${MAN}/fmkdir.1   : fmkdir.1   ; cp fmkdir.1    ${MAN}/fmkdir.1
${MAN}/fpro.1     : fprocmd.1  ; cp fpro.1      ${MAN}/fpro.1
${MAN}/fprocmd.1  : fprocmd.1  ; cp fprocmd.1   ${MAN}/fprocmd.1
${MAN}/fput.1     : fput.1     ; cp fput.1      ${MAN}/fput.1
${MAN}/frm.1      : frmcmd.1   ; cp frm.1       ${MAN}/frm.1
${MAN}/frmcmd.1   : frmcmd.1   ; cp frmcmd.1    ${MAN}/frmcmd.1
${MAN}/frmdir.1   : frmdircmd.1; cp frmdir.1    ${MAN}/frmdir.1
${MAN}/frmdircmd.1: frmdircmd.1; cp frmdircmd.1 ${MAN}/frmdircmd.1
${MAN}/fspd.1     : fspd.1     ; cp fspd.1      ${MAN}/fspd.1
${MAN}/fver.1     : fver.1     ; cp fver.1      ${MAN}/fver.1

#############################################################################

server_main.o: server_main.c server_def.h common_def.h Makefile
	cc ${CFLAGS} -DDEF_FSP_PORT=${DEF_FSP_PORT}	\
		     -DDEF_FSP_HOME=\"${DEF_FSP_HOME}\"	\
		     -DVERSION_STR=\"${VERSION_STR}\"	\
		     -DFILE_NAME_LIMIT=${FILE_NAME_LIMIT} \
		     -c server_main.c

client_lock.o: client_lock.c client_def.h common_def.h Makefile
	cc ${CFLAGS} ${LOCK_FLAGS} -c client_lock.c

client_lib.o: client_lib.c client_def.h common_def.h
client_util.o: client_util.c client_def.h common_def.h
fcatcmd.o: fcatcmd.c client_def.h common_def.h
fcdcmd.o: fcdcmd.c client_def.h common_def.h
fgetcmd.o: fgetcmd.c client_def.h common_def.h
fgrabcmd.o: fgrabcmd.c client_def.h common_def.h
flscmd.o: flscmd.c client_def.h common_def.h
fmkdir.o: fmkdir.c client_def.h common_def.h
fprocmd.o: fprocmd.c client_def.h common_def.h
fput.o: fput.c client_def.h common_def.h
frmcmd.o: frmcmd.c client_def.h common_def.h
fver.o: fver.c client_def.h common_def.h
frmdircmd.o: frmdircmd.c client_def.h common_def.h
server_host.o: server_host.c server_def.h common_def.h
server_file.o: server_file.c server_def.h common_def.h
server_lib.o: server_lib.c server_def.h common_def.h
server_main.o: server_main.c server_def.h common_def.h
udp_io.o: udp_io.c common_def.h

clean:
	rm -f *.o ${PROGS}
	@ cd bsd_src; make clean

de-install:
	rm -f ${IPROGS} ${IMANS}
