#
# 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.
#

TOP=..
include $(TOP)/rules

ARCH	= linux
LWP	= $(ARCH)/liblwp.a
LWPORDIR= $(TOP)/lwp-0.2d
LWPORIG	= $(LWPORDIR)/$(ARCH)/liblwp.a

CPPFLAGS+= -DARCH_HDR=\"linux.h\" # -I$(LWPORDIR)
CXXFLAGS+= -DARCH_HDR=\"linux.h\" # -I$(LWPORDIR)
CFLAGS  += -DARCH_HDR=\"linux.h\" # -I$(LWPORDIR)

SRCXX	= LWP.cc
OBJ	= $(SRCXX:.cc=.o)
DEP	= $(foreach obj, $(OBJ), $(LWP)($(obj)))
HDR	= LWP.h
ALLHDRS	= $(HDR) $(foreach a, $(ARCHES), $(a).h)
ARFLAGS	= rs

.PRECIOUS: $(LWP)
.KEEP_STATE:

all:: lwp.h $(LWPORIG) liblwp.a

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

$(LWPORIG):
	( cd $(LWPORDIR) ; ./config linux-elf )
	make -C $(LWPORDIR)
	( cd $(LWPORDIR) ; ./config linux )
	make -C $(LWPORDIR)

$(LWP): $(LWPORIG) $(ARCH) $(HDR) $(DEP) $(OBJ) 
	cp -b $(LWPORIG) $(LWP)
	ar $(ARFLAGS) $(LWP) $(OBJ)
	ranlib $(LWP)

$(DEP):	$(HDR)

$(ARCH):
	-mkdir $@

lwp.h: 	$(LWPORDIR)/lwp.h
	+ln -s $(LWPORDIR)/lwp.h .

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

clean::
	-rm -rf  linux lwp.h core a.out \
		.depend  *.o *.a *~

distclean: clean
	-rm -f arch


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