#############################################################################
##  v      #                   The Coq Proof Assistant                     ##
## <O___,, #                INRIA - CNRS - LIX - LRI - PPS                 ##
##   \VV/  #                                                               ##
##    //   #  Makefile automagically generated by coq_makefile V8.5pl1     ##
#############################################################################

# WARNING
#
# This Makefile has been automagically generated
# Edit at your own risks !
#
# END OF WARNING

#
# This Makefile was generated by the command line :
# coq_makefile -f _CoqProject -o Makefile 
#

.DEFAULT_GOAL := all

# This Makefile may take arguments passed as environment variables:
# COQBIN to specify the directory where Coq binaries resides;
# TIMECMD set a command to log .v compilation time;
# TIMED if non empty, use the default time command as TIMECMD;
# ZDEBUG/COQDEBUG to specify debug flags for ocamlc&ocamlopt/coqc;
# DSTROOT to specify a prefix to install path.

# Here is a hack to make $(eval $(shell works:
define donewline


endef
includecmdwithout@ = $(eval $(subst @,$(donewline),$(shell { $(1) | tr -d '\r' | tr '\n' '@'; })))
$(call includecmdwithout@,$(COQBIN)coqtop -config)

TIMED=
TIMECMD=
STDTIME?=/usr/bin/time -f "$* (user: %U mem: %M ko)"
TIMER=$(if $(TIMED), $(STDTIME), $(TIMECMD))

vo_to_obj = $(addsuffix .o,\
  $(filter-out Warning: Error:,\
  $(shell $(COQBIN)coqtop -q -noinit -batch -quiet -print-mod-uid $(1))))

##########################
#                        #
# Libraries definitions. #
#                        #
##########################

COQLIBS?=\
  -R "." coqart86
COQDOCLIBS?=\
  -R "." coqart86

##########################
#                        #
# Variables definitions. #
#                        #
##########################

COQDOCFLAGS=-interpolate -utf8 --latex --html

OPT?=
COQDEP?="$(COQBIN)coqdep" -c
COQFLAGS?=-q $(OPT) $(COQLIBS) $(OTHERFLAGS) $(COQ_XML)
COQCHKFLAGS?=-silent -o
COQDOCFLAGS?=-interpolate -utf8
COQC?=$(TIMER) "$(COQBIN)coqc"
GALLINA?="$(COQBIN)gallina"
COQDOC?="$(COQBIN)coqdoc"
COQCHK?="$(COQBIN)coqchk"
COQMKTOP?="$(COQBIN)coqmktop"

##################
#                #
# Install Paths. #
#                #
##################

ifdef USERINSTALL
XDG_DATA_HOME?="$(HOME)/.local/share"
COQLIBINSTALL=$(XDG_DATA_HOME)/coq
COQDOCINSTALL=$(XDG_DATA_HOME)/doc/coq
else
COQLIBINSTALL="${COQLIB}user-contrib"
COQDOCINSTALL="${DOCDIR}user-contrib"
COQTOPINSTALL="${COQLIB}toploop"
endif

######################
#                    #
# Files dispatching. #
#                    #
######################

VFILES:=tutorial_type_classes/SRC/Power_mono.v\
  tutorial_type_classes/SRC/Mat.v\
  tutorial_type_classes/SRC/EMonoid.v\
  tutorial_type_classes/SRC/Trace_Monoid.v\
  tutorial_type_classes/SRC/Monoid_op_classes.v\
  tutorial_type_classes/SRC/Lost_in_NY.v\
  tutorial_type_classes/SRC/Monoid_prog.v\
  tutorial_type_classes/SRC/Monoid.v\
  ch13_co_inductive_types/SRC/LMap.v\
  ch13_co_inductive_types/SRC/finite_or_infinite.v\
  ch13_co_inductive_types/SRC/Llist_to_list.v\
  ch13_co_inductive_types/SRC/DamienPous_alt.v\
  ch13_co_inductive_types/SRC/bug_infinite.v\
  ch13_co_inductive_types/SRC/graft_absorb.v\
  ch13_co_inductive_types/SRC/building.v\
  ch13_co_inductive_types/SRC/LTree_bisimilar.v\
  ch13_co_inductive_types/SRC/Tree_Inf.v\
  ch13_co_inductive_types/SRC/Ltree.v\
  ch13_co_inductive_types/SRC/infinite_impred.v\
  ch13_co_inductive_types/SRC/infinite_impred_prelude.v\
  ch13_co_inductive_types/SRC/chap13.v\
  ch13_co_inductive_types/SRC/list_inject.v\
  ch13_co_inductive_types/SRC/graft.v\
  ch13_co_inductive_types/SRC/finiteness_needed.v\
  ch14_fundations_of_inductive_types/SRC/plus_with_natrec.v\
  ch14_fundations_of_inductive_types/SRC/list_ltree_ind2.v\
  ch14_fundations_of_inductive_types/SRC/update_eq.v\
  ch14_fundations_of_inductive_types/SRC/triangular.v\
  ch14_fundations_of_inductive_types/SRC/triangular_dep.v\
  ch14_fundations_of_inductive_types/SRC/factor.v\
  ch14_fundations_of_inductive_types/SRC/ltree_to_ntree.v\
  ch14_fundations_of_inductive_types/SRC/use_le_ind_max.v\
  ch14_fundations_of_inductive_types/SRC/ltree_count.v\
  ch14_fundations_of_inductive_types/SRC/chap14.v\
  ch2_types_expressions/SRC/Zbtree.v\
  ch2_types_expressions/SRC/bin_nums.v\
  ch2_types_expressions/SRC/btree.v\
  ch2_types_expressions/SRC/sol1.v\
  ch2_types_expressions/SRC/ex1.v\
  ch8_inductive_predicates/SRC/le_prime.v\
  ch8_inductive_predicates/SRC/Hoare_sequence.v\
  ch8_inductive_predicates/SRC/JM_assoc.v\
  ch8_inductive_predicates/SRC/parsing.v\
  ch8_inductive_predicates/SRC/lt_le.v\
  ch8_inductive_predicates/SRC/weird_induc2.v\
  ch8_inductive_predicates/SRC/chap8.v\
  ch8_inductive_predicates/SRC/even.v\
  ch8_inductive_predicates/SRC/perms2.v\
  ch8_inductive_predicates/SRC/le_diff.v\
  ch8_inductive_predicates/SRC/last.v\
  ch8_inductive_predicates/SRC/infinite_loop.v\
  ch8_inductive_predicates/SRC/Hoare_while_rule_bis.v\
  ch8_inductive_predicates/SRC/perms.v\
  ch8_inductive_predicates/SRC/JMeqSolution.v\
  ch8_inductive_predicates/SRC/id_solution.v\
  ch8_inductive_predicates/SRC/magaud.v\
  ch8_inductive_predicates/SRC/frobenius.v\
  ch8_inductive_predicates/SRC/le_impred.v\
  ch8_inductive_predicates/SRC/impredicative.v\
  ch8_inductive_predicates/SRC/palindrome.v\
  ch8_inductive_predicates/SRC/non_inductive_sorted.v\
  ch8_inductive_predicates/SRC/weird_induc.v\
  new_exercises/SRC/Partial.v\
  new_exercises/SRC/notwf.v\
  new_exercises/SRC/G4.v\
  new_exercises/SRC/permutation.v\
  new_exercises/SRC/buildingZ.v\
  new_exercises/SRC/union_not_wf.v\
  new_exercises/SRC/Upairs.v\
  new_exercises/SRC/evenproof.v\
  new_exercises/SRC/mergesort.v\
  ch10_extraction_and_imperative_programs/SRC/chap10.v\
  ch4_dependent_product/SRC/all_perm.v\
  ch4_dependent_product/SRC/thrice.v\
  ch4_dependent_product/SRC/polyminimal.v\
  ch4_dependent_product/SRC/chap4.v\
  ch4_dependent_product/SRC/polymorph.v\
  ch3_propositions_proofs/SRC/cut_example.v\
  ch3_propositions_proofs/SRC/simple_proofs.v\
  ch3_propositions_proofs/SRC/chap3.v\
  ch7_tactics_automation/SRC/le_lt_S_eq.v\
  ch7_tactics_automation/SRC/chap7.v\
  ch7_tactics_automation/SRC/primes_hyps.v\
  ch7_tactics_automation/SRC/Zpos_x_tac.v\
  ch9_function_specification/SRC/fib_positive.v\
  ch9_function_specification/SRC/div2tofib_ind.v\
  ch9_function_specification/SRC/compare_spec.v\
  ch9_function_specification/SRC/even_odd.v\
  ch9_function_specification/SRC/moreperms.v\
  ch9_function_specification/SRC/extract.v\
  ch9_function_specification/SRC/plusss.v\
  ch9_function_specification/SRC/exo_eqdec.v\
  ch9_function_specification/SRC/fib_tail.v\
  ch9_function_specification/SRC/chap9.v\
  ch9_function_specification/SRC/plus_prim.v\
  ch9_function_specification/SRC/mod2.v\
  ch9_function_specification/SRC/fib_intro.v\
  ch9_function_specification/SRC/div2_mod2.v\
  ch9_function_specification/SRC/div3.v\
  ch9_function_specification/SRC/sqrt.v\
  ch9_function_specification/SRC/fib_ind.v\
  ch1_overview/SRC/chap1.v\
  tutorial_inductive_co_inductive_types/SRC/RecTutorial.v\
  ch16_proof_by_reflection/SRC/chap16.v\
  ch16_proof_by_reflection/SRC/neutral.v\
  ch16_proof_by_reflection/SRC/verif_divide.v\
  ch16_proof_by_reflection/SRC/prime_sqrt.v

ifneq ($(filter-out archclean clean cleanall printenv,$(MAKECMDGOALS)),)
-include $(addsuffix .d,$(VFILES))
else
ifeq ($(MAKECMDGOALS),)
-include $(addsuffix .d,$(VFILES))
endif
endif

.SECONDARY: $(addsuffix .d,$(VFILES))

VO=vo
VOFILES:=$(VFILES:.v=.$(VO))
GLOBFILES:=$(VFILES:.v=.glob)
GFILES:=$(VFILES:.v=.g)
HTMLFILES:=$(VFILES:.v=.html)
GHTMLFILES:=$(VFILES:.v=.g.html)
OBJFILES=$(call vo_to_obj,$(VOFILES))
ALLNATIVEFILES=$(OBJFILES:.o=.cmi) $(OBJFILES:.o=.cmo) $(OBJFILES:.o=.cmx) $(OBJFILES:.o=.cmxs)
NATIVEFILES=$(foreach f, $(ALLNATIVEFILES), $(wildcard $f))
ifeq '$(HASNATDYNLINK)' 'true'
HASNATDYNLINK_OR_EMPTY := yes
else
HASNATDYNLINK_OR_EMPTY :=
endif

#######################################
#                                     #
# Definition of the toplevel targets. #
#                                     #
#######################################

all: $(VOFILES) 

quick: $(VOFILES:.vo=.vio)

vio2vo:
	$(COQC) $(COQDEBUG) $(COQFLAGS) -schedule-vio2vo $(J) $(VOFILES:%.vo=%.vio)
checkproofs:
	$(COQC) $(COQDEBUG) $(COQFLAGS) -schedule-vio-checking $(J) $(VOFILES:%.vo=%.vio)
gallina: $(GFILES)

html: $(GLOBFILES) $(VFILES)
	- mkdir -p html
	$(COQDOC) -toc $(COQDOCFLAGS) -html $(COQDOCLIBS) -d html $(VFILES)

gallinahtml: $(GLOBFILES) $(VFILES)
	- mkdir -p html
	$(COQDOC) -toc $(COQDOCFLAGS) -html -g $(COQDOCLIBS) -d html $(VFILES)

all.ps: $(VFILES)
	$(COQDOC) -toc $(COQDOCFLAGS) -ps $(COQDOCLIBS) -o $@ `$(COQDEP) -sort -suffix .v $^`

all-gal.ps: $(VFILES)
	$(COQDOC) -toc $(COQDOCFLAGS) -ps -g $(COQDOCLIBS) -o $@ `$(COQDEP) -sort -suffix .v $^`

all.pdf: $(VFILES)
	$(COQDOC) -toc $(COQDOCFLAGS) -pdf $(COQDOCLIBS) -o $@ `$(COQDEP) -sort -suffix .v $^`

all-gal.pdf: $(VFILES)
	$(COQDOC) -toc $(COQDOCFLAGS) -pdf -g $(COQDOCLIBS) -o $@ `$(COQDEP) -sort -suffix .v $^`

validate: $(VOFILES)
	$(COQCHK) $(COQCHKFLAGS) $(COQLIBS) $(notdir $(^:.vo=))

beautify: $(VFILES:=.beautified)
	for file in $^; do mv $${file%.beautified} $${file%beautified}old && mv $${file} $${file%.beautified}; done
	@echo 'Do not do "make clean" until you are sure that everything went well!'
	@echo 'If there were a problem, execute "for file in $$(find . -name \*.v.old -print); do mv $${file} $${file%.old}; done" in your shell/'

.PHONY: all archclean beautify byte clean cleanall gallina gallinahtml html install install-doc install-natdynlink install-toploop opt printenv quick uninstall userinstall validate vio2vo

####################
#                  #
# Special targets. #
#                  #
####################

byte:
	$(MAKE) all "OPT:=-byte"

opt:
	$(MAKE) all "OPT:=-opt"

userinstall:
	+$(MAKE) USERINSTALL=true install

install:
	cd "." && for i in $(VOFILES) $(VFILES) $(GLOBFILES) $(NATIVEFILES) $(CMOFILES) $(CMIFILES) $(CMAFILES); do \
	 install -d "`dirname "$(DSTROOT)"$(COQLIBINSTALL)/coqart86/$$i`"; \
	 install -m 0644 $$i "$(DSTROOT)"$(COQLIBINSTALL)/coqart86/$$i; \
	done

install-doc:
	install -d "$(DSTROOT)"$(COQDOCINSTALL)/coqart86/html
	for i in html/*; do \
	 install -m 0644 $$i "$(DSTROOT)"$(COQDOCINSTALL)/coqart86/$$i;\
	done

uninstall_me.sh: Makefile
	echo '#!/bin/sh' > $@
	printf 'cd "$${DSTROOT}"$(COQLIBINSTALL)/coqart86 && rm -f $(VOFILES) $(VFILES) $(GLOBFILES) $(NATIVEFILES) $(CMOFILES) $(CMIFILES) $(CMAFILES) && find . -type d -and -empty -delete\ncd "$${DSTROOT}"$(COQLIBINSTALL) && find "coqart86" -maxdepth 0 -and -empty -exec rmdir -p \{\} \;\n' >> "$@"
	printf 'cd "$${DSTROOT}"$(COQDOCINSTALL)/coqart86 \\\n' >> "$@"
	printf '&& rm -f $(shell find "html" -maxdepth 1 -and -type f -print)\n' >> "$@"
	printf 'cd "$${DSTROOT}"$(COQDOCINSTALL) && find coqart86/html -maxdepth 0 -and -empty -exec rmdir -p \{\} \;\n' >> "$@"
	chmod +x $@

uninstall: uninstall_me.sh
	sh $<

.merlin:
	@echo 'FLG -rectypes' > .merlin
	@echo "B $(COQLIB) kernel" >> .merlin
	@echo "B $(COQLIB) lib" >> .merlin
	@echo "B $(COQLIB) library" >> .merlin
	@echo "B $(COQLIB) parsing" >> .merlin
	@echo "B $(COQLIB) pretyping" >> .merlin
	@echo "B $(COQLIB) interp" >> .merlin
	@echo "B $(COQLIB) printing" >> .merlin
	@echo "B $(COQLIB) intf" >> .merlin
	@echo "B $(COQLIB) proofs" >> .merlin
	@echo "B $(COQLIB) tactics" >> .merlin
	@echo "B $(COQLIB) tools" >> .merlin
	@echo "B $(COQLIB) toplevel" >> .merlin
	@echo "B $(COQLIB) stm" >> .merlin
	@echo "B $(COQLIB) grammar" >> .merlin
	@echo "B $(COQLIB) config" >> .merlin

clean::
	rm -f $(OBJFILES) $(OBJFILES:.o=.native) $(NATIVEFILES)
	find . -name .coq-native -type d -empty -delete
	rm -f $(VOFILES) $(VOFILES:.vo=.vio) $(GFILES) $(VFILES:.v=.v.d) $(VFILES:=.beautified) $(VFILES:=.old)
	rm -f all.ps all-gal.ps all.pdf all-gal.pdf all.glob $(VFILES:.v=.glob) $(VFILES:.v=.tex) $(VFILES:.v=.g.tex) all-mli.tex
	- rm -rf html mlihtml uninstall_me.sh

cleanall:: clean
	rm -f $(patsubst %.v,.%.aux,$(VFILES))

archclean::
	rm -f *.cmx *.o

printenv:
	@"$(COQBIN)coqtop" -config
	@echo 'CAMLC =	$(CAMLC)'
	@echo 'CAMLOPTC =	$(CAMLOPTC)'
	@echo 'PP =	$(PP)'
	@echo 'COQFLAGS =	$(COQFLAGS)'
	@echo 'COQLIBINSTALL =	$(COQLIBINSTALL)'
	@echo 'COQDOCINSTALL =	$(COQDOCINSTALL)'

Makefile: _CoqProject
	mv -f $@ $@.bak
	"$(COQBIN)coq_makefile" -f $< -o $@


###################
#                 #
# Implicit rules. #
#                 #
###################

$(VOFILES): %.vo: %.v
	$(COQC) $(COQDEBUG) $(COQFLAGS) $*

$(GLOBFILES): %.glob: %.v
	$(COQC) $(COQDEBUG) $(COQFLAGS) $*

$(VFILES:.v=.vio): %.vio: %.v
	$(COQC) -quick $(COQDEBUG) $(COQFLAGS) $*

$(GFILES): %.g: %.v
	$(GALLINA) $<

$(VFILES:.v=.tex): %.tex: %.v
	$(COQDOC) $(COQDOCFLAGS) -latex $< -o $@

$(HTMLFILES): %.html: %.v %.glob
	$(COQDOC) $(COQDOCFLAGS) -html $< -o $@

$(VFILES:.v=.g.tex): %.g.tex: %.v
	$(COQDOC) $(COQDOCFLAGS) -latex -g $< -o $@

$(GHTMLFILES): %.g.html: %.v %.glob
	$(COQDOC) $(COQDOCFLAGS)  -html -g $< -o $@

$(addsuffix .d,$(VFILES)): %.v.d: %.v
	$(COQDEP) $(COQLIBS) "$<" > "$@" || ( RV=$$?; rm -f "$@"; exit $${RV} )

$(addsuffix .beautified,$(VFILES)): %.v.beautified:
	$(COQC) $(COQDEBUG) $(COQFLAGS) -beautify $*

# WARNING
#
# This Makefile has been automagically generated
# Edit at your own risks !
#
# END OF WARNING

