diff --git a/configure b/configure
index 171693a31136f0db837de0053fc705b9e9080d12..751fbea5daddd0b4c93d0a68a8f26110d170afbc 100755
--- a/configure
+++ b/configure
@@ -663,6 +663,10 @@ PWLIB_LIBDIR
 PWLIB_INCDIR
 PWLIBDIR
 PTLIB_CONFIG
+PYTHONDEV_LIBS
+PYTHONDEV_CFLAGS
+PYTHONDEV_INCLUDE
+PYTHONDEV_LIB
 PJPROJECT_LIBS
 PJPROJECT_CFLAGS
 PG_CONFIG
@@ -1425,6 +1429,8 @@ LIBEDIT_CFLAGS
 LIBEDIT_LIBS
 PJPROJECT_CFLAGS
 PJPROJECT_LIBS
+PYTHONDEV_CFLAGS
+PYTHONDEV_LIBS
 GMIME_CFLAGS
 GMIME_LIBS
 GTK2_CFLAGS
@@ -2168,6 +2174,10 @@ Some influential environment variables:
               C compiler flags for PJPROJECT, overriding pkg-config
   PJPROJECT_LIBS
               linker flags for PJPROJECT, overriding pkg-config
+  PYTHONDEV_CFLAGS
+              C compiler flags for PYTHONDEV, overriding pkg-config
+  PYTHONDEV_LIBS
+              linker flags for PYTHONDEV, overriding pkg-config
   GMIME_CFLAGS
               C compiler flags for GMIME, overriding pkg-config
   GMIME_LIBS  linker flags for GMIME, overriding pkg-config
@@ -25444,6 +25454,97 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
 
 
+
+
+   if test "x${PBX_PYTHONDEV}" != "x1" -a "${USE_PYTHONDEV}" != "no"; then
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for PYTHONDEV" >&5
+$as_echo_n "checking for PYTHONDEV... " >&6; }
+
+if test -n "$PYTHONDEV_CFLAGS"; then
+    pkg_cv_PYTHONDEV_CFLAGS="$PYTHONDEV_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"python\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "python") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_PYTHONDEV_CFLAGS=`$PKG_CONFIG --cflags "python" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$PYTHONDEV_LIBS"; then
+    pkg_cv_PYTHONDEV_LIBS="$PYTHONDEV_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"python\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "python") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_PYTHONDEV_LIBS=`$PKG_CONFIG --libs "python" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+   	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+	        PYTHONDEV_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "python" 2>&1`
+        else
+	        PYTHONDEV_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "python" 2>&1`
+        fi
+	# Put the nasty error message in config.log where it belongs
+	echo "$PYTHONDEV_PKG_ERRORS" >&5
+
+
+            PBX_PYTHONDEV=0
+
+
+elif test $pkg_failed = untried; then
+     	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+            PBX_PYTHONDEV=0
+
+
+else
+	PYTHONDEV_CFLAGS=$pkg_cv_PYTHONDEV_CFLAGS
+	PYTHONDEV_LIBS=$pkg_cv_PYTHONDEV_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+
+            PBX_PYTHONDEV=1
+            PYTHONDEV_INCLUDE="$PYTHONDEV_CFLAGS"
+            PYTHONDEV_LIB="$PYTHONDEV_LIBS"
+
+$as_echo "#define HAVE_PYTHONDEV 1" >>confdefs.h
+
+
+fi
+   fi
+
+
+
 if test "x${PBX_POPT}" != "x1" -a "${USE_POPT}" != "no"; then
    pbxlibdir=""
    # if --with-POPT=DIR has been specified, use it.
diff --git a/configure.ac b/configure.ac
index b136d867f91b2ea15bf6dea8cffd03431943546f..9c11054e93c5379612a163b73ec6589a48bf01a2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2207,6 +2207,10 @@ if test "$USE_PJPROJECT" != "no" ; then
    fi
 fi
 
+AC_SUBST([PYTHONDEV_LIB])
+AC_SUBST([PYTHONDEV_INCLUDE])
+AST_PKG_CONFIG_CHECK([PYTHONDEV], [python])
+
 AST_EXT_LIB_CHECK([POPT], [popt], [poptStrerror], [popt.h])
 
 AST_EXT_LIB_CHECK([PORTAUDIO], [portaudio], [Pa_GetDeviceCount], [portaudio.h])
diff --git a/include/asterisk/autoconfig.h.in b/include/asterisk/autoconfig.h.in
index b5fe655d7faa65a4e1da0c52db3a241b4da43126..72242122828ec4994ee3ef85e4b5b5da136d0d75 100644
--- a/include/asterisk/autoconfig.h.in
+++ b/include/asterisk/autoconfig.h.in
@@ -730,6 +730,9 @@
 /* Define if your system has the PWLib libraries. */
 #undef HAVE_PWLIB
 
+/* Define if your system has the PYTHONDEV libraries. */
+#undef HAVE_PYTHONDEV
+
 /* Define to 1 if you have the Radius Client library. */
 #undef HAVE_RADIUS
 
diff --git a/makeopts.in b/makeopts.in
index 6baef1b4660ee4acf14fb6fa7514a9f17c9340dd..d4347daf1beb092e016e8a7aaa0e2e4b52d3842d 100644
--- a/makeopts.in
+++ b/makeopts.in
@@ -243,6 +243,9 @@ PORTAUDIO_LIB=@PORTAUDIO_LIB@
 PRI_INCLUDE=@PRI_INCLUDE@
 PRI_LIB=@PRI_LIB@
 
+PYTHONDEV_INCLUDE=@PYTHONDEV_INCLUDE@
+PYTHONDEV_LIB=@PYTHONDEV_LIB@
+
 RESAMPLE_INCLUDE=@RESAMPLE_INCLUDE@
 RESAMPLE_LIB=@RESAMPLE_LIB@
 
diff --git a/third-party/pjproject/Makefile b/third-party/pjproject/Makefile
index 7fa3902baa7d2a3ab96d8d9bfb8bd234ca72b75e..7349db62f839c86b2330c6d1001fb2f4b43650e4 100644
--- a/third-party/pjproject/Makefile
+++ b/third-party/pjproject/Makefile
@@ -45,6 +45,13 @@ ifeq ($(SPECIAL_TARGETS),)
         CF := $(filter-out -I%,$(CF))
         export CFLAGS += $(CF)
         export LDFLAGS += $(CC_LDFLAGS)
+        TARGETS := pjproject.symbols
+        ifeq ($(findstring TEST_FRAMEWORK,$(MENUSELECT_CFLAGS)),TEST_FRAMEWORK)
+            TARGETS += source/pjsip-apps/bin/pjsua-$(TARGET_NAME)
+            ifneq ($(PYTHONDEV_LIB),)
+                TARGETS += source/pjsip-apps/src/python/build/_pjsua.so
+            endif
+        endif
     else
         all install:
     endif
@@ -95,12 +102,10 @@ source/pjlib/build/.pjlib-$(TARGET_NAME).depend: build.mak
 	$(ECHO_PREFIX) "Making dependencies"
 	+$(CMD_PREFIX) $(SUBMAKE) -C source dep
 
-
 menuselect: ../../menuselect.makeopts ../../makeopts
 	-$(CMD_PREFIX) test -d source && ($(SUBMAKE) -C source clean ; find source -name *.a -delete ; rm -rf source/pjsip-apps/src/python/build) || :
 	-$(CMD_PREFIX) rm -rf pjproject.symbols
 
-
 source/pjlib/lib/libpj-$(TARGET_NAME).a: menuselect source/pjlib/build/.pjlib-$(TARGET_NAME).depend
 	$(ECHO_PREFIX) Compiling libs
 	+$(CMD_PREFIX) $(SUBMAKE) -C source lib $(REALLY_QUIET)
@@ -117,17 +122,22 @@ source/pjsip-apps/src/python/build/_pjsua.so: source/pjlib/lib/libpj-$(TARGET_NA
 	$(ECHO_PREFIX) Compiling python bindings
 	$(CMD_PREFIX) (cd source/pjsip-apps/src/python ; MAKE=$(MAKE) python setup.py build --build-platlib=./build $(REALLY_QUIET))
 
-_all: pjproject.symbols source/pjsip-apps/bin/pjsua-$(TARGET_NAME) source/pjsip-apps/src/python/build/_pjsua.so
+_all: $(TARGETS)
 
 _install: _all
-	$(ECHO_PREFIX) Installing apps and python bindings
 	@if [ ! -d "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject" ]; then \
 		$(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject"; \
 	fi;
+ifneq ($(findstring source/pjsip-apps/bin/pjsua-$(TARGET_NAME),$(TARGETS)),)
+	$(ECHO_PREFIX) Installing apps
 	$(CMD_PREFIX) $(INSTALL) -m 755 source/pjsip-apps/bin/pjsua-$(TARGET_NAME) "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject/pjsua"
 	$(CMD_PREFIX) $(INSTALL) -m 755 source/pjsip-apps/bin/pjsystest-$(TARGET_NAME) "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject/pjsystest"
+endif
+ifneq ($(findstring source/pjsip-apps/src/python/build/_pjsua.so,$(TARGETS)),)
+	$(ECHO_PREFIX) Installing python bindings
 	$(CMD_PREFIX) $(INSTALL) -m 755 source/pjsip-apps/src/python/build/_pjsua.so "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject/"
 	$(CMD_PREFIX) $(INSTALL) -m 644 source/pjsip-apps/src/python/build/pjsua.py "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject/"
+endif
 
 uninstall:
 	$(ECHO_PREFIX) Uninstalling apps and python bindings
@@ -135,7 +145,7 @@ uninstall:
 
 clean:
 	$(ECHO_PREFIX) Cleaning
-	-$(CMD_PREFIX) test -d source && ($(SUBMAKE) -C source clean ; find source -name *.a -delete ; rm -rf source/pjsip-apps/src/python/build) || :
+	-$(CMD_PREFIX) test -d source && ($(SUBMAKE) -C source clean ; find source -name *.a -delete ; rm -rf source/pjsip-apps/src/python/build ; rm -rf source/pjsip-apps/bin/* ) || :
 	-$(CMD_PREFIX) rm -rf pjproject.symbols
 
 distclean:
diff --git a/third-party/pjproject/Makefile.rules b/third-party/pjproject/Makefile.rules
index 6b51c2f2a7658427f0303888e333574042a951ec..d2e7d25a4b7cce150c8048fedb7adea246e34b00 100644
--- a/third-party/pjproject/Makefile.rules
+++ b/third-party/pjproject/Makefile.rules
@@ -3,7 +3,7 @@ PJPROJECT_URL = http://www.pjsip.org/release/$(PJPROJECT_VERSION)
 # Even though we're not installing pjproject, we're setting prefix to /opt/pjproject to be safe
 PJPROJECT_CONFIG_OPTS = --prefix=/opt/pjproject --disable-speex-codec --disable-speex-aec \
 	--disable-gsm-codec --disable-video --disable-v4l2 --disable-sound --disable-opencore-amr \
-	--disable-ilbc-codec --without-libyuv --disable-g7221-codec
+	--disable-ilbc-codec --without-libyuv --disable-g7221-codec --disable-resample
 
 ifeq ($(shell uname -s),Linux)
    PJPROJECT_CONFIG_OPTS +=  --enable-epoll