#
# 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@
HAVE_CURSES     := @HAVE_CURSES@
HAVE_LIBCURL    := @HAVE_LIBCURL@
HAVE_MAPI       := @HAVE_MAPI@
SYS             := @SYS@
WXFLAGS		:= @WXFLAGS@

GHC		:= @GHC@
INSTALL		:= @INSTALL@
INSTALL_DATA   	:= @INSTALL_DATA@
LATEX		:= @LATEX@
DVIPS		:= @DVIPS@
MAKEMANUAL      := @MAKEMANUAL@
PREPROCHTML	:= @PREPROCHTML@
MAKENSIS	:= @MAKENSIS@
GHC_LIBDIR      := @GHC_LIBDIR@

GIT_SRCS        := @GIT_SRCS@
GIT_C_OBJS      := @GIT_C_OBJS@
GHCFLAGS_Git.o   = $(GHCFLAGS) @GIT_GHC_FLAGS@

all : config @TARGETS@

install: all @INSTALLWHAT@

ifeq ('@I_AM_IN_REPO@', '1')
release/STATE src/ThisVersion.lhs: _darcs/inventory src/ThisVersion.lhs.in \
				release/determine_release_state.pl
	perl release/determine_release_state.pl $(DARCS_VERSION) > release/STATE
src/Context.hs: _darcs/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

# Weird and wonderful GNU Make "target-specific variable" syntax
ifneq (,'@GIT_C_OBJS@')
$(GIT_C_OBJS) : OPTCCFLAGS+= @GIT_GHC_FLAGS@
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))

%.o : %.lhs
	$(GHC) $(CPPFLAGS) $(call ghcflags_fancy,$@) -c $<
	@touch $*.hi

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

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

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

% : src/%.hs
	rm -f Main.hi Main.o
	$(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

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

