-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
178 lines (137 loc) · 5.77 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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
LANGUAGES = de fr
FORMATS = pdf odt docx html
INPUT_DIR = inputs
OUTPUT_DIR = outputs
LOCALE_DIR = locale
PANDOC=/usr/bin/pandoc
RM=/bin/rm
CP=/usr/bin/cp
CSS = datamodel.css
# Define targets for each language and format
OUTPUTS = $(foreach lang,$(LANGUAGES),$(foreach fmt,$(FORMATS),$(OUTPUT_DIR)/$(lang)/datamodel.$(fmt)))
# Define the list of required .mo files for each language
MO_FILES = $(foreach lang,$(LANGUAGES),$(LOCALE_DIR)/$(lang)/LC_MESSAGES/datamodel.mo $(LOCALE_DIR)/$(lang)/LC_MESSAGES/app.mo)
INPUTS = $(foreach lang,$(LANGUAGES),$(foreach fmt,$(FORMATS),$(INPUT_DIR)/$(lang)/datamodel.md))
# Options for all doc format
PANDOC_OPTIONS=--standalone \
-V papersize:a4 \
--number-sections \
--shift-heading-level-by=-1 \
--variable mainfont="DejaVu Sans" \
-V colorlinks=true \
-V linkcolor=teal \
-V urlcolor=teal \
-V toccolor=gray
# Define language-specific options
OPTIONS_de = --metadata lang=de --metadata-file=$(INPUT_DIR)/de/metadata.yaml -V lang=de
OPTIONS_fr = --metadata lang=fr --metadata-file=$(INPUT_DIR)/fr/metadata.yaml -V lang=fr
# format specific options
PANDOC_HTML_OPTIONS=--to html5 --toc-depth=2 --toc --css $(CSS)
PANDOC_PDF_OPTIONS=--pdf-engine=xelatex
PANDOC_DOCX_OPTIONS=
PANDOC_ODT_OPTIONS=
# Help target
help:
@echo "Usage:"
@echo " make all - Generate all files (PDF, DOCX, HTML and ODT for all languages)"
@echo " make pdfs - Generate only PDF files for all languages"
@echo " make docxs - Generate only DOCX files for all languages"
@echo " make odts - Generate only ODT files for all languages"
@echo " make htmls - Generate only HTML files for all languages"
@echo " make mds - Generate only Markdown files for all languages"
@echo " make de - Generate all files (PDF, DOCX, HTML and ODT) for German"
@echo " make fr - Generate all files (PDF, DOCX, HTML and ODT) for French"
@echo " make babel - Generate .mo translation files"
@echo " make markdown - Generate markdown files"
@echo " make diagram - Generate ER diagram"
@echo " make validate - Validate the datamodel against the schema"
@echo " make clean - Remove all generated files"
@echo " make help - Display this help message"
.PHONY: assets
assets:
mkdir -p $(OUTPUT_DIR)/de
mkdir -p $(OUTPUT_DIR)/fr
$(CP) assets/$(CSS) $(OUTPUT_DIR)/de
$(CP) assets/$(CSS) $(OUTPUT_DIR)/fr
$(CP) assets/geocover.png $(OUTPUT_DIR)/de
$(CP) assets/geocover.png $(OUTPUT_DIR)/fr
$(CP) assets/geocover.png .
babel: $(MO_FILES)
# Rule to compile .mo files if missing
$(LOCALE_DIR)/%/LC_MESSAGES/datamodel.mo: $(LOCALE_DIR)/%/LC_MESSAGES/datamodel.po
mkdir -p $(@D)
pybabel compile --domain=datamodel --directory=locale --use-fuzzy
$(LOCALE_DIR)/%/LC_MESSAGES/app.mo: $(LOCALE_DIR)/%/LC_MESSAGES/app.po
mkdir -p $(@D)
pybabel compile --domain=app --directory=locale --use-fuzzy
markdown: $(MO_FILES) $(INPUTS)
diagram: assets
python create_gv.py
$(INPUT_DIR)/datamodel.xlsx:
datamodel export datamodel.yaml -o $@
.PHONY: all
all: $(MO_FILES) $(INPUTS) $(OUTPUTS) diagram $(INPUT_DIR)/datamodel.xlsx
# Define individual rules for each format and language
define build_rule
$(INPUT_DIR)/$(1)/metadata.yaml: assets $(MO_FILES)
mkdir -p $$(@D)
datamodel generate --lang=$(1) -o $(INPUT_DIR) datamodel.yaml
$(INPUT_DIR)/$(1)/datamodel.md: assets $(MO_FILES)
mkdir -p $$(@D)
datamodel generate --lang=$(1) -o $(INPUT_DIR) datamodel.yaml
$(OUTPUT_DIR)/$(1)/datamodel.pdf: $(INPUT_DIR)/$(1)/datamodel.md $(INPUT_DIR)/$(1)/metadata.yaml
mkdir -p $$(@D)
$(PANDOC) $(PANDOC_OPTIONS) $(OPTIONS_$1) $(PANDOC_PDF_OPTIONS) -o $$@ $$<
$(OUTPUT_DIR)/$(1)/datamodel.docx: $(INPUT_DIR)/$(1)/datamodel.md $(INPUT_DIR)/$(1)/metadata.yaml
mkdir -p $$(@D)
$(PANDOC) $(PANDOC_OPTIONS) $(OPTIONS_$1) $(PANDOC_DOCX_OPTIONS) -o $$@ $$<
$(OUTPUT_DIR)/$(1)/datamodel.odt: $(INPUT_DIR)/$(1)/datamodel.md $(INPUT_DIR)/$(1)/metadata.yaml
mkdir -p $$(@D)
$(PANDOC) $(PANDOC_OPTIONS) $(OPTIONS_$1) $(PANDOC_ODT_OPTIONS) -o $$@ $$<
$(OUTPUT_DIR)/$(1)/datamodel.html: $(INPUT_DIR)/$(1)/datamodel.md $(INPUT_DIR)/$(1)/metadata.yaml
mkdir -p $$(@D)
$(PANDOC) $(PANDOC_OPTIONS) $(OPTIONS_$1) $(PANDOC_HTML_OPTIONS) -o $$@ $$<
endef
# Apply the build_rule for each language
$(foreach lang,$(LANGUAGES),$(eval $(call build_rule,$(lang))))
# Targets for building specific formats
.PHONY: pdfs odts htmls docxs mds
pdfs: $(foreach lang,$(LANGUAGES),$(OUTPUT_DIR)/$(lang)/datamodel.pdf)
odts: $(foreach lang,$(LANGUAGES),$(OUTPUT_DIR)/$(lang)/datamodel.odt)
htmls: $(foreach lang,$(LANGUAGES),$(OUTPUT_DIR)/$(lang)/datamodel.html)
docxs: $(foreach lang,$(LANGUAGES),$(OUTPUT_DIR)/$(lang)/datamodel.docx)
mds: $(foreach lang,$(LANGUAGES),$(INPUT_DIR)/$(lang)/datamodel.md)
# Targets for building specific languages
.PHONY: de fr it
de: $(foreach fmt,$(FORMATS),$(OUTPUT_DIR)/de/datamodel.$(fmt))
fr: $(foreach fmt,$(FORMATS),$(OUTPUT_DIR)/fr/datamodel.$(fmt))
.PHONY: validate
validate:
datamodel validate datamodel.yaml
# Clean up
# Clean up all generated files
.PHONY: clean cleanall
cleanall: clean cleaninputs cleanpdf cleanodt cleanhtml cleandocx
clean:
rm -rf $(OUTPUT_DIR)/*
find $(LOCALE_DIR) -name "*.mo" -delete
# Clean up only generated PDF files
.PHONY: cleanpdf
cleanpdf:
find $(OUTPUT_DIR) -name "*.pdf" -delete
# Clean up only generated ODT files
.PHONY: cleanodt
cleanodt:
find $(OUTPUT_DIR) -name "*.odt" -delete
# Clean up only generated DOCX files
.PHONY: cleandocx
cleandocx:
find $(OUTPUT_DIR) -name "*.docx" -delete
# Clean up only generated HTML, CSS, and image files
.PHONY: cleanhtml
cleanhtml:
find $(OUTPUT_DIR) -type f \( -name "*.html" -o -name "*.css" -o -name "*.png" -o -name "*.jpg" -o -name "*.jpeg" \) -delete
.PHONY: cleaninputs
cleaninputs:
rm -rf $(INPUT_DIR)/de/*
rm -rf $(INPUT_DIR)/fr/*