#
# System properties as determined by Autoconf.
#
# @configure_input@
#
prefix		= @prefix@
exec_prefix	= @exec_prefix@
bindir		= @bindir@
sbindir		= @sbindir@
datarootdir	= @datarootdir@
mandir		= @mandir@
datadir		= @datadir@
sysconfdir	= @sysconfdir@
libexecdir	= @libexecdir@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
docdir		= @docdir@

DARCS_VERSION	= @DARCS_VERSION@
DEFS		= @DEFS@
CPPFLAGS	= @CPPFLAGS@ @DEFS@
CFLAGS		= @CFLAGS@
OPTCCFLAGS      = $(addprefix -optc,$(CFLAGS) $(CPPFLAGS))
LDFLAGS		= @LDFLAGS@
OPTLLDFLAGS     = $(addprefix -optl,$(LDFLAGS))
LIBS            = @LIBS@
OPTLLIBS        = $(filter-out -%,$(LIBS)) $(addprefix -optl,$(filter -%,$(LIBS)))
# GHCFLAGS detects if the output file is a profiling target, and
# adjusts itself accordingly.  GHCFLAGS_0 is just an intermediary.
GHCFLAGS	= $(if $(filter %_p %.p_o %.p_hi,$@),$(filter-out -threaded,$(GHCFLAGS0)) -prof -auto-all -hisuf p_hi -osuf p_o,$(GHCFLAGS0))
GHCFLAGS0	= @GHCFLAGS@ @CPPFLAGS@ @DEFS@
USE_GNULIBSHA1  = @USE_GNULIBSHA1@
HAVE_HTTP       = @HAVE_HTTP@
HAVE_CURSES     = @HAVE_CURSES@
HAVE_LIBCURL    = @HAVE_LIBCURL@
HAVE_LIBWWW     = @HAVE_LIBWWW@
HAVE_MAPI       = @HAVE_MAPI@
HAVE_TERMIO_H   = @HAVE_TERMIO_H@
SYS             = @SYS@
WXFLAGS		= @WXFLAGS@

GHC		= @GHC@
INSTALL		= @INSTALL@
INSTALL_DATA   	= @INSTALL_DATA@
LATEX		= @LATEX@
PDFLATEX	= @PDFLATEX@
DVIPS		= @DVIPS@
RUBBER		= @RUBBER@
MAKEMANUAL      = @MAKEMANUAL@
PREPROCHTML	= @PREPROCHTML@
MAKENSIS	= @MAKENSIS@
HADDOCK_VERSION = @HADDOCK_VERSION@

all : config @TARGETS@ microbench

install:: @INSTALLWHAT@

ifeq ('@I_AM_IN_REPO@', 'yes')
release/STATE src/ThisVersion.hs doc/index.html: _darcs/hashed_inventory src/ThisVersion.hs.in \
				release/determine_release_state.pl \
                                doc/index.html.in config.status
	perl release/determine_release_state.pl $(DARCS_VERSION) > release/STATE
src/Context.hs: _darcs/hashed_inventory stringify config.command
	PATH=".:$$PATH" darcs changes --context | cat config.command - \
		| ./stringify Context context > $@
else
src/ThisVersion.hs doc/index.html: release/STATE src/ThisVersion.hs.in \
				release/determine_release_state.pl \
                                doc/index.html.in config.status
	perl release/determine_release_state.pl $(DARCS_VERSION)
release/STATE:
	echo -n $(DARCS_VERSION) '(unknown)' > $@
src/Context.hs: stringify
	test -f $@ || echo unknown | ./stringify Context context > $@
endif

darcs-stable.tar.gz: dist
	ln -sf "darcs-$(DARCS_VERSION).tar.gz" $@
.PHONY: darcs-stable.tar.gz

.SUFFIXES:

# This is a hack to allow a normal GHCFLAGS to be overridden for a few
# source files, see the GHCFLAGS_src__*.o settings in GNUmakefile.
ghcflags_deslash=$(GHCFLAGS_$(subst /,__,$1))
ghcflags_fancy=$(if $(call ghcflags_deslash,$1),$(call ghcflags_deslash,$1),$(GHCFLAGS))

ifdef VERBOSE
ANNOUNCE_GHC=$(GHC)
else
ANNOUNCE_GHC=@echo [ghc] $@; $(GHC)
endif


%.o %.p_o : %.lhs
	$(ANNOUNCE_GHC) $(call ghcflags_fancy,$@) -c $<
%.o %.p_o : %.hs
	$(ANNOUNCE_GHC) $(call ghcflags_fancy,$@) -c $<
# stupid rule to do nothing to make a .hi file from a .o file.
%.hi: %.o
	@touch $@
%.p_hi: %.p_o
	@touch $@
%.o %.p_o : %.c
	$(ANNOUNCE_GHC) $(CPPFLAGS) $(OPTCCFLAGS) -c $<
% %_p: src/%.lhs
	@rm -f Main.hi Main.o
	$(ANNOUNCE_GHC) $(GHCFLAGS) $(OPTLLDFLAGS) -o $@ $^ $(OPTLLIBS)
% %_p: src/%.hs
	@rm -f Main.hi Main.o
	$(ANNOUNCE_GHC) $(GHCFLAGS) $(OPTLLDFLAGS) -o $@ $^ $(OPTLLIBS)

%.hs : %.hsc
	hsc2hs $<

# rubber(1) is a wrapper for TeX that suppresses boring output (while
# printing errors). It also uses temp dirs, so concurrent TeX runs are
# not a problem.
ifneq (,$(RUBBER))
%.pdf: %.tex
	cd $(<D) && $(RUBBER) --pdf $(<F)
%.ps: %.tex
	cd $(<D) && $(RUBBER) --ps $(<F)
else
%.dvi : %.tex
	cd $(<D) && $(LATEX) $(<F)
	while grep >/dev/null "Rerun to get cross-references right" $*.log; do \
	    (cd $(<D) && $(LATEX) $(<F)); \
	done

# The "| %.dvi" declares an order-only dependency, thereby ensuring
# that make -j2 won't run both pdflatex and latex at the same time,
# but still allowing PDFs to be built without ever building the PS or
# DVI versions.
%.pdf : %.tex | %.dvi
	cd $(<D) && $(PDFLATEX) $(<F)
	while grep >/dev/null "Rerun to get cross-references right" $*.log; do \
	    (cd $(<D) && $(PDFLATEX) $(<F)); \
	done
%.ps : %.dvi
	$(DVIPS) -t letter -o $@ $<
endif
