diff --git a/build/modmake.rules.in b/build/modmake.rules.in
index b61420ad6f..fe87d3321d 100644
--- a/build/modmake.rules.in
+++ b/build/modmake.rules.in
@@ -46,12 +46,13 @@ CXXLINK = $(LIBTOOL) --mode=link --tag=CXX $(CXXLD) $(ALL_CXXFLAGS) $(LDFLAGS) -
 
 CSOURCEFILE=$(MODNAME).c
 CXXSOURCEFILE=$(MODNAME).cpp
+TOUCH_TARGET=@if test -f "$@" ; then touch "$@" ; fi ;
 
 RECURSE_MODNAME=`pwd | sed -e 's|^.*/||'`
 RECURSE_SOURCEFILE=`if test -f $$modname.cpp; then echo $$modname.cpp; else echo $$modname.c; fi`
 RECURSE_OUR_DEPS=`test -z "$(WANT_CURL)" || if test ! -z "$(LIBCURL_DEPS)"; then echo $(CURLLA); fi`
-RECURSE_OUR_CFLAGS=`test -z "$(WANT_CURL)" || echo $(LIBCURL_CPPFLAGS)`
-RECURSE_OUR_LDFLAGS=`test -z "$(WANT_CURL)" || echo $(LIBCURL)`
+RECURSE_OUR_CFLAGS=`test -z "$(WANT_CURL)" || echo $(LIBCURL_CPPFLAGS) ; $(LOCAL_INSERT_CFLAGS) `
+RECURSE_OUR_LDFLAGS=`test -z "$(WANT_CURL)" || echo $(LIBCURL) ; $(LOCAL_INSERT_LDFLAGS) `
 RECURSE_CHECKS=if test -z "$(MODNAME)" || test -z "$(SOURCEFILE)" || test -z "$(OUR_DEPS)" ; \
 	then modname=$(RECURSE_MODNAME) ; \
 	sourcefile=$(RECURSE_SOURCEFILE) ; \
@@ -92,9 +93,9 @@ extraclean: Makefile
 all-modules: local_depend local_all $(MODNAME).$(DYNAMIC_LIB_EXTEN) Makefile
 depend-modules: local_depend
 clean-modules: local_clean mod_clean
-install-modules: all depend_install local_install mod_install
+install-modules: all-modules depend_install local_install mod_install
 uninstall-modules: local_uninstall mod_uninstall
-distclean-modules: clean local_distclean
+distclean-modules: clean-modules local_distclean
 extraclean-modules: distclean local_extraclean
 
 Makefile:
diff --git a/src/mod/applications/mod_enum/Makefile b/src/mod/applications/mod_enum/Makefile
index 060c5e7fda..23b952de83 100644
--- a/src/mod/applications/mod_enum/Makefile
+++ b/src/mod/applications/mod_enum/Makefile
@@ -1,11 +1,11 @@
-
 BASE=../../../..
-UDNSA=$(BASE)/libs/udns/libudns.a
-LOCAL_CFLAGS=-I$(BASE)/libs/udns
+UDNS_DIR=$(BASE)/libs/udns
+UDNSA=$(UDNS_DIR)/libudns.a
+LOCAL_CFLAGS=-I$(UDNS_DIR)
 LOCAL_LIBADD=$(UDNSA)
 include $(BASE)/build/modmake.rules
 
-$(UDNSA):
-	cd $(BASE)/libs/udns && $(MAKE) staticlib
-
+$(UDNSA): $(UDNS_DIR) $(UDNS_DIR)/.update
+	cd $(UDNS_DIR) && $(MAKE) staticlib
+	$(TOUCH_TARGET)
 
diff --git a/src/mod/codecs/mod_amr/Makefile b/src/mod/codecs/mod_amr/Makefile
index 30d1c53337..2690cf38fc 100644
--- a/src/mod/codecs/mod_amr/Makefile
+++ b/src/mod/codecs/mod_amr/Makefile
@@ -1,16 +1,6 @@
-
 BASE=../../../..
 
-topdir=$(shell cd $(BASE) && pwd)
-ifeq ($(shell test -d $(topdir)/libs/amr && cd $(topdir)/libs/amr && pwd),$(topdir)/libs/amr)
-
-LOCAL_CFLAGS = -I$(PREFIX)/include/amr
-LOCAL_LDFLAGS =-lamr
-
-else
-
-LOCAL_CFLAGS = -DAMR_PASSTHROUGH
-
-endif
+LOCAL_INSERT_CFLAGS=if test -d $(BASE)/libs/amr; then echo "-I$(PREFIX)/include/amr" ; else echo "-DAMR_PASSTHROUGH" ; fi ;
+LOCAL_INSERT_LDFLAGS=test ! -d $(BASE)/libs/amp || echo "-lamr"
 
 include $(BASE)/build/modmake.rules
diff --git a/src/mod/codecs/mod_g711/Makefile b/src/mod/codecs/mod_g711/Makefile
index beb0e8db72..c79370f696 100644
--- a/src/mod/codecs/mod_g711/Makefile
+++ b/src/mod/codecs/mod_g711/Makefile
@@ -1,11 +1,5 @@
-# define these targets in your makefile if you wish
-# local_all local_depend local_clean depend_install local_install local_distclean local_extraclean:
-
-# and define these variables to impact your build
-
+BASE=../../../..
 LOCAL_CFLAGS=-I$(BASE)/libs/codec/g7xx/src/include
-LOCAL_LDFLAGS=
-LOCAL_OBJS=
-include ../../../../build/modmake.rules
+include $(BASE)/build/modmake.rules
 
 
diff --git a/src/mod/codecs/mod_g722/Makefile b/src/mod/codecs/mod_g722/Makefile
index 28c7ded049..26a36bee67 100644
--- a/src/mod/codecs/mod_g722/Makefile
+++ b/src/mod/codecs/mod_g722/Makefile
@@ -1,10 +1,10 @@
-
 BASE=../../../..
-G7XXLA=$(BASE)/libs/codec/g7xx/libg7xx.la
-LOCAL_CFLAGS=-I$(BASE)/libs/codec/g7xx/src/include/
+G7XX_DIR=$(BASE)/libs/codec/g7xx
+G7XXLA=$(G7XX_DIR)/libg7xx.la
+LOCAL_CFLAGS=-I$(G7XX_DIR)/src/include/
 LOCAL_LIBADD=$(G7XXLA)
 include $(BASE)/build/modmake.rules
 
-$(G7XXLA):
-	cd $(BASE)/libs/codec/g7xx && $(MAKE)
-
+$(G7XXLA): $(G7XX_DIR) $(G7XX_DIR)/.update
+	cd $(G7XX_DIR) && $(MAKE)
+	$(TOUCH_TARGET)
diff --git a/src/mod/codecs/mod_g723_1/Makefile b/src/mod/codecs/mod_g723_1/Makefile
index 241ebe5c97..288f707af3 100644
--- a/src/mod/codecs/mod_g723_1/Makefile
+++ b/src/mod/codecs/mod_g723_1/Makefile
@@ -1,10 +1,6 @@
-
 BASE=../../../..
-topdir=$(shell cd $(BASE) && pwd)
-ifeq ($(shell test -d $(topdir)/libs/libg723_1 && cd $(topdir)/libs/libg723_1 && pwd),$(topdir)/libs/libg723_1)
-LOCAL_CFLAGS += -I$(PREFIX)/include/g723
-LOCAL_LDFLAGS +=-lg723
-else
-LOCAL_CFLAGS += -DG723_PASSTHROUGH
-endif
+
+LOCAL_INSERT_CFLAGS=if test -d $(BASE)/libs/libg723_1; then echo "-I$(PREFIX)/include/g723" ; else echo "-DG723_PASSTHROUGH" ; fi ;
+LOCAL_INSERT_LDFLAGS=test ! -d $(BASE)/libs/libg723_1 || echo "-lg723"
+
 include $(BASE)/build/modmake.rules
diff --git a/src/mod/codecs/mod_g726/Makefile b/src/mod/codecs/mod_g726/Makefile
index 0c1b49e6d0..d04cb2a8af 100644
--- a/src/mod/codecs/mod_g726/Makefile
+++ b/src/mod/codecs/mod_g726/Makefile
@@ -1,10 +1,10 @@
-
 BASE=../../../..
-G726LA=$(BASE)/libs/codec/g726/libg726.la
-LOCAL_CFLAGS=-I$(BASE)/libs/codec/g726/src
+G726_DIR=$(BASE)/libs/codec/g726
+G726LA=$(G726_DIR)/libg726.la
+LOCAL_CFLAGS=-I$(G726_DIR)/src
 LOCAL_LIBADD=$(G726LA)
 include $(BASE)/build/modmake.rules
 
-$(G726LA):
-	cd $(BASE)/libs/codec/g726 && $(MAKE)
-
+$(G726LA): $(G726_DIR) $(G726_DIR)/.update
+	cd $(G726_DIR) && $(MAKE)
+	$(TOUCH_TARGET)
diff --git a/src/mod/codecs/mod_g729/Makefile b/src/mod/codecs/mod_g729/Makefile
index aa98f19779..1dbc868274 100644
--- a/src/mod/codecs/mod_g729/Makefile
+++ b/src/mod/codecs/mod_g729/Makefile
@@ -1,11 +1,4 @@
-
 BASE=../../../..
-topdir=$(shell cd $(BASE) && pwd)
-ifeq ($(shell test -d $(topdir)/libs/libg729 && cd $(topdir)/libs/libg729 && pwd),$(topdir)/libs/libg729)
-LOCAL_CFLAGS += -I$(PREFIX)/include/libg729
-LOCAL_LDFLAGS +=-lg729
-else
-LOCAL_CFLAGS += -DG729_PASSTHROUGH
-endif
-
+LOCAL_INSERT_CFLAGS=if test -d $(BASE)/libs/libg729; then echo "-I$(PREFIX)/include/libg729" ; else echo "-DG729_PASSTHROUGH" ; fi ;
+LOCAL_INSERT_LDFLAGS=test ! -d $(BASE)/libs/libg729 || echo "-lg729" 
 include $(BASE)/build/modmake.rules
diff --git a/src/mod/codecs/mod_gsm/Makefile b/src/mod/codecs/mod_gsm/Makefile
index 6e3649b64c..ab739c72cf 100644
--- a/src/mod/codecs/mod_gsm/Makefile
+++ b/src/mod/codecs/mod_gsm/Makefile
@@ -1,9 +1,10 @@
-
 BASE=../../../..
-GSMLA=$(BASE)/libs/codec/gsm/libgsm.la
-LOCAL_CFLAGS=-I$(BASE)/libs/codec/gsm/inc
+GSM_DIR=$(BASE)/libs/codec/gsm
+GSMLA=$(GSM_DIR)/libgsm.la
+LOCAL_CFLAGS=-I$(GSM_DIR)/inc
 LOCAL_LIBADD=$(GSMLA)
 include $(BASE)/build/modmake.rules
 
-$(GSMLA):
-	cd $(BASE)/libs/codec/gsm && $(MAKE)
+$(GSMLA): $(GSM_DIR) $(GSM_DIR)/.update
+	cd $(GSM_DIR) && $(MAKE)
+	$(TOUCH_TARGET)
diff --git a/src/mod/codecs/mod_ilbc/Makefile b/src/mod/codecs/mod_ilbc/Makefile
index 34aa9b4da3..adc04e5363 100644
--- a/src/mod/codecs/mod_ilbc/Makefile
+++ b/src/mod/codecs/mod_ilbc/Makefile
@@ -1,9 +1,10 @@
-
 BASE=../../../..
-ILBCLA=$(BASE)/libs/codec/ilbc/libilbc.la
-LOCAL_CFLAGS=-I$(BASE)/libs/codec/ilbc/src
+ILBC_DIR=$(BASE)/libs/codec/ilbc
+ILBCLA=$(ILBC_DIR)/libilbc.la
+LOCAL_CFLAGS=-I$(ILBC_DIR)/src
 LOCAL_LIBADD=$(ILBCLA)
 include $(BASE)/build/modmake.rules
 
-$(ILBCLA):
-	cd $(BASE)/libs/codec/ilbc && $(MAKE)
+$(ILBCLA): $(ILBC_DIR) $(ILBC_DIR)/.update
+	cd $(ILBC_DIR) && $(MAKE)
+	$(TOUCH_TARGET)
diff --git a/src/mod/codecs/mod_lpc10/Makefile b/src/mod/codecs/mod_lpc10/Makefile
index 985a328449..b74e716de5 100644
--- a/src/mod/codecs/mod_lpc10/Makefile
+++ b/src/mod/codecs/mod_lpc10/Makefile
@@ -1,9 +1,9 @@
-
 BASE=../../../..
-LPC10LA=$(BASE)/libs/codec/lpc10/liblpc10.la
-LOCAL_CFLAGS=-I$(BASE)/libs/codec/lpc10/src
+LPC10_DIR=$(BASE)/libs/codec/lpc10
+LPC10LA=$(LPC10_DIR)/liblpc10.la
+LOCAL_CFLAGS=-I$(LPC10_DIR)/src
 LOCAL_LIBADD=$(LPC10LA)
 include $(BASE)/build/modmake.rules
 
-$(LPC10LA):
-	cd $(BASE)/libs/codec/lpc10 && $(MAKE)
+$(LPC10LA): $(LPC10_DIR) $(LPC10_DIR)/.update
+	cd $(LPC10_DIR) && $(MAKE)
diff --git a/src/mod/codecs/mod_speex/Makefile b/src/mod/codecs/mod_speex/Makefile
index 2a95459a5f..6e3b123d36 100644
--- a/src/mod/codecs/mod_speex/Makefile
+++ b/src/mod/codecs/mod_speex/Makefile
@@ -1,19 +1,12 @@
-# define these targets in your makefile if you wish
-# local_all local_depend local_clean depend_install local_install local_distclean local_extraclean:
-
-# and define these variables to impact your build
-
-
 BASE=../../../..
 
-SPEEXLA=$(BASE)/libs/speex/libspeex/libspeex.la
+SPEEX_DIR=$(BASE)/libs/speex
+SPEEXLA=$(SPEEX_DIR)/libspeex/libspeex.la
 
-LOCAL_CFLAGS=-I$(BASE)/libs/speex/include
-LOCAL_LDFLAGS=$(SPEEXLA)
-LOCAL_OBJS=
+LOCAL_CFLAGS=-I$(SPEEX_DIR)/include
+LOCAL_LIBADD=$(SPEEXLA)
 include $(BASE)/build/modmake.rules
 
-local_depend: $(SPEEXLA)
-
-$(SPEEXLA): $(BASE)/libs/speex/stamp-h1
-	cd $(BASE)/libs/speex && $(MAKE)
+$(SPEEXLA): $(SPEEX_DIR) $(SPEEX_DIR)/.update
+	cd $(SPEEX_DIR) && $(MAKE)
+	$(TOUCH_TARGET)
diff --git a/src/mod/directories/mod_ldap/Makefile b/src/mod/directories/mod_ldap/Makefile
index 647ad49ade..faf503bcd4 100644
--- a/src/mod/directories/mod_ldap/Makefile
+++ b/src/mod/directories/mod_ldap/Makefile
@@ -1,4 +1,3 @@
-
 switch_srcdir=../../../..
 
 LDAP=openldap-2.3.19
@@ -15,9 +14,10 @@ LOCAL_LIBADD=$(LDAPLA) $(LIBLBERLA)
 
 include $(switch_srcdir)/build/modmake.rules
 
-$(LDAP_DIR)/Makefile:
+$(LDAP_DIR):
 	$(GETLIB) $(LDAP).tgz
 	cd $(LDAP_DIR) && ./configure $(DEFAULT_ARGS) --disable-bdb --disable-hdb
 
-$(LDAPLA) $(LIBLBERLA): $(LDAP_DIR)/Makefile $(LDAP_DIR)/stamp-h
+$(LDAPLA) $(LIBLBERLA): $(LDAP_DIR)
 	cd $(LDAP_DIR) && $(MAKE)
+	$(TOUCH_TARGET)
diff --git a/src/mod/endpoints/mod_dingaling/Makefile b/src/mod/endpoints/mod_dingaling/Makefile
index 7ed422b5a5..77f9d609ed 100644
--- a/src/mod/endpoints/mod_dingaling/Makefile
+++ b/src/mod/endpoints/mod_dingaling/Makefile
@@ -1,30 +1,27 @@
-# define these targets in your makefile if you wish
-# local_all local_depend local_clean depend_install local_install local_distclean local_extraclean:
-
-# and define these variables to impact your build
-
 BASE=../../../..
 
-IKSEMELLA=$(BASE)/libs/iksemel/src/libiksemel.la
-DINGLA=$(BASE)/libs/libdingaling/libdingaling.la
+IKSEMEL_DIR=$(BASE)/libs/iksemel
+DING_DIR=$(BASE)/libs/libdingaling
+IKSEMELLA=$(IKSEMEL_DIR)/src/libiksemel.la
+DINGLA=$(DING_DIR)/libdingaling.la
 
-LOCAL_CFLAGS=-I$(BASE)/libs/libdingaling/src
-LOCAL_LDFLAGS=
-LOCAL_OBJS=
+LOCAL_CFLAGS=-I$(DING_DIR)/src
 LOCAL_LIBADD=$(DINGLA)
 
 include $(BASE)/build/modmake.rules
 
 INST_DINGLA=$(PREFIX)/lib/libdingaling.la
 
-$(IKSEMELLA):
-	cd $(BASE)/libs/iksemel && $(MAKE)
+$(IKSEMELLA): $(IKSEMEL_DIR) $(IKSEMEL_DIR)/.update
+	cd $(IKSEMEL_DIR) && $(MAKE)
+	$(TOUCH_TARGET)
 
-$(DINGLA): $(IKSEMELLA)
-	cd $(BASE)/libs/libdingaling && $(MAKE)
+$(DINGLA): $(IKSEMELLA) $(DING_DIR) $(DING_DIR)/.update
+	cd $(DING_DIR) && $(MAKE)
+	$(TOUCH_TARGET)
 
 depend_install: $(INST_DINGLA)
 
 $(INST_DINGLA): $(DINGLA)
-	cd $(BASE)/libs/libdingaling && $(MAKE) install
+	cd $(DING_DIR) && $(MAKE) install
 
diff --git a/src/mod/endpoints/mod_iax/Makefile b/src/mod/endpoints/mod_iax/Makefile
index 33a8050c70..5492f9d64f 100644
--- a/src/mod/endpoints/mod_iax/Makefile
+++ b/src/mod/endpoints/mod_iax/Makefile
@@ -1,15 +1,11 @@
-# define these targets in your makefile if you wish
-# local_all local_depend local_clean depend_install local_install local_distclean local_extraclean:
-
-# and define these variables to impact your build
-
 BASE=../../../..
-IAXLA=$(BASE)/libs/iax/src/libiax.la
-LOCAL_CFLAGS=-I$(BASE)/libs/iax/src
-LOCAL_LDFLAGS=
+
+IAX_DIR=$(BASE)/libs/iax
+IAXLA=$(IAX_DIR)/src/libiax.la
+LOCAL_CFLAGS=-I$(IAX_DIR)/src
 LOCAL_LIBADD=$(IAXLA)
 include $(BASE)/build/modmake.rules
 
-$(IAXLA):
-	cd $(BASE)/libs/iax && $(MAKE)
+$(IAXLA): $(IAX_DIR) $(IAX_DIR)/.update
+	cd $(IAX_DIR) && $(MAKE)
 
diff --git a/src/mod/endpoints/mod_portaudio/Makefile b/src/mod/endpoints/mod_portaudio/Makefile
index 305fbf16bc..d878c49ca1 100644
--- a/src/mod/endpoints/mod_portaudio/Makefile
+++ b/src/mod/endpoints/mod_portaudio/Makefile
@@ -1,10 +1,10 @@
 BASE=../../../..
 OSARCH=$(shell uname -s)
 
-BASE=../../../..
+PA_DIR=$(BASE)/libs/portaudio
 
-PALA=$(BASE)/libs/portaudio/lib/libportaudio.la
-LOCAL_CFLAGS=-I. -I$(BASE)/libs/portaudio/include
+PALA=$(PA_DIR)/lib/libportaudio.la
+LOCAL_CFLAGS=-I. -I$(PA_DIR)/include
 LOCAL_LDFLAGS=
 ifeq ($(OSARCH),Darwin)
 LOCAL_LDFLAGS += -framework CoreAudio -framework AudioToolbox -framework AudioUnit -framework Carbon
@@ -14,8 +14,11 @@ LOCAL_OBJS=pablio.o pa_ringbuffer.o
 
 include $(BASE)/build/modmake.rules
 
-$(PALA):
-	cd $(BASE)/libs/portaudio && $(MAKE)
+$(PALA): $(PA_DIR) $(PA_DIR)/.update
+	cd $(PA_DIR) && $(MAKE)
+	$(TOUCH_TARGET)
 
 pa_ringbuffer.o: pa_ringbuffer.c
 	$(COMPILE) -D__EXTENSION__=1  -c -o $@ $<
+
+pablio.o: pablio.c
diff --git a/src/mod/endpoints/mod_sofia/Makefile b/src/mod/endpoints/mod_sofia/Makefile
index d6437c7465..0c94dcbf6f 100644
--- a/src/mod/endpoints/mod_sofia/Makefile
+++ b/src/mod/endpoints/mod_sofia/Makefile
@@ -1,30 +1,30 @@
-
-
 BASE=../../../..
 
 OS_ARCH         := $(subst /,_,$(shell uname -s | sed /\ /s//_/))
 
-LOCAL_CFLAGS  = -I. -I$(BASE)/libs/sofia-sip/libsofia-sip-ua/bnf  -I$(BASE)/libs/sofia-sip/libsofia-sip-ua/features
-LOCAL_CFLAGS += -I$(BASE)/libs/sofia-sip/libsofia-sip-ua/http -I$(BASE)/libs/sofia-sip/libsofia-sip-ua/ipt
-LOCAL_CFLAGS += -I$(BASE)/libs/sofia-sip/libsofia-sip-ua/iptsec -I$(BASE)/libs/sofia-sip/libsofia-sip-ua/msg
-LOCAL_CFLAGS += -I$(BASE)/libs/sofia-sip/libsofia-sip-ua/nea -I$(BASE)/libs/sofia-sip/libsofia-sip-ua/nta
-LOCAL_CFLAGS += -I$(BASE)/libs/sofia-sip/libsofia-sip-ua/nth -I$(BASE)/libs/sofia-sip/libsofia-sip-ua/nua
-LOCAL_CFLAGS += -I$(BASE)/libs/sofia-sip/libsofia-sip-ua/sdp -I$(BASE)/libs/sofia-sip/libsofia-sip-ua/sip
-LOCAL_CFLAGS += -I$(BASE)/libs/sofia-sip/libsofia-sip-ua/soa -I$(BASE)/libs/sofia-sip/libsofia-sip-ua/sresolv
-LOCAL_CFLAGS += -I$(BASE)/libs/sofia-sip/libsofia-sip-ua/stun -I$(BASE)/libs/sofia-sip/libsofia-sip-ua/su
-LOCAL_CFLAGS += -I$(BASE)/libs/sofia-sip/libsofia-sip-ua/tport -I$(BASE)/libs/sofia-sip/libsofia-sip-ua/url
+SOFIA_DIR=$(BASE)/libs/sofia-sip
+SOFIAUA_DIR=$(SOFIA_DIR)/libsofia-sip-ua
 
-SOFIALA=$(BASE)/libs/sofia-sip/libsofia-sip-ua/libsofia-sip-ua.la
+LOCAL_CFLAGS  = -I. -I$(SOFIAUA_DIR)/bnf  -I$(SOFIAUA_DIR)/features
+LOCAL_CFLAGS += -I$(SOFIAUA_DIR)/http -I$(SOFIAUA_DIR)/ipt
+LOCAL_CFLAGS += -I$(SOFIAUA_DIR)/iptsec -I$(SOFIAUA_DIR)/msg
+LOCAL_CFLAGS += -I$(SOFIAUA_DIR)/nea -I$(SOFIAUA_DIR)/nta
+LOCAL_CFLAGS += -I$(SOFIAUA_DIR)/nth -I$(SOFIAUA_DIR)/nua
+LOCAL_CFLAGS += -I$(SOFIAUA_DIR)/sdp -I$(SOFIAUA_DIR)/sip
+LOCAL_CFLAGS += -I$(SOFIAUA_DIR)/soa -I$(SOFIAUA_DIR)/sresolv
+LOCAL_CFLAGS += -I$(SOFIAUA_DIR)/stun -I$(SOFIAUA_DIR)/su
+LOCAL_CFLAGS += -I$(SOFIAUA_DIR)/tport -I$(SOFIAUA_DIR)/url
 
-LOCAL_LDFLAGS=$(SOFIALA)
+SOFIALA=$(SOFIAUA_DIR)/libsofia-sip-ua.la
+
+LOCAL_LIBADD=$(SOFIALA)
 
 ifeq ($(OS_ARCH),Darwin)
 	LOCAL_LDFLAGS +=-framework CoreFoundation -framework SystemConfiguration
 endif
 
-include ../../../../build/modmake.rules
+include $(BASE)/build/modmake.rules
 
-local_depend: $(SOFIALA)
-
-$(SOFIALA):
-	cd $(BASE)/libs/sofia-sip && $(MAKE)
+$(SOFIALA): $(SOFIA_DIR) $(SOFIA_DIR)/.update
+	cd $(SOFIA_DIR) && $(MAKE)
+	$(TOUCH_TARGET)
diff --git a/src/mod/endpoints/mod_wanpipe/Makefile b/src/mod/endpoints/mod_wanpipe/Makefile
index 04f810a5a9..12308059f6 100644
--- a/src/mod/endpoints/mod_wanpipe/Makefile
+++ b/src/mod/endpoints/mod_wanpipe/Makefile
@@ -1,13 +1,9 @@
-# define these targets in your makefile if you wish
-# local_all local_depend local_clean depend_install local_install local_distclean local_extraclean:
-
-# and define these variables to impact your build
-
+BASE=../../../..
 LOCAL_CFLAGS  =-I/usr/local/include -I/usr/src/libpri -I/usr/src/linux/include -I. -I/usr/include 
 LOCAL_CFLAGS +=-D__LINUX__ -D_REENTRANT -D_GNU_SOURCE -DAFT_A104 -DWANPIPE_TDM_API -I$(switch_srcdir)/libs/libteletone/src
 LOCAL_LDFLAGS=-lsangoma $(BASE)/libs/libteletone/libteletone.la
 LOCAL_OBJS=ss7boost_client.o
-include ../../../../build/modmake.rules
+include $(BASE)/build/modmake.rules
 
 local_depend:
 	MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install libsangoma --prefix=$(PREFIX) --with-libpri=/usr/src/libpri
diff --git a/src/mod/event_handlers/mod_xmpp_event/Makefile b/src/mod/event_handlers/mod_xmpp_event/Makefile
index d6e0ce8fe9..3f27db3a51 100644
--- a/src/mod/event_handlers/mod_xmpp_event/Makefile
+++ b/src/mod/event_handlers/mod_xmpp_event/Makefile
@@ -5,14 +5,14 @@
 
 BASE=../../../..
 
-IKSEMELLA=$(BASE)/libs/iksemel/src/libiksemel.la
+IKSEMEL_DIR=$(BASE)/libs/iksemel
+IKSEMELLA=$(IKSEMEL_DIR)/src/libiksemel.la
 
-LOCAL_CFLAGS=-I$(BASE)/libs/iksemel/include
-LOCAL_LDFLAGS=$(IKSEMELA)
+LOCAL_CFLAGS=-I$(IKSEMEL_DIR)/include
+LOCAL_LIBADD=$(IKSEMELA)
 LOCAL_OBJS=
 include $(BASE)/build/modmake.rules
 
-local_depend: $(IKSEMELLA)
-
-$(IKSEMELLA):
-	cd $(BASE)/libs/iksemel && $(MAKE)
+$(IKSEMELLA): $(IKSEMEL_DIR) $(IKSEMEL_DIR)/.update
+	cd $(IKSEMEL_DIR) && $(MAKE)
+	$(TOUCH_TARGET)
diff --git a/src/mod/event_handlers/mod_zeroconf/Makefile b/src/mod/event_handlers/mod_zeroconf/Makefile
index 514494217b..d3e36dff43 100644
--- a/src/mod/event_handlers/mod_zeroconf/Makefile
+++ b/src/mod/event_handlers/mod_zeroconf/Makefile
@@ -1,4 +1,3 @@
-
 switch_srcdir=../../../..
 
 HOWL=howl-1.0.0
@@ -12,9 +11,10 @@ DEFAULT_ARGS=--prefix=$(PREFIX) --disable-shared --with-pic
 
 include $(switch_srcdir)/build/modmake.rules
 
-$(HOWL_DIR)/Makefile:
+$(HOWL_DIR):
 	$(GETLIB) $(HOWL).tar.gz
 	cd $(HOWL_DIR) && ./configure $(DEFAULT_ARGS)
 
-$(HOWLLA): $(HOWL_DIR)/Makefile
+$(HOWLLA): $(HOWL_DIR)
 	cd $(HOWL_DIR) && $(MAKE)
+	$(TOUCH_TARGET)
diff --git a/src/mod/formats/mod_shout/Makefile b/src/mod/formats/mod_shout/Makefile
index 5fcc549f23..44cc1195e7 100644
--- a/src/mod/formats/mod_shout/Makefile
+++ b/src/mod/formats/mod_shout/Makefile
@@ -1,4 +1,3 @@
-
 LAME=lame-3.97
 SHOUT=libshout-2.2.2
 switch_srcdir=../../../..
@@ -25,20 +24,21 @@ DEFAULT_ARGS=--prefix=$(PREFIX) --disable-shared --with-pic
 
 $(LOCAL_OBJS): $(LOCAL_SOURCES)
 
-$(LAME_DIR)/Makefile:
+$(LAME_DIR):
 	$(GETLIB) $(LAME).tar.gz
 	cd $(LAME_DIR) && ./configure $(DEFAULT_ARGS) --disable-decoder
 
-$(LAMELA): $(LAME_DIR)/Makefile
+$(LAMELA): $(LAME_DIR)
 	cd $(LAME_DIR) && $(MAKE)
+	$(TOUCH_TARGET)
 
-$(SHOUT_DIR)/Makefile:
+$(SHOUT_DIR):
 	$(GETLIB) $(SHOUT).tar.gz
 	cd $(SHOUT_DIR) && ./configure $(DEFAULT_ARGS) --with-speex=no
 
-$(SHOUTLA): $(SHOUT_DIR)/Makefile
+$(SHOUTLA): $(SHOUT_DIR)
 	cd $(SHOUT_DIR) && $(MAKE)
-
+	$(TOUCH_TARGET)
 
 
 
diff --git a/src/mod/formats/mod_sndfile/Makefile b/src/mod/formats/mod_sndfile/Makefile
index dd3ab82658..8bf44207eb 100644
--- a/src/mod/formats/mod_sndfile/Makefile
+++ b/src/mod/formats/mod_sndfile/Makefile
@@ -1,20 +1,14 @@
-# define these targets in your makefile if you wish
-# local_all local_depend local_clean depend_install local_install local_distclean local_extraclean:
-
-# and define these variables to impact your build
-
-
 BASE=../../../..
 
-SNDFILELA=$(BASE)/libs/libsndfile/src/libsndfile.la
+SNDFILE_DIR=$(BASE)/libs/libsndfile
+SNDFILELA=$(SNDFILE_DIR)/src/libsndfile.la
 
-LOCAL_CFLAGS=-I$(BASE)/libs/libsndfile/src
-LOCAL_LDFLAGS=$(SNDFILELA)
+LOCAL_CFLAGS=-I$(SNDFILE_DIR)/src
+LOCAL_LIBADD=$(SNDFILELA)
 LOCAL_OBJS=
 
 include $(BASE)/build/modmake.rules
 
-local_depend: $(SNDFILELA)
-
-$(SNDFILELA):
-	cd $(BASE)/libs/libsndfile && $(MAKE)
+$(SNDFILELA): $(SNDFILE_DIR) $(SNDFILE_DIR)/.update
+	cd $(SNDFILE_DIR) && $(MAKE)
+	$(TOUCH_TARGET)
diff --git a/src/mod/languages/mod_spidermonkey/Makefile b/src/mod/languages/mod_spidermonkey/Makefile
index 0489478ff1..811ac16b5e 100644
--- a/src/mod/languages/mod_spidermonkey/Makefile
+++ b/src/mod/languages/mod_spidermonkey/Makefile
@@ -1,4 +1,3 @@
-
 WANT_CURL=yes
 
 LOCAL_CFLAGS=
@@ -9,8 +8,6 @@ include sm.mak
 
 depend_install: $(DESTDIR)$(PREFIX)/lib/libjs.la
 
-
-
 $(DESTDIR)$(PREFIX)/lib/libjs.la: $(JSLA)
 	cd $(JS_DIR)/nsprpub/ && $(MAKE) install
 	cd $(JS_DIR) && $(MAKE) install
diff --git a/src/mod/languages/mod_spidermonkey/sm.mak b/src/mod/languages/mod_spidermonkey/sm.mak
index c50e90e4ce..86617568e4 100644
--- a/src/mod/languages/mod_spidermonkey/sm.mak
+++ b/src/mod/languages/mod_spidermonkey/sm.mak
@@ -8,6 +8,7 @@ LOCAL_LIBADD+=$(JSLA)
 
 include $(switch_srcdir)/build/modmake.rules
 
-$(JSLA):
+$(JSLA): $(JS_DIR) $(JS_DIR)/.update
 	cd $(JS_DIR)/nsprpub && $(MAKE)
 	cd $(JS_DIR) && $(MAKE)
+	$(TOUCH_TARGET)
diff --git a/src/mod/languages/mod_spidermonkey_core_db/Makefile b/src/mod/languages/mod_spidermonkey_core_db/Makefile
index 2734c2113b..1426e33cf8 100644
--- a/src/mod/languages/mod_spidermonkey_core_db/Makefile
+++ b/src/mod/languages/mod_spidermonkey_core_db/Makefile
@@ -1,4 +1,3 @@
-
 switch_srcdir=../../../..
 LOCAL_CFLAGS=
 LOCAL_LDFLAGS=
diff --git a/src/mod/languages/mod_spidermonkey_etpan/Makefile b/src/mod/languages/mod_spidermonkey_etpan/Makefile
index 35c68c8359..bc5085990e 100644
--- a/src/mod/languages/mod_spidermonkey_etpan/Makefile
+++ b/src/mod/languages/mod_spidermonkey_etpan/Makefile
@@ -1,16 +1,12 @@
-
-
 switch_srcdir=../../../..
-
 ETPAN_DIR=$(switch_srcdir)/libs/libetpan
 ETPANLA=$(ETPAN_DIR)/src/libetpan.la
 
 LOCAL_CFLAGS=-I$(ETPAN_DIR)/include
-LOCAL_LDFLAGS=
 LOCAL_LIBADD=$(ETPANLA)
 
 include ../mod_spidermonkey/sm.mak
 
-$(ETPANLA):
+$(ETPANLA): $(ETPAN_DIR) $(ETPAN_DIR)/.update
 	cd $(ETPAN_DIR) && $(MAKE)
-
+	$(TOUCH_TARGET)
diff --git a/src/mod/languages/mod_spidermonkey_odbc/Makefile b/src/mod/languages/mod_spidermonkey_odbc/Makefile
index ac00c93426..8cf7068d2c 100644
--- a/src/mod/languages/mod_spidermonkey_odbc/Makefile
+++ b/src/mod/languages/mod_spidermonkey_odbc/Makefile
@@ -1,23 +1,25 @@
-
 switch_srcdir=../../../..
 
 ODBC=unixODBC-2.2.12
 ODBC_DIR=$(switch_srcdir)/libs/$(ODBC)
 ODBCLA=libodbc.la
+
 UNINST_ODBCLA=$(ODBC_DIR)/DriverManager/$(ODBCLA)
 INST_ODBCLA=$(DESTDIR)$(PREFIX)/lib/$(ODBCLA)
+
 LOCAL_CFLAGS=-I$(ODBC_DIR)/include
 LOCAL_LDFLAGS=
 LOCAL_LIBADD=$(UNINST_ODBCLA)
 
 include ../mod_spidermonkey/sm.mak
 
-$(ODBC_DIR)/Makefile:
+$(ODBC_DIR):
 	$(GETLIB) $(ODBC).tar.gz
 	cd $(ODBC_DIR) && ./configure --prefix=$(PREFIX) --disable-gui --without-x --with-pic 
 
-$(UNINST_ODBCLA): $(ODBC_DIR)/Makefile
+$(UNINST_ODBCLA): $(ODBC_DIR)
 	cd $(ODBC_DIR) && $(MAKE)
+	$(TOUCH_TARGET)
 
 depend_install: $(INST_ODBCLA)
 
diff --git a/src/mod/languages/mod_spidermonkey_teletone/Makefile b/src/mod/languages/mod_spidermonkey_teletone/Makefile
index 0524e79da1..3e2030ecbb 100644
--- a/src/mod/languages/mod_spidermonkey_teletone/Makefile
+++ b/src/mod/languages/mod_spidermonkey_teletone/Makefile
@@ -1,7 +1,5 @@
-
 switch_srcdir=../../../..
 LOCAL_CFLAGS=-I$(switch_srcdir)/libs/libteletone/src
-LOCAL_LDFLAGS=
 LOCAL_LIBADD=$(switch_srcdir)/libs/libteletone/libteletone.la
 include ../mod_spidermonkey/sm.mak
 
diff --git a/src/mod/xml_int/mod_xml_curl/Makefile b/src/mod/xml_int/mod_xml_curl/Makefile
index cb9eba2527..c762c5353d 100644
--- a/src/mod/xml_int/mod_xml_curl/Makefile
+++ b/src/mod/xml_int/mod_xml_curl/Makefile
@@ -1,7 +1,2 @@
-# define these targets in your makefile if you wish
-# local_all local_depend local_clean depend_install local_install local_distclean local_extraclean:
-
-# and define these variables to impact your build
-
 WANT_CURL=yes
 include ../../../../build/modmake.rules
diff --git a/src/mod/xml_int/mod_xml_rpc/Makefile b/src/mod/xml_int/mod_xml_rpc/Makefile
index 97522cad20..5161d9c0d7 100644
--- a/src/mod/xml_int/mod_xml_rpc/Makefile
+++ b/src/mod/xml_int/mod_xml_rpc/Makefile
@@ -1,17 +1,17 @@
-
 BASE=../../../..
+XMLRPC_DIR=$(BASE)/libs/xmlrpc-c
 
-XMLRPCLAS  = $(BASE)/libs/xmlrpc-c/src/libxmlrpc.la $(BASE)/libs/xmlrpc-c/src/libxmlrpc_server.la 
-XMLRPCLAS += $(BASE)/libs/xmlrpc-c/src/libxmlrpc_server_abyss.la $(BASE)/libs/xmlrpc-c/lib/abyss/src/libxmlrpc_abyss.la
-XMLRPCLAS += $(BASE)/libs/xmlrpc-c/lib/expat/xmlparse/libxmlrpc_xmlparse.la
+XMLRPCLAS  = $(XMLRPC_DIR)/src/libxmlrpc.la $(XMLRPC_DIR)/src/libxmlrpc_server.la 
+XMLRPCLAS += $(XMLRPC_DIR)/src/libxmlrpc_server_abyss.la $(XMLRPC_DIR)/lib/abyss/src/libxmlrpc_abyss.la
+XMLRPCLAS += $(XMLRPC_DIR)/lib/expat/xmlparse/libxmlrpc_xmlparse.la
 
 LOCAL_LDFLAGS = $(XMLRPCLAS)
-LOCAL_CFLAGS=-I$(BASE)/libs/xmlrpc-c/include
+LOCAL_CFLAGS=-I$(XMLRPC_DIR)/include
 
-include ../../../../build/modmake.rules
+include $(BASE)/build/modmake.rules
 
 local_depend: $(XMLRPCLAS)
 
-$(XMLRPCLAS):
-	cd $(BASE)/libs/xmlrpc-c && $(MAKE)
-
+$(XMLRPCLAS): $(XMLRPC_DIR) $(XMLRPC_DIR)/.update
+	cd $(XMLRPC_DIR) && $(MAKE)
+	$(TOUCH_TARGET)