#*************************************************************#
#
#   Ensemble, (Version 0.61)
#   Copyright 1999 Cornell University
#   All rights reserved.
#
#   See ensemble/doc/license.txt for further information.
#
#*************************************************************#

ENS		= $(ENSROOT)

CC		= gcc

# DEBUG

#CC		= gcc -g

SYSNAME		= linux

#**********************************************************

# Change this between -g and -O to compile for debugging/performance
OPT_OPS		= -O

################
#CSIM_LIB = /home/kemme/csim18/gpp/lib/csim.gpp.a
#INCL_CSIM = -I/home/kemme/csim18/cpp/lib
##############

############
# POSTGRES
############
BASE = $(HOME)
# LIBPOSTGRES= -lgen -lcrypt -ldl -lm -ltermcap -lcurses  -L $(BASE)/postgres-r/src/interfaces/libpq -lpq
LIBPOSTGRES= -lcrypt -ldl -lm -ltermcap -lcurses  -L $(PGLIB) -lpq 
INCLPOSTGRES=-I $(PGINCLUDE)

CFLAGS		= 	\
		-I $(ENS)/hot/include	\
		$(OPT_OPS)		\
		-D$(SYSNAME)            \
                $(INCLPOSTGRES)

RM		= /bin/rm -f
AR		= ar r

.SUFFIXES: .c.o 

PLATFORM	= $(MACHTYPE)-$(OSTYPE)
OBJDIR		= ./

HOTLIB		= $(ENS)/lib/$(PLATFORM)/libhot.a
HOTLIBO		= $(ENS)/lib/$(PLATFORM)/libhoto.a

CRYPTOLIB	=
#CRYPTOLIB	= $(ENS)/lib/$(PLATFORM)/libcryptoc.a

# sparc-solaris_LIB 	= -lsocket -lposix4 -lthread -lpthread \
# 			-lnsl -ltermcap -lm

i386-linux_LIB       = -lpthread -lnsl -ltermcap -lm

SYSLIB		= $($(PLATFORM)_LIB)

LIB		= $(HOTLIB) $(CRYPTOLIB) $(SYSLIB)
LIBO		= $(HOTLIBO) $(CRYPTOLIB) $(SYSLIB)

SPREAD		= /usr/local/lib/libspread.a

%o: ./%c
	$(CC) $(CFLAGS) -g  -c -o $@ $<

all: transmng


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


#spread:	spread_test.o spread.o threads.o
#	$(CC) -g  -o sp_test spread_test.o spread.o threads.o $(LIB) $(SPREAD)

hot_test:	hot_test.o semaphore.o threads.o
	$(CC) -g  -o hot_test hot_test.o semaphore.o threads.o $(LIB)

hot_test2:	hot_test2.o semaphore.o threads.o
	$(CC) -g  -o hot_test2 hot_test2.o semaphore.o threads.o $(LIB)

hot_testo:	hot_test.o semaphore.o threads.o
	$(CC) -g  -o hot_testo hot_test.o semaphore.o threads.o $(LIBO)

prueba:	prueba.o semaphore.o threads.o
	$(CC) -g  -o prueba prueba.o semaphore.o threads.o $(LIB)

prueba2: prueba2.o
	$(CC) -g  -o prueba2 prueba2.o $(LIBPOSTGRES)

client:	client.o mc_send.o semaphore.o threads.o
	$(CC) -g  -o client client.o mc_send.o semaphore.o threads.o $(LIB)

timetrans:	timetrans.o
	$(CC) -g  -o timetrans timetrans.o $(LIB) $(LIBPOSTGRES)

replica:	replica.o semaphore.o threads.o
	$(CC) -g  -o replica replica.o semaphore.o threads.o $(LIB)

skclient: skclient.o sock.o
	$(CC) -g  -o skclient skclient.o sock.o $(LIB) 

testlist: testlist.o list.o declarations.o
	$(CC) -g  -o testlist testlist.o list.o declarations.o $(LIB) 

test_qmqueue: test_qmqueue.o qmqueue.o transmng.o
	$(CC) -g  -o test_qmqueue test_qmqueue.o qmqueue.o  $(LIB) 

transmng: transmng.o declarations.o qmqueue.o queue.o list.o socku.o tools.o sqlmiddlertools.o database.o qmsockets.o groupcomm.o commitlist.o mc_send.o semaphore.o pgserver.o pgconnection.o utilities.o dllist.o hashtable.o hashtypes.o threads.o process.o fillHash.o log.o stat.o
	$(CC) -g -o transmng transmng.o declarations.o qmqueue.o queue.o list.o commitlist.o socku.o tools.o sqlmiddlertools.o database.o qmsockets.o groupcomm.o mc_send.o pgserver.o pgconnection.o utilities.o dllist.o hashtable.o hashtypes.o semaphore.o threads.o process.o fillHash.o log.o stat.o $(LIB) $(LIBPOSTGRES)

testpost:	testpost.o
	$(CC) -g  -o testpost testpost.o $(LIBPOSTGRES) $(LIB)
mc_send:	mc_send.o
	$(CC) -g  -o mc_send mc_send.o  $(LIB)
mc_recv:	mc_recv.o
	$(CC) -g  -o mc_recv mc_recv.o  $(LIB)
mc_test:	mc_test.o
	$(CC) -g  -o mc_test mc_test.o  $(LIB)
clienttest1:	clienttest1.o semaphore.o threads.o
	$(CC) -g  -o clienttest1 clienttest1.o semaphore.o threads.o $(LIB) $(CSIM_LIB)
clienttest2:	clienttest2.o semaphore.o
	$(CC) -g -o clienttest2 clienttest2.o semaphore.o threads.o $(LIB) $(CSIM_LIB)
testqueue:	testqueue.o queue.o transmng.o declarations.o
	$(CC) -g  -o testqueue testqueue.o queue.o declarations.o $(LIB)  $(CSIM_LIB)
clean:
	$(RM) *.o *~ hot_test hot_test2 hot_testo prueba client clienttest1 \
	clienttest2 mc_recv mc_test testlist testpost test_qmqueue timetrans \
	replica testqueue FillDb transmng pgserver testTableAcceded prueba2 sp_test

	$(RM) adapt*

FillDb: FillDb2.o
	$(CC) -g  -o FillDb FillDb2.o $(LIB) $(LIBPOSTGRES)
