##############################################################################
#                                                                            #
#    Makefile,v
#    Makefile for directory iod
#                                                                            #
#    Copyright (C) 1995 A. Bode, S. Lamberts, T. Ludwig, C. R"oder           #
#                                                                            #
#    PFSLib (Parallel I/O on workstations)                                   #
#                                                                            #
#    PFSLib offers parallel access to files for a parallel application       #
#    running on a cluster of workstations.                                   #
#    It is intended but not restricted to be used in message passing         #
#    applications based on PVM, NXLib, MPI, and other.                       #
#                                                                            #
#    PFSLib consists of a LIBRARY, deamon PROGRAMS, and utility PROGRAMS.    #
#                                                                            #
#    PFSLib is free software; you can redistribute the LIBRARY and/or        #
#    modify it under the terms of the GNU Library General Public             #
#    License as published by the Free Software Foundation; either            #
#    version 2 of the License, or (at your option) any later version.        #
#    You can redistribute the daemon PROGRAMS and utility PROGRAMS           #
#    and/or modify them under the terms of the GNU General Public            #
#    License as published by the Free Software Foundation; either            #
#    version 2 of the License, or (at your option) any later version.        #
#                                                                            #
#    PFSLib is distributed in the hope that it will be useful,               #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of          #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       #
#    Library General Public License and GNU General Public License           #
#    for more details.                                                       #
#                                                                            #
#    You should have received a copy of the GNU Library General Public       #
#    License and the GNU General Public License along with this              #
#    library; if not, write to the Free                                      #
#    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.      #
#                                                                            #
#    Contact to the authors:                                                 #
#                                                                            #
#    electronic mail: pfslib@informatik.tu-muenchen.de                       #
#                                                                            #
#    paper mail:      Prof. Dr. A. Bode                                      #
#                     Lehrstuhl f"ur Rechnertechnik und                      #
#                     Rechnerorganisation                                    #
#                     Institut f"ur Informatik                               #
#                     Technische Universit"at M"unchen                       #
#                     80290 M"unchen                                         #
#                     Germany                                                #
#                                                                            #
#    This project was partially funded by a research grant form Intel        #
#    Corporation.                                                            #
#                                                                            #
##############################################################################


##############################################################################
#                                                                            #
#  RCS Filename : Makefile,v
#  RCS Date     : 1996/05/29 15:49:20
#  RCS Revision : 1.4
#  RCS Author   : lamberts
#  RCS State    : V2_0_B
#                                                                            #
#  Authors: Stefan Lamberts                                                  #
#                                                                            #
##############################################################################


##############################################################################
# Macros                                                                     #
##############################################################################

SHELL		= /bin/sh

INCLUDEPATH	= ../include
ADDPATH		= ../add

RPCGEN		= rpcgen

ANSI_C		= -DANSI_C
CC		= gcc
CFLAGS		= -ansi -g
CPPFLAGS	= -I$(INCLUDEPATH) $(ANSI_C) -D$(ARCH) $(CPPDEFINES) $(ARCHCPPFLAGS)

LDFLAGS		=
LDLIBS		=
SVCLDLIBS	= -lrpcsvc

LINT		= lint
LINTFLAGS	= -a -b -c -h 
# lint option to create .ln file
LINT_ln		= -i

RM		= rm -f

INSTALLBINDIR	= .

##############################################################################
# Suffixes                                                                   #
##############################################################################

.SUFFIXES: .ln $(SUFFIXES)

.c.o:
	$(CC) $(CFLAGS) $(CPPFLAGS) -c $<

.c.ln:
	$(LINT) $(LINTFLAGS) $(CPPFLAGS) $(LINT_ln) $<

##############################################################################
# Files generated by rcpgen                                                  #
##############################################################################

RPCFILES	=\
	iod_svc.c\
	iod_xdr.c\
	iod_clnt.c\
	iod.h

##############################################################################
# iod server object files generated by rpcgen                                #
##############################################################################

RPCOBJ		=\
	iod_svc.o\
	iod_xdr.o

RPCLNOBJ	= $(RPCOBJ:.o=.ln)

##############################################################################
# iod client object files generated by rpcgen                                #
##############################################################################

CLTOBJ		=\
	iod_clnt.o\
	iod_xdr.o

CLTLNOBJ	= $(CLTOBJ:.o=.ln)

##############################################################################
# iod server files                                                           #
##############################################################################

SVCSRC		=\
	iod_exit.c\
	iod_init.c\
	iod_read.c\
	iod_signal.c\
	iod_sockopt.c\
	iod_trunc.c\
	iod_unlink.c\
	iod_write.c

SVCOBJ		= $(SVCSRC:.c=.o)

SVCLNOBJ	= $(SVCSRC:.c=.ln)

##############################################################################
# additional server object files                                             #
##############################################################################

ADDOBJ	=\
	$(ADDPATH)/add_auth.o\
	$(ADDPATH)/add_error.o\
	$(ADDPATH)/add_xdr.o

##############################################################################
# all object files of iod server                                             #
##############################################################################

ALLSVCOBJ	= $(SVCOBJ) $(RPCOBJ) $(ADDOBJ)

ALLSVCLNOBJ	= $(ALLSVCOBJ:.o=.ln)

##############################################################################
# Main targets                                                               #
##############################################################################

all: iod_client iod_server

iod_client: iod.h $(CLTOBJ)

iod_server: iod

rpc: $(RPCFILES)

##############################################################################
# Installation                                                               #
##############################################################################

inst_files: $(INSTALLBINDIR)/iod

$(INSTALLBINDIR)/iod: iod
	cp iod			$(INSTALLBINDIR)/

uninst_files:
	@if [ "$(INSTALLBINDIR)" != "." ]
	then
		echo "rm -f			$(INSTALLBINDIR)/iod"
		rm -f			$(INSTALLBINDIR)/iod
	fi

##############################################################################
# Dependencies and rules                                                     #
##############################################################################

iod: $(ALLSVCOBJ)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(ALLSVCOBJ) $(SVCLDLIBS) $(LDLIBS)

##########################
# rpcgen generated files #
##########################

iod.h: iod.x $(INCLUDEPATH)/global_rpc.h
	@if { uname -sr | grep "SunOS 4.1" > /dev/null; };\
	then\
		echo "Making $@";\
		$(RPCGEN) -h -T -o $@ iod.x;\
	else\
		echo "Unable to make $@; rpcgen must be run on SunOS 4.1.x";\
		exit 1;\
	fi

iod_svc.c: iod.x $(INCLUDEPATH)/global_rpc.h
	@if { uname -sr | grep "SunOS 4.1" > /dev/null; };\
	then\
		echo "Making $@";\
		$(RPCGEN) -s udp -s tcp iod.x |\
		sed\
		-e '/!svc_sendreply/,/^	}$$/c\
		\
		/* BEGIN PATCH done by Makefile */\
		/* Send reply only if resul != NULL\
		 * otherwise reply has to be delayed and sent by _do_op()\
		 */\
		if (result != NULL) {\
		  if (!svc_sendreply(transp, xdr_result, result)) {\
		    svcerr_systemerr(transp); }}\
		/* END PATCH */\
		'\
		 -e '/switch/i\
		\
		/* BEGIN PATCH done by Makefile */\
		if (!pfslib_auth_ok(rqstp,transp)) return;\
		iod_sockopt(rqstp,transp);\
		/* END PATCH */\
		' > $@;\
	else\
		echo "Unable to make $@; rpcgen must be run on SunOS 4.1.x";\
		exit 1;\
	fi

iod_svc.ln \
iod_svc.o:\
	iod.h\
	$(INCLUDEPATH)/global.h

iod_clnt.c: iod.x $(INCLUDEPATH)/global_rpc.h
	@if { uname -sr | grep "SunOS 4.1" > /dev/null; };\
	then\
		echo "Making $@";\
		$(RPCGEN) -l -o $@ iod.x;\
	else\
		echo "Unable to make $@; rpcgen must be run on SunOS 4.1.x";\
		exit 1;\
	fi

iod_clnt.ln \
iod_clnt.o:\
	iod.h\
	$(INCLUDEPATH)/global.h

iod_xdr.c: iod.x $(INCLUDEPATH)/global_rpc.h
	@if { uname -sr | grep "SunOS 4.1" > /dev/null; };\
	then\
		echo "Making $@";\
		$(RPCGEN) -c -o $@ iod.x;\
	else\
		echo "Unable to make $@; rpcgen must be run on SunOS 4.1.x";\
		exit 1;\
	fi

iod_xdr.ln \
iod_xdr.o:\
	iod.h\
	$(INCLUDEPATH)/global.h

########################
# Regular source files #
########################

iod_exit.ln \
iod_exit.o:\
	$(INCLUDEPATH)/global.h

iod_init.ln \
iod_init.o:\
	iod.h\
	$(INCLUDEPATH)/global.h

iod_read.ln \
iod_read.o:\
	iod.h\
	$(INCLUDEPATH)/global.h\
	$(INCLUDEPATH)/pfslib_errno.h

iod_sockopt.ln \
iod_sockopt.o:\
	iod.h\
	$(INCLUDEPATH)/global.h\
	$(INCLUDEPATH)/rpc_defaults.h

iod_signal.ln \
iod_signal.o:

iod_trunc.ln \
iod_trunc.o:\
	iod.h\
	$(INCLUDEPATH)/global.h\
	$(INCLUDEPATH)/pfslib_errno.h

iod_unlink.ln \
iod_unlink.o:\
	iod.h\
	$(INCLUDEPATH)/pfslib_errno.h

iod_write.ln \
iod_write.o:\
	iod.h\
	$(INCLUDEPATH)/global.h\
	$(INCLUDEPATH)/pfslib_errno.h

##############################################################################
# targets in other directories                                               #
##############################################################################

$(ADDOBJ):
	@echo "Making $@ in directory $(ADDPATH)"
	@(\
		cd $(ADDDPATH);\
		target=`echo $@ | sed -e 's%$(ADDPATH)/%%'`;\
		$(MAKE) $(MFLAGS)\
			"ARCH=$(ARCH)"\
			"CFLAGS=$(CFLAGS)"\
			"ANSI_C=$(ANSI_C)"\
			"CPPDEFINES=$(CPPDEFINES)"\
			"ARCHCPPFLAGS=$(ARCHCPPFLAGS)"\
			"CC=$(CC)"\
			"LINT=$(LINT)"\
			"LINTFLAGS=$(LINTFLAGS)"\
			"LINT_ln=$(LINT_ln)"\
			$$target;\
	)

##############################################################################
# Additional targets                                                         #
##############################################################################

rpcmod:	$(RPCFILES)
	chmod a-w $(RPCFILES)

tags: TAGS

TAGS: $(RPCFILES) $(SVCSRC)
	etags -t $(RPCFILES) $(SVCSRC)


lint: $(SVCLNOBJ) $(RPCLNOBJ) $(CLTLNOBJ)
	$(LINT) $(LINTFLAGS) $(ALLSVCLNOBJ)


clean:
	$(RM)	*.o *.ln iod

rpcclean:
	$(RM)	$(RPCFILES)

realclean: clean
	$(RM)	TAGS *~

##############################################################################
# End of Makefile                                                            #
##############################################################################
