Here is my current diff to build clang alongside gcc.  The idea is
that if you add an architecture to both CLANG_ARCH and GCC4_ARCH, both
compilers get built, but gcc remains the default compiler.  It forces
the clang-related libraries (libcompiler_rt, libc++abi, libc++) to be
built with clang.

You'll need to bootstrap clang with the ports gcc before you can do a
make build.  This is done using:

# pkg_add g++
# cd /usr/src/gnu/usr.bin/clang
# make obj
# make BOOTSTRAP_CLANG=yes
# make install

Thoughts?  ok?  If we don't want to start building clang on amd64 just
yet, I can leave GCC4_ARCHS empty for now.


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        15 Apr 2017 12:06:10 -0000
@@ -10,7 +10,8 @@ SUBDIR+=      cc clang gcc
 SUBDIR+=       gcc
 .  elif ${COMPILER_VERSION:L} == "gcc4"
 SUBDIR+=       cc
-.  elif ${COMPILER_VERSION:L} == "clang"
+.  endif
+.  if ${BUILD_CLANG} == "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: 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 15 Apr 2017 12:14:38 -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} == "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 15 Apr 2017 12:04:11 -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} == "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      15 Apr 2017 12:00:40 -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} == "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 15 Apr 2017 11:58:41 -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=amd64
 GCC3_ARCH=m88k
 
 # m88k: ?
@@ -23,12 +24,20 @@ 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
+.elif !empty(GCC4_ARCH:M${_arch})
+COMPILER_VERSION?=gcc4
+.elif !empty(CLANG_ARCH:M${_arch})
+COMPILER_VERSION?=clang
 .else
 COMPILER_VERSION?=gcc4
+.endif
+
+.if !empty(CLANG_ARCH:M${_arch})
+BUILD_CLANG?=yes
+.else
+BUILD_CLANG?=no
 .endif
 
 .if !empty(STATICPIE_ARCH:M${_arch})

Reply via email to