Make sure you have all the dependencies installed:
```bash
brew install coreutils
brew tap discoteq/discoteq
brew install flock
brew install qemu
brew install wget
brew install e2fsprogs
brew install m4
brew install autoconf
brew install libtool
brew install automake
brew cask install osxfuse
Toolchain/BuildFuseExt2.sh
```
Notes:
- fuse-ext2 is not available as brew formula so it must be installed using `BuildFuseExt2.sh`
- Xcode and `xcode-tools` must be installed (`git` is required by some scripts)
- coreutils is needed to build gcc cross compiler
-`flock` command can also be installed with `brew install util-linux` but in that case you will need to add it to `$PATH`
- qemu is needed to run the compiled OS image. You can also build it using the `BuildQemu.sh` script
- osxfuse, e2fsprogs, m4, autoconf, automake, libtool and `BuildFuseExt2.sh` are needed if you want to build the root filesystem disk image natively on macOS. This allows mounting an EXT2 fs and also installs commands like `mke2fs` that are not available on stock macOS.
- If you install some commercial EXT2 macOS fs handler instead of osxfuse and fuse-ext2, you will need to `brew install e2fsprogs` to obtain `mke2fs` anyway.
Once you've built the toolchain, create a directory for the build to live in (for example, `Build/`), and run the CMake build:
```
$ mkdir Build && cd Build
$ cmake ..
$ make
$ make install
```
This will compile all of SerenityOS and install the built files into `Root/` inside the build tree. `make install` actually pulls in the regular `make` (`make all`) automatically, so there isn't really a need to run it exlicitly. You may also want ask `make` to build things in parallel by using `-j`, optionally specifying the maximum number of jobs to run.
Now to build a disk image, run `make image`, and if nothing breaks too much, take it for a spin by using `make run`.
On Linux, QEMU is significantly faster if it's able to use KVM. The run script will automatically enable KVM if `/dev/kvm` exists and is readable+writable by the current user.
Bare curious users may even consider sourcing suitable hardware to [install Serenity on a physical PC.](https://github.com/SerenityOS/serenity/blob/master/INSTALL.md)
Later on, when you `git pull` to get the latest changes, there's no need to rebuild the toolchain. You can simply run `make install`, `make image`, `make run` again. CMake will only rebuild those parts that have been updated.
You may also want to replace `make` with `ninja` in the above (use `cmake .. -G Ninja` when configuring the build) for some additional build speed benefits.
To add a package from the ports collection to Serenity, for example curl, go into `Ports/curl/` and run **./package.sh**. The sourcecode for the package will be downloaded and the package will be built. After that, run **./sync.sh** from the `Kernel/` directory to update the disk image. The next time you start Serenity with **./run**, `curl` will be available.