Index: /pjproject/trunk/build.mak.in
===================================================================
--- /pjproject/trunk/build.mak.in	(revision 4710)
+++ /pjproject/trunk/build.mak.in	(revision 4711)
@@ -173,11 +173,4 @@
 	-I$(PJDIR)/pjsip/include
 export APP_CXXFLAGS := $(APP_CFLAGS)
-#  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x
-#
-# FIX THIS
-#
-# pjsua2 is c++ library hence maybe needs to be put in separate
-# variables. it will also require -lstdc++ or -static-libstdc++
-#  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x
 export APP_LDFLAGS := -L$(PJDIR)/pjlib/lib\
 	-L$(PJDIR)/pjlib-util/lib\
@@ -187,16 +180,9 @@
 	-L$(PJDIR)/third_party/lib\
 	$(PJ_VIDEO_LDFLAGS) \
-	-static-libstdc++ \
 	@LDFLAGS@
-
-#  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x
-#
-# FIX THIS
-#
-# pjsua2 is c++ library hence maybe needs to be put in separate
-# variables. it will also require -lstdc++
-#  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x
+export APP_LDXXFLAGS := $(APP_LDFLAGS) \
+	-static-libstdc++
+
 export APP_LIB_FILES = \
-	$(PJ_DIR)/pjsip/lib/libpjsua2-$(LIB_SUFFIX) \
 	$(PJ_DIR)/pjsip/lib/libpjsua-$(LIB_SUFFIX) \
 	$(PJ_DIR)/pjsip/lib/libpjsip-ua-$(LIB_SUFFIX) \
@@ -211,4 +197,7 @@
 	$(APP_THIRD_PARTY_LIB_FILES) \
 	$(PJ_DIR)/pjlib/lib/libpj-$(LIB_SUFFIX)
+export APP_LIBXX_FILES = \
+	$(PJ_DIR)/pjsip/lib/libpjsua2-$(LIB_SUFFIX) \
+	$(APP_LIB_FILES)
 
 ifeq ($(PJ_SHARED_LIBRARIES),)
@@ -239,5 +228,5 @@
 export PJSUA2_LIB_LDLIB := -lpjsua2
 
-APP_LIB_FILES += $(PJ_DIR)/pjsip/lib/libpjsua.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/pjsip/lib/libpjsua.$(SHLIB_SUFFIX) \
+export ADD_LIB_FILES := $(PJ_DIR)/pjsip/lib/libpjsua.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/pjsip/lib/libpjsua.$(SHLIB_SUFFIX) \
 	$(PJ_DIR)/pjsip/lib/libpjsip-ua.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/pjsip/lib/libpjsip-ua.$(SHLIB_SUFFIX) \
 	$(PJ_DIR)/pjsip/lib/libpjsip-simple.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/pjsip/lib/libpjsip-simple.$(SHLIB_SUFFIX) \
@@ -250,8 +239,12 @@
 	$(PJ_DIR)/pjlib-util/lib/libpjlib-util.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/pjlib-util/lib/libpjlib-util.$(SHLIB_SUFFIX) \
 	$(PJ_DIR)/pjlib/lib/libpj.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/pjlib/lib/libpj.$(SHLIB_SUFFIX)
-endif
-
-export APP_LDLIBS := $(PJSUA2_LIB_LDLIB) \
-	$(PJSUA_LIB_LDLIB) \
+
+APP_LIB_FILES += $(ADD_LIB_FILES)
+
+APP_LIBXX_FILES += $(PJ_DIR)/pjsip/lib/libpjsua2.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/pjsip/lib/libpjsua2.$(SHLIB_SUFFIX) \
+	$(ADD_LIB_FILES)
+endif
+
+export APP_LDLIBS := $(PJSUA_LIB_LDLIB) \
 	$(PJSIP_UA_LDLIB) \
 	$(PJSIP_SIMPLE_LDLIB) \
@@ -267,4 +260,7 @@
 	$(PJLIB_LDLIB) \
 	@LIBS@
+export APP_LDXXLIBS := $(PJSUA2_LIB_LDLIB) \
+	-lstdc++ \
+	$(APP_LDLIBS)
 
 # Here are the variabels to use if application is using the library
@@ -275,6 +271,9 @@
 export PJ_CXXFLAGS := $(APP_CXXFLAGS)
 export PJ_LDFLAGS := $(APP_LDFLAGS)
+export PJ_LDXXFLAGS := $(APP_LDXXFLAGS)
 export PJ_LDLIBS := $(APP_LDLIBS)
+export PJ_LDXXLIBS := $(APP_LDXXLIBS)
 export PJ_LIB_FILES := $(APP_LIB_FILES)
+export PJ_LIBXX_FILES := $(APP_LIBXX_FILES)
 
 # And here are the variables to use if application is using the
Index: /pjproject/trunk/pjsip-apps/build/Makefile
===================================================================
--- /pjproject/trunk/pjsip-apps/build/Makefile	(revision 4710)
+++ /pjproject/trunk/pjsip-apps/build/Makefile	(revision 4711)
@@ -59,14 +59,6 @@
 
 export CC_OUT CC AR RANLIB HOST_MV HOST_RM HOST_RMDIR HOST_MKDIR OBJEXT LD LDOUT 
-###############################################################################
-# Main entry
-#
-#
-#  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x
-#
-#                FIX THIS
-#
-#  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x
-TARGETS := $(BINDIR)/$(PJSUA_EXE) $(BINDIR)/$(PJSYSTEST_EXE) samples
+
+TARGETS := $(PJSUA_EXE) $(PJSYSTEST_EXE) samples
 
 all: $(TARGETS)
Index: /pjproject/trunk/pjsip-apps/build/Samples.mak
===================================================================
--- /pjproject/trunk/pjsip-apps/build/Samples.mak	(revision 4710)
+++ /pjproject/trunk/pjsip-apps/build/Samples.mak	(revision 4711)
@@ -11,4 +11,5 @@
 export _CXXFLAGS:= $(PJ_CXXFLAGS)
 export _LDFLAGS := $(PJ_LDFLAGS) $(PJ_LDLIBS) $(LDFLAGS)
+export _LDXXFLAGS := $(PJ_LDXXFLAGS) $(PJ_LDXXLIBS) $(LDFLAGS)
 
 SRCDIR := ../src/samples
@@ -30,5 +31,4 @@
 	   pjsip-perf \
 	   pcaputil \
-	   pjsua2_demo \
 	   playfile \
 	   playsine \
@@ -48,12 +48,19 @@
 	   vid_streamutil
 
+PJSUA2_SAMPLES := pjsua2_demo
+
 EXES := $(foreach file, $(SAMPLES), $(file)$(HOST_EXE))
+PJSUA2_EXES := $(foreach file, $(PJSUA2_SAMPLES), $(file)$(HOST_EXE))
 
 .PHONY: $(EXES)
+.PHONY: $(PJSUA2_EXES)
 
-all: $(EXES)
+all: $(EXES) $(PJSUA2_EXES)
 
 $(EXES):
-	$(MAKE) --no-print-directory -f $(RULES_MAK) SAMPLE_SRCDIR=$(SRCDIR) SAMPLE_OBJS=$@.o SAMPLE_CFLAGS="$(_CFLAGS)" SAMPLE_CXXFLAGS="$(_CXXFLAGS)" SAMPLE_LDFLAGS="$(_LDFLAGS) -lstdc++" SAMPLE_EXE=$@ APP=SAMPLE app=sample $(subst /,$(HOST_PSEP),$(BINDIR)/$@)
+	$(MAKE) --no-print-directory -f $(RULES_MAK) SAMPLE_SRCDIR=$(SRCDIR) SAMPLE_OBJS=$@.o SAMPLE_CFLAGS="$(_CFLAGS)" SAMPLE_CXXFLAGS="$(_CXXFLAGS)" SAMPLE_LDFLAGS="$(_LDFLAGS)" SAMPLE_EXE=$@ APP=SAMPLE app=sample $(subst /,$(HOST_PSEP),$(BINDIR)/$@)
+
+$(PJSUA2_EXES):
+	$(MAKE) --no-print-directory -f $(RULES_MAK) PJSUA2_SAMPLE_SRCDIR=$(SRCDIR) PJSUA2_SAMPLE_OBJS=$@.o PJSUA2_SAMPLE_CFLAGS="$(_CFLAGS)" PJSUA2_SAMPLE_CXXFLAGS="$(_CXXFLAGS)" PJSUA2_SAMPLE_LDFLAGS="$(_LDXXFLAGS)" PJSUA2_SAMPLE_EXE=$@ APP=PJSUA2_SAMPLE app=pjsua2_sample $(subst /,$(HOST_PSEP),$(BINDIR)/$@)
 
 depend:
Index: /pjproject/trunk/pjsip-apps/src/swig/java/Makefile
===================================================================
--- /pjproject/trunk/pjsip-apps/src/swig/java/Makefile	(revision 4710)
+++ /pjproject/trunk/pjsip-apps/src/swig/java/Makefile	(revision 4711)
@@ -1,3 +1,4 @@
 include ../../../../build.mak
+include ../../../../build/common.mak
 
 ifneq ($(findstring android,$(TARGET_NAME)),)
@@ -49,7 +50,4 @@
   MY_JNI_CFLAGS	 	= -fPIC
   MY_JNI_LDFLAGS	= -L$(MY_JDK)/lib
-  ifeq ($(OS),darwin)
-    MY_JNI_LDFLAGS 	:= $(MY_JNI_LDFLAGS) -Wl,-soname,pjsua2.so
-  endif
   ifeq ($(OS),android)
     MY_JNI_CFLAGS	:= $(MY_JNI_CFLAGS) -D__ANDROID__
@@ -68,9 +66,9 @@
 endif
 MY_JNI_CFLAGS	 := $(MY_JNI_CFLAGS) -I$(MY_JDK)/include -I$(MY_JDK)/include/win32 \
-		    -I$(MY_JDK)/include/linux -I.
+		    -I$(MY_JDK)/include/linux -I$(MY_JDK)/include/darwin -I.
 
 # Build settings
-MY_CFLAGS	 = $(PJ_CFLAGS) $(MY_JNI_CFLAGS)
-MY_LDFLAGS	 = $(PJ_LDFLAGS) -lpjsua2-$(TARGET_NAME) $(PJ_LDLIBS) $(MY_JNI_LDFLAGS)
+MY_CFLAGS	 = $(PJ_CXXFLAGS) $(MY_JNI_CFLAGS) $(CFLAGS)
+MY_LDFLAGS	 = $(PJ_LDXXFLAGS) $(PJ_LDXXLIBS) $(MY_JNI_LDFLAGS) $(LDFLAGS)
 MY_PACKAGE_NAME	 = org.pjsip.pjsua2
 ifeq ($(OS),android)
Index: /pjproject/trunk/pjsip/build/Makefile
===================================================================
--- /pjproject/trunk/pjsip/build/Makefile	(revision 4710)
+++ /pjproject/trunk/pjsip/build/Makefile	(revision 4711)
@@ -152,5 +152,5 @@
 export PJSUA2_TEST_CFLAGS += $(_CFLAGS) $(PJ_VIDEO_CFLAGS)
 export PJSUA2_TEST_CXXFLAGS = $(PJSUA2_LIB_CFLAGS) 
-export PJSUA2_TEST_LDFLAGS += -lpjsua2-$(TARGET_NAME) -lstdc++ $(PJ_LDFLAGS) $(PJ_LDLIBS) $(LDFLAGS)
+export PJSUA2_TEST_LDFLAGS += $(PJ_LDXXFLAGS) $(PJ_LDXXLIBS) $(LDFLAGS)
 export PJSUA2_TEST_EXE := pjsua2-test-$(TARGET_NAME)$(HOST_EXE)
 
