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

DARCS_VERSION	:= @DARCS_VERSION@
DEFS		:= @DEFS@
CPPFLAGS	:= @CPPFLAGS@ @DEFS@
CFLAGS		:= @CFLAGS@
OPTCCFLAGS      := $(addprefix -optc,$(CFLAGS) $(CPPFLAGS))
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 ThisVersion.lhs: _darcs/inventory ThisVersion.lhs.in \
				determine_release_state.pl
	perl determine_release_state.pl $(DARCS_VERSION) > RELEASE_STATE
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
ThisVersion.lhs: ThisVersion.lhs.in config.status
	sh config.status
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:

%.o : %.lhs
	$(GHC) $(CPPFLAGS) $(if $(GHCFLAGS_$@),$(GHCFLAGS_$@),$(GHCFLAGS)) -c $<
	@touch $*.hi

%.o : %.hs
	$(GHC) $(CPPFLAGS) $(if $(GHCFLAGS_$@),$(GHCFLAGS_$@),$(GHCFLAGS)) -c $<
	@touch $*.hi

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

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

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

%.hs : %.hsc
	hsc2hs $<

%.hi : %.o
	@:

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

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

