#
# Sun RPC is a product of Sun Microsystems, Inc. and is provided for
# unrestricted use provided that this legend is included on all tape
# media and as a part of the software program in whole or part.  Users
# may copy or modify Sun RPC without charge, but are not authorized
# to license or distribute it to anyone else except as part of a product or
# program developed by the user.
#
# SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
# WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
# PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
#
# Sun RPC is provided with no support and without any obligation on the
# part of Sun Microsystems, Inc. to assist in its use, correction,
# modification or enhancement.
#
# SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
# INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
# OR ANY PART THEREOF.
#
# In no event will Sun Microsystems, Inc. be liable for any lost revenue
# or profits or other special, indirect and consequential damages, even if
# Sun has been advised of the possibility of such damages.
#
# Sun Microsystems, Inc.
# 2550 Garcia Avenue
# Mountain View, California  94043
#

#  @(#)makefile 1.2 92/06/22 SMI

# Makefile to make the client and server for the performance test
# programs

CC = /opt/SUNWste/bin/cc
AS = /usr/ccs/bin/as


RPCGEN = /usr/bin/rpcgen
RPCGENFLAGS = -C

INCDIRS = 
OPT =  
DEFINE = -DSVR4  -DMICROTIMER
TARGET = 

CFLAGS += $(INCDIRS) $(DBG) $(OPT) $(DEFINE)
ASFLAGS += -P $(DEFINE)
LIBS +=  -lnsl -lm
HFILES = test.h

SVCSRCS = 	server.c  \
		test_main.c \
	        test_svc.c \
		test_xdr.c


CLNTSRCS = 	client.c \
		stat.c \
		test.c \
		test_clnt.c \
		test_xdr.c \
		util.c 


SVCTLISRCS =	server_tli.c

CLNTTLISRCS =	clnt_tli.c \
		clnt_tli_lib.c \
		stat.c \
		test.c \
		test_xdr.c \
		util.c 

RAWSRCS =	test_clnt.c \
		test_raw.c \
		raw_server.c \
		raw_test_svc.c \
		stat.c \
		test.c \
		test_xdr.c \
		util.c 

AS_SRC = gethrtime.s

AS_OBJS = $(AS_SRC:%.s=bin$(TARGET)/%.o)

# how to convert .c files into .o files
bin$(TARGET)/%.o profile$(TARGET)/%.o : %.c
	$(COMPILE.c) -o $@ $<

bin$(TARGET)/%.o profile$(TARGET)/%.o : %.s
	$(COMPILE.s) -o $@ $<

# profile only the main RPC test files.
PROFILE_S = profile$(TARGET)/server 	
PROFILE_C = profile$(TARGET)/client

ALL_S = bin$(TARGET)/server
ALL_C = bin$(TARGET)/client
ALL_S_TLI = bin$(TARGET)/server_tli
ALL_C_TLI = bin$(TARGET)/client_tli
ALL_CRAW = bin$(TARGET)/client_raw

ALL =  $(ALL_S) $(ALL_C) $(ALL_CRAW) $(ALL_S_TLI) $(ALL_C_TLI)

# targets 
all: bin$(TARGET) $(HFILES) $(ALL) $(AS_OBJS)
profile: profile$(TARGET) $(HFILES) $(PROFILE_S) $(PROFILE_C)

server: bin$(TARGET) $(HFILES) $(ALL_S)
client: bin$(TARGET) $(HFILES) $(ALL_C) $(AS_OBJS)
server_tli: bin$(TARGET) $(HFILES) $(ALL_S_TLI)
client_tli: bin$(TARGET) $(HFILES) $(ALL_C_TLI) $(AS_OBJS)
client_raw: bin$(TARGET) $(HFILES) $(ALL_CRAW) $(AS_OBJS)

# profile
$(PROFILE_S) $(PROFILE_C) $(PROFILE_CRAW) :=	CFLAGS += -DGPROF -pg -O
$(PROFILE_S)	:=	OBJS = $(SVCSRCS:%.c=profile$(TARGET)/%.o)
$(PROFILE_C)	:=	OBJS = $(CLNTSRCS:%.c=profile$(TARGET)/%.o) $(AS_OBJS)
$(PROFILE_CRAW)	:=	OBJS = $(RAWSRCS:%.c=profile$(TARGET)/%.o) 
			OBJS = $(RAWSRCS:%.s=profile$(TARGET)/%.o)

# all 
$(ALL_S)	:=	OBJS = $(SVCSRCS:%.c=bin$(TARGET)/%.o)
$(ALL_C)	:=	OBJS = $(CLNTSRCS:%.c=bin$(TARGET)/%.o) $(AS_OBJS)
$(ALL_S_TLI)	:=	OBJS = $(SVCTLISRCS:%.c=bin$(TARGET)/%.o)
$(ALL_C_TLI)	:=	OBJS = $(CLNTTLISRCS:%.c=bin$(TARGET)/%.o) $(AS_OBJS)
$(ALL_CRAW)	:=	OBJS = $(RAWSRCS:%.c=bin$(TARGET)/%.o) $(AS_OBJS)

ALL_OBJS =	$(SVCSRCS:%.c=bin$(TARGET)/%.o) \
		$(CLNTSRCS:%.c=bin$(TARGET)/%.o) \
		$(SVCTLISRCS:%.c=bin$(TARGET)/%.o) \
		$(CLNTTLISRCS:%.c=bin$(TARGET)/%.o) \
		$(RAWSRCS:%.c=bin$(TARGET)/%.o) \
		$(AS_OBJS)
# directories
profile$(TARGET) bin$(TARGET):
	-mkdir $@

$(PROFILE_S) $(PROFILE_C) $(ALL): $$(OBJS) $(HEADER) $(TEST_SOBJ)
	$(LINK.c)  -o $@ $(OBJS) $(TEST_SOBJ) $(LIBS)

test.h: test.x
	$(RPCGEN) $(RPCGENFLAGS) -h -o test.h test.x

test_svc.c: test.x
	$(RPCGEN) $(RPCGENFLAGS) -m -o test_svc.c test.x

test_clnt.c: test.x
	$(RPCGEN) $(RPCGENFLAGS) -l -o test_clnt.c test.x

test_xdr.c: test.x
	$(RPCGEN) $(RPCGENFLAGS) -c -o test_xdr.c test.x

test_raw.o raw_server.o test.o:	 $(HFILES)

client.o server.o test_main.o  test_clnt.o test_svc.o test_xdr.o : $(HFILES)

clean:
	/bin/rm -f $(ALL_OBJS) test.h test_xdr.c test_svc.c test_clnt.c
