-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
132 lines (102 loc) · 3.19 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
# Source directory of man page markdown files.
MAN_IDIR=docs/man
# Output directory of generated man pages.
MAN_ODIR=build/docs/man
# System directory for section 3 man pages.
MAN_3DIR=/usr/local/man/man3
# System directory for section 7 man pages.
MAN_7DIR=/usr/local/man/man7
# Source Markdown files for man pages
MAN_SRC!=find $(MAN_IDIR)/ -type f -name '*.md' | sort
# Generated man pages from Markdown source files.
MAN_PG=$(MAN_SRC:$(MAN_IDIR)/%.md=$(MAN_ODIR)/%)
# Man page title namespace
MAN_NS=libchrysalid
# External sources
EXT_SRC=external/cJSON/cJSON.c external/cJSON/cJSON_Utils.c \
external/iniparser/src/dictionary.c external/iniparser/src/iniparser.c
EXT_OBJ=$(EXT_SRC:%.c=build/%.o)
CC=clang
# Libchrysalid library sources
LIB_SRC!=find src/ -type f -name '*.c' | sort
LIB_OBJ=$(LIB_SRC:src/%.c=build/%.o)
LIB_BIN=build/libchrysalid.so
# Rule to build libchrysalid objects
build/%.o: src/%.c
$(CC) -fPIC -Wall -c $< -o $@
# Rule to build cJSON objects
build/external/cJSON/%.o: external/cJSON/%.c
mkdir -p build/external/cJSON
$(CC) -fPIC -Wall -c $< -o $@
# Rule to build iniparser objects
build/external/iniparser/src/%.o: external/iniparser/src/%.c
mkdir -p build/external/iniparser/src
$(CC) -fPIC -Wall -c $< -o $@
$(LIB_BIN): $(LIB_OBJ) $(EXT_OBJ)
mkdir -p build/external/iniparser/src
$(CC) -rdynamic -lpcre2-8 -shared $^ -o $@
lib: $(LIB_BIN)
tests: build/test
$<
build/test: tests/hptr.c tests/utf8.c $(LIB_BIN)
mkdir -p build
$(CC) $^ -lpcre2-8 -lcriterion -o $@
man:
tools/mandoc.sh
tools/install-man.sh
docs: $(MAN_PG)
$(MAN_PG): $(MAN_SRC)
$(MAN_ODIR)/%: $(MAN_IDIR)/%.md
pandoc $< --bibliography=docs/references.bib --citeproc -s -t man -o $@
clean:
rm -f $(MAN_ODIR)/*
rm -f $(MAN_ODIR)/*
rm -f build/examples/*
rm -f build/test
rm -f build/*.o
lib-install: $(LIB_BIN)
sudo mkdir -p /usr/local/include/libchrysalid/include
sudo mkdir -p /usr/local/include/libchrysalid/external/cJSON
sudo cp include/* /usr/local/include/libchrysalid/include
sudo cp external/cJSON/cJSON.h /usr/local/include/libchrysalid/external/cJSON
sudo cp $(LIB_BIN) /usr/local/lib
sudo ldconfig
install: $(MAN_PG)
sudo mkdir -p $(MAN_3DIR)
sudo mkdir -p $(MAN_7DIR)
sudo rm -f $(MAN_3DIR)/$(MAN_NS)*
sudo rm -f $(MAN_7DIR)/$(MAN_NS)*
cd $(MAN_ODIR); \
for f in *.3; \
do sudo cp -v -- "$$f" "$(MAN_3DIR)/$(MAN_NS):$$f"; \
done
cd $(MAN_ODIR); \
for f in *.7; \
do sudo cp -v -- "$$f" "$(MAN_7DIR)/$(MAN_NS):$$f"; \
done
for f in $(MAN_3DIR)/$(MAN_NS)*; \
do sudo gzip -f "$$f"; \
done
for f in $(MAN_7DIR)/$(MAN_NS)*; \
do sudo gzip -f "$$f"; \
done
sudo mandb
uninstall: $(MAN_3DIR) $(MAN_7DIR)
sudo rm -f $(MAN_3DIR)/$(MAN_NS)*
sudo rm -f $(MAN_7DIR)/$(MAN_NS)*
sudo mandb
examples: build/examples/json build/examples/log build/examples/cfg
build/examples/json
build/examples/log
build/examples/cfg
build/examples/json: examples/json.c $(LIB_BIN)
mkdir -p build/examples
$(CC) $^ -lpcre2-8 -o $@
build/examples/log: examples/log.c $(LIB_BIN)
mkdir -p build/examples
$(CC) $^ -lpcre2-8 -o $@
build/examples/cfg: examples/cfg.c $(LIB_BIN)
mkdir -p build/examples
$(CC) $^ -lpcre2-8 -o $@
.PHONY:
clean docs install uninstall