diff --git a/third-party/Makefile b/third-party/Makefile
index e87e26f32690b6650859a9fe9db4656e3f6846bd..532bf532ef55847002952a415af806264360e779 100644
--- a/third-party/Makefile
+++ b/third-party/Makefile
@@ -1,13 +1,26 @@
 
+-include ../makeopts
 include Makefile.rules
 
-TP_SUBDIRS := pjproject jansson
+TP_SUBDIRS :=
 # Sub directories that contain special install/uninstall targets must be explicitly listed
 # to prevent accidentally running the package's default install target.
-TP_INSTALL_SUBDIRS := pjproject jansson
+TP_INSTALL_SUBDIRS :=
+
+ifeq ($(PJPROJECT_BUNDLED),yes)
+TP_SUBDIRS += pjproject
+TP_INSTALL_SUBDIRS += pjproject
+endif
+
+ifeq ($(JANSSON_BUNDLED),yes)
+TP_SUBDIRS += jansson
+TP_INSTALL_SUBDIRS += jansson
+endif
 
 .PHONY: all dist-clean distclean install clean moduleinfo makeopts uninstall $(TP_SUBDIRS)
 
+ifneq ($(TP_SUBDIRS),)
+
 override MAKECMDGOALS?=all
 
 MAKECMDGOALS:=$(subst dist-clean,distclean,$(MAKECMDGOALS))
@@ -17,3 +30,5 @@ install uninstall: $(TP_INSTALL_SUBDIRS)
 
 $(TP_SUBDIRS):
 	+$(CMD_PREFIX) $(SUBMAKE) -C $@ $(MAKECMDGOALS)
+
+endif
\ No newline at end of file
diff --git a/third-party/pjproject/Makefile b/third-party/pjproject/Makefile
index 612c116bd9f31cd253cd6d2b8c32cc0e2107f2a9..28cb5db85bf4120388f0b7b0e633e01c7f48ba24 100644
--- a/third-party/pjproject/Makefile
+++ b/third-party/pjproject/Makefile
@@ -126,7 +126,7 @@ source/pjlib/include/pj/%.h: patches/%.h
 	$(ECHO_PREFIX) Rebuilding
 	$(CMD_PREFIX) $(MAKE) clean $(REALLY_QUIET)
 
-source/build.mak: Makefile.rules source/user.mak $(if $(PJPROJECT_BUNDLED_OOT),,.rebuild_needed)
+source/build.mak: Makefile.rules source/user.mak $(if $(PJPROJECT_BUNDLED_OOT),,.rebuild_needed) $(subst patches,source/pjlib/include/pj,$(wildcard patches/*.h))
 	$(ECHO_PREFIX) Configuring with $(PJPROJECT_CONFIG_OPTS) 
 	$(CMD_PREFIX) (cd source ; ./aconfigure $(QUIET_CONFIGURE) $(PJPROJECT_CONFIG_OPTS))