##
##              Camlp4 quotations in original syntax
##
##                Copyright (C) 2005  Hendrik Tews
##
##  This library is free software; you can redistribute it and/or
##  modify it under the terms of the GNU Library General Public
##  License as published by the Free Software Foundation; either
##  version 2 of the License, or (at your option) any later version.
##
##  This library 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
##  Library General Public License in the file LICENCE in this or one
##  of the parent directories for more details.
##
##  Time-stamp: <Tuesday 14 June 05 0:08:56 tews@debian>
##
##  $Id: Makefile.in,v 1.14 2005/10/06 20:41:22 tews Exp $
##


OCAMLC=ocamlc
OCAMLSRC=OCAMLSRC
CAMLP4LIBDIR=/usr/local/lib/ocaml/camlp4
BINDIR=/usr/local/bin
CHECKGOAL=


world: paqo_o.cmo pp_qo.cma pp_q.cma $(CHECKGOAL)

normal: parse_test_input_qo parse_test_input_q

revised: parse_test_input_q parse_test_input_qo

qo_MLast.cmo: qo_MLast.ml 
	$(OCAMLC) -c -pp "camlp4r pa_extend.cmo pa_extend_m.cmo q_MLast.cmo" \
		-I +camlp4 $<

pp_util.cmo: pp_util.ml
	$(OCAMLC) -I +camlp4 -c pp_util.ml

pp_util.cmi: pp_util.cmo

pp_qo.cmo: pp_qo.ml qo_MLast.cmo pp_util.cmi pp_qo.cmi
	$(OCAMLC) -pp 'camlp4o -I . qo_MLast.cmo -verbose' -c -I +camlp4 $<

pp_qo.cmi: pp_qo.mli pp_util.cmi
	$(OCAMLC) -I +camlp4 $<

p4pp_qo.cmo: p4pp_qo.ml pp_util.cmi pp_qo.cmi 
	$(OCAMLC) -c -I +camlp4 $<

pp_qo.cma: pp_util.cmo pp_qo.cmo p4pp_qo.cmo
	$(OCAMLC) -a -o $@ $^

pp_q.cmo: pp_q.ml pp_util.cmi pp_q.cmi
	$(OCAMLC) -pp 'camlp4o q_MLast.cmo -verbose' -c -I +camlp4 $<

pp_q.cmi: pp_q.mli pp_util.cmi
	$(OCAMLC) -I +camlp4 $<

p4pp_q.cmo: p4pp_q.ml pp_util.cmi pp_q.cmi
	$(OCAMLC) -c -I +camlp4 $<

pp_q.cma: pp_util.cmo pp_q.cmo p4pp_q.cmo
	$(OCAMLC) -a -o $@ $^

# test_q.cmo: test_q.ml
# 	$(OCAMLC) -pp 'camlp4o q_MLast.cmo -verbose' -c -I +camlp4 $<

paqo_o.cmo: paqo_o.ml qo_MLast.cmo 
	$(OCAMLC) -c -pp 'camlp4o pa_extend.cmo ./qo_MLast.cmo' -I +camlp4 $<

check_config.cmo: check_config.ml
	$(OCAMLC) -c $<

qocheck: qocheck.ml check_config.cmo paqo_o.cmo pp_util.cmo pp_qo.cmo pp_q.cmo \
		$(OCAMLSRC)/camlp4/lib/token.cmo \
		$(OCAMLSRC)/camlp4/lib/extfun.cmo \
		$(OCAMLSRC)/camlp4/lib/stdpp.cmo \
		$(OCAMLSRC)/camlp4/lib/gramext.cmo \
		$(OCAMLSRC)/camlp4/lib/grammar.cmo \
		$(OCAMLSRC)/camlp4/lib/plexer.cmo \
		$(OCAMLSRC)/camlp4/camlp4/spretty.cmo \
		$(OCAMLSRC)/camlp4/camlp4/quotation.cmo \
		$(OCAMLSRC)/camlp4/camlp4/reloc.cmo \
		$(OCAMLSRC)/camlp4/camlp4/pcaml.cmo
	$(OCAMLC) -o qocheck -I +camlp4 dynlink.cma unix.cma \
		${OCAMLSRC}/camlp4/lib/{token,extfun,stdpp,gramext,grammar,plexer}.cmo \
		${OCAMLSRC}/camlp4/camlp4/{spretty,quotation,reloc,pcaml}.cmo \
		pp_util.cmo pp_qo.cmo pp_q.cmo check_config.cmo $<


clean:
	rm -f qocheck
	rm -f *.{cmo,cmi,cma}

install: qo_MLast.cmo
	cp $^ $(CAMLP4LIBDIR)

install-pp: pp_qo.cma pp_q.cma
	cp $^ $(CAMLP4LIBDIR)

install-qocheck: qocheck
	cp $^ $(BINDIR)


.PHONY: parse_test_input_q parse_test_input_qo docheck clean 
.PHONY: diff diff-src generation test clean install
.PHONY: parse_test_input_qo2


parse_test_input_qo: test_input.ml test_rinput.ml pp_qo.cma 
	@echo "######################### NORMAL ##########################"
	camlp4o -I . pp_qo.cma -test test_input.ml | tee qo_out
	@echo "######################### NORMAL revised input ############"
	camlp4r -I . pp_qo.cma -test test_rinput.ml | tee qor_out

parse_test_input_qo2: a.ml pp_qo.cma
	camlp4o -I . pp_qo.cma -test a.ml

parse_test_input_q: test_input.ml test_rinput.ml pp_q.cma
	@echo "######################### REVISED #########################"
	camlp4o -I . pp_q.cma -test test_input.ml | tee q_out
	@echo "######################### REVISED revised input ###########"
	camlp4r -I . pp_q.cma -test test_rinput.ml | tee qr_out

parse_test_input_q2: a.ml pp_q.cma
	camlp4o -I . pp_q.cma -test a.ml

generation:
	cp q_out save_q_out
	cp qo_out save_qo_out
	cp qor_out save_qor_out
	cp qr_out save_qr_out

diff:
	@echo "##################### diff qo_out ##########################"
	diff -u  save_qo_out qo_out; true
	@echo "##################### diff q_out ##########################"
	diff -u  save_q_out q_out; true
	@echo "##################### diff qor_out ##########################"
	diff -u  save_qor_out qor_out; true
	@echo "##################### diff qr_out ##########################"
	diff -u  save_qr_out qr_out; true


diff-src:
	@echo "##################### diff mypa_o ##########################"
	diff -u  Orig/mypa_o.ml $(OCAMLSRC)/camlp4/etc/pa_o.ml; true
	@echo "##################### diff mypa_r ##########################"
	diff -u  Orig/mypa_r.ml $(OCAMLSRC)/camlp4/meta/pa_r.ml; true
	@echo "##################### diff myq_MLast #######################"
	diff -u  Orig/myq_MLast.ml $(OCAMLSRC)/camlp4/meta/q_MLast.ml; true
	@echo "##################### diff mypa_extend #####################"
	diff -u  Orig/mypa_extend.ml $(OCAMLSRC)/camlp4/meta/pa_extend.ml; true
	@echo "##################### diff mypa_extend_m ###################"
	diff -u  Orig/mypa_extend_m.ml $(OCAMLSRC)/camlp4/meta/pa_extend_m.ml; true


docheck: qocheck
	./qocheck -I . test_input.ml


# see also checkerrors in make-snapshot
CHECKERRORS=0 1 2 3 10 11 12 20 21 22 23 24 25 26 \
		120 121 122 123 124 125 126 200 201 202 203

STATUS=test/status
FILES=test/mlfiles

test: $(FILES) qocheck
	for f in $$(cat $(FILES)) ; do \
		./qocheck -I . -nopp -nodumpast -nodumpdiffs $$f; \
		echo -n "$$? "; echo $$f; \
	done \
		| tee $(STATUS)
	for c in $(CHECKERRORS) ; do \
		echo =============== grep $$c ====================; \
		grep "^$$c " $(STATUS) | tee $(STATUS).$$c; \
		true; \
	done
	wc -l $(STATUS).{0,1,2,3,10,11,12,20,21,22,23,24,25,26,120,121,122,123,124,125,126,200,201,202,203} | grep -v "  0 "

fulltest: test/allmlfiles
	$(MAKE) FILES=test/allmlfiles STATUS=test/fullstatus test


disttest: test/mlfiles-distribution
	$(MAKE) FILES=test/mlfiles-distribution \
		STATUS=test/status-distribution test



# wc -l test/fullstatus.{0,1,2,3,10,11,12,20,21,22,23,24,25,26,120,121,122,123,124,125,126,200,201,202,203}


.PHONY: savestatus savefullstatus

savestatus:
	mkdir -p test/old
	for f in ${STATUS}* ; do \
		cp $$f $$(dirname $$f)/old/$$(basename $$f); \
	done

savefullstatus:
	$(MAKE) FILES=test/allmlfiles STATUS=test/fullstatus savestatus


# grep -c module $(awk '{print $2;}' fullstatus.11) | awk -F : '{print $2, $1;}'



### Local Variables: ***
### time-stamp-line-limit: 30 ***
### End: ***
