-
Notifications
You must be signed in to change notification settings - Fork 116
/
Makefile
238 lines (201 loc) · 6.51 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
T=openssl
PREFIX ?=/usr/local
PKG_CONFIG ?=pkg-config
CC := $(CROSS)$(CC)
AR := $(CROSS)$(AR)
LD := $(CROSS)$(LD)
LUA :=
#OS auto detect
ifneq (,$(TARGET_SYS))
SYS := $(TARGET_SYS)
else
SYS := $(shell gcc -dumpmachine)
endif
#Lua auto detect
LUA_VERSION := $(shell $(PKG_CONFIG) luajit --print-provides)
ifeq ($(LUA_VERSION),)
# Not found luajit package, try lua
LUA_VERSION := $(shell $(PKG_CONFIG) lua --print-provides)
ifeq ($(LUA_VERSION),)
# Not found lua package, try from prefix
LUA_VERSION := $(shell lua -e "_,_,v=string.find(_VERSION,'Lua (.+)');print(v)")
LUA_CFLAGS ?= -I$(PREFIX)/include
LUA_LIBS ?= -L$(PREFIX)/lib #-llua
LUA_LIBDIR ?= $(PREFIX)/lib/lua/$(LUA_VERSION)
LUA := lua
else
# Found lua package
LUA_VERSION := $(shell lua -e "_,_,v=string.find(_VERSION,'Lua (.+)');print(v)")
LUA_CFLAGS ?= $(shell $(PKG_CONFIG) lua --cflags)
LUA_LIBS ?= $(shell $(PKG_CONFIG) lua --libs)
LUA_LIBDIR ?= $(PREFIX)/lib/lua/$(LUA_VERSION)
LUA := lua
endif
else
# Found luajit package
LUA_VERSION := $(shell luajit -e "_,_,v=string.find(_VERSION,'Lua (.+)');print(v)")
LUA_CFLAGS ?= $(shell $(PKG_CONFIG) luajit --cflags)
LUA_LIBS ?= $(shell $(PKG_CONFIG) luajit --libs)
LUA_LIBDIR ?= $(PREFIX)/lib/lua/$(LUA_VERSION)
LUA := luajit
endif
#OpenSSL auto detect
OPENSSL_CFLAGS ?= $(shell $(PKG_CONFIG) openssl --cflags)
ifeq (${OPENSSL_STATIC},)
OPENSSL_LIBS ?= $(shell $(PKG_CONFIG) openssl --static --libs)
else
OPENSSL_LIBDIR ?= $(shell $(PKG_CONFIG) openssl --variable=libdir)
OPENSSL_LIBS ?= $(OPENSSL_LIBDIR)/libcrypto.a $(OPENSSL_LIBDIR)/libssl.a
endif
TARGET = $(MAKECMDGOALS)
ifeq (coveralls, ${TARGET})
CFLAGS +=-g -fprofile-arcs -ftest-coverage
LDFLAGS +=-g -fprofile-arcs
endif
# asan {{{
ifeq (asan, ${TARGET})
ifneq (, $(findstring apple, $(SYS)))
ASAN_LIB = $(shell dirname $(shell dirname $(shell clang -print-libgcc-file-name)))/darwin/libclang_rt.asan_osx_dynamic.dylib
LDFLAGS +=-g -fsanitize=address
endif
ifneq (, $(findstring linux, $(SYS)))
ASAN_LIB = $(shell dirname $(shell cc -print-libgcc-file-name))/libasan.so
LDFLAGS +=-g -fsanitize=address -lubsan
endif
CC ?= clang
LD ?= clang
CFLAGS +=-g -O0 -fsanitize=address,undefined
endif
# asan }}}
# tsan {{{
ifeq (tsan, ${TARGET})
ifneq (, $(findstring apple, $(SYS)))
ASAN_LIB = $(shell dirname $(shell dirname $(shell clang -print-libgcc-file-name)))/darwin/libclang_rt.tsan_osx_dynamic.dylib
LDFLAGS +=-g -fsanitize=thread
endif
ifneq (, $(findstring linux, $(SYS)))
ASAN_LIB = $(shell dirname $(shell cc -print-libgcc-file-name))/libtsan.so
LDFLAGS +=-g -fsanitize=thread -lubsan -ltsan
endif
CC ?= clang
LD ?= clang
CFLAGS +=-g -O0 -fsanitize=thread
endif
# tsan }}}
ifeq (debug, ${TARGET})
CFLAGS +=-g -Og
LDFLAGS +=-g -Og
endif
ifeq (valgrind, ${TARGET})
CFLAGS +=-g -O0
LDFLAGS +=-g -O0
endif
ifneq (, $(findstring linux, $(SYS)))
# Do linux things
CFLAGS += -fPIC
LDFLAGS += -fPIC # -Wl,--no-undefined
endif
ifneq (, $(findstring apple, $(SYS)))
# Do darwin things
CFLAGS += -fPIC
LDFLAGS += -fPIC -Wl,-undefined,dynamic_lookup -ldl
MACOSX_DEPLOYMENT_TARGET="10.12"
CC := MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET} $(CC)
endif
ifneq (, $(findstring mingw, $(SYS)))
# Do mingw things
CFLAGS += -DLUA_LIB -DLUA_BUILD_AS_DLL -DWIN32_LEAN_AND_MEAN
endif
ifneq (, $(findstring cygwin, $(SYS)))
# Do cygwin things
CFLAGS += -fPIC
endif
ifneq (, $(findstring iOS, $(SYS)))
# Do iOS things
CFLAGS += -fPIC
LDFLAGS += -fPIC -ldl
endif
#custom config
ifeq (.config, $(wildcard .config))
include .config
endif
CFLAGS += $(OPENSSL_CFLAGS) $(LUA_CFLAGS) $(TARGET_FLAGS)
LDFLAGS += $(OPENSSL_LIBS)
# Compilation directives
WARN_MIN = -Wall -Wno-unused-value -Wno-unused-function
WARN = -Wall
WARN_MOST = $(WARN) -W -Waggregate-return -Wcast-align -Wmissing-prototypes \
-Wnested-externs -Wshadow -Wwrite-strings -pedantic
CFLAGS += $(WARN_MIN) -Ideps -Ideps/lua-compat/c-api -Ideps/auxiliar
OBJS=src/asn1.o deps/auxiliar/auxiliar.o src/bio.o src/cipher.o src/cms.o src/compat.o \
src/crl.o src/csr.o src/dh.o src/digest.o src/dsa.o src/ec.o src/engine.o \
src/hmac.o src/lbn.o src/lhash.o src/misc.o src/ocsp.o src/openssl.o src/ots.o \
src/pkcs12.o src/pkcs7.o src/pkey.o src/rsa.o src/ssl.o src/th-lock.o src/util.o \
src/x509.o src/xattrs.o src/xexts.o src/xname.o src/xstore.o src/xalgor.o \
src/param.o src/kdf.o \
src/callback.o src/srp.o src/mac.o deps/auxiliar/subsidiar.o
.PHONY: all install test info doc coveralls asan
.c.o:
$(CC) $(CFLAGS) -c -o $@ $?
all: $T.so
@echo "Target system: "$(SYS)
$T.so: lib$T.a
$(CC) -shared -o $@ src/openssl.o -L. -l$T $(LDFLAGS)
lib$T.a: $(OBJS)
$(AR) rcs $@ $?
install: all
mkdir -p $(LUA_LIBDIR)
cp $T.so $(LUA_LIBDIR)
doc:
ldoc src -d doc
info:
@echo "Target system: "$(SYS)
@echo "CC:" $(CC)
@echo "AR:" $(AR)
@echo "PREFIX:" $(PREFIX)
test: all
cd test && LUA_CPATH=$(shell pwd)/?.so $(shell which $(LUA)) test.lua -v && cd ..
debug: all
coveralls: test
ifeq ($(CI),)
lcov -c -d src -o ${T}.info
genhtml -o ${T}.html -t "${T} coverage" --num-spaces 2 ${T}.info
endif
valgrind: all
cd test && LUA_CPATH=$(shell pwd)/?.so \
valgrind --gen-suppressions=all --suppressions=../.github/lua-openssl.supp \
--error-exitcode=1 --leak-check=full --show-leak-kinds=all \
--child-silent-after-fork=yes $(LUA) test.lua && cd ..
asan: all
ifneq (, $(findstring apple, $(SYS)))
cd test && LUA_CPATH=$(shell pwd)/?.so \
ASAN_LIB=$(ASAN_LIB) \
LSAN_OPTIONS=suppressions=${shell pwd}/.github/asan.supp \
DYLD_INSERT_LIBRARIES=$(ASAN_LIB) \
$(LUA) test.lua && cd ..
endif
ifneq (, $(findstring linux, $(SYS)))
cd test && LUA_CPATH=$(shell pwd)/?.so \
ASAN_LIB=$(ASAN_LIB) \
LSAN_OPTIONS=suppressions=${shell pwd}/.github/asan.supp \
LD_PRELOAD=$(ASAN_LIB) \
$(LUA) test.lua && cd ..
endif
tsan: all
ifneq (, $(findstring apple, $(SYS)))
cd test && LUA_CPATH=$(shell pwd)/?.so \
ASAN_LIB=$(ASAN_LIB) \
LSAN_OPTIONS=suppressions=${shell pwd}/.github/asan.supp \
DYLD_INSERT_LIBRARIES=$(ASAN_LIB) \
$(LUA) test.lua && cd ..
endif
ifneq (, $(findstring linux, $(SYS)))
cd test && LUA_CPATH=$(shell pwd)/?.so \
ASAN_LIB=$(ASAN_LIB) \
LSAN_OPTIONS=suppressions=${shell pwd}/.github/asan.supp \
LD_PRELOAD=$(ASAN_LIB) \
$(LUA) test.lua && cd ..
endif
clean:
rm -rf $T.* lib$T.a $(OBJS) src/*.g*
# vim: ts=8 sw=8 noet