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

# Makefile for Active Threads libraries and tests
#CC	      = gcc -ansi -Wall -pedantic

#turned off -ansi for assembly
CC	      = gcc 
AR	      = ar
#MAKE	      = gmake
VPATH		= .:../include

SCHED		= ../schedulers
MD		= ../md
LIB		= ../lib
TESTS		= ../tests

#
# Need to include from the current directory because "qt.h"
# will include <qtmd.h>.
#
# 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)
INC_DIR	      = -I../include -I$(MD)/$(ARCH) #DEBUG_FLAGS   = -g -DAT_NO_INLINE
DEBUG_FLAGS   = -O3
CFLAGS	      = $(INC_DIR) $(DEBUG_FLAGS)

HDRS	      = qt.h \
		$(MD)/$(ARCH)/qtmd.h \
		$(MD)/$(ARCH)/utils.h \
		$(MD)/$(ARCH)/lwp.h \
		$(MD)/$(ARCH)/md-atomic.h \
		at.h \
		at-inline.h \
		at-int.h \
		at-lwp.h \
		mutex.h \
		cond.h \
		rw.h \
		pool.h \
		p_pool.h \
		sema.h \
		barrier.h \
		spinlock.h \
		thread.h \
		wrappers.h \
		bundle.h \
		const.h

LDFLAGS	      = $(CFLAGS)

LIBS	      = libat.a libqt.a libschedulers.a

LINKER	      = $(CC)

MAKEFILE      = Makefile

OBJS	      = $(MD)/$(ARCH)/qtmdb.o \
		meas.o


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

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

sparc-solaris:		
		$(MAKE) all ARCH=sparc-solaris DEBUG_FLAGS=$(DEBUG_FLAGS)
		$(MAKE) tests ARCH=sparc-solaris

i386-solaris:	
		$(MAKE) all ARCH=i386-solaris

axp-osf:
		$(MAKE) all ARCH=axp-osf

hppa-hpux:
		$(MAKE) all ARCH=hppa-hpux

mips-irix5:		
		$(MAKE) all ARCH=mips-irix5 DEBUG_FLAGS=$(DEBUG_FLAGS)
		$(MAKE) tests ARCH=mips-irix5

all:		beware $(LIB)/libqt.a $(LIB)/libat.a $(LIB)/libschedulers.a

beware:		
#		@if [ -z "$(ARCH)" ]; then \
#		echo "---------------------------------------------"; \
#		echo "You forgot to set ARCH"; \
#		echo "Possible choices: sparc-solaris, i386-solaris"; \
#		echo "---------------------------------------------"; \
#		exit 1; \
#		fi
$(LIB)/libqt.a:	$(QTOBJS) 
		$(AR) crvs $(LIB)/libqt.a $(QTOBJS)
#		ranlib $(LIB)/libqt.a

clean:
		rm -f *.o 
		rm -f $(MD)/*/*.o
		rm -f $(SCHED)/*.o
		rm -f $(LIB)/libqt.a $(LIB)/libat.a $(LIB)/libschedulers.a
		cd $(TESTS); $(MAKE) clean

cleanup:
		rm -f *.o 
		rm -f $(SCHED)/*.o
		rm -f $(LIB)/libqt.a $(LIB)/libat.a $(LIB)/libschedulers.a

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

###
qtmdb.o: qtmdb.s b.h
meas.o: meas.c /usr/include/stdio.h $(QT_H) b.h at.h
qt.o: qt.c $(QT_H)
at.o: at.c at.h $(QT_H)
#$(MD)/$(ARCH)/qtmds.o: $(MD)/$(ARCH)/qtmds.s
#	$(CC) -c -g $(MD)/$(ARCH)/qtmds.s -o $(MD/$(ARCH)/qtmds.o

$(MD)/$(ARCH)/qtmds.o: $(MD)/$(ARCH)/qtmds.s
		cd $(MD)/$(ARCH); $(MAKE) qtmds.o

$(MD)/$(ARCH)/hwperf.o: 
		cd $(MD)/$(ARCH); $(MAKE) hwperf.o

at.h:		at-inline.h wrappers.h mutex.h cond.h rw.h sema.h barrier.h 
at-int.h:	qt.h spinlock.h at.h at-inline.h at-lwp.h mutex.h cond.h rw.h\
		pool.h p_pool.h $(MD)/$(ARCH)/utils.h thread.h wrappers.h \
		const.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 

#$(MD)/$(ARCH)/lwp.o:	$(MD)/$(ARCH)/lwp.h wrappers.h $(MD)/$(ARCH)/lwp.c
#		$(CC) -c $(CFLAGS) $(MD)/$(ARCH)/lwp.c -o $(MD)/$(ARCH)/lwp.o

$(MD)/$(ARCH)/lwp.o:	$(MD)/$(ARCH)/lwp.h wrappers.h $(MD)/$(ARCH)/lwp.c
		cd $(MD)/$(ARCH); $(MAKE) lwp.o 
thread.o:	at-int.h thread.c
wrappers.o:	spinlock.h wrappers.c


$(LIB)/libat.a:	at.o $(MD)/$(ARCH)/lwp.o wrappers.o pool.o p_pool.o thread.o mutex.o cond.o sema.o barrier.o rw.o $(HDRS) 
		$(AR) crvs $(LIB)/libat.a at.o $(MD)/$(ARCH)/lwp.o wrappers.o pool.o p_pool.o thread.o mutex.o cond.o rw.o sema.o barrier.o 
#		ranlib $(LIB)/libat.a

$(LIB)/libschedulers.a: 
		cd $(SCHED); $(MAKE) ARCH=$(ARCH) DEBUG_FLAGS="$(DEBUG_FLAGS)"

tests:		
		cd $(TESTS); $(MAKE) tests ARCH=$(ARCH)



at_merge:	all
		$(MAKE) all
		cd $(TESTS); $(MAKE) at_merge ARCH=$(ARCH)



