# @package      hubzero-texvc
# @file         Makefile
# @author       Nicholas J. Kisseberth <nkissebe@purdue.edu>
# @copyright    Copyright (c) 2010-2018 HUBzero Foundation, LLC.
# @license      http://www.gnu.org/licenses/gpl-2.0.html GPLv2
#
# Copyright (c) 2010-2018 HUBzero Foundation, LLC.
#
# This file is part of: The HUBzero(R) Platform for Scientific Collaboration
#
# The HUBzero(R) Platform for Scientific Collaboration (HUBzero) is free
# 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, version 2.
#
# HUBzero 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 this program.  If not, see <http://www.gnu.org/licenses/>.
#
# HUBzero is a registered trademark of HUBzero Foundation, LLC.
#

DISTRIBUTION:=$(shell lsb_release -i -s)

# docbook.xsl is in a different location for RH and DEBIAN
ifeq ($(DISTRIBUTION),Debian)
dbook="/usr/share/sgml/docbook/stylesheet/xsl/nwalsh/manpages/docbook.xsl"
else
dbook="/usr/share/sgml/docbook/xsl-stylesheets-1.75.2/manpages/docbook.xsl"
endif



USRBIN=$(DESTDIR)/usr/bin
USRSHAREMAN=$(DESTDIR)/usr/share/man

OBJ =	render_info.cmo tex.cmo texutil.cmo parser.cmo lexer.cmo texvc.cmo \
	render_info.cmx tex.cmx texutil.cmx parser.cmx lexer.cmx texvc.cmx \
	lexer.cmi parser.cmi render_info.cmi tex.cmi texutil.cmi texvc.cmi \
	lexer.o parser.o render_info.o tex.o texutil.o texvc.o \
	lexer.ml parser.ml parser.mli texvc \
	util.o \
	util.cmo util.cmx util.cmi \
	render.o render.cmi render.cmo render.cmx \
	html.cmi html.cmo html.cmx \
	html.o mathml.cmi mathml.cmo mathml.cmx mathml.o

COMMON_NATIVE_OBJ  =util.cmx parser.cmx html.cmx mathml.cmx texutil.cmx lexer.cmx

all: texvc texvc.1
	@true

texvc.1: texvc.xml
	xsltproc -nonet -o texvc.1 $(dbook) texvc.xml

texvc: $(COMMON_NATIVE_OBJ) render.cmx texvc.cmx
	ocamlopt -o $@ unix.cmxa $^

# Pattern rules

#  .ml source  .mli interface
#  .cmi compiled interface
#  .cmo object       .cma library object
#  .cmx object file  .cmxa library object file

%.ml: %.mll
	ocamllex $<

%.mli %.ml: %.mly
	ocamlyacc $<

%.cmo: %.ml
	ocamlc -c $<

%.cmx: %.ml
	ocamlopt -c $<

%.cmi: %.mli
	ocamlc -c $<

# Various dependencies

html.cmo: render_info.cmi tex.cmi util.cmo html.cmi 
html.cmx: render_info.cmi tex.cmi util.cmx html.cmi 
html.cmi: tex.cmi 
lexer.cmo: parser.cmi render_info.cmi tex.cmi texutil.cmi 
lexer.cmx: parser.cmx render_info.cmi tex.cmi texutil.cmx 
mathml.cmo: tex.cmi mathml.cmi 
mathml.cmx: tex.cmi mathml.cmi 
mathml.cmi: tex.cmi 
parser.cmo: render_info.cmi tex.cmi parser.cmi 
parser.cmx: render_info.cmi tex.cmi parser.cmi 
parser.cmi: render_info.cmi tex.cmi 
render.cmo: texutil.cmi util.cmo 
render.cmx: texutil.cmx util.cmx 
tex.cmi: render_info.cmi 
texutil.cmo: html.cmi parser.cmi render_info.cmi tex.cmi util.cmo texutil.cmi 
texutil.cmx: html.cmx parser.cmx render_info.cmi tex.cmi util.cmx texutil.cmi 
texutil.cmi: parser.cmi tex.cmi 
texvc.cmo: html.cmi lexer.cmo mathml.cmi parser.cmi render.cmo texutil.cmi util.cmo 
texvc.cmx: html.cmx lexer.cmx mathml.cmx parser.cmx render.cmx texutil.cmx util.cmx 

install:
	install --mode 0755 texvc -D $(USRBIN)/texvc
	install --mode 0644 texvc.1 -D $(USRSHAREMAN)/man1/texvc.1

uninstall:
	@true

postinst:
	@true

clean:
	rm -f $(OBJ) texvc.1

.PHONY: all install uninstall postinst clean
