#------------------------------->  Makefile  <--------------------------------#
#- Copyright (C) 199x by International Computer Science Institute            -#
#- This file is part of the GNU Sather package. It is free software; you may -#
#- redistribute  and/or modify it under the terms of the  GNU General Public -#
#- License (GPL)  as  published  by the  Free  Software  Foundation;  either -#
#- version 2 of the license, or (at your option) any later version.          -#
#- This  program  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 Doc/GPL for more details.        -#
#- The license text is also available from:  Free Software Foundation, Inc., -#
#- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                     -#
#------------->  Please email comments to <bug-sather@gnu.org>  <-------------#

SATHER_HOME=$(shell cd ../../..;pwd)

include $(SATHER_HOME)/config.default

ARCHITECTURES=osf_axp_smp_at \
	      hppa_hpux_smp_at \
	      linux_smp_at \
	      solaris_x86 \
	      cygwin_smp_at \
	      mips_irix5 \
	      solaris_sparc_smp

LIBDEST=../../lib
INCLUDEDEST=../../include

# At least -O or higher is needed for inlining to work properly
# in gcc

#To enable inlining, comment out DEBUG_FLAGS
#If you do this, make sure -O or higher is used
#(gcc fails to do inilining otherwise)
DEBUG_FLAGS   =-g -DAT_NO_INLINE
#DEBUG_FLAGS   =-O3
CFLAGS	      =$(DEBUG_FLAGS) -DAT_$(ARCH) -I. -I ../schedulers


HEADERS=at-inline.h \
	at-int.h \
	at-lwp.h \
	at.h \
	bundle.h \
	cond.h \
	const.h \
	md-atomic.h \
	md-lwp.h \
	md-qtmd.h \
	md-utils.h \
	mutex.h \
	p_pool.h \
	pool.h \
	qt.h \
	sema.h \
	spinlock.h \
	thread.h \
	wrappers.h
#	barrier.h \
#	rw.h




ARCH_HDRS=     $(ARCH)/qtmd.h \
               $(ARCH)/utils.h \
               $(ARCH)/lwp.h \
               $(ARCH)/md-atomic.h

LDFLAGS	 =$(CFLAGS)
LINKER	 =$(CC)
OBJS     =$(ARCH)/qtmdb.o meas.o

# Temporarily disabled hardware feedback */
#QTOBJS =qt.o $(ARCH)/qtmds.o $(ARCH)/hwperf.o
QTOBJS =qt.o $(ARCH)/qtmds.o

ATOBJS =at.o mutex.o cond.o pool.o p_pool.o sema.o \
        wrappers.o $(ARCH)/lwp.o thread.o
#        barrier.o rw.o

QT_H   =qt.h $(QTMD_H)
QTMD_H =$(ARCH)/qtmd.h

#############################################################

default: qt_$(ARCH).a at_$(ARCH).a

#    'all' apparently omitted!!
all:     default

install: all
	cp $(HEADERS) $(INCLUDEDEST)
	@for i in $(ARCHITECTURES) ; do \
		if [ -e at_$$i.a ] ; then \
			cp at_$$i.a $(LIBDEST)/libat.a ; \
			cp qt_$$i.a $(LIBDEST)/libqt.a ; \
			mkdir $(INCLUDEDEST)/$$i ; \
			cp $$i/*.h $(INCLUDEDEST)/$$i ; \
		fi ; \
	done

qtmdb.o: qtmdb.s b.h
meas.o: meas.c $(QT_H) b.h at.h
qt.o: qt.c $(QT_H)
at.o: at.c at.h $(QT_H)

at.h: at-inline.h wrappers.h mutex.h cond.h sema.h \
#      barrier.h rw.h
at-int.h: qt.h spinlock.h at.h at-inline.h at-lwp.h mutex.h cond.h const.h \
          pool.h p_pool.h $(ARCH)/utils.h thread.h wrappers.h \
#          rw.h

pool.h:		spinlock.h wrappers.h
p_pool.h:	pool.h spinlock.h wrappers.h
bundle.h:	at-int.h

at.o:		at-int.h at.c
mutex.o:	at-int.h mutex.c
cond.o:		at-int.h cond.c
# rw.o:		at-int.h rw.c
pool.o:		pool.h pool.c
p_pool.o:	p_pool.h p_pool.c
sema.o:		at-int.h sema.c
# barrier.o:	at-int.h barrier.c

thread.o: at-int.h thread.c
wrappers.o: spinlock.h wrappers.c

$(ARCH)/qtmds.o: $(ARCH)/qtmds.s
        $(MAKE) -C ARCH=$(ARCH) qtmds.o

$(ARCH)/hwperf.o:
        $(MAKE) -C ARCH=$(ARCH) hwperf.o

$(ARCH)/lwp.o: $(ARCH)/lwp.h wrappers.h $(ARCH)/lwp.c
        $(MAKE) -C ARCH=$(ARCH) lwp.o

qt_$(ARCH).a: $(QTOBJS)
	$(AR) crvs qt_$(ARCH).a $(QTOBJS)

at_$(ARCH).a: $(ATOBJS)
	$(AR) crvs at_$(ARCH).a $(ATOBJS)

clean:
	rm -f *.o
	rm -f */*.o
	rm -f qt_*.a at_*.a
