Building Packages on BeleniX #1

Several people have been asking me to detail the steps I use to build packages for BeleniX, so here is an overview of what needs to be done and what are the gotchas to be kept in mind.

BeleniX uses the Pkgbuild utility to build packages. Pkgbuild is similar to Rpmbuild and uses Spec files to store the build recipes. However instead of generating RPMs it generates SVR4 packages. Since we are actively considering a move to RPM from the venerable but somewhat dated SVR4, having spec files that need a little massaging is an advantage. Though this is still being discussed a bit. If you are not familiar with Spec files I’d recommend you to go through some of the excellent resources and howtos available on the net regarding writing Spec files and generating RPM packages. In addition Pkgbuild has some OpenSolaris – specific extensions that are documented in the Pkgbuild manual page.

However you should Not use the standard Pkgbuild utility from the original website. We have a slightly modified older version of Pkgbuild that supports the “Conflicts” directive among a few other tweaks. This is packaged via the BELpkgbuild package available in the BeleniX package repo.

If you have installed BeleniX 0.8 Beta1 using the install_belenix Network Installer mechanism, you will find that the installation lacks various headers, compilers and other files needed for development. To ease the task of getting a baseline development environment the package repo provides a group package called “devel” that pulls in all the necessary stuff. Consider this as the Debian “build-essential” thingy.

In BeleniX we primarily use the Gcc4 compiler since in the spirit of opensource we much prefer an opensource toolchain even though SUN Studio can provide some benefits over Gcc in terms of performance. In addition it is much easier to port and build third-party software using Gcc as compared to Studio since FOSS developers tend to use Gcc themselves. Since we are a resource-constrained small team we would prefer not to spend all our time chasing down compiler related build issues. The “devel” group package pulls in Gcc4 as well. However in addition to Gcc4 you will need Studio for certain things like building OpenSolaris from source. In that case I’d recommend you to download and install the latest tarball version of the SUN Studio compiler by visiting this page.

Next you will have to checkout the BeleniX spec files from the SVN repo and setup the initial Pkgbuild environment.

So preparatory steps are:

  1. Install development packages:  pfexec spkg install devel
  2. Install SUN Studio(optional)
  3. Checkout spec files from BeleniX SVN: svn co belenix_specs
  4. The above command may give an error due to an issue older locale packages on the beta1 release try setting the C locale explicitly: export LANG=C
  5. Now create some directories that Pkgbuild expects. By default Pkgbuild expects a directory structure within the user’s home directory. The following directories need to be created: ~/packages/SPECS, ~/packages/SOURCES, ~/packages/BUILD, ~/packages/PKGS
  6. Now copy the needed files into these directories:
    1. cp belenix_specs/base-specs/* ~/packages/SPECS
    2. cp belenix_specs/include/* ~/packages/SPECS
    3. cp belenix_specs/patches/* ~/packages/SOURCES
    4. cp belenix_specs/ext-sources/* ~/packages/SOURCES

Now you are ready to play around further. Typically Pkgbuild provides two utilities called pkgbuild (aka rpmbuild) and pkgtool a higher-level wrapper around pkgbuild that can automatically download sources files and execute all the pkgbuild steps to generate a package and also install it. You can read more about pkgtool and pkgbuild commands by executing them with the ‘–help’ option or read the online manual. i am not going to repeat the details here.

In order to correctly use pkgbuild however certain environment variables and PATH must be set. At the minimum CC and CXX variables must be set to point to the C and C++ compilers. To simplify things a wrapper script is provided that sets up things properly for SUN Studio or Gcc4. It can be found at belenix_spec/run-build assuming belenix_specs is where you have checked out the spec files. So to build a spec file using Gcc the incantation will look like this:  cd belenix_specs; sh run-build SFEfoo.spec gcc

The above invocation will automatically download the tarballs, apply patches, build, package and install the package. The SVR4 packages are kept under ~/packages/PKGS. During the build process the build output is sent to a log file having the package name. So for SFEfoo.spec the log file will be /tmp/SFEfoo.log. However pkgbuild first sends the logs to a temporary file and then appends those to SFEfoo.log. In order to monitor a running build the following simple script can be used:

PID=`ps -ef | grep pkgb | grep " /bin/bash " | awk '{ print $2 }'`
LF=`pfiles ${PID} | grep "/tmp/pkgbuild.out" | head -1`
echo "********************"
tail -f ${LF}

This completes a brief intro into the initial preparatory steps. The next step is to actually look at a spec file and prepare a new one. There are various gotchas and things to keep in mind when doing that. I will briefly go through the stuff that one should do when preparing a new spec file on BeleniX in the next post. In the meantime one can look at existing spec files to check how things are done. Two suggested sample spec files to look at will be SFEpth.spec and SFEmrxvt.spec. Pth is the GNU portable threads library. It shows how to write a single spec file to build both 32Bit and 64Bit versions of a library. Mrxvt is a multi-tabbed terminal emulator. To look at typical cmake invocation that I have been using one can look at the KDE4 spec files in belenix_specs/kde4.


3 thoughts on “Building Packages on BeleniX #1

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s