On macOS the standard build is done using MacPorts, and it is very difficult to make a 10.9 MacPorts on a 10.11 system, so I strongly recommend having a 10.9 system.
Luckily, 10.9 works very nicely in a VM, provided that the host is running macOS/OSX, and it’s 100% legal (if you have a license for the host macOS).
Building in a VM can be painful because of the disk space it occupies, so I just keep the basic system (macOS + Xcode) in the VM, and I put the whole /opt directory in a “sparsebundle image” named “opt” mounted from the host. The name should have no space in it (MacPorts doesn’t like paths with spaces). A sparsebundle is a hfs disk image which is dynamically and automatically resizable. This means that it will not keep growing and filling up you host disk.
Here’s my setup for the macOS VM:
- network: NAT, port forwartding host:3022 guest:22
To mount the sparsebundle, you must first create the sparsebundle on the host using Disk Utility (a 100GB image should be OK, and that’s just the maximum allowed size).
Then mount the host disk using SMB: lookup the host IP and do something like this in the guest terminal:
macOS may ask for a password, and whether it should save it in the keychain, say yes.
Then mount the sparseimage:
sudo hdiutil attach -owners on /Volumes/your_host_user_name/Path/To/MacPorts-opt-OSX-109.sparsebundle
And in the host you now just have to
sudo rmdir /opt; sudo ln -s /Volumes/opt / (if you named the image opt, it should mount as /Volumes/opt)
now you can install macports and start building.