# -*- makefile -*-
GOBJECTS = $(SOURCES:%.scm=%.go) $(ELISP_SOURCES:%.el=%.go)

GUILE_WARNINGS ?= -W1
GUILE_OPTIMIZATIONS ?= -O2

moddir = $(pkgdatadir)/$(GUILE_EFFECTIVE_VERSION)/$(modpath)
nobase_mod_DATA = $(SOURCES) $(ELISP_SOURCES) $(NOCOMP_SOURCES)
ccachedir = $(pkglibdir)/$(GUILE_EFFECTIVE_VERSION)/ccache/$(modpath)
nobase_ccache_DATA = $(GOBJECTS)
EXTRA_DIST = $(SOURCES) $(ELISP_SOURCES) $(NOCOMP_SOURCES)
ETAGS_ARGS = $(SOURCES) $(ELISP_SOURCES) $(NOCOMP_SOURCES)

CLEANFILES = $(GOBJECTS)

# Make sure source files are installed first, so that the mtime of
# installed compiled files is greater than that of installed source
# files.  See
# <http://lists.gnu.org/archive/html/guile-devel/2010-07/msg00125.html>
# for details.
guile_install_go_files = install-nobase_ccacheDATA
$(guile_install_go_files): install-nobase_modDATA

AM_V_GUILEC = $(AM_V_GUILEC_$(V))
AM_V_GUILEC_ = $(AM_V_GUILEC_$(AM_DEFAULT_VERBOSITY))
AM_V_GUILEC_0 = @echo "  GUILEC" $@;

SUFFIXES = .scm .el .go

.scm.go:
	$(AM_V_GUILEC)GUILE_AUTO_COMPILE=0			\
	$(top_builddir)/meta/build-env				\
	guild compile --target="$(host)" $(GUILE_WARNINGS) $(GUILE_OPTIMIZATIONS) \
	  -L "$(abs_srcdir)" -L "$(abs_builddir)"		\
	  -L "$(abs_top_srcdir)/guile-readline"			\
	  -o "$@" "$<"

.el.go:
	$(AM_V_GUILEC)GUILE_AUTO_COMPILE=0			\
	$(top_builddir)/meta/build-env				\
	guild compile --target="$(host)" $(GUILE_WARNINGS) $(GUILE_OPTIMIZATIONS) \
	  -L "$(abs_srcdir)" -L "$(abs_builddir)"		\
	  -L "$(abs_top_srcdir)/guile-readline"			\
	  --from=elisp -o "$@" "$<"
