diff --git a/Makefile b/Makefile
index 16f613c..4bece6e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,87 +1,73 @@
-# 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++
-	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
+VERSION ?=	0.0
+
+PREFIX ?=	/usr
+LIB ?=		lib
+LIBDIR ?=	$(PREFIX)/$(LIB)
+INCDIR ?=	$(PREFIX)/include
+
+PKG_CONFIG ?=	pkg-config
+
+LIBTARGET =	libusockets.so
+LIBTARGETV =	$(LIBTARGET).$(VERSION)
+
+REQUIRES =
+COMMON_FLAGS =	-fPIC -Isrc
+
+# WITH_OPENSSL=1 enables OpenSSL 1.1+ support or BoringSSL
+# For now we need to link with C++ for OpenSSL support, but should be removed with time
+ifeq ($(WITH_OPENSSL),1)
+COMMON_FLAGS +=	-DLIBUS_USE_OPENSSL
+REQUIRES +=	libssl libcrypto
 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
+# WITH_ASIO builds with boost asio event-loop
 ifeq ($(WITH_ASIO),1)
-	override CFLAGS += -DLIBUS_USE_ASIO
-	override LDFLAGS += -lstdc++ -lpthread
-	override CXXFLAGS += -pthread -DLIBUS_USE_ASIO
+COMMON_FLAGS +=	-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
-
-override CFLAGS += -std=c11 -Isrc
-override LDFLAGS += uSockets.a
+CFLAGS +=	-std=c11 $(COMMON_FLAGS)
+CXXFLAGS +=	-std=c++17 $(COMMON_FLAGS)
 
 # By default we build the uSockets.a static library
 default:
-	rm -f *.o
-	$(CC) $(CFLAGS) -flto -O3 -c src/*.c src/eventing/*.c src/crypto/*.c
+	$(CC) $(CFLAGS) -c src/*.c src/eventing/*.c src/crypto/*.c
 # Also link in Boost Asio support
 ifeq ($(WITH_ASIO),1)
-	$(CXX) $(CXXFLAGS) -Isrc -std=c++14 -flto -O3 -c src/eventing/asio.cpp
+	$(CXX) $(CXXFLAGS) -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) -c src/crypto/*.cpp
 endif
-ifeq ($(WITH_BORINGSSL),1)
-	$(CXX) $(CXXFLAGS) -std=c++17 -flto -O3 -c src/crypto/*.cpp
-endif
-	$(AR) rvs uSockets.a *.o
-
-# BoringSSL needs cmake and golang
-.PHONY: boringssl
-boringssl:
-	cd boringssl && mkdir -p build && cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && make -j8
+	$(AR) rvs libusockets.a *.o
+	$(CXX) $(CXXFLAGS) -shared -o $(LIBTARGETV) *.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):" libusockets.pc.in > libusockets.pc
 
-# Builds all examples
-.PHONY: examples
-examples: default
-	for f in examples/*.c; do $(CC) -flto -O3 $(CFLAGS) -o $$(basename "$$f" ".c") "$$f" $(LDFLAGS); done
+install:
+	install -d "$(DESTDIR)$(LIBDIR)/pkgconfig" "$(DESTDIR)$(INCDIR)"
+	install -m 644 src/libusockets.h "$(DESTDIR)$(INCDIR)/"
+	install -m 755 $(LIBTARGETV) "$(DESTDIR)$(LIBDIR)"
+	ln -sf $(LIBTARGETV) "$(DESTDIR)$(LIBDIR)/$(LIBTARGET)"
+	install -m 755 libusockets.a "$(DESTDIR)$(LIBDIR)/"
+	install -m 644 libusockets.pc "$(DESTDIR)$(LIBDIR)/pkgconfig/"
 
-swift_examples:
-	swiftc -O -I . examples/swift_http_server/main.swift uSockets.a -o swift_http_server
+test:
+	rm -f localhost.pem localhost.crt
+	openssl req -x509 -out localhost.crt -keyout localhost.pem -newkey rsa:2048 -nodes -sha256 -subj '/CN=localhost' -extensions EXT -config localhost.conf
+	$(CXX) $(CXXFLAGS) examples/hammer_test.c libusockets.a -o hammer_test `$(PKG_CONFIG) --libs $(REQUIRES)` $(LDFLAGS)
+	./hammer_test
 
 clean:
 	rm -f *.o
 	rm -f *.a
+	rm -f *.so
 	rm -rf .certs
+	rm -f libusockets.pc
+
+.PHONY: default install clean
