diff --git a/Makefile.inc1 b/Makefile.inc1
index ab4343e..4f3bd67 100644
--- a/Makefile.inc1
+++ b/Makefile.inc1
@@ -797,6 +797,7 @@ _gcc34_tools= gnu/usr.bin/cc34/cc_prep gnu/usr.bin/cc34/cc_tools
 .endif
 _gcc41_cross= gnu/usr.bin/cc41
 _gcc41_tools= gnu/usr.bin/cc41/cc_prep gnu/usr.bin/cc41/cc_tools
+_custom_cross= libexec/customcc
 _binutils= gnu/usr.bin/binutils217
 
 .if exists(${.CURDIR}/kerberos5) && exists(${.CURDIR}/crypto) && \
@@ -826,7 +827,7 @@ _btxld=	usr.sbin/btxld
 cross-tools:
 .for _tool in ${_btxld} ${_binutils} \
 	      usr.bin/objformat usr.bin/crunch/crunchide \
-	      ${_gcc34_cross} ${_gcc41_cross}
+	      ${_gcc34_cross} ${_gcc41_cross} ${_custom_cross}
 	${ECHODIR} "===> ${_tool} (cross-tools)"; \
 		cd ${.CURDIR}/${_tool}; \
 		${MAKE} DIRPRFX=${_tool}/ obj; \
diff --git a/contrib/diffutils-2.8/src/diff.h b/contrib/diffutils-2.8/src/diff.h
index e7a4b2d..2b7db69 100644
--- a/contrib/diffutils-2.8/src/diff.h
+++ b/contrib/diffutils-2.8/src/diff.h
@@ -21,7 +21,7 @@
    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #include "system.h"
-#include <regex.h>
+#include <gnuregex.h>
 #include <stdio.h>
 #include <unlocked-io.h>
 
diff --git a/contrib/gcc-4.1/gcc/toplev.h b/contrib/gcc-4.1/gcc/toplev.h
index 35d53eb..beab8fa 100644
--- a/contrib/gcc-4.1/gcc/toplev.h
+++ b/contrib/gcc-4.1/gcc/toplev.h
@@ -171,6 +171,7 @@ extern int floor_log2                  (unsigned HOST_WIDE_INT);
 #  define CTZ_HWI __builtin_ctz
 # endif
 
+#if 0
 extern inline int
 floor_log2 (unsigned HOST_WIDE_INT x)
 {
@@ -182,6 +183,7 @@ exact_log2 (unsigned HOST_WIDE_INT x)
 {
   return x == (x & -x) && x ? (int) CTZ_HWI (x) : -1;
 }
+#endif
 #endif /* GCC_VERSION >= 3004 */
 
 /* Functions used to get and set GCC's notion of in what directory
diff --git a/etc/Makefile b/etc/Makefile
index 67921e8..bfc08ea 100644
--- a/etc/Makefile
+++ b/etc/Makefile
@@ -54,7 +54,7 @@ DIRS+=	secure/usr.bin/openssl
 #
 BIN2=	pccard_ether rc.firewall rc.suspend rc.resume
 
-DEFAULTS= rc.conf make.conf periodic.conf uuids
+DEFAULTS= compilers.conf make.conf periodic.conf rc.conf uuids
 
 MTREE=	BSD.include.dist BSD.local.dist BSD.root.dist BSD.usr.dist \
 	BSD.var.dist
diff --git a/etc/defaults/compilers.conf b/etc/defaults/compilers.conf
new file mode 100644
index 0000000..ea9ba41
--- /dev/null
+++ b/etc/defaults/compilers.conf
@@ -0,0 +1,9 @@
+# clang from SVN trunk
+clang_CC=/usr/local/bin/clang
+clang_CFLAGS="-fno-color-diagnostics -std=gnu89"
+clang_VERSION=4.1.2
+
+# gcc44 from pkgsrc
+gcc44_CC=/usr/pkg/gcc44/bin/cc
+gcc44_CXX=/usr/pkg/gcc44/bin/c++
+gcc44_CPP=/usr/pkg/gcc44/bin/cpp
diff --git a/etc/mtree/BSD.usr.dist b/etc/mtree/BSD.usr.dist
index f4b8ad4..2a6106f 100644
--- a/etc/mtree/BSD.usr.dist
+++ b/etc/mtree/BSD.usr.dist
@@ -65,6 +65,8 @@
             elf
             ..
         ..
+        custom
+        ..
         gcc34
         ..
         gcc41
diff --git a/gnu/usr.bin/diff/Makefile b/gnu/usr.bin/diff/Makefile
index 1ce18df..6c1d856 100644
--- a/gnu/usr.bin/diff/Makefile
+++ b/gnu/usr.bin/diff/Makefile
@@ -16,7 +16,6 @@ SRCS+=xmalloc.c strtoumax.c cmpbuf.c exitfail.c error.c quotesys.c \
 # Important for ctype macros!
 CFLAGS+=-funsigned-char
 
-CFLAGS+=-I${.OBJDIR} -I-
 CFLAGS+=-I${.CURDIR}/../../../contrib/diffutils-2.8
 CFLAGS+=-I${.CURDIR}/../../../contrib/diffutils-2.8/src
 CFLAGS+=-I${.CURDIR}/../../../contrib/diffutils-2.8/lib
@@ -28,6 +27,6 @@ DPADD+=	${LIBGNUREGEX}
 LDADD+=	-lgnuregex
 
 CONTRIBDIR=${.CURDIR}/../../../contrib/diffutils-2.8/src
-SRCS+=diff.c.patch diff.h.patch
+SRCS+=diff.c.patch
 
 .include <bsd.prog.mk>
diff --git a/gnu/usr.bin/diff/diff.h.patch b/gnu/usr.bin/diff/diff.h.patch
deleted file mode 100644
index 74b0bd2..0000000
--- a/gnu/usr.bin/diff/diff.h.patch
+++ /dev/null
@@ -1,12 +0,0 @@
-$DragonFly: src/gnu/usr.bin/diff/diff.h.patch,v 1.1 2007/08/05 05:47:00 pavalos Exp $
---- diff.h.orig	2007-08-03 00:26:58.000000000 -0400
-+++ diff.h	2007-08-03 00:27:17.000000000 -0400
-@@ -21,7 +21,7 @@
-    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
- 
- #include "system.h"
--#include <regex.h>
-+#include <gnuregex.h>
- #include <stdio.h>
- #include <unlocked-io.h>
- 
diff --git a/lib/libc/stdtime/localtime.c b/lib/libc/stdtime/localtime.c
index 88cfa54..85efeec 100644
--- a/lib/libc/stdtime/localtime.c
+++ b/lib/libc/stdtime/localtime.c
@@ -308,10 +308,13 @@ settzname(void)
 static int
 differ_by_repeat(const time_t t1, const time_t t0)
 {
+	int_fast64_t _t0 = t0;
+	int_fast64_t _t1 = t1;
+
 	if (TYPE_INTEGRAL(time_t) &&
 		TYPE_BIT(time_t) - TYPE_SIGNED(time_t) < SECSPERREPEAT_BITS)
 			return 0;
-	return t1 - t0 == SECSPERREPEAT;
+	return _t1 - _t0 == SECSPERREPEAT;
 }
 
 static int
diff --git a/lib/libthread_xu/thread/thr_fork.c b/lib/libthread_xu/thread/thr_fork.c
index cdacc3d..235f35c 100644
--- a/lib/libthread_xu/thread/thr_fork.c
+++ b/lib/libthread_xu/thread/thr_fork.c
@@ -105,8 +105,8 @@ _pthread_atfork(void (*prepare)(void), void (*parent)(void),
 /*
  * For a while, allow libpthread to work with a libc that doesn't
  * export the malloc lock.
+ * #pragma weak __malloc_lock
  */
-#pragma weak __malloc_lock
 
 pid_t _fork(void);
 
diff --git a/libexec/Makefile b/libexec/Makefile
index f4d8a0e..471a9f7 100644
--- a/libexec/Makefile
+++ b/libexec/Makefile
@@ -6,6 +6,7 @@
 SUBDIR=	atrun \
 	bootpd \
 	comsat \
+	customcc \
 	dma \
 	fingerd \
 	ftpd \
diff --git a/libexec/customcc/Makefile b/libexec/customcc/Makefile
new file mode 100644
index 0000000..1627f9b
--- /dev/null
+++ b/libexec/customcc/Makefile
@@ -0,0 +1,13 @@
+SCRIPTS=	cc
+SCRIPTSDIR=	/usr/libexec/custom
+SYMLINKS=	cc ${SCRIPTSDIR}/cpp \
+		cc ${SCRIPTSDIR}/c++ \
+		cc ${SCRIPTSDIR}/gcc \
+		cc ${SCRIPTSDIR}/g++
+CLEANFILES=	cc
+NOMAN=
+
+beforeinstall:
+	sed "s#@@PREFIX2@@#${USRDATA_PREFIX}/usr#g" ${.CURDIR}/cc.sh >cc
+
+.include <bsd.prog.mk>
diff --git a/libexec/customcc/cc.sh b/libexec/customcc/cc.sh
new file mode 100644
index 0000000..3c2faec
--- /dev/null
+++ b/libexec/customcc/cc.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+CMDNAME=$(basename $0)
+CMDDIR=$(dirname $0)
+
+. /etc/defaults/compilers.conf
+[ -f /etc/compilers.conf ] && . /etc/compilers.conf
+
+CUSTOM_CC=`eval echo \$\{${CCVER}_CC\}`
+CUSTOM_CFLAGS=`eval echo \$\{${CCVER}_CFLAGS\}`
+CUSTOM_CXX=`eval echo \$\{${CCVER}_CXX\}`
+CUSTOM_CXXFLAGS=`eval echo \$\{${CCVER}_CXXFLAGS\}`
+CUSTOM_CPP=`eval echo \$\{${CCVER}_CPP\}`
+CUSTOM_CPPFLAGS=`eval echo \$\{${CCVER}_CPPFLAGS\}`
+CUSTOM_VERSION=`eval echo \$\{${CCVER}_VERSION\}`
+
+# XXX clang c++ hack
+if [ "${CCVER}" = "clang" ]; then
+	RESULT=`echo "$@" | \
+	    grep -e "\.cc" -e "\.cp" -e "\.cxx" -e "\.CPP" -e "\.c++" -e "\.C"`
+	if [ "${RESULT}" != "" -o "${CMDNAME}" = "c++" -o "${CMDNAME}" = "g++" ]; then
+		exec ${CMDDIR}/../gcc41/c++ "$@"
+	elif [ "${CMDNAME}" = "cpp" ]; then
+		exec ${CMDDIR}/../gcc41/cpp "$@"
+	fi
+fi
+
+INCOPT="-isystem @@PREFIX2@@/include -isystem @@PREFIX2@@/libdata/gcc41"
+
+if [ "${CUSTOM_VERSION}" != "" -a "$1" = "-dumpversion" ]; then
+	echo ${CUSTOM_VERSION}
+elif [ "${CMDNAME}" = "cc" -o "${CMDNAME}" = "gcc" ]; then
+	exec ${CUSTOM_CC} ${INCOPT} ${CUSTOM_CFLAGS} "$@"
+elif [ "${CMDNAME}" = "c++" -o "${CMDNAME}" = "g++" ]; then
+	exec ${CUSTOM_CXX} ${INCOPT} ${CUSTOM_CXXFLAGS} "$@"
+elif [ "${CMDNAME}" = "cpp" ]; then
+	exec ${CUSTOM_CPP} ${INCOPT} ${CUSTOM_CPPFLAGS} "$@"
+else
+	echo "unknown compiler ${CMDNAME}"
+	exit 1
+fi
diff --git a/libexec/rpc.rquotad/rquotad.c b/libexec/rpc.rquotad/rquotad.c
index f321e7c..268a2f8 100644
--- a/libexec/rpc.rquotad/rquotad.c
+++ b/libexec/rpc.rquotad/rquotad.c
@@ -26,7 +26,6 @@
 #include <unistd.h>
 
 #include <syslog.h>
-#include <varargs.h>
 
 #include <vfs/ufs/quota.h>
 #include <rpc/rpc.h>
diff --git a/share/examples/etc/README.examples b/share/examples/etc/README.examples
index 3d30dbb..d2bf37f 100644
--- a/share/examples/etc/README.examples
+++ b/share/examples/etc/README.examples
@@ -15,6 +15,7 @@ This directory contains the following files:
 amd.map		- configuration file for amd(8)
 apmd.conf	- configuration file for apmd(8)
 auth.conf	- authentication capability database
+compilers.conf	- configuration for non-base compilers
 crontab		- system scheduled command table
 csh.cshrc	- system-wide .cshrc for csh(1)
 csh.login	- system-wide .login for csh(1)
diff --git a/share/man/man5/Makefile b/share/man/man5/Makefile
index dc8808b..2ec1fc6 100644
--- a/share/man/man5/Makefile
+++ b/share/man/man5/Makefile
@@ -5,6 +5,7 @@
 #MISSING: dump.5 plot.5
 MAN=	acct.5 \
 	a.out.5 \
+	compilers.conf.5 \
 	core.5 \
 	devices.conf.5 \
 	dir.5 \
diff --git a/share/man/man5/compilers.conf.5 b/share/man/man5/compilers.conf.5
new file mode 100644
index 0000000..49ac8b2
--- /dev/null
+++ b/share/man/man5/compilers.conf.5
@@ -0,0 +1,116 @@
+.\"
+.\" Copyright (c) 2009
+.\"	The DragonFly Project.  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. Neither the name of The DragonFly Project 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 COPYRIGHT HOLDERS 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
+.\" COPYRIGHT HOLDERS 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.
+.\"
+.Dd June 6, 2009
+.Os
+.Dt COMPILERS.CONF 5
+.Sh NAME
+.Nm compilers.conf
+.Nd configuration file for external compilers
+.Sh SYNOPSIS
+.Pa /etc/compilers.conf
+.Sh DESCRIPTION
+The
+.Nm
+file allows to configure
+.Dq external
+compilers for usage with the
+.Dx
+.Xr build 7
+system.
+.Pp
+The
+.Pa /etc/defaults/compilers.conf
+file specifies the default settings for all variables, the
+.Pa /etc/compilers.conf
+file specifies override settings.
+.Pp
+The following variables are available:
+.Bl -tag -width ".Va <version>_CPPFLAGS"
+.It Va <version>_CC
+The pathname of the
+.Nm cc
+program of the compiler.
+.It Va <version>_CFLAGS
+Any additional flags to pass to
+.Va <version>_CC .
+.It Va <version>_CPP
+The pathname of the
+.Nm cpp
+program of the compiler.
+.It Va <version>_CPPFLAGS
+Any additional flags to pass to
+.Va <version>_CPP .
+.It Va <version>_CXX
+The pathname of the
+.Nm c++
+program of the compiler.
+.It Va <version>_CXXFLAGS
+Any additional flags to pass to
+.Va <version>_CXX .
+.It Va <version>_VERSION
+What to output when the
+.Fl dumpversion
+option is used.
+This helps
+.Nm clang
+with
+.Xr pkgsrc 7 .
+.El
+.Pp
+Once configured the compiler can then be used like this:
+.Bd -literal -offset indent
+cd /usr/pkgsrc/wip/gcc44
+[build and install gcc44]
+cd /usr/src
+env WORLD_CCVER=gcc44 make buildworld
+.Ed
+.Pp
+Defaults are provided for
+.Nm clang
+(installed from SVN trunk)
+and
+.Nm gcc44
+(installed from
+.Pa pkgsrc/wip ) .
+.Sh FILES
+.Bl -tag -width ".Pa /etc/compilers.conf" -compact
+.It Pa /etc/compilers.conf
+external compiler configuration file
+.El
+.Sh SEE ALSO
+.Xr objformat 1 ,
+.Xr build 7
+.Sh HISTORY
+The
+.Nm
+file first appeared in
+.Dx 2.3 .
diff --git a/share/mk/Makefile b/share/mk/Makefile
index 116dd52..a26ca3b 100644
--- a/share/mk/Makefile
+++ b/share/mk/Makefile
@@ -3,7 +3,7 @@
 #	@(#)Makefile	8.1 (Berkeley) 6/8/93
 
 FILES=	bsd.README
-FILES+=	bsd.cpu.mk bsd.cpu.gcc34.mk bsd.cpu.gcc41.mk
+FILES+=	bsd.cpu.mk bsd.cpu.gcc34.mk bsd.cpu.gcc41.mk bsd.cpu.custom.mk
 FILES+=	bsd.dep.mk bsd.doc.mk bsd.files.mk bsd.patch.mk
 FILES+=	bsd.incs.mk bsd.info.mk bsd.init.mk
 FILES+=	bsd.kmod.mk bsd.hostlib.mk
diff --git a/share/mk/bsd.cpu.custom.mk b/share/mk/bsd.cpu.custom.mk
new file mode 100644
index 0000000..65ca858
--- /dev/null
+++ b/share/mk/bsd.cpu.custom.mk
@@ -0,0 +1,7 @@
+# Set default CPU compile flags for custom compilers. Not much to see here.
+
+. if ${MACHINE_ARCH} == "i386"
+MACHINE_CPU = i486
+. elif ${MACHINE_ARCH} == "amd64"
+MACHINE_CPU = amd64 sse2 sse
+. endif
diff --git a/share/mk/bsd.cpu.mk b/share/mk/bsd.cpu.mk
index e7aa9a2..fcad0d7 100644
--- a/share/mk/bsd.cpu.mk
+++ b/share/mk/bsd.cpu.mk
@@ -17,11 +17,19 @@
 
 CCVER ?= gcc41
 _CCVER := ${CCVER}
+.if ${_CCVER} == "gcc34" || ${_CCVER} == "gcc41"
 .if exists(/usr/libexec/${_CCVER}/cc)
 HOST_CCVER?= ${_CCVER}
 .else
 HOST_CCVER?= gcc34
 .endif
+.else
+.if exists(/usr/libexec/custom/cc)
+HOST_CCVER?= ${CCVER}
+.else
+HOST_CCVER?= gcc34
+.endif
+.endif
 
 .if ${CCVER} == "gcc34"
 .  include <bsd.cpu.gcc34.mk>
@@ -32,7 +40,7 @@ HOST_CCVER?= gcc34
 .    include "${CCVER_BSD_CPU_MK}"
 .  endif
 .else
-.error "Either set CCVER to a known compiler or specify CCVER_BSD_CPU_MK"
+.  include <bsd.cpu.custom.mk>
 .endif
 
 # /usr/bin/cc depend on the CCVER environment variable, make sure CCVER is
diff --git a/sys/boot/pc32/boot2/Makefile b/sys/boot/pc32/boot2/Makefile
index 92006e1..8aaac07 100644
--- a/sys/boot/pc32/boot2/Makefile
+++ b/sys/boot/pc32/boot2/Makefile
@@ -10,6 +10,10 @@ NM?=		nm
 NXCFLAGS=
 NXLDFLAGS=
 
+.if ${CCVER} != "gcc34" && ${CCVER} != "gcc41"
+CCVER=		gcc41
+.endif
+
 .PATH: ${.CURDIR}/..
 .PATH: ${.CURDIR}/../../common
 .PATH: ${.CURDIR}/../../../../lib/libstand
@@ -63,7 +67,7 @@ CFLAGS+= -march=i386
 # the problem has been narrowed down to the 'boot2' code.  The /boot/loader
 # doesn't seem to have a problem.
 #
-CFLAGS+= -fno-unit-at-a-time
+#CFLAGS+= -fno-unit-at-a-time
 
 # Disable propolice on gcc that supports it
 .if ${CCVER} == "gcc34"
diff --git a/usr.bin/objformat/objformat.c b/usr.bin/objformat/objformat.c
index f2e4d0e..b853230 100644
--- a/usr.bin/objformat/objformat.c
+++ b/usr.bin/objformat/objformat.c
@@ -181,8 +181,14 @@ main(int argc, char **argv)
 			asprintf(&newcmd, "%s%s/%s/%s/%s",
 				chunk, base_path, env_value, objformat, cmd);
 		} else {
-			asprintf(&newcmd, "%s%s/%s/%s",
-				chunk, base_path, env_value, cmd);
+			if (strncmp(env_value, "gcc34", 5) != 0 &&
+			    strncmp(env_value, "gcc41", 5) != 0) {
+				asprintf(&newcmd, "%s%s/custom/%s",
+				    chunk, base_path, cmd);
+			} else {
+				asprintf(&newcmd, "%s%s/%s/%s",
+				    chunk, base_path, env_value, cmd);
+			}
 		}
 		if (newcmd == NULL)
 			err(1, "cannot allocate memory");
