###############################################################################
###############################################################################
##
##  Copyright (C) 2004 Red Hat, Inc.  All rights reserved.
##
##  This copyrighted material is made available to anyone wishing to use,
##  modify, copy, or redistribute it subject to the terms and conditions
##  of the GNU General Public License v.2.
##
###############################################################################
###############################################################################
top_srcdir=..
include ${top_srcdir}/make/defines.mk
UNINSTALL=${top_srcdir}/scripts/uninstall.pl

INCLUDES+= -I. -I${incdir}
LIBS    += -L${libdir} -ldlm_lt
CFLAGS  += -D_CLUSTER_
OBJS     = sm.o services.o
TARGETS  = magma_sm.so

ifneq (${KERNEL_SRC}, )
# Use the kernel tree if patched, otherwise, look where cluster headers
#  should be installed
INCLUDES += $(shell if [ -d ${KERNEL_SRC}/include/cluster ]; then \
                echo '-I${KERNEL_SRC}/include/cluster'; else \
                echo '-I${incdir}/cluster'; fi)
else
INCLUDES += -I${incdir}/cluster
endif

all: $(TARGETS)

install: all
	mkdir -p ${plugindir}
	install -m 0755 $(TARGETS) ${plugindir}

uninstall:
	${UNINSTALL} ${TARGETS} ${plugindir}

magma_sm.so: buildtest $(OBJS)
	$(CC) -o $@ $(OBJS) -shared $(CFLAGS) $(LIBS)

buildtest: $(OBJS)
	echo "int main(void) { return 0; }" > _buildtest.c
	$(CC) -c _buildtest.c
	$(CC) -o $@ _buildtest.o $(OBJS) $(LIBS) -lpthread
	rm -f _buildtest*

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

clean:
	rm -f *o *~ *.so buildtest

