Use the Source, Luke

06.02.08 27 Comments

OK, so you’d like to build from source and contribute to the project. Git (and GitHub) make this really easy, and give you powers far beyond what non-distributed version control systems like Subversion provide.

The problem with Subversion and CVS in open source projects is that they’re like a walled fortress, and you’re either on the inside or the outside. If you’re a “member” you’re given commit access, and then you can develop on your own branches, checkpoint your work, etc. However, life isn’t so good on the outside. You essentially work without a version control system! You can pull in updates as they get committed to the repository (hoping they merge cleanly with your code), but in terms of keeping order to your local changes and check-pointing them, you’re shit out of luck.

Distributed version control systems like Git essentially democratize the process, giving everyone first-class revision control capabilities. GitHub takes this a step further and puts the “official” people making releases of a project on the *exact* same footing as everyone else with an Internet connection. With a click of a button, you can fork an existing project, work on it with a bunch of your friends, and then request a pull from the parent project. Check out the fork tree for the Ruby on Rails source.

I’ve used quite a few revision control systems (CVS, Perforce, Subversion, and Clearcase — ick), and Git is the only one that both got me excited and fundamentally changed the way I work.

There are two basic ways to start. You can fork my repository on GitHub, or you can simply clone it. I recommend the former because that way you get instant offsite backup of your work.

First steps:

  • Download and install MacPorts.
  • Download and install XCode. I use the new 3.1 version that’s part of the iPhone SDK.

Now install Git (which pulls in quite a bit of stuff with it). Why you need to manually specify gawk is beyond me. If you’re uncomfortable with the Terminal, you probably want to do some calisthenics or a shot at this point.

$ sudo port install gawk git-core +svn

Let's get your Git environment set up. Skip the "color" configuration if you don't like color highlighting.

$ git config --global "Barkley Dawg"
$ git config --global ""
$ git config --global color.diff auto
$ git config --global color.status auto
$ git config --global color.branch auto
$ git config --global core.excludesfile ~/.gitignore

Edit the ~/.gitignore file and add the following to it:

Now we need to clone the repository. As I mentioned above, you can either clone mine, or fork on GitHub and clone that one. The example below clones mine; simply substitute your URL if you forked.
$ git clone git://

At this point you'll need to wait a while, during which time you probably want to have MacPorts install the rest of the dependencies:

$ sudo port install libsdl libsdl_image libsdl_mixer glew fribidi
            freetype python24 mysql5 lzo libmad pcre
            fontconfig py-pyobjc

(Note that for SAMBA, you should follow the instructions here).

Now sit back and relax, or do shots of tequila while your machine crunches away. When it's done, you can make yourself a branch to work on. I'm currently working on the v0.5 branch for releases, so you can create yourself a tracking branch starting from there to work from, and check it out:

$ git branch --track my-branch origin/v0.5
$ git checkout my-branch

Now we'll build the code and run it. You can also do this inside XCode, of course.

$ xcodebuild -parallelizeTargets -configuration Debug
$ export XBMC_HOME=/Path/To/
$ ./build/Debug/XBMC

Time to write some code! If you want to merge in the latest changes to the branch, you can issue a pull:

$ git pull origin/v0.5

In order to push to the remote repository, you'll need to tell it which local branch to push. This next operation will only work if you did fork my repository (in which case you would likely add my v0.5 branch as a remote).

$ git push origin my-branch  # First time.
$ git push origin            # Subsequent times.

So now you're set. You can do development on one or more branches locally, push them to GitHub, get updates from my branch (or other people's branches!) and when the code is ready to be integrated, simply issue a pull request on the GitHub site.

I haven't really even covered all the different cool things you can do with Git, but hopefully this will serve as a reasonable primer. Notice I never talked about "commit access" -- why is that? Well, if you're doing the occasional one-off patch or experiment, you really don't need it, and you get all the benefits of version control and offsite backup without it. If you're starting to get more involved and you want commit access because I'm slowing you down with my pokey pulls, just ask for it and I'll give it to you, provided you're not a raging psychopath. That's the funny thing about Git; commit access doesn't stand in the way of getting stuff done. And remember, using Git means you never have to say you're sorry!

Some great Git resources:

  • This is a brilliant video of Linus talking about Git at Google. Really hilarious, if only to watch him call lots of people stupid in a way only he can get away with.
  • I can't recommend this booklet on Git enough. The nine bucks is more than worth it.
  • A nice cheat-sheet for the common commands and their usage.

Please let me know if any of the above doesn't work for you. We'll be moving these instructions somewhere more permanent once I know they're correct. Also, I'll post most Git tips over time. I've been especially loving the bash autocompletion.

Tab completion

Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedIn
Share this


  • Where’s barky?

  • Didn’t test these but atleast I cant compile out of box because some python problems. Compiling that #include <python2.4/… is not found. Replacing this with #include <python/… gets it to somewhare but more errors are coming..

    [Editor: removed compile error]

    I think you should check the compiling with some clean system or something… Or maybe I’m just doing something wrong. I have had it compiling through these errors on my desktop but cant check it out now. Atleast I cat say it doesnt compile “out of box”

  • Ah, I just checked github and it seems you have fixed it already. Thanks.

  • Yeah, sorry about that. Make sure you checkout the branch and not the tag, as the fix occurred after the last tag.

    @Andemann: Barkley only comes out for releases. He’s actually quite bored with the idea of distributed revision control systems. Tennis balls? Yes. Git? No.

  • I love macadamia nuts :-)
    Great work Elan. As usual.

  • Macadamia Media Center would make a good name for the project :)

  • Okay, now I checked this and only one mistake anymore in the Xcodeproject, add libbz2.1.0.4.dylib from /opt/local/lib/ to project and it will work (and ofc, bunzip2 to port install line).

  • @tv: Thanks! I’ve pulled your fix and pushed it out to my v0.5 branch on GitHub.

  • Alright, cool, I’ve been forked four times already :)

    Please let me know if you have any Git questions, and remember my work is happening on the v0.5 branch at the moment.

  • I hate to sound negative but how is this any different than the way svn works in principle. You still have the main code that no one can commit too except you. As far as I can tell the only difference is people develop their code online in an open place so you can pick through it and see what you want to scavange for the main version you develop.
    Hrmm that second point sounds familiar wonder where from

  • @Jess_X: Not negative, just unfamiliar. Git is a Distributed Version Control System, probably the most striking difference is that unlike SVN there is no canonical copy of the source tree. This article — — is a comparison of various DVCS offerings, but the introduction does a good job of explaining the benefits over Subversion. Also, “git for the confused” might be of some help to you :

  • I only got as far as sudo port install :-(

    —> Building sqlite3 with target all
    Error: Target returned: shell command ” cd “/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_databases_sqlite3/work/sqlite-3.5.9″ && gnumake all ” returned error 2
    Command output: sed -e s/–VERS–/3.5.9/ ./src/ |
    sed -e s/–VERSION-NUMBER–/3005009/ >sqlite3.h
    /usr/bin/gcc-4.0 -O2 -o mkkeywordhash ./tool/mkkeywordhash.c
    ./mkkeywordhash >keywordhash.h
    /usr/bin/gcc-4.0 -O2 -o lemon ./tool/lemon.c
    cp ./tool/lempar.c .
    cp ./src/parse.y .
    ./lemon parse.y
    mv parse.h parse.h.temp
    f ./addopcodes.awk parse.h.temp >parse.h
    /bin/sh: f: command not found
    gnumake: [parse.c] Error 127 (ignored)
    cat parse.h ./src/vdbe.c | -f ./mkopcodeh.awk >opcodes.h
    /bin/sh: -f: command not found
    cat: stdout: Broken pipe
    gnumake: *** [opcodes.h] Error 127

    Error: The following dependencies failed to build: p5-svn-simple subversion-perlbindings apr-util sqlite3 neon subversion p5-term-readkey rsync popt
    Error: Status 1 encountered during processing.

  • @Choccy: Try this : sudo port clean sqlite3 ; sudo port install sqlite3

  • That worked :-) thanks cullman, it’s continuing ok now

  • I am getting error when port tries to install db4.4. Does anyone else here face the same issue.

  • @Anush: make sure you are up to date with your ports ($ sudo port sync), and when in doubt try the $ sudo port clean db4.4 if you’re not starting from scratch. I have:

    db44 @4.4.20_1 (active)

    installed on my system.

  • that helped !!

  • I get stuck with this message for about 30 minutes..
    —> Installing samba3 3.0.29_0+darwin_9
    —> Activating samba3 3.0.29_0+darwin_9

    Samething happens for mysql5 too.. any pointers…

  • Hmmm, it does take a while, but it shouldn’t take that long. Try running:

    $ sudo port -v install …

    And maybe the verbose output will tell you more.

  • restart works

  • Followed the instructions but got 64 compilation errors involving libcmyth and libpython.

    Giving up and going to sleep.

  • @gmackenz: 64 is a nice number, I have to admit. I suspect you’re not building the HEAD of the v0.5 branch. This could either be because my instructions sucked, or because you didn’t follow them. I strongly suspect the former.

  • It looks like the downloads are not working. Neither the http nor the torrent.

  • @Springs: they seem okay for me (for b5 at least). Amazon had a fairly severe outage today, perhaps that is what caused your problem.

  • Still interested in this, but I am a relative newbie in code repository systems (i.e. great at following specific instructions when doing svn checkouts and simple modifications of configuration commands after reading the INSTALL CONFIGURE documents for Mac OS X.

    So what’s different in your instructions to allow me to building the head of the 0.5 branch.

  • silly question, is this the source to the plex media server?

    • @Jeffrey ~ nope, the media center.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>