# h1 makefile template.
#   Copyright (C) 2003-2005 Jean Goubault-Larrecq and LSV, CNRS UMR 8643 & ENS Cachan.
#
#   This file is part of h1.
#
#   h1 is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2, or (at your option)
#   any later version.
#
#   h1 is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with h1; see the file COPYING.  If not, write to
#   the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

# do:
# make install exec_prefix=/usr/local
# to install in /usr/local.  You must supply exec_prefix, otherwise it won't install.

GIMML = /usr/local/bin/gimml
GIMMLDEP = /usr/local/bin/gimmldep
GIMMLLNK = /usr/local/bin/gimmllnk
GYACC = /usr/local/bin/gyacc
GLEX = /usr/local/bin/glex

CC = gcc
CFLAGS = -ggdb -O3 -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DHAVE_LIBZ=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_UNISTD_H=1 -DHAVE_STRSTR=1 
# -pg -fschedule-insns2
LFLAGS = -ggdb -O3 -lz 
# -pg
YACC = /usr/bin/bison
LEX = /usr/bin/flex

BINDIR = ${exec_prefix}/bin

.PHONY: all clean depend

%.mlx : %.ml
	$(GIMML) -c $<

OBJS = queue.mlx heap.mlx gensym.mlx rel.mlx sort.mlx verbose.mlx fixbool.mlx scc.mlx topsort.mlx \
	auto.mlx term.mlx \
	intersym_lex.mlx exactsym_lex.mlx intersym.mlx \
	clause.mlx gclause.mlx monadic.mlx \
	seidl.mlx print_seidl.mlx \
	cc.mlx model.mlx tptp_tab.mlx tptp_lex.mlx
PL2TPTPOBJS = gensym.mlx term.mlx gclause.mlx pl_tab.mlx pl_lex.mlx yyerror.mlx pl2tptp.mlx
XMLAUTOOBJS = gensym.mlx sort.mlx term.mlx gclause.mlx \
	intersym_lex.mlx exactsym_lex.mlx intersym.mlx \
	rel.mlx yyerror.mlx \
	xmlauto_tab.mlx xmlauto_lex.mlx xmlauto.mlx
PLDETOBJS = gensym.mlx sort.mlx fixbool.mlx auto.mlx verbose.mlx \
	intersym_lex.mlx exactsym_lex.mlx intersym.mlx \
	determinize.mlx term.mlx yyerror.mlx \
	plauto_tab.mlx plauto_lex.mlx pldet.mlx
MORPHOBJS = gensym.mlx term.mlx gclause.mlx yyerror.mlx morph_tab.mlx morph_lex.mlx \
	morphrewrite.mlx tptp_tab.mlx tptp_lex.mlx morph.mlx
LINEAROBJS = gensym.mlx sort.mlx rel.mlx linear_tab.mlx linear_lex.mlx lin.mlx \
	yyerror.mlx linmain.mlx
AUTODOTOBJS = gensym.mlx sort.mlx rel.mlx yyerror.mlx \
	xmlauto_tab.mlx xmlauto_lex.mlx autodot.mlx
PL2GASTEXOBJS = gensym.mlx sort.mlx fixbool.mlx auto.mlx yyerror.mlx \
	intersym_lex.mlx exactsym_lex.mlx intersym.mlx \
	plauto_tab.mlx plauto_lex.mlx pl2gastex.mlx
H1OBJS = yyerror.mlx clauses.mla plauto_tab.mlx plauto_lex.mlx main.mlx
H1TRACEOBJS = rel.mlx sort.mlx topsort.mlx term.mlx yyerror.mlx gclause.mlx \
	ne.mlx gensym.mlx coq_kw.mlx coq_fun.mlx coq_term.mlx coq_gclause.mlx \
	proof_tab.mlx proof_lex.mlx \
	intersym_lex.mlx exactsym_lex.mlx intersym.mlx \
	natded.mlx pfcprint.mlx pfcprinttree.mlx pfcprinttreeabbrv.mlx pfcprintcoq.mlx \
	h1trace.mlx
H1LOGSTRIPOBJS = cproof.tab.o cproof.lex.o
H1MCOBJS = yyerror.mlx plauto_tab.mlx plauto_lex.mlx proof_tab.mlx proof_lex.mlx \
	rel.mlx sort.mlx gensym.mlx topsort.mlx \
	verbose.mlx term.mlx fixbool.mlx gclause.mlx \
	ne.mlx intersym_lex.mlx exactsym_lex.mlx intersym.mlx \
	natded.mlx monadic.mlx \
	auto.mlx cc.mlx model.mlx scc.mlx \
	coq_kw.mlx coq_fun.mlx coq_term.mlx coq_gclause.mlx coq_auto.mlx coq_model.mlx \
	pfcprinttree.mlx pfcprintcoq.mlx tptp_tab.mlx tptp_lex.mlx \
	h1mc.mlx
PLPURGE = term.mlx gclause.mlx pl_tab.mlx pl_lex.mlx rel.mlx yyerror.mlx plpurge.mlx
TPTP2DFG = term.mlx gclause.mlx yyerror.mlx tptp_tab.mlx tptp_lex.mlx tptp2dfg.mlx
HIFI = term.mlx fixbool.mlx gclause.mlx yyerror.mlx tptp_tab.mlx tptp_lex.mlx auto.mlx rel.mlx verbose.mlx gensym.mlx cc.mlx rel.mlx h1ficc.mlx h1fi.mlx
ALLOBJS = $(OBJS) $(PL2TPTPOBJS) $(XMLAUTOOBJS) $(PLDETOBJS) $(MORPHOBJS) $(LINEAROBJS) \
	$(AUTODOTOBJS) $(H1OBJS) $(H1TRACEOBJS) $(H1MCOBJS) $(H1LOGSTRIPOBJS) $(PL2GASTEXOBJS) \
	$(TPTP2DFG) $(HIFI)
ALL = h1 pl2tptp auto2pl pldet tptpmorph linauto autodot h1trace h1logstrip h1mc \
	h1mon pl2gastex plpurge tptp2dfg h1fi

all: $(ALL)

install: $(ALL)
	install $(ALL) h1getlog $(BINDIR)

count:
	@wc `sh filelist $(ALLOBJS)`

counth1:
	@wc `sh filelist $(OBJS) $(H1OBJS)`

h1: $(H1OBJS)
	$(GIMMLLNK) $@ $(H1OBJS)

pl2tptp: $(PL2TPTPOBJS)
	$(GIMMLLNK) $@ $(PL2TPTPOBJS)

auto2pl: $(XMLAUTOOBJS)
	$(GIMMLLNK) $@ $(XMLAUTOOBJS)

pldet: $(PLDETOBJS)
	$(GIMMLLNK) $@ $(PLDETOBJS)

tptpmorph: $(MORPHOBJS)
	$(GIMMLLNK) $@ $(MORPHOBJS)

linauto: $(LINEAROBJS)
	$(GIMMLLNK) $@ $(LINEAROBJS)

autodot: $(AUTODOTOBJS)
	$(GIMMLLNK) $@ $(AUTODOTOBJS)

pl2gastex: $(PL2GASTEXOBJS)
	$(GIMMLLNK) $@ $(PL2GASTEXOBJS)

plpurge: $(PLPURGE)
	$(GIMMLLNK) $@ $(PLPURGE)

tptp2dfg: $(TPTP2DFG)
	$(GIMMLLNK) $@ $(TPTP2DFG)

h1fi : $(HIFI)
	$(GIMMLLNK) $@ $(HIFI)

h1trace: $(H1TRACEOBJS)
	$(GIMMLLNK) $@ $(H1TRACEOBJS)

h1logstrip : $(H1LOGSTRIPOBJS)
	$(CC) $(LFLAGS) -o $@ $(H1LOGSTRIPOBJS)

h1mc: $(H1MCOBJS)
	$(GIMMLLNK) $@ $(H1MCOBJS)

h1mon: monitor.c
	$(CC) $< -o $@

clauses.mla: $(OBJS)
	$(GIMMLLNK) -a $@ $(OBJS)

monitor.mlx: monitor.ml
	$(GIMML) -c $<
	chmod +x monitor.mlx

tptp_tab.ml tptp_tab_h.ml : tptp.y
	$(GYACC) --debug -p tptp $<

tptp_lex.ml : tptp.l
	$(GLEX) -s -Ptptp -otptp_lex.ml $<

intersym_lex.ml : intersym.l
	$(GLEX) -s -Pintersym -ointersym_lex.ml $<

exactsym_lex.ml : exactsym.l
	$(GLEX) -s -Pexactsym -oexactsym_lex.ml $<

pl_tab.ml pl_tab_h.ml : pl.y
	$(GYACC) --debug -p pl $<

pl_lex.ml : pl.l
	$(GLEX) -s -Ppl -opl_lex.ml $<

xmlauto_tab.ml xmlauto_tab_h.ml : xmlauto.y
	$(GYACC) --debug -p xmlauto $<

xmlauto_lex.ml : xmlauto.l
	$(GLEX) -s -Pxmlauto -oxmlauto_lex.ml $<

plauto_tab.ml plauto_tab_h.ml : plauto.y
	$(GYACC) --debug -p plauto $<

plauto_lex.ml : plauto.l
	$(GLEX) -s -Pplauto -oplauto_lex.ml $<

morph_tab.ml morph_tab_h.ml : morph.y
	$(GYACC) --debug -p morph $<

morph_lex.ml : morph.l
	$(GLEX) -s -Pmorph -omorph_lex.ml $<

linear_tab.ml linear_tab_h.ml : linear.y
	$(GYACC) --debug -p linear $<

linear_lex.ml : linear.l
	$(GLEX) -s -Plinear -olinear_lex.ml $<

proof_tab.ml proof_tab_h.ml : proof.y
	$(GYACC) --debug -p proof $<

proof_lex.ml : proof.l
	$(GLEX) -s -Pproof -oproof_lex.ml $<

cproof.tab.c cproof.tab.h : cproof.y
	$(YACC) -dv $<

cproof.lex.c : cproof.l
	$(LEX) -CFa -s -8 -ocproof.lex.c cproof.l

chash.lex.c : chash.l
	$(LEX) -CFa -s -8 -ochash.lex.c chash.l

clean:
	-rm *.mlx *.o
	-rm *_tab*.ml
	-rm *_lex*.ml
	-rm $(ALL)
	-rm dep.ps
	-rm clauses.mla gc.out abc.v
	-rm *.model.pl *.model.xml *.log *.mc *.tree
	-rm Fabrice/*.model.pl Fabrice/*.model.xml Fabrice/*.log Fabrice/*.mc Fabrice/*.tree
	-rm h1.pgr

cleanall : clean
	-rm *~

dep.ps: depend
	ocamldot .depend | dot -Tps >dep.ps

depend:
	$(GIMMLDEP) *.ml >.depend
	$(CC) -MM *.c >>.depend

include .depend
