## 
## prooftree --- proof tree display for Proof General
## 
## Copyright (C) 2011 - 2016 Hendrik Tews
## 
## This file is part of "prooftree".
## 
## "prooftree" 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 3 of the
## License, or (at your option) any later version.
## 
## "prooftree" 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 in file COPYING in this or one of the parent
## directories for more details.
## 
## You should have received a copy of the GNU General Public License
## along with "prooftree". If not, see <http://www.gnu.org/licenses/>.
## 
## $Id: Makefile.in,v 1.29 2016/01/23 12:57:13 tews Exp $
## 
## Commentary: Makefile
## 

#############################################################################
##
## CONFIGURATION SECTION
##
#############################################################################

# The following variables are normally set by the configure script. 
# If this fails for some reason you can also rename Makefile.in to Makefile
# and set these variables manually.

# BINDIR: Directory where binaries are to be instelled. 
BINDIR:=@BINDIR@

# MANDIR: Directory where the man page is to be installed.
MANDIR:=@MANDIR@

# Should be ``prooftree.opt'' if you have ocamlopt.opt available.
# Should be ``prooftree.byte'' if you only have ocamlc.
prooftree: @PROOFTREE@

# ocaml compiler: should be ``ocamlopt.opt'' if available, ``ocamlc'' otherwise
OCAMLC:=@OCAMLC@

# ocaml dependency analyzer
# should be ``ocamldep.opt'' if available, ``ocamldep'' otherwise
OCAMLDEP:=@OCAMLDEP@

# ocaml documentation generator
# should be ``ocamldoc.opt'' if available, ``ocamldep'' otherwise
OCAMLDOC:=@OCAMLDOC@

# location of the lablgtk2 library
LABLGTKDIR:=@LABLGTKDIR@

#############################################################################
##
## END OF CONFIGURATION SECTION
##
#############################################################################

ODOC_CHECK:=/home/tews/src/odoc_check/odoc_check.cmxs
ODOC_XREF:=/home/tews/src/odoc_xref/odoc_xref.cmxs
LABLGTKURL:=/usr/share/doc/liblablgtk2-ocaml-doc/html/api


.PHONY: all
all: prooftree

ML_SOURCES:=\
	version.ml \
	util.ml \
	gtk_ext.ml \
	configuration.ml \
	draw_tree.ml \
	tree_layers.ml \
	about_window.ml \
	help_window.ml \
	node_window.ml \
	ext_dialog.ml \
	emacs_commands.ml \
	proof_window.ml \
	proof_tree.ml \
	coq.ml \
	input.ml \
	main.ml

MLI_SOURCES:=\
	version.mli \
	proof_tree.mli \
	input.mli

SOURCES:=$(MLI_SOURCES) $(ML_SOURCES)
CMO_OBJECTS:=$(ML_SOURCES:.ml=.cmo)
CMX_OBJECTS:=$(ML_SOURCES:.ml=.cmx)


TOCLEAN+=Makefile.deps
Makefile.deps : $(SOURCES)
	$(OCAMLDEP) $^ > Makefile.deps

include Makefile.deps

OCAMLFLAGS:=-safe-string -w Aem-48 -g -I $(LABLGTKDIR)

%.cmx: %.ml
	$(OCAMLC) -c $(OCAMLFLAGS) $<

%.cmo: %.ml
	$(OCAMLC) -c $(OCAMLFLAGS) $<

%.cmi: %.mli
	$(OCAMLC) -c $(OCAMLFLAGS) $<


TOCLEAN+=prooftree

.PHONY: prooftree.opt
prooftree.opt: $(CMX_OBJECTS)
	$(OCAMLC) -g -I $(LABLGTKDIR) -o prooftree \
		unix.cmxa lablgtk.cmxa gtkInit.cmx $^

.PHONY: prooftree.byte
prooftree.byte: $(CMO_OBJECTS)
	$(OCAMLC) -g -I $(LABLGTKDIR) -o prooftree \
		unix.cma lablgtk.cma gtkInit.cmo $^

TOCLEAN+=version.ml
version.ml: version.txt
	echo '(* This file is automatically generated from version.txt *)' > $@
	echo '(* DO NOT EDIT! *)' >> $@
	echo "let version = \"`head -1 version.txt`\"" >> $@

.PHONY: install
install:
	mkdir -p $(DESTDIR)$(BINDIR)
	cp prooftree $(DESTDIR)$(BINDIR)
	mkdir -p $(DESTDIR)$(MANDIR)/man1
	cp prooftree.1 $(DESTDIR)$(MANDIR)/man1


TOCLEAN+=dump.odoc-dump
dump.odoc-dump: $(SOURCES)
	$(OCAMLDOC) -I $(LABLGTKDIR) -d doc \
		-inv-merge-ml-mli -m A -dump $@ $(SOURCES)

.PHONY: doc
doc: dump.odoc-dump
	rm -rf doc
	mkdir doc
	$(OCAMLDOC) -I $(LABLGTKDIR) -d doc \
		-g $(ODOC_XREF) -libxref lablgtk $(LABLGTKURL) \
		-inv-merge-ml-mli -m A -load dump.odoc-dump
	$(OCAMLDOC) -I $(LABLGTKURL) -dot -dot-reduce \
		-o doc/dependencies.dot -load dump.odoc-dump
	dot -Tps doc/dependencies.dot > doc/dependencies.ps

.PHONY: check-doc
check-doc: dump.odoc-dump
	$(OCAMLDOC) -g $(ODOC_CHECK) -load dump.odoc-dump -check-all fcd

clean:
	rm -f $(TOCLEAN)
	rm -f *.cmi *.cmo *.cmx *.o *.cma *.cmxa *.a

TAGS: $(SOURCES)
	otags $(SOURCES)

prooftree.man.txt: prooftree.1
	nroff -man $< > $@

prooftree.man.html: prooftree.1
	man2html $< | \
		tail -n +3 |\
		sed -e 's|<A HREF=".*Return to Main Contents</A>||' \
		    -e 's|/cgi-bin/man/man2html?1.\([^"]*\)|http://www.linuxmanpages.com/man1/\1.1.php|' \
		    -e 's|HREF="/cgi-bin/man/man2html">man2html|HREF="http://www.nongnu.org/man2html/">man2html|' \
		> $@

.PHONY: sloc
sloc:
	wc $(SOURCES) | sort -n
