-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
74 lines (53 loc) · 1.71 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
# Disable built-in rules and variables
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-builtin-variables
# version spec
VER_FILE := version
# toolset version
VER := $(shell head -n 1 $(VER_FILE))
# programs to compile
PROGS := ocr-open ocr-ls ocr
# other scripts
SCRIPTS := crop-image norm-image norm-text norm-page
# flags
CFLAGS := -O2 -s -std=c11 -Wall -Wextra -Wformat -Wl,--strip-all \
-DPROG_VER=\"$(VER)\" -D_GNU_SOURCE
# source directory
SRC := src
# release file
RELEASE_FILE := ocr-$(VER).tar.xz
# compile all
.PHONY: all
all: $(PROGS) $(SCRIPTS)
# release
.PHONY: release
release: $(RELEASE_FILE)
$(RELEASE_FILE): $(PROGS) $(SCRIPTS) LICENSE
tar -caf $@ $^
# clean-up
.PHONY: clean
clean:
rm -f $(PROGS) $(RELEASE_FILE)
# version update for scripts
$(SCRIPTS): $(VER_FILE)
sed -i -E 's/^VER=.+/VER=\"$(VER)\"/' $@
# version update for compiled programs
$(PROGS): $(VER_FILE)
# programs ----------------------------------------------------------------------
COMMON_SRC := utils.c utils.h page_spec.c page_spec.h str.h str.c
# ocr-open
OCR_OPEN_SRC := $(COMMON_SRC) ocr_open.c
ocr-open: $(addprefix $(SRC)/,$(OCR_OPEN_SRC))
gcc $(CFLAGS) -DPROG_NAME=\"$@\" -o $@ $(filter %.c,$^) -lmagic
# ocr-ls
OCR_LS_SRC := $(COMMON_SRC) ocr_ls.c list_pages.h list_pages.c
ocr-ls: $(addprefix $(SRC)/,$(OCR_LS_SRC))
gcc $(CFLAGS) -DPROG_NAME=\"$@\" -o $@ $(filter %.c,$^)
# ocr
OCR_SRC := $(COMMON_SRC) ocr.c tesseract.h tesseract.c list_pages.h list_pages.c
ocr: $(addprefix $(SRC)/,$(OCR_SRC))
gcc $(CFLAGS) -DPROG_NAME=\"$@\" -o $@ $(filter %.c,$^)
# helpers -----------------------------------------------------------------------
.PHONY: submodule-update
submodule-update:
git submodule update --remote --merge