-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
106 lines (82 loc) · 2.78 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
PROJECT_NAME := ocrd_fileformat
TOOLS = ocrd-fileformat-transform
DOCKER_BASE_IMAGE ?= docker.io/ocrd/core:v2.69.0
DOCKER_TAG ?= ocrd/fileformat
PIP ?= pip3
# Directory to install to ('$(PREFIX)')
PREFIX ?= $(if $(VIRTUAL_ENV),$(VIRTUAL_ENV),/usr/local)
BINDIR = $(PREFIX)/bin
SHAREDIR = $(PREFIX)/share/$(PROJECT_NAME)
TESTDIR = tests
# BEGIN-EVAL makefile-parser --make-help Makefile
help:
@echo ""
@echo " Targets"
@echo ""
@echo " deps Install python packages"
@echo " install Install the executable in $(PREFIX)/bin and the ocrd-tool.json to $(SHAREDIR)"
@echo " uninstall Uninstall scripts and $(SHAREDIR)"
@echo " docker Build Docker image"
@echo " $(TESTDIR)/assets Setup test assets"
@echo " assets-clean Remove $(TESTDIR)/assets"
@echo " deps-test Install dev dependencies with pip"
@echo " test Run tests with pytest"
@echo ""
@echo " Variables"
@echo ""
@echo " PREFIX Directory to install to ('$(PREFIX)')"
# END-EVAL
# Install python packages
deps:
$(PIP) install 'ocrd >= 2.67.0' # needed for ocrd CLI (and bashlib)
install-fileformat:
make -C repo/ocr-fileformat PREFIX=$(PREFIX) vendor install
# Install the executable in $(PREFIX)/bin and the ocrd-tool.json to $(SHAREDIR)
install: deps install-fileformat install-tools
install-tools: $(SHAREDIR)/ocrd-tool.json
install-tools: $(TOOLS:%=$(BINDIR)/%)
$(SHAREDIR)/ocrd-tool.json: ocrd-tool.json
mkdir -p $(SHAREDIR)
cp ocrd-tool.json $(SHAREDIR)
$(TOOLS:%=$(BINDIR)/%): $(BINDIR)/%: %
mkdir -p $(BINDIR)
sed 's,^SHAREDIR.*,SHAREDIR="$(SHAREDIR)",' $< > $@
chmod a+x $@
ifeq ($(findstring $(BINDIR),$(subst :, ,$(PATH))),)
@echo "you need to add '$(BINDIR)' to your PATH"
else
@echo "you already have '$(BINDIR)' in your PATH. good job."
endif
# Uninstall scripts and $(SHAREDIR)
uninstall:
-$(RM) -v $(SHAREDIR)
-$(RM) -v $(TOOLS:%=$(BINDIR)/%)
-$(MAKE) -C repo/ocr-fileformat PREFIX=$(PREFIX) uninstall
# Build Docker image
docker:
docker build \
--build-arg DOCKER_BASE_IMAGE=$(DOCKER_BASE_IMAGE) \
--build-arg VCS_REF=$$(git rev-parse --short HEAD) \
--build-arg BUILD_DATE=$$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
-t $(DOCKER_TAG) .
#
# Assets
#
repo/assets repo/ocr-fileformat:
git submodule update --init
.PHONY: assets $(TESTDIR)/assets
assets: repo/assets $(TESTDIR)/assets
# Setup test assets
$(TESTDIR)/assets:
mkdir -p $(TESTDIR)/assets
cp -r repo/assets/data/* $(TESTDIR)/assets
# Remove $(TESTDIR)/assets
assets-clean:
rm -rf $(TESTDIR)/assets
# Install dev dependencies with pip
deps-test:
$(PIP) install -r requirements-test.txt
# Run tests with pytest
test: install deps-test assets
PATH="$(PREFIX)/bin:$$PATH" pytest tests
.PHONY: help deps install-fileformat install-tools install uninstall docker