-
Notifications
You must be signed in to change notification settings - Fork 3
/
CONST_Makefile
227 lines (177 loc) · 6.78 KB
/
CONST_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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
VENV_BIN ?= .build/venv/Scripts
PYTHON_VERSION = $(shell $(VENV_BIN)/python -c "import sys; print('%i.%i' % (sys.version_info.major, sys.version_info.minor))" 2> /dev/null)
PACKAGE = historic_cadastre
PIP_CMD ?= $(VENV_BIN)/pip
PIP_INSTALL_ARGS += install
PIP_VERSION ?= pip>=9
SETUPTOOL_VERSION ?= setuptools>=36
OUTPUT_DIR = $(PACKAGE)/static/build
# Make rules
# Requirements
CONST_REQUIREMENT ?= CONST_requirements.txt
EGGS_DEPENDENCIES += .build/venv.timestamp-noclean setup.py CONST_versions.txt $(CONST_REQUIREMENT)
REQUIREMENTS += -r $(CONST_REQUIREMENT)
TEMPLATES_FILES = $(shell find $(PACKAGE)/templates -type f -print)
# Templates
TEMPLATE_EXCLUDE += .build node_modules print/templates \
CONST_alembic/main/script.py.mako \
CONST_alembic/static/script.py.mako \
$(PACKAGE)/static/lib
FIND_OPTS = $(foreach ELEM, $(TEMPLATE_EXCLUDE),-path ./$(ELEM) -prune -o) -type f
TEMPLATE_FILES = $(shell find $(FIND_OPTS) -name "*.in" -print)
MAKO_FILES = $(shell find $(FIND_OPTS) -name "*.mako" -print)
JINJA_FILES = $(shell find $(FIND_OPTS) -name "*.jinja" -print)
VARS_FILES += CONST_vars.yaml $(VARS_FILE)
VARS_DEPENDS += $(VARS_FILES)
CONFIG_VARS += \
sqlalchemy.url \
authtkt \
jsbuild \
print_templates \
type_configuration \
image_server_graphique \
image_server_mutation \
image_server_servitudes \
image_server_cadastre_graphique \
print_url
JSBUILD_MAIN_FILES = $(shell find $(PACKAGE)/static/lib $(PACKAGE)/static/js -name "*.js" -print 2> /dev/null)
JSBUILD_MAIN_CONFIG = jsbuild/app.cfg
JSBUILD_MAIN_OUTPUT_FILES ?= app.js lang-fr.js
JSBUILD_MAIN_OUTPUT_FILES := $(addprefix $(OUTPUT_DIR)/, $(JSBUILD_MAIN_OUTPUT_FILES))
TOMCAT_START_COMMAND ?= net START Tomcat7
TOMCAT_STOP_COMMAND ?= net STOP Tomcat7
PRINT_TMP = tmp
PRINT_BASE_DIR ?= print
PRINT_WAR ?= print-$(INSTANCE_ID).war
PRINT_OUTPUT ?= D:/Applications/ApacheTomcat/webapps
PRINT_OUTPUT_WAR = $(PRINT_OUTPUT)/$(PRINT_WAR)
PRINT_BASE_WAR ?= print-servlet-2.0-SNAPSHOT-IMG-MAGICK.war
PRINT_INPUT_LS += config.yaml WEB-INF/classes/log4j.properties
PRINT_INPUT_FIND += *.tif *.bmp *.jpg *.jpeg *.gif *.png *.pdf *.xml
PRINT_INPUT += $(shell cd $(PRINT_BASE_DIR) && ls -1 $(PRINT_INPUT_LS) 2> /dev/null)
PRINT_INPUT += $(foreach INPUT, $(PRINT_INPUT_FIND), $(shell cd $(PRINT_BASE_DIR) && find -name '$(INPUT)' -type f))
PRINT_REQUIREMENT += $(addprefix $(PRINT_BASE_DIR)/, $(PRINT_INPUT))
PRINT_REQUIREMENT += $(PRINT_BASE_DIR)/$(PRINT_BASE_WAR)
APACHE_ENTRY_POINT ?= /$(INSTANCE_ID)/
ENVIRONMENT_VARS += INSTANCE_ID=${INSTANCE_ID} \
APACHE_ENTRY_POINT=$(APACHE_ENTRY_POINT) \
DEVELOPMENT=${DEVELOPMENT} \
PACKAGE=${PACKAGE}
C2C_TEMPLATE_CMD = $(ENVIRONMENT_VARS) $(VENV_BIN)/c2c-template --vars $(VARS_FILE)
MAKE_FILES = $(shell ls -1 *.mk) CONST_Makefile
PY_FILES = $(shell find $(PACKAGE) -type f -name '*.py' -print)
DEFAULT_BUILD_RULES ?= .build/requirements.timestamp build-javascript build-server
DEFAULT_BUILD_RULES += print
BUILD_RULES ?= $(PRE_RULES) $(filter-out $(DISABLE_BUILD_RULES),$(DEFAULT_BUILD_RULES)) $(POST_RULES)
# Disabling Make built-in rules to speed up execution time
.SUFFIXES:
.PHONY: help
help:
@echo "Usage: make <target>"
@echo
@echo "Main targets:"
@echo
@echo "- build Build and configure the project"
@echo "- checks Perform a number of checks on the code"
@echo "- serve Run the development server (Pserve)"
@echo "- clean Remove generated files"
@echo "- cleanall Remove all the build artefacts"
ifdef UTILITY_HELP
@echo $(UTILITY_HELP)
endif
@echo
@echo "Secondary targets:"
@echo
@echo "- build-javascript Build the javascript"
@echo "- template-clean Clean the template file"
@echo "- template-generate Generate the template file"
ifdef SECONDARY_HELP
@echo $(SECONDARY_HELP)
endif
@echo
.PHONY: build
build: $(BUILD_RULES)
.PHONY: checks
checks: flake8 $(CLIENT_CHECK_RULE) $(WEB_RULE)
.PHONY: clean
clean: template-clean
rm -f .build/*.timestamp
rm -f $(APACHE_CONF_DIR)/$(INSTANCE_ID).conf
.PHONY: cleanall
cleanall: clean
rm -rf .build
.PHONY: flake8
flake8: $(VENV_BIN)/flake8
$(VENV_BIN)/flake8 $(PACKAGE)
.PHONY: build-server
build-server: template-generate
.PHONY: serve
serve: build development.ini
$(VENV_BIN)/pserve --reload --monitor-restart development.ini
.PHONY: build-javascript
build-javascript: $(JSBUILD_MAIN_OUTPUT_FILES)
# echo $(JSBUILD_MAIN_FILES)
# Print
.PHONY: print
print: $(PRINT_OUTPUT)/$(PRINT_WAR)
$(PRINT_OUTPUT)/$(PRINT_WAR): $(PRINT_REQUIREMENT)
mkdir -p $(PRINT_BASE_DIR)/$(PRINT_TMP)
cp $(PRINT_BASE_DIR)/$(PRINT_BASE_WAR) $(PRINT_BASE_DIR)/$(PRINT_TMP)/$(PRINT_WAR)
cd $(PRINT_BASE_DIR) && jar -uf $(PRINT_TMP)/$(PRINT_WAR) $(PRINT_INPUT)
ifneq ($(TOMCAT_STOP_COMMAND),)
$(TOMCAT_STOP_COMMAND)
endif
$(TOMCAT_OUTPUT_CMD_PREFIX) rm -f $(PRINT_OUTPUT)/$(PRINT_WAR)
$(TOMCAT_OUTPUT_CMD_PREFIX) rm -rf $(PRINT_OUTPUT)/$(PRINT_WAR:.war=)
mv $(PRINT_BASE_DIR)/$(PRINT_TMP)/$(PRINT_WAR) $(PRINT_OUTPUT)
cd $(PRINT_BASE_DIR) && rm -fd $(PRINT_TMP)
ifneq ($(TOMCAT_START_COMMAND),)
$(TOMCAT_START_COMMAND)
endif
# Templates
.PHONY: template-clean
template-clean:
rm -f $(TEMPLATE_FILES:.in=)
rm -f $(MAKO_FILES:.mako=)
rm -f $(JINJA_FILES:.jinja=)
rm -f .build/config.yaml
.PHONY: template-generate
template-generate: $(TEMPLATE_FILES:.in=) $(MAKO_FILES:.mako=) $(JINJA_FILES:.jinja=) .build/config.yaml
$(TEMPLATE_FILES:.in=) $(MAKO_FILES:.mako=) $(JINJA_FILES:.jinja=): $(VENV_BIN)/c2c-template $(VARS_DEPENDS)
%: %.in $(INSTANCE_ID_MARKER)
ifeq ($(origin VARS_FILE), undefined)
@echo "Error: the variable VARS_FILE is required."
exit 1
endif
$(C2C_TEMPLATE_CMD) --engine template --files $<
%: %.mako $(INSTANCE_ID_MARKER)
ifeq ($(origin VARS_FILE), undefined)
@echo "Error: the variable VARS_FILE is required."
exit 1
endif
$(C2C_TEMPLATE_CMD) --engine mako --files $<
%: %.jinja $(INSTANCE_ID_MARKER)
ifeq ($(origin VARS_FILE), undefined)
@echo "Error: the variable VARS_FILE is required."
exit 1
endif
$(C2C_TEMPLATE_CMD) --engine jinja --files $<
#$(VENV_BIN)/c2c-template: .build/dev-requirements.timestamp
.build/config.yaml: $(INSTANCE_ID_MARKER) $(VENV_BIN)/c2c-template $(VARS_DEPENDS) $(MAKE_FILES)
$(C2C_TEMPLATE_CMD) --get-config .build/config.yaml $(CONFIG_VARS)
$(VENV_BIN)/gjslint: .build/dev-requirements.timestamp
$(VENV_BIN)/flake8: .build/dev-requirements.timestamp
# Venv
.build/venv.timestamp-noclean:
mkdir -p $(dir $@)
virtualenv --setuptools --no-site-packages .build/venv
$(PIP_CMD) install \
'$(PIP_VERSION)' '$(SETUPTOOL_VERSION)'
touch $@
.build/requirements.timestamp: $(EGGS_DEPENDENCIES)
$(PIP_CMD) $(PIP_INSTALL_ARGS) $(REQUIREMENTS) $(PIP_REDIRECT)
touch $@
#$(VENV_BIN)/jsbuild: .build/dev-requirements.timestamp
$(JSBUILD_MAIN_OUTPUT_FILES): $(JSBUILD_MAIN_FILES) $(JSBUILD_MAIN_CONFIG) $(VENV_BIN)/jsbuild
mkdir -p $(dir $@)
$(VENV_BIN)/jsbuild $(JSBUILD_MAIN_CONFIG) $(JSBUILD_ARGS) -j $(notdir $@) -o $(OUTPUT_DIR)