General

The usual caveats above about using a consistent compiler apply.

Using clang from the base system

See clang and the base system.

Using clang from pkgsrc in the same prefix

Building

You can build clang from pkgsrc (lang/clang). However, it needs gcc 6 or higher and cmake.

Configuration

Once built, you should (\todo test this) be able to set:

PKGSRC_COMPILER=       clang
CLANGBASE=             /usr/pkg

Perhaps, but probably not, you might set:

HAVE_LLVM=             yes

Rebuilding clang and dependencies with clang

After building, you will have clang and everything it depends on built with some combination of the base system compiler, and, if that's < gcc6, also gcc6. This violates the normal rule about using the same complier. One can "make replace" those packages to recover, as long as nothing goes wrong in the meantime. It might be best to "pkg_admin set rebuild=YES" of all those packages (perhaps "*" if this is done before building anything else) and then "pkg_rolling-replace uv".

In particular, libtool embeds paths to compiler objects, and at least that should be rebuilt. It is unclear if clang itself needs rebuilding.

Using clang from pkgsrc in a different prefix

This section is completely untested

Bootstrap pkgsrc as e.g. /usr/pkg-clang, and in that prefix build clang.

In /usr/pkg, remove all packages and configure

PKGSRC_COMPILER=       clang
CLANGBASE=             /usr/pkg-clang

and then build packages.