-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
112 lines (77 loc) · 2.92 KB
/
Makefile
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
# Makefile: the magical sauce that powers this website
# Read about GNU make if you want to figure out how this works exactly
.PHONY: index clean all
OUTPUT := ./out
SOURCE := ./src
GENERATED := ./gen
# $(PAGES) is only used for the 'all' target for now
PAGES := index politburo officers join constitution tutoring computing-resources events hackathon industry readme
# Unused for now
SOURCE_MD := $(patsubst %,$(SOURCE)/%.md,$(PAGES))
OUTPUT_HTML := $(patsubst %.md,%.html,$(subst $(SOURCE),$(OUTPUT),$(SOURCE_MD)))
PANDOC = pandoc -s -H $(SOURCE)/header.html $(SOURCE)/navbar.md $< $(SOURCE)/footer.md -o $@
COMMON := $(SOURCE)/header.html $(SOURCE)/footer.md $(SOURCE)/navbar.md
COPYDIRS := img css
all: index.html $(OUTPUT_HTML) $(foreach c,$(COPYDIRS),$(OUTPUT)/$(c)) \
$(GENERATED)/officer_usernames.txt $(GENERATED)/officers.yml
# Generate these directories if they dont exist since make clean removes them
$(OUTPUT) $(GENERATED):
mkdir -p $@
define COPYDIR
$(OUTPUT)/$(1): $(SOURCE)/$(1)
mkdir -p $(OUTPUT)
ln -snf $$(realpath $$<) $$@
@# Use -n to avoid putting symlink into symlinked directory
@sync
endef
$(foreach copydir,$(COPYDIRS),$(eval $(call COPYDIR,$(copydir))))
##### Targets for website files ###############################################
$(GENERATED)/officer_usernames.txt: | $(GENERATED)
getent group officers | awk '{ split($$1,a,":"); split(a[4],b,","); {for(i in b) print(b[i])}}' > $@
$(GENERATED)/officers.yml: $(GENERATED)/officer_usernames.txt
echo "---" > $@
echo "officers:" >> $@
cat $< | sort | xargs getent passwd | awk '{ split($$_,a,":"); \
split(a[5],b,","); \
split(b[1],c," "); \
print("- first: "c[1]); \
print(" last: "c[2]); \
print(" username: "a[1])}' \
>> $@ || rm $@
echo "---" >> $@
$(GENERATED)/officer_groups.txt: $(GENERATED)/officer_usernames.txt
cat $< | xargs id -nG > $@
define SIMPLE_PANDOC
$(1): $(2) $(COMMON)
$(PANDOC)
endef
index.html: README.md $(COMMON)
$(pandoc)
$(OUTPUT)/readme.html: README.md $(COMMON)
$(PANDOC)
# TODO: join all the simple page targets using a define block.
$(OUTPUT)/index.html: $(SOURCE)/index.md $(COMMON)
$(PANDOC)
$(OUTPUT)/politburo.html: $(SOURCE)/politburo.md $(COMMON)
$(PANDOC)
$(GENERATED)/officers.md: $(SOURCE)/officers.md $(GENERATED)/officers.yml
pandoc --template $< $(GENERATED)/officers.yml -o $@
$(OUTPUT)/officers.html: $(GENERATED)/officers.md $(COMMON)
$(PANDOC)
$(OUTPUT)/join.html: $(SOURCE)/join.md $(COMMON)
$(PANDOC)
$(OUTPUT)/constitution.html: $(SOURCE)/constitution.md $(COMMON)
$(PANDOC)
$(OUTPUT)/tutoring.html: $(SOURCE)/tutoring.md $(COMMON)
$(PANDOC)
$(OUTPUT)/computing-resources.html: $(SOURCE)/computing-resources.md $(COMMON)
$(PANDOC)
$(OUTPUT)/events.html: $(SOURCE)/events.md $(COMMON)
$(PANDOC)
$(OUTPUT)/hackathon.html: $(SOURCE)/hackathon.md $(COMMON)
$(PANDOC)
$(OUTPUT)/industry.html: $(SOURCE)/industry.md $(COMMON)
$(PANDOC)
clean:
rm -rf $(OUTPUT) $(GENERATED) index.html
@sync