#
# 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 or with the express written consent of
# Sun Microsystems, Inc.
#
# 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.16 91/03/11 TIRPC 1.0; from 1.80 89/12/13 SMI
#
# Copyright (c) 1987, 1990 by Sun Microsystems, Inc.
#
# Sources are organized in a hierarchy according to function, OS-type,
# and machine.  At the highest level things with similar function are
# grouped together.
#
#       The "all" target builds an optimized, profiled, debug and shared
#       (pic) version of the library for the current architecture.
#       Objects are build in $VARIANT/$@.o. VARIANT is a combination of
#       system architecture and compiling options, ARCH/OPTION, producing
#       two subdirectory hierarchies.  The first level is the architecture
#	(currently one of sun2, sun3 or sun4), and the second level is
#       the compile option (one of obj (optimized), obj_p (profiled), obj_g
#       (debugging) or shared (pic)).
#
#       For the shared library, the current version (major.minor) is
#       found in the file "vers-$ARCH".   This is appended to the library
#	name when it is installed.  
#
#       Also note that the shell script install_librpc.sh is used to install
#       the shared version of the library.
#
all:	xall

include Makefile.arch
include Makefile.master
MAKE_INCLUDE = Makefile.arch Makefile.master $(VERS$(TARGET_MACH)) install_librpc.sh
INSTALL = install
COMMDIRS = netdir netsel rpc yp-compat
ALLDIRS = $(COMMDIRS)
GLOBAL_DATA = rpc_comdata.o nd_comdata.o
GLOBAL_DATA-sparc =

# NOTE - Major version numbers are machine dependent.

VERS-sparc =  vers-sparc

librpc.so	:= SUBDIRS = $(COMMDIRS)
librpc.a librpc_p.a  librpc_g.a := SUBDIRS = $(COMMDIRS)

librpc.so	:= DIRS = $(COMMDIRS:%=%/shared/*.o)
librpc.a	:= DIRS = $(COMMDIRS:%=%/obj/*.o)
librpc_p.a 	:= DIRS = $(COMMDIRS:%=%/obj_p/*.o)
librpc_g.a 	:= DIRS = $(COMMDIRS:%=%/obj_g/*.o)

BUILD = ar rv $(LIB) $?; ranlib $(LIB)

librpc.so	:= BUILD = rm -rf shared; mkdir shared; \
		ln $(DIRS) shared; \
		xstr -l librpc_xstr;\
		$(CC) $(CFLAGS$(TARGET_MACH)) $(CFLAGS) -R -c -pic xs.c;\
		mv xs.o shared;\
		$(LD) -Bsymbolic=object_globals -assert pure-text `lorder shared/*.o | tsort`;\
		mv a.out $(LIB);

XSTR = strings
MEMBERS =  $(LIB)($(DIRS))
librpc.so 	:= MEMBERS = $(DIRS)

.INIT: $(MAKE_INCLUDE) object_globals

.PRECIOUS: $(LIBS)

xall: $(MAKE_INCLUDE) $(LIBS) $(LIBS_SA)

$(LIBS) : $(XSTR) $$(SUBDIRS) $$@_BUILT

LIB_BUILT = $(LIBS:%=%_BUILT)
$(LIB_BUILT) :  $$(MEMBERS)
	$(BUILD)
	touch $@

$$(LIB)(%.o) : %.o
	@true

$$(DIRS):
	@true

$(XSTR) : FRC
	@if [ ! -f strings ]; then \
		make clean;\
	fi

$(COMMDIRS) : FRC
	cd $@; $(MAKE) $(MFLAGS) $(LIB)

librpc.sa: librpc.a
	ar x librpc.a $(GLOBAL_DATA) $(GLOBAL_DATA$(TARGET_MACH))
	ar rv $@ $(GLOBAL_DATA) $(GLOBAL_DATA$(TARGET_MACH))
	ranlib $@

clean:
	-for i in ${ALLDIRS}; do (cd $$i; $(MAKE) clean); done
	rm -rf tmp version *.o strings
	rm -rf librpc.a librpc_p.a librpc_g.a librpc.so librpc.sa
	rm -rf librpc.a_BUILT librpc_p.a_BUILT librpc_g.a_BUILT \
		librpc.so_BUILT librpc.sa

international:
	$(MAKE) $(MFLAGS) DESTDIR=$(DESTDIR) IFLAGS="$(IFLAGS)" \
	    LDFLAGS="$(LDFLAGS)" -f Makefile.inter

install: $(VERS$(TARGET_MACH)) $(LIBS) $(LIBS_SA)
	-for i in ${ALLDIRS}; do (cd $$i; $(MAKE) install); done
	install -d -m 755 ${DESTDIR}/lib
	${INSTALL} -m 644 librpc.a ${DESTDIR}/lib/librpc.a
	ranlib ${DESTDIR}/lib/librpc.a
	${INSTALL} -m 644 librpc_p.a ${DESTDIR}/lib/librpc_p.a
	ranlib ${DESTDIR}/lib/librpc_p.a
	if [ -s $(VERS$(TARGET_MACH)) ]; then \
		sh -x install_librpc.sh $(INSTALL) $(VERS$(TARGET_MACH)) $(DESTDIR); \
	fi;

FRC:
