# 7.20. Using External Source - externalsrc.bbclass

## 7.20. Using External Source - `externalsrc.bbclass`

You can use this class to build software from source code that is external to the OpenEmbedded build system. In other words, your source code resides in an external tree outside of the Yocto Project. Building software from an external source tree means that the normal fetch, unpack, and patch process is not used.

To use the class, you need to define the `S` variable to point to the directory that contains the source files. You also need to have your recipe inherit the `externalsrc.bbclass` class.

This class expects the source code to support recipe builds that use the `B` variable to point to the directory in which the OpenEmbedded build system places the generated objects built from the recipes. By default, the `B` directory is set to the following, which is separate from the Source Directory (`S`):

         ${WORKDIR}/${BPN}-{PV}/

See the glossary entries for the `WORKDIR`, `BPN`, `PV`, `S`, and `B` for more information.

You can build object files in the external tree by setting the `B` variable equal to `"${S}"`. However, this practice does not work well if you use the source for more than one variant (i.e., "natives" such as `quilt-native`, or "crosses" such as `gcc-cross`). So, be sure there are no "native", "cross", or "multilib" variants of the recipe.

If you do want to build different variants of a recipe, you can use the `BBCLASSEXTEND` variable. When you do, the `B` variable must support the recipe's ability to build variants in different working directories. Most autotools-based recipes support separating these directories. The OpenEmbedded build system defaults to using separate directories for `gcc` and some kernel recipes. Alternatively, you can make sure that separate recipes exist that each use the `BBCLASSEXTEND` variable to build each variant. The separate recipes can inherit a single target recipe.

For information on how to use this class, see the "Building Software from an External Source" section in the Yocto Project Development Manual.