# Build the pdf library as byte code and native code
# Outputs pdfcaml.cmxa, pdfcaml.cma
# and dllcamlpdf_stubs.so, libcamlpdf_stubs.a or similar 

# OCaml and C source and interface files. Order matters.
SOURCES = utility.ml utility.mli io.ml io.mli \
	  zlib.ml zlib.mli \
	  zlibstubs.c \
	  transform.ml transform.mli \
	  units.ml units.mli \
	  paper.ml paper.mli \
	  pdf.ml pdf.mli \
	  pdfcrypt.ml pdfcrypt.mli \
	  pdfwrite.ml pdfwrite.mli \
	  pdfcodec.ml pdfcodec.mli \
	  pdfread.ml pdfread.mli \
	  pdfpages.ml pdfpages.mli \
	  pdfdoc.ml pdfdoc.mli \
	  pdffun.ml pdffun.mli \
	  pdfimage.ml pdfimage.mli \
	  glyphlist.ml glyphlist.mli \
	  pdftext.ml pdftext.mli \
          fonttables.ml fonttables.mli

RESULT = camlpdf

TRASH = tl prog.tex camlpdf.tex camlpdf.aux camlpdf.log camlpdf.toc 

# ML Libraries
LIBS = unix bigarray str

CLIBS = z

#Uncomment for debug build
#OCAMLNCFLAGS = -g
#OCAMLBCFLAGS = -g
#CAMLLDFLAGS = -g

all : native-code-library byte-code-library

# Predefined generic makefile
-include OCamlMakefile

# Build the reference
documents:
	mkdir -p doc/camlpdf/html; ocamldoc -html -d doc/camlpdf/html utility.mli io.mli transform.mli units.mli paper.mli pdf.mli pdfcrypt.mli pdfwrite.mli pdfcodec.mli pdfread.mli pdfpages.mli pdfdoc.mli pdffun.mli pdfimage.mli glyphlist.mli pdftext.mli fonttables.mli

# Build the regression tester
regtest: regtest.ml utility.ml
	ocamlc -o regtest bigarray.cma utility.ml regtest.ml

# Build the literate program
literate:
	ocamlweb --noweb --header -o prog.tex \
	pdf.ml \
	pdfcrypt.ml \
	pdfdoc.ml \
	pdfcodec.ml \
	pdfwrite.ml \
	pdfread.ml \
	pdfpages.ml \
	pdffun.ml \
	pdfimage.ml \
	pdftext.ml \
	fonttables.ml \
	glyphlist.ml \
	utility.ml \
	transform.ml \
	units.ml \
	paper.ml \
	io.ml \
	pdfhello.ml \
	pdfdecomp.ml \
	pdftest.ml \
	pdfmerge.ml \
	pdfdraft.ml;
	tail -n +8 prog.tex > tl; cat headpdf.tex tl > camlpdf.tex; \
	pdflatex camlpdf.tex;

# Finish up literate program, getting references, table of contents etc. correct
litfinish:
	pdflatex camlpdf.tex; pdflatex camlpdf.tex

