# @configure_input@
# FULLDEBUG = TRUE
include ../../include/config.Makefile
VPATH = @srcdir@
CPPFLAGS += -I@srcdir@ -I.
YACC = @YACC@
%.tab.c %.tab.h: %.y; $(YACC.y) $< && mv y.tab.c $*.tab.c && mv y.tab.h $*.tab.h
%.fixed.c : %.tab.c
	sed 's="bison.simple"="/usr/share/bison.simple"=' <$< >$@.tmp
	mv $@.tmp $@
LEX = flex
LFLAGS += -f -s -i -8 -v
CFLAGS += -Wall -g
HSRC := buffer.h html-check-links.h getmem.h grammar.h
CSRC := html-check-links.c getmem.c
LSRC := lex.l
YSRC := grammar.y
SRC :=  $(YSRC) $(CSRC) $(LSRC) $(HSRC)
CFILES := $(CSRC) $(LSRC:.l=.c) $(YSRC:.y=.fixed.c)
YFLAGS += -d
ifeq ($(YACC),bison)
YFLAGS += --verbose
endif

# we don't include @LIBS@ here because including -llapack would make it also
# necessary to link with the fortran support libraries:
LOADLIBES += -lgc
# we should have added this only after checking for its presence/necessity in configure.ac:
# LOADLIBES += -ldl

ifeq (@DEBUG@,yes)
CPPFLAGS += -DYYDEBUG
endif
ifdef FULLDEBUG
LDFLAGS := -g
CPPFLAGS += -DDEBUG
LFLAGS += -d
YFLAGS += --debug
endif
ifneq (@ETAGS@,false)
all: TAGS
endif
all: html-check-links

getmem.o: html-check-links.h  getmem.h
grammar.fixed.o:  html-check-links.h  buffer.h  getmem.h grammar.h
html-check-links.o: html-check-links.h  grammar.h  getmem.h
lex.o: getmem.h grammar.h grammar.tab.h

html-check-links : $(CFILES:.c=.o)

TAGS: $(SRC); @ETAGS@ $^
lex.o : grammar.fixed.c

CHKARGS = --no-absolute-links
DIR = $(shell pwd)
NEW = @pre_htmldir@
all check : html-check-links run-html-check-links
run-html-check-links: html-check-links
ifneq (,$(findstring w,$(word 1,$(MAKEFLAGS))))
	@echo "make: Entering directory \`$(NEW)'"
endif
	cd $(NEW) && @FIND@ . -name \*.html -o -name \*.xhtml -exec ls -rt {} + | LD_LIBRARY_PATH="$(BUILTLIBPATH)/lib:$$LD_LIBRARY_PATH" xargs "$(DIR)"/html-check-links $(CHKARGS)
ifneq (,$(findstring w,$(word 1,$(MAKEFLAGS))))
	@echo "make: Leaving directory \`$(NEW)'"
endif

Makefile : Makefile.in
	cd ../..; ./config.status Macaulay2/html-check-links/Makefile
clean:; rm -f	*.o html-check-links *.dep y.tab.h lex.yy.c TAGS y.output \
		core grammar.c grammar.tab.* lex.c grammar.fixed.* grammar.output
distclean : clean
	rm -f Makefile

# Local Variables:
# compile-command: "make -C $M2BUILDDIR/Macaulay2/html-check-links run-html-check-links"
# End:
.NOTPARALLEL:
