2009-06-11
On June 8th, 2009 there was an episode of Hacker Public Radio about sap which was hosted by the illustrious lostnbronx. To be more specific the episode was about his experience with compiling and using sap. This has exposed more people to the sap project, which in turn has resulted in more feedback regarding sap and, more importantly, building sap.

The line to compile sap is
valac --thread --pkg curses --pkg gstreamer-0.10 curses_ui.vala audioplayer.vala main_controller.vala -o sap -X -lncurses
and since I don't want to type that out over and over again as I develop, entering the line into an executable file name build made things really easy. Whenever I want to build a new version of the app, I simply type
./build
and sap gets compiles. Sure, this work fine on my system, but what about other people's computers? It would be nice if the build script was a bit more robust and would first look for the Vala compiler and also check the version of the compiler to make sure things work nicely.

What I ended up with was the largest shell script that I've ever written. Normally I'd use PHP or Python when I need a script to get system info and manipulate string data but this was a special instance where the reliance upon yet another piece of software was highly frowned upon. Here is the script, in all of its gory glory:
#!/bin/sh _COMPILER=valac _REQ_VERSION="0.7.1" _COMPILE_STRING="valac --thread --pkg curses --pkg gstreamer-0.10 curses_ui.vala audioplayer.vala main_controller.vala -o sap -X -lncurses" function bad_version {     print_error     echo "Vala compiler installed version is $1"     compiler_not_found $2 } function compile {     echo "Running: $@"     if $@          then             echo "compile success!"         else             echo "there was a problem compiling"     fi } function compiler_not_installed {     print_error     echo "The Vala compiler is not installed"     compiler_not_found $1 } function compiler_not_found {     echo "Vala compiler version $1 or greater is required to compile this application"     echo "The latest version of the Vala compiler is available at http://live.gnome.org/Vala" } function print_error {     echo "--ERROR--" } #determine if the compiler is installed if which $_COMPILER > /dev/null 2>/dev/null then     #get the version     _VERSION=`valac --version`     #get just the version numbers     _VERSION_NUM=${_VERSION#V*\ }       #if the installed version is less than the required version     if "$_VERSION_NUM" \< "$_REQ_VERSION" ]     then         #this is a non usable version, display an error         bad_version $_VERSION_NUM $_REQ_VERSION     else         #this is a good version, run the compile string         compile $_COMPILE_STRING     fi      else     compiler_not_installed $_REQ_VERSION fi

The required version of Vala is set in line 2 and the command needed for compilation is entered on line 3. In theory, this will work for most code written in Vala and the script has already been added to the sap source on launchpad. Moving forward, it may be better to use a makefile type system to detect the compiler, compiler version, and required dependencies. I'll get there when I get there.
Comments
Name:
not required
Email:
not required (will not be displayed)
Website:
not required (will link your name to your site)
Comment:
required
Please do not post HTML code or bbcode unless you want it to show up as code in your post. (or if you are a blog spammer, in which case, you probably aren't reading this anyway).
Prove you are human by solving a math problem! I'm sorry, but due to an increase of blog spam, I've had to implement a CAPTCHA.
Problem:
3 plus 9
Answer:
required
  • Tags:
subscribe
 
2016
2015
2014
2013
2012
2011
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008