Index: pjproject/trunk/build.mak.in
===================================================================
--- pjproject/trunk/build.mak.in	(revision 2182)
+++ pjproject/trunk/build.mak.in	(revision 2183)
@@ -8,21 +8,28 @@
 export LINUX_POLL := @ac_linux_poll@ 
 
+LIB_SUFFIX = $(TARGET_NAME).a
+
 # Determine which party libraries to use
 export APP_THIRD_PARTY_LIBS := -lresample-$(TARGET_NAME) -lmilenage-$(TARGET_NAME) -lsrtp-$(TARGET_NAME)
+export APP_THIRD_PARTY_LIB_FILES = $(PJ_DIR)/third_party/lib/libresample-$(LIB_SUFFIX) $(PJ_DIR)/third_party/lib/libmilenage-$(LIB_SUFFIX) $(PJ_DIR)/third_party/lib/libsrtp-$(LIB_SUFFIX)
 
 ifneq (@ac_no_gsm_codec@,1)
 APP_THIRD_PARTY_LIBS += -lgsmcodec-$(TARGET_NAME)
+APP_THIRD_PARTY_LIB_FILES += $(PJ_DIR)/third_party/lib/libgsmcodec-$(LIB_SUFFIX)
 endif
 
 ifneq (@ac_no_speex_codec@,1)
 APP_THIRD_PARTY_LIBS += -lspeex-$(TARGET_NAME)
+APP_THIRD_PARTY_LIB_FILES += $(PJ_DIR)/third_party/lib/libspeex-$(LIB_SUFFIX)
 endif
 
 ifneq (@ac_no_ilbc_codec@,1)
 APP_THIRD_PARTY_LIBS += -lilbccodec-$(TARGET_NAME)
+APP_THIRD_PARTY_LIB_FILES += $(PJ_DIR)/third_party/lib/libilbccodec-$(LIB_SUFFIX)
 endif
 
 ifneq ($(findstring pa,@ac_pjmedia_snd@),)
 APP_THIRD_PARTY_LIBS += -lportaudio-$(TARGET_NAME)
+APP_THIRD_PARTY_LIB_FILES += $(PJ_DIR)/third_party/lib/libportaudio-$(LIB_SUFFIX)
 endif
 
@@ -57,4 +64,14 @@
 	-lpj-$(TARGET_NAME)\
 	@LIBS@
+export APP_LIB_FILES = $(PJ_DIR)/pjsip/lib/libpjsua-$(LIB_SUFFIX) \
+	$(PJ_DIR)/pjsip/lib/libpjsip-ua-$(LIB_SUFFIX) \
+	$(PJ_DIR)/pjsip/lib/libpjsip-simple-$(LIB_SUFFIX) \
+	$(PJ_DIR)/pjsip/lib/libpjsip-$(LIB_SUFFIX) \
+	$(PJ_DIR)/pjmedia/lib/libpjmedia-codec-$(LIB_SUFFIX) \
+	$(PJ_DIR)/pjmedia/lib/libpjmedia-$(LIB_SUFFIX) \
+	$(PJ_DIR)/pjnath/lib/libpjnath-$(LIB_SUFFIX) \
+	$(PJ_DIR)/pjlib-util/lib/libpjlib-util-$(LIB_SUFFIX) \
+	$(APP_THIRD_PARTY_LIB_FILES) \
+	$(PJ_DIR)/pjlib/lib/libpj-$(LIB_SUFFIX)
 
 export PJ_DIR := $(PJDIR)
@@ -64,3 +81,4 @@
 export PJ_LDFLAGS := $(APP_LDFLAGS)
 export PJ_LDLIBS := $(APP_LDLIBS)
+export PJ_LIB_FILES := $(APP_LIB_FILES)
 
Index: pjproject/trunk/build/rules.mak
===================================================================
--- pjproject/trunk/build/rules.mak	(revision 2182)
+++ pjproject/trunk/build/rules.mak	(revision 2183)
@@ -75,9 +75,11 @@
 	@echo LIBDIR=$(LIBDIR)
 
-$(LIB): $(LIBDIR) $(OBJDIRS) $(OBJS) $($(APP)_EXTRA_DEP)
+$(LIB): $(OBJDIRS) $(OBJS) $($(APP)_EXTRA_DEP)
+	if test ! -d $(LIBDIR); then $(subst @@,$(subst /,$(HOST_PSEP),$(LIBDIR)),$(HOST_MKDIR)); fi
 	$(AR) $(LIB) $(OBJS)
 	$(RANLIB) $(LIB)
 
-$(EXE): $(BINDIR) $(OBJDIRS) $(OBJS) $($(APP)_EXTRA_DEP)
+$(EXE): $(OBJDIRS) $(OBJS) $($(APP)_EXTRA_DEP)
+	if test ! -d $(BINDIR); then $(subst @@,$(subst /,$(HOST_PSEP),$(BINDIR)),$(HOST_MKDIR)); fi
 	$(LD) $(LDOUT)$(subst /,$(HOST_PSEP),$(EXE)) \
 	    $(subst /,$(HOST_PSEP),$(OBJS)) $($(APP)_LDFLAGS)
Index: pjproject/trunk/pjlib-util/build/Makefile
===================================================================
--- pjproject/trunk/pjlib-util/build/Makefile	(revision 2182)
+++ pjproject/trunk/pjlib-util/build/Makefile	(revision 2183)
@@ -69,5 +69,5 @@
 	$(MAKE) -f $(RULES_MAK) APP=PJLIB_UTIL app=pjlib-util $(PJLIB_UTIL_LIB)
 
-pjlib-util-test: $(PJLIB_LIB)
+pjlib-util-test:
 	$(MAKE) -f $(RULES_MAK) APP=UTIL_TEST app=pjlib-util-test $(UTIL_TEST_EXE)
 
@@ -94,5 +94,5 @@
 	$(MAKE) -f $(RULES_MAK) APP=PJLIB_UTIL app=pjlib-util $@
 	$(MAKE) -f $(RULES_MAK) APP=UTIL_TEST app=pjlib-util-test $@
-	echo '$(TEST_EXE): $(PJLIB_UTIL_LIB)' >> .pjlib-util-test-$(TARGET_NAME).depend; \
+	echo '$(UTIL_TEST_EXE): $(PJLIB_UTIL_LIB) $(PJLIB_LIB)' >> .pjlib-util-test-$(TARGET_NAME).depend; \
 
 
Index: pjproject/trunk/pjmedia/build/Makefile
===================================================================
--- pjproject/trunk/pjmedia/build/Makefile	(revision 2182)
+++ pjproject/trunk/pjmedia/build/Makefile	(revision 2183)
@@ -172,7 +172,5 @@
 	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA_TEST app=pjmedia-test $@
 	$(MAKE) -f $(RULES_MAK) APP=PJSDP app=pjsdp $@
-	echo '$(PJMEDIA_LIB): .pjmedia-$(TARGET_NAME).depend' >> .pjmedia-$(TARGET_NAME).depend; \
-	echo '$(PJMEDIA_CODEC_LIB): .pjmedia-codec-$(TARGET_NAME).depend' >> .pjmedia-codec-$(TARGET_NAME).depend; \
-	echo '$(PJMEDIA_TEST_EXE): $(PJMEDIA_LIB) $(PJMEDIA_CODEC_LIB)' >> .pjmedia-test-$(TARGET_NAME).depend; \
+	echo '$(PJMEDIA_TEST_EXE): $(PJMEDIA_LIB) $(PJMEDIA_CODEC_LIB) $(PJNATH_LIB) $(PJLIB_UTIL_LIB) $(PJLIB_LIB)' >> .pjmedia-test-$(TARGET_NAME).depend
 
 
Index: pjproject/trunk/pjnath/build/Makefile
===================================================================
--- pjproject/trunk/pjnath/build/Makefile	(revision 2182)
+++ pjproject/trunk/pjnath/build/Makefile	(revision 2183)
@@ -132,5 +132,7 @@
 	$(MAKE) -f $(RULES_MAK) APP=PJTURN_CLIENT app=pjturn-client $@
 	$(MAKE) -f $(RULES_MAK) APP=PJTURN_SRV app=pjturn-srv $@
-	echo '$(TEST_EXE): $(PJNATH_LIB)' >> .pjnath-test-$(TARGET_NAME).depend; \
+	echo '$(PJNATH_TEST_EXE): $(PJNATH_LIB) $(PJLIB_UTIL_LIB) $(PJLIB_LIB)' >> .pjnath-test-$(TARGET_NAME).depend
+	echo '$(PJTURN_CLIENT_EXE): $(PJNATH_LIB) $(PJLIB_UTIL_LIB) $(PJLIB_LIB)' >> .pjturn-client-$(TARGET_NAME).depend
+	echo '$(PJTURN_SRV_EXE): $(PJNATH_LIB) $(PJLIB_UTIL_LIB) $(PJLIB_LIB)' >> .pjturn-srv-$(TARGET_NAME).depend
 
 
Index: pjproject/trunk/pjsip-apps/build/Makefile
===================================================================
--- pjproject/trunk/pjsip-apps/build/Makefile	(revision 2182)
+++ pjproject/trunk/pjsip-apps/build/Makefile	(revision 2183)
@@ -71,5 +71,5 @@
 	$(MAKE) -f Samples.mak $@
 	@if test "$@" = "depend"; then \
-	  echo '$(PJSUA_EXE): $(PJSIP_LIB) $(PJSIP_UA_LIB) $(PJSIP_SIMPLE) $(PJSUA_LIB_LIB) $(PJLIB_LIB) $(PJLIB_UTIL_LIB) $(PJNATH_LIB) $(PJMEDIA_LIB) $(PJMEDIA_CODEC_LIB) Makefile' >> .pjsua-$(TARGET_NAME).depend; \
+	  echo '$(PJSUA_EXE): $(APP_LIB_FILES)' >> .pjsua-$(TARGET_NAME).depend; \
 	fi
 
Index: pjproject/trunk/pjsip-apps/build/Samples.mak
===================================================================
--- pjproject/trunk/pjsip-apps/build/Samples.mak	(revision 2182)
+++ pjproject/trunk/pjsip-apps/build/Samples.mak	(revision 2183)
@@ -42,5 +42,5 @@
 all: $(OBJDIR) $(EXES)
 
-$(BINDIR)/%-$(TARGET_NAME)$(HOST_EXE): $(OBJDIR)/%$(OBJEXT) $(LIBS)
+$(BINDIR)/%-$(TARGET_NAME)$(HOST_EXE): $(OBJDIR)/%$(OBJEXT) $(PJ_LIB_FILES)
 	$(LD) $(LDOUT)$(subst /,$(HOST_PSEP),$@) \
 	    $(subst /,$(HOST_PSEP),$<) \
Index: pjproject/trunk/pjsip/build/Makefile
===================================================================
--- pjproject/trunk/pjsip/build/Makefile	(revision 2182)
+++ pjproject/trunk/pjsip/build/Makefile	(revision 2183)
@@ -156,5 +156,5 @@
 	$(MAKE) -f $(RULES_MAK) APP=PJSUA_LIB app=pjsua-lib $@
 
-clean depend:
+clean:
 	$(MAKE) -f $(RULES_MAK) APP=PJSIP app=pjsip $@
 	$(MAKE) -f $(RULES_MAK) APP=PJSIP_UA app=pjsip-ua $@
@@ -162,4 +162,12 @@
 	$(MAKE) -f $(RULES_MAK) APP=PJSUA_LIB app=pjsua-lib $@
 	$(MAKE) -f $(RULES_MAK) APP=TEST app=pjsip-test $@
+
+depend:
+	$(MAKE) -f $(RULES_MAK) APP=PJSIP app=pjsip $@
+	$(MAKE) -f $(RULES_MAK) APP=PJSIP_UA app=pjsip-ua $@
+	$(MAKE) -f $(RULES_MAK) APP=PJSIP_SIMPLE app=pjsip-simple $@
+	$(MAKE) -f $(RULES_MAK) APP=PJSUA_LIB app=pjsua-lib $@
+	$(MAKE) -f $(RULES_MAK) APP=TEST app=pjsip-test $@
+	echo '$(TEST_EXE): $(PJMEDIA_LIB) $(PJSUA_LIB_LIB) $(PJSIP_SIMPLE_LIB) $(PJSIP_UA_LIB) $(PJSIP_LIB) $(PJNATH_LIB) $(PJLIB_UTIL_LIB) $(PJLIB_LIB)' >> .pjsip-test-$(TARGET_NAME).depend
 
 realclean:
Index: pjproject/trunk/third_party/build/gsm/Makefile
===================================================================
--- pjproject/trunk/third_party/build/gsm/Makefile	(revision 2182)
+++ pjproject/trunk/third_party/build/gsm/Makefile	(revision 2183)
@@ -61,5 +61,4 @@
 depend:
 	$(MAKE) -f $(RULES_MAK) APP=GSM_CODEC app=libgsmcodec $@
-	echo '$(GSM_CODEC_LIB): .libgsmcodec-$(TARGET_NAME).depend' >> .libgsmcodec-$(TARGET_NAME).depend; \
 
 
Index: pjproject/trunk/third_party/build/ilbc/Makefile
===================================================================
--- pjproject/trunk/third_party/build/ilbc/Makefile	(revision 2182)
+++ pjproject/trunk/third_party/build/ilbc/Makefile	(revision 2183)
@@ -62,5 +62,4 @@
 depend:
 	$(MAKE) -f $(RULES_MAK) APP=ILBC app=libilbccodec $@
-	echo '$(ILBC_LIB): .libilbccodec-$(TARGET_NAME).depend' >> .libilbccodec-$(TARGET_NAME).depend; \
 
 
Index: pjproject/trunk/third_party/build/milenage/Makefile
===================================================================
--- pjproject/trunk/third_party/build/milenage/Makefile	(revision 2182)
+++ pjproject/trunk/third_party/build/milenage/Makefile	(revision 2183)
@@ -55,5 +55,4 @@
 depend:
 	$(MAKE) -f $(RULES_MAK) APP=MILENAGE app=libmilenage $@
-	echo '$(MILENAGE_LIB): .libmilenage-$(TARGET_NAME).depend' >> .libmilenage-$(TARGET_NAME).depend; \
 
 
Index: pjproject/trunk/third_party/build/portaudio/Makefile
===================================================================
--- pjproject/trunk/third_party/build/portaudio/Makefile	(revision 2182)
+++ pjproject/trunk/third_party/build/portaudio/Makefile	(revision 2183)
@@ -66,4 +66,3 @@
 depend:
 	$(MAKE) -f $(RULES_MAK) APP=PORTAUDIO app=libportaudio $@
-	echo '$(PORTAUDIO_LIB): .libportaudio-$(TARGET_NAME).depend' >> .libportaudio-$(TARGET_NAME).depend; \
 
Index: pjproject/trunk/third_party/build/resample/Makefile
===================================================================
--- pjproject/trunk/third_party/build/resample/Makefile	(revision 2182)
+++ pjproject/trunk/third_party/build/resample/Makefile	(revision 2183)
@@ -55,5 +55,4 @@
 depend:
 	$(MAKE) -f $(RULES_MAK) APP=RESAMPLE app=libresample $@
-	echo '$(RESAMPLE_LIB): .libresample-$(TARGET_NAME).depend' >> .libresample-$(TARGET_NAME).depend; \
 
 
Index: pjproject/trunk/third_party/build/speex/Makefile
===================================================================
--- pjproject/trunk/third_party/build/speex/Makefile	(revision 2182)
+++ pjproject/trunk/third_party/build/speex/Makefile	(revision 2183)
@@ -70,5 +70,4 @@
 depend:
 	$(MAKE) -f $(RULES_MAK) APP=SPEEX app=libspeex $@
-	echo '$(SPEEX_LIB): .libspeex-$(TARGET_NAME).depend' >> .libspeex-$(TARGET_NAME).depend; \
 
 
Index: pjproject/trunk/third_party/build/srtp/Makefile
===================================================================
--- pjproject/trunk/third_party/build/srtp/Makefile	(revision 2182)
+++ pjproject/trunk/third_party/build/srtp/Makefile	(revision 2183)
@@ -83,5 +83,4 @@
 depend:
 	$(MAKE) -f $(RULES_MAK) APP=SRTP app=libsrtp $@
-	echo '$(SRTP_LIB): .libsrtp-$(TARGET_NAME).depend' >> .libsrtp-$(TARGET_NAME).depend; \
 
 
