#
# License Applicability. Except to the extent portions of this file are
# made subject to an alternative license as permitted in the SGI Free
# Software License B, Version 1.1 (the "License"), the contents of this
# file are subject only to the provisions of the License. You may not use
# this file except in compliance with the License. You may obtain a copy
# of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
# Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
#
# http://oss.sgi.com/projects/FreeB
#
# Note that, as provided in the License, the Software is distributed on an
# "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
# DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
# CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
# PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
#
# Original Code. The Original Code is: OpenGL Sample Implementation,
# Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
# Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
# Copyright in any portions created by third parties is as indicated
# elsewhere herein. All Rights Reserved.
#
# Additional Notice Provisions: The application programming interfaces
# established by SGI in conjunction with the Original Code are The
# OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
# April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
# 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
# Window System(R) (Version 1.3), released October 19, 1998. This software
# was created using the OpenGL(R) version 1.2.1 Sample Implementation
# published by SGI, but has not been independently verified as being
# compliant with the OpenGL(R) version 1.2.1 Specification.
#
# $Date$ $Revision$
# $Header$

# Generic rules for making manpages
#
# Usage:
#   make <name>.psv		# view page with $(PSVIEW) (no file created)
#   make <name>.xpsv		# view page with $(XPSVIEW) (no file created)
#   make <name>.dit		# view page with $(DITVIEW) (no file created)
#   make <name>.p		# print page (no file created)
#   make <name>.ps		# create PostScript for page
#   make <name>.z		# create online packed version; view with
#				# man -d <name>.z
#   make <name>.tr		# create troff source for man page
#   make print-list		# writes a list of the hardcopy (.p) targets
#				#  for the current directory to stdout
#
#   make default		# the standard SGI targets
#   make install
#   make clean
#   make clobber
#
#

TT = /tmp/mmdoc$$$$

# To provide override, define MANPREF
$(MANPREF)default: $(MANPREF)_force
	@$(LISTLEGAL) \
	    | sed -e 's/\.$(LEGALSUF1)$$/.z/' -e 's/\.$(LEGALSUF2)$$/.z/' \
		-e 's/\.$(LEGALSUF3)$$/.z/' -e 's/\.$(LEGALSUF4)$$/.z/' \
	    | xargs -l4 $(MAKE)

# remove all .z, .ps, and unsuffixed versions of legal man filenames (except
# a, c, f, and p).
$(MANPREF)clean:
	find . \( -name '*.z' -o -name '*.ps' \) -print | xargs rm -f
	$(LISTLEGAL) \
	    | sed -e 's/\.$(LEGALSUF1)$$//' -e 's/\.$(LEGALSUF2)$$//' \
		-e 's/\.$(LEGALSUF3)$$//' -e 's/\.$(LEGALSUF4)$$//' \
	    | sed '/^[acfp]$$/d' \
	    | xargs rm -f
	rm -f $(LDIRT)

$(MANPREF)clobber: $(MANPREF)clean

#
# Define generic build rules
#
# Some directories have multiple sections in them (like 3c, 3, 3x, etc)
# and so we must define more than 1 default rule.
#
# The .mn suffix is for pages that are part of the printed GL Reference Manual
# but not of the online man pages.
#
.SUFFIXES:.z .p .ps .dit .tr .psv .xpsv .1 .1c .1g .1m .1w .1X .2 .2b .3 .3a .3b .3c .3f .gl .3m .3n .3p .3r .3s .3t .3w .3x .3y .4 .5 .5w .6 .6d .7 .7p .7m .3X11 .3Xt .3i .mn .3l .3gl .html

.gl.3gl:
	@echo "\t$(MMDOC) Op=$(LANGOPT) $< > $@"
	@$(ADDMAGIC) | $(THTOUPPER) > $@

.1.z .1c.z .1g.z .1m.z .1w.z .1X.z .2.z .2b.z .3.z .3a.z .3f.z .3c.z .3p.z .3y.z .3r.z .3x.z .3n.z .3w.z .3s.z .3b.z .3m.z .3t.z .4.z .5.z .5w.z .6.z .6d.z .7.z .7p.z .7m.z .gl.z .3X11.z .3Xt.z .3i.z .3l.z:
	@echo "\t$(MMDOC) Op=$(LANGOPT) $< | pack > $*.z"
	@$(ADDMAGIC) | $(THTOUPPER) > $(TT) ; $(RUNMMDOC) $(TT) > $* ; \
								rm -f $(TT)
	@rm -f $*.z; pack -f $* > /dev/null

.1.p .1c.p .1g.p .1m.p .1w.p .1X.p .2.p .2b.p .3.p .3a.p .3f.p .3c.p .3p.p .3y.p .3r.p .3x.p .3n.p .3w.p .3s.p .3b.p .3m.p .3t.p .4.p .5.p .5w.p .6.p .6d.p .7.p .7p.p .7m.p .3X11.p .3Xt.p .3i.p .3l.p:
	@echo "\t$(MMDOC) -Tpsc -rC5 Op=$(LANGOPT) $<"
	@$(ADDMAGIC) > $(TT) ; $(RUNMMDOC) -Tpsc -rC5 $(TT) ; rm -f $(TT)

.gl.p .mn.p:
	@echo "\t$(MMDOC) -Tpsc -rC5 Op=$(LANGOPT) $<"
	@$(ADDGLMAGIC) > $(TT) ; $(RUNMMDOC) -Tpsc -rC5 $(TT) ; rm -f $(TT)

.1.ps .1c.ps .1g.ps .1m.ps .1w.ps .1X.ps .2.ps .2b.ps .3.ps .3a.ps .3f.ps .3c.ps .3p.ps .3y.ps .3r.ps .3x.ps .3n.ps .3w.ps .3s.ps .3b.ps .3m.ps .3t.ps .4.ps .5.ps .5w.ps .6.ps .6d.ps .7.ps .7p.ps .7m.ps .3X11.ps .3Xt.ps .3i.ps .3l.ps:
	@echo "\t$(MMDOC) -TPS Op=$(LANGOPT) $< > $@"
	@$(ADDMAGIC) > $(TT) ; $(RUNMMDOC) -TPS $(TT) > $@ ; rm -f $(TT)

.gl.ps .mn.ps:
	@echo "\t$(MMDOC) -TPS Op=$(LANGOPT) $< > $@"
	@$(ADDGLMAGIC) > $(TT) ; $(RUNMMDOC) -TPS $(TT) > $@ ; rm -f $(TT)

.gl.tr .mn.tr:
#	@echo "\t$(ADDGLMAGIC) $< > $@"
	@$(ADDGLMAGIC) > $@

.tr.ps:
	@echo "\t$(MMDOC) -TPS Op=$(LANGOPT) $< > $@"
	@$(RUNMMDOC) -TPS $< > $@

.1.psv .1c.psv .1g.psv .1m.psv .1w.psv .1X.psv .2.psv .2b.psv .3.psv .3a.psv.3f.psv .3c.psv .3p.psv .3y.psv .3r.psv .3x.psv .3n.psv .3w.psv .3s.psv .3b.psv .3m.psv .3t.psv .4.psv .5.psv .5w.psv .6.psv .6d.psv .7.psv .7p.psv .7m.psv .3X11.psv .3Xt.psv .3i.psv .3l.psv:
	@echo "\t$(MMDOC) -TPS -rC4 Op=$(LANGOPT) $< | $(PSVIEW) $(PSVIEWOPTS)"
	@$(ADDMAGIC) > $(TT) ; $(RUNMMDOC) -TPS -rC4 $(TT) | $(PSVIEW) $(PSVIEWOPTS); rm -f $(TT)

.gl.psv .mn.psv:
	@echo "\t$(MMDOC) -TPS -rC4 Op=$(LANGOPT) $< | $(PSVIEW) $(PSVIEWOPTS)"
	@$(ADDGLMAGIC) > $(TT) ; $(RUNMMDOC) -TPS -rC4 $(TT) | $(PSVIEW) $(PSVIEWOPTS); rm -f $(TT)

.1.xpsv .1c.xpsv .1g.xpsv .1m.xpsv .1w.xpsv .1X.xpsv .2.xpsv .2b.xpsv .3.xpsv .3a.xpsv .3f.xpsv .3c.xpsv .3p.xpsv .3y.xpsv .3r.xpsv .3x.xpsv .3n.xpsv .3w.xpsv .3s.xpsv .3b.xpsv .3m.xpsv .3t.xpsv .4.xpsv .5.xpsv .5w.xpsv .6.xpsv .6d.xpsv .7.xpsv .7p.xpsv .7m.xpsv .3X11.xpsv .3Xt.xpsv .3i.xpsv .3l.xpsv .3il.xpsv:
	@echo "\t$(MMDOC) -TPS -rC4 Op=$(LANGOPT) $< | $(XPSVIEW) $(XPSVIEWOPTS)"
	@$(ADDMAGIC) > $(TT) ; $(RUNMMDOC) -TPS -rC4 $(TT) | $(XPSVIEW) $(XPSVIEWOPTS); rm -f $(TT)

.gl.xpsv .mn.xpsv:
	@echo "\t$(MMDOC) -TPS -rC4 Op=$(LANGOPT) $< | $(XPSVIEW) $(XPSVIEWOPTS)"
	@$(ADDGLMAGIC) > $(TT) ; $(RUNMMDOC) -TPS -rC4 $(TT) | $(XPSVIEW) $(XPSVIEWOPTS); rm -f $(TT)

.1.dit .1c.dit .1g.dit .1m.dit .1w.dit .1X.dit .2.dit .2b.dit .3.dit .3a.dit .3f.dit .3c.dit .3p.dit .3y.dit .3r.dit .3x.dit .3n.dit .3w.dit .3s.dit .3b.dit .3m.dit .3t.dit .4.dit .5.dit .5w.dit .6.dit .6d.dit .7.dit .7p.dit .7m.dit .3X11.dit .3Xt.dit .3i.dit .3l.dit:
	@echo "\t$(MMDOC) -TX100 -rC4 Op=$(LANGOPT) $< | $(DITVIEW)"
	@$(ADDMAGIC) > $(TT) ; $(RUNMMDOC) -TX100 -rC4 $(TT) | $(DITVIEW)

.gl.dit .mn.dit:
	@echo "\t$(MMDOC) -TX100 -rC4 Op=$(LANGOPT) $< | $(DITVIEW)"
	@$(ADDGLMAGIC) > $(TT) ; $(RUNMMDOC) -TX100 -rC4 $(TT) | $(DITVIEW)

# The Irix man -d option must have a full pathname. This assumes
# that $(VPATH) is the full pathname to the dependency directory.
ifeq ($(OS),IRIX)
.3gl.html:
	man -d $(VPATH)/$(<F) | $(MAN2HTML) > $@
endif
ifeq ($(OS),Linux)
.3gl.html:
	man -M . $< | $(MAN2HTML) > $@
endif

# write a list of the hardcopy (.p) targets for the current directory to stdout
# use LOCALPRINTLISTFILTER to do directory-dependent filtering, e.g reordering
# to put intro.p first
print-list: $(MANPREF)_force
	@$(LISTLEGAL) \
	    | sed -e 's/\.$(LEGALSUF1)$$/.p/' -e 's/\.$(LEGALSUF2)$$/.p/' \
		-e 's/\.$(LEGALSUF3)$$/.p/' -e 's/\.$(LEGALSUF4)$$/.p/' \
	    | sort -t. +0 -1 \
	    $(LOCALPRINTLISTFILTER)

$(MANPREF)install: $(MANPREF)default MakeOtherInstalls
	$(INSTALL) -idb $(IDB_TAG) -m 444 -F $(IDB_PATH) *.z

# only look for aliases in legal man page filenames
MakeOtherInstalls: $(MANPREF)_force
	@echo "\tmaking symlink install lines"
	@$(LISTLEGAL) \
	    | xargs $(GETNAMES) opt=$(LANGOPT) \
	    | $(ADDINST) $(IDB_TAG) $(IDB_PATH) $(INSTALL) > $(TT); \
	    sh $(TT); rm -f $(TT)

$(MANPREF)_force:
