#
# lib/Makefile
#
# x-kernel v3.3
#
# Copyright (c) 1996,1993,1991,1990  Arizona Board of Regents
#
# $Log: Makefile,v $
# Revision 1.4  1996/06/05 16:39:24  slm
# Removed references to pthreads-fsu, which is no longer required on linux.
#
# Revision 1.3  1996/02/07  18:24:48  slm
# Cosmetic changes.
#
# Revision 1.2  1996/02/02  23:33:57  slm
# Cosmetic changes.
#
# Revision 1.1  1995/07/28  21:34:08  slm
# Initial revision
#
# Revision 1.2.1.1.1.2  1994/11/22  20:43:34  hkaram
# Added tcplib and pthreads lib.
#
# Revision 1.2.1.1.1.1  1994/11/14  23:10:06  hkaram
# New branch
#
# Revision 1.2.1.1  1994/01/10  20:00:38  menze
# If XK_BIN_TYPE is not defined, use ARCH instead.
#
# Revision 1.1  1994/01/06  00:16:18  menze
# Initial revision
#
# -----------------------------------------------------------------
# Libraries are built in subdirectories of each library source area,
# named for the object type (XK_BIN_TYPE).  
# 
# When a build for a new XK_BIN_TYPE is performed for a library, a new
# subdirectory of the library source area is created and the 'xksetup'
# target is run from that directory, using the parent directory (i.e.,
# the library source directory) Makefile.  Makefiles for new libraries
# should add support for the xksetup target to take whatever actions are
# appropriate to make subsequent 'make' invocations from the
# subdirectory work properly.  (This typically involves setting up
# symbolic links.)
# 
# When adding new libraries, modify DIRS, LIBS, and the sections
# marked 'NEW LIBRARIES' below.

ifeq ($(XK_BIN_TYPE),)
XK_BIN_TYPE = $(ARCH)
endif

ifeq ($(XK_BIN_TYPE),)
install verify def1:
	@echo "Make variables ARCH or XK_BIN_TYPE must be defined"
else

DIRS = tcplib
LIBS = libtcp.a

ifeq ($(XPLATFORM), solaris)
DIRS += pthreads
LIBS += libpthreads.a
endif

ifeq ($(XPLATFORM), sunos)
DIRS += pthreads
LIBS += libpthreads.a
endif

LIB_TARGETS = $(addprefix $(XK_BIN_TYPE)/, $(LIBS))

AR=ar
SHELL = /bin/sh

default: install

# Just rebuild libraries, don't install them in the public areas. 

local_only: LOOP

# NEW LIBRARIES: Add a dependency line for each library 

$(XK_BIN_TYPE)/libpthreads.a: pthreads/$(XK_BIN_TYPE)/libpthreads.a
$(XK_BIN_TYPE)/libtcp.a: tcplib/$(XK_BIN_TYPE)/libtcp.a

COPY_RULE = @echo installing $@ ; cp $< $@ ; $(RANLIB) $@

# NEW LIBRARIES: Add one of these rules for each library directory

$(XK_BIN_TYPE)/%.a: pthreads/$(XK_BIN_TYPE)/%.a
	$(COPY_RULE)

$(XK_BIN_TYPE)/%.a: tcplib/$(XK_BIN_TYPE)/%.a
	$(COPY_RULE)

depend clean:
ifeq ($(DIRS),)
	@true
else
	@make LOOP TARGET=$@
endif

.PHONY: LOOP
LOOP:
	@dirs="$(DIRS)" ;                                                  \
	for dir in $$dirs ; do                                             \
	    echo $$dir ;                                                   \
	    if [ ! -d $$dir/$(XK_BIN_TYPE) ] ; then                        \
	        echo Creating new object directory: $$dir/$(XK_BIN_TYPE) ; \
	        mkdir $$dir/$(XK_BIN_TYPE) ;                               \
	        cd $$dir/$(XK_BIN_TYPE) ;                                  \
	        make -f ../Makefile xksetup ;                              \
	    else                                                           \
	        cd $$dir/$(XK_BIN_TYPE) ;                                  \
	    fi ;                                                           \
	    $(MAKE) $(TARGET) ;                                            \
	    cd ../.. ;                                                     \
	done
	@true

install: LOOP 
	@if [ ! -d $(XK_BIN_TYPE) ] ; then \
	    mkdir $(XK_BIN_TYPE) ;         \
	else                               \
	    true ;                         \
	fi
	@make $(LIB_TARGETS)

# NEW LIBRARIES: If there is a verification suite for the library, put 
# rules for running it here.

endif
