#
# 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)) $(addprefix -opta,$(CFLAGS))
LDFLAGS		:= @LDFLAGS@ @LIBS@
OPTLLDFLAGS     := $(addprefix -optl,$(LDFLAGS))
GHCFLAGS	:= -cpp @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@
MAKEMANUAL      := @MAKEMANUAL@
PREPROCHTML	:= @PREPROCHTML@
MAKENSIS	:= @MAKENSIS@
GHC_LIBDIR      := @GHC_LIBDIR@

all : config @TARGETS@ microbench

install: all @INSTALLWHAT@

ifeq ('@I_AM_IN_REPO@', '1')
release/STATE src/ThisVersion.lhs: _darcs/hashed_inventory src/ThisVersion.lhs.in \
				release/determine_release_state.pl
	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
release/STATE:
	if test ! -f release/STATE then; echo -n unknown > release/STATE; fi
src/ThisVersion.lhs: src/ThisVersion.lhs.in config.status
	sh config.status
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: release/STATE darcs-stable.tar.gz

.SUFFIXES:

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 : %.lhs
	$(ANNOUNCE_GHC) $(call ghcflags_fancy,$@) -c $<
	@touch $*.hi

%.o : %.hs
	$(ANNOUNCE_GHC) $(call ghcflags_fancy,$@) -c $<
	@touch $*.hi

%.o : %.c
	$(ANNOUNCE_GHC) $(CPPFLAGS) $(OPTCCFLAGS) -c $<

% : src/%.lhs
	rm -f Main.hi Main.o
	$(ANNOUNCE_GHC) $(GHCFLAGS) $(OPTLLDFLAGS) -o $@ $^

% : src/%.hs
	rm -f Main.hi Main.o
	$(ANNOUNCE_GHC) $(GHCFLAGS) $(OPTLLDFLAGS) -o $@ $^

%.hs : %.hsc
	hsc2hs $<

%.hi : %.o
	@:

%.dvi : %.tex
	(cd `dirname $<` && $(LATEX) `basename $<`)
	while grep >/dev/null "Rerun to get cross-references right" $*.log; do \
	    (cd `dirname $<` && $(LATEX) `basename $<`); \
	done


%.pdf : %.tex
	(cd `dirname $<` && $(PDFLATEX) `basename $<`)
	while grep >/dev/null "Rerun to get cross-references right" $*.log; do \
	    (cd `dirname $<` && $(PDFLATEX) `basename $<`); \
	done

%.ps : %.dvi
	$(DVIPS) -t letter -o $@ $<

