July 14th, 2010 @ 23:29

TLDR : directly skip to the last paragraph

For a few weeks now a couple of friends and I have been working on a media player for Maemo 5 with some extra bonuses (mostly track scoring and track prediction). Now that we have something pretty much functional, I was willing to produce some .deb packages for easy installation. I knew it wouldn’t be an easy task — and it definitely wasn’t.

Since I had no Scratchbox setup in the first place (64 bits distro, etc.), I first tried the py2deb/PyPackager approach, which let’s you create .deb packages directly on the tablet for python apps. Sadly, this approach requires you to sort your source tree in a very strict manner, which is as it will be on the device. Since I plan to rebuild my package often and I don’t want to work in an uglily organized environment, this is not the solution.

I thus set a debian virtualbox and installed Scratchbox on it, and tried to use a very simple cdbs build system, using python-distutils.mk (I already had a distutils build system working), and then building the .deb with dpkg-buildpackage. Sadly, for an unknown reason (to me) this was putting the python libs into /var/lib/pyshared/, which is definitely not in the n900 PYTHON_PATH, plus the package did not include the empty __init__.py files in the packages (it seems they were removed by python-support which is used by python-distutils.mk and are meant to be reconstructed upon install, though they weren’t), which lead to a completely broken package.

The next attempt I made was to use sbdmock, which is used by the official maemo.org autobuilder. Sadly, while it was successfully building other packages, it never succeeded at building my package because “pyversions”, which is required by python-distutils.mk, was missing (seems this is a known problem — though this might actually be fixed now and I might just be lacking the right builddep).

Instead of try to do it right, I should probably have done it fast. Since I’m using a debian-based distribution on my laptop, all I had to do was :

  • Install python2.5 in the right prefix (/usr), restore the /usr/bin/python symlink to python2.6
  • Write a simple homemade debian/rules file which runs distutils and then sorts everything to the right package prefix (this is actually even easier if you only have one package since there is no sorting involved ; I included a sample one at the end of the post)
  • Specify Architecture: all in debian/control (since this is a full python package, it should run on any platform)
  • Run dpkg-buildpackage. Enjoy !

Let’s note that there is something called stdeb which might be easier than this process. Too bad I only found it now :sad:

Sample debian/rules :

#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
INSTALL_PROGRAM += -s
endif

configure: configure-stamp

configure-stamp:
dh_testdir
touch configure-stamp

build: build-stamp

build-stamp: configure-stamp
dh_testdir
$(MAKE)
touch build-stamp

clean:
dh_testdir
dh_testroot
rm -f build-stamp configure-stamp
rm -rf $(CURDIR)/debian/mymediaplayergui
rm -rf $(CURDIR)/debian/python-mymediaplayer
-$(MAKE) clean
dh_clean

install: build
dh_testdir
dh_testroot
dh_clean -k
dh_installdirs
$(MAKE) install DESTDIR=$(CURDIR)/debian/python-mymediaplayer
mkdir -p $(CURDIR)/debian/mymediaplayergui/usr/bin
mkdir -p $(CURDIR)/debian/mymediaplayergui/usr/lib/python2.5/site-packages
mkdir -p $(CURDIR)/debian/mymediaplayergui/usr/share
mkdir -p $(CURDIR)/debian/mymediaplayergui/usr/share/applications/hildon
mv $(CURDIR)/debian/python-mymediaplayer/usr/bin/maemotunes.py \
$(CURDIR)/debian/mymediaplayergui/usr/bin/
mv $(CURDIR)/debian/python-mymediaplayer/usr/bin/mymediaplayergui.py \
$(CURDIR)/debian/mymediaplayer/usr/bin/
mv $(CURDIR)/debian/python-mymediaplayer/usr/lib/python2.5/site-packages/mymediaplayergui \
$(CURDIR)/debian/mymediaplayergui/usr/lib/python2.5/site-packages

binary-indep: build install
dh_testdir
dh_testroot
dh_installchangelogs
dh_fixperms
dh_installdeb
dh_gencontrol
dh_md5sums
dh_builddeb

binary-arch: build install

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure