Skip to content

Commit

Permalink
Makefile: Make docs makefile portable
Browse files Browse the repository at this point in the history
This patch makes the docs makefile portable with GNU Make, BSD make and
Solaris make by:
 - removing all pattern rules
 - removing all conditionals from makefile (ok in shell)
 - removing all obscure macro functions
  • Loading branch information
tleedjarv committed Dec 17, 2024
1 parent b14ab18 commit 0b55693
Showing 1 changed file with 64 additions and 40 deletions.
104 changes: 64 additions & 40 deletions doc/Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
# Manual

# IMPORTANT!
#
# This file is portable and compatible with GNU Make, BSD make and
# Solaris (d)make. Do not make any changes in this file unless you
# are certain that the changes do not break this portability.


# a shorthand just for brevity
m = unison-manual

.PHONY: all
all: unison-manual.pdf unison-manual.html unison-manual.txt ../src/strings.ml
all: $(m).pdf $(m).html $(m).txt ../src/strings.ml

DRAFT = false

-include ../src/Makefile.ProjectInfo
include ../src/Makefile.ProjectInfo

SOURCES = unison-manual.tex \
local.tex short.tex \
unisonversion.tex prefs.tmp prefsdocs.tmp
FORMATS = html pdf txt dvi ps info
FORMATS_AUX = dtxt aux htoc toc

$(addprefix unison-manual., $(FORMATS) $(FORMATS_AUX)): $(SOURCES)
$(m).pdf $(m).html $(m).txt $(m).ps: $(SOURCES)
$(m).dtxt $(m).aux $(m).htoc $(m).toc: $(SOURCES)

unison-manual-directives.tex unison-manual-text-directives.tex:

ifneq ($(strip $(shell hevea -version)),)
HEVEA=true
endif
HEVEA_FOUND = test -n "$$(command -v hevea > /dev/null 2>&1 && echo true)"

unisonversion.tex: ../src/Makefile.ProjectInfo
echo '\def\unisonversion{$(VERSION)}' > $@
Expand All @@ -28,54 +33,73 @@ unisonversion.tex: ../src/Makefile.ProjectInfo
# jobname (or, output name for hevea) so that files for non-text versions are
# not overwritten. Here, suffix -text is used.

%-text-directives.tex:
$(m)-text-directives.tex:
printf '$(TEXDIRECTIVES)\\textversiontrue\\draft$(DRAFT)' > $@

%.dtxt: %.tex %-text-directives.tex
ifeq ($(HEVEA),true)
hevea -o $*-text.html $<
(TERM=vt100; export TERM; lynx -display_charset=utf8 -dump $*-text.html > $@)
endif
.SUFFIXES:
.SUFFIXES: .tex .pdf .ps .html .dtxt .txt

$(m).dtxt: $(m)-text-directives.tex

%.txt: %.dtxt
ifeq ($(HEVEA),true)
sed -e "/^----SNIP----/,+2 d" -e "/^Junk/,$$ d" $< > $@
endif
.tex.dtxt:
if $(HEVEA_FOUND) ; then \
hevea -o $*-text.html $< ; \
(TERM=vt100; export TERM; lynx -display_charset=utf8 -dump $*-text.html > $@) \
; fi

../src/strings.ml: unison-manual.dtxt docs.ml
ifeq ($(HEVEA),true)
ocaml docs.ml < $< > $@
endif
.dtxt.txt:
if $(HEVEA_FOUND) ; then \
sed -e "/^----SNIP----/,+2 d" -e "/^Junk/,$$ d" $< > $@ \
; fi

%-directives.tex:
../src/strings.ml: $(m).dtxt docs.ml
if $(HEVEA_FOUND) ; then \
ocaml docs.ml < $(m).dtxt > $@ \
; fi

$(m)-directives.tex:
printf '$(TEXDIRECTIVES)\\textversionfalse\\draft$(DRAFT)' > $@

# (pdf)latex must be run multiple times to generate toc and correct references

%.aux %.htoc: %.tex %-directives.tex
pdflatex -draftmode $<
pdflatex -draftmode $<

%.pdf: %.tex %-directives.tex %.aux
$(m).aux $(m).htoc &: $(m).tex $(m)-directives.tex
pdflatex -draftmode $(m).tex && \
pdflatex -draftmode $(m).tex
# &: is the GNU Make group target separator. Other make implementations do not
# support it but accept it nevertheless because it's treated as a target named &
# Without group targets, the same outcome is achieved by the following:
.ORDER: $(m).aux $(m).htoc # BSD make
.NO_PARALLEL$(.MAKE.PID): $(m).aux $(m).htoc # Solaris make
# BSD make interprets .NO_PARALLEL as the entire makefile not parallel.
# .MAKE.PID (which is only defined by BSD make) is in there just to prevent
# BSD make from interpreting this rule

$(m).pdf: $(m).tex $(m)-directives.tex $(m).aux

.tex.pdf:
pdflatex $<

%.ps: %.pdf
.pdf.ps:
pdf2ps $<

%.html: %.tex %-directives.tex %.htoc
ifeq ($(HEVEA),true)
hevea $<
endif
$(m).html: $(m).tex $(m)-directives.tex $(m).htoc

.tex.html:
if $(HEVEA_FOUND) ; then \
hevea $< \
; fi

# Listing of preferences
prefs.tmp: ../src/$(NAME)$(EXEC_EXT)
-../src/$(NAME)$(EXEC_EXT) -help > prefs.tmp
prefsdocs.tmp: ../src/$(NAME)$(EXEC_EXT)
-../src/$(NAME)$(EXEC_EXT) -prefsdocs 2> prefsdocs.tmp
prefs.tmp: ../src/$(NAME)
-../src/$(NAME) -help > prefs.tmp
prefsdocs.tmp: ../src/$(NAME)
../src/$(NAME) -prefsdocs 2> prefsdocs.tmp

../src/$(NAME)$(EXEC_EXT):
../src/$(NAME):
$(MAKE) -C ../src tui

RM = rm -f

.PHONY: clean
clean:
$(RM) -r \
Expand Down

0 comments on commit 0b55693

Please sign in to comment.