# @configure_input@

# Package-specific substitution variables
package = @PACKAGE_NAME@
version = @PACKAGE_VERSION@
tarname = @PACKAGE_TARNAME@
distdir = $(tarname)-$(version)

# Prefix-specific substitution variables
prefix      = @prefix@
includedir  = @includedir@
docdir      = @docdir@
htmldir     = @htmldir@
libdir      = @libdir@
# Supplementary
exec_prefix = @exec_prefix@
libexecdir  = @libexecdir@
lispdir     = @lispdir@
# VPATH-specific substitution variables
srcdir = @srcdir@
VPATH  = @srcdir@
# Tool-specific substitution variables
CC        = @CC@
CFLAGS    = @CFLAGS@
CPPFLAGS  = @CPPFLAGS@
FC        = @FC@
FCFLAGS   = @FCFLAGS@
LIBS      = @LIBS@
LDFLAGS   = @LDFLAGS@
INSTALL   = @INSTALL@

.PHONY: FORCE all install uninstall clean clean-all check dist distcheck
.POSIX:
.SUFFIXES:

all install uninstall:
	cd src && $(MAKE) $@


check:
	cd tests && $(MAKE) $@


clean clean-all:
	cd src && $(MAKE) $@
	cd tests && $(MAKE) $@


dist: $(distdir).tar.gz


$(distdir).tar.gz: $(distdir)
	tar chof - $(distdir) | gzip -9 -c > $@
	$(RM) -r -- $(distdir)

# for now copy entire src/ directory into $(distdir) in order for distcheck rule to work
# later on can be changed to ship only files like *.c *.h *.f90 *.so *.mod
$(distdir): FORCE
	mkdir -p $(distdir)
	cp $(srcdir)/configure.ac $(distdir)
	cp $(srcdir)/configure $(distdir)
	cp $(srcdir)/config.h.in $(distdir)
	cp $(srcdir)/install-sh $(distdir)
	mkdir -p $(distdir)/src
	mkdir -p $(distdir)/tests
	mkdir -p $(distdir)/include
	mkdir -p $(distdir)/lib
	cp $(srcdir)/src/trexio*.c $(distdir)/src
	cp $(srcdir)/src/trexio*.h $(distdir)/src
	cp $(srcdir)/src/trexio*.f90 $(distdir)/src
	cp $(srcdir)/src/Makefile.in $(distdir)/src
	cp $(srcdir)/tests/test.c $(distdir)/tests
	cp $(srcdir)/tests/test.f90 $(distdir)/tests
	cp $(srcdir)/tests/Makefile.in $(distdir)/tests
	cp $(srcdir)/Makefile.in $(distdir)
	cp $(srcdir)/LICENSE $(distdir)


FORCE:
	-$(RM) -- $(distdir).tar.gz >/dev/null 2>&1
	-$(RM) -r -- $(distdir) >/dev/null 2>&1


distcheck: $(distdir).tar.gz
	gzip -cd $(distdir).tar.gz | tar xvf -
	cd $(distdir) && \
		./configure CC="$(CC)" CFLAGS="$(CFLAGS)" && \
		$(MAKE) && \
		$(MAKE) DESTDIR=$${PWD}/_inst install && \
		$(MAKE) DESTDIR=$${PWD}/_inst check && \
		$(MAKE) DESTDIR=$${PWD}/_inst uninstall && \
		$(MAKE) clean
	$(RM) -r -- $(distdir)
	@echo "*** Package $(distdir).tar.gz is ready for distribution."


Makefile: Makefile.in config.status
	./config.status $@


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