build: Install bash completion data
diff --git a/Makefile.am b/Makefile.am
index 57b7372..91a766a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -89,6 +89,10 @@
 EXTRA_DIST += libkmod/libkmod.pc.in
 CLEANFILES += libkmod/libkmod.pc
 
+bashcompletiondir=@bashcompletiondir@
+dist_bashcompletion_DATA = \
+	shell-completion/bash/kmod
+
 install-exec-hook:
 	if test "$(libdir)" != "$(rootlibdir)"; then \
 		$(MKDIR_P) $(DESTDIR)$(rootlibdir) && \
@@ -207,7 +211,8 @@
 DISTCLEAN_LOCAL_HOOKS += testsuite-distclean
 EXTRA_DIST += testsuite/rootfs-pristine
 
-DISTCHECK_CONFIGURE_FLAGS=--enable-gtk-doc --sysconfdir=/etc --with-zlib
+DISTCHECK_CONFIGURE_FLAGS=--enable-gtk-doc --sysconfdir=/etc --with-zlib \
+	--with-bashcompletiondir=$$dc_install_base/$(bashcompletiondir)
 
 distclean-local: $(DISTCLEAN_LOCAL_HOOKS)
 
diff --git a/configure.ac b/configure.ac
index 194dfab..15c69d4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -82,6 +82,15 @@
 	AC_MSG_NOTICE([zlib support not requested])
 ])
 
+AC_ARG_WITH([bashcompletiondir],
+	AS_HELP_STRING([--with-bashcompletiondir=DIR], [Bash completions directory]),
+	[],
+	[AS_IF([$($PKG_CONFIG --exists bash-completion)], [
+		with_bashcompletiondir=$($PKG_CONFIG --variable=completionsdir bash-completion)
+	] , [
+		with_bashcompletiondir=${datadir}/bash-completion/completions
+	])])
+AC_SUBST([bashcompletiondir], [$with_bashcompletiondir])
 
 #####################################################################
 # --enable-
@@ -194,7 +203,7 @@
 AC_OUTPUT
 AC_MSG_RESULT([
 	$PACKAGE $VERSION
-	======
+	=======
 
 	prefix:			${prefix}
 	sysconfdir:		${sysconfdir}
@@ -202,6 +211,7 @@
 	rootlibdir:		${rootlibdir}
 	includedir:		${includedir}
 	bindir:			${bindir}
+	Bash completions dir:   ${with_bashcompletiondir}
 
 	compiler:		${CC}
 	cflags:			${with_cflags} ${CFLAGS}