This page explains how to use clang with the NetBSD base system. See also how to use clang to build packages.

\todo: review this entire page.

Since NetBSD 6, the base system has included clang, but it is not built or used by default.

\todo Explain if there are or aren't plans to enable it by default, or to switch, keeping in mind that compiler support varies by architecture.

There are three steps that can be taken with clang; each depends on the previous.

Building clang

To build clang as part of the build, set

MKLLVM=yes

in mk.conf before running "build.sh release".

This will build clang, which will appear in /usr/bin/clang and also build libraries that clang needs. NetBSD itself will not be built with clang, but you will be able to use clang to build programs.

Using clang to build the NetBSD base system

In addition, set

HAVE_LLVM=yes

to cause clang to be used instead of gcc.

Not building gcc

On a system that builds clang and uses it to build the base system, you can refrain from building gcc, by additionally adding:

MKGCC=no

status

On NetBSD-current, clang builds successfully on several architectures. These builds are with all three of the above flags enabled.

https://releng.netbsd.org/builds/HEAD-llvm/

Add a comment