# threads/Makefile
#
# $Source: /usr0/ecc/nectar/src/cab/threads/RCS/Makefile,v $
#
# $Header: Makefile,v 1.6 88/05/09 16:03:06 ecc Exp $
#
# Makefile for threads package.
#
# Parameters for "generic" rules:
#
#	LIB		libthreads.a or libthreads_p.a
#
#	PROFILE		null, -p, or -pg
#
# Implicit parameters:
#
#	machine		machine type, set by make

INCDIR = ../../../include
LIBDIR = ../../../lib
LIB = libthreads.a
PROFILE =
COMMONFLAGS = -I$(INCDIR)
CFLAGS = -g $(COMMONFLAGS) $(PROFILE)
LINTFLAGS = -u $(COMMONFLAGS)

# Use the following definition to enable inline expansion.
INLINE = $(LIBDIR)/thread_inline
# Use the following definition to disable inline expansion.
# INLINE = cat

.SUFFIXES: .c .o

.c.o:
	$(CC) $(CFLAGS) -S $*.c
	mv $*.s $*.S
	$(INLINE) $(LIBDIR) $*.S > $*.s
	$(AS) -o $@ $*.s
	rm -f $*.s $*.S

SRCS = mutex.c procs.c stack.c threads.c time.c unix.c

OBJS = mutex.o procs.o stack.o \
       threads.o time.o unix.o \
       csw.o lock.o

all: machine $(LIB)

$(LIB): $(OBJS)
	ar r $(LIB) $?
	ranlib $(LIB)

$(OBJS): $(INCDIR)/nectar_sys.h $(INCDIR)/threads.h thread_internals.h

time.o unix.o: $(INCDIR)/time.h

csw.o: machine/csw.s
	$(AS) -o csw.o machine/csw.s

lock.o: machine/lock.s
	$(AS) -o lock.o machine/lock.s

lint:
	lint $(LINTFLAGS) $(SRCS)

machine:
	-@if [ -d machine ] ; then \
		true ; \
	else \
		if [ "$(machine)" ] ; then \
			echo Linking machine to $(machine) ; \
			ln -s $(machine) machine ; \
		else \
			echo Unable to determine machine type. ; \
			echo Please make symbolic link manually. ; \
			false ; \
		fi ; \
	fi

clean:
	-rm -f $(LIB) a.out core errs *.d *.s *.S *.o *.BAK *.CKP
