From: Michael Tremer Date: Sun, 29 Sep 2019 14:21:48 +0000 (+0000) Subject: perl: Automatically build modules X-Git-Tag: 0.9.0~50^2~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=747cbcb12b70a0ae6f7612eb4d82dbdda959ab84;p=location%2Flibloc.git perl: Automatically build modules Fixes: #12192 Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index fc6f313..75f6e6b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,6 +4,11 @@ ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS} AM_MAKEFLAGS = --no-print-directory SUBDIRS = . po +BINDINGS = + +if ENABLE_PERL +BINDINGS += perl +endif AM_CPPFLAGS = \ -include $(top_builddir)/config.h \ @@ -122,6 +127,57 @@ src_python_location_la_LIBADD = \ src/libloc.la \ $(PYTHON_LIBS) +# Compile & install bindings +all-local: $(foreach binding,$(BINDINGS),build-$(binding)) +check-local: $(foreach binding,$(BINDINGS),check-$(binding)) +install-exec-local: $(foreach binding,$(BINDINGS),install-$(binding)) +clean-local: $(foreach binding,$(BINDINGS),clean-$(binding)) +uninstall-local: $(foreach binding,$(BINDINGS),uninstall-$(binding)) + +# Perl Bindings +EXTRA_DIST += \ + src/perl/.gitignore \ + src/perl/Location.xs \ + src/perl/MANIFEST \ + src/perl/Makefile.PL \ + src/perl/lib/Location.pm \ + src/perl/t/Location.t \ + src/perl/typemap + +.PHONY: build-perl +build-perl: + @mkdir -p $(builddir)/src/perl/{lib,t} + @test -e $(builddir)/src/perl/Location.xs || ln -s --relative $(srcdir)/src/perl/Location.xs $(builddir)/src/perl/ + @test -e $(builddir)/src/perl/MANIFEST || ln -s --relative $(srcdir)/src/perl/MANIFEST $(builddir)/src/perl/ + @test -e $(builddir)/src/perl/Makefile.PL || ln -s --relative $(srcdir)/src/perl/Makefile.PL $(builddir)/src/perl/ + @test -e $(builddir)/src/perl/lib/Location.pm || ln -s --relative $(srcdir)/src/perl/lib/Location.pm $(builddir)/src/perl/lib/ + @test -e $(builddir)/src/perl/t/Location.t || ln -s --relative $(srcdir)/src/perl/t/Location.t $(builddir)/src/perl/t/ + @test -e $(builddir)/src/perl/typemap || ln -s --relative $(srcdir)/src/perl/typemap $(builddir)/src/perl/ + + cd $(builddir)/src/perl && $(PERL) Makefile.PL PREFIX="$(prefix)" \ + INC="-I$(abs_srcdir)/src" LIBS="-L$(abs_builddir)/src/.libs -lloc" + cd $(builddir)/src/perl && $(MAKE) + +.PHONY: check-perl +check-perl: + cd $(builddir)/src/perl && $(MAKE) test + +.PHONY: install-perl +install-perl: + cd $(builddir)/src/perl && $(MAKE) install + +.PHONY: clean-perl +clean-perl: + cd $(builddir)/src/perl && $(MAKE) distclean + +.PHONY: uninstall-perl +uninstall-perl: + rm -rvf \ + $(DESTDIR)/$(prefix)/lib/*/perl/*/Location.pm \ + $(DESTDIR)/$(prefix)/lib/*/perl/*/auto/Location \ + $(DESTDIR)/$(prefix)/lib/*/perl/*/perllocal.pod \ + $(DESTDIR)/$(prefix)/man/man3/Location.3pm + bin_SCRIPTS = \ src/python/location-query diff --git a/configure.ac b/configure.ac index 567c611..b573ddc 100644 --- a/configure.ac +++ b/configure.ac @@ -83,6 +83,15 @@ AC_SUBST([my_CFLAGS]) AM_PATH_PYTHON([3.4]) PKG_CHECK_MODULES([PYTHON], [python-${PYTHON_VERSION}]) +# Perl +AC_PATH_PROG(PERL, perl, no) +AC_SUBST(PERL) + +AX_PROG_PERL_MODULES(ExtUtils::MakeMaker,, AC_MSG_WARN(Need some Perl modules)) + +AC_ARG_ENABLE(perl, AS_HELP_STRING([--disable-perl], [do not build the perl modules]), [],[enable_perl=yes]) +AM_CONDITIONAL(ENABLE_PERL, test "$enable_perl" = "yes") + AC_CONFIG_HEADERS(config.h) AC_CONFIG_FILES([ Makefile @@ -104,4 +113,7 @@ AC_MSG_RESULT([ ldflags: ${LDFLAGS} debug: ${enable_debug} + + Bindings: + perl: ${enable_perl} ]) diff --git a/m4/ax_prog_perl_modules.m4 b/m4/ax_prog_perl_modules.m4 new file mode 100644 index 0000000..70b3230 --- /dev/null +++ b/m4/ax_prog_perl_modules.m4 @@ -0,0 +1,77 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_prog_perl_modules.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_PROG_PERL_MODULES([MODULES], [ACTION-IF-TRUE], [ACTION-IF-FALSE]) +# +# DESCRIPTION +# +# Checks to see if the given perl modules are available. If true the shell +# commands in ACTION-IF-TRUE are executed. If not the shell commands in +# ACTION-IF-FALSE are run. Note if $PERL is not set (for example by +# calling AC_CHECK_PROG, or AC_PATH_PROG), AC_CHECK_PROG(PERL, perl, perl) +# will be run. +# +# MODULES is a space separated list of module names. To check for a +# minimum version of a module, append the version number to the module +# name, separated by an equals sign. +# +# Example: +# +# AX_PROG_PERL_MODULES( Text::Wrap Net::LDAP=1.0.3, , +# AC_MSG_WARN(Need some Perl modules) +# +# LICENSE +# +# Copyright (c) 2009 Dean Povey +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 8 + +AU_ALIAS([AC_PROG_PERL_MODULES], [AX_PROG_PERL_MODULES]) +AC_DEFUN([AX_PROG_PERL_MODULES],[dnl + +m4_define([ax_perl_modules]) +m4_foreach([ax_perl_module], m4_split(m4_normalize([$1])), + [ + m4_append([ax_perl_modules], + [']m4_bpatsubst(ax_perl_module,=,[ ])[' ]) + ]) + +# Make sure we have perl +if test -z "$PERL"; then +AC_CHECK_PROG(PERL,perl,perl) +fi + +if test "x$PERL" != x; then + ax_perl_modules_failed=0 + for ax_perl_module in ax_perl_modules; do + AC_MSG_CHECKING(for perl module $ax_perl_module) + + # Would be nice to log result here, but can't rely on autoconf internals + $PERL -e "use $ax_perl_module; exit" > /dev/null 2>&1 + if test $? -ne 0; then + AC_MSG_RESULT(no); + ax_perl_modules_failed=1 + else + AC_MSG_RESULT(ok); + fi + done + + # Run optional shell commands + if test "$ax_perl_modules_failed" = 0; then + : + $2 + else + : + $3 + fi +else + AC_MSG_WARN(could not find perl) +fi])dnl