Use the Source, Luke - Plex Blog

Use the Source, Luke

| 02 Jun 2008 | by 25 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 this

25 Comments so far

  1. Andemann June 2nd, 2008 7:39 pm

    Where’s barky?

  2. tv June 2nd, 2008 8:16 pm

    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”

  3. tv June 2nd, 2008 8:20 pm

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

  4. elan June 2nd, 2008 10:31 pm

    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.

  5. jalanr June 3rd, 2008 12:49 am

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

  6. Levitate June 3rd, 2008 4:23 am

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

  7. tv June 4th, 2008 3:37 am

    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).

  8. elan June 4th, 2008 7:54 am

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

  9. elan June 4th, 2008 9:58 am

    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.

  10. Jezz_X June 4th, 2008 9:57 pm

    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

  11. cullman June 4th, 2008 11:09 pm

    @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 :

  12. ChoccyHobNob June 5th, 2008 9:16 am

    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.

  13. cullman June 5th, 2008 10:13 am

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

  14. ChoccyHobNob June 5th, 2008 10:42 am

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

  15. Anush June 5th, 2008 2:44 pm

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

  16. elan June 5th, 2008 2:54 pm

    @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.

  17. Anush June 5th, 2008 3:51 pm

    that helped !!

  18. Anush June 5th, 2008 5:53 pm

    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…

  19. elan June 5th, 2008 6:05 pm

    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.

  20. Anush June 5th, 2008 8:14 pm

    restart works

  21. gmackenz June 5th, 2008 10:21 pm

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

    Giving up and going to sleep.

  22. elan June 5th, 2008 10:27 pm

    @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.

  23. Springs June 5th, 2008 11:47 pm

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

  24. superpea June 6th, 2008 11:03 am

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

  25. gmackenz June 8th, 2008 3:44 pm

    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.

Leave a reply