[2/2] Install bash-completion files.

Message ID 20230224162206.89971-2-stefan.schantl@ipfire.org
State Accepted
Headers
Series [1/2] Add bash-completion file for the location command. |

Commit Message

Stefan Schantl Feb. 24, 2023, 4:22 p.m. UTC
  Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
---
 Makefile.am  |  9 +++++++++
 configure.ac | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)
  

Patch

diff --git a/Makefile.am b/Makefile.am
index 4da2ec5..4edb9e9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -13,6 +13,8 @@  if ENABLE_PERL
 BINDINGS += perl
 endif
 
+bashcompletiondir = @bashcompletiondir@
+
 AM_CPPFLAGS = \
 	-include $(top_builddir)/config.h \
 	-DSYSCONFDIR=\""$(sysconfdir)"\" \
@@ -172,6 +174,13 @@  EXTRA_DIST += \
 CLEANFILES += \
 	src/libloc.pc
 
+#dist_bashcompletion_DATA =
+
+if BUILD_BASH_COMPLETION
+dist_bashcompletion_DATA = \
+	bash-completion/location
+endif
+
 dist_pkgpython_PYTHON = \
 	src/python/database.py \
 	src/python/downloader.py \
diff --git a/configure.ac b/configure.ac
index edca1d4..e21574d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -55,6 +55,41 @@  AC_CHECK_PROGS(ASCIIDOC, [asciidoc])
 if test "${have_man_pages}" = "yes" && test -z "${ASCIIDOC}"; then
 	AC_MSG_ERROR([Required program 'asciidoc' not found])
 fi
+
+# - pkg-config -----------------------------------------------------------------
+
+m4_ifndef([PKG_PROG_PKG_CONFIG],
+	[m4_fatal([Could not locate the pkg-config autoconf
+		macros. These are usually located in /usr/share/aclocal/pkg.m4.
+		If your macros are in a different location, try setting the
+		environment variable AL_OPTS="-I/other/macro/dir" before running
+		./autogen.sh or autoreconf again. Make sure pkg-config is installed.])])
+
+PKG_PROG_PKG_CONFIG
+PKG_INSTALLDIR(['${usrlib_execdir}/pkgconfig'])
+
+# - bash-completion ------------------------------------------------------------
+
+#enable_bash_completion=yes
+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])
+
+AC_ARG_ENABLE([bash-completion],
+	AS_HELP_STRING([--disable-bash-completion], [do not install bash completion files]),
+	[], [enable_bash_completion=yes]
+)
+
+AM_CONDITIONAL([BUILD_BASH_COMPLETION], [test "x$enable_bash_completion" = xyes])
+
 # - debug ----------------------------------------------------------------------
 
 AC_ARG_ENABLE([debug],
@@ -206,6 +241,7 @@  AC_MSG_RESULT([
 
         debug:                  ${enable_debug}
         systemd support:        ${have_systemd}
+	bash-completion:        ${enable_bash_completion}
 
 	Bindings:
 	  perl:			${enable_perl}