# 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		= /bin/sh

srcdir		= .
top_srcdir	= .
prefix		= /opt/tcl/8.6
exec_prefix	= /opt/tcl/8.6
datarootdir	= ${prefix}/share
libdir		= ${exec_prefix}/lib
mandir		= ${datarootdir}/man
bindir		= ${exec_prefix}/bin

DESTDIR		=
pkglibdir	= $(libdir)/ooxml1.13.1
top_builddir	= /Users/alex/src/ooxml

PACKAGE_NAME	= ooxml
PACKAGE_VERSION	= 1.13.1
CYGPATH		= echo

#========================================================================
# 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	= /Library/Frameworks/Tcl.framework
TCL_SRC_DIR	= /Users/alex/src/tcl8.6.17
EXTRA_PATH	= $(top_builddir):$(TCL_BIN_DIR)
TCLLIBPATH	= $(top_builddir)
TCLSH_ENV	= TCL_LIBRARY=`echo $(TCL_SRC_DIR)/library`
PKG_ENV		= LD_LIBRARY_PATH="$(EXTRA_PATH):$(@LD_LIBRARY_PATH_VAR@)" \
		  PATH="$(EXTRA_PATH):$(PATH)" \
		  TCLLIBPATH="$(TCLLIBPATH)"

TCLSH_PROG	= /opt/tcl/8.6/bin/tclsh8.6
TCLSH   	= $(PKG_ENV) $(TCLSH_ENV) $(TCLSH_PROG)

PKG_TCL_SOURCES	=  ooxml.tcl ooxml-docx.tcl ooxml-docx-lib.tcl ooxml-docx-math.tcl manifest.txt

CONFIG_CLEAN_FILES = Makefile pkgIndex.tcl manifest.txt
CLEANFILES	= 

HAVE_PANDOC	= yes

#========================================================================
# 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) `echo $(srcdir)/helper.tcl` cp $(PKG_TCL_SOURCES) pkgIndex.tcl $(pkglibdir)

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

archive: manifest.txt pkgIndex.tcl
	sh tools/archive.sh ooxml 1.13.1 $(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
