Avatar

Ps0ke

Φίλιππος Στέφανος

Nocturnal Inclination

Nerdkram, Internethumor und der ganzen Rest.

Setting up the Pebble Development Environment on Gentoo Linux 64bit

The official guide to set up the Pebble Development Environment on Linux is Ubuntu only.

Please note: Pebble SDK is only supported on Ubuntu GNU/Linux 12.04 LTS.

While this might work well on other distributions that user binary packages, it does not work so well if you are used to compile your source code yourself. This guide describes how to install the Pebble SDK on Gentoo Linux, but might work on other build-from-source distributions as well.

I am going to keep the structure close to the official guide and recommend to read it, too.

I am using zsh, but everyting should work in bash, too. Command prefixed with % shall be run as normal user, those with a # in front of them need to be run as root.

1. Download and install Pebble SDK

Setup a working directory to install the Pebble SDK into. This is probably also where you want to keep your own watchapp projects. All further instructions will assume you are in that working directory.

% mkdir pebble-dev
% cd pebble-dev

Now download Pebble SDK manually, wget won't work as the folks at Pebble want you to login and do some cookie and redirect nastiness. After you downloaded the SDK, unpack it:

% tar xf PebbleSDK-1.12.tar.gz

2. Download and install Pebble ARM toolchain

The Problem with the precompiled toolchain from the Pebble homepage is, that it links dynamically to libmpc2. First off you might even have libmpc3 installed and if you're on a 64bit system, both of the libs are also 64bit. But the toolchain links again the 32bit version. But as libmpc is somewhat essential to building software (e.g. via portage) you don't want to screw around with it and fuck up your build system. Been there done that.

So instead of using the precompiled toolchain provided by Pebble Inc. let's do it the Gentoo-way. Gentoo provides us with a nice tool for setting up cross-compiling toolchains that live next to our native build system. Enter crossdev.

Generating a cross-compiler by hand was a long and painful process. This is why it has been fully integrated into Gentoo! A frontend called crossdev will run emerge with all of the proper environment variables and install all the right packages to generate arbitrary cross-compilers based on your needs

Install sys-devel/crossdev. It is recommended that you use the unstable version to get the latest fixes, so unmask the package first.

# echo "sys-devel/crossdev" >> /etc/portage/package.accept_keywords
# emerge crossdev

You might get an error message telling you to convert package.use to a directory. To do so, run

# mv /etc/portage/package.use /etc/portage/package.use.orig
# mkdir /etc/portage/package.use
# mv /etc/portage/package.use.orig /etc/portage/package.use

Now with crossdev up and running, lets install the specific toolchain for the Pebble ARM architecture:

# crossdev --target arm-none-eabi

To test the freshly installed toolchain simply check its version. The output should be similar to the one provided below.

% arm-none-eabi-gcc --version
arm-none-eabi-gcc (Gentoo 4.7.3 p1.1, pie-0.5.5) 4.7.3
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

To go even further with testing (you want your build system to work probably, don't you?), let's compile a simple test. This should result in an output file a.out and should not throw any errors.

% echo "int main(void) {return 0;}" | arm-none-eabi-gcc -x c -
% ls | grep a.out
a.out*

3. Download and install SDK dependencies

Now with the compiler stuff being done, let's move on to install the actual Pebble SDK dependencies. You need do install Python 2.7 and the Python package manager pip (if they are not yet installed).

# emerge dev-lang/python:2.7 dev-python/pip

On my system the default Python version is 3.2, but the Pebble scripts are written against Python 2.7 and are not compatible with 2.7. This brings us to the problem of managing different versions of Python dynamically. You don't want to change your global Python version, so we use virtualenv instead.

virtualenv is a tool to create isolated Python environments.

Install it via pip:

# pip install virualenv

Now in the pebble working directory, let's setup a Python 2.7 for use in Pebble Development. This creates a directory pebble-python and installs a separate Python version into it.

% virtualenv -p /usr/bin/python2.7 --distribute pebble-python

Now activate pebble-python for the current shell session (maybe alias this to make it more comfortable). You need to to this in every new shell session before using the Pebble SDK.

% source pebble-python/bin/activate

After you're done developing you can either close the shell session or run deactivate to get out of the virtual environment and get your normal python back.

After activating your pebble-python, your shell prompt should have changed and you can test your Python version, which should result in something similar to the output provided below.

(pebble-python)% python --version
Python 2.7.3
(pebble-python)% which python
/home/ps0ke/Projects/Pebble/dev/pebble-python/bin/python

Now install the Pebble SDK dependencies as provided in the SDK into the new virtual pebble-python environment:

(pebble-python)% pip install -r PebbleSDK-1.12/Pebble/sdk/requirements.txt

And you should finally be ready to go. Why not start with the Hello World?