Cleaning up Makefile
Getty Ritter
9 years ago
1 | # basic pages that will always exist: | |
2 | ||
3 | # Maybe we want to override this? | |
4 | OUTDIR=output | |
5 | DATADIR=/home/getty/projects/lib-data | |
6 | ||
1 | # The set of basic pages we want to generate | |
7 | 2 | pages=$(OUTDIR)/quotes/index.html $(OUTDIR)/quips/index.html \ |
8 | 3 | $(OUTDIR)/links/index.html $(OUTDIR)/category/index.html \ |
9 | 4 | $(OUTDIR)/index.html |
10 | 5 | |
6 | # The static files we just need to copy | |
11 | 7 | static_tgt=$(OUTDIR)/static/jquery.js \ |
12 | 8 | $(OUTDIR)/static/main.css \ |
13 | 9 | $(OUTDIR)/static/quotes.js |
10 | ||
11 | # (We should generate this list another way, but it's unlikely to | |
12 | # change with any regularity) | |
13 | cats_src=comics fascicles poems stories | |
14 | 14 | |
15 | 15 | # We find all the stuff we want to generate... |
16 | 16 | quotes_src=$(wildcard $(DATADIR)/quotes/*) |
17 | 17 | quips_src=$(wildcard $(DATADIR)/quips/*) |
18 | 18 | links_src=$(wildcard $(DATADIR)/links/*) |
19 | 19 | works_src=$(notdir $(wildcard $(DATADIR)/works/*/*)) |
20 | cats_src=comics fascicles poems stories | |
21 | 20 | |
22 | 21 | # and figure out what the $(OUTDIR) file will be called by matching |
23 | 22 | # on the input file. |
26 | 25 | links_tgt=$(links_src:$(DATADIR)/links/%=$(OUTDIR)/links/%/index.html) |
27 | 26 | cats_tgt=$(cats_src:%=$(OUTDIR)/category/%/index.html) |
28 | 27 | |
29 | # I'm doing this manually for now. | |
30 | ||
31 | # this is kind of gross---the problem is that I do want to store | |
32 | # 'works' (other writing) inside directories that correspond to their | |
33 | # kind, but don't want that in the output, so I can't straightforwardly | |
34 | # use patsubst like above: I'd have to write something like | |
35 | # works_src:$(DATADIR)/works/*/%=$(OUTDIR)/%/index.html | |
36 | # which doesn't work. I could also filter out all the known kinds of | |
37 | # works through other wildcard magic. instead, I just shell out to sed. | |
38 | 28 | works_tgt=$(works_src:%=$(OUTDIR)/%/index.html) |
39 | 29 | |
30 | # ------------------------------------------------------------------------------ | |
40 | 31 | |
41 | 32 | all: $(pages) $(quotes_tgt) $(quips_tgt) $(links_tgt) $(works_tgt) \ |
42 | 33 | $(cats_tgt) $(static_tgt) |
34 | ||
35 | # ------------------------------------------------------------------------------ | |
43 | 36 | |
44 | 37 | # A lot of these are boringly similar: probably should come up with a way of abstracting |
45 | 38 | # this common pattern, but, y'know, Make... |
56 | 49 | mkdir -p `dirname $@` |
57 | 50 | bin/link.sh $(DATADIR) all >$@ |
58 | 51 | |
52 | # ------------------------------------------------------------------------------ | |
53 | ||
59 | 54 | $(OUTDIR)/quotes/%/index.html: $(DATADIR)/quotes/% templates/quote.mustache templates/main.mustache |
60 | 55 | mkdir -p `dirname $@` |
61 | 56 | bin/quote.sh $(DATADIR) $< >$@ |
67 | 62 | $(OUTDIR)/links/%/index.html: $(DATADIR)/links/% templates/link.mustache templates/main.mustache |
68 | 63 | mkdir -p `dirname $@` |
69 | 64 | bin/link.sh $(DATADIR) $< >$@ |
65 | ||
66 | # ------------------------------------------------------------------------------ | |
70 | 67 | |
71 | 68 | $(OUTDIR)/%/index.html: $(DATADIR)/works/*/% templates/textpage.mustache templates/main.mustache |
72 | 69 | mkdir -p `dirname $@` |
80 | 77 | mkdir -p `dirname $@` |
81 | 78 | bin/all-categories.sh $(DATADIR) >$@ |
82 | 79 | |
80 | # ------------------------------------------------------------------------------ | |
81 | ||
83 | 82 | $(OUTDIR)/index.html: $(OUTDIR)/index/index.html |
84 | 83 | cp $< $@ |
85 | 84 |