#
# Makefile for the lightweight process library
# Stephen Crane, March and April 1991, March and April 1992
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
# 
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Library General Public License for more details.
# 
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
.SUFFIXES: .tex .dvi .ps

TOP=..
include $(TOP)/rules

LIB	= /usr/local/lib
#DEBUG	= -g -O2
DVIPS	= dvips $< -o $@

#ARCH	= $(shell "./arch")
ARCH	= linux
LWP	= $(ARCH)/liblwp.a
DOC	= lwp.ps

ARCHES	= sun3 sun4 mips linux 386bsd
SRC	= lwp.c sem.c queue.c clk.c sig.c
SRCXX	= LWP.cc
ALLSRC	= $(SRC) $(foreach a, $(ARCHES), $(a).c)
TESTS	= bm.c producer.c timer.c 
OBJ	= $(SRC:.c=.o) $(SRCXX:.cc=.o) arch.o
DEP	= $(foreach obj, $(OBJ), $(LWP)($(obj)))
HDR	= lwp.h
ALLHDRS	= $(HDR) $(foreach a, $(ARCHES), $(a).h)
OTHERS	= lwp.tex config Makefile COPYING-LIB README
#CFLAGS	= $(DEBUG)
#CXXFLAGS= $(DEBUG)
ARFLAGS	= r

.PRECIOUS: $(LWP)
.KEEP_STATE:

all:: liblwp.a

liblwp.a: $(LWP)
	ln -sf $(LWP) liblwp.a

$(LWP): $(ARCH) $(HDR) $(DEP) 
	ranlib $(LWP)

$(DEP):	$(HDR)

arch.c:
	-ln -s $(ARCH).c $@

arch.h:
	-ln -s $(ARCH).h $@

$(ARCH): arch.c arch.h
	-mkdir $@

.tex.dvi:
	latex $<
	rm $*.aux $*.log

.dvi.ps:
	$(DVIPS)

install:
	@-mkdir -p $(LIB)/$(ARCH) $(LIB)/$(INCLUDE) $(LIB)/doc
	cp $(LWP) $(LIB)/$(LWP)
	ranlib $(LIB)/$(LWP)
	install -c -m 0644 $(HDR) $(LIB)/include
	install -c -m 0644 $(DOC) $(LIB)/doc

distrib: $(ALLHDRS) $(ALLSRC) $(TESTS) $(OTHERS)
	tar cf lwp.tar $(ALLHDRS) $(ALLSRC) $(TESTS) $(OTHERS)
	gzip lwp.tar

clean::
	-rm -rf sun3 sun4 mips linux 386bsd arch.c arch.h core a.out \
		.depend lwp.aux lwp.dvi lwp.log lwp.ps lwp.tar *.o *.a *~

distclean: clean
	-rm -f arch


depend dep:: dummy arch.h
	$(CPP) $(CPPFLAGS) -M *.c *.cc> .depend
