include Make.def

MAJOR_VERSION=0
MINOR_VERSION=6
LIBNAME_BASE=libqpthr.so
LIBNAME_S=libqpthr.a

#
# Solaris Intel, SUNWspro 4.2
#
ifeq ($(DEST), Solaris_Intel)
LIBNAME=$(LIBNAME_BASE).$(MAJOR_VERSION).$(MINOR_VERSION)
LDFLAGS=-G -mt
LDLIBS=
CFLAGS=-g -pta -mt -pic -D_REENTRANT -DSOLARIS -DSUNWSPRO42 -I$(STL_INC) -I.
ARCH_OBJ=arch/i386/spinlock_sunwspro.o
CXX=CC
INSTALL=/usr/sbin/install
endif

#
# Linux Intel, EGCS 1.1.1
#
ifeq ($(DEST), Linux_Intel)
LIBNAME=$(LIBNAME_BASE).$(MAJOR_VERSION).$(MINOR_VERSION)
LDFLAGS=-shared -Wl,-soname,$(LIBNAME_BASE).$(MAJOR_VERSION)
LDLIBS=
CFLAGS=-g -fPIC -Wall -D_REENTRANT -DLINUX -DEGCS111 -I.
ARCH_OBJ=arch/i386/spinlock_gnu.o
CXX=g++
INSTALL=/usr/bin/install
endif

#
# DEC Alpha, DEC C++ 6.0
#
ifeq ($(DEST), OSF1_Alpha)
LIBNAME=$(LIBNAME_BASE)
LDFLAGS=-shared -set_version $(LIBNAME_BASE).$(MAJOR_VERSION)
LDLIBS=-lrt -pthread
CFLAGS=-g -pta -pthread -D_REENTRANT -DOSF1 -DDECCXX60 -I.
ARCH_OBJ=arch/alpha/spinlock.o
CXX=cxx
INSTALL=/usr/bin/install
endif


all2: $(LIBNAME) links

all: $(LIBNAME) $(LIBNAME_S) links



$(LIBNAME): qp.o qp_base.o qp_synch.o qp_thr.o qp_sig.o \
		qp_timer.o qp_misc.o $(ARCH_OBJ)
	$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)

$(LIBNAME_S): qp.o qp_base.o qp_synch.o qp_thr.o qp_sig.o \
		qp_timer.o qp_misc.o $(ARCH_OBJ)
	ar -rs $@ $^
ifeq ($(DEST), Solaris_Intel)
	find Templates.DB \( -type f -a -name \*.o \) -print >/tmp/templates.oo
	ar -rs $@ `cat /tmp/templates.oo`
	rm -f /tmp/templates.oo
	ranlib $@
endif
ifeq ($(DEST), OSF1_Alpha)
	find cxx_repository \( -type f -a -name \*.o \) -print >/tmp/templates.oo
	ar -rs $@ `cat /tmp/templates.oo`
	rm -f /tmp/templates.oo
	ranlib $@
endif

.cc.o:
	$(CXX) ${CFLAGS} -c -o $@ $<

links:
	ln -sf $(LIBNAME) $(LIBNAME_BASE)
	ln -sf $(LIBNAME) $(LIBNAME_BASE).$(MAJOR_VERSION)



install:
	@if [ ! -x "$(INSTALL)" ]; then echo set INSTALL variable in Makefile; exit 1; fi
ifeq ($(DEST), Linux_Intel)
	$(INSTALL) -d $(INST_PREFIX)/include/qpthr $(INST_PREFIX)/lib
	$(INSTALL) -m 0644 *.h    $(INST_PREFIX)/include/qpthr
	$(INSTALL) -m 0755 $(LIBNAME)  $(INST_PREFIX)/lib

	ln -sf $(LIBNAME) $(INST_PREFIX)/lib/$(LIBNAME_BASE)
	ln -sf $(LIBNAME) $(INST_PREFIX)/lib/$(LIBNAME_BASE).$(MAJOR_VERSION)

	$(INSTALL) -m 0644 $(LIBNAME_S)  $(INST_PREFIX)/lib
endif
ifeq ($(DEST), Solaris_Intel)
	$(INSTALL) -d $(INST_PREFIX)/include/qpthr $(INST_PREFIX)/lib
	for i in *.h; do \
		$(INSTALL) -m 0644 -f $(INST_PREFIX)/include/qpthr $$i ;\
	done
	$(INSTALL) -m 0755 -f $(INST_PREFIX)/lib $(LIBNAME)  

	ln -s $(LIBNAME) $(INST_PREFIX)/lib/$(LIBNAME_BASE)
	ln -s $(LIBNAME) $(INST_PREFIX)/lib/$(LIBNAME_BASE).$(MAJOR_VERSION)

	$(INSTALL) -m 0644 -f $(INST_PREFIX)/lib $(LIBNAME_S)
endif
ifeq ($(DEST), OSF1_Alpha)
	if [ ! -d $(INST_PREFIX)/include/qpthr ]; then mkdir -p $(INST_PREFIX)/include/qpthr; fi
	if [ ! -d $(INST_PREFIX)/lib ]; then mkdir -p $(INST_PREFIX)/lib; fi
	for i in *.h; do \
		$(INSTALL) -m 0644 -f $(INST_PREFIX)/include/qpthr $$i ;\
	done
	$(INSTALL) -m 0755 -f $(INST_PREFIX)/lib $(LIBNAME)  

	ln -s $(LIBNAME) $(INST_PREFIX)/lib/$(LIBNAME_BASE).$(MAJOR_VERSION)

	$(INSTALL) -m 0644 -f $(INST_PREFIX)/lib $(LIBNAME_S)
endif
	



clean:
	rm -rf *.o core a.out Templates.DB arch/i386/*.o arch/alpha/*.o \
	so_locations cxx_repository

clean-dist: clean
	rm -rf *.a
	for i in $(LIBNAME) $(LIBNAME_BASE)* $(LIBNAME_BASE).$(MAJOR_VERSION); do \
		if [ -f $$i -o -h $$i ]; then rm $$i; fi \
	done
