diff --git a/build/autoconf/match-dir.sh b/build/autoconf/match-dir.sh
new file mode 100755
index 0000000000000000000000000000000000000000..258e6a34201a94931eea0cf023cff13b4e22723f
--- /dev/null
+++ b/build/autoconf/match-dir.sh
@@ -0,0 +1,93 @@
+#!/bin/sh
+#
+# The contents of this file are subject to the Netscape Public License
+# Version 1.0 (the "NPL"); you may not use this file except in
+# compliance with the NPL.  You may obtain a copy of the NPL at
+# http://www.mozilla.org/NPL/
+#
+# Software distributed under the NPL is distributed on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
+# for the specific language governing rights and limitations under the
+# NPL.
+#
+# The Initial Developer of this code under the NPL is Netscape
+# Communications Corporation.  Portions created by Netscape are
+# Copyright (C) 1998 Netscape Communications Corporation.  All Rights
+# Reserved.
+#
+
+#
+# This script will match a dir with a set of dirs.
+#
+# Usage: match-dir.sh match [dir1 dir2 ... dirn]
+#
+# Send comments, improvements, bugs to ramiro@netscape.com
+# 
+
+# Make sure a Makefile.in exists
+#if [ $# -lt 1 ]
+#then
+#	echo
+#	echo "Usage: `basename $0` match [dir1 dir2 ... dirn]"
+#	echo
+#
+#	exit 1
+#fi
+
+# Make sure a Makefile.in exists
+if [ ! -f Makefile.in ]
+then
+	echo
+	echo "There ain't no 'Makefile.in' over here: $pwd, dude."
+	echo
+
+	exit 1
+fi
+
+# Use DEPTH in the Makefile.in to determine the depth
+depth=`grep -w DEPTH Makefile.in  | grep -e "\.\." | awk -F"=" '{ print $2; }'`
+
+# Determine the depth count
+n=`echo $depth | tr '/' ' ' | wc -w`
+
+# Determine the path (strip anything before the mozilla/ root)
+path=`pwd | awk -v count=$n -F"/" '\
+{ for(i=NF-count+0; i <= NF ; i++) \
+{ \
+if (i!=NF) \
+  { printf "%s/", $i } \
+else \
+  { printf "%s", $i } \
+} \
+}'`
+
+match=$path
+
+for i in $*
+do
+#	echo "Looking for $match in $i"
+
+	echo $i | grep -q -x $match
+
+	if [ $? -eq 0 ]
+	then
+		echo "1"
+
+		exit 0
+	fi
+
+#	echo "Looking for $i in $match"
+
+	echo $match | grep -q $i
+
+	if [ $? -eq 0 ]
+	then
+		echo "1"
+
+		exit 0
+	fi
+done
+
+echo "0"
+
+exit 0
diff --git a/build/autoconf/print-depth-path.sh b/build/autoconf/print-depth-path.sh
new file mode 100755
index 0000000000000000000000000000000000000000..cd4ae0a283308cb4eeb80568d09029716ab3bdb7
--- /dev/null
+++ b/build/autoconf/print-depth-path.sh
@@ -0,0 +1,59 @@
+#!/bin/sh
+#
+# The contents of this file are subject to the Netscape Public License
+# Version 1.0 (the "NPL"); you may not use this file except in
+# compliance with the NPL.  You may obtain a copy of the NPL at
+# http://www.mozilla.org/NPL/
+#
+# Software distributed under the NPL is distributed on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
+# for the specific language governing rights and limitations under the
+# NPL.
+#
+# The Initial Developer of this code under the NPL is Netscape
+# Communications Corporation.  Portions created by Netscape are
+# Copyright (C) 1998 Netscape Communications Corporation.  All Rights
+# Reserved.
+#
+
+#
+# This script will print the depth path for a mozilla directory based
+# on the info in Makefile.in
+#
+# Its a hack.  Its brute force.  Its horrible.  
+# It dont use Artificial Intelligence.  It dont use Virtual Reality.
+# Its not perl.  Its not python.   But it works.
+#
+# Usage: print-depth-path.sh
+#
+# Send comments, improvements, bugs to ramiro@netscape.com
+# 
+
+# Make sure a Makefile.in exists
+if [ ! -f Makefile.in ]
+then
+	echo
+	echo "There ain't no 'Makefile.in' over here: $pwd, dude."
+	echo
+
+	exit
+fi
+
+# Use DEPTH in the Makefile.in to determine the depth
+depth=`grep -w DEPTH Makefile.in  | grep -e "\.\." | awk -F"=" '{ print $2; }'`
+
+# Determine the depth count
+n=`echo $depth | tr '/' ' ' | wc -w`
+
+# Determine the path (strip anything before the mozilla/ root)
+path=`pwd | awk -v count=$n -F"/" '\
+{ for(i=NF-count+0; i <= NF ; i++) \
+{ \
+if (i!=NF) \
+  { printf "%s/", $i } \
+else \
+  { printf "%s", $i } \
+} \
+}'`
+
+echo $path
diff --git a/config/autoconf.mk.in b/config/autoconf.mk.in
index e06d52d635efc4640c0f10bb90ac2dabaa17eceb..d5f174474f1b4cf075714542013920151abc4706 100644
--- a/config/autoconf.mk.in
+++ b/config/autoconf.mk.in
@@ -53,6 +53,11 @@ MOZ_NATIVE_PNG	= @SYSTEM_PNG@
 
 MOZ_UPDATE_XTERM = @MOZ_UPDATE_XTERM@
 
+MOZ_INSURE = @MOZ_INSURE@
+MOZ_INSURIFYING = @MOZ_INSURIFYING@
+MOZ_INSURE_DIRS = @MOZ_INSURE_DIRS@
+MOZ_INSURE_EXCLUDE_DIRS = @MOZ_INSURE_EXCLUDE_DIRS@
+
 # Should the extra CFLAGS only be added in Makefile.ins that need them? 
 OS_CFLAGS	= @CFLAGS@ $(DSO_CFLAGS)
 OS_INCLUDES	= $(NSPR_CFLAGS) $(JPEG_CFLAGS) $(PNG_CFLAGS) $(ZLIB_CFLAGS)
@@ -75,6 +80,10 @@ CXX		= @CXX@
 GNU_CC		= @GNU_CC@
 GNU_CXX		= @GNU_CXX@
 
+ifdef MOZ_INSURIFYING
+include $(topsrcdir)/config/insure.mk
+endif # MOZ_INSURIFYING
+
 ACEMACS		= @EMACS@
 ACPERL		= @PERL@
 ACRANLIB	= @RANLIB@
diff --git a/config/insure.mk b/config/insure.mk
new file mode 100644
index 0000000000000000000000000000000000000000..04e32ab48ee3bb234792f12cbb0c87f298975a41
--- /dev/null
+++ b/config/insure.mk
@@ -0,0 +1,31 @@
+#
+# The contents of this file are subject to the Netscape Public License
+# Version 1.0 (the "NPL"); you may not use this file except in
+# compliance with the NPL.  You may obtain a copy of the NPL at
+# http://www.mozilla.org/NPL/
+#
+# Software distributed under the NPL is distributed on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
+# for the specific language governing rights and limitations under the
+# NPL.
+#
+# The Initial Developer of this code under the NPL is Netscape
+# Communications Corporation.  Portions created by Netscape are
+# Copyright (C) 1998 Netscape Communications Corporation.  All Rights
+# Reserved.
+#
+
+INSURE_MATCH_SCRIPT=$(topsrcdir)/build/autoconf/match-dir.sh
+
+INSURE_EXCLUDE=$(shell $(INSURE_MATCH_SCRIPT) $(MOZ_INSURE_EXCLUDE_DIRS))
+
+INSURE_INCLUDE=$(shell $(INSURE_MATCH_SCRIPT) $(MOZ_INSURE_DIRS))
+
+ifeq ($(INSURE_EXCLUDE),0)
+
+ifeq ($(INSURE_INCLUDE),1)
+CC		= $(MOZ_INSURE) gcc
+CXX		= $(MOZ_INSURE) g++
+endif # INSURE_INCLUDE == 1
+
+endif # INSURE_EXCLUDE == 0
diff --git a/configure.in b/configure.in
index a2c1d7ed7d94c114a58899c19d211e5c9edb0e3d..b303bea767f79c54b6b1b7a457f5fc9b66c1b8e0 100644
--- a/configure.in
+++ b/configure.in
@@ -16,9 +16,12 @@ dnl are Copyright (C) 1998 Christopher Seawood.  All Rights Reserved.
 dnl
 dnl Contributors:
 dnl Jamie Zawinski <jwz@jwz.org>	gettimeofday args check
+dnl
 dnl Christopher Blizzard <blizzard@appliedtheory.com>
 dnl					gnomefe update & enable-pthreads
+dnl
 dnl Ramiro Estrugo <ramiro@netscape.com>	X11 makedepend support
+dnl                                         Insure support.
 dnl
 dnl Process this file with autoconf to produce a configure script.
 dnl ========================================================
@@ -134,6 +137,7 @@ case "$target" in
 *-*-aix*)
     DSO_CFLAGS=
     ;;
+
 *-*-solaris*) 
     AC_DEFINE(BROKEN_QSORT)
     if test -z "$GNU_CC"; then
@@ -549,6 +553,18 @@ MOZ_ARG_ENABLE_BOOL(gprof,
 [  --enable-gprof	  enable gprof symbols],
   [ GPROF_CFLAGS="-pg" ])
 
+MOZ_ARG_ENABLE_BOOL(insure,
+[  --enable-insure	  enable insure++ instrumentation (linux only)],
+  [ MOZ_INSURE="insure" MOZ_INSURIFYING=1 MOZ_INSURE_DIRS="mozilla" MOZ_INSURE_EXCLUDE_DIRS="mozilla/config" ])
+
+MOZ_ARG_WITH_STRING(insure-dirs,
+[  --with-insure-dirs=\$dirs dirs to instrument ],
+  MOZ_INSURE_DIRS=$withval )
+
+MOZ_ARG_WITH_STRING(insure-exclude-dirs,
+[  --with-insure-exclude-dirs=\$dirs dirs to instrument ],
+  MOZ_INSURE_EXCLUDE_DIRS="mozilla/config $withval" )
+
 MOZ_ARG_ENABLE_BOOL(profile,
 [  --enable-profile        enable profiling (solaris only)],
   MOZILLA_GPROF=1)
@@ -625,6 +641,10 @@ AC_SUBST(MOZ_OJI)
 AC_SUBST(MOZ_DEBUG)
 AC_SUBST(MOZ_DEBUG_MODULES)
 AC_SUBST(MOZILLA_GPROF)
+AC_SUBST(MOZ_INSURE)
+AC_SUBST(MOZ_INSURE_DIRS)
+AC_SUBST(MOZ_INSURE_EXCLUDE_DIRS)
+AC_SUBST(MOZ_INSURIFYING)
 AC_SUBST(MOZ_MAIL_NEWS)
 AC_SUBST(MOZ_LDAP)
 AC_SUBST(MOZ_EDITOR)