# Makefile.in --
#
#	If ths is "Makefile.in" then it is a template for a Makefile;  to generate 
#	the actual Makefile, run "./configure", which is a configuration script
#	generated by the "autoconf" program (constructs like "@foo@" will get
#	replaced in the actual Makefile.
#
# Copyright (C) 2019 Alexander Schoepe, Bochum, DE
#

#========================================================================
# Nothing of the variables below this line need to be changed.
#========================================================================

SHELL		= @SHELL@

srcdir		= @srcdir@
top_srcdir	= @top_srcdir@
prefix		= @prefix@
exec_prefix	= @exec_prefix@
datarootdir	= @datarootdir@
libdir		= @libdir@
mandir		= @mandir@
bindir		= @bindir@

DESTDIR		=
pkglibdir	= $(libdir)/@PACKAGE_NAME@@PACKAGE_VERSION@
top_builddir	= @abs_top_builddir@

PACKAGE_NAME	= @PACKAGE_NAME@
PACKAGE_VERSION	= @PACKAGE_VERSION@
CYGPATH		= @CYGPATH@

#========================================================================
# TCLLIBPATH seeds the auto_path in Tcl's init.tcl so we can test our
# package without installing.  The other environment variables allow us
# to test against an uninstalled Tcl.  Add special env vars that you
# require for testing here (like TCLX_LIBRARY).
#========================================================================

TCL_BIN_DIR	= @TCL_BIN_DIR@
TCL_SRC_DIR	= @TCL_SRC_DIR@
EXTRA_PATH	= $(top_builddir):$(TCL_BIN_DIR)
TCLLIBPATH	= $(top_builddir)
TCLSH_ENV	= TCL_LIBRARY=`@CYGPATH@ $(TCL_SRC_DIR)/library`
PKG_ENV		= LD_LIBRARY_PATH="$(EXTRA_PATH):$(@LD_LIBRARY_PATH_VAR@)" \
		  PATH="$(EXTRA_PATH):$(PATH)" \
		  TCLLIBPATH="$(TCLLIBPATH)"

TCLSH_PROG	= @TCLSH_PROG@
TCLSH   	= $(PKG_ENV) $(TCLSH_ENV) $(TCLSH_PROG)

PKG_TCL_SOURCES	= @PKG_TCL_SOURCES@ manifest.txt

CONFIG_CLEAN_FILES = Makefile pkgIndex.tcl manifest.txt
CLEANFILES	= @CLEANFILES@

HAVE_PANDOC	= @HAVE_PANDOC@

#========================================================================
# Start of user-definable TARGETS section
#========================================================================

# Keep the generated build files in sync with their templates, so that
# e.g. a version bump in configure.ac propagates automatically before
# any target is built (GNU make re-executes itself after remaking the
# Makefile).

configure: configure.ac
	autoconf

config.status: configure
	./config.status --recheck

Makefile: Makefile.in config.status
	./config.status Makefile

pkgIndex.tcl: pkgIndex.tcl.in config.status
	./config.status pkgIndex.tcl

manifest.txt: manifest manifest.uuid tools/mkversion.tcl configure.ac
	$(TCLSH) tools/mkversion.tcl > $@

havepandoc:
	@if test "${HAVE_PANDOC}" != "yes" ; then \
		echo "No pandoc found in the path. Pandoc is needed to" ;\
		echo "build the nroff and html versions of the documentation." ;\
	fi

doc/ooxml.html: doc/ooxml.md
	@if test "${HAVE_PANDOC}" = "yes" ; then \
		pandoc --template doc/ooxml-default.html -f markdown -t html doc/ooxml.md \
			--css tcl-docs.css -o doc/ooxml.html;\
	fi

doc/ooxml.n: doc/ooxml.md
	@if test "${HAVE_PANDOC}" = "yes" ; then \
		pandoc --standalone -f markdown -t man doc/ooxml.md -o doc/ooxml.n ;\
	fi

doc/ooxml-docx.html: doc/ooxml-docx.md
	@if test "${HAVE_PANDOC}" = "yes" ; then \
		pandoc --template doc/ooxml-default.html -f markdown -t html doc/ooxml-docx.md \
			--css tcl-docs.css -o doc/ooxml-docx.html;\
	fi

doc/ooxml-docx.n: doc/ooxml-docx.md
	@if test "${HAVE_PANDOC}" = "yes" ; then \
		pandoc --standalone -f markdown -t man doc/ooxml-docx.md \
			-o doc/ooxml-docx.n ;\
	fi

doc: havepandoc doc/ooxml.html doc/ooxml.n doc/ooxml-docx.html doc/ooxml-docx.n

all: havepandoc manifest.txt doc/ooxml.html doc/ooxml.n

install: all
	$(TCLSH) `@CYGPATH@ $(srcdir)/helper.tcl` cp $(PKG_TCL_SOURCES) pkgIndex.tcl $(pkglibdir)

test:
	$(TCLSH) `@CYGPATH@ $(srcdir)/tests/all.tcl` $(TESTFLAGS) \
	  -load "package ifneeded ${PACKAGE_NAME} ${PACKAGE_VERSION} [list source [file join `@CYGPATH@ $(srcdir)` $(PACKAGE_NAME).tcl]]"

archive: manifest.txt pkgIndex.tcl
	sh tools/archive.sh @PACKAGE_NAME@ @PACKAGE_VERSION@ $(PKG_TCL_SOURCES)

release: archive
	@echo ""
	@echo "Release packages for $(PACKAGE_NAME) $(PACKAGE_VERSION) created in uv/:"
	@ls -l uv/$(PACKAGE_NAME)$(PACKAGE_VERSION)*.zip uv/$(PACKAGE_NAME)$(PACKAGE_VERSION)*.tar.gz
	@echo "Publish them with: make publish"

publish:
	fossil uv add uv/$(PACKAGE_NAME)$(PACKAGE_VERSION).zip --as $(PACKAGE_NAME)$(PACKAGE_VERSION).zip
	fossil uv add uv/$(PACKAGE_NAME)$(PACKAGE_VERSION).tar.gz --as $(PACKAGE_NAME)$(PACKAGE_VERSION).tar.gz
	fossil uv add uv/$(PACKAGE_NAME)$(PACKAGE_VERSION)-src.tar.gz --as $(PACKAGE_NAME)$(PACKAGE_VERSION)-src.tar.gz
	fossil uv add uv/download.html --as download.html
	fossil uv sync
	fossil uv list

clean:
	-test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
	-rm -rf doc/ooxml.html doc/ooxml.n doc/ooxml-docx.html doc/ooxml-docx.n

distclean: clean
	-rm -f $(CONFIG_CLEAN_FILES)
	-rm -rf autom4te.cache
	-rm -f config.cache config.log config.status

.PHONY: install test archive release publish clean distclean
