# This TeXLive installation (on ingwe) has the TikZ fix.
TEX_DIR = /scratch/tlmiller/install/texlive/2017/bin/x86_64-linux/
export PATH := $(TEX_DIR):$(PATH)

# The .fig sources are stored in git.
FIG_FIGS =		user-man/dagman-node.eps \
				user-man/dagman-diamond.eps \
				user-man/dagman-connect.eps

# The .dia sources are stored in git, but Make doesn't make the .eps files.
DIA_FIGS =		admin-man/states.eps \
				admin-man/activities.eps

# The .dot sources are stored in git, but Make doesn't make the .eps files.
DOT_FIGS = 		user-man/splice-simple.eps \
				user-man/splice-X.eps \
				user-man/splice-s1.eps \
				user-man/splice-complex.eps

# The .ps file is stored in git; there is no "source."
PS_FIGS =		contrib/view-screenshot.ps

FIGURES =		$(FIG_FIGS:%.eps=%.pdf) \
				$(DIA_FIGS:%.eps=%.pdf) \
				$(DOT_FIGS:%.eps=%.pdf) \
				$(PS_FIGS:%.ps=%.pdf)

LATEX_ARGS =	-file-line-error-style -halt-on-error

# Convert the list of each ${manpage}.tex sourced to build the manual
# into the list of ${manpage}.html generate by latex2html.  This is
# rather a hack, but I don't care enough about the man pages to fix it.
MANPAGES = $(shell grep '^\\input' man-pages/man.tex | grep -v condor_dagman_metrics_reporter.tex | grep -v tool_common.tex | awk -F/ '{print $$2}' | awk -F. '{printf "%s.html ",$$1}')

all : ref.pdf

# Only helpful for debugging.  Do NOT insert this as a dependency
# of ref.pdf; that will force it to be rebuilt every time.
figures : $(FIGURES)

#
# Moved the ref.pdf rule to the bottom of this file because rebuilding
# was either never or always happening otherwise.
#

# 'ref' is what we're building.  '3' is how many sections deep to split
# the pages.  'sec-filename' is to use the symbolic section names in
# the URLs, which should make the links more stable.  'next' adds the 'next'
# link to the header and footer.  'info' is a debugging option?
#
# 'NoFonts' disables the broken-ass default that uses SVG's tspan tags.
# 'fonts' turns on something that's based on span tags with classes
# corresponding to LaTeX font classes (textit, textbf, and texttt).
HTLATEX_OPTIONS=ref,3,sec-filename,next,info,NoFonts,fonts
ref.html : ref.tex condor-macros.4ht ref.cfg $(FIGURES) $(LATEX_SOURCES)
	@make tex-clean
	@rm -fr ref.html
	@htlatex ref.tex $(HTLATEX_OPTIONS)
	@tex '\def\filename{{ref}{idx}{4dx}{ind}} \input idxmake.4ht'
	@makeindex -o ref.ind ref.4dx
	@htlatex ref.tex $(HTLATEX_OPTIONS)
	@mkdir ref && cd ref && mv ../ref.css ../*.html ../*.svg ../*.png . && cd .. && mv ref ref.html

just-man-pages : just-man-pages.tex $(MANUAL_SOURCES)
	@cd makeman ; make clean && make makeman
	@latex2html -split 4 -link 2 -antialias -tmp /tmp -long_titles 3 -toc_depth 2 -local_icons just-man-pages.tex
	@cd just-man-pages; for html in $(MANPAGES); do \
		../makeman/makeman -v -i $${html} -s 1; \
	done
	@cd just-man-pages; mv condor_dagman_metrics_repor.html condor_dagman_metrics_reporter.html; ../makeman/makeman -v -i condor_dagman_metrics_reporter.html -s 1
	@rm -fr man
	@mkdir man
	@mkdir man/man1
	@mv just-man-pages/*.1 man/man1
#	@rm -fr just-man-pages

%.pdf : %.ps
	@ps2pdf -dEPSCrop $< $@

%.pdf : %.eps
	@epstopdf $< > $@

%.eps : %.fig
	@fig2dev -L eps -m .6 $< > $@

# Make automatically deletes intermediate files (files created as the
# result of a implicit rule whose result is not a target).  The special
# target .SECONDARY says to not delete the listed intermediate files;
# this -- as far as I know -- is the only way to prevent Make from reporting
# that they're being deleted (which is just confusing noise).
.SECONDARY : $(FIG_FIGS)

clean : figures-clean tex-clean pdf-clean html-clean man-clean

figures-clean :
	@rm -f $(FIG_FIGS)
	@rm -f $(FIGURES)

tex-clean :
	@rm -f ref.log ref.aux ref.toc ref.ind ref.idx ref.ilg ref.out

pdf-clean :
	@rm -f ref.pdf

html-clean :
	@rm -fr *.html *.png ref ref.html
	@rm -fr ref.dvi texput.log
	@rm -fr idxmake.dvi idxmake.log
	@rm -fr ref.4ct ref.4dx ref.4ix ref.4tc ref.css ref.idv ref.lg ref.tmp ref.xref

man-clean :
	@rm -fr man just-man-pages
	@cd makeman; make clean > /dev/null 2>&1

release : ref.pdf ref.html
	@/bin/bash -e make-release

#
# Originally generated by 'tex-dependencies.pl ref.tex' and edited for
# ease of updating (and to make the manual and man pages rebuild correctly
# after changes).  In order by sub-directory.
#

MANUAL_SOURCES = \
    man-macros.tex \
    man-pages/man.tex man-pages/tool_common.tex man-pages/bosco_cluster.tex man-pages/bosco_findplatform.tex man-pages/bosco_install.tex man-pages/bosco_ssh_start.tex man-pages/bosco_start.tex man-pages/bosco_stop.tex man-pages/bosco_uninstall.tex man-pages/condor_advertise.tex man-pages/condor_annex.tex man-pages/condor_check_userlogs.tex man-pages/condor_checkpoint.tex man-pages/condor_chirp.tex man-pages/condor_cod.tex man-pages/condor_compile.tex man-pages/condor_config_val.tex man-pages/condor_configure.tex man-pages/condor_continue.tex man-pages/condor_convert_history.tex man-pages/condor_dagman.tex man-pages/condor_dagman_metrics_reporter.tex man-pages/condor_drain.tex man-pages/condor_fetchlog.tex man-pages/condor_findhost.tex man-pages/condor_gather_info.tex man-pages/condor_gpu_discovery.tex man-pages/condor_history.tex man-pages/condor_hold.tex man-pages/condor_install.tex man-pages/condor_job_router_info.tex man-pages/condor_master.tex man-pages/condor_off.tex man-pages/condor_on.tex man-pages/condor_ping.tex man-pages/condor_pool_job_report.tex man-pages/condor_power.tex man-pages/condor_preen.tex man-pages/condor_prio.tex man-pages/condor_procd.tex man-pages/condor_q.tex man-pages/condor_qedit.tex man-pages/condor_qsub.tex man-pages/condor_reconfig.tex man-pages/condor_release.tex man-pages/condor_reschedule.tex man-pages/condor_restart.tex man-pages/condor_rm.tex man-pages/condor_rmdir.tex man-pages/condor_router_history.tex man-pages/condor_router_q.tex man-pages/condor_router_rm.tex man-pages/condor_run.tex man-pages/condor_set_shutdown.tex man-pages/condor_ssh_to_job.tex man-pages/condor_sos.tex man-pages/condor_stats.tex man-pages/condor_status.tex man-pages/condor_store_cred.tex man-pages/condor_submit.tex man-pages/submitcmds.tex man-pages/condor_submit_dag.tex man-pages/condor_suspend.tex man-pages/condor_tail.tex man-pages/condor_top.tex man-pages/condor_transfer_data.tex man-pages/condor_transform_ads.tex man-pages/condor_update_machine_ad.tex man-pages/condor_updates_stats.tex man-pages/condor_urlfetch.tex man-pages/condor_userlog.tex man-pages/condor_userprio.tex man-pages/condor_vacate.tex man-pages/condor_vacate_job.tex man-pages/condor_version.tex man-pages/condor_wait.tex man-pages/condor_who.tex man-pages/gidd_alloc.tex man-pages/procd_ctl.tex man-pages/condor_now.tex

LATEX_SOURCES = $(MANUAL_SOURCES) \
                condor-macros.sty \
                symbol.tex license.tex faq.tex \
                admin-man/if-else.tex admin-man/function-macros.tex admin-man/admin.tex admin-man/intro.tex admin-man/install.tex admin-man/install-windows.tex admin-man/configure-intro.tex admin-man/if-else.tex admin-man/function-macros.tex admin-man/configure-metaknobs.tex admin-man/configure.tex admin-man/userprio.tex admin-man/policy.tex admin-man/multi-core.tex admin-man/security.tex admin-man/networking.tex admin-man/ports.tex admin-man/shared-port-daemon.tex admin-man/multiple-interfaces.tex admin-man/ccb.tex admin-man/tcp-update.tex admin-man/ipv6.tex admin-man/ckpt-server.tex admin-man/daemoncore.tex admin-man/monitoring.tex admin-man/absent.tex admin-man/high-availability.tex admin-man/ha.tex admin-man/special.tex admin-man/afs.tex admin-man/url-transfer.tex admin-man/multiple-platforms.tex admin-man/full-condor-compile.tex admin-man/kbdd.tex admin-man/condor-view-server.tex admin-man/virtual-machines.tex admin-man/dedicated.tex admin-man/backfill.tex admin-man/PID-namespaces.tex admin-man/group-tracking.tex admin-man/limits.tex admin-man/limits-cgroup.tex admin-man/concurrency.tex admin-man/java.tex admin-man/vm.tex admin-man/singularity.tex admin-man/power.tex \
                clouds/cloud-computing.tex clouds/introduction.tex clouds/user-guide.tex clouds/customization.tex clouds/aws.tex clouds/azure.tex clouds/gcp.tex clouds/softlayer.tex clouds/config.tex \
                contrib/contrib.tex contrib/hdfs.tex contrib/condor-view-client.tex contrib/logview.tex \
                grids/grid-computing.tex grids/intro.tex grids/flocking.tex grids/grid-universe.tex grids/condor-c.tex grids/condor-g.tex grids/using.tex grids/grid-monitor.tex grids/nordugrid.tex grids/unicore.tex grids/batch.tex grids/amazon.tex grids/gce.tex grids/cream.tex grids/boinc.tex grids/grid-matchmaking.tex grids/job_router.tex \
                misc/misc.tex misc/classad.tex misc/ckpt.tex misc/cod.tex misc/hooks.tex misc/job-hooks.tex misc/logging.tex misc/attributes.tex misc/jobad.tex misc/machad.tex misc/masterad.tex misc/scheddad.tex misc/negotiatorad.tex misc/submitterad.tex misc/defragad.tex misc/collectorad.tex misc/statsattributes.tex misc/numbers.tex misc/API.tex misc/pythonbindings.tex misc/chirp.tex misc/user-log.tex misc/commandline.tex misc/drmaa.tex \
                overview/overview.tex overview/contributions.tex \
                platforms/platforms.tex platforms/linux.tex platforms/windows.tex platforms/macosx.tex \
                user-man/limitations.tex user-man/user.tex user-man/limitations.tex user-man/filetransfer.tex user-man/interactive.tex user-man/managing.tex user-man/java.tex user-man/parallel.tex user-man/dagman.tex user-man/vm.tex user-man/docker.tex user-man/time-scheduling.tex \
                version-history/history.tex version-history/upgradingto8-8.tex version-history/8-8.history.tex version-history/8-7.history.tex version-history/8-6.history.tex

# Only the v8.7 branch requires the fourth run to remove the 'labels may
# changed' warning.  We should figure out why.
#
# The index files (ref.ind, at least) produced by htlatex confuse pdflatex,
# so we need to make sure that they're gone before building.  We don't
# depend on tex-clean because then we always rebuild.
ref.pdf : ref.tex $(FIGURES) $(LATEX_SOURCES)
	@make tex-clean
	@pdflatex $(LATEX_ARGS) ref.tex
	@makeindex ref
	@pdflatex $(LATEX_ARGS) ref.tex
	@pdflatex $(LATEX_ARGS) ref.tex
	@pdflatex $(LATEX_ARGS) ref.tex
