srcdir = @srcdir@
VPATH = @srcdir@

prefix = @prefix@
exec_prefix = @exec_prefix@
includedir = @includedir@
libdir = @libdir@
bindir = @bindir@
CC = @CC@
CXX = @CXX@
CFLAGS = @CFLAGS@
DEFS = @DEFS@

#LIBRADIR=/afs/cs/project/cmcl-pach/libra
#CC=gcc
#CXX=g++
#CFLAGS=-static -g

#INCFLAGS=-I$(LIBRADIR)/include -I/usr/include/libxml2
CPPFLAGS = @CPPFLAGS@

#LIBFLAGS=-L$(LIBRADIR)/lib
#LIBS=-llibra -lpthread -lxml2 -lz -lm -lslp
LIBS = @LIBS@

#USRFLAGS=$(CFLAGS) $(INCFLAGS) $(LIBFLAGS)
COMPILE = $(CXX) $(CFLAGS) $(CPPFLAGS) $(DEFS) -c
LINK = $(CXX) $(CFLAGS)

OBJS=SynthESMService.o SynthIPMZService.o \
     ESMProxyLocator.o ESMProxyInitor.o \
     IPMZService.o \
     mtest.o slptest.o c2.o c3.o c4.o c5.o i1.o \
     ex_esmproxy.o ex_esmproxy1.o ex_vgw.o fe.o fe1.o \
     ipmz.o synth.o ex_compnode.o c6.o \
     ex_gnp.o cgnp.o

TARGETS=mtest slptest c3 c4 ex_esmproxy ex_esmproxy1 ex_vgw fe fe1 \
        ex_compnode c6 ex_gnp cgnp

all: $(OBJS) allbin

ALLBIN=$(TARGETS) esmservice ipmz synth
BIN_INSTALL=$(addprefix .install-,$(ALLBIN))

allbin: $(ALLBIN)


ESMProxyLocator.o ESMProxyInitor.o: ESM.h
SynthESMService.o SynthIPMZService.o: Synth.h
IPMZService.o: IPMZService.h

$(OBJS): %.o: %.cpp
	$(COMPILE) $<

$(TARGETS): %: %.o
	$(LINK) -o $@ $^ $(LIBS)

esmservice: esmservice.o ESMProxyLocator.o ESMProxyInitor.o
	$(LINK) -o $@ $^ $(LIBS)

c2: c2.o SynthESMService.o
	$(LINK) -o $@ $^ $(LIBS)

c5: c5.o SynthIPMZService.o
	$(LINK) -o $@ $^ $(LIBS)

i1: i1.o IPMZService.o
	$(LINK) -o $@ $^ $(LIBS)

ipmz: ipmz.o IPMZService.o
	$(LINK) -o $@ $^ $(LIBS)

synth: synth.o SynthIPMZService.o SynthESMService.o
	$(LINK) -o $@ $^ $(LIBS)

#install: allbin
#	mkdir -p $(bindir)
#	for prog in $(ALLBIN); do \
#		cp -f $$prog $(bindir); \
#	done

$(BIN_INSTALL): .install-%: %
	cp -f $< $(bindir)
	touch $@

install: $(BIN_INSTALL)

clean:
	rm -f core *.o c2 c3 c4 c5 i1 mtest slptest \
	ex_esmproxy ex_esmproxy1 ex_vgw \
	esmservice ipmz synth fe fe1 \
	ex_compnode c6 \
	ex_gnp cgnp
