#
# Cluster Information Service makefile
#

CC = gcc

INCLUDES = -I../include

CFLAGS = -g -O0 -Wall -D_GNU_SOURCE -DDEBUG

LIBSENSORS_PATH = /usr/local/lib

ifeq ($(MAKELEVEL), 0)
DAEMONS = cisd sysmon procmon sockmon netmon lmmon cismon
OBJS = sys_func.o proc_func.o sock_func.o net_func.o lm_func.o
LIBS = -L$(LIBSENSORS_PATH) -lsensors
DEFINES = -DWITH_SYSMON -DWITH_PROCMON -DWITH_NETMON -DWITH_SOCKMON -DWITH_LMMON
else
DAEMONS = cisd
OBJS =
endif

ifeq ($(INTEGRATED_MONITOR),y)
	DAEMONS += cismon
	ifeq ($(WITH_SYSMON),y)
        	DEFINES += -DWITH_SYSMON
                OBJS += sys_func.o
        endif
	ifeq ($(WITH_PROCMON),y)
        	DEFINES += -DWITH_PROCMON
                OBJS += proc_func.o
        endif
	ifeq ($(WITH_NETMON),y)
        	DEFINES += -DWITH_NETMON
                OBJS += net_func.o
        endif
	ifeq ($(WITH_SOCKMON),y)
        	DEFINES += -DWITH_SOCKMON
                OBJS += sock_func.o
        endif
	ifeq ($(WITH_LMMON),y)
        	DEFINES += -DWITH_LMMON
                OBJS += lm_func.o
                LIBS += -L$(LIBSENSORS_PATH) -lsensors
        endif
else
	ifeq ($(WITH_SYSMON),y)
        	DAEMONS += sysmon
        endif
	ifeq ($(WITH_PROCMON),y)
        	DAEMONS += procmon
        endif
	ifeq ($(WITH_NETMON),y)
        	DAEMONS += netmon
        endif
	ifeq ($(WITH_SOCKMON),y)
        	DAEMONS += sockmon
        endif
	ifeq ($(WITH_LMMON),y)
        	DAEMONS += lmmon
        endif
endif	

all: $(DAEMONS) libCis.a libCisrec.a

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

cismon.o:cismon.c
	$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -c $< -o $@


clean: 
	rm -f cisd *mon libCis* *.o *~

cisd: cisd.o cisd_rpc.o syscall.o cis_xdr.o hash.o history.o
	$(CC) $(CFLAGS) -o $@ $^

cismon: cismon.o syscall.o mon_common.o $(OBJS)
	$(CC) $(CFLAGS) $(LIBS) -o $@ $^

sysmon: sysmon.o syscall.o mon_common.o sys_func.o
	$(CC) $(CFLAGS) -o $@ $^

procmon: procmon.o syscall.o mon_common.o proc_func.o
	$(CC) $(CFLAGS) -o $@ $^

sockmon: sockmon.o syscall.o mon_common.o sock_func.o
	$(CC) $(CFLAGS) -o $@ $^

netmon: netmon.o syscall.o mon_common.o net_func.o
	$(CC) $(CFLAGS) -o $@ $^

lmmon: lmmon.o syscall.o mon_common.o lm_func.o
	$(CC) $(CFLAGS) -L$(LIBSENSORS_PATH) -lsensors -o $@ $^

libCis.a: cis_clnt.o cis_xdr.o
	rm -f $@
	ar clq $@ $^
	ranlib $@

libCisrec.a: cis_rec.o cis_xdr.o
	rm -f $@
	ar clq $@ $^
	ranlib $@

libCis.so: cis_clnt.o cis_xdr.o
	rm -f $@ $@.$(VERSION)
	$(CC) $(CFLAGS) -o $@.$(VERSION) -shared -Wl,-soname,$@.$(VERSION) $^ 
	ln -s $@.$(VERSION) $@

depend:
	$(CC) $(CFLAGS) -M *.c

install:
	cp -vf $(DAEMONS) /usr/sbin

# dependencies

*mon.o *func.o: ../include/cis.h cis_mon.h mon_common.h cis_mon.h

cis_xdr.o: \
			../include/cis.h \
                        cis_xdr.h
cis_rpc.o cis_clnt.o: \
			../include/cis.h \
                        ../include/cis_clnt.h \
                        cisd.h cis_xdr.h hash.h history.h cis_mon.h
cis_rec.o: \
			../include/cis.h \
                        ../include/cis_rec.h
