-
Notifications
You must be signed in to change notification settings - Fork 107
/
Makefile
198 lines (157 loc) · 4.88 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
# Copyright (C) 2013 Yichun Zhang (agentzh)
# Copyright (C) 2005-2012 Mike Pall.
MAJVER= 0
MINVER= 0
RELVER= 1
VERSION= $(MAJVER).$(MINVER).$(RELVER)
FILE_T= sregex-cli
FILE_A= libsregex.a
FILE_SO= libsregex.so
CC= gcc
CFLAGS+= -fpic -g -Wall -O3 -Isrc -I.
PREFIX= /usr/local
DESTDIR=
INSTALL_X= install -m 0755
INSTALL_F= install -m 0644
MKDIR= mkdir -p
RMDIR= rmdir 2>/dev/null
UNINSTALL= $(HOST_RM)
HOST_RM= rm -f
LDCONFIG= ldconfig -n
SYMLINK= ln -sf
LUA= luajit
DASM= $(LUA) dynasm/dynasm.lua
DASM_FLAGS=
INSTALL_INC= $(DESTDIR)$(PREFIX)/include/sregex
INSTALL_LIB= $(DESTDIR)$(PREFIX)/lib
INSTALL_BIN= $(DESTDIR)$(PREFIX)/bin
INSTALL_ANAME= libsregex.a
INSTALL_SONAME= libsregex.so.$(MAJVER).$(MINVER).$(RELVER)
INSTALL_SOSHORT1= libsregex.so
INSTALL_SOSHORT2= libsregex.so.$(MAJVER)
ifeq (Darwin,$(shell uname -s))
INSTALL_SONAME= libsregex.$(MAJVER).$(MINVER).$(RELVER).dylib
INSTALL_SOSHORT1= libsregex.dylib
INSTALL_SOSHORT2= libsregex.$(MAJVER).dylib
endif
INSTALL_T= $(INSTALL_BIN)/$(FILE_T)
INSTALL_STATIC= $(INSTALL_LIB)/$(INSTALL_ANAME)
INSTALL_DYN= $(INSTALL_LIB)/$(INSTALL_SONAME)
INSTALL_SHORT1= $(INSTALL_LIB)/$(INSTALL_SOSHORT1)
INSTALL_SHORT2= $(INSTALL_LIB)/$(INSTALL_SOSHORT2)
INSTALL_DIRS= $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_BIN)
TARGET_SONAME= libsregex.so.$(MAJVER)
ifeq (Darwin,$(shell uname -s))
TARGET_SONAME= libsregex.$(MAJVER).dylib
LDCONFIG= :
else
ifeq (SunOS,$(shell uname -s))
INSTALL_X=cp -p
INSTALL_F=cp -p
endif
endif
TARGET_DYLIBPATH= $(PREFIX)/lib/$(TARGET_SONAME)
TARGET_XSHLDFLAGS= -shared -fpic -Wl,-soname,$(TARGET_SONAME)
TARGET_AR=ar rcus
HOST_SYS:= $(shell uname -s)
ifeq (Darwin,$(HOST_SYS))
FILE_SO= libsregex.dylib
TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fpic
TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).$(RELVER)
endif
jobs= 1
ifeq ($(use_valgrind), 1)
CFLAGS += -DSRE_USE_VALGRIND=1
endif
Q= @
E= @echo
pwd = $(shell pwd)
lib_c_files= \
src/sregex/sre_palloc.c \
src/sregex/sre_regex.c \
src/sregex/sre_yyparser.c \
src/sregex/sre_regex_compiler.c \
src/sregex/sre_vm_bytecode.c \
src/sregex/sre_vm_thompson.c \
src/sregex/sre_vm_pike.c \
src/sregex/sre_capture.c \
src/sregex/sre_vm_thompson_jit.c
lib_o_files= $(patsubst %.c,%.o,$(lib_c_files))
h_files= src/sregex/sre_capture.h \
src/sregex/sre_palloc.h \
src/sregex/sre_vm_bytecode.h \
src/sregex/sre_yyparser.h \
src/sregex/sre_core.h \
src/sregex/sre_regex.h \
src/sregex/sre_vm_thompson_x64.h \
src/sregex/sre_vm_thompson.h \
src/sregex/sregex.h \
src/sregex/ddebug.h \
plist_vfiles= $(patsubst src/sregex/%.c,%.plist,$(lib_c_files))
INSTALL_H_FILES= src/sregex/sregex.h src/sregex/ddebug.h
.PHONY: all clean distclean test val install uninstall
.PRECIOUS: \
src/sregex/sre_yyparser.c \
src/sregex/sre_yyparser.h \
src/sregex/sre_vm_thompson_x64.h
all: $(FILE_SO) $(FILE_A) $(FILE_T)
$(FILE_T): src/sre_cli.o $(lib_o_files)
$(E) "LINK $@"
$(Q)$(CC) -o $@ $+
$(FILE_SO): $(lib_o_files)
$(E) "DYNLINK $@"
$(Q)$(CC) $(TARGET_XSHLDFLAGS) -o $@ $+
$(E) "SYMLINK $(INSTALL_SOSHORT2)"
$(Q)$(SYMLINK) $@ $(INSTALL_SOSHORT2)
$(FILE_A): $(lib_o_files)
$(E) "AR $@"
$(Q)$(TARGET_AR) $@ $(lib_o_files)
%.o: %.c $(h_files)
$(E) "CC $@"
$(Q)$(CC) $(CFLAGS) -c -o $@ $<
%.c %.h: %.y
$(E) "BISON $@"
$(Q)bison -p sregex_yy -v $<
$(Q)./util/fix-bison-comments
%.h: %.dasc
$(E) "DYNASM $@"
$(Q)$(DASM) $(DASM_FLAGS) -o $@ $<
clean:
$(HOST_RM) *.dylib *.so *.so.* src/*.o $(lib_o_files) core $(TARGET) \
src/sregex/*.output \
$(FILE_T) $(FILE_SO) $(FILE_A)
distclean: clean
$(HOST_RM) src/sregex/sre_yyparser.[ch]
test: all
prove -j$(jobs) -r t
val:
$(MAKE) use_valgrind=1 all -B -j$(jobs)
valtest: val
TEST_SREGEX_USE_VALGRIND=1 prove -j$(jobs) -r t
$(MAKE) -B -j$(jobs)
clang: $(plist_vfiles)
%.plist: src/sregex/%.c $(h_files)
@echo $<
-@clang -O --analyze -Wextra -Wall -Werror -Isrc -I. $<
install: all
@echo "==== Installing sregex $(VERSION) to $(PREFIX) ===="
$(MKDIR) $(INSTALL_DIRS)
$(INSTALL_X) $(FILE_T) $(INSTALL_T)
$(INSTALL_F) $(INSTALL_H_FILES) $(INSTALL_INC)
$(INSTALL_X) $(FILE_SO) $(INSTALL_DYN)
-$(LDCONFIG) $(INSTALL_LIB)
$(SYMLINK) $(INSTALL_SONAME) $(INSTALL_SHORT1)
-$(SYMLINK) $(INSTALL_SONAME) $(INSTALL_SHORT2)
@echo "==== Successfully installed sregex $(VERSION) to $(PREFIX) ===="
uninstall:
@echo "==== Uninstalling sregex $(VERSION) to $(PREFIX) ===="
$(UNINSTALL) $(INSTALL_T)
$(UNINSTALL) $(INSTALL_LIB)/$(FILE_SO)
$(UNINSTALL) $(INSTALL_LIB)/libsregex.a
$(UNINSTALL) $(INSTALL_SHORT1)
$(UNINSTALL) $(INSTALL_SHORT2)
for file in $(patsubst src/sregex/%,%,$(INSTALL_H_FILES)); do \
$(UNINSTALL) $(INSTALL_INC)/$$file; \
done
$(RMDIR) $(INSTALL_INC)
@echo "==== Successfully uninstalled sregex $(VERSION) from $(PREFIX) ===="