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?

Thanks!

link|improve this question

feedback

4 Answers

up vote 43 down vote accepted
+300

Building Unity from Source (current development version 12.04)

Last content update: 3 Apr 2012

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:

sudo apt-get install bzr cmake compiz-dev gnome-common libbamf3-dev libboost-dev \
libboost-serialization-dev libgconf2-dev libgdu-dev libglewmx1.6-dev \
libgnome-desktop-3-dev libibus-1.0-dev libindicator3-dev libjson-glib-dev \
libnotify-dev libnux-2.0-dev libpci-dev libsigc++-2.0-dev libunity-dev \
libunity-misc-dev libutouch-geis-dev libxxf86vm-dev xsltproc

1. Preparing the environment

Replace SOURCE and PREFIX with the directories you'd like the source and build files to go. In this example I put both in my home directory:

export SOURCE=/home/htorque/source/unity
export PREFIX=/home/htorque/build/unity

export PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig:$PKG_CONFIG_PATH"
export LD_LIBRARY_PATH="$PREFIX/lib:$LD_LIBRARY_PATH"
export LD_RUN_PATH="$PREFIX/lib:$LD_RUN_PATH"
export XDG_DATA_DIRS="$PREFIX/share:$XDG_DATA_DIRS"

mkdir -p "$PREFIX"
mkdir -p "$SOURCE"
cd "$SOURCE"

2. Building Nux

You will probably need to grab the latest version of Nux to get Unity trunk to compile:

bzr branch lp:nux
cd nux
./autogen.sh --disable-examples --disable-gputests --disable-tests --prefix="$PREFIX"
make -j4
make install
cd ..

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 run make -j4 to minimize the compilation time.

3. Building Unity

Now grab the latest Unity code and build it:

bzr branch lp:unity
cd unity
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DCOMPIZ_PLUGIN_INSTALL_TYPE=local -DGSETTINGS_LOCALINSTALL=ON -DCMAKE_INSTALL_PREFIX="$PREFIX"
make -j4
make install

That's it, log out and back in again and you should be running the latest Unity. Alternatively, you can run

setsid $PREFIX/bin/unity

4. Updating

Make sure to prepare the environment like described in step 1, then simply enter both top-level directories nux and unity, run bzr pull, rebuild, and reinstall.

I suggest removing and recreating the build directory in the unity directory, to make sure no old files are messing with your build.

5. Removing Unity

Remove the three directories $SOURCE, $PREFIX and ~/.compiz-1.

link|improve this answer
5  
using sudo checkinstall, rather than sudo make install, will use the package manager so you can easily uninstall the package. – scottl Mar 8 '11 at 22:37
@scottl: Unity is installed to /opt/unity, which already should make it easy to uninstall. Anyways, good point! – htorque Mar 9 '11 at 7:53
1  
For step 0 wouldn't sudo apt-get build-dep unity be easier, assuming that you're already running the development release of Ubuntu? – Jeremy Bicha Mar 11 '11 at 1:13
3  
@jbicha Depends on how often those dependencies get updated. E.g., the latest updates added a new dependency, which won't yet get pulled in by sudo apt-get build-dep unity – htorque Mar 18 '11 at 19:32
1  
On a fresh 12.04 install w/ 01/08 image the above worked fine. Only used the above build-dep command, the only other packages installed were ccsm & synaptic. For future use though the workarounds may need to be updated if needed though #2 & 3 would normally just be warnings. I believe the bzr source uses 'maintainer mode', (-Werror), so if a user is hung up they could try turning maintainer mode off. It's in the CMakeLists.txt in top level of the unity source, currently line 114 – doug Jan 8 at 21:48
show 3 more comments
feedback

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

link|improve this answer
feedback

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 :

  • go in the compiz-1 folder and rename all .so by .so1, except for libgtkloader.so
  • restart compiz with unity 4.0.1
  • activate the gtk Load module in compizconfig-settings-manager
  • rename the libraries back to .so
  • restart compiz.
link|improve this answer
feedback

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:

  1. Ensure you have all the build dependencies from this answer.

  2. 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:

    #!/bin/bash
    
    PREFIX=/home/jorge/staging
    
    export XDG_DATA_DIRS="$PREFIX/share:$XDG_DATA_DIRS"
    export LD_LIBRARY_PATH="$PREFIX/lib/"
    export PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig/"
    

    I call this unity.sh and I run it every time I want to build Unity. So basically chmod +x unity.sh and then ./unity.sh when you want to build.

  3. Build nux:

    bzr branch lp:nux
    cd nux
    ./autogen.sh --prefix=/home/jorge/staging
    make -j4
    make install
    cd ..
    
  4. Build Unity:

    bzr branch lp:unity
    cd unity
    mkdir build
    cd build
    cmake .. -DCMAKE_INSTALL_PREFIX=/home/jorge/staging/ -DCMAKE_BUILD_TYPE=Debug -DCOMPIZ_PLUGIN_INSTALL_TYPE=local -DGSETTINGS_LOCALINSTALL=ON
    make -j4
    make install
    

NOTE: This builds nux and unity in your home directory, there's no need for sudo here or anything like that.

  • Logging out and back in will run this version of Unity/nux automatically since it was built in ~/.compiz
  • To revert to the normal packages just log out, delete ~/.compiz and log back in.
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.