+# ------------------------------------------------------------------------------
+
+if ENABLE_LUA
+lua_LTLIBRARIES = \
+ src/lua/location.la
+
+luadir = $(LUA_INSTALL_CMOD)
+
+src_lua_location_la_SOURCES = \
+ src/lua/as.c \
+ src/lua/as.h \
+ src/lua/compat.h \
+ src/lua/country.c \
+ src/lua/country.h \
+ src/lua/database.c \
+ src/lua/database.h \
+ src/lua/location.c \
+ src/lua/location.h \
+ src/lua/network.c \
+ src/lua/network.h
+
+src_lua_location_la_CFLAGS = \
+ $(AM_CFLAGS) \
+ $(LUA_CFLAGS)
+
+src_lua_location_la_LDFLAGS = \
+ $(AM_LDFLAGS) \
+ $(LUA_LDFLAGS) \
+ -shared \
+ -module \
+ -avoid-version
+
+src_lua_location_la_LIBADD = \
+ src/libloc.la \
+ $(LUA_LIBS)
+endif
+
+EXTRA_DIST += \
+ src/lua/as.c \
+ src/lua/as.h \
+ src/lua/country.c \
+ src/lua/country.h \
+ src/lua/database.c \
+ src/lua/database.h \
+ src/lua/location.c \
+ src/lua/location.h \
+ src/lua/network.c \
+ src/lua/network.h
+
+LUA_TESTS = \
+ tests/lua/main.lua
+
+EXTRA_DIST += \
+ $(LUA_TESTS)
+
+# ------------------------------------------------------------------------------
+
+# 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
+
+build-perl: src/libloc.la
+ @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 NO_PACKLIST=1 NO_PERLLOCAL=1 \
+ INSTALLDIRS=vendor \
+ INC="-I$(abs_srcdir)/src" LIBS="-L$(abs_builddir)/src/.libs -lloc"
+ cd $(builddir)/src/perl && $(MAKE)
+ touch build-perl
+
+.PHONY: check-perl
+check-perl: testdata.db build-perl
+ cd $(builddir)/src/perl && $(MAKE) LD_LIBRARY_PATH="$(abs_builddir)/src/.libs" test \
+ database="../../$<" keyfile="$(abs_srcdir)/examples/public-key.pem"
+
+.PHONY: install-perl
+install-perl: build-perl
+ cd $(builddir)/src/perl && $(MAKE) install DESTDIR=$(DESTDIR)
+
+.PHONY: clean-perl
+clean-perl:
+ cd $(builddir)/src/perl && $(MAKE) distclean
+ rm -f build-perl
+
+.PHONY: uninstall-perl
+uninstall-perl:
+ rm -vf \
+ $(DESTDIR)/@PERL_MODPATH@/Location.pm \
+ $(DESTDIR)/@PERL_MODPATH@/auto/Location/Location.so \
+ $(DESTDIR)/@PERL_MANPATH@/Location.3pm
+ -rmdir $(DESTDIR)/@PERL_MODPATH@/auto/Location
+
+bin_SCRIPTS = \
+ src/scripts/location \
+ src/scripts/location-importer
+
+EXTRA_DIST += \
+ src/scripts/location.in \
+ src/scripts/location-importer.in
+
+CLEANFILES += \
+ src/scripts/location \
+ src/scripts/location-importer
+
+# ------------------------------------------------------------------------------
+
+# Use systemd timers if available
+if HAVE_SYSTEMD
+systemdsystemunit_DATA = \
+ src/systemd/location-update.service \
+ src/systemd/location-update.timer
+
+CLEANFILES += \
+ $(systemdsystemunit_DATA)
+
+INSTALL_DIRS += \
+ $(systemdsystemunitdir)
+
+# Otherwise fall back to cron
+else
+cron_daily_SCRIPTS = \
+ src/cron/location-update
+
+CLEANFILES += \
+ $(cron_daily_DATA)
+endif
+
+EXTRA_DIST += \
+ src/cron/location-update.in \
+ src/systemd/location-update.service.in \
+ src/systemd/location-update.timer.in
+
+# ------------------------------------------------------------------------------
+
+dist_database_DATA = \
+ data/database.db \
+ data/signing-key.pem
+
+install-data-hook:
+ chmod 444 $(DESTDIR)$(databasedir)/database.db
+
+.PHONY: update-database
+update-database:
+ curl https://location.ipfire.org/databases/1/location.db.xz | xz -d > data/database.db
+
+# ------------------------------------------------------------------------------
+