#-----------------------------------------------------------------------------
#  Copyright (c) 1991,1992 Southeastern Universities Research Association,
#                          Continuous Electron Beam Accelerator Facility
# 
#  This software was developed under a United States Government license
#  described in the NOTICE file included as part of this distribution.
# 
#  CEBAF Data Acquisition Group, 12000 Jefferson Ave., Newport News, VA 23606
#  Email: coda@cebaf.gov  Tel: (804) 249-7101  Fax: (804) 249-7363
# -----------------------------------------------------------------------------
#  
#  Description:  Makefile for Trigger Supervisor RPC libraries and Server
# 	
# 	
#  Author:  David Abbott, TJANF Data Acquisition Group
# 
#  Revision History:
#    $Log: Makefile,v $
#    Revision 1.1  2000/08/17 19:22:34  abbottd
#    Initial Revision
#
#

ifndef OSTYPE
  OSTYPE := $(subst -,_,$(shell uname))
endif

ifeq ($(OSTYPE),HP_UX)
LIBS = 
EXTRA = -D_HPUX_SOURCE -Dhpux
endif

ifeq ($(OSTYPE),SunOS)
LIBS = -lrpcsvc -lnsl
EXTRA =
endif

ifndef ARCH
  ARCH=$(OSTYPE)
endif

ifeq ($(ARCH),VXWORKS68K51)

VXWORKS_ROOT = /usr/local/tornado/68k/target

  DEFS   = -m68020 -msoft-float -DCPU=MC68020 -DVXWORKS -DVXWORKS68K51 -O -fvolatile -fstrength-reduce -nostdinc
  INCS   = -I. -I$(VXWORKS_ROOT)/h -I$(VXWORKS_ROOT)/h/rpc -I$(VXWORKS_ROOT)/h/net

  lib_targets      = libts.o
  bin_targets      = tsSrvr
  include_targets  = ts.h ts_macros.h
  
  CC     = cc68k $(INCS) $(DEFS)
  LD     = ld68k
  RPCGEN = /usr/local/tornado/ppc2/target/unsupported/rpc4.0/rpcgen/rpcgen

  sources = tsRpc_svc.c tsRpc_xdr.c tsSrvrLib.c

# explicit targets

all: clean libts.o tsSrvr

install: 
	@echo "installing tsSrvr"
	cp tsSrvr $(CODA)/VXWORKS68K51/bin/tsSrvr
	@echo "installing libts.o"
	cp libts.o $(CODA)/VXWORKS68K51/lib/libts.o

clean:
	rm -f tsRpc_svc.o tsRpc_xdr.o tsSrvrLib.o tsSrvr libts.o

tsSrvr: tsRpc_svc.o tsRpc_xdr.o tsSrvrLib.o
	$(LD) -o $@ -r tsRpc_svc.o tsRpc_xdr.o tsSrvrLib.o
	cp $@ tsSrvr_68k
	rm -f tsRpc_xdr.o

libts.o: libts.c ts.h ts_macros.h
	$(CC) -c libts.c
	cp $@ libts.o.68k

endif


ifeq ($(ARCH),VXWORKSPPC)

VXWORKS_ROOT = /usr/local/tornado/ppc2/target

  DEFS   = -mcpu=604 -DCPU=PPC604 -DVXWORKS -D_GNU_TOOL -nostdinc -fno-for-scope -fno-builtin -fvolatile -DVXWORKSPPC
  INCS   = -I. -I$(VXWORKS_ROOT)/h -I$(VXWORKS_ROOT)/h/rpc -I$(VXWORKS_ROOT)/h/net

  lib_targets      = libts.o
  bin_targets      = tsSrvr
  include_targets  = ts.h ts_macros.h
  
  CC     = ccppc $(INCS) $(DEFS)
  LD     = ldppc
  RPCGEN = /usr/local/tornado/ppc2/target/unsupported/rpc4.0/rpcgen/rpcgen

  sources = tsRpc_svc.c tsRpc_xdr.c tsSrvrLib.c

# explicit targets

all: clean libts.o tsSrvr

install: 
	@echo "installing tsSrvr"
	cp tsSrvr $(CODA)/VXWORKSPPC/bin/tsSrvr
	@echo "installing libts.o"
	cp libts.o $(CODA)/VXWORKSPPC/lib/libts.o

clean:
	rm -f tsRpc_svc.o tsRpc_xdr.o tsSrvrLib.o tsSrvr libts.o

tsSrvr: tsRpc_svc.o tsRpc_xdr.o tsSrvrLib.o
	$(LD) -o $@ -r tsRpc_svc.o tsRpc_xdr.o tsSrvrLib.o
	cp $@ tsSrvr_ppc
	rm -f tsRpc_xdr.o

libts.o: libts.c ts.h ts_macros.h
	$(CC) -c libts.c
	cp $@ libts.o.ppc

endif


ifeq ($(ARCH),SunOS)

  DEFS   =
  INCS   =

  lib_targets      = libts.a
  bin_targets      = tsp
  include_targets  = ts.h ts_macros.h
  
  CC     = cc
  CCOPTS = -O -I.
  LD     = ld
  RPCGEN = /usr/local/tornado/ppc2/target/unsupported/rpc4.0/rpcgen/rpcgen

  sources = tsp.c tsRpc_clnt.c tsRpc_xdr.c tsSrvrLib.c

# explicit targets

all: clean libts.a tsp

install:
	@echo "installing libts.a, ts.h, ts_macros.h and tsp"
	cp libts.a $(CODA_LIB)/libts.a
	cp ts.h $(CODA)/common/include/ts.h
	cp ts_macros.h $(CODA)/common/include/ts_macros.h
	cp tsp $(CODA_BIN)/tsp

libts.a: tsRpc.h tsRpc_clnt.o tsClientLib.o tsRpc_xdr.o
	rm -f $@
	ar cr $@ tsClientLib.o tsRpc_clnt.o tsRpc_xdr.o
	rm -f tsRpc_xdr.o
	ranlib $@

tsp: tsp.c libts.a
	$(CC) $(CCOPTS) -o $@ tsp.c -L. -lts $(LIBS)

clean:
	rm -f  tsRpc_clnt.o tsRpc_xdr.o tsClientLib.o tsp.o tsp libts.a

endif

tsRpc_xdr.o: tsRpc_xdr.c
	$(CC) -c $(CCOPTS) tsRpc_xdr.c

tsRpc_svc.c: tsRpc.x
	$(RPCGEN) -o tsRpc_svc1.c -s tcp tsRpc.x
	awk -f modify_server_code.awk tsRpc_svc1.c > $@

tsRpc_xdr.c: tsRpc.x
	$(RPCGEN) -o $@ -c tsRpc.x

tsRpc_clnt.c: tsRpc.x
	$(RPCGEN) -o $@ -l tsRpc.x

tsRpc.h: tsRpc.x
	$(RPCGEN) -o $@ -h tsRpc.x

cleanall:
	rm -f *.o *~ tsp libts.a tsSrvr tsRpc.h tsRpc_clnt.c tsRpc_xdr.c  tsRpc_svc.c \
                     libts.o.68k libts.o.ppc tsSrvr_68k tsSrvr_ppc







