IBM Support

How to build an application for multiple Linux distributions from a single source

Technical Blog Post


Abstract

How to build an application for multiple Linux distributions from a single source

Body

In a world where there are multiple package formats, managers and Linux distributions, it can be a pain for an open source project maintainer, application provider or ISV to package software for multiple architectures and multiple distributions. The following may make your life as a packager much more easier and provide access to more users!

Usually building a package for community distributions like Ubuntu, Fedora or openSUSE requires having that distribution installed locally with build dependencies available, so your application will find them. To increase reproducibility, more diligence is often required to isolate the package build environment, and each distribution has its own methodology for that process. Fortunately, there is a software solution available which targets this overall problem space. It is called Open Build Service [OBS] (http://openbuildservice.org) providing a ready to use appliance infrastructure, complete with a web interface, published application programming interfaces and a command-line client (already packaged for multiple distributions, as you might guess). There is even a public instance available for anybody (http://build.opensuse.org) to use which may even offer hardware architectures that you may not have readily available.

To get you started, I'm going to describe how to use this service by interacting with the public instance, building for multiple Linux distributions and targeting other hardware architectures, like PowerPC.

First you will need to create a free account (no worries, as there are not any restrictions imposed on the account) at https://build.opensuse.org , click "Sign Up" and fill out the simple form. Once completed you're ready to start packaging.

  • As background, here are a few basic OBS terms you should understand:

    • project - A workspace you're in. Every registered user has their own, so called, home project. Each project may have many sub-projects

    • build target (repository) - The "distribution" you're building against. For example openSUSE_13.1 or Ubuntu_1404

    • submit request - A request to merge package changes from one project to another. (Allows other people to collaborate and contribute packaging fixes or patches)

    • meta prjconf - Project configuration. Contains specific optimization flags, additional macros.

    • meta prj - Your build target specification in XML format

 

Okay, let's get started.

Replace "your_username" with your OBS userid and "packagename" with a package name you're working with

  • The command line, `osc`, has subversion-like logic, so you need to checkout a working copy of your home project from the server.

    • To begin, check out your home, project and change to the directory:
      > osc checkout home:<your_username>
      > cd home:<your_username>

      Note: When you run osc for the first time, it will prompt you for your login credentials that you setup for your account.

  • Next we're ready to create a package structure:
    > osc mkpac home:<your_username>/<packagename>
    > cd home:<your_username>/<packagename>

With these steps completed, an empty package structure has been created on the server that forms the basis for your package.

As noted before, OBS can build against multiple distributions but also for different architectures, so let's focus on the PowerPC architecture. With following we will add the distribution versions for openSUSE Factory, RHEL 6.5, SLES11SP3, and Ubuntu 14.04 and build for their respective available ppc64 and ppc64le architectures.
 

  • We will specify these build targets via:
    > osc meta prj -e home:<your_username>

    Then with your text editor, modify and save the project “meta prj” to match the following:

    <project name="home:your_username">
    <title>My cool project</title>
    <description></description>
    <person userid="your_username" role="maintainer"/>
    <repository name="openSUSE_Factory">
    <path project="openSUSE:Factory:PowerPC" repository="standard"/>
    <arch>ppc64</arch>
    <arch>ppc64le</arch>
    </repository>
    <repository name="rhel">
    <path project="RedHat:RHEL-6" repository="standard"/>
    <arch>ppc64</arch>
    </repository>
    <repository name="SLES11">
    <path project="SUSE:SLE-11:SP3" repository="standard"/>
    <arch>ppc64</arch>
    </repository>
    <repository name="ubuntu_ppc">
    <path project="Ubuntu:14.04" repository="standard"/>
    <arch>ppc64le</arch>
    </repository>
    </project>

  • Next, add your application sources under the home:<your_username>/<packagename> project directory You should also add an appropriate “.spec” file for rpm-based builds and a “.dsc” file for either Debian or Ubuntu based builds (there is no need to start with a source RPM or source DEB package). Don't forget to manage all these new files in your project within the version tracking, via:

    > osc ar # add/remove

  • If you would like to test the actual package build locally, which is a good practice assuming you have a compatible hardware architecture (you can list the configured build targets with `osc repos` command):
    > osc build buildtarget architecture
    > osc localbuildlog
    # to show the build log of a local buildchroot
    > osc chroot
    # if errors/issues are encountered, you can debug in the build environment chroot

    Notes:

    • By default `osc` builds from source in a chroot, ensuring that the build environment is sane, containing only a minimal set of core packages plus any specified build dependencies and is self-contained to avoid issues with the host system

    • Further, `osc` is also capable of doing KVM-based builds. If you have KVM-capable ppc64 machine you could build ppc64le packages with:
      >osc build buildtarget ppc64le --vm-type kvm

  • Reminder, as the final step, commit all of your changes needed to successfully build your package, via:
    > osc commit

    Notes:

    • If you don't have an access to PowerPC hardware, the packages can be built on the server side, by queuing for the next available worker node for your specified build target.

    • And you can track such a remote build with:
      >osc remotebuildlog home:<your_username>/<packagename>/buildtarget/architecture

  • When your server-side packages have been successfully built, you can find your package published at:

    http://download.opensuse.org/repositories/home:/
    <your_username>:/buildtarget/

    complete with the corresponding repository meta data created for your lucky users to access.

That's all there is to it, easy huh?

Have fun!

[{"Business Unit":{"code":"BU054","label":"Systems w\/TPS"},"Product":{"code":"HW1W1","label":"Power ->PowerLinux"},"Component":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"","Edition":"","Line of Business":{"code":"","label":""}}]

UID

ibm16170775