summarylogtreecommitdiffstats
path: root/usockets-0.8.8-Makefile.patch
blob: 1a4cb2e4d585c75677bed4abc7e2299e58198847 (plain)
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
diff --git a/Makefile b/Makefile
index f6e2c6b..fdce16d 100644
--- a/Makefile
+++ b/Makefile
@@ -1,109 +1,68 @@
 # By default we use LTO, but Windows does not support it
 ifneq ($(WITH_LTO),0)
-	override CFLAGS += -flto
+CFLAGS += -flto
 endif
 
+DESTDIR ?=
+
+prefix ?= /usr
+exec_prefix ?= $(prefix)
+LIB ?= lib
+libdir ?= $(exec_prefix)/$(LIB)
+includedir ?= $(exec_prefix)/include
+
+PKG_CONFIG ?= pkg-config
+
+VERSION ?= 0.0
+LIBTARGET = libusockets.so.$(VERSION)
+
+REQUIRES =
+COMMON_FLAGS = -Isrc
+
-# WITH_BORINGSSL=1 enables BoringSSL support, linked statically (preferred over OpenSSL)
-# You need to call "make boringssl" before
-ifeq ($(WITH_BORINGSSL),1)
-	override CFLAGS += -Iboringssl/include -pthread -DLIBUS_USE_OPENSSL
-	override LDFLAGS += -pthread boringssl/build/ssl/libssl.a boringssl/build/crypto/libcrypto.a -lstdc++
-else
-	# WITH_OPENSSL=1 enables OpenSSL 1.1+ support
-	# For now we need to link with C++ for OpenSSL support, but should be removed with time
-	ifeq ($(WITH_OPENSSL),1)
-		override CFLAGS += -DLIBUS_USE_OPENSSL
-		# With problems on macOS, make sure to pass needed LDFLAGS required to find these
-		override LDFLAGS += -lssl -lcrypto -lstdc++
+ifeq ($(WITH_OPENSSL),1)
+COMMON_FLAGS += -DLIBUS_USE_OPENSSL
+LDFLAGS += -lstdc++
+REQUIRES += libssl libcrypto
-	else
-		# WITH_WOLFSSL=1 enables WolfSSL 4.2.0 support (mutually exclusive with OpenSSL)
-		ifeq ($(WITH_WOLFSSL),1)
-			# todo: change these
-			override CFLAGS += -DLIBUS_USE_WOLFSSL -I/usr/local/include
-			override LDFLAGS += -L/usr/local/lib -lwolfssl
-		else
-			override CFLAGS += -DLIBUS_NO_SSL
-		endif
-	endif
 endif
 
-# WITH_IO_URING=1 builds with io_uring as event-loop and network implementation
 ifeq ($(WITH_IO_URING),1)
-	override CFLAGS += -DLIBUS_USE_IO_URING
-	# override LDFLAGS += -l
+COMMON_FLAGS += -DLIBUS_USE_IO_URING
+REQUIRES += liburing
 endif
 
 # WITH_LIBUV=1 builds with libuv as event-loop
 ifeq ($(WITH_LIBUV),1)
-	override CFLAGS += -DLIBUS_USE_LIBUV
-	override LDFLAGS += -luv
+COMMON_FLAGS += -DLIBUS_USE_LIBUV
+REQUIRES += libuv
 endif
 
-# WITH_ASIO builds with boot asio event-loop
-ifeq ($(WITH_ASIO),1)
-	override CFLAGS += -DLIBUS_USE_ASIO
-	override LDFLAGS += -lstdc++ -lpthread
-	override CXXFLAGS += -pthread -DLIBUS_USE_ASIO
-endif
-
-# WITH_GCD=1 builds with libdispatch as event-loop
-ifeq ($(WITH_GCD),1)
-	override CFLAGS += -DLIBUS_USE_GCD
-	override LDFLAGS += -framework CoreFoundation
-endif
-
-# WITH_ASAN builds with sanitizers
-ifeq ($(WITH_ASAN),1)
-	override CFLAGS += -fsanitize=address -g
-	override LDFLAGS += -fsanitize=address
-endif
-
-ifeq ($(WITH_QUIC),1)
-	override CFLAGS += -DLIBUS_USE_QUIC -pthread -std=c11 -Isrc -Ilsquic/include
-	override LDFLAGS += -pthread -lz -lm uSockets.a lsquic/src/liblsquic/liblsquic.a
-else
-	override CFLAGS += -std=c11 -Isrc
-	override LDFLAGS += uSockets.a
-endif
-
-# Also link liburing for io_uring support
-ifeq ($(WITH_IO_URING),1)
-	override LDFLAGS += /usr/lib/liburing.a
-endif
-
-# By default we build the uSockets.a static library
+CFLAGS += -std=c11 $(COMMON_FLAGS)
+CXXFLAGS += -std=c++17 $(COMMON_FLAGS)
+
 default:
-	rm -f *.o
-	$(CC) $(CFLAGS) -O3 -c src/*.c src/eventing/*.c src/crypto/*.c src/io_uring/*.c
+	$(CC) $(CFLAGS) -fPIC -c src/*.c src/eventing/*.c src/crypto/*.c src/io_uring/*.c
-# Also link in Boost Asio support
-ifeq ($(WITH_ASIO),1)
-	$(CXX) $(CXXFLAGS) -Isrc -std=c++14 -flto -O3 -c src/eventing/asio.cpp
-endif
 
-# For now we do rely on C++17 for OpenSSL support but we will be porting this work to C11
 ifeq ($(WITH_OPENSSL),1)
-	$(CXX) $(CXXFLAGS) -std=c++17 -flto -O3 -c src/crypto/*.cpp
+	$(CXX) $(CXXFLAGS) -fPIC -c src/crypto/*.cpp
 endif
-ifeq ($(WITH_BORINGSSL),1)
-	$(CXX) $(CXXFLAGS) -std=c++17 -flto -O3 -c src/crypto/*.cpp
-endif
-# Create a static library (try windows, then unix)
-	lib.exe /out:uSockets.a *.o || $(AR) rvs uSockets.a *.o
+	$(AR) rvs libusockets.a *.o
+	$(CC) -shared -o $(LIBTARGET) *.o -Wl,-soname,$(LIBTARGET) `$(PKG_CONFIG) --libs $(REQUIRES)` $(LDFLAGS)
+	sed -e "s:@PREFIX@:$(prefix):" -e "s:@REQUIRES@:$(REQUIRES):" \
+	-e "s:@LIB@:$(LIB):" -e "s:@VERSION@:$(VERSION):" usockets.pc.in > usockets.pc
-
-# BoringSSL needs cmake and golang
-.PHONY: boringssl
-boringssl:
-	cd boringssl && mkdir -p build && cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && make -j8
 
-# Builds all examples
-.PHONY: examples
-examples: default
-	for f in examples/*.c; do $(CC) -O3 $(CFLAGS) -o $$(basename "$$f" ".c")$(EXEC_SUFFIX) "$$f" $(LDFLAGS); done
-
-swift_examples:
-	swiftc -O -I . examples/swift_http_server/main.swift uSockets.a -o swift_http_server
+install:
+	install -d "$(DESTDIR)$(libdir)/pkgconfig" "$(DESTDIR)$(includedir)"
+	install -m 644 src/libusockets.h "$(DESTDIR)$(includedir)/"
+	install -m 755 $(LIBTARGET) "$(DESTDIR)$(libdir)"
+	ln -sf $(LIBTARGET) "$(DESTDIR)$(libdir)/libusockets.so"
+	install -m 755 libusockets.a "$(DESTDIR)$(libdir)/"
+	install -m 644 usockets.pc "$(DESTDIR)$(libdir)/pkgconfig/"
 
 clean:
 	rm -f *.o
 	rm -f *.a
+	rm -f *.so
 	rm -rf .certs
+	rm -f usockets.pc
+
+.PHONY: default install clean
diff --git a/usockets.pc.in b/usockets.pc.in
new file mode 100644
index 0000000..b818020
--- /dev/null
+++ b/usockets.pc.in
@@ -0,0 +1,12 @@
+prefix=@PREFIX@
+libdir=${prefix}/@LIB@
+includedir=${prefix}/include
+
+Name: uSockets
+Version: @VERSION@
+Description: eventing, networking and crypto for async applications.
+URL: https://github.com/uNetworking/uSockets
+
+Cflags: -I${includedir}
+Libs: -L${libdir} -lusockets
+Requires.private: @REQUIRES@