diff --git a/Makefile b/Makefile
index 814a592..07c71ca 100644
--- a/Makefile
+++ b/Makefile
@@ -20,7 +20,7 @@ include Makethird
 # Do not specify CFLAGS or LIBS on the make invocation line - specify
 # XCFLAGS or XLIBS instead. Make ignores any lines in the makefile that
 # set a variable that was set on the command line.
-CFLAGS += $(XCFLAGS) -Iinclude
+CFLAGS += $(XCFLAGS) -Iinclude -fPIC
 LIBS += $(XLIBS) -lm
 
 ifneq ($(threading),no)
@@ -58,6 +58,7 @@ ifdef RANLIB
   RANLIB_CMD = $(QUIET_RANLIB) $(RANLIB) $@
 endif
 LINK_CMD = $(QUIET_LINK) $(MKTGTDIR) ; $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
+LINK_SHARED_CMD = $(QUIET_LINK) $(CC) $(LDFLAGS) -shared -Wl,-soname,$(notdir $@) -o $@ $^ $(LIBS)
 TAGS_CMD = $(QUIET_TAGS) ctags -R --c-kinds=+p
 WINDRES_CMD = $(QUIET_WINDRES) $(MKTGTDIR) ; $(WINDRES) $< $@
 OBJCOPY_CMD = $(QUIET_OBJCOPY) $(MKTGTDIR) ; $(LD) -r -b binary -o $@ $<
@@ -68,6 +69,9 @@ $(OUT)/%.a :
 	$(AR_CMD)
 	$(RANLIB_CMD)
 
+$(OUT)/%.so.0: $(OUT)/%.a
+	$(LINK_SHARED_CMD)
+	
 $(OUT)/%.exe: %.c
 	$(LINK_CMD)
 
@@ -189,8 +193,8 @@ generate: source/pdf/js/util.js.h
 
 # --- Library ---
 
-MUPDF_LIB = $(OUT)/libmupdf.a
-THIRD_LIB = $(OUT)/libmupdf-third.a
+MUPDF_LIB = $(OUT)/libmupdf.so.0
+THIRD_LIB = $(OUT)/libmupdf-third.so.0
 THREAD_LIB = $(OUT)/libmupdf-threads.a
 PKCS7_LIB = $(OUT)/libmupdf-pkcs7.a
 
