#
# SCCS INFO
#      %W% %G%
#
# Kim Gillies	June 1992
#
# make--make the package.
# make depend--rebuild the make file dependencies.
#
.KEEP_STATE:

# Set this variable to the directory that holds the tclIPC distribution
TclIpcDir = /home/gillies/ui/tclipc

# If you don't have Extended TCL set TclDir to the location of
# the TCL source directory and use the second, augmented
# source list
TclDir = /mpgc/tclstuff/tk2.3/tcl

# Set the extended location to the extended TCL location if you have it.
ETclDir = /mpgc/tclstuff/extended/src

# Location of your tcl or extended tcl library
#TclLibDir = /usr/local/lib
TclLibDir = /mpgc/tclstuff/tk2.3/tcl

# -------  Installation places ----------------
# Where should the library file go?
DestDir = /usr/local/lib

# Where should the public .h file go
IncludeDir = /usr/include/tclIPC

# ----------  Compiler stuff -----------------
# New rpcgen or old
#RPCGEN = rpcgen.new -b -C -a
RPCGEN = rpcgen 

# Uncomment these two lines to use that old C
#CC = cc
#MYCFLAGS = -g

# Yes, ANSI C
CC = gcc
MYCFLAGS = -ggdb  -O -W -Wswitch -Wreturn-type -Wunused -Wcomment

# ----------- Nothing should change past this point --------------

INCLUDES= -I$(TclDir) 
CFLAGS = $(MYCFLAGS) $(INCLUDES)

LIB=libtclIPC.a
CLIENT=ipc
OTHERS=pmgr multi
XFILE=tclIPC
# Needed when I use CodeCenter
GCCLIB = /usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.2.2/libgcc.a

#Files required to add handles to library
HANDLES=handles.c extendUtil.c 

# Files generated by RPCGEN
SRVRNEEDED= $(XFILE)_xdr.c $(XFILE)_ksvc.c $(XFILE)_clnt.c

OTHERSOURCE= Sender.c Receiver.c rpcMods.c \
	  tclipc.c PortMgrUser.c cmdsend.c ipcHandles.c dispatch.c svc_tcp.c

# Use this if you do not have Extended TCL
SRVRSOURCES= $(SRVRNEEDED) $(HANDLES) $(OTHERSOURCE)

# Use this if you have Extended TCL
#SRVRSOURCES= $(SRVRNEEDED) $(OTHERSOURCE)

SRVROBJECTS= $(SRVRSOURCES:.c=.o) 

CLNTSOURCES=tclmain.c
CLNTOBJECTS= $(CLNTSOURCES:.c=.o)

all:	$(LIB) $(CLIENT) $(OTHERS)
	@echo Build of tclIPC is complete.

#
# The client program 
#
$(CLIENT):	$(CLNTOBJECTS) $(LIB)
	$(CC) $(CLNTOBJECTS) -o $@ $(LIB) -L$(TclLibDir) -ltcl 

#
# The library routines
#
$(LIB): $(SRVROBJECTS)
	$(RM) $(LIB); \
	ar cr $(LIB) $(SRVROBJECTS); \
	ranlib $(LIB)

# Create the RPC files
$(XFILE)_ksvc.o:   $(XFILE).x $(XFILE).h
	rm -f $(XFILE)_svc.c
	$(RPCGEN) -m -o $(XFILE)_svc.c $(XFILE).x
	sed s/cmdsend_4\;/cmdsend_4_svc\;/g $(XFILE)_svc.c > $(XFILE)_ksvc.c
	$(CC) $(CFLAGS) -c $(XFILE)_ksvc.c

$(XFILE)_xdr.o:   $(XFILE).x $(XFILE).h
	rm -f $(XFILE)_xdr.c
	$(RPCGEN) -c -o $(XFILE)_xdr.c $(XFILE).x
	$(CC) $(CFLAGS) -c $(XFILE)_xdr.c

$(XFILE)_clnt.o:  $(XFILE).x $(XFILE).h
	rm -f $(XFILE)_clnt.c
	$(RPCGEN) -l -o $(XFILE)_clnt.c $(XFILE).x
	$(CC) $(CFLAGS) -c $(XFILE)_clnt.c

$(XFILE).h:       $(XFILE).x
	rm -f $(XFILE).h
	$(RPCGEN) -h -o $(XFILE).h $(XFILE).x

#
# Others in the lower-level directorys
#
pmgr:	$(LIB) FORCE
	cd $(@F); $(MAKE) 'CC=$(CC)' 'MYCFLAGS=$(CFLAGS) -I$(ETclDir)' \
         'TclLibDir=$(TclLibDir)'

multi:	$(LIB) FORCE
	cd $(@F); $(MAKE) 'CC=$(CC)' 'MYCFLAGS=$(CFLAGS)' \
         'TclLibDir=$(TclLibDir)'

# build some other files
handles.o:
	cd extended;$(MAKE) -$(MAKEFLAGS) all 'CFLAGS= -I$(TclDir)'

ipcHandles.o:
	$(CC) $(CFLAGS) -I$(ETclDir) -c $<

svc_tcp.o:
	cc -g -c svc_tcp.c

FORCE:

print:
	vgrind -t *.c *.h | lpr -t -Plw10

install:
	cp $(LIB) $(DestDir)
	@ranlib $(DestDir)/$(LIB)
	cp tclipc.h $(IncludeDir)

depend:	
	@echo 'Making Dependencies'
	@cc -M $(INCLUDES) $(SRC) > makedep
	@echo '$$r makedep' >>eddep
	@echo '/^# DO NOT DELETE THIS LINE/+1,$$d' >>eddep
	@echo '$$r makedep' >>eddep
	@echo 'w' >>eddep
	@cp Makefile Makefile.bak
	@ed - Makefile < eddep
	@rm eddep makedep

saber_src:
	#load $(MYCFLAGS) $(SRVRSOURCES) $(CLNTSOURCES) $(GCCLIB) -ltcl -lm

saber_obj:
        #load $(OBJECTS) $(LLIBS)

clean:
	rm -rf *.o core $(CLIENT) $(LIB) .nse* .make.state
	cd extended; make clean
	cd pmgr; make clean
	cd tk; make clean
	cd multi; make clean
	cd olit; make clean
	cd xview; make clean

# DO NOT DELETE THIS LINE -- make depend uses it
