forked from Seagate/cortx-hare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
664 lines (582 loc) · 24.3 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
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
# Copyright (c) 2020 Seagate Technology LLC and/or its Affiliates
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# For any questions about this software or licensing,
# please email [email protected] or [email protected].
.PHONY: default
default: build
.PHONY: help
help:
@echo 'General targets:'
@echo ' build - build binary components (hax)'
@echo ' test - run tests'
@echo ' clean - remove build artefacts'
@echo ' distclean - perform clean and remove Python virtual env'
@echo ' directory with all installed pip modules'
@echo ' install - system-wide installation, respects DESTDIR'
@echo ' devinstall - local installation in the development mode,'
@echo ' respects DESTDIR'
@echo ' uninstall - uninstall all components, respects DESTDIR'
@echo
@echo 'Code linters:'
@echo ' check - run `flake8` and `mypy` linters for Python code'
@echo ' flake8 - run `flake8` for Python code'
@echo ' mypy - run `mypy` for Python code'
@echo
@echo 'Distribution targets:'
@echo ' rpm - build release rpm package'
@echo ' dist - generate source code distribution archive'
@echo
@echo 'Docker:'
@echo ' docker-images - build Docker images for CI environment'
@echo ' docker-push - upload local Hare images to Docker registry'
@echo ' docker-clean - remove local Hare images'
# Globals --------------------------------------------- {{{1
#
SHELL := bash
TOP_SRC_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
PY_VENV_DIR := $(TOP_SRC_DIR).py3venv
PYTHON := python3.6
PY_VENV := source $(PY_VENV_DIR)/bin/activate
PIP := $(PY_VENV); pip3
SETUP_PY := $(PY_VENV); $(PYTHON) setup.py
PY3_VERSION := 36
PY3_VERSION_MINOR := $(shell grep -o . <<<$(PY3_VERSION) | tail -n1)
DHALL_VERSION := 1.26.1
DHALL_URL := https://github.com/dhall-lang/dhall-haskell/releases/download/$(DHALL_VERSION)/dhall-$(DHALL_VERSION)-x86_64-linux.tar.bz2
DHALL_JSON_VERSION := 1.4.1
DHALL_JSON_URL := https://github.com/dhall-lang/dhall-haskell/releases/download/$(DHALL_VERSION)/dhall-json-$(DHALL_JSON_VERSION)-x86_64-linux.tar.bz2
DHALL_PRELUDE_VERSION := 11.1.0
DHALL_PRELUDE_URL := https://github.com/dhall-lang/dhall-lang/archive/v$(DHALL_PRELUDE_VERSION).tar.gz
# Build ----------------------------------------------- {{{1
#
.PHONY: build
build: hax miniprov
@$(MAKE) --quiet check
.PHONY: hax
HARE_VERSION := $(shell cat VERSION)
HAX_WHL := hax/dist/hax-$(HARE_VERSION)-cp$(PY3_VERSION)-cp$(PY3_VERSION)m-linux_x86_64.whl
hax: $(HAX_WHL)
HAX_SRC := $(wildcard hax/setup.py hax/hax/*.py hax/hax/motr/*.[ch] hax/hax/motr/*.py hax/hax/queue/*.py)
$(HAX_WHL): $(PY_VENV_DIR) $(HAX_SRC)
@$(call _info,Building hax .whl package)
@cd hax && $(SETUP_PY) bdist_wheel
.PHONY: miniprov
MP_VERSION := $(shell cat VERSION)
MP_WHL := provisioning/miniprov/dist/hare_mp-$(MP_VERSION)-py3-none-any.whl
miniprov: $(MP_WHL)
MP_SRC := $(wildcard provisioning/miniprov/setup.py provisioning/miniprov/hare_mp/*.py provisioning/miniprov/hare_mp/dhall/*.dhall)
$(MP_WHL): $(PY_VENV_DIR) $(HAX_SRC)
@$(call _info,Building miniprov .whl package)
@cd provisioning/miniprov && $(SETUP_PY) bdist_wheel
$(PY_VENV_DIR): $(patsubst %,%/requirements.txt,cfgen hax provisioning/miniprov)
@$(call _info,Initializing virtual env in $(PY_VENV_DIR))
@$(PYTHON) -m venv --system-site-packages $@
@$(call _info,Installing pip modules in virtual env)
@for f in $^; do \
$(call _log,processing $$f); \
$(PIP) install --ignore-installed -r $$f; \
done
# Clean ----------------------------------------------- {{{1
#
.PHONY: distclean
distclean: clean
@$(call _info,Cleaning python virtual env and pip modules)
@if [[ -e $(PY_VENV_DIR) ]]; then \
$(call _log,removing $(PY_VENV_DIR)); \
rm -rf $(PY_VENV_DIR); \
fi
@$(call _info,Cleaning cached vendor files)
@if [[ -d vendor ]]; then \
$(call _log,removing vendor/ dir); \
rm -rf vendor/; \
fi
.PHONY: clean
clean: clean-hax clean-mypy clean-dhall-prelude clean-miniprov
.PHONY: clean-hax
clean-hax:
@$(call _info,Cleaning hax)
@for d in hax/build hax/dist hax/hax.egg-info hax/*.so \
hax/hax/__pycache__ hax/hax/motr/__pycache__ \
hax/hax/queue/__pycache__ hax/test/__pycache__; do \
if [[ -e $$d ]]; then \
$(call _log,removing $$d); \
rm -rf $$d; \
fi; \
done
.PHONY: clean-mypy
clean-mypy:
@$(call _info,Cleaning mypy cache)
@find . -type d -name .mypy_cache -printf '%P\n' | while read d; do \
$(call _log,removing $$d); \
rm -rf $$d; \
done
.PHONY: clean-dhall-prelude
clean-dhall-prelude:
$(MAKE) --quiet -C cfgen clean-dhall-prelude
.PHONY: clean-miniprov
clean-miniprov:
$(MAKE) --quiet -C provisioning/miniprov clean
# Install --------------------------------------------- {{{1
#
PREFIX := opt/seagate/cortx/hare
CFGEN_EXE = $(DESTDIR)/$(PREFIX)/bin/cfgen
CFGEN_SHARE = $(DESTDIR)/$(PREFIX)/share/cfgen
CONSUL_LIBEXEC = $(DESTDIR)/$(PREFIX)/libexec/consul
CONSUL_SHARE = $(DESTDIR)/$(PREFIX)/share/consul
HARE_CONF = $(DESTDIR)/$(PREFIX)/conf
HARE_CONF_LOG = $(DESTDIR)/$(PREFIX)/conf/logrotate
HARE_LIBEXEC = $(DESTDIR)/$(PREFIX)/libexec
HARE_RULES = $(DESTDIR)/$(PREFIX)/rules
HAX_EXE = $(DESTDIR)/$(PREFIX)/bin/hax
MP_EXE = $(DESTDIR)/$(PREFIX)/bin/hare_setup
HAX_EGG_LINK = $(DESTDIR)/$(PREFIX)/lib/python3.$(PY3_VERSION_MINOR)/site-packages/hax.egg-link
MP_EGG_LINK = $(DESTDIR)/$(PREFIX)/lib/python3.$(PY3_VERSION_MINOR)/site-packages/hare_mp.egg-link
SYSTEMD_CONFIG_DIR = $(DESTDIR)/usr/lib/systemd/system
LOGROTATE_CONF_DIR = $(DESTDIR)/etc/logrotate.d
ETC_CRON_DIR = $(DESTDIR)/etc/cron.hourly
MINIPROV_TMPL_DIR = $(DESTDIR)/$(PREFIX)/conf/
# dhall-bin {{{2
vendor/dhall-bin/$(DHALL_VERSION)/dhall-$(DHALL_VERSION)-x86_64-linux.tar.bz2:
@$(call _log,fetching dhall $(DHALL_VERSION) archive)
@mkdir -p vendor/dhall-bin/$(DHALL_VERSION)
@cd vendor/dhall-bin/$(DHALL_VERSION) && \
curl --location --remote-name $(DHALL_URL)
vendor/dhall-bin/$(DHALL_VERSION)/dhall-json-$(DHALL_JSON_VERSION)-x86_64-linux.tar.bz2:
@$(call _log,fetching dhall-json $(DHALL_VERSION) archive)
@mkdir -p vendor/dhall-bin/$(DHALL_VERSION)
@cd vendor/dhall-bin/$(DHALL_VERSION) && \
curl --location --remote-name $(DHALL_JSON_URL)
vendor/dhall-bin/$(DHALL_VERSION)/bin/dhall: \
vendor/dhall-bin/$(DHALL_VERSION)/dhall-$(DHALL_VERSION)-x86_64-linux.tar.bz2
@$(call _log,unpacking dhall $(DHALL_VERSION) archive)
@cd vendor/dhall-bin/$(DHALL_VERSION) && \
tar --no-same-owner -xmf dhall-$(DHALL_VERSION)-x86_64-linux.tar.bz2
vendor/dhall-bin/$(DHALL_VERSION)/bin/dhall-to-json: \
vendor/dhall-bin/$(DHALL_VERSION)/dhall-json-$(DHALL_JSON_VERSION)-x86_64-linux.tar.bz2
@$(call _log,unpacking dhall-json $(DHALL_VERSION) archive)
@cd vendor/dhall-bin/$(DHALL_VERSION) && \
tar --no-same-owner -xmf dhall-json-$(DHALL_JSON_VERSION)-x86_64-linux.tar.bz2
.PHONY: unpack-dhall-bin
unpack-dhall-bin: \
vendor/dhall-bin/$(DHALL_VERSION)/bin/dhall \
vendor/dhall-bin/$(DHALL_VERSION)/bin/dhall-to-json
@cd vendor/dhall-bin && ln -sfn $(DHALL_VERSION)/bin current
# dhall-prelude {{{2
vendor/dhall-prelude/$(DHALL_PRELUDE_VERSION):
@mkdir -p vendor/dhall-prelude/$(DHALL_PRELUDE_VERSION)
vendor/dhall-prelude/current: vendor/dhall-prelude/$(DHALL_PRELUDE_VERSION)
@cd vendor/dhall-prelude && ln -sfn $(DHALL_PRELUDE_VERSION) current
vendor/dhall-prelude/$(DHALL_PRELUDE_VERSION)/v$(DHALL_PRELUDE_VERSION).tar.gz: vendor/dhall-prelude/$(DHALL_PRELUDE_VERSION)
@$(call _log,fetching dhall-prelude $(DHALL_PRELUDE_VERSION) archive)
@cd vendor/dhall-prelude/$(DHALL_PRELUDE_VERSION) && \
curl --location --output v$(DHALL_PRELUDE_VERSION).tar.gz \
$(DHALL_PRELUDE_URL)
.PHONY: fetch-dhall-prelude
fetch-dhall-prelude: \
vendor/dhall-prelude/$(DHALL_PRELUDE_VERSION)/v$(DHALL_PRELUDE_VERSION).tar.gz \
vendor/dhall-prelude/current
.PHONY: unpack-dhall-prelude
unpack-dhall-prelude: fetch-dhall-prelude
@$(MAKE) --quiet -C cfgen unpack-dhall-prelude
# install {{{2
.PHONY: install
install: install-dirs install-cfgen install-hax install-miniprov install-systemd install-vendor install-provisioning
@$(call _info,Installing hare utils)
@for f in utils/*; do \
$(call _log,copying $$f -> $(HARE_LIBEXEC)); \
install $$f $(HARE_LIBEXEC); \
done
@$(call _info,Installing RC rules)
@for f in rules/*; do \
$(call _log,copying $$f -> $(HARE_RULES)); \
install $$f $(HARE_RULES); \
done
@$(call _log,copying hctl -> $(DESTDIR)/$(PREFIX)/bin)
@install hctl $(DESTDIR)/$(PREFIX)/bin
@$(call _log,linking hctl -> $(DESTDIR)/usr/bin)
@install --verbose --directory $(DESTDIR)/usr/bin
@ln -sf /$(PREFIX)/bin/hctl $(DESTDIR)/usr/bin
@$(call _log,copying h0q -> $(DESTDIR)/$(PREFIX)/bin)
@install utils/h0q $(DESTDIR)/$(PREFIX)/bin
@$(call _log,linking h0q -> $(DESTDIR)/usr/bin)
@ln -sf /$(PREFIX)/bin/h0q $(DESTDIR)/usr/bin
@$(call _log,copying m0trace-prune -> $(ETC_CRON_DIR))
@install utils/m0trace-prune $(ETC_CRON_DIR)
@for f in provisioning/miniprov/hare_mp/templates/hare.* \
provisioning/setup.yaml \
provisioning/support.yaml ; do \
$(call _log,copying $$f -> $(MINIPROV_TMPL_DIR)); \
install $$f $(MINIPROV_TMPL_DIR); \
done
@$(call _info,Altering generated executables to make Python imports work)
@$(call _fix_hare_imports,hare_setup)
@$(call _fix_hare_imports,configure)
@$(call _fix_hare_imports,m0ping)
@$(call _fix_hare_imports,update-conf)
@$(call _fix_hare_imports,cfgen)
.PHONY: install-dirs
install-dirs:
@for d in $(HARE_CONF) \
$(HARE_CONF_LOG) \
$(HARE_LIBEXEC) \
$(HARE_RULES) \
$(ETC_CRON_DIR) \
$(DESTDIR)/run/cortx \
$(DESTDIR)/var/log/seagate/hare \
$(DESTDIR)/etc/logrotate.d \
$(DESTDIR)/var/motr/hax; \
do \
install --verbose --directory $$d; \
done
@install --verbose --directory --mode=0775 $(DESTDIR)/var/lib/hare
.PHONY: install-cfgen
install-cfgen: CFGEN_INSTALL_CMD = install
install-cfgen: CFGEN_PIP_CMD = $(PIP) install --ignore-installed --prefix $(DESTDIR)/$(PREFIX) -r $<
install-cfgen: $(CFGEN_EXE) install-cfgen-deps unpack-dhall-bin unpack-dhall-prelude
@$(call _info,Installing cfgen/dhall configs)
@install --verbose --directory $(CFGEN_SHARE)
@for d in cfgen/dhall cfgen/examples; do \
$(call _log,copying $$d -> $(CFGEN_SHARE)/$${d##*/}); \
cp --no-dereference --preserve=links --recursive $$d $(CFGEN_SHARE); \
done
.PHONY: install-cfgen-deps
install-cfgen-deps: cfgen/requirements.txt $(PY_VENV_DIR)
@$(call _info,Installing cfgen dependencies)
@$(CFGEN_PIP_CMD)
$(CFGEN_EXE): cfgen/cfgen
@$(call _info,Installing cfgen)
@install --verbose --directory $(DESTDIR)/$(PREFIX)/bin
@$(CFGEN_INSTALL_CMD) --verbose $(TOP_SRC_DIR)cfgen/cfgen $(DESTDIR)/$(PREFIX)/bin
.PHONY: install-systemd
install-systemd: $(wildcard systemd/*)
@$(call _info,Installing systemd configs)
@install --verbose --directory $(SYSTEMD_CONFIG_DIR)
@for f in systemd/*.service; do \
$(call _log,copying $$f -> $(SYSTEMD_CONFIG_DIR)); \
install --mode=0644 $$f $(SYSTEMD_CONFIG_DIR); \
done
@install --verbose --directory $(CONSUL_LIBEXEC)
@install --verbose systemd/hare-consul $(CONSUL_LIBEXEC)
@install --verbose --directory $(CONSUL_SHARE)
@for f in systemd/consul*.in; do \
$(call _log,copying $$f -> $(CONSUL_SHARE)); \
install --mode=0644 $$f $(CONSUL_SHARE); \
done
.PHONY: install-hax
install-hax: HAX_INSTALL_CMD = $(PIP) install --ignore-installed --prefix $(DESTDIR)/$(PREFIX) $(HAX_WHL:hax/%=%)
install-hax: export PYTHONPATH = $(DESTDIR)/$(PREFIX)/lib64/python3.$(PY3_VERSION_MINOR)/site-packages
install-hax: $(HAX_EXE)
@cd hax && $(SETUP_PY) install
$(HAX_EGG_LINK) $(HAX_EXE): $(HAX_WHL)
@$(call _info,Installing hax with '$(HAX_INSTALL_CMD)')
@cd hax && $(HAX_INSTALL_CMD)
.PHONY: install-miniprov
install-miniprov: MP_INSTALL_CMD = $(PIP) install --ignore-installed --prefix $(DESTDIR)/$(PREFIX) $(MP_WHL:provisioning/miniprov/%=%)
install-miniprov: export PYTHONPATH = $(DESTDIR)/$(PREFIX)/lib/python3.$(PY3_VERSION_MINOR)/site-packages
install-miniprov: $(MP_EXE)
@cd provisioning/miniprov && $(SETUP_PY) install
$(MP_EGG_LINK) $(MP_EXE): $(MP_WHL)
@$(call _info,Installing miniprov with '$(MP_INSTALL_CMD)')
@cd provisioning/miniprov && $(MP_INSTALL_CMD)
.PHONY: install-vendor
install-vendor:
@$(call _info,Installing Dhall)
@install --verbose --directory $(DESTDIR)/$(PREFIX)/bin
@install --verbose $(wildcard vendor/dhall-bin/current/*) $(DESTDIR)/$(PREFIX)/bin
.PHONY: install-provisioning
install-provisioning:
@$(call _info,Installing hare provisioning)
@for f in provisioning/*; do \
$(call _log,copying $$f -> $(HARE_CONF)); \
install $$f $(HARE_CONF); \
done
@$(call _info,Installing hare provisioning/logrotate)
@for f in provisioning/logrotate/*; do \
$(call _log,copying $$f -> $(HARE_CONF_LOG)); \
install $$f $(HARE_CONF_LOG); \
done
@$(call _log,copying provisioning/logrotate/hare -> $(LOGROTATE_CONF_DIR))
@install --mode=0644 provisioning/logrotate/hare $(LOGROTATE_CONF_DIR)
# devinstall {{{2
.PHONY: devinstall
devinstall: install-dirs devinstall-cfgen devinstall-hax devinstall-miniprov devinstall-systemd devinstall-vendor devinstall-provisioning
@$(call _info,linking hare utils)
@for f in utils/*; do \
$(call _log,linking $$f -> $(HARE_LIBEXEC)); \
ln -sf $(TOP_SRC_DIR)$$f $(HARE_LIBEXEC); \
done
@$(call _info,linking RC rules)
@for f in rules/*; do \
$(call _log,linking $$f -> $(HARE_RULES)); \
ln -sf $(TOP_SRC_DIR)$$f $(HARE_RULES); \
done
@$(call _log,linking hctl -> $(DESTDIR)/$(PREFIX)/bin)
@ln -sf $(TOP_SRC_DIR)hctl $(DESTDIR)/$(PREFIX)/bin
@$(call _log,linking hctl -> $(DESTDIR)/usr/bin)
@install --verbose --directory $(DESTDIR)/usr/bin
@ln -sf $(TOP_SRC_DIR)hctl $(DESTDIR)/usr/bin
@$(call _log,linking h0q -> $(DESTDIR)/usr/bin)
@ln -sf $(TOP_SRC_DIR)/utils/h0q $(DESTDIR)/usr/bin
@$(call _log,creating hare group)
@groupadd --force hare
@$(call _log,changing permission of $(DESTDIR)/var/lib/hare)
@chgrp hare $(DESTDIR)/var/lib/hare
@chmod --changes g+w $(DESTDIR)/var/lib/hare
@$(call _log,copying m0trace-prune -> $(ETC_CRON_DIR))
@install utils/m0trace-prune $(ETC_CRON_DIR)
@$(call _log,linking virtual environment to $(DESTDIR)/$(PREFIX))
@ln -s $(PY_VENV_DIR)/lib $(DESTDIR)/$(PREFIX)/lib
@ln -s $(PY_VENV_DIR)/lib64 $(DESTDIR)/$(PREFIX)/lib64
@for f in provisioning/miniprov/hare_mp/templates/hare.* \
provisioning/setup.yaml ; do \
$(call _log,linking $$f -> $(MINIPROV_TMPL_DIR)); \
ln -sf $(TOP_SRC_DIR)$$f $(MINIPROV_TMPL_DIR); \
done
@$(call _fix_hare_imports,cfgen)
.PHONY: devinstall-cfgen
devinstall-cfgen: CFGEN_INSTALL_CMD = ln -sf
devinstall-cfgen: CFGEN_PIP_CMD = $(PIP) install --ignore-installed -r $<
devinstall-cfgen: $(CFGEN_EXE) install-cfgen-deps unpack-dhall-bin unpack-dhall-prelude
@$(call _info,Installing cfgen/dhall configs)
@install --verbose --directory $(CFGEN_SHARE)
@for d in cfgen/dhall cfgen/examples; do \
$(call _log,linking $$d -> $(CFGEN_SHARE)/$${d##*/}); \
ln -sf $(TOP_SRC_DIR)$$d $(CFGEN_SHARE); \
done
.PHONY: devinstall-systemd
devinstall-systemd: $(wildcard systemd/*)
@$(call _info,Installing systemd configs)
@install --verbose --directory $(SYSTEMD_CONFIG_DIR)
@for f in systemd/*.service; do \
$(call _log,linking $$f -> $(SYSTEMD_CONFIG_DIR)); \
ln -sf $(TOP_SRC_DIR)$$f $(SYSTEMD_CONFIG_DIR); \
done
@install --verbose --directory $(CONSUL_LIBEXEC)
@$(call _log,linking systemd/hare-consul -> $(CONSUL_LIBEXEC))
@ln -sf $(TOP_SRC_DIR)systemd/hare-consul $(CONSUL_LIBEXEC)
@install --verbose --directory $(CONSUL_SHARE)
@for f in systemd/consul*.in; do \
$(call _log,linking $$f -> $(CONSUL_SHARE)); \
ln -sf $(TOP_SRC_DIR)$$f $(CONSUL_SHARE); \
done
@$(call _info,Reloading systemd configs)
@systemctl daemon-reload
.PHONY: devinstall-hax
# Don't specify --prefix $(DESTDIR)/$(PREFIX) since we do want to use our
# virtualenv folder instead. Generated executables will point to python binary
# from our virtualenv via shebang. Those executables will be put to /opt/seagate
# as symlinks. So it is critical to have virtualenv folder populated.
devinstall-hax: HAX_INSTALL_CMD = $(SETUP_PY) develop
devinstall-hax: export PYTHONPATH = $(DESTDIR)/$(PREFIX)/lib64/python3.$(PY3_VERSION_MINOR)/site-packages
devinstall-hax: hax/requirements.txt $(HAX_EGG_LINK)
@$(call _info,Installing hax development dependencies)
@$(PIP) install --ignore-installed \
--requirement <(sed -ne '/^#:runtime-requirements:/,$$p' $<)
@$(call _info,Creating symlinks for hax executables)
@ln -v -sf $(PY_VENV_DIR)/bin/hax $(DESTDIR)/$(PREFIX)/bin
@ln -v -sf $(PY_VENV_DIR)/bin/q $(DESTDIR)/$(PREFIX)/bin
@ln -v -sf $(PY_VENV_DIR)/bin/configure $(DESTDIR)/$(PREFIX)/bin
@ln -v -sf $(PY_VENV_DIR)/bin/update-conf $(DESTDIR)/$(PREFIX)/bin
@ln -v -sf $(PY_VENV_DIR)/bin/m0ping $(DESTDIR)/$(PREFIX)/bin
.PHONY: devinstall-miniprov
devinstall-miniprov: MP_INSTALL_CMD = $(SETUP_PY) develop
devinstall-miniprov: export PYTHONPATH = $(DESTDIR)/$(PREFIX)/lib/python3.$(PY3_VERSION_MINOR)/site-packages
devinstall-miniprov: provisioning/miniprov/requirements.txt $(MP_EGG_LINK)
@$(call _info,Installing miniprov development dependencies)
@$(PIP) install --ignore-installed \
--requirement <(sed -ne '/^#:runtime-requirements:/,$$p' $<)
@$(call _info,Creating symlinks for mini-provisioner executables)
@ln -v -sf $(PY_VENV_DIR)/bin/hare_setup $(DESTDIR)/$(PREFIX)/bin
.PHONY: devinstall-vendor
devinstall-vendor:
@$(call _info,Installing Dhall)
@install --verbose --directory $(DESTDIR)/$(PREFIX)/bin
@ln -v -sf $(addprefix $(TOP_SRC_DIR), $(wildcard vendor/dhall-bin/current/*)) $(DESTDIR)/$(PREFIX)/bin
.PHONY: devinstall-provisioning
devinstall-provisioning:
@$(call _info,Installing hare provisioning)
@for f in provisioning/*; do \
$(call _log,copying $$f -> $(HARE_CONF)); \
install $$f $(HARE_CONF); \
done
@$(call _info,Installing hare provisioning/logrotate)
@for f in provisioning/logrotate/*; do \
$(call _log,copying $$f -> $(HARE_CONF_LOG)); \
install $$f $(HARE_CONF_LOG); \
done
# Uninstall ------------------------------------------- {{{1
#
HAX_EGG = $(wildcard $(DESTDIR)/$(PREFIX)/lib/python3.$(PY3_VERSION_MINOR)/site-packages/hax-*.egg)
HAX_MODULE = $(wildcard $(DESTDIR)/$(PREFIX)/lib64/python3.$(PY3_VERSION_MINOR)/site-packages/*hax*)
EASY_INST_PTH = $(DESTDIR)/$(PREFIX)/lib/python3.$(PY3_VERSION_MINOR)/site-packages/easy-install.pth
.PHONY: uninstall
uninstall:
@$(call _info,Un-installing)
@for d in $(CFGEN_EXE) $(CFGEN_SHARE) \
$(HARE_CONF) \
$(HARE_RULES) \
$(HAX_EXE) $(HAX_EGG_LINK) $(HAX_EGG) $(HAX_MODULE) \
$(EASY_INST_PTH) \
$(CONSUL_LIBEXEC) $(CONSUL_SHARE) \
$(SYSTEMD_CONFIG_DIR)/hare*.service \
$(DESTDIR)/$(PREFIX) \
$(DESTDIR)/usr/bin/hctl \
$(DESTDIR)/var/lib/hare \
$(DESTDIR)/var/log/seagate/hare \
$(DESTDIR)/var/motr/hax; \
do \
if [[ -e $$d ]]; then \
$(call _log,removing $$d); \
rm -rf $$d; \
fi; \
done
# Linters --------------------------------------------- {{{1
#
PYTHON_SCRIPTS := $(shell grep 'python3' -n utils/* 2>/dev/null | grep ':1:' | sed 's/^\([^:]*\):.*$$/\1/g')
.PHONY: check
check: check-cfgen check-hax check-miniprov flake8 mypy
.PHONY: check-cfgen
check-cfgen: $(PY_VENV_DIR)
@$(call _info,Checking cfgen)
@$(PY_VENV); $(MAKE) --quiet -C cfgen flake8 typecheck
.PHONY: test-hax
test-hax: $(PY_VENV_DIR)
@$(call _info,Running hax autotests)
@cd hax &&\
$(PY_VENV) &&\
pytest -v test/
.PHONY: lint-hax
lint-hax: $(PY_VENV_DIR)
@$(call _info,Running static analysis of hax sources)
@cd hax &&\
$(PY_VENV) &&\
MYPYPATH=../stubs $(PYTHON) setup.py flake8 mypy
.PHONY: check-hax
check-hax: $(PY_VENV_DIR) lint-hax test-hax
.PHONY: check-miniprov
check-miniprov:
@$(call _info,Checking hare_mp)
@$(MAKE) --quiet -C provisioning/miniprov check
.PHONY: flake8
flake8: $(PYTHON_SCRIPTS)
@$(call _info,Checking files with flake8)
@$(PY_VENV); flake8 $(FLAKE8_OPTS) $^
.PHONY: mypy
override MYPY_OPTS := --config-file hax/mypy.ini $(MYPY_OPTS)
mypy: $(PYTHON_SCRIPTS)
@$(call _info,Checking files with mypy)
@$(PY_VENV); \
set -eu -o pipefail; for f in $^; do MYPYPATH=stubs:hax:utils mypy $(MYPY_OPTS) $$f; done
# Tests ----------------------------------------------- {{{1
#
.PHONY: test
test: test-cfgen
.PHONY: test-cfgen
test-cfgen: export PYTHONPATH = $(DESTDIR)/$(PREFIX)/lib64/python3.$(PY3_VERSION_MINOR)/site-packages
test-cfgen: $(PY_VENV_DIR) unpack-dhall-bin unpack-dhall-prelude
@$(call _info,Testing cfgen)
@$(PY_VENV); PATH=$$PWD/vendor/dhall-bin/current:$$PATH \
$(MAKE) --quiet -C cfgen test-cfgen check-dhall
# RPM ------------------------------------------------- {{{1
#
VERSION := $(shell cat VERSION)
GITREV = git$(shell git rev-parse --short HEAD)
DIST_FILE := cortx-hare-$(VERSION).tar.gz
RPMBUILD_DIR := $(HOME)/rpmbuild
RPMBUILD_TOPDIR := $(abspath $(RPMBUILD_DIR))
RPMSOURCES_DIR := $(RPMBUILD_DIR)/SOURCES
RPMSPECS_DIR := $(RPMBUILD_DIR)/SPECS
.PHONY: dist
dist: unpack-dhall-bin unpack-dhall-prelude
@$(call _info,Generating dist archive)
@rm -f $(DIST_FILE)
@git archive -v --prefix=cortx-hare/ HEAD -o $(DIST_FILE:.gz=)
@tar --append --verbose --transform 's#^vendor#cortx-hare/vendor#' \
--file=$(DIST_FILE:.gz=) vendor
@gzip $(DIST_FILE:.gz=)
.PHONY: __rpm_pre
__rpm_pre: dist
@$(call _info,Preparing rpmbuild environment)
@mkdir -v -p $(RPMSOURCES_DIR) $(RPMSPECS_DIR)
@mv -v $(DIST_FILE) $(RPMSOURCES_DIR)
@cp -v hare.spec $(RPMSPECS_DIR)
@chown $$(id -u):$$(id -g) $(RPMSOURCES_DIR)/$(DIST_FILE)
@chown $$(id -u):$$(id -g) $(RPMSPECS_DIR)/hare.spec
.PHONY: __rpm
__rpm:
@$(call _info,Building rpm packages)
@rpmbuild -ba $(RPMSPECS_DIR)/hare.spec \
--define "_topdir $(RPMBUILD_TOPDIR)" \
--define "h_version $(VERSION)" \
--define "h_gitrev $(GITREV)" \
$(RPMBUILD_FLAGS)
.PHONY: __rpm_post
__rpm_post:
@rm -f $(RPMSOURCES_DIR)/$(DIST_FILE) $(RPMSPECS_DIR)/hare.spec
.PHONY: __rpm_srpm
__rpm_srpm:
@$(call _info,Building source rpm packages)
@rpmbuild -bs $(RPMSPECS_DIR)/hare.spec \
--define "_topdir $(RPMBUILD_TOPDIR)" \
--define "h_version $(VERSION)" \
--define "h_gitrev $(GITREV)" \
$(RPMBUILD_FLAGS)
.PHONY: rpm
rpm:
@$(MAKE) __rpm_pre
@$(MAKE) __rpm
@$(MAKE) __rpm_post
.PHONY: srpm
srpm:
@$(MAKE) __rpm_pre
@$(MAKE) __rpm_srpm
@$(MAKE) __rpm_post
# Docker ---------------------------------------------- {{{1
#
# delegate all 'docker*' targets to docker/Makefile
docker-%:
@$(MAKE) -C docker/ $*
# Functions ------------------------------------------- {{{1
#
# all variations of white and grey colors are invisible on terminals that use
# Solarized colorscheme, cyan seems to be a good compromise here, it looks
# decent on the default black/white terminal, as well as on Solarized
define _info
if [[ -t 1 ]]; then \
CYAN=$$(tput bold; tput setaf 6); \
NC=$$(tput sgr0); \
fi; \
echo "$${CYAN}--> $(1)$${NC}"
endef
define _log
if [[ -t 1 ]]; then \
YELLOW=$$(tput setaf 3); \
NC=$$(tput sgr0); \
fi; \
echo "$${YELLOW} $(1)$${NC}"
endef
define _fix_hare_imports_ex
sed -i "7i sys.path.insert(1, '$(1)/lib64/python3.6/site-packages') # Added by Makefile" $(2) ;\
sed -i "8i sys.path.insert(2, '$(1)/lib/python3.6/site-packages') # Added by Makefile" $(2)
endef
# This function does't use DESTDIR intentionally.
# DESTDIR will point to a temporary RPM BUILDROOT folder when make install is
# invoked while building the RPM.
#
define _fix_hare_imports
$(call _log,Fixing /$(PREFIX)/bin/$(1)) ;\
$(call _fix_hare_imports_ex,/$(PREFIX),/$(DESTDIR)/$(PREFIX)/bin/$(1))
endef
# vim: textwidth=80 nowrap foldmethod=marker