#
# UNIX Makefile for NASM documentation
#

srcdir		= .

prefix		= /usr/local
exec_prefix	= ${prefix}
bindir		= ${exec_prefix}/bin
mandir		= ${datarootdir}/man
docdir		= $(prefix)/doc/nasm
infodir		= ${datarootdir}/info
datarootdir	= ${prefix}/share

INSTALL		= /usr/bin/install -c
INSTALL_PROGRAM	= ${INSTALL}
INSTALL_DATA	= ${INSTALL} -m 644

PERL		= perl
MAKEINFO	= makeinfo
TEXI2DVI        = texi2dvi
PS2PDF          = ps2pdf		# Part of GhostScript

SRCS		= nasmdoc.src
OUT		= nasm.info nasmdoc.ps nasmdoc.pdf

# exports
export srcdir
export PERL

all: $(OUT)

os2: nasm.inf

inslist.src: inslist.pl ../insns.dat
	$(PERL) $(srcdir)/inslist.pl

# Consider html, txt and ps output a side effect
nasmdoc.dip: nasmdoc.src rdsrc.pl inslist.src
	mkdir -p html
	$(PERL) $(srcdir)/rdsrc.pl < $<
	mv -f *.html html

nasmdoc.texi: nasmdoc.dip
	: Generated by side effect

nasmdoc.ps: nasmdoc.dip nasmlogo.eps $(srcdir)/../version genpsdriver.pl \
	    genps.pl psfonts.ph pswidth.ph head.ps
	$(PERL) $(srcdir)/genpsdriver.pl > nasmdoc.ps

nasmdoc.pdf: nasmdoc.ps
	$(PS2PDF) nasmdoc.ps

nasm.info: info/nasm.info

info/nasm.info: nasmdoc.texi
	mkdir -p info
	$(MAKEINFO) $<
	mv -f *.info *.info-* info

# DVI output from texinfo (optional)
nasmdoc.dvi: nasmdoc.texi
	$(TEXI2DVI) nasmdoc.texi

# Rules for building an OS/2 book
nasmdoc.ipf: nasmdoc.texi
	texi2ipf $< >$@

nasm.inf: nasmdoc.ipf
	ipfc -i -s $< $@

clean:
	-rm -f *.rtf *.hpj *.texi *.gid *.ipf *.dip
	-rm -f *.aux *.cp *.fn *.ky *.pg *.log *.toc *.tp *.vr

spotless: clean
	-rm -rf html info
	-rm -f *.hlp nasmdoc.txt *.inf *.pdf *.dvi
	-rm -f nasmdoc*.ps inslist.src

install: all
	$(INSTALL_DATA) info/* $(INSTALLROOT)$(infodir)
	mkdir -p $(INSTALLROOT)$(docdir)/html
	$(INSTALL_DATA) html/* $(INSTALLROOT)$(docdir)/html
	$(INSTALL_DATA) nasmdoc.ps nasmdoc.pdf nasmdoc.txt $(INSTALLROOT)$(docdir)
