depth = ../..

include $(depth)/make/lilypond.make


# Only needed for building the documentation.
ifeq ($(out),www)
  ifndef VERBOSE
    TEX_QUIET = >/dev/null
    PLTOTF_QUIET = &>/dev/null
  else
    TEX_QUIET =
    PLTOTF_QUIET =
  endif

  # We need the AFM files of the 'lmodern' fonts as TeX input.
  AFMDIR = $(dir $(shell kpsewhich -format=afm lmtl10))
  TEXDIR = $(src-dir)

  LMFILES = lmttb lmttbo lmttr lmttro
  AUXFILES = lmtt.map ot1ttx.enc

  $(outdir)/dep: \
    $(LMFILES:%=$(outdir)/%.tfm) \
    $(AUXFILES:%=$(outdir)/%)

  # The TeX calls below create multiple targets; to make this work properly
  # with parallel execution we use intermediate targets; see
  # https://stackoverflow.com/questions/19822435/multiple-targets-from-one-recipe-and-parallel-execution
  #
  # The StackOverflow answer also demonstrates a simpler solution (using the
  # new `&:` operator instead of `:`), available since the release of GNU
  # make 4.3 in January 2020.  Alas, at the time of this writing (February
  # 2022) this version is still too new to be universally available.

  .INTERMEDIATE: lmfiles auxfiles

  $(LMFILES:%=$(outdir)/%.pl) \
  lm-ot1-transforms.recs: lmfiles

  $(AUXFILES:%=$(outdir)/%): auxfiles

  lmfiles: lm-ot1.tex ot1ttx.etx
	  $(call ly_info,Making .pl files for lm fonts < afm)
	  cd $(outdir) \
	  && TEXINPUTS="$(AFMDIR);$(TEXDIR);" $(TEX) $< $(TEX_QUIET)

  # The `.recs` file is generated by `lm-ot1.tex`, too.
  auxfiles: lm-ot1-map.tex lm-ot1-transforms.recs
	  $(call ly_info,Making .map and .enc files for lm fonts (tex))
	  cd $(outdir) \
	  && TEXINPUTS="$(TEXDIR);" $(TEX) $< $(TEX_QUIET)

  $(outdir)/%.tfm: $(outdir)/%.pl
	  $(call ly_progress,Making,$@,< pl)
	  $(PLTOTF) $< $@ $(PLTOTF_QUIET)

  local-WWW: $(outdir)/dep
endif # out=www
