diff --git a/Makefile b/Makefile index fa6e2ff..529ed74 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,14 @@ +DESTDIR ?= + +prefix ?= "/usr/local" +exec_prefix ?= "$(prefix)" +libdir ?= "$(exec_prefix)/lib" +includedir?= "$(exec_prefix)/include/uSockets" + +# OpenBSD specific library version +LIBTARGET = libusockets.so.$(LIBusockets_VERSION) + + # WITH_OPENSSL=1 enables OpenSSL 1.1+ support ifeq ($(WITH_OPENSSL),1) override CFLAGS += -DLIBUS_USE_OPENSSL @@ -33,13 +44,33 @@ ifeq ($(WITH_ASAN),1) endif override CFLAGS += -std=c11 -Isrc -override LDFLAGS += uSockets.a -# By default we build the uSockets.a static library -default: +static: rm -f *.o - $(CC) $(CFLAGS) -flto -O3 -c src/*.c src/eventing/*.c src/crypto/*.c - $(AR) rvs uSockets.a *.o + $(CC) $(CFLAGS) -c src/*.c src/eventing/*.c src/crypto/*.c + $(AR) rvs libusockets.a *.o + +dynamic: + rm -f *.o + $(CC) -fPIC -c src/*.c src/eventing/*.c src/crypto/*.c $(CFLAGS) + $(CC) -shared -fPIC -Wl,-soname,$(LIBTARGET) $(CFLAGS) -o $(LIBTARGET) *.o $(LDFLAGS) + +default: static dynamic + +install: + # install the folders needed (making sure that the exist) + install -d "$(DESTDIR)$(libdir)" \ + "$(DESTDIR)$(includedir)/internal/eventing" \ + "$(DESTDIR)$(includedir)/internal/networking" + # OpenBSD specific library version + install -m 755 $(LIBTARGET) "$(DESTDIR)$(libdir)/" + # install static library + install -m 755 libusockets.a "$(DESTDIR)$(libdir)/" + # we also install all the header files + install src/*.h "$(DESTDIR)$(includedir)/" + install -m 644 src/internal/*.h "$(DESTDIR)$(includedir)/internal/" + install -m 644 src/internal/eventing/*.h "$(DESTDIR)$(includedir)/internal/eventing/" + install -m 644 src/internal/networking/*.h "$(DESTDIR)$(includedir)/internal/networking/" # Builds all examples .PHONY: examples @@ -52,4 +83,5 @@ swift_examples: clean: rm -f *.o rm -f *.a + rm -f *.so rm -rf .certs