I'd like to know how I would build Unity from source code in the current development release. Please cover the following topics:
- Which packages are needed to compile Unity?
- Where would I get the current source code?
- What are the steps to actually configure and compile Unity?
- Is it possible to safely run the latest version alongside the version from the repositories?
Building Unity from Source
In this guide you will build a separated version of Unity trunk (locally installed to your home directory), so you don't need to worry about corrupting the version from the Ubuntu repositories and you also won't need to get root permissions throughout the whole process (except for installing the build dependencies).
0. Installing build dependencies
You'll need to run this once to install all necessary build dependencies:
If you have source code repositories (aka
deb-src
) enabled, you can instead use:1. Preparing the environment
Replace
SOURCE
andPREFIX
with the directories you'd like the source and build files to go. In this example I put both in my home directory:2. Building Nux
You will probably need to grab the latest version of
Nux
to get Unity trunk to compile:Tip: Most modern desktops and laptops have several cores. You can greatly speed up the compilation by taking advantage of this. The
make
command has build-in support for this which you can activate using the -jN switch where N is the number of jobs to run in parallel. A good rule of thumb is to run 2 times the number of cores on your processor. Thus, on a normal dual core computer you should runmake -j4
to minimize the compilation time.3. Building Unity
Now grab the latest Unity code and build it:
That's it, log out and back in again and you should be running the latest Unity. Alternatively, you can run
4. Updating
Make sure to prepare the environment like described in step 1, then simply enter both top-level directories
nux
andunity
, runbzr pull
, rebuild, and reinstall.I suggest removing and recreating the
build
directory in theunity
directory, to make sure no old files are messing with your build.5. Removing Unity
Remove the three directories
$SOURCE
,$PREFIX
and~/.compiz-1
.Useful Link:
I've made a script based on the Wayland build script and these instructions to automate installing prerequisites, cloning, updating, configuring and building Unity.
https://github.com/bitshifter/Unity-Build/raw/master/build-unity.sh
Building in your home directory
Sometimes for testing reasons it's useful to build Unity and nux in your home directory so you can try to see if something is fixed in trunk without mucking around with packages and/or PPAs. I asked Jason Smith (Unity Dev) how he builds Unity and he explained his method to me:
Ensure you have all the build dependencies from this answer.
First make a directory in your home called "staging", this is where we'll build Unity. Create a little script that will prepare the build environment, replace the home directory with your own:
I call this
unity.sh
and I run it every time I want to build Unity. So basicallychmod +x unity.sh
and then./unity.sh
when you want to build.Build nux:
Build Unity:
NOTE: This builds nux and unity in your home directory, there's no need for sudo here or anything like that.
~/.compiz
~/.compiz
and log back in.The source code for the default environment (Unity) can be found in the package
unity
. Install the source withapt-get source unity
, the dependencies to build it withsudo apt-get build-dep unity
and hack away.This will let you position the launcher on the right, bottom, top, etc.
There is excellent official documentation here - Developing Unity.
Here's an excerpt from it on building Unity - installing from source and compiling
The installation got trickier recently : a new module has been added to compiz named GTK Load (or it will crash in XInternAtom). We need to activate this module to use 4.0.1, but activating it will crash unity 3.8.
It's getting hard to keep both of them. The way I did it was to :