Index: pjproject/trunk/pjmedia/build/Makefile
===================================================================
--- pjproject/trunk/pjmedia/build/Makefile	(revision 4637)
+++ pjproject/trunk/pjmedia/build/Makefile	(revision 4656)
@@ -10,4 +10,7 @@
 include $(PJDIR)/build/common.mak
 
+export LIBDIR := ../lib
+export BINDIR := ../bin
+
 RULES_MAK := $(PJDIR)/build/rules.mak
 
@@ -16,9 +19,23 @@
 PJNATH_LIB:=$(PJDIR)/pjnath/lib/libpjnath-$(TARGET_NAME)$(LIBEXT)
 
-export PJMEDIA_LIB:=../lib/libpjmedia-$(TARGET_NAME)$(LIBEXT)
-export PJMEDIA_CODEC_LIB:=../lib/libpjmedia-codec-$(TARGET_NAME)$(LIBEXT)
-export PJSDP_LIB:=../lib/libpjsdp-$(TARGET_NAME)$(LIBEXT)
-export PJMEDIA_AUDIODEV_LIB:=../lib/libpjmedia-audiodev-$(TARGET_NAME)$(LIBEXT)
-export PJMEDIA_VIDEODEV_LIB:=../lib/libpjmedia-videodev-$(TARGET_NAME)$(LIBEXT)
+export PJMEDIA_LIB:=libpjmedia-$(TARGET_NAME)$(LIBEXT)
+export PJMEDIA_CODEC_LIB:=libpjmedia-codec-$(TARGET_NAME)$(LIBEXT)
+export PJSDP_LIB:=libpjsdp-$(TARGET_NAME)$(LIBEXT)
+export PJMEDIA_AUDIODEV_LIB:=libpjmedia-audiodev-$(TARGET_NAME)$(LIBEXT)
+export PJMEDIA_VIDEODEV_LIB:=libpjmedia-videodev-$(TARGET_NAME)$(LIBEXT)
+
+ifeq ($(PJ_SHARED_LIBRARIES),)
+else
+export PJMEDIA_SONAME:=libpjmedia.$(SHLIB_SUFFIX)
+export PJMEDIA_SHLIB:=$(PJMEDIA_SONAME).$(PJ_VERSION_MAJOR)
+export PJMEDIA_CODEC_SONAME:=libpjmedia-codec.$(SHLIB_SUFFIX)
+export PJMEDIA_CODEC_SHLIB:=$(PJMEDIA_CODEC_SONAME).$(PJ_VERSION_MAJOR)
+export PJSDP_SONAME:=libpjsdp.$(SHLIB_SUFFIX)
+export PJSDP_SHLIB:=$(PJSDP_SONAME).$(PJ_VERSION_MAJOR)
+export PJMEDIA_AUDIODEV_SONAME:=libpjmedia-audiodev.$(SHLIB_SUFFIX)
+export PJMEDIA_AUDIODEV_SHLIB:=$(PJMEDIA_AUDIODEV_SONAME).$(PJ_VERSION_MAJOR)
+export PJMEDIA_VIDEODEV_SONAME:=libpjmedia-videodev.$(SHLIB_SUFFIX)
+export PJMEDIA_VIDEODEV_SHLIB:=$(PJMEDIA_VIDEODEV_SONAME).$(PJ_VERSION_MAJOR)
+endif
 
 
@@ -36,16 +53,9 @@
 export _CXXFLAGS:= $(_CFLAGS) $(CC_CXXFLAGS) $(OS_CXXFLAGS) $(M_CXXFLAGS) \
 		   $(HOST_CXXFLAGS) $(CXXFLAGS)
-export _LDFLAGS := $(subst /,$(HOST_PSEP),$(PJMEDIA_VIDEODEV_LIB)) \
-		   $(subst /,$(HOST_PSEP),$(PJMEDIA_CODEC_LIB)) \
-		   $(subst /,$(HOST_PSEP),$(PJMEDIA_LIB)) \
-		   $(subst /,$(HOST_PSEP),$(PJMEDIA_AUDIODEV_LIB)) \
-		   $(subst /,$(HOST_PSEP),$(PJLIB_LIB)) \
-		   $(subst /,$(HOST_PSEP),$(PJLIB_UTIL_LIB)) \
-		   $(subst /,$(HOST_PSEP),$(PJNATH_LIB)) \
-		   -L$(PJDIR)/third_party/lib \
-		   $(APP_THIRD_PARTY_LIBS) \
+
+export _LDFLAGS := $(APP_THIRD_PARTY_LIBS) \
 		   $(APP_THIRD_PARTY_EXT) \
 		   $(CC_LDFLAGS) $(OS_LDFLAGS) $(M_LDFLAGS) $(HOST_LDFLAGS) \
-		   $(LDFLAGS) 
+		   $(APP_LDFLAGS) $(LDFLAGS) 
 
 ###############################################################################
@@ -75,4 +85,10 @@
 export PJMEDIA_CFLAGS += $(_CFLAGS)
 export PJMEDIA_CXXFLAGS += $(_CXXFLAGS)
+export PJMEDIA_LDFLAGS += $(PJMEDIA_VIDEODEV_LDLIB) \
+			  $(PJMEDIA_AUDIODEV_LDLIB) \
+			  $(PJLIB_LDLIB) \
+			  $(PJLIB_UTIL_LDLIB) \
+			  $(PJNATH_LDLIB) \
+			  $(_LDFLAGS)
 
 
@@ -87,4 +103,6 @@
 export PJMEDIA_AUDIODEV_CFLAGS += $(_CFLAGS)
 export PJMEDIA_AUDIODEV_CXXFLAGS += $(_CXXFLAGS)
+export PJMEDIA_AUDIODEV_LDFLAGS += $(PJLIB_LDLIB) \
+				   $(_LDFLAGS)
 
 
@@ -97,4 +115,6 @@
 export PJMEDIA_VIDEODEV_CFLAGS += $(_CFLAGS)
 export PJMEDIA_VIDEODEV_CXXFLAGS += $(_CXXFLAGS)
+export PJMEDIA_VIDEODEV_LDFLAGS += $(PJLIB_LDLIB) \
+				   $(_LDFLAGS)
 
 
@@ -110,4 +130,8 @@
 export PJSDP_CFLAGS += $(_CFLAGS)
 export PJSDP_CXXFLAGS += $(_CXXFLAGS)
+export PJSDP_LDFLAGS += $(PJMEDIA_LDLIB) \
+			$(PJLIB_LDLIB) \
+			$(PJLIB_UTIL_LDLIB) \
+			$(_LDFLAGS)
 
 
@@ -125,5 +149,7 @@
 export PJMEDIA_CODEC_CXXFLAGS += $(_CXXFLAGS) $(GSM_CFLAGS) $(SPEEX_CFLAGS) \
 			$(ILBC_CFLAGS) $(IPP_CFLAGS) $(G7221_CFLAGS)
-
+export PJMEDIA_CODEC_LDFLAGS += $(PJMEDIA_LDLIB) \
+				$(PJLIB_LDLIB) \
+				$(_LDFLAGS)
 
 ###############################################################################
@@ -137,6 +163,13 @@
 export PJMEDIA_TEST_CFLAGS += $(_CFLAGS)
 export PJMEDIA_TEST_CXXFLAGS += $(_CXXFLAGS)
-export PJMEDIA_TEST_LDFLAGS += $(_LDFLAGS)
-export PJMEDIA_TEST_EXE:=../bin/pjmedia-test-$(TARGET_NAME)$(HOST_EXE)
+export PJMEDIA_TEST_LDFLAGS += $(PJMEDIA_CODEC_LDLIB) \
+			       $(PJMEDIA_VIDEODEV_LDLIB) \
+			       $(PJMEDIA_LDLIB) \
+			       $(PJMEDIA_AUDIODEV_LDLIB) \
+			       $(PJLIB_LDLIB) \
+			       $(PJLIB_UTIL_LDLIB) \
+			       $(PJNATH_LDLIB) \
+			       $(_LDFLAGS)
+export PJMEDIA_TEST_EXE:=pjmedia-test-$(TARGET_NAME)$(HOST_EXE)
 
 	
@@ -147,5 +180,10 @@
 # $(TARGET) is defined in os-$(OS_NAME).mak file in current directory.
 #
-TARGETS := pjmedia pjmedia-videodev pjmedia-audiodev pjmedia-codec pjsdp pjmedia-test
+TARGETS := $(PJMEDIA_LIB) $(PJMEDIA_SONAME) \
+	   $(PJMEDIA_CODEC_LIB) $(PJMEDIA_CODEC_SONAME)\
+	   $(PJMEDIA_VIDEODEV_LIB) $(PJMEDIA_VIDEODEV_SONAME) \
+	   $(PJMEDIA_AUDIODEV_LIB) $(PJMEDIA_AUDIODEV_SONAME) \
+	   $(PJSDP_LIB) $(PJSDP_SONAME) \
+	   $(PJMEDIA_TEST_EXE)
 
 all: $(TARGETS)
@@ -165,45 +203,59 @@
 distclean: realclean
 
-.PHONY: dep depend clean realclean distclean
+.PHONY: all dep depend clean realclean distclean
 .PHONY: $(TARGETS)
-.PHONY: $(PJMEDIA_LIB) $(PJMEDIA_CODEC_LIB) $(PJMEDIA_VIDEODEV_LIB) $(PJMEDIA_AUDIODEV_LIB) $(PJSDP_LIB) $(PJMEDIA_TEST_EXE)
+.PHONY: $(PJMEDIA_LIB) $(PJMEDIA_SONAME)
+.PHONY: $(PJMEDIA_CODEC_LIB) $(PJMEDIA_CODEC_SONAME)
+.PHONY: $(PJMEDIA_VIDEODEV_LIB) $(PJMEDIA_VIDEODEV_SONAME)
+.PHONY: $(PJMEDIA_AUDIODEV_LIB) $(PJMEDIA_AUDIODEV_SONAME)
+.PHONY: $(PJSDP_LIB) $(PJSDP_SONAME)
+.PHONY: $(PJMEDIA_TEST_EXE)
 
 pjmedia: $(PJMEDIA_LIB)
-$(PJMEDIA_LIB):
-	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA app=pjmedia $(PJMEDIA_LIB)
+$(PJMEDIA_SONAME): $(PJMEDIA_LIB)
+$(PJMEDIA_LIB) $(PJMEDIA_SONAME): $(PJMEDIA_AUDIODEV_LIB) $(PJMEDIA_AUDIODEV_SONAME) $(PJMEDIA_VIDEODEV_LIB) $(PJMEDIA_VIDEODEV_SONAME)
+	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA app=pjmedia $(subst /,$(HOST_PSEP),$(LIBDIR)/$@)
 
 pjmedia-codec: $(PJMEDIA_CODEC_LIB)
-$(PJMEDIA_CODEC_LIB):
-	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA_CODEC app=pjmedia-codec $(PJMEDIA_CODEC_LIB)
+$(PJMEDIA_CODEC_SONAME): $(PJMEDIA_CODEC_LIB)
+$(PJMEDIA_CODEC_LIB) $(PJMEDIA_CODEC_SONAME): $(PJMEDIA_LIB) $(PJMEDIA_SONAME)
+	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA_CODEC app=pjmedia-codec $(subst /,$(HOST_PSEP),$(LIBDIR)/$@)
 
 pjmedia-videodev: $(PJMEDIA_VIDEODEV_LIB)
-$(PJMEDIA_VIDEODEV_LIB):
-	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA_VIDEODEV app=pjmedia-videodev $(PJMEDIA_VIDEODEV_LIB)
+$(PJMEDIA_VIDEODEV_SONAME): $(PJMEDIA_VIDEODEV_LIB)
+$(PJMEDIA_VIDEODEV_LIB) $(PJMEDIA_VIDEODEV_SONAME):
+	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA_VIDEODEV app=pjmedia-videodev $(subst /,$(HOST_PSEP),$(LIBDIR)/$@)
 
 pjmedia-audiodev: $(PJMEDIA_AUDIODEV_LIB)
-$(PJMEDIA_AUDIODEV_LIB):
-	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA_AUDIODEV app=pjmedia-audiodev $(PJMEDIA_AUDIODEV_LIB)
+$(PJMEDIA_AUDIODEV_SONAME): $(PJMEDIA_AUDIODEV_LIB)
+$(PJMEDIA_AUDIODEV_LIB) $(PJMEDIA_AUDIODEV_SONAME):
+	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA_AUDIODEV app=pjmedia-audiodev $(subst /,$(HOST_PSEP),$(LIBDIR)/$@)
 
 pjsdp: $(PJSDP_LIB)
-$(PJSDP_LIB):
-	$(MAKE) -f $(RULES_MAK) APP=PJSDP app=pjsdp $(PJSDP_LIB)
+$(PJSDP_SONAME): $(PJSDP_LIB)
+$(PJSDP_LIB) $(PJSDP_SONAME): $(PJMEDIA_LIB) $(PJMEDIA_SONAME)
+	$(MAKE) -f $(RULES_MAK) APP=PJSDP app=pjsdp $(LIBDIR)/$@
 
 pjmedia-test: $(PJMEDIA_TEST_EXE)
-$(PJMEDIA_TEST_EXE): $(PJMEDIA_LIB) $(PJMEDIA_CODEC_LIB)
-	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA_TEST app=pjmedia-test $(PJMEDIA_TEST_EXE)
-
-.PHONY: ../lib/pjmedia.ko
-../lib/pjmedia.ko:
+$(PJMEDIA_TEST_EXE): $(PJMEDIA_LIB) $(PJMEDIA_SONAME)
+$(PJMEDIA_TEST_EXE): $(PJMEDIA_AUDIODEV_LIB) $(PJMEDIA_AUDIODEV_SONAME)
+$(PJMEDIA_TEST_EXE): $(PJMEDIA_VIDEODEV_LIB) $(PJMEDIA_VIDEODEV_SONAME)
+$(PJMEDIA_TEST_EXE): $(PJMEDIA_CODEC_LIB) $(PJMEDIA_CODEC_SONAME)
+$(PJMEDIA_TEST_EXE):
+	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA_TEST app=pjmedia-test $(BINDIR)/$@
+
+.PHONY: pjmedia.ko
+pjmedia.ko:
 	echo Making $@
-	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA app=pjmedia $@
-
-.PHONY: ../lib/pjmedia-codec.ko
-../lib/pjmedia-codec.ko:
+	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA app=pjmedia $(LIBDIR)/$@
+
+.PHONY: pjmedia-codec.ko
+pjmedia-codec.ko:
 	echo Making $@
-	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA_CODEC app=pjmedia-codec $@
-
-.PHONY: ../lib/pjmedia-test.ko
-../lib/pjmedia-test.ko:
-	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA_TEST app=pjmedia-test $@
+	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA_CODEC app=pjmedia-codec $(LIBDIR)/$@
+
+.PHONY: pjmedia-test.ko
+pjmedia-test.ko:
+	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA_TEST app=pjmedia-test $(LIBDIR)/$@
 
 clean:
@@ -237,5 +289,5 @@
 	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA_TEST app=pjmedia-test $@
 	$(MAKE) -f $(RULES_MAK) APP=PJSDP app=pjsdp $@
-	echo '$(PJMEDIA_TEST_EXE): $(PJMEDIA_LIB) $(PJMEDIA_CODEC_LIB) $(PJNATH_LIB) $(PJLIB_UTIL_LIB) $(PJLIB_LIB)' >> .pjmedia-test-$(TARGET_NAME).depend
-
-
+	echo '$(BINDIR)/$(PJMEDIA_TEST_EXE): $(LIBDIR)/$(PJMEDIA_LIB) $(LIBDIR)/$(PJMEDIA_CODEC_LIB) $(PJNATH_LIB) $(PJLIB_UTIL_LIB) $(PJLIB_LIB)' >> .pjmedia-test-$(TARGET_NAME).depend
+
+
