Wednesday, May 20, 2009

Making your own one-step build in Ubuntu

It's been a while, so I thought I could at least share something quick that Koya Charles and I came up with yesterday. Koya's done a lot of work to make sure that Scenic's autoconf/build setup stays sane. The one important feature we were missing was a "one button build". Typically, I'd do something like:

./ && ./configure && make -j4 && sudo make install

Note the -jn flag which tells make to build n sources in parallel, good if you have a multicore machine (see Jeff Atwood's argument on the quad-core vs. dual-core debate, particularly the 'Comments' section for relevant discussion).

So Koya and I made a shell script to do this:

cd "`dirname $BASH_SOURCE`/../../trunk"
notify-send -t 2000 "Building scenic..."
make -j4 && gksu make install && notify-send -t 10000 "Done building scenic"

First, the variable $BASH_SOURCE evaluates to the location of the build script in question. We then use this to get the path to our source tree (as both are in our repository). We then call notify-send (requires libnotify-bin) to show a popup telling us that the build is being attempted. We then compile and call gksu, as this is intended to be used via a hotkey, instead of plain sudo for the make install. Provided the make and make install were successful, we again use notify to post a popup that the build is done. You should make this script executable with

chmod u+x

This script can be called from the command line, but to be even more useful I made a hotkey for it.

Running gconf-editor, you can edit what keybindings you have for your global workspace, with the following steps:
  1. run gconf-editor from a terminal (or just Alt-F2, then type in gconf-editor in the "Run Application" window that appears).
  2. click on the tab for apps, under /
  3. click on the tab for metacity, under apps
  4. click on global_keybindings
  5. in the adjacent window, right-click on run_command_1 (assuming it's disabled, otherwise use the first run_command_x listed as disabled) and click Edit key.
  6. I use F5 (as in the F5 key) for my binding, but it can be whatever you choose. Just type 'F' and '5' in the Value: field, NOT the F5 key itself, to get this binding.
  7. Next, click on the tab keybinding_commands, right below global_keybindings, and right-click on command_1 (or whichever you chose) and click Edit Key.
  8. In the field labelled Value:, enter the path to your build script, for example: /home/tristan/devel/scenic/inhouse/misc/
Now, I can build my project no matter what window is in focus, without opening a terminal, just by hitting the F5 key.

No comments: