Index: pjproject/trunk/pjlib/build/Makefile
===================================================================
--- pjproject/trunk/pjlib/build/Makefile	(revision 4637)
+++ pjproject/trunk/pjlib/build/Makefile	(revision 4656)
@@ -3,8 +3,16 @@
 include $(PJDIR)/build/common.mak
 
+export LIBDIR := ../lib
+export BINDIR := ../bin
+
 RULES_MAK := $(PJDIR)/build/rules.mak
 
+export PJLIB_LIB := libpj-$(TARGET_NAME)$(LIBEXT)
 
-export PJLIB_LIB := ../lib/libpj-$(TARGET_NAME)$(LIBEXT)
+ifeq ($(PJ_SHARED_LIBRARIES),)
+else
+export PJLIB_SONAME := libpj.$(SHLIB_SUFFIX)
+export PJLIB_SHLIB := $(PJLIB_SONAME).$(PJ_VERSION_MAJOR)
+endif
 
 ###############################################################################
@@ -15,7 +23,7 @@
 export _CXXFLAGS:= $(_CFLAGS) $(CC_CXXFLAGS) $(OS_CXXFLAGS) $(M_CXXFLAGS) \
 		   $(HOST_CXXFLAGS) $(CXXFLAGS)
-export _LDFLAGS := $(subst /,$(HOST_PSEP),$(PJLIB_LIB)) \
-		   $(CC_LDFLAGS) $(OS_LDFLAGS) $(M_LDFLAGS) $(HOST_LDFLAGS) \
-		   $(LDFLAGS) 
+export _LDFLAGS := $(CC_LDFLAGS) $(OS_LDFLAGS) $(M_LDFLAGS) $(HOST_LDFLAGS) \
+		   $(APP_LDFLAGS) $(LDFLAGS) 
+
 
 ###############################################################################
@@ -32,4 +40,5 @@
 export PJLIB_CFLAGS += $(_CFLAGS)
 export PJLIB_CXXFLAGS += $(_CXXFLAGS)
+export PJLIB_LDFLAGS += $(_LDFLAGS)
 
 ###############################################################################
@@ -47,8 +56,8 @@
 export TEST_CFLAGS += $(_CFLAGS)
 export TEST_CXXFLAGS += $(_CXXFLAGS)
-export TEST_LDFLAGS += $(_LDFLAGS)
-export TEST_EXE := ../bin/pjlib-test-$(TARGET_NAME)$(HOST_EXE)
+export TEST_LDFLAGS += $(PJLIB_LDLIB) $(_LDFLAGS)
+export TEST_EXE := pjlib-test-$(TARGET_NAME)$(HOST_EXE)
 
-	
+
 export CC_OUT CC AR RANLIB HOST_MV HOST_RM HOST_RMDIR HOST_MKDIR OBJEXT LD LDOUT 
 ###############################################################################
@@ -77,10 +86,11 @@
 	$(MAKE) -f $(RULES_MAK) APP=PJLIB app=pjlib depend
 	$(MAKE) -f $(RULES_MAK) APP=TEST app=pjlib-test depend
-	echo '$(TEST_EXE): $(PJLIB_LIB)' >> .pjlib-test-$(TARGET_NAME).depend
+	echo '$(BINDIR)/$(TEST_EXE): $(LIBDIR)/$(PJLIB_LIB)' >> .pjlib-test-$(TARGET_NAME).depend
 
 
-.PHONY: dep depend clean realclean distclean
+.PHONY: all dep depend clean realclean distclean
 .PHONY: $(TARGETS)
-.PHONY: $(PJLIB_LIB) $(TEST_EXE)
+.PHONY: $(PJLIB_LIB) $(PJLIB_SONAME)
+.PHONY: $(TEST_EXE)
 
 dep: depend
@@ -88,5 +98,8 @@
 pjlib: $(PJLIB_LIB)
 $(PJLIB_LIB): ../include/pj/config_site.h
-	$(MAKE) -f $(RULES_MAK) APP=PJLIB app=pjlib $(PJLIB_LIB)
+
+$(PJLIB_SONAME): $(PJLIB_LIB)
+$(PJLIB_LIB) $(PJLIB_SONAME):
+	$(MAKE) -f $(RULES_MAK) APP=PJLIB app=pjlib $(subst /,$(HOST_PSEP),$(LIBDIR)/$@)
 
 ../include/pj/config_site.h:
@@ -94,15 +107,15 @@
 
 pjlib-test: $(TEST_EXE)
-$(TEST_EXE): $(PJLIB_LIB)
-	$(MAKE) -f $(RULES_MAK) APP=TEST app=pjlib-test $(TEST_EXE)
+$(TEST_EXE): $(PJLIB_LIB) $(PJLIB_SONAME)
+	$(MAKE) -f $(RULES_MAK) APP=TEST app=pjlib-test $(subst /,$(HOST_PSEP),$(BINDIR)/$@)
 
-.PHONY: ../lib/pjlib.ko
-../lib/pjlib.ko:
+.PHONY: pjlib.ko
+pjlib.ko:
 	echo Making $@
-	$(MAKE) -f $(RULES_MAK) APP=PJLIB app=pjlib $@
+	$(MAKE) -f $(RULES_MAK) APP=PJLIB app=pjlib $(subst /,$(HOST_PSEP),$(LIBDIR)/$@)
 
-.PHONY: ../lib/pjlib-test.ko
-../lib/pjlib-test.ko:
-	$(MAKE) -f $(RULES_MAK) APP=TEST app=pjlib-test $@
+.PHONY: pjlib-test.ko
+pjlib-test.ko:
+	$(MAKE) -f $(RULES_MAK) APP=TEST app=pjlib-test $(subst /,$(HOST_PSEP),$(LIBDIR)/$@)
 
 clean:
Index: pjproject/trunk/pjlib/build/os-auto.mak.in
===================================================================
--- pjproject/trunk/pjlib/build/os-auto.mak.in	(revision 4637)
+++ pjproject/trunk/pjlib/build/os-auto.mak.in	(revision 4656)
@@ -30,5 +30,5 @@
 # operating system.
 #
-export TARGETS	    =	pjlib pjlib-test
+export TARGETS	    =	$(PJLIB_LIB) $(PJLIB_SONAME) $(TEST_EXE)
 
 
Index: pjproject/trunk/pjlib/build/os-darwinos.mak
===================================================================
--- pjproject/trunk/pjlib/build/os-darwinos.mak	(revision 4637)
+++ pjproject/trunk/pjlib/build/os-darwinos.mak	(revision 4656)
@@ -34,4 +34,4 @@
 # operating system.
 #
-export TARGETS	    =	pjlib pjlib-test
+export TARGETS	    =	$(PJLIB_LIB) $(PJLIB_SONAME) $(TEST_EXE)
 
Index: pjproject/trunk/pjlib/build/os-linux-kernel.mak
===================================================================
--- pjproject/trunk/pjlib/build/os-linux-kernel.mak	(revision 4637)
+++ pjproject/trunk/pjlib/build/os-linux-kernel.mak	(revision 4656)
@@ -43,5 +43,5 @@
 # operating system.
 #
-export TARGETS :=	../lib/pjlib.ko ../lib/pjlib-test.ko
+export TARGETS :=	pjlib.ko pjlib-test.ko
 
 
Index: pjproject/trunk/pjlib/build/os-linux.mak
===================================================================
--- pjproject/trunk/pjlib/build/os-linux.mak	(revision 4637)
+++ pjproject/trunk/pjlib/build/os-linux.mak	(revision 4656)
@@ -36,4 +36,4 @@
 # operating system.
 #
-export TARGETS	    =	pjlib pjlib-test
+export TARGETS	    =	$(PJLIB_LIB) $(PJLIB_SONAME) $(TEST_EXE)
 
Index: pjproject/trunk/pjlib/build/os-rtems.mak
===================================================================
--- pjproject/trunk/pjlib/build/os-rtems.mak	(revision 4637)
+++ pjproject/trunk/pjlib/build/os-rtems.mak	(revision 4656)
@@ -41,5 +41,5 @@
 # operating system.
 #
-export TARGETS	    =	pjlib pjlib-test
+export TARGETS	    =	$(PJLIB_LIB) $(TEST_EXE)
 
 
Index: pjproject/trunk/pjlib/build/os-sunos.mak
===================================================================
--- pjproject/trunk/pjlib/build/os-sunos.mak	(revision 4637)
+++ pjproject/trunk/pjlib/build/os-sunos.mak	(revision 4656)
@@ -33,4 +33,4 @@
 # operating system.
 #
-export TARGETS	    =	pjlib pjlib-test
+export TARGETS	    =	$(PJLIB_LIB) $(PJLIB_SONAME) $(TEST_EXE)
 
Index: pjproject/trunk/pjlib/build/os-win32.mak
===================================================================
--- pjproject/trunk/pjlib/build/os-win32.mak	(revision 4637)
+++ pjproject/trunk/pjlib/build/os-win32.mak	(revision 4656)
@@ -30,4 +30,4 @@
 # operating system.
 #
-export TARGETS	    =	pjlib pjlib-test
+export TARGETS	    =	$(PJLIB_LIB) $(TEST_EXE)
 
