Building click packages should be easy. And to a reasonable extent, qtcreator and click-buddy do make it easy. Things however can get a bit more complicated when you need to build a package that needs to run on an armhf device (you know like your phone!). Since your pc is almost certainly based on x86, you need to use, create or fake an armhf environment for building the package.
So then what options exist for getting a proper build of a project that will install properly on your device?
A phone can be more than a phone
It can also be a development environment!? Although it's not my recommendation, you can always use the source device to compile the package with. The downsides of this is namely speed and storage space. Nevertheless, it will build a click.
- shell into your device (adb shell / ssh mydevice)
- checkout the code (bzr branch lp:my-project)
- install the needed dependencies and sdk (apt-get install ubuntu-sdk)
- build with click-buddy (click-buddy --dir .)
The click tools contain a handy way to build a chroot expressly suited for use with click-buddy to build things. Basically, we can create a nice fake environment and pretend it's armhf, even though we're not running that architecture.
sudo click chroot -a armhf -f ubuntu-sdk-14.04 create
click-buddy --dir . --arch armhf
Most likely your package will require extra dependencies, which for now will need to be specified and passed in with the --extra-deps argument. These arguments are packages names, just like you would apt-get. Like so;
click-buddy --dir . --arch armhf --extra-deps "libboost-dev:armhf libssl-dev:armhf"
Notice we specified the arch as well, armhf. If we also add a --maint-mode, our extra installed packages will persist. This is handy if you will only ever be building a single project and don't want to constantly update the base chroot with your build dependencies.
Qtcreator build it for me!
Cmake makes all things possible. Qt Creator can not only build the click for you, it can also hold your hand through creating a chroot1. To create a chroot in qtcreator, do the following:
- Open Qt Creator
- Navigate to Tools > Options > Ubuntu > Click
- Click on Create Click Target
- After the click target is finished, add the dependencies needed for building. You can do this by clicking the maintain button.
- Apt-get add what you need or otherwise setup the environment. Once ready, exit the chroot.
- Open qt creator and open the project
- Select armhf when prompted
- You can also manually add the chroot to the project via Projects > Add kit and then select the UbuntuSDK armhf kit.
- Navigate to Projects tab and ensure the UbuntuSDK for armhf kit is selected.
So, click can setup a chroot for you, and qt creator can build and manage one too. And these are great options for building one project. However if you find yourself building a plethora of packages or you simply want more control, I recommend setting up and using your own chroot to build. For my own use, I've picked pbuilder, but you can setup the chroot using other tools (like schroot which Qt Creator uses).
sudo apt-get install qemu-user-static ubuntu-dev-tools
pbuilder-dist trusty armhf create
pbuilder-dist trusty armhf login --save-after-login
Then, from inside the chroot shell, install a couple things you will always want available; namely the build tools and bzr/git/etc for grabbing the source you need. Be careful here and don't install too much. We want to maintain an otherwise pristine environment for building our packages. By default changes you make inside the chroot will be wiped. That means those package specific dependencies we'll install each time to build something won't persist.
apt-get install ubuntu-sdk bzr git phablet-tools
By exiting, you'll notice pbuilder will update the base tarball with our changes. Now, when you want to build something, simply do the following:
pbuilder-dist trusty armhf login
bzr branch lp:my-project
apt-get install build-dependencies-you-need
Now, you can build as usual using click tools, so something like
click-buddy --dir .
works as expected. You can even add the --provision to send the resulting click to your device. If you want to grab the resulting click, you'll need to copy it before exiting the chroot, which is mounted on your filesystem under /var/cache/pbuilder/build/. Look for the last line after you issue your login command (pbuilder-dist trusty armhf login). You should see something like,
File extracted to: /var/cache/pbuilder/build//26213
If you cd to this directory on your local machine, you'll see the environment chroot filesystem. Navigate to your source directory and grab a copy of the resulting click. Copy it to a safe place (somewhere outside of the chroot) before exiting the chroot or you will lose your build!
But wait, there's more!
Since you have access to the chroot while it's open (and you can login several times if you wish to create several sessions from the base tarball), you can iteratively build packages as needed, hack on code, etc. The chroot is your playground.
Remember, click is your friend. Happy hacking!
1. Thanks to David Planella for this info Read more