diff --git a/Makefile b/Makefile
index 22a016c4f6680c54f78e0c644c4b4f95dded7921..9a266645127c78f127db102d56821e44b0fa5ff6 100644
--- a/Makefile
+++ b/Makefile
@@ -239,10 +239,6 @@ OTHER_SUBDIRS:=utils agi
 SUBDIRS:=$(OTHER_SUBDIRS) $(MOD_SUBDIRS)
 SUBDIRS_INSTALL:=$(SUBDIRS:%=%-install)
 SUBDIRS_CLEAN:=$(SUBDIRS:%=%-clean)
-SUBDIRS_CLEAN_DEPEND:=$(SUBDIRS:%=%-clean-depend)
-MOD_SUBDIRS_DEPEND:=$(MOD_SUBDIRS:%=%-depend)
-OTHER_SUBDIRS_DEPEND:=$(OTHER_SUBDIRS:%=%-depend)
-SUBDIRS_DEPEND:=$(OTHER_SUBDIRS_DEPEND) $(MOD_SUBDIRS_DEPEND)
 SUBDIRS_UNINSTALL:=$(SUBDIRS:%=%-uninstall)
 MOD_SUBDIRS_EMBED_LDSCRIPT:=$(MOD_SUBDIRS:%=%-embed-ldscript)
 MOD_SUBDIRS_EMBED_LDFLAGS:=$(MOD_SUBDIRS:%=%-embed-ldflags)
@@ -306,7 +302,7 @@ makeopts.embed_rules: menuselect.makeopts
 	@$(MAKE) --no-print-directory $(MOD_SUBDIRS_EMBED_LDFLAGS)
 	@$(MAKE) --no-print-directory $(MOD_SUBDIRS_EMBED_LIBS)
 
-$(SUBDIRS): depend makeopts.embed_rules
+$(SUBDIRS): include/asterisk/version.h include/asterisk/build.h include/asterisk/buildopts.h defaults.h makeopts.embed_rules
 
 # ensure that all module subdirectories are processed before 'main' during
 # a parallel build, since if there are modules selected to be embedded the
@@ -348,19 +344,13 @@ include/asterisk/build.h:
 	fi
 	@rm -f $@.tmp
 
-$(SUBDIRS_CLEAN_DEPEND):
-	@$(MAKE) --no-print-directory -C $(@:-clean-depend=) clean-depend
-
 $(SUBDIRS_CLEAN):
 	@$(MAKE) --no-print-directory -C $(@:-clean=) clean
 
-clean-depend: $(SUBDIRS_CLEAN_DEPEND)
-
-clean: $(SUBDIRS_CLEAN) clean-depend
+clean: $(SUBDIRS_CLEAN)
 	rm -f defaults.h
 	rm -f include/asterisk/build.h
 	rm -f include/asterisk/version.h
-	rm -f .depend
 	@$(MAKE) -C menuselect clean
 	cp -f .cleancount .lastclean
 
@@ -404,7 +394,6 @@ update:
 			grep ^C update.out | cut -b4- ; \
 		fi ; \
 		rm -f update.out; \
-		$(MAKE) clean-depend; \
 	else \
 		echo "Not under version control";  \
 	fi
@@ -636,14 +625,6 @@ config:
 		echo "We could not install init scripts for your operating system."; \
 	fi
 
-$(MOD_SUBDIRS_DEPEND):
-	@ASTCFLAGS="$(MOD_SUBDIR_CFLAGS) $(ASTCFLAGS)" $(MAKE) --no-print-directory -C $(@:-depend=) depend
-
-$(OTHER_SUBDIRS_DEPEND):
-	@ASTCFLAGS="$(OTHER_SUBDIR_CFLAGS) $(ASTCFLAGS)" $(MAKE) --no-print-directory -C $(@:-depend=) depend
-
-depend: include/asterisk/version.h include/asterisk/buildopts.h include/asterisk/build.h defaults.h $(SUBDIRS_DEPEND)
-
 sounds:
 	$(MAKE) -C sounds all
 
@@ -703,4 +684,4 @@ menuselect-tree: $(foreach dir,$(filter-out main,$(MOD_SUBDIRS)),$(wildcard $(di
 	@echo "Generating input for menuselect ..."
 	@build_tools/prep_moduledeps > $@
 
-.PHONY: menuselect main sounds clean clean-depend dist-clean distclean all prereqs depend cleantest uninstall _uninstall uninstall-all dont-optimize $(SUBDIRS_INSTALL) $(SUBDIRS_CLEAN) $(SUBDIRS_CLEAN_DEPEND) $(SUBDIRS_DEPEND) $(SUBDIRS_UNINSTALL) $(SUBDIRS) $(MOD_SUBDIRS_EMBED_LDSCRIPT) $(MOD_SUBDIRS_EMBED_LDFLAGS) $(MOD_SUBDIRS_EMBED_LIBS)
+.PHONY: menuselect main sounds clean dist-clean distclean all prereqs cleantest uninstall _uninstall uninstall-all dont-optimize $(SUBDIRS_INSTALL) $(SUBDIRS_CLEAN) $(SUBDIRS_UNINSTALL) $(SUBDIRS) $(MOD_SUBDIRS_EMBED_LDSCRIPT) $(MOD_SUBDIRS_EMBED_LDFLAGS) $(MOD_SUBDIRS_EMBED_LIBS)
diff --git a/Makefile.moddir_rules b/Makefile.moddir_rules
index 6925636b9b03c0e5bae21a825298dc2defacaee5..c614c2ab5501e65f1ed799d0b2c2f70e3bb575d7 100644
--- a/Makefile.moddir_rules
+++ b/Makefile.moddir_rules
@@ -40,7 +40,7 @@ $(addsuffix .so,$(filter $(LOADABLE_MODS),$(CC_MODS))): %.so: %.oo
 modules.link: $(addsuffix .o,$(filter $(EMBEDDED_MODS),$(C_MODS)))
 modules.link: $(addsuffix .oo,$(filter $(EMBEDDED_MODS),$(CC_MODS)))
 
-.PHONY: clean clean-depend depend uninstall _all
+.PHONY: clean uninstall _all
 
 ifneq ($(LOADABLE_MODS),)
 _all: $(LOADABLE_MODS:%=%.so)
@@ -67,11 +67,9 @@ modules.link:
 	@for file in $(patsubst %,$(SUBDIR)/%,$(filter %.o,$^)); do echo "INPUT (../$${file})" >> $@; done
 	@for file in $(patsubst %,$(SUBDIR)/%,$(filter-out %.o,$^)); do echo "INPUT (../$${file})" >> $@; done
 
-clean-depend::
-	rm -f .depend
-
-clean:: clean-depend
+clean::
 	rm -f *.so *.o *.oo
+	rm -f .*.o.d .*.oo.d
 	rm -f modules.link
 
 install:: all
@@ -79,11 +77,6 @@ install:: all
 
 uninstall::
 
-ifneq ($(wildcard .depend),)
-  include .depend
+ifneq ($(wildcard .*.d),)
+   include .*.d
 endif
-
-depend: .depend
-
-.depend:
-	../build_tools/mkdep $(ASTCFLAGS) `ls *.c *.cc 2> /dev/null`
diff --git a/Makefile.rules b/Makefile.rules
index 59ced05eacad406001e9722bae90a7badb5aceac..591322ef2fcab35e71da8c74df03474afc910d52 100644
--- a/Makefile.rules
+++ b/Makefile.rules
@@ -38,11 +38,19 @@ endif
 
 %.o: %.c
 	$(ECHO_PREFIX) echo "   [CC] $< -> $@"
+ifeq ($(AST_DEVMODE),yes)
+	$(CMD_PREFIX) $(CC) -o $@ -c $< $(ASTCFLAGS) -MMD -MT $@ -MF .$(subst /,_,$@).d -MP
+else
 	$(CMD_PREFIX) $(CC) -o $@ -c $< $(ASTCFLAGS)
+endif
 
 %.oo: %.cc
 	$(ECHO_PREFIX) echo "   [CXX] $< -> $@"
+ifeq ($(AST_DEVMODE),yes)
+	$(CMD_PREFIX) $(CXX) -o $@ -c $< $(ASTCFLAGS) -MMD -MT $@ -MF .$(subst /,_,$@).d -MP
+else
 	$(CMD_PREFIX) $(CXX) -o $@ -c $< $(ASTCFLAGS)
+endif
 
 %.c: %.y
 	$(ECHO_PREFIX) echo "   [BISON] $< -> $@"
diff --git a/agi/Makefile b/agi/Makefile
index 3a3495138b1ca8565aa719ee7b20c89b6459630d..4066cda0bb7e2e554880c7b46423f5af548f4197 100644
--- a/agi/Makefile
+++ b/agi/Makefile
@@ -11,7 +11,7 @@
 # the GNU General Public License
 #
 
-.PHONY: clean clean-depend all depend uninstall
+.PHONY: clean all uninstall
 
 AGIS=agi-test.agi eagi-test eagi-sphinx-test jukebox.agi
 
@@ -37,18 +37,11 @@ install: all
 uninstall:
 	for x in $(AGIS); do rm -f $(DESTDIR)$(AGI_DIR)/$$x ; done
 
-clean-depend:
-	rm -f .depend
-
-clean: clean-depend
+clean:
 	rm -f *.so *.o look eagi-test eagi-sphinx-test
+	rm -f .*.o.d .*.oo.d
 	rm -f strcompat.c
 
-ifneq ($(wildcard .depend),)
-  include .depend
+ifneq ($(wildcard .*.d),)
+   include .*.d
 endif
-
-depend: .depend
-
-.depend:
-	../build_tools/mkdep $(CFLAGS) `ls *.c`
diff --git a/build_tools/mkdep b/build_tools/mkdep
deleted file mode 100755
index 84f969b1d6046f1a38a140b408fe34849af0f470..0000000000000000000000000000000000000000
--- a/build_tools/mkdep
+++ /dev/null
@@ -1,123 +0,0 @@
-#!/bin/sh -
-#
-#	$OpenBSD: mkdep.gcc.sh,v 1.8 1998/09/02 06:40:07 deraadt Exp $
-#	$NetBSD: mkdep.gcc.sh,v 1.9 1994/12/23 07:34:59 jtc Exp $
-#
-# Copyright (c) 1991, 1993
-#	The Regents of the University of California.  All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-#    notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-#    notice, this list of conditions and the following disclaimer in the
-#    documentation and/or other materials provided with the distribution.
-# 3. All advertising materials mentioning features or use of this software
-#    must display the following acknowledgement:
-#	This product includes software developed by the University of
-#	California, Berkeley and its contributors.
-# 4. Neither the name of the University nor the names of its contributors
-#    may be used to endorse or promote products derived from this software
-#    without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-# SUCH DAMAGE.
-#
-#	@(#)mkdep.gcc.sh	8.1 (Berkeley) 6/6/93
-#
-
-D=.depend			# default dependency file is .depend
-append=0
-pflag=
-dflag=
-
-while :
-	do case "$1" in
-		# -a appends to the depend file
-		-a)
-			append=1
-			shift ;;
-
-		# -f allows you to select a makefile name
-		-f)
-			D=$2
-			shift; shift ;;
-
-		# the -p flag produces "program: program.c" style dependencies
-		# so .o's don't get produced
-		-p)
-			pflag=p
-			shift ;;
-
-      		# the -d flag produces double-colon rules instead of single-colon rules
-      		-d)
-			dflag=d
-			shift ;;
-
-		*)
-			break ;;
-	esac
-done
-
-if [ $# = 0 ] ; then
-	echo 'usage: mkdep [-p] [-d] [-f depend_file] [cc_flags] file ...'
-	exit 1
-fi
-
-DTMP=/tmp/mkdep$$
-TMP=$DTMP/mkdep
-
-um=`umask`
-umask 022
-mkdir $DTMP
-if [ $? != 0 ] ; then
-	echo failed to create tmp dir $DTMP
-	exit 1
-fi
-
-umask $um
-trap 'rm -rf $DTMP ; trap 2 ; kill -2 $$' 1 2 3 13 15
-
-if [ x$pflag = xp ]; then
-	${CC:-cc} -M "$@" 2>/dev/null | sed -e 's;\.o :; :;' -e 's; \./; ;g' > $TMP
-elif [ x$dflag = xd ]; then
-	${CC:-cc} -M "$@" 2>/dev/null | sed -e 's;\.o:;\.o::;' -e 's; \./; ;g' > $TMP
-else
-	${CC:-cc} -M "$@" 2>/dev/null | sed -e 's; \./; ;g' > $TMP
-fi
-
-if [ $? != 0 ]; then
-	echo 'mkdep: compile failed.'
-	rm -rf $DTMP
-	exit 1
-fi
-
-if [ $append = 1 ]; then
-	cat $TMP >> $D
-	if [ $? != 0 ]; then
-		echo 'mkdep: append failed.'
-		rm -rf $DTMP
-		exit 1
-	fi
-else
-	mv $TMP $D
-	if [ $? != 0 ]; then
-		echo 'mkdep: rename failed.'
-		rm -rf $DTMP
-		exit 1
-	fi
-fi
-
-rm -rf $DTMP
-exit 0
diff --git a/main/Makefile b/main/Makefile
index ac543baa33bf23691cd423e45ce44b7f3eea3349..4d1bb086099bef5f04b5578538063d882269035b 100644
--- a/main/Makefile
+++ b/main/Makefile
@@ -140,7 +140,6 @@ asterisk: $(OBJS) editline/libedit.a db1-ast/libdb1.a $(AST_EMBED_LDSCRIPTS)
 
 clean::
 	rm -f asterisk
-	rm -f .depend
 	@if [ -f editline/Makefile ]; then $(MAKE) -C editline distclean ; fi
 	@$(MAKE) -C db1-ast clean
 	@$(MAKE) -C stdtime clean
diff --git a/utils/Makefile b/utils/Makefile
index 747e048f201c81fd9b328ed4cba2c2f4c4b0abba..7d8d553743a705ae57c427c70d041fc8f301fcf5 100644
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -11,7 +11,7 @@
 # the GNU General Public License
 #
 
-.PHONY: clean clean-depend all depend uninstall
+.PHONY: clean all uninstall
 
 ALL_UTILS:=astman smsq stereorize streamplayer aelparse muted
 UTILS:=$(ALL_UTILS)
@@ -51,11 +51,9 @@ install:
 uninstall:
 	for x in $(ALL_UTILS); do rm -f $$x $(DESTDIR)$(ASTSBINDIR)/$$x; done
 
-clean-depend:
-	rm -f .depend
-
-clean: clean-depend
+clean:
 	rm -f *.o $(ALL_UTILS) check_expr
+	rm -f .*.o.d .*.oo.d
 	rm -f md5.c strcompat.c ast_expr2.c ast_expr2f.c pbx_ael.c
 	rm -f aelparse.c aelbison.c
 
@@ -122,11 +120,6 @@ streamplayer: streamplayer.o
 muted: muted.o
 muted: LIBS+=$(AUDIO_LIBS)
 
-ifneq ($(wildcard .depend),)
-  include .depend
+ifneq ($(wildcard .*.d),)
+   include .*.d
 endif
-
-depend: .depend
-
-.depend:
-	../build_tools/mkdep $(ASTCFLAGS) `ls *.c`