#!gmake


CC = @CC@
AR = ar
ARFLAGS = cru
RANLIB = ranlib
prefix = @prefix@
exec_prefix = @exec_prefix@
datarootdir = @datarootdir@
includedir = @includedir@
docdir = @docdir@
libdir = @libdir@
bindir = @bindir@
sbindir = @sbindir@
mandir = @mandir@
localstatedir = @localstatedir@
logdir = @LOGDIR@
sockpath = @SOCKPATH@
VPATH = @srcdir@:@tdbdir@:@tallocdir@:@libreplacedir@:@poptdir@:@teventdir@:
srcdir = @srcdir@
etcdir = @sysconfdir@
builddir = @builddir@
DESTDIR = /
EXTRA_OBJ=@EXTRA_OBJ@
XSLTPROC = /usr/bin/xsltproc
INSTALLCMD = @INSTALL@

POPT_LIBS = @POPT_LIBS@
POPT_CFLAGS = @POPT_CFLAGS@
POPT_OBJ = @POPT_OBJ@

TALLOC_LIBS = @TALLOC_LIBS@
TALLOC_CFLAGS = @TALLOC_CFLAGS@
TALLOC_OBJ = @TALLOC_OBJ@

TEVENT_LIBS = @TEVENT_LIBS@
TEVENT_CFLAGS = @TEVENT_CFLAGS@
TEVENT_OBJ = @TEVENT_OBJ@

TDB_LIBS = @TDB_LIBS@
TDB_CFLAGS = @TDB_CFLAGS@
TDB_OBJ = @TDB_OBJ@

SOCKET_WRAPPER_OBJ = @SOCKET_WRAPPER_OBJS@

PMDA_LIBS = -lpcp -lpcp_pmda
PMDA_INSTALL = @CTDB_PMDA_INSTALL@
PMDA_DEST_DIR = /var/lib/pcp/pmdas

CFLAGS=@CPPFLAGS@ -g -I$(srcdir)/include -Iinclude -Ilib -Ilib/util -I$(srcdir) \
       $(TALLOC_CFLAGS) $(TEVENT_CFLAGS) $(TDB_CFLAGS) -I@libreplacedir@ \
	-DVARDIR=\"$(localstatedir)\" -DETCDIR=\"$(etcdir)\" \
	-DLOGDIR=\"$(logdir)\" \
	-DSOCKPATH=\"$(sockpath)\" \
	-DUSE_MMAP=1 -DTEVENT_DEPRECATED_QUIET=1 @CFLAGS@ -Wno-format-zero-length $(POPT_CFLAGS) \
	-fPIC

LDSHFLAGS=-fPIC -shared
#LDSHFLAGS=-fPIC -shared -Wl,-Bsymbolic -Wl,-z,relo -Wl,-Bsymbolic-funtions -Wl,--as-needed -Wl,-z,defs
SHLD=${CC} ${CFLAGS} ${LDSHFLAGS} -o $@

LIB_FLAGS=@LDFLAGS@ -Llib @LIBS@ $(POPT_LIBS) $(TALLOC_LIBS) $(TEVENT_LIBS) $(TDB_LIBS) \
		  @INFINIBAND_LIBS@ @CTDB_PCAP_LDFLAGS@

CTDB_VERSION_H = include/version.h

UTIL_OBJ = lib/util/idtree.o lib/util/db_wrap.o lib/util/strlist.o lib/util/util.o \
	lib/util/util_time.o lib/util/util_file.o lib/util/fault.o lib/util/substitute.o \
	lib/util/signal.o

CTDB_COMMON_OBJ =  common/ctdb_io.o common/ctdb_util.o \
	common/ctdb_ltdb.o common/ctdb_message.o common/cmdline.o  \
	lib/util/debug.o common/rb_tree.o @CTDB_SYSTEM_OBJ@ common/system_common.o \
	common/ctdb_logging.c common/ctdb_fork.o

CTDB_LIB_OBJ = libctdb/ctdb.o libctdb/io_elem.o libctdb/local_tdb.o \
	libctdb/messages.o libctdb/sync.o libctdb/control.o \
	libctdb/logging.o $(SOCKET_WRAPPER_OBJ)

CTDB_TCP_OBJ = tcp/tcp_connect.o tcp/tcp_io.o tcp/tcp_init.o

CTDB_CLIENT_OBJ = client/ctdb_client.o \
	$(CTDB_COMMON_OBJ) $(POPT_OBJ) $(UTIL_OBJ) $(TALLOC_OBJ) $(TDB_OBJ) \
	@LIBREPLACEOBJ@ $(EXTRA_OBJ) $(TEVENT_OBJ) $(SOCKET_WRAPPER_OBJ)

CTDB_SERVER_OBJ = server/ctdbd.o server/ctdb_daemon.o \
	server/ctdb_recoverd.o server/ctdb_recover.o server/ctdb_freeze.o \
	server/ctdb_tunables.o server/ctdb_monitor.o server/ctdb_server.o \
	server/ctdb_control.o server/ctdb_call.o server/ctdb_ltdb_server.o \
	server/ctdb_traverse.o server/eventscript.o server/ctdb_takeover.o \
	server/ctdb_serverids.o server/ctdb_persistent.o \
	server/ctdb_keepalive.o server/ctdb_logging.o server/ctdb_uptime.o \
	server/ctdb_vacuum.o server/ctdb_banning.o server/ctdb_statistics.o \
	server/ctdb_update_record.o server/ctdb_lock.o \
	$(CTDB_CLIENT_OBJ) $(CTDB_TCP_OBJ) @INFINIBAND_WRAPPER_OBJ@

TEST_BINS=tests/bin/ctdb_bench tests/bin/ctdb_fetch tests/bin/ctdb_fetch_one \
	tests/bin/ctdb_fetch_lock_once \
	tests/bin/ctdb_fetch_readonly_once tests/bin/ctdb_fetch_readonly_loop \
	tests/bin/ctdb_store tests/bin/ctdb_trackingdb_test \
	tests/bin/ctdb_randrec tests/bin/ctdb_persistent \
	tests/bin/ctdb_traverse tests/bin/rb_test tests/bin/ctdb_transaction \
	tests/bin/ctdb_takeover_tests tests/bin/ctdb_update_record \
	tests/bin/ctdb_update_record_persistent \
	tests/bin/ctdb_tool_libctdb tests/bin/ctdb_tool_stubby \
	@INFINIBAND_BINS@

BINS = bin/ctdb @CTDB_SCSI_IO@ bin/smnotify bin/ping_pong bin/ltdbtool @CTDB_PMDA@

SBINS = bin/ctdbd

DIRS = lib bin tests/bin

.SUFFIXES: .c .o .h

all: showflags dirs $(CTDB_VERSION_H) $(CTDB_SERVER_OBJ) $(CTDB_CLIENT_OBJ) $(CTDB_LIB_OBJ) $(BINS) $(SBINS) $(TEST_BINS)

showflags:
	@echo 'ctdb will be compiled with flags:'
	@echo '  CFLAGS = $(CFLAGS)'
	@echo '  LIBS = $(LIB_FLAGS)'

showlayout::
	@echo "ctdb will be installed into:"
	@echo "  prefix:      $(prefix)"
	@echo "  bindir:      $(bindir)"
	@echo "  sbindir:     $(sbindir)"
	@echo "  libdir:      $(libdir)"
	@echo "  vardir:      $(localstatedir)"
	@echo "  logdir:      $(logdir)"
	@echo "  mandir:      $(mandir)"
	@echo "  etcdir:      $(etcdir)"

.c.o:
	@echo Compiling $*.c
	@mkdir -p `dirname $@`
	@$(CC) $(CFLAGS) -c $< -o $@

dirs:
	@mkdir -p $(DIRS)

$(CTDB_VERSION_H):
	@echo Generating $@
	@./packaging/mkversion.sh

bin/ctdbd: $(CTDB_SERVER_OBJ)
	@echo Linking $@
	@$(CC) $(CFLAGS) -o $@ $(CTDB_SERVER_OBJ) $(LIB_FLAGS)

libctdb/libctdb.a: $(CTDB_LIB_OBJ)
	@echo Linking $@
	-rm -f libctdb.a
	@$(AR) $(ARFLAGS) libctdb/libctdb.a $(CTDB_LIB_OBJ)
	@$(RANLIB) libctdb/libctdb.a

libctdb/libctdb.so.0: $(CTDB_LIB_OBJ)
	@echo Linking $@
	@$(SHLD) -Wl,-soname=libctdb.so.0 $(CTDB_LIB_OBJ)

libctdb/libctdb.so: libctdb/libctdb.so.0
	@echo Creating $@
	-@rm -f libctdb/libctdb.so
	@ln -s libctdb.so.0 libctdb/libctdb.so

bin/scsi_io: $(CTDB_CLIENT_OBJ) utils/scsi_io/scsi_io.o 
	@echo Linking $@
	@$(CC) $(CFLAGS) -o $@ utils/scsi_io/scsi_io.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS)

bin/ctdb: $(CTDB_CLIENT_OBJ) tools/ctdb.o tools/ctdb_vacuum.o libctdb/libctdb.a
	@echo Linking $@
	@$(CC) $(CFLAGS) -o $@ tools/ctdb.o tools/ctdb_vacuum.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS) libctdb/libctdb.a

bin/ltdbtool: tools/ltdbtool.o $(TDB_OBJ)
	@echo Linking $@
	@$(CC) $(CFLAGS) -o $@ $+ $(TDB_LIBS)

bin/smnotify: utils/smnotify/gen_xdr.o utils/smnotify/gen_smnotify.o utils/smnotify/smnotify.o $(POPT_OBJ)
	@echo Linking $@
	@$(CC) $(CFLAGS) -o $@ utils/smnotify/smnotify.o utils/smnotify/gen_xdr.o utils/smnotify/gen_smnotify.o $(POPT_OBJ) $(LIB_FLAGS)

utils/smnotify/smnotify.o: utils/smnotify/smnotify.c utils/smnotify/smnotify.h

utils/smnotify/smnotify.h:  utils/smnotify/smnotify.x
	@echo Generating $@
	rpcgen -h utils/smnotify/smnotify.x > utils/smnotify/smnotify.h

utils/smnotify/gen_xdr.c: utils/smnotify/smnotify.x utils/smnotify/smnotify.h
	@echo Generating $@
	rpcgen -c utils/smnotify/smnotify.x | grep -Ev '^[[:space:]]+register int32_t \*buf;' > utils/smnotify/gen_xdr.c 

utils/smnotify/gen_smnotify.c: utils/smnotify/smnotify.x utils/smnotify/smnotify.h
	@echo Generating $@
	rpcgen -l utils/smnotify/smnotify.x > utils/smnotify/gen_smnotify.c 

bin/ping_pong: utils/ping_pong/ping_pong.o
	@echo Linking $@
	@$(CC) $(CFLAGS) -o $@ utils/ping_pong/ping_pong.o

bin/pmdactdb: $(CTDB_CLIENT_OBJ) utils/pmda/pmda_ctdb.o
	@echo Linking $@
	@$(CC) $(CFLAGS) -o $@ utils/pmda/pmda_ctdb.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS) $(PMDA_LIBS)

tests/bin/rb_test: $(CTDB_CLIENT_OBJ) tests/src/rb_test.o 
	@echo Linking $@
	@$(CC) $(CFLAGS) -o $@ tests/src/rb_test.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS)

tests/bin/ctdb_bench: $(CTDB_CLIENT_OBJ) tests/src/ctdb_bench.o 
	@echo Linking $@
	@$(CC) $(CFLAGS) -o $@ tests/src/ctdb_bench.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS)

tests/bin/ctdb_fetch: $(CTDB_CLIENT_OBJ) tests/src/ctdb_fetch.o 
	@echo Linking $@
	@$(CC) $(CFLAGS) -o $@ tests/src/ctdb_fetch.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS)

tests/bin/ctdb_fetch_one: $(CTDB_CLIENT_OBJ) tests/src/ctdb_fetch_one.o 
	@echo Linking $@
	@$(CC) $(CFLAGS) -o $@ tests/src/ctdb_fetch_one.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS)

tests/bin/ctdb_fetch_lock_once: libctdb/libctdb.a tests/src/ctdb_fetch_lock_once.o 
	@echo Linking $@
	@$(CC) $(CFLAGS) -o $@ tests/src/ctdb_fetch_lock_once.o $(TDB_OBJ) $(POPT_OBJ) libctdb/libctdb.a $(LIB_FLAGS)

tests/bin/ctdb_fetch_readonly_once: libctdb/libctdb.a tests/src/ctdb_fetch_readonly_once.o
	@echo Linking $@
	@$(CC) $(CFLAGS) -o $@ tests/src/ctdb_fetch_readonly_once.o $(TDB_OBJ) $(POPT_OBJ) libctdb/libctdb.a $(LIB_FLAGS)

tests/bin/ctdb_fetch_readonly_loop: $(CTDB_CLIENT_OBJ) tests/src/ctdb_fetch_readonly_loop.o
	@echo Linking $@
	@$(CC) $(CFLAGS) -o $@ tests/src/ctdb_fetch_readonly_loop.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS)

tests/bin/ctdb_trackingdb_test: $(CTDB_CLIENT_OBJ) tests/src/ctdb_trackingdb_test.o
	@echo Linking $@
	@$(CC) $(CFLAGS) -o $@ tests/src/ctdb_trackingdb_test.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS)

tests/bin/ctdb_update_record: $(CTDB_CLIENT_OBJ) tests/src/ctdb_update_record.o 
	@echo Linking $@
	@$(CC) $(CFLAGS) -o $@ tests/src/ctdb_update_record.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS)

tests/bin/ctdb_update_record_persistent: $(CTDB_CLIENT_OBJ) tests/src/ctdb_update_record_persistent.o 
	@echo Linking $@
	@$(CC) $(CFLAGS) -o $@ tests/src/ctdb_update_record_persistent.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS)

tests/bin/ctdb_store: $(CTDB_CLIENT_OBJ) tests/src/ctdb_store.o 
	@echo Linking $@
	@$(CC) $(CFLAGS) -o $@ tests/src/ctdb_store.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS)

tests/bin/ctdb_traverse: $(CTDB_CLIENT_OBJ) tests/src/ctdb_traverse.o 
	@echo Linking $@
	@$(CC) $(CFLAGS) -o $@ tests/src/ctdb_traverse.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS)

tests/bin/ctdb_randrec: $(CTDB_CLIENT_OBJ) tests/src/ctdb_randrec.o 
	@echo Linking $@
	@$(CC) $(CFLAGS) -o $@ tests/src/ctdb_randrec.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS)

tests/bin/ctdb_persistent: $(CTDB_CLIENT_OBJ) tests/src/ctdb_persistent.o 
	@echo Linking $@
	@$(CC) $(CFLAGS) -o $@ tests/src/ctdb_persistent.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS)

tests/bin/ctdb_transaction: $(CTDB_CLIENT_OBJ) tests/src/ctdb_transaction.o 
	@echo Linking $@
	@$(CC) $(CFLAGS) -o $@ tests/src/ctdb_transaction.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS)

CTDB_SERVER_MOST_OBJ = $(CTDB_SERVER_OBJ:server/ctdbd.o=)
CTDBD_TEST_C = $(CTDB_SERVER_MOST_OBJ:.o=.c) tests/src/ctdbd_test.c

CTDB_TEST_C = $(CTDB_CLIENT_OBJ:.o=.c) tools/ctdb.c tools/ctdb_vacuum.c  tests/src/ctdb_test.c

CTDB_TEST_OBJ =  $(TALLOC_OBJ) $(TDB_OBJ) \
	@CTDB_SYSTEM_OBJ@ @LIBREPLACEOBJ@ $(EXTRA_OBJ) $(TEVENT_OBJ) $(SOCKET_WRAPPER_OBJ)

tests/src/ctdb_takeover_tests.o: tests/src/ctdb_takeover_tests.c $(CTDBD_TEST_C)

tests/bin/ctdb_takeover_tests: $(CTDB_TEST_OBJ) tests/src/ctdb_takeover_tests.o
	@echo Linking $@
	@$(CC) $(CFLAGS) -o $@ tests/src/ctdb_takeover_tests.o $(CTDB_TEST_OBJ) $(LIB_FLAGS)

tests/src/ctdb_tool_libctdb.o: tests/src/ctdb_tool_libctdb.c tests/src/libctdb_test.c $(CTDB_TEST_C)

tests/bin/ctdb_tool_libctdb: $(CTDB_TEST_OBJ) tests/src/ctdb_tool_libctdb.o
	@echo Linking $@
	@$(CC) $(CFLAGS) -o $@ tests/src/ctdb_tool_libctdb.o $(CTDB_TEST_OBJ) $(POPT_OBJ) $(LIB_FLAGS)

tests/src/ctdb_tool_stubby.o: tests/src/ctdb_tool_stubby.c tests/src/libctdb_test.c $(CTDB_TEST_C)

tests/bin/ctdb_tool_stubby: $(CTDB_TEST_OBJ) tests/src/ctdb_tool_stubby.o
	@echo Linking $@
	@$(CC) $(CFLAGS) -o $@ tests/src/ctdb_tool_stubby.o $(CTDB_TEST_OBJ) $(POPT_OBJ) $(LIB_FLAGS)

tests/bin/ibwrapper_test: $(CTDB_CLIENT_OBJ) ib/ibwrapper_test.o
	@echo Linking $@
	@$(CC) $(CFLAGS) -o $@ ib/ibwrapper_test.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS)

manpages:
	$(MAKE) -C doc

clean:
	rm -f *.o */*.o */*.a */*/*.o */*~
	rm -f utils/smnotify/gen_xdr.c
	rm -f $(BINS) $(SBINS) $(TEST_BINS)

distclean: clean
	rm -f *~ */*~
	rm -rf bin
	rm -f config.log config.status config.cache config.h
	rm -f Makefile

install: all manpages $(PMDA_INSTALL)
	mkdir -p $(DESTDIR)$(libdir)/pkgconfig
	mkdir -p $(DESTDIR)$(bindir)
	mkdir -p $(DESTDIR)$(sbindir)
	mkdir -p $(DESTDIR)$(includedir)
	mkdir -p $(DESTDIR)$(etcdir)/ctdb
	mkdir -p $(DESTDIR)$(etcdir)/ctdb/events.d
	mkdir -p $(DESTDIR)$(docdir)/ctdb
	${INSTALLCMD} -m 644 ctdb.pc $(DESTDIR)$(libdir)/pkgconfig
	${INSTALLCMD} -m 755 bin/ctdb $(DESTDIR)$(bindir)
	${INSTALLCMD} -m 755 bin/ctdbd $(DESTDIR)$(sbindir)
	${INSTALLCMD} -m 755 bin/smnotify $(DESTDIR)$(bindir)
	$(INSTALLCMD) -m 755 bin/ping_pong $(DESTDIR)$(bindir)
	$(INSTALLCMD) -m 755 bin/ltdbtool $(DESTDIR)$(bindir)
	$(INSTALLCMD) -m 755 libctdb/libctdb.a $(DESTDIR)$(libdir)
	${INSTALLCMD} -m 644 include/ctdb.h $(DESTDIR)$(includedir)
	${INSTALLCMD} -m 644 include/ctdb_client.h $(DESTDIR)$(includedir)
	${INSTALLCMD} -m 644 include/ctdb_protocol.h $(DESTDIR)$(includedir)
	${INSTALLCMD} -m 644 include/ctdb_private.h $(DESTDIR)$(includedir) # for samba3
	${INSTALLCMD} -m 644 include/ctdb_typesafe_cb.h $(DESTDIR)$(includedir)
	${INSTALLCMD} -m 644 config/functions $(DESTDIR)$(etcdir)/ctdb
	${INSTALLCMD} -m 755 config/statd-callout $(DESTDIR)$(etcdir)/ctdb
	${INSTALLCMD} -m 644 README $(DESTDIR)$(docdir)/ctdb/README
	${INSTALLCMD} -m 644 COPYING $(DESTDIR)$(docdir)/ctdb/COPYING
	${INSTALLCMD} -m 644 config/events.d/README $(DESTDIR)$(docdir)/ctdb/README.eventscripts
	${INSTALLCMD} -m 644 doc/recovery-process.txt $(DESTDIR)$(docdir)/ctdb/recovery-process.txt
	${INSTALLCMD} -m 755 config/events.d/00.ctdb $(DESTDIR)$(etcdir)/ctdb/events.d
	${INSTALLCMD} -m 755 config/events.d/01.reclock $(DESTDIR)$(etcdir)/ctdb/events.d
	${INSTALLCMD} -m 755 config/events.d/10.interface $(DESTDIR)$(etcdir)/ctdb/events.d
	${INSTALLCMD} -m 755 config/events.d/11.natgw $(DESTDIR)$(etcdir)/ctdb/events.d
	${INSTALLCMD} -m 755 config/events.d/11.routing $(DESTDIR)$(etcdir)/ctdb/events.d
	${INSTALLCMD} -m 755 config/events.d/13.per_ip_routing $(DESTDIR)$(etcdir)/ctdb/events.d
	${INSTALLCMD} -m 644 config/events.d/20.multipathd $(DESTDIR)$(etcdir)/ctdb/events.d
	${INSTALLCMD} -m 644 config/events.d/31.clamd $(DESTDIR)$(etcdir)/ctdb/events.d
	${INSTALLCMD} -m 755 config/events.d/40.vsftpd $(DESTDIR)$(etcdir)/ctdb/events.d
	${INSTALLCMD} -m 644 config/events.d/40.fs_use $(DESTDIR)$(etcdir)/ctdb/events.d
	${INSTALLCMD} -m 755 config/events.d/41.httpd $(DESTDIR)$(etcdir)/ctdb/events.d
	${INSTALLCMD} -m 755 config/events.d/49.winbind $(DESTDIR)$(etcdir)/ctdb/events.d
	${INSTALLCMD} -m 755 config/events.d/50.samba $(DESTDIR)$(etcdir)/ctdb/events.d
	${INSTALLCMD} -m 755 config/events.d/60.nfs $(DESTDIR)$(etcdir)/ctdb/events.d
	${INSTALLCMD} -m 755 config/events.d/60.ganesha $(DESTDIR)$(etcdir)/ctdb/events.d
	${INSTALLCMD} -m 755 config/events.d/62.cnfs $(DESTDIR)$(etcdir)/ctdb/events.d
	${INSTALLCMD} -m 755 config/events.d/70.iscsi $(DESTDIR)$(etcdir)/ctdb/events.d
	${INSTALLCMD} -m 755 config/events.d/91.lvs $(DESTDIR)$(etcdir)/ctdb/events.d
	${INSTALLCMD} -m 755 tools/ctdb_diagnostics $(DESTDIR)$(bindir)
	${INSTALLCMD} -m 755 tools/onnode $(DESTDIR)$(bindir)
	if [ -f doc/ctdb.1 ];then ${INSTALLCMD} -d $(DESTDIR)$(mandir)/man1; fi
	if [ -f doc/ctdb.1 ];then ${INSTALLCMD} -m 644 doc/ctdb.1 $(DESTDIR)$(mandir)/man1; fi
	if [ -f doc/ctdbd.1 ];then ${INSTALLCMD} -m 644 doc/ctdbd.1 $(DESTDIR)$(mandir)/man1; fi
	if [ -f doc/onnode.1 ];then ${INSTALLCMD} -m 644 doc/onnode.1 $(DESTDIR)$(mandir)/man1; fi
	if [ -f doc/ltdbtool.1 ]; then ${INSTALLCMD} -m 644 doc/ltdbtool.1 $(DESTDIR)$(mandir)/man1; fi
	if [ -f doc/ping_pong.1 ];then ${INSTALLCMD} -m 644 doc/ping_pong.1 $(DESTDIR)$(mandir)/man1; fi
	if [ -f doc/ctdb.1.html ];then ${INSTALLCMD} -m 644 doc/ctdb.1.html $(DESTDIR)$(docdir)/ctdb; fi
	if [ -f doc/ctdbd.1.html ];then ${INSTALLCMD} -m 644 doc/ctdbd.1.html $(DESTDIR)$(docdir)/ctdb; fi
	if [ -f doc/onnode.1.html ];then ${INSTALLCMD} -m 644 doc/onnode.1.html $(DESTDIR)$(docdir)/ctdb; fi
	if [ -f doc/ltdbtool.1.html ];then ${INSTALLCMD} -m 644 doc/ltdbtool.1.html $(DESTDIR)$(docdir)/ctdb; fi
	if [ -f doc/ping_pong.1.html ];then ${INSTALLCMD} -m 644 doc/ping_pong.1.html $(DESTDIR)$(docdir)/ctdb; fi
	if [ ! -f $(DESTDIR)$(etcdir)/ctdb/notify.sh ];then ${INSTALLCMD} -m 755 config/notify.sh $(DESTDIR)$(etcdir)/ctdb; fi
	${INSTALLCMD} -m 755 config/debug-hung-script.sh $(DESTDIR)$(etcdir)/ctdb
	if [ ! -f $(DESTDIR)$(etcdir)/ctdb/ctdb-crash-cleanup.sh ];then ${INSTALLCMD} -m 755 config/ctdb-crash-cleanup.sh $(DESTDIR)$(etcdir)/ctdb; fi
	if [ ! -f $(DESTDIR)$(etcdir)/ctdb/gcore_trace.sh ];then ${INSTALLCMD} -m 755 config/gcore_trace.sh $(DESTDIR)$(etcdir)/ctdb; fi

install_pmda:
	$(INSTALLCMD) -m 755 -d $(PMDA_DEST_DIR)
	$(INSTALLCMD) -m 755 pmda/Install pmda/Remove $(PMDA_DEST_DIR)
	$(INSTALLCMD) -m 644 pmda/pmns pmda/domain.h pmda/help pmda/README $(PMDA_DEST_DIR)
	$(INSTALLCMD) -m 755 bin/pmdactdb $(PMDA_DEST_DIR)

# Should use $(datarootdir) but older autoconfs don't do this.  :-(
install_tests: all
	tests/INSTALL --destdir=$(DESTDIR) --datarootdir=$(prefix)/share --libdir=$(libdir) --bindir=$(bindir) --etcdir=$(etcdir)

test: all
	tests/run_tests.sh -V tests/var

test_cluster: all
	tests/run_cluster_tests.sh

valgrindtest: all
	VALGRIND="valgrind -q --trace-children=yes" tests/run_tests.sh

ctags:
	find . -name "*.[ch]" | xargs ctags

etags:
	find . -name "*.[ch]" | xargs etags

realdistclean: distclean
	rm -f configure config.h.in ctdb.pc
