After further discussion it Theo, here is a new version of the diff. It explicitly lists the gcc4 architectures now, introduces BUILD_GCC3 and BUILD_GCC4 variables and fixes installation of the c++ headers.
After applying this diff you need to: 1. Run make install in /usr/src/share/mk 2. Bootstrap clang by running: # pkg_add g++ # cd /usr/src/gnu/usr.bin/clang # make obj # make BOOTSTRAP_CLANG=yes # make install 3. Build libcompiler_rt # cd /usr/src/lib/libcompiler_rt # make obj # make depend # make # make install 4. Do a full build These instructions may not be 100% accurate yet ;). Index: gnu/lib/Makefile =================================================================== RCS file: /cvs/src/gnu/lib/Makefile,v retrieving revision 1.20 diff -u -p -r1.20 Makefile --- gnu/lib/Makefile 21 Jan 2017 12:40:49 -0000 1.20 +++ gnu/lib/Makefile 16 Apr 2017 18:30:53 -0000 @@ -6,9 +6,10 @@ SUBDIR+=libiberty libreadline .if make(obj) SUBDIR+=libobjc libstdc++ libstdc++-v3 libsupc++-v3 ../usr.bin/cc/libobjc .else -. if ${COMPILER_VERSION:L} == "gcc3" +. if ${BUILD_GCC3:L} == "yes" SUBDIR+=libobjc libstdc++ -. elif ${COMPILER_VERSION:L} == "gcc4" +. endif +. if ${BUILD_GCC4:L} == "gcc4" # XXX make sure we build libobjc & libstdc++-v3 from gcc4 SUBDIR+=../usr.bin/cc/libobjc SUBDIR+=libstdc++-v3 libsupc++-v3 Index: gnu/usr.bin/Makefile =================================================================== RCS file: /cvs/src/gnu/usr.bin/Makefile,v retrieving revision 1.58 diff -u -p -r1.58 Makefile --- gnu/usr.bin/Makefile 20 Feb 2017 01:00:26 -0000 1.58 +++ gnu/usr.bin/Makefile 16 Apr 2017 18:32:43 -0000 @@ -6,11 +6,13 @@ .if make(obj) SUBDIR+= cc clang gcc .else -. if ${COMPILER_VERSION:L} == "gcc3" +. if ${BUILD_GCC3:L} == "yes" SUBDIR+= gcc -. elif ${COMPILER_VERSION:L} == "gcc4" +. endif +. if ${BUILD_GCC4:L} == "yes" SUBDIR+= cc -. elif ${COMPILER_VERSION:L} == "clang" +. endif +. if ${BUILD_CLANG:L} == "yes" SUBDIR+= clang . endif .endif Index: gnu/usr.bin/clang/Makefile.inc =================================================================== RCS file: /cvs/src/gnu/usr.bin/clang/Makefile.inc,v retrieving revision 1.4 diff -u -p -r1.4 Makefile.inc --- gnu/usr.bin/clang/Makefile.inc 16 Feb 2017 02:08:42 -0000 1.4 +++ gnu/usr.bin/clang/Makefile.inc 27 Mar 2017 15:56:49 -0000 @@ -2,6 +2,11 @@ LLVM_SRCS?= ${.CURDIR}/../../../llvm +.if ${COMPILER_VERSION:L} != "clang" +CC= clang +CXX= clang++ +.endif + BOOTSTRAP_CLANG?=no .if ${BOOTSTRAP_CLANG} == "yes" CC= egcc Index: include/Makefile =================================================================== RCS file: /cvs/src/include/Makefile,v retrieving revision 1.218 diff -u -p -r1.218 Makefile --- include/Makefile 12 Mar 2017 23:28:13 -0000 1.218 +++ include/Makefile 16 Apr 2017 18:38:35 -0000 @@ -42,13 +42,15 @@ RDIRS= ../lib/libcurses ../lib/libedit \ ../usr.bin/lex ../gnu/lib/libreadline \ ../sys/arch/${MACHINE} -.if ${COMPILER_VERSION:L} == "gcc3" +.if ${BUILD_GCC3:L} == "yes" RDIRS+= ../gnu/usr.bin/gcc ../gnu/lib/libobjc PRDIRS+= ../gnu/lib/libstdc++ -.elif ${COMPILER_VERSION:L} == "gcc4" +.endif +.if ${BUILD_GCC4:L} == "yes" RDIRS+= ../gnu/usr.bin/cc/libobjc PRDIRS+= ../gnu/lib/libstdc++-v3 ../gnu/usr.bin/cc/include -.elif ${COMPILER_VERSION:L} == "clang" +.endif +.if ${BUILD_CLANG:L} == "yes" RDIRS+= ../lib/libcxxabi ../lib/libcxx .endif Index: lib/libcompiler_rt/Makefile =================================================================== RCS file: /cvs/src/lib/libcompiler_rt/Makefile,v retrieving revision 1.6 diff -u -p -r1.6 Makefile --- lib/libcompiler_rt/Makefile 9 Apr 2017 21:47:05 -0000 1.6 +++ lib/libcompiler_rt/Makefile 16 Apr 2017 18:35:14 -0000 @@ -2,7 +2,12 @@ .include <bsd.own.mk> -.if ${COMPILER_VERSION:L} == "clang" +.if ${COMPILER_VERSION:L} != "clang" +CC= clang +CXX= clang++ +.endif + +.if ${BUILD_CLANG:L} == "yes" LIB= compiler_rt NOPIC= Index: lib/libcxx/Makefile =================================================================== RCS file: /cvs/src/lib/libcxx/Makefile,v retrieving revision 1.5 diff -u -p -r1.5 Makefile --- lib/libcxx/Makefile 16 Feb 2017 02:08:42 -0000 1.5 +++ lib/libcxx/Makefile 16 Apr 2017 18:35:26 -0000 @@ -2,7 +2,12 @@ .include <bsd.own.mk> -.if ${COMPILER_VERSION:L} == "clang" +.if ${COMPILER_VERSION:L} != "clang" +CC= clang +CXX= clang++ +.endif + +.if ${BUILD_CLANG:L} == "yes" HDRDIR= ${.CURDIR}/include SRCDIR= ${.CURDIR}/src Index: lib/libcxxabi/Makefile =================================================================== RCS file: /cvs/src/lib/libcxxabi/Makefile,v retrieving revision 1.7 diff -u -p -r1.7 Makefile --- lib/libcxxabi/Makefile 6 Apr 2017 09:28:29 -0000 1.7 +++ lib/libcxxabi/Makefile 16 Apr 2017 18:35:39 -0000 @@ -2,7 +2,12 @@ .include <bsd.own.mk> -.if ${COMPILER_VERSION:L} == "clang" +.if ${COMPILER_VERSION:L} != "clang" +CC= clang +CXX= clang++ +.endif + +.if ${BUILD_CLANG:L} == "yes" HDRDIR= ${.CURDIR}/include SRCDIR= ${.CURDIR}/src Index: share/mk/bsd.own.mk =================================================================== RCS file: /cvs/src/share/mk/bsd.own.mk,v retrieving revision 1.182 diff -u -p -r1.182 bsd.own.mk --- share/mk/bsd.own.mk 18 Dec 2016 17:02:21 -0000 1.182 +++ share/mk/bsd.own.mk 16 Apr 2017 18:27:18 -0000 @@ -15,7 +15,8 @@ SKEY?= yes # Set `YP' to `yes' to build with support for NIS/YP. YP?= yes -CLANG_ARCH=aarch64 +CLANG_ARCH=aarch64 amd64 +GCC4_ARCH=alpha amd64 arm hppa i386 mips64 mips64el powerpc sh sparc64 GCC3_ARCH=m88k # m88k: ? @@ -23,12 +24,28 @@ PIE_ARCH=alpha amd64 arm hppa i386 mips6 STATICPIE_ARCH=alpha amd64 arm hppa i386 mips64 mips64el powerpc sh sparc64 .for _arch in ${MACHINE_ARCH} -.if !empty(CLANG_ARCH:M${_arch}) -COMPILER_VERSION?=clang -.elif !empty(GCC3_ARCH:M${_arch}) +.if !empty(GCC3_ARCH:M${_arch}) COMPILER_VERSION?=gcc3 -.else +.elif !empty(GCC4_ARCH:M${_arch}) COMPILER_VERSION?=gcc4 +.elif !empty(CLANG_ARCH:M${_arch}) +COMPILER_VERSION?=clang +.endif + +.if !empty(GCC3_ARCH:M${_arch}) +BUILD_GCC3?=yes +.else +BUILD_GCC3?=no +.endif +.if !empty(GCC4_ARCH:M${_arch}) +BUILD_GCC4?=yes +.else +BUILD_GCC4?=no +.endif +.if !empty(CLANG_ARCH:M${_arch}) +BUILD_CLANG?=yes +.else +BUILD_CLANG?=no .endif .if !empty(STATICPIE_ARCH:M${_arch})