summaryrefslogtreecommitdiff
path: root/macros/generic/memoize/Makefile
blob: 120b10490396ceb8965160bef2d02a0461a1d2df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Prepare the CTAN submission for all three packages.

PACKAGES = memoize advice collargs

all: ctan/memoize.zip
	$(MAKE) -f Makefile.advice ctan/advice.zip
	$(MAKE) -f Makefile.collargs ctan/collargs.zip
	@echo "Don't forget to run the tests!"

# Prepare the CTAN submission.

PACKAGE = memoize
VERSION = 1.1.1
YEAR = 2024
MONTH = 01
DAY = 16

FORMAT = generic

COMMON = memoize nomemoize memoizable
PLAIN = memoize-extract-one.tex
GENERIC = memoizable.code.tex
SOURCE = memoize.edtx memoize.ins

SCRIPTS := memoize-extract memoize-clean
man-src := $(SCRIPTS:%=doc/%.1.md)
MAN := $(SCRIPTS:%=%.1) $(SCRIPTS:%=%.pl.1) $(SCRIPTS:%=%.py.1)
MAN := $(MAN:%=doc/%)
SCRIPTS := $(SCRIPTS:%=%.pl) $(SCRIPTS:%=%.py)

%.pl.1: %.1
	echo .so man1/$*.1 > $@     # link to .1 man page
%.py.1: %.1
	echo .so man1/$*.1 > $@     # link to .1 man page

README = doc/README.memoize.md
INSTALL = INSTALL.md
CHANGELOG = CHANGELOG.md
MAKEFILE = Makefile
LICENCE = LICENCE

PACKAGES.edtx = $(PACKAGES:%=%.edtx)
PACKAGES.ins = $(PACKAGES:%=%.ins)

makefiles = Makefile.package Makefile.runtimes Makefile.advice Makefile.collargs 

codedoc-source = memoize-code.tex \
                 memoize-code.sty memoize-doc-common.sty

manual-source = memoize-doc.tex \
                memoize-doc.sty memoize-doc-common.sty yadoc.sty \
		memoize-doc.mst

PDF = memoize-doc.pdf memoize-code.pdf

codedoc-source := $(codedoc-source:%=doc/%)
manual-source := $(manual-source:%=doc/%)
pdf := $(PDF:%=doc/%)
DOC = $(sort $(codedoc-source) $(manual-source)) $(pdf) $(man-src)

examples-src := Makefile ins.begin ins.mid ins.end
examples-src := $(examples-src:%=doc/examples/%)
#examples-src += $(shell git ls-files | grep ^doc/examples/.*dtx$)
examples-src += $(shell find doc/examples -name '*.dtx')

# doc/attachments.lst is produced by compiling memoize.tex (without memoization).
# doc-examples will hold soft links to the relevant generated example files.
doc-examples := $(shell sed 's/^.* \(.*\) ##.*$$/\1/' doc/attachments.lst)
doc-examples := $(doc-examples:%=doc/examples/%)

ctan/$(PACKAGE).zip:
	$(TDS-BEGIN)
#	Check for duplicate filenames:
	echo $(doc-examples) | tr ' ' '\n' | uniq -d | ifne false
	cd doc && zip ../$(TDS-DOC-DIR)/examples-src.zip $(examples-src:doc/%=%)
#	For each line ($1 $2) in attachments.lst, link $1 to $2 ...
	cd doc/examples && sed 's!^examples/!ln -sfr !' ../attachments.lst | sh
#	... and zip those links.
	cd doc && zip -r ../$(TDS-DOC-DIR)/examples.zip $(doc-examples:doc/%=%)
	$(TDS-END)
	$(CTAN-BEGIN)
	ln -sr $(TDS-DOC-DIR)/examples-src.zip $(CTAN-DIR)/doc
	ln -sr $(TDS-DOC-DIR)/examples.zip $(CTAN-DIR)/doc
	$(CTAN-END)

%.py.dtx: %.py
	edtx2dtx -s -c '#' -B '^__version__' -E '^# Local Variables:' $< \
		| sed -e '/^% Local Variables:/Q' > $@

%.pl.dtx: %.pl
	edtx2dtx -s -c '#' -B '^my \$$PROG' -E '^# Local Variables:' $< \
		| sed -e '/^% Local Variables:/Q' > $@

doc/memoize-code.pdf: $(codedoc-source) \
                      $(PACKAGES.edtx) $(PACKAGES.ins) $(SCRIPTS:%=%.dtx)

doc/memoize.pdf: $(manual-source) $(examples-src) $(PACKAGES.edtx)

%.pdf: %.tex
	latexmk -cd -lualatex -bibtex- $(LATEXMK) $<  && touch $@



# Maintanence

test.tex = $(wildcard test*.tex)

.PHONY: all runtime force clean versions-show

.PRECIOUS: %.1

clean: # clean this directory
	memoize-clean.py -a $(test.tex:%.tex=-p %.) $(test.tex:%.tex=-p %.memo.dir/)
	latexmk -C -f $(test.tex) _region_

version:
	$(MAKE) -f Makefile.collargs version
	$(MAKE) -f Makefile.advice version
	$(call EDIT-VERSION-LATEX,memoize.edtx,memoize)
	$(call EDIT-VERSION-LATEX,memoize.edtx,nomemoize)
	$(call EDIT-VERSION-LATEX,memoize.edtx,memoizable)
	$(call EDIT-VERSION-CONTEXT,memoize.edtx)
	$(call EDIT-VERSION-PLAIN,memoize.edtx,memoize)
	$(call EDIT-VERSION-PLAIN,memoize.edtx,nomemoize)
	$(call EDIT-VERSION-PLAIN,memoize.edtx,memoizable)
	$(call EDIT-VERSION-PERL,memoize-extract.pl)
	$(call EDIT-VERSION-PERL,memoize-clean.pl)
	$(call EDIT-VERSION-PYTHON,memoize-extract.py)
	$(call EDIT-VERSION-PYTHON,memoize-clean.py)
	$(call EDIT-VERSION-MAN,doc/memoize-extract.1.md)
	$(call EDIT-VERSION-MAN,doc/memoize-clean.1.md)
	$(call EDIT-DATE-CHANGELOG,CHANGELOG.md)
define COLOR_VERSION
grep -E --color '[0-9]{4}[/-][0-9]{1,2}[/-][0-9]{1,2}|v?[0-9]\.[0-9]\.[0-9]([-a-z]*)|(January|February|March|April|May|June|July|August|September|October|November|December) [0-9]+, [0-9]{4}'
endef

versions-show:
	@grep -E '%<latex>\\ProvidesPackage|^%<context>%D\s*(version|date)=' $(PACKAGES.edtx) | ${COLOR_VERSION}
	@grep __version__ *.py | ${COLOR_VERSION}
	@grep VERSION *.pl | ${COLOR_VERSION}
	@grep -E '^(footer|date):' doc/memoize-*.md | ${COLOR_VERSION}
	@${COLOR_VERSION} CHANGELOG.md doc/CHANGELOG.advice.md doc/CHANGELOG.collargs.md

include Makefile.package
include Makefile.runtimes

VERSION-MAN = of Memoize v$(VERSION)

.PHONY: all-runtimes link-all-runtimes unlink-all-runtimes test

all-runtimes: runtimes
	$(MAKE) -f Makefile.advice runtimes
	$(MAKE) -f Makefile.collargs runtimes

link-all-runtimes: link-runtimes
	$(MAKE) -f Makefile.advice link-runtimes
	$(MAKE) -f Makefile.collargs link-runtimes

unlink-all-runtimes: unlink-runtimes
	$(MAKE) -f Makefile.advice unlink-runtimes
	$(MAKE) -f Makefile.collargs unlink-runtimes

test:
	cd testing && ./MakeTests.py