forked from swisstopo/lg-geology-data-model
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
163 lines (116 loc) · 4.51 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
# Makefile
#
# Help target
help:
@echo "Usage:"
@echo " make docs - Generate all files (PDF, DOCX, HTML and ODT for all languages)"
@echo " make pdf - Generate only PDF files for all languages"
@echo " make docx - Generate only PDF 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 clean - Remove all generated files"
@echo " make help - Display this help message"
INPUT_DIR = input
OUTPUT_DIR = output
SOURCES = $(wildcard $(INPUT_DIR)/datamodel_*.md)
FORMATS = pdf docx odt html
CSS = datamodel.css
# Extract base names and languages from sources
BASENAMES = $(basename $(notdir $(SOURCES)))
LANGUAGES = $(patsubst datamodel_%, %, $(BASENAMES))
PANDOC=/usr/bin/pandoc
RM=/bin/rm
CP=/usr/bin/cp
# 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)/metadata_de.yaml -V lang=de
OPTIONS_fr = --metadata lang=fr --metadata-file=$(INPUT_DIR)/metadata_fr.yaml -V lang=fr
# format specific options
PANDOC_HTML_OPTIONS=--to html5 --toc --css $(CSS)
PANDOC_PDF_OPTIONS=--pdf-engine=xelatex
PANDOC_DOCX_OPTIONS=
PANDOC_ODT_OPTIONS=
# Define target files
TARGETS = $(foreach lang, $(LANGUAGES), \
$(foreach format, $(FORMATS), \
$(OUTPUT_DIR)/datamodel_$(lang).$(format)))
# Define PDF target files
PDF_TARGETS = $(foreach lang, $(LANGUAGES), \
$(OUTPUT_DIR)/datamodel_$(lang).pdf)
# Define Microsoft .docx target files
DOCX_TARGETS = $(foreach lang, $(LANGUAGES), \
$(OUTPUT_DIR)/datamodel_$(lang).docx)
# Define LibreOffice .odt target files
ODT_TARGETS = $(foreach lang, $(LANGUAGES), \
$(OUTPUT_DIR)/datamodel_$(lang).odt)
# Define HTML target files
HTML_TARGETS = $(foreach lang, $(LANGUAGES), \
$(OUTPUT_DIR)/datamodel_$(lang).html)
# Define language-specific target files
DE_TARGETS = $(foreach format, $(FORMATS), $(OUTPUT_DIR)/datamodel_de.$(format))
FR_TARGETS = $(foreach format, $(FORMATS), $(OUTPUT_DIR)/datamodel_fr.$(format))
# $(info $$TARGETS is [${TARGETS}])
# Default target
docs: babel assets $(TARGETS)
# Target to generate only PDF files
pdf: assets $(PDF_TARGETS)
# Target to generate only docx files
docx: assets $(DOCX_TARGETS)
# Target to generate only docx files
odt: assets $(ODT_TARGETS)
# Target to generate only html files
html: assets $(HTML_TARGETS)
assets:
$(CP) assets/$(CSS) $(OUTPUT_DIR)
$(CP) assets/geocover.png $(OUTPUT_DIR)
$(CP) assets/geocover.png .
de: assets $(DE_TARGETS)
fr: assets $(FR_TARGETS)
all: markdown diagram docs
# Phony targets
.PHONY: all clean de fr help assets
babel:
pybabel compile --domain=app --directory=locale --use-fuzzy
pybabel compile --domain=datamodel --directory=locale --use-fuzzy
markdown: babel
python datamodel.py --lang=de
python datamodel.py --lang=fr
diagram:
python create_gv.py
# Pattern rule for conversion
$(OUTPUT_DIR)/datamodel_%.pdf: $(INPUT_DIR)/datamodel_%.md
$(PANDOC) $(PANDOC_OPTIONS) $(OPTIONS_$*) $(PANDOC_PDF_OPTIONS) -o $@ $<
$(OUTPUT_DIR)/datamodel_%.docx: $(INPUT_DIR)/datamodel_%.md
$(PANDOC) $(PANDOC_OPTIONS) $(OPTIONS_$*) $(PANDOC_DOCX_OPTIONS) -o $@ $<
$(OUTPUT_DIR)/datamodel_%.html: $(INPUT_DIR)/datamodel_%.md
$(PANDOC) $(PANDOC_OPTIONS) $(OPTIONS_$*) $(PANDOC_HTML_OPTIONS) -o $@ $<
$(OUTPUT_DIR)/datamodel_%.odt: $(INPUT_DIR)/datamodel_%.md
$(PANDOC) $(PANDOC_OPTIONS) $(OPTIONS_$*) $(PANDOC_ODT_OPTIONS) -o $@ $<
# Clean generated files
clean:
rm -f $(TARGETS)
cleanall: clean
find . -name '*.mo' -exec rm -f {} \;
rm -f $(OUTPUT_DIR)/*.css
# Ensure the output directory exists
$(OUTPUT_DIR):
mkdir -p $(OUTPUT_DIR)
# Phony targets
.PHONY: all clean babel
# Ensure the output directory is created before generating files
$(TARGETS): | $(OUTPUT_DIR)
$(PDF_TARGETS): | $(OUTPUT_DIR)
$(DE_TARGETS): | $(OUTPUT_DIR)
$(FR_TARGETS): | $(OUTPUT_DIR)