build when --enable-plugins is set and libtool is used.
 # --client-only directories
 fd_subdirs = src scripts src/lib src/findlib src/filed \
        @READLINE_SRC@ @BAT_DIR@ @TRAY_MONITOR_DIR@ @WX_DIR@ \
-       src/console src/plugins/fd
+       src/console @FD_PLUGIN_DIR@
 
 # Non-client-only directores
 subdirs =    src/cats @DIRD_DIR@ @STORED_DIR@ src/tools
 
 
 AC_SUBST(SBINPERM)
 
+dnl --------------------------------------------------
+dnl plugin support
+dnl --------------------------------------------------
+use_plugins=yes
+AC_ARG_ENABLE(plugins,
+   AC_HELP_STRING([--enable-plugins], [enable plugin support @<:@default=yes@:>@]),
+   [
+       if test x$enableval = xno; then
+          use_plugins=no
+       fi
+   ]
+)
+
+if test "x$use_libtool" != "xyes" -a test "x$use_plugins" = "xyes"; then
+   echo " "
+   echo "You specified --enable-plugins but disabled libtool with --disable-libtool"
+   echo "We only support plugins using libtool so either disable plugins or enable libtool"
+   echo " "
+   echo "Aborting the configuration ..."
+   echo " "
+   echo " "
+   exit 1
+fi
+
+FD_PLUGIN_DIR=""
+if test "x$use_plugins" = "xyes" ; then
+   FD_PLUGIN_DIR="src/plugins/fd"
+fi
+AC_SUBST(FD_PLUGIN_DIR)
+
 dnl ------------------------------------------------
 dnl Bacula check for various SQL database engines
 dnl ------------------------------------------------
 
 
 .SUFFIXES:    .c .o .lo
 
-.c.o:
-       $(CXX) $(DEFS) $(DEBUG) $(CPPFLAGS) -I${SRCDIR} -I${DIRDIR} -DTEST_PROGRAM -c $<
-
 .c.lo:
        $(LIBTOOL_COMPILE) $(CXX) $(DEFS) $(DEBUG) $(CPPFLAGS) -I${SRCDIR} -I${DIRDIR} -DTEST_PROGRAM -c $<
 
-all: example-plugin-dir$(DEFAULT_SHARED_OBJECT_TYPE)
-
-test: main example-plugin-dir.so
-
-dir_plugins.o: ${DIRDIR}/dir_plugins.h ${DIRDIR}/dir_plugins.c
-       $(CXX) -I${SRCDIR} -I${DIRDIR} -DTEST_PROGRAM -c ${DIRDIR}/dir_plugins.c 
-
-main: dir_plugins.o
-       $(CXX) $(LDFLAGS) -L${LIBDIR} dir_plugins.o -o main -lbac -lpthread -lssl -l crypto -ldl
-
-example-plugin-dir.o: example-plugin-dir.c ${DIRDIR}/dir_plugins.h
-       $(CXX) $(DEFS) $(DEBUG) $(CPPFLAGS) -fPIC -I../.. -I${DIRDIR} -c example-plugin-dir.c
-
-example-plugin-dir.so: example-plugin-dir.o 
-       $(CXX) $(LDFLAGS) -shared example-plugin-dir.o -o example-plugin-dir.so
+all: example-plugin-dir.la
 
 example-plugin-dir.lo: example-plugin-dir.c ${DIRDIR}/dir_plugins.h
        $(LIBTOOL_COMPILE) $(CXX) $(DEFS) $(DEBUG) $(CFLAGS) -I../.. -I${DIRDIR} -c example-plugin-dir.c
 
-example-plugin-dir.la: Makefile example-plugin-dir$(DEFAULT_OBJECT_TYPE)
+example-plugin-dir.la: Makefile example-plugin-dir.lo
        $(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -shared example-plugin-dir.lo -o $@ -rpath $(plugindir) -module -export-dynamic -avoid-version
 
 install: all
        $(MKDIR) $(DESTDIR)$(plugindir)
-       $(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) example-plugin-dir$(DEFAULT_SHARED_OBJECT_TYPE) $(DESTDIR)$(plugindir)
+       $(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) example-plugin-dir.la $(DESTDIR)$(plugindir)
        $(RMF) $(DESTDIR)$(plugindir)/example-plugin-dir.la
 
 libtool-clean:
 distclean: clean
        rm -f Makefile
 
-uninstall:
-       $(RMF) $(DESTDIR)$(plugindir)/example-plugin-dir.so
+libtool-uninstall:
+       $(LIBTOOL_UNINSTALL) $(RMF) $(DESTDIR)$(plugindir)/example-plugin-dir.la
+
+uninstall: @LIBTOOL_UNINSTALL_TARGET@
 
 depend:
 
 SRCDIR=../..
 LIBDIR=../../lib
 
-.SUFFIXES:    .c .o .lo
-
-.c.o:
-       $(CXX) $(DEFS) $(DEBUG) $(CPPFLAGS) -I${SRCDIR} -I${FDDIR} -DTEST_PROGRAM -c $<
+.SUFFIXES:    .c .lo
 
 .c.lo:
        $(LIBTOOL_COMPILE) $(CXX) $(DEFS) $(DEBUG) $(CPPFLAGS) -I${SRCDIR} -I${FDDIR} -DTEST_PROGRAM -c $<
 
-all: bpipe-fd$(DEFAULT_SHARED_OBJECT_TYPE)
-
-test: main example-plugin-fd.so
-
-fd_plugins.o: ${FDDIR}/fd_plugins.h ${FDDIR}/fd_plugins.c
-       $(CXX) -I${SRCDIR} -I${FDDIR} -DTEST_PROGRAM -c ${FDDIR}/fd_plugins.c 
-
-main: fd_plugins.o
-       $(CXX) $(LDFLAGS) -L${LIBDIR} fd_plugins.o -o main -lbac -lpthread -lssl -l crypto -ldl
-
-example-plugin-fd.o: example-plugin-fd.c ${FDDIR}/fd_plugins.h
-       $(CXX) -fPIC -I../.. -I${FDDIR} -c example-plugin-fd.c
-
-example-plugin-fd.so: example-plugin-fd.o 
-       $(CXX) $(LDFLAGS) -shared example-plugin-fd.o -o example-plugin-fd.so
-
-bpipe-fd.o: bpipe-fd.c ${FDDIR}/fd_plugins.h
-       $(CXX) $(DEFS) $(DEBUG) $(CPPFLAGS) -fPIC -I../.. -I${FDDIR} -c bpipe-fd.c
+all: bpipe-fd.la
 
 bpipe-fd.lo: bpipe-fd.c ${FDDIR}/fd_plugins.h
        $(LIBTOOL_COMPILE) $(CXX) $(DEFS) $(DEBUG) $(CPPFLAGS) $(CFLAGS) -I../.. -I${FDDIR} -c bpipe-fd.c
 bpipe-fd.la: Makefile bpipe-fd$(DEFAULT_OBJECT_TYPE)
        $(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -shared bpipe-fd.lo -o $@ -rpath $(plugindir) -module -export-dynamic -avoid-version 
 
-bpipe-fd.so: bpipe-fd.o
-       $(CXX) $(LDFLAGS) -shared bpipe-fd.o -o $@
-
 install: all
        $(MKDIR) $(DESTDIR)$(plugindir)
-       $(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) bpipe-fd$(DEFAULT_SHARED_OBJECT_TYPE) $(DESTDIR)$(plugindir)
+       $(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) bpipe-fd.la $(DESTDIR)$(plugindir)
        $(RMF) $(DESTDIR)$(plugindir)/bpipe-fd.la
 
 libtool-clean:
 distclean: clean
        @rm -f Makefile
 
-uninstall:
-       $(RMF) $(DESTDIR)$(plugindir)/bpipe-fd.so
+libtool-uninstall:
+       $(LIBTOOL_UNINSTALL) $(RMF) $(DESTDIR)$(plugindir)/bpipe-fd.so
+
+uninstall: @LIBTOOL_UNINSTALL_TARGET@
 
 depend:
 
 
 .SUFFIXES:    .c .o .lo
 
-.c.o:
-       $(CXX) $(DEFS) $(DEBUG) $(CPPFLAGS) -I${SRCDIR} -I${SDDIR} -DTEST_PROGRAM -c $<
-
 .c.lo:
        $(LIBTOOL_COMPILE) $(CXX) $(DEFS) $(DEBUG) $(CPPFLAGS) -I${SRCDIR} -I${SDDIR} -DTEST_PROGRAM -c $<
 
-all: example-plugin-sd$(DEFAULT_SHARED_OBJECT_TYPE)
-
-test: main example-plugin-sd.so
-
-dir_plugins.o: ${SDDIR}/dir_plugins.h ${SDDIR}/dir_plugins.c
-       $(CXX) -I${SRCDIR} -I${SDDIR} -DTEST_PROGRAM -c ${SDDIR}/dir_plugins.c 
-
-main: dir_plugins.o
-       $(CXX) $(LDFLAGS) -L${LIBDIR} dir_plugins.o -o main -lbac -lpthread -lssl -l crypto -ldl
-
-example-plugin-sd.o: example-plugin-sd.c ${SDDIR}/dir_plugins.h
-       $(CXX) $(DEFS) $(DEBUG) $(CPPFLAGS) -fPIC -I../.. -I${SDDIR} -c example-plugin-sd.c
-
-example-plugin-sd.so: example-plugin-sd.o 
-       $(CXX) $(LDFLAGS) -shared example-plugin-sd.o -o example-plugin-sd.so
+all: example-plugin-sd.la
 
 example-plugin-sd.lo: example-plugin-sd.c ${SDDIR}/dir_plugins.h
        $(LIBTOOL_COMPILE) $(CXX) $(DEFS) $(DEBUG) $(CFLAGS) -I../.. -I${SDDIR} -c example-plugin-sd.c
 distclean: clean
        rm -f Makefile
 
-uninstall:
-       $(RMF) $(DESTDIR)$(plugindir)/example-plugin-sd.so
+libtool-uninstall:
+       $(LIBTOOL_UNINSTALL) $(RMF) $(DESTDIR)$(plugindir)/example-plugin-sd.so
+
+uninstall: @LIBTOOL_UNINSTALL_TARGET@
 
 depend: