-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
142 lines (105 loc) · 3.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
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
VERSION = 2.8
CC = gcc -std=c18
CFLAGS = -O3 -march=native -Wall -Wextra -Wno-implicit-fallthrough -Wpedantic
LDFLAGS =
TARGET = reliq
O_SMALL_STACK := 0 # limits for small stack
O_PHPTAGS := 1 # support for <?php ?>
O_AUTOCLOSING := 1 # support for autoclosing tags (tag ommission https://html.spec.whatwg.org/multipage/syntax.html#optional-tags)
O_EDITING := 1 #support for editing
PREFIX ?= /usr
MANPREFIX ?= ${PREFIX}/share/man
BINDIR = ${DESTDIR}${PREFIX}/bin
MANDIR = $(DESTDIR)${MANPREFIX}/man1
LD_LIBRARY_PATH ?= ${PREFIX}/lib
INCLUDE_PATH ?= ${PREFIX}/include
# all of the above variables can be changed from cli
O_LIB := 0 # compile libreliq
O_LINKED := 0 # link reliq to libreliq
STRIP_ARGS =
LDFLAGS_R = ${LDFLAGS}
CFLAGS_D = -DRELIQ_VERSION=\"${VERSION}\"
LIB_SRC = src/flexarr.c src/sink.c src/html.c src/reliq.c src/hnode_print.c src/ctype.c src/utils.c src/output.c src/htmlescapecodes.c src/pattern.c src/range.c src/npattern.c src/exprs_comp.c src/exprs_exec.c src/format.c
ifeq ("$(shell uname -s)","Darwin")
STRIP_ARGS += -x
endif
ifeq ($(strip ${O_SMALL_STACK}),1)
CFLAGS_D += -DRELIQ_SMALL_STACK
endif
ifeq ($(strip ${O_PHPTAGS}),1)
CFLAGS_D += -DRELIQ_PHPTAGS
endif
ifeq ($(strip ${O_AUTOCLOSING}),1)
CFLAGS_D += -DRELIQ_AUTOCLOSING
endif
ifeq ($(strip ${O_EDITING}),1)
LIB_SRC += src/edit.c src/edit_sed.c src/edit_wc.c src/edit_tr.c
CFLAGS_D += -DRELIQ_EDITING
endif
SRC = src/main.c ${LIB_SRC}
ifeq ($(strip ${O_LIB}),1)
SRC = ${LIB_SRC}
LDFLAGS_R += -shared
CFLAGS_D += -fPIC
endif
ifeq ($(strip ${O_LINKED}),1)
CFLAGS_D += -DLINKED
SRC = src/main.c
LDFLAGS_R += -lreliq
endif
TEST_FLAGS=$(shell echo "${CFLAGS_D}" | sed -E 's/(^| )-D/\1/g; s/(^| )[a-zA-Z0-9_]+=("[^"]*")?[^ ]*( |$$)//')
CFLAGS_ALL = ${CFLAGS} ${CFLAGS_D}
OBJ = ${SRC:.c=.o}
.PHONY: all options reliq lib lib-install install linked test test-advanced test-errors test-all test-update dist uninstall
all: options reliq
options:
@echo ${SRC}
@echo ${TARGET} build options:
@echo "CFLAGS = ${CFLAGS_ALL}"
@echo "LDFLAGS = $(strip ${LDFLAGS_R})"
@echo "CC = ${CC}"
reliq-h:
@echo ${CFLAGS_D} | cat - src/reliq.h | sed '1{ s/ /\n/g; s/-D/#define /g; s/=/ /; h; d; }; /^\/\/#RELIQ_COMPILE_FLAGS/{ s/.*//;G;D; }' > reliq.h
lib: clean reliq-h
@make O_LIB=1 TARGET=lib${TARGET}.so
install-pc:
sed "s/#VERSION#/${VERSION}/g;s|#PREFIX#|${PREFIX}|g;s/#CFLAGS_D#/${CFLAGS_D}/g" reliq.pc > $$(pkg-config --variable pc_path pkg-config | cut -d: -f1)/reliq.pc
lib-install: lib install-pc
install -m755 lib${TARGET}.so ${LD_LIBRARY_PATH}
install -m644 reliq.h ${INCLUDE_PATH}
linked: lib lib-install
@make O_LINKED=1
reliq: ${OBJ}
${CC} ${CFLAGS_ALL} $^ ${LDFLAGS_R} -o ${TARGET}
strip ${STRIP_ARGS} ${TARGET}
%.o: %.c
${CC} ${CFLAGS_ALL} -c $< -o $@
test: all
@./test.sh test/basic.test . "${TEST_FLAGS}" || true
test-advanced: all
@./test.sh test/advanced.test . "${TEST_FLAGS}" || true
test-errors: all
@./test.sh test/errors.test . "${TEST_FLAGS}" || true
test-all: all
@./test.sh test/all.test . "${TEST_FLAGS}" || true
test-update: test
@./test.sh test/all.test update "${TEST_FLAGS}" || true
test-speed: lib
@gcc -O3 testspeed.c -o testspeed ./libreliq.so
@./testspeed
dist: clean
mkdir -p ${TARGET}-${VERSION}
cp -r test LICENSE Makefile README.md src reliq.1 ${TARGET}-${VERSION}
tar -c ${TARGET}-${VERSION} | xz -e9 > ${TARGET}-${VERSION}.tar.xz
rm -rf ${TARGET}-${VERSION}
clean:
rm -f ${TARGET} lib${TARGET}.so ${OBJ} reliq.h ${TARGET}-${VERSION}.tar.xz
install: all
mkdir -p ${BINDIR}
install -m755 ${TARGET} ${BINDIR}
mkdir -p ${MANDIR}
sed "s/VERSION/${VERSION}/g" ${TARGET}.1 | bzip2 -9 > ${MANDIR}/${TARGET}.1.bz2
chmod 644 ${MANDIR}/${TARGET}.1.bz2
uninstall:
rm -f ${BINDIR}/${TARGET}\
${MANDIR}/${TARGET}.1.bz2