#
# PostGIS - Spatial Types for PostgreSQL
# http://www.postgis.net
#
# This is free software; you can redistribute and/or modify it under
# the terms of the GNU General Public Licence. See the COPYING file.
#
# PostGIS documentation build Makefile
#
# Copyright 2003-2023 Sandro Santilli <strk@kbt.io>
# Copyright 2004-2012 Paul Ramsey <pramsey@cleverelephant.ca>
# Copyright 2009-2022 Regina Obe <lr@pcorp.us>
# Copyright 2008-2010 Mark Cave-Ayland
# Copyright 2008-2010 Kevin Neufeld <kneufeld.ca@gmail.com>
# Copyright 2009-2010 Olivier Courtin <olivier.courtin@camptocamp.com>
# Copyright 2005-2006 Markus Schaber <markus@schabi.de>
#
# NOTE: We don't use a standard PGXS Makefile here since the DOCS target
# only allows files to be stored within contrib/ and we currently
# store documentation under contrib/postgis due to the possibility
# that we could produce a large number of files (think chunked HTML)
#

translations = it_IT pt_BR fr es pl ka ko_KR de ja ru zh_Hans ro uk

PACKAGE_TARNAME = @PACKAGE_TARNAME@

prefix = @prefix@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
abs_top_srcdir = @abs_top_srcdir@
datarootdir = @datarootdir@
datadir = @datadir@
builddir = @builddir@
top_builddir = @top_builddir@
abs_top_builddir = @abs_top_builddir@
mandir = @mandir@
abs_srcdir = @abs_srcdir@
abs_builddir = @abs_builddir@
docdir = @docdir@
htmldir = @htmldir@

POSTGIS_MAJOR_VERSION=@POSTGIS_MAJOR_VERSION@
POSTGIS_MINOR_VERSION=@POSTGIS_MINOR_VERSION@
POSTGIS_MICRO_VERSION=@POSTGIS_MICRO_VERSION@

DOCSUFFIX=-en

# TODO: change this ?
html_builddir=$(abs_builddir)/html
images_builddir=$(html_builddir)/images

ifneq (,$(findstring dev,$(POSTGIS_MICRO_VERSION)))
  POSTGIS_DOWNLOAD_URL=https://postgis.net/stuff
else
  POSTGIS_DOWNLOAD_URL=https://download.osgeo.org/postgis/source
endif

INSTALL=@INSTALL@
INSTALL_DATA=@INSTALL_DATA@

XMLCATALOG=@XMLCATALOG@
XSLTPROC=@XSLTPROC@
XSLBASE=@XSLBASE@
DOCBOOK5_RNG=@DOCBOOK5_RNG@
DOCBOOK5_DTD=@DOCBOOK5_DTD@
CAN_UPDATE_TRANSLATIONS=@CAN_UPDATE_TRANSLATIONS@
XMLLINT=@XMLLINT@
CAN_BUILD_COMMENTS=@CAN_BUILD_COMMENTS@
PERL=@PERL@
#CAN_BUILD_PDF=@CAN_BUILD_PDF@
#CAN_BUILD_EPUB=@CAN_BUILD_EPUB@

# To allow network access use:
#
# $(MAKE) html XSLTPROCFLAGS=
#
ifeq ($(XSLTPROCFLAGS),)
	XSLTPROCFLAGS=--nonet
endif

XSLT_PATH= \
	$(builddir):$(abs_srcdir)

XSLTPROC_PATH_OPT= \
	--path "$(XSLT_PATH)"

XSLTPROC_CUSTOM_VARS = \
	--stringparam postgis_version $(POSTGIS_MAJOR_VERSION).$(POSTGIS_MINOR_VERSION) \
	--stringparam postgis_language $(patsubst -%,%,$(DOCSUFFIX))/

XSLTPROC_COMMONOPTS= \
	$(XSLTPROC_PATH_OPT) \
	--param section.autolabel 1 \
	--param section.label.includes.component.label 1 \
	--param chunk.section.depth 0 \
	--param generate.section.toc.level 2 \
	--param toc.section.depth 1 \
	--param funcsynopsis.style kr \
	--param admon.graphics 1 \
	--param admon.textlabel 0 \
	--param make.clean.html 1 \
	--param simplesect.in.toc 0 \
	--param use.id.as.filename 1 \
	--param chunk.quietly 1 \
	--param header.rule 0 \
	--param footer.rule 0 \
	--param table.borders.with.css 1 \
	--stringparam docbook.css.source "" \
	--stringparam html.ext .html \
	--stringparam saxon.character.representation decimal \
	$(XSLTPROCFLAGS)

XSLTPROC_CHUNKED_HTML_OPTS = \
	--stringparam chunker.output.encoding UTF-8 \
	--stringparam chunker.output.indent yes \
	--stringparam admon.graphics.path ../images/ \
	--stringparam img.src.path ../ \
	--stringparam html.stylesheet ../style.css

HTML_DOCBOOK_XSL=$(XSLBASE)/xhtml5/docbook.xsl
CHUNK_HTML_DOCBOOK_XSL=$(XSLBASE)/xhtml5/chunk.xsl

# DBLatex's dblatex script for PDF generation from DocBook
DBLATEX=@DBLATEX@

# Gettext for translated documentation
MSGCAT=@MSGCAT@
MSGCOMM=@MSGCOMM@
MSGMERGE=@MSGMERGE@
MSGINIT=@MSGINIT@
MSGATTRIB=@MSGATTRIB@

# XML gettext tools
XML2POT=@XML2POT@

# DOCBOOK to EPUB
DBTOEPUB=@DBTOEPUB@

# Directories for postgresql subdirectories
PGSQL_DOCDIR=@PGSQL_DOCDIR@

BUILD_TARGET =

ifeq ($(CAN_BUILD_COMMENTS),yes)
BUILD_TARGET += comments
endif

ifeq ($(CAN_BUILD_PDF),yes)
BUILD_TARGET += pdf
endif

ifeq ($(CAN_BUILD_EPUB),yes)
BUILD_TARGET += epub
endif


# TODO: add "html" to the BUILD_TARGET if it can be built

all: $(BUILD_TARGET)

XML_SOURCES = \
	administration.xml \
	database_tuning.xml \
	extras_address_standardizer.xml \
	extras_historytable.xml \
	extras_tigergeocoder.xml \
	extras_topology.xml \
	extras.xml \
	installation.xml \
	introduction.xml \
	performance_tips.xml \
	postgis_special.xml \
	postgis.xml \
	reference_accessor.xml \
	reference_bbox.xml \
	reference_cluster.xml \
	reference_constructor.xml \
	reference_coverage.xml \
	reference_editor.xml \
	reference_exception.xml \
	reference_guc.xml \
	reference_input.xml \
	reference_lrs.xml \
	reference_management.xml \
	reference_measure.xml \
	reference_operator.xml \
	reference_output.xml \
	reference_overlay.xml \
	reference_processing.xml \
	reference_raster.xml \
	reference_relationship.xml \
	reference_sfcgal.xml \
	reference_srs.xml \
	reference_trajectory.xml \
	reference_transformation.xml \
	reference_troubleshooting.xml \
	reference_type.xml \
	reference_validation.xml \
	reference_version.xml \
	reference.xml \
	release_notes.xml \
	reporting.xml \
	using_postgis_dataman.xml \
	using_postgis_query.xml \
	using_raster_dataman.xml \
	xsl-config.xml

XSL_GENERATED_SOURCES = \
	list_3d_functions.xsl.xml \
	list_aggregates.xsl.xml \
	list_box_functions.xsl.xml \
	list_curved_geometry_functions.xsl.xml \
	list_dump_functions.xsl.xml \
	list_geography_functions.xsl.xml \
	list_new_functions.xsl.xml \
	list_raster_functions.xsl.xml \
	list_sqlmm_functions.xsl.xml \
	list_window_functions.xsl.xml \
	table_body_function_support_matrix.xsl.xml \
	list_polyhedral_functions.xsl.xml

TAG_GENERATED_SOURCES = \
	address_standardizer_required.tag \
	curve_support.tag \
	geography_transform.tag \
	index_aware.tag \
	M_support.tag \
	P_support.tag \
	sfcgal_enhanced.tag \
	sfcgal_required.tag \
	sfs_compliant.tag \
	sqlmm_compliant.tag \
	T_support.tag \
	Z_support.tag \
	overlay_gridsize_arg.tag

XML_GENERATED_SOURCES = \
	$(XSL_GENERATED_SOURCES)

XML_INPUTS = $(XML_SOURCES) $(XML_GENERATED_SOURCES) $(TAG_GENERATED_SOURCES)

XML_SOURCE_POTS = $(XML_SOURCES:%.xml=%.xml.pot)

XML_UNIFIED_POT = $(srcdir)/po/templates/postgis-manual.pot

PO_FILES = $(patsubst \
	%, \
	$(srcdir)/po/%/postgis-manual.po, \
	$(translations) \
)

GENERATED_COMMENT_FILES = $(patsubst \
	$(srcdir)/xsl/%.xsl, \
	%, \
	$(wildcard $(srcdir)/xsl/*_comments.sql.xsl) \
)

GENERATED_CHEATSHEET_FILES = $(patsubst \
	$(abs_srcdir)/xsl/%.html.xsl, \
	$(html_builddir)/%$(DOCSUFFIX).html, \
	$(wildcard $(abs_srcdir)/xsl/*_cheatsheet.html.xsl) \
)

VPATH = $(srcdir)


CAN_CHECK_XML = yes

ifeq ($(XMLLINT),)
postgis-nospecial.xml: requirements_not_met_xmllint
postgis-out.xml: requirements_not_met_xmllint
check-cheatsheets: requirements_not_met_xmllint
check-xml: requirements_not_met_xmllint
CAN_CHECK_XML = no
endif

ifeq ($(XMLCATALOG),)
check-xml: requirements_not_met_xmlcatalog
CAN_CHECK_XML = no
endif

ifeq ($(DOCBOOK5_RNG),)
CAN_CHECK_XML = no
endif

ifeq ($(DOCBOOK5_DTD),)
CAN_CHECK_XML = no
endif

ifeq ($(MSGMERGE),)
$(PO_FILES): requirements_not_met_msgmerge
endif

ifeq ($(MSGATTRIB),)
$(PO_FILES): requirements_not_met_msgattrib
endif

ifeq ($(MSGCOMM),)
$(PO_FILES): requirements_not_met_msgcomm
$(XML_UNIFIED_POT): requirements_not_met_msgcomm
endif

ifeq ($(MSGCAT),)
$(XML_UNIFIED_POT): requirements_not_met_msgcat
endif

ifeq ($(MSGINIT),)
$(PO_FILES): requirements_not_met_msginit
endif

ifeq ($(XML2POT),)
$(XML_SOURCE_POTS): requirements_not_met_xml2pot
endif

CHECK_UNIT_TARGET =

ifeq ($(CAN_CHECK_XML),yes)
CHECK_UNIT_TARGET = check-xml
endif


$(XML_SOURCE_POTS): %.xml.pot: %.xml po/strip_untranslatable.sh
	$(XML2POT) $< > $@
	$(abs_srcdir)/po/strip_untranslatable.sh $@

# Update translation template
update-pot: $(XML_UNIFIED_POT)

$(XML_UNIFIED_POT): $(XML_SOURCE_POTS)
	@$(MSGCAT) --sort-by-file --use-first --no-location -o $@.tmp $(XML_SOURCE_POTS)
	@if test -f $@; then \
    if test -n "$$($(MSGCOMM) --unique $@.tmp $@ | tail -1)"; then \
      echo "$@ updated"; \
    else \
      echo "$@ unchanged"; \
      rm -f $@.tmp; \
    fi; \
  fi; \
  if test -f $@.tmp; then \
    mv $@.tmp $@; \
  fi;

# Creates or updates translation files
update-po: $(PO_FILES)

$(PO_FILES): $(XML_UNIFIED_POT)
	@mkdir -p `dirname $@`
	@lang=`basename $$(dirname $@)`; \
	if test -f $@; then \
		$(MSGMERGE) --no-fuzzy-matching -q -o $@.tmp $@ $(XML_UNIFIED_POT) || exit 1; \
		$(MSGATTRIB) --no-obsolete -o $@.tmp $@.tmp || exit 1; \
		if test -n "$$($(MSGCOMM) --unique $@.tmp $@ | tail -1)"; then \
			mv $@.tmp $@; \
			echo "$@ updated"; \
		else \
			echo "$@ unchanged"; \
			touch $@; \
			rm -f $@.tmp; \
		fi; \
	else \
		$(MSGINIT) -i $(XML_UNIFIED_POT) -o $@ -l $$lang --no-translator || exit 1; \
		echo "$@ created"; \
	fi;

ifeq ($(XSLTPROC),)
$(XSL_GENERATED_SOURCES): requirements_not_met_xsltproc
else
$(XSL_GENERATED_SOURCES): %.xsl.xml: xsl/%.xml.xsl postgis-nospecial.xml xsl-config.xml $(TAG_GENERATED_SOURCES) $(XML_SOURCES)
	$(XSLTPROC) --novalid $(XSLTPROC_PATH_OPT) -o $@ $< postgis-nospecial.xml
endif

ifeq ($(XSLTPROC),)
$(TAG_GENERATED_SOURCES): requirements_not_met_xsltproc
else
$(TAG_GENERATED_SOURCES): xsl/node_by_xpath.xsl xsl-config.xml | Makefile
	tag=tag_$(basename $(notdir $@)); \
	$(XSLTPROC) --stringparam xpath "/config/tags/para[@role='$$tag']/node()" -o $@ $^
	test -s $@ # ensure something was extracted
endif

$(GENERATED_COMMENT_FILES): %.sql: xsl/%.sql.xsl postgis-out.xml xsl/common_utils.xsl xsl/common_comments.xsl
	$(XSLTPROC) --novalid $(XSLTPROCFLAGS) $(XSLTPROC_PATH_OPT) -o $@ $< postgis-out.xml

$(GENERATED_CHEATSHEET_FILES): $(html_builddir)/%$(DOCSUFFIX).html: xsl/%.html.xsl postgis-out.xml xsl/common_cheatsheet.xsl xsl/common_utils.xsl
	$(XSLTPROC) --novalid $(XSLTPROCFLAGS) $(XSLTPROC_PATH_OPT) $(XSLTPROC_CUSTOM_VARS) -o $@ $< postgis-out.xml

postgis-nospecial.xml: postgis.xml $(XML_SOURCES) $(TAG_GENERATED_SOURCES) Makefile
	grep -v '\&postgis_special;' $< > $@.in
	$(XMLLINT) $(XSLTPROC_PATH_OPT) --noent -o $@ $@.in

# TODO: use a postgis_release_version variable passed via --stringparam
postgis-out.xml: postgis.xml Makefile $(XML_INPUTS) Makefile
	$(PERL) -lpe "s'@@LAST_RELEASE_VERSION@@'${POSTGIS_MAJOR_VERSION}.${POSTGIS_MINOR_VERSION}.${POSTGIS_MICRO_VERSION}'g;s'@@POSTGIS_DOWNLOAD_URL@@'${POSTGIS_DOWNLOAD_URL}'g;" $< > $@.in
	$(XMLLINT) $(XSLTPROC_PATH_OPT) --noent -o $@ $@.in

chunked-html: $(html_builddir)/postgis$(DOCSUFFIX)/index.html
$(html_builddir)/postgis$(DOCSUFFIX)/index.html: postgis-out.xml Makefile
	$(XSLTPROC) $(XSLTPROC_COMMONOPTS) \
		$(XSLTPROC_CHUNKED_HTML_OPTS) \
		$(XSLTPROCFLAGS) \
		--output $(dir $@) \
		$(CHUNK_HTML_DOCBOOK_XSL) \
		$<

html: $(html_builddir)/postgis$(DOCSUFFIX).html

%-localized:
	rule=$(patsubst %-localized,%,$@); \
	for lang in $(translations); do \
    echo "Making $$rule for language $$lang..."; \
    $(MAKE) -C po/$$lang local-$$rule || exit 1; \
  done

$(html_builddir)/postgis$(DOCSUFFIX).html: postgis-out.xml Makefile
	$(XSLTPROC) $(XSLTPROC_COMMONOPTS) \
		--stringparam html.stylesheet style.css \
		--output $(html_builddir)/postgis$(DOCSUFFIX).html \
		$(HTML_DOCBOOK_XSL) \
		$<


postgis-${POSTGIS_MAJOR_VERSION}.${POSTGIS_MINOR_VERSION}.${POSTGIS_MICRO_VERSION}$(DOCSUFFIX).pdf: postgis-out.xml $(abs_srcdir)/texstyle-common.sty $(abs_srcdir)/texstyle.sty | images
ifeq ($(DBLATEX),)
	@echo
	@echo "configure was unable to find the 'dblatex' utility program."
	@echo "To create pdf files, install dblatex and then re-run configure."
	@echo
	@false
else
	$(DBLATEX) -T native -t pdf \
		 -x "--path $(XSLT_PATH)" \
		 -I "$(abs_builddir)/html" \
		 -P doc.collab.show=0 \
		 -P figure.note="images/note" \
		 -P figure.tip="images/tip" \
		 -P figure.important="images/important" \
		 -P figure.warning="images/warning" \
		 -P figure.caution="images/caution" \
		 -P latex.output.revhistory=0 \
		 --texinputs "$(srcdir):$(abs_srcdir)" \
		 -s "texstyle" \
		 $(DBLATEX_EXTRA_OPTIONS) \
		 -o postgis-${POSTGIS_MAJOR_VERSION}.${POSTGIS_MINOR_VERSION}.${POSTGIS_MICRO_VERSION}$(DOCSUFFIX).pdf $<
endif

pdf-install: postgis-${POSTGIS_MAJOR_VERSION}.${POSTGIS_MINOR_VERSION}.${POSTGIS_MICRO_VERSION}$(DOCSUFFIX).pdf
	mkdir -p $(DESTDIR)$(docdir)
	$(INSTALL_DATA) $< $(DESTDIR)$(docdir)/

pdf-uninstall:
	rm -f $(DESTDIR)$(docdir)/postgis-${POSTGIS_MAJOR_VERSION}.${POSTGIS_MINOR_VERSION}.${POSTGIS_MICRO_VERSION}$(DOCSUFFIX).pdf

postgis-${POSTGIS_MAJOR_VERSION}.${POSTGIS_MINOR_VERSION}.${POSTGIS_MICRO_VERSION}$(DOCSUFFIX).epub: postgis-out.xml images
ifeq ($(DBTOEPUB),)
	@echo
	@echo "configure was unable to find the 'dbtoepub' utility program."
	@echo "To create pdf files, install dbtoepub and then re-run configure."
	@echo
	@false
else
	ln -fs html/images .; # work around https://trac.osgeo.org/postgis/ticket/5422
	$(DBTOEPUB) -c "${PWD}/html/style.css" \
	 -o postgis-${POSTGIS_MAJOR_VERSION}.${POSTGIS_MINOR_VERSION}.${POSTGIS_MICRO_VERSION}$(DOCSUFFIX).epub \
		$<
endif

epub-install: postgis-${POSTGIS_MAJOR_VERSION}.${POSTGIS_MINOR_VERSION}.${POSTGIS_MICRO_VERSION}$(DOCSUFFIX).epub
	mkdir -p $(DESTDIR)$(docdir)
	$(INSTALL_DATA) $< $(DESTDIR)$(docdir)/

epub-uninstall:
	rm -f $(DESTDIR)$(docdir)/postgis-${POSTGIS_MAJOR_VERSION}.${POSTGIS_MINOR_VERSION}.${POSTGIS_MICRO_VERSION}$(DOCSUFFIX).epub

epub: postgis-${POSTGIS_MAJOR_VERSION}.${POSTGIS_MINOR_VERSION}.${POSTGIS_MICRO_VERSION}$(DOCSUFFIX).epub

pdf: postgis-${POSTGIS_MAJOR_VERSION}.${POSTGIS_MINOR_VERSION}.${POSTGIS_MICRO_VERSION}$(DOCSUFFIX).pdf

doxygen.cfg: doxygen.cfg.in
	$(PERL) -lpe "s'@@LAST_RELEASE_VERSION@@'${POSTGIS_MAJOR_VERSION}.${POSTGIS_MINOR_VERSION}.${POSTGIS_MICRO_VERSION}'g" $< > $@

doxygen: doxygen.cfg
	doxygen $<

images images-install images-uninstall images-clean:
	$(MAKE) -C $(images_builddir) $@

html-clean:
	rm -f $(html_builddir)/postgis$(DOCSUFFIX).html
	rm -rf $(html_builddir)/postgis$(DOCSUFFIX)/

pdf-clean:
	rm -f postgis*$(DOCSUFFIX).pdf

epub-clean:
	rm -f postgis*$(DOCSUFFIX).epub

cheatsheet-install: $(GENERATED_CHEATSHEET_FILES)
	mkdir -p $(DESTDIR)$(htmldir)
	$(INSTALL_DATA) $(GENERATED_CHEATSHEET_FILES) $(DESTDIR)$(htmldir)/

cheatsheet-clean:
	rm -f $(GENERATED_CHEATSHEET_FILES)

clean: images-clean html-clean pdf-clean epub-clean cheatsheet-clean clean-pot
	rm -f images # work around https://trac.osgeo.org/postgis/ticket/5422
	rm -f $(XML_GENERATED_SOURCES)
	rm -f postgis-nospecial.xml postgis-nospecial.xml.in
	rm -f postgis-out.xml postgis-out.xml.in
	rm -f $(TAG_GENERATED_SOURCES)
	$(MAKE) -C $(images_builddir) clean
	rm -f postgis_gardentest_${POSTGIS_MAJOR_VERSION}${POSTGIS_MINOR_VERSION}.sql
	rm -f raster_gardentest_${POSTGIS_MAJOR_VERSION}${POSTGIS_MINOR_VERSION}.sql
	rm -f sfcgal_gardentest_${POSTGIS_MAJOR_VERSION}${POSTGIS_MINOR_VERSION}.sql
	rm -f *.tmp
	$(MAKE) clean-localized

clean-pot:
	rm -f *.pot

distclean: clean
	$(MAKE) -C $(images_builddir) distclean
	$(MAKE) distclean-localized
	rm -f Makefile Makefile.comments

maintainer-clean: distclean
	rm -f $(GENERATED_COMMENT_FILES)

ifneq ($(CAN_BUILD_COMMENTS),yes)
comments:
else
comments: $(GENERATED_COMMENT_FILES)
endif

cheatsheets: $(GENERATED_CHEATSHEET_FILES)

ifneq ($(CAN_BUILD_COMMENTS),yes)
comments-install:
	if test -e postgis_comments.sql  -a \
	        -e raster_comments.sql   -a \
	        -e topology_comments.sql -a \
	        -e sfcgal_comments.sql -a \
	        -e tiger_geocoder_comments.sql; then \
	  $(MAKE) -f Makefile.comments install; \
	fi
else
comments-install: comments
	$(MAKE) -f Makefile.comments install
endif

comments-uninstall:
	$(MAKE) -f Makefile.comments uninstall

man-install: man/shp2pgsql.1 man/pgsql2shp.1 man/pgtopo_export.1 man/pgtopo_import.1 man/postgis.1 man/postgis_restore.1
	mkdir -p $(DESTDIR)$(mandir)/man1
	for f in $^; do \
		$(INSTALL_DATA) $$f $(DESTDIR)$(mandir)/man1/`basename $$f`; \
	done

man-uninstall:
	rm -f $(DESTDIR)$(mandir)/man1/shp2pgsql.1
	rm -f $(DESTDIR)$(mandir)/man1/pgsql2shp.1
	rm -f $(DESTDIR)$(mandir)/man1/pgtopo_export.1
	rm -f $(DESTDIR)$(mandir)/man1/pgtopo_import.1
	rm -f $(DESTDIR)$(mandir)/man1/postgis.1
	rm -f $(DESTDIR)$(mandir)/man1/postgis_restore.1

html-install: $(html_builddir)/postgis$(DOCSUFFIX).html
	mkdir -p $(DESTDIR)$(htmldir)
	$(INSTALL_DATA) $(html_builddir)/postgis$(DOCSUFFIX).html $(DESTDIR)$(htmldir)/

html-uninstall:
	rm -f $(DESTDIR)$(htmldir)/postgis$(DOCSUFFIX).html

chunked-html-install: chunked-html
	mkdir -p $(DESTDIR)$(htmldir)
	cp -R $(html_builddir)/postgis$(DOCSUFFIX) $(DESTDIR)$(htmldir)/

chunked-html-uninstall:
	rm -rf $(DESTDIR)$(htmldir)/postgis$(DOCSUFFIX)/

html-assets-install: images-install
	$(INSTALL_DATA) $(abs_srcdir)/html/style.css $(DESTDIR)$(htmldir)/

html-assets-uninstall: images-install
	rm -f $(DESTDIR)$(htmldir)/style.css

docs-install: html-install html-assets-install
	mkdir -p $(DESTDIR)$(PGSQL_DOCDIR)/postgis
	$(INSTALL_DATA) ../README.postgis $(DESTDIR)$(PGSQL_DOCDIR)/postgis/README.postgis

docs-uninstall: html-uninstall html-assets-uninstall
	rm -f $(DESTDIR)$(PGSQL_DOCDIR)/postgis/README.postgis

install: comments-install man-install

uninstall: comments-uninstall man-uninstall

ifeq ($(XSLTPROC),)
garden: requirements_not_met_xsltproc
else
garden: postgis_gardentest_${POSTGIS_MAJOR_VERSION}${POSTGIS_MINOR_VERSION}.sql raster_gardentest_${POSTGIS_MAJOR_VERSION}${POSTGIS_MINOR_VERSION}.sql sfcgal_gardentest_${POSTGIS_MAJOR_VERSION}${POSTGIS_MINOR_VERSION}.sql
endif

%_gardentest_${POSTGIS_MAJOR_VERSION}${POSTGIS_MINOR_VERSION}.sql: xsl/%_gardentest.sql.xsl postgis-out.xml
	$(XSLTPROC) -o $@ $(XSLTPROC_PATH_OPT) $^

check: check-unit
check-regress:

check-unit: $(CHECK_UNIT_TARGET)

check-xml: postgis-out.xml
	# TODO: --schematron http://docbook.org/xml/5.0/sch/docbook.sch
	# See https://trac.osgeo.org/postgis/ticket/5532
	$(XMLLINT) --noout --nonet \
		--valid --loaddtd \
		--relaxng $(DOCBOOK5_RNG) \
		$<

check-cheatsheets: cheatsheets
	for f in $(html_builddir)/*_cheatsheet-en.html; do \
		$(abs_top_srcdir)/utils/check_localized_cheatsheets.sh $${f} en $(patsubst -%,%,$(DOCSUFFIX)) || exit 1; \
	done

requirements_not_met_xsltproc:
	@echo
	@echo "configure was unable to find 'xsltproc' which is required"
	@echo "to build the documentation."
	@echo "Install xsltproc and then re-run configure. Alternatively "
	@echo "refer to online manual:"
	@echo
	@echo "  http://postgis.net/documentation"
	@echo
	@false

requirements_not_met_xmllint:
	@echo
	@echo "configure was unable to find 'xmllint' which is required"
	@echo "to build the postgis comments and documentation."
	@echo "Install xmllint and then re-run configure."
	@echo
	@false

requirements_not_met_xmlcatalog:
	@echo
	@echo "configure was unable to find 'xmlcatalog' which is required"
	@echo "to check the postgis documentation."
	@echo "Install xmlcatalog and then re-run configure."
	@echo
	@false


requirements_not_met_xslbase:
	@echo
	@echo "configure was unable to find the Docbook XSL stylesheet directory"
	@echo "which is required to build the documentation."
	@echo "Install the Docbook XSL stylesheets and/or re-run configure "
	@echo "with the --with-xsldir option."
	@echo "Alternatively refer to online manual:"
	@echo
	@echo "  http://postgis.net/documentation"
	@echo

requirements_not_met_msginit: requirements_not_met_gettext
requirements_not_met_msgattrib: requirements_not_met_gettext
requirements_not_met_msgcat: requirements_not_met_gettext
requirements_not_met_msgcomm: requirements_not_met_gettext
requirements_not_met_msgmerge: requirements_not_met_gettext
requirements_not_met_gettext:
	@echo
	@echo "configure was unable to find gettext utility programs."
	@echo "To update the translation templates, install gettext and then re-run configure."
	@echo
	@false

requirements_not_met_xml2pot:
	@echo
	@echo "configure was unable to find the 'xml2pot' utility program."
	@echo "To update the translation templates, install poxml and then re-run configure."
	@echo
