Thursday, April 8, 2010

Scripts, Not Just for Making Movies

A few months ago, I offered to write the Handbook for Amarok, my favorite music software. Along the way to that goal, I began publishing the Amarok Insider, which had been on hiatus for awhile. I've heard it said that the best way to learn something is to teach it to someone else, and this has proven true for me at least in technical writing. I wanted to learn how to build from source, because the more people do this, the more testing can be done before release, instead of after. This makes for more stable releases, and for the newsletter editor, provides advance experience with new features.

We have wonderful help for building Amarok from source should you be interested in doing so, here: http://blogs.fsfe.org/myriam/2009/09/compiling-amarok-from-git-locally-full-summary/. Right now developers are working on a new backend for Amarok, because Xine and Gstreamer, the two available now, are not satisfactory. VLC has the additional advantage of being cross-platform, and Amarok is available for Linux, Windows and Mac. Phonon-VLC, the new backend, is in rapid development like Amarok is, so testers need to build from source in much the same way. Again, Myriam has written the essential guide to installing and updating: http://blogs.fsfe.org/myriam/2010/04/want-to-test-the-phonon-vlc-backend-here-you-go/.

After using her guides to install Amarok, VLC and Phonon-VLC from source (with invaluable personal support from her, and other developers), I decided to make myself a shortened version, with just the commands I need to update and build, since I have all the dependencies installed, and the proper directory structure built. I realized once I had the short list written, that it looked a bit like a script! Here is my list:

Clean build?
rm ~/kde/build/amarok/CMakeCache.txt
rm ~/kde/src/phonon-vlc/build/CMakeCache.txt

Update phonon-vlc

cd ~/kde/src/phonon-vlc/build
git pull

cmake -DCMAKE_INSTALL_PREFIX=$HOME/kde/ -DCMAKE_INCLUDE_PATH=$HOME/kde/include/ -DCMAKE_LIBRARY_PATH=$HOME/kde/lib/ -DCMAKE_BUILD_TYPE=debugfull $HOME/kde/src/phonon-vlc/

make -j3 && sudo make install


Update Amarok

cd $HOME/kde/src/amarok
git pull

cd $HOME/kde/build/amarok
cmake -DCMAKE_INSTALL_PREFIX=$HOME/kde -DCMAKE_BUILD_TYPE=debugfull $HOME/kde/src/amarok

make install

kbuildsycoca4 --noincremental

After this stroke of inspiration, I looked around for some help in building a bash script, but found only tutorials which didn't seem to apply. When I asked on #linuxchix, rik, chf and joh6nn offered to help. We eventually came up with a Makefile, which unfortunately doesn't really work yet, although I don't understand why yet. Here is our product:

# Makefile for updating and building

.PHONY: all install clean all-clean phonon-vlc-clean phonon-vlc-update phonon-vlc-build phonon-vlc-install amarok-clean amarok-update amarok-build amarok-install

.DEFAULT: install

phonon-vlc-clean:
rm ${HOME}/kde/src/phonon-vlc/build/CMakeCache.txt

phonon-vlc-update:
cd ${HOME}/kde/src/phonon-vlc/build
git pull

phonon-vlc-build: phonon-vlc-update
cd ${HOME}/kde/src/phonon-vlc/build
cmake -DCMAKE_INSTALL_PREFIX=${HOME}/kde/ -DCMAKE_INCLUDE_PATH=${HOME}/kde/include/ -DCMAKE_LIBRARY_PATH=${HOME}/kde/lib/ -DCMAKE_BUILD_TYPE=debugfull ${HOME}/kde/src/phonon-vlc/

phonon-vlc-install: phonon-vlc-build
make -j3
sudo make install

amarok-clean:
rm ${HOME}/kde/build/amarok/CMakeCache.txt

amarok-update:
cd ${HOME}/kde/src/amarok
git pull

amarok-build: amarok-update
cd ${HOME}/kde/build/amarok
cmake -DCMAKE_INSTALL_PREFIX=${HOME}/kde -DCMAKE_BUILD_TYPE=debugfull ${HOME}/kde/src/amarok

amarok-install: amarok-build
make install
kbuildsycoca4 --noincremental

all: phonon-vlc-install amarok-install

install: amarok-install

clean: amarok-clean phonon-vlc-clean

all-clean: amarok-clean amarok-install phonon-vlc-clean phonon-vlc-install

Two reasons this isn't finished and working: I had a meeting, and rik had to sleep! I did a make -d all and got a TON of output, the end of which is at http://pastie.org/908564 . My console buffer was full of output! Later I hope to have a finished script to present to those who are interested in building packages from source. The problem so far is that the script seems to skip over or error out on the git pull step. Updates later.