Development/Howto/LSB Package

From Mandriva Community Wiki

Jump to: navigation, search


This document will attempt to walk through building a package as an LSB package, which should be able to be installed and run on any LSB compliant distribution. It is not the intent of this guide to replace the LSB specification, nor the book Writing LSB Applications, published by IBM press, but simply to pull together a bit of the available information in a short guide. Much more detail on the specification requirements as well as portability issues are covered by these documents.

LSB compliant applications may be packaged as rpm v3 packages or another package format. Since Mandriva Linux is an RPM based distribution, we'll focus on rpm packaging.

File Locations

LSB applications should, for the most part, place files under the /opt directory. Configuration files should go under /etc/opt. Namespace should follow LANANA namings for package and provider. Init scripts can be placed in /etc/init.d and can be initialized for the desired bootlevels using the LSB defined install_initd and remove_initd which should be located in /usr/lib/lsb in an LSB compliant distribution.


Company Foobar with application wizbang (both names registered with LANANA):

  • Binarys, libs, shared files: /opt/foobar/wizbang/{bin,lib,var,share} or /opt/wizbang/{bin,lib,var,share}
  • Configuration files: /etc/opt/foobar/wizbang or /etc/opt/wizbang

Symbolic links can be used to simplify paths, but must not be created outside the assigned namespace. The system administrator is responsible for creating any PATH modifications to make the application readily available for users. This should not be done in any %post scripts in the packaging.

ISVs as well as open source projects should register their desired namespace with LANANA, to avoid conflicts.

Restrictions to LSB compliance

The application must only use those libraries defined by LSB. Any additional requirements must be provided by the package as private shared libraries or statically compiled.

The application should not make any assumptions about the system init style of the system, beyond what is defined by the specification.


Mandriva Linux provides a toolchain for building LSB compliant applications, with the lsb-build packages. The packages include:

  • lsb-build-base-devel
  • lsb-build-cc
  • lsb-build-c++-devel

These packages provide a wrapper environment around the system gcc to insure LSB compliance in the compilation and linking of an application.

Testing for compliance

The LSB group provides several test packages to test your application for compliance:

  • lsb-appchk - check a binary application for compliance
  • lsb-archk - check a static archive for compliance
  • lsb-dynchk - check application interfaces to LSB ABI while the application is running
  • lsb-pkgchk - check a packaged LSB application

Very simple compilation example using hello.c

#include <stdio.h>
int main()
    printf("Hello, World.\n");

GCC compilation: gcc -o hello hello.c

[stew@presario30 c-code]$ ldd hello =>  (0xffffe000) => /lib/tls/ (0xb7eb1000)
        /lib/ (0xb7fec000)

[stew@presario30 c-code]$ /opt/lsb/bin/lsbappchk hello
/opt/lsb/bin/lsbappchk for LSB Specification 3.0.0 
Checking binary hello
Incorrect program interpreter: /lib/
Header[ 1] PT_INTERP    Failed
Found wrong intepreter in .interp section: /lib/ instead of: /lib/l
Section .got.plt: Not recognized by name. Checking as type SHT_PROGBITS

Lsbcc compilation: lsbcc -o hello hello.c

[stew@presario30 c-code]$ ldd hello =>  (0xffffe000) => /lib/tls/ (0xb7fb8000) => /lib/tls/ (0xb7e8d000)
        /lib/ (0xb7fec000)

[stew@presario30 c-code]$ /opt/lsb/bin/lsbappchk hello
/opt/lsb/bin/lsbappchk for LSB Specification 3.0.0 
Checking binary hello
Section .got.plt: Not recognized by name. Checking as type SHT_PROGBITS

This is built with LSB3.0 versions of the toolset, on a system preparing for LSB 3.0. An LSB2.0 system would show in the ldd output.

Choosing an LSB version

LSB is a maturing spec. It attempts to document existing practice and as such will change as Linux changes. It is possible to be compliant with multiple versions of LSB, provided the distribution or runtime environment provides compliance for the target versions. At the of this writing LSB2.0 is the released specification, with LSB3.0 scheduled to be released very soon.

Packaging the gnu xpaint application in an LSB compliant manner

We're going to repackage xpaint as an LSB applicaton, calling it xpaint-lsb. The complete source rpm is available on my web space.

As we discuss the various changes we'll need to make to the spec file, we show snippets of the diff between the orginal spec file and the new one. The first change will be the name, as well as defining %{tdir} as a macro to aid in setting up/installing the application. We also need to override the automatic requires, as an LSB package should only require lsb-core and possibly lsb-graphics.

---     2005-06-13 19:27:49.000000000 -0400
+++ xpaint-lsb.spec     2005-06-13 19:20:32.000000000 -0400
@@ -1,16 +1,23 @@
+%define rname  xpaint
+%define tdir   /opt/%{rname}
+%define <i>requires</i>exceptions \\(lib\\(ICE\\|SM\\|X11\\|Xext\\|Xt\\|c\\|dl\\|m\\|z\\)\\)\\.so*   
 Summary:       An X Window System image editing or paint program
-Name:          xpaint
+Name:          %{rname}-lsb

If we look the the xpaint package included with Mandriva Linux, we'll find the binary is linked with several libraries not defined in the LSB. =>  (0xffffe000) => /usr/X11R6/lib/ (0x55581000) => /usr/lib/ (0x55591000) => /usr/lib/ (0x555df000) => /usr/lib/ (0x555fd000) => /lib/ (0x55624000) => /lib/ (0x55635000) => /usr/X11R6/lib/ (0x55639000) => /usr/X11R6/lib/ (0x55695000) => /usr/X11R6/lib/ (0x556aa000) => /usr/X11R6/lib/ (0x556fc000) => /usr/X11R6/lib/ (0x55706000) => /usr/X11R6/lib/ (0x5571e000) => /usr/X11R6/lib/ (0x55726000) => /usr/X11R6/lib/ (0x55734000) => /lib/ (0x55801000) => /lib/ (0x55825000)
        /lib/ (0x55555000)

Specifically, libtiff, libjpeg, libpng, libXaw, libXmu and libXp are not part of LSB at this time.

This means we'll need to either provide these libs in our package or compile them in statically. For the example, we'll choose static compilation, which means the BuildRequirements of the package will change:

 Version:       2.7.7
 Release:       1mdk
 License:        MIT
 Group:         Graphics
-BuildRequires:         XFree86-devel xpm-devel jpeg-devel png-devel 
-BuildRequires: tiff-devel zlib-devel bison flex
+BuildRequires:         XFree86-static-devel xpm-devel jpeg-static-devel png-sta
+BuildRequires: tiff-static-devel zlib-devel bison flex lsbcc

Also, since LSB does not yet define how menus are setup for a GUI, we'll drop the icons and menu setupparts of the spec:

-Source1:       icons-%{name}.tar.bz2
 BuildRoot:     %{_tmppath}/xpaint-root
-mkdir -p $RPM_BUILD_ROOT%{_menudir}
-#mdk menu entry
-cat << EOF > $RPM_BUILD_ROOT%{_menudir}/%{name} 
-?package(xpaint):needs="X11" \
-section="Multimedia/Graphics" \
-title="Xpaint" \
-longtitle="Paint program" \
-command="/usr/X11R6/bin/xpaint" \
-#mdk icon
-install -d $RPM_BUILD_ROOT%{_iconsdir}
-tar jxf %{SOURCE1} -C $RPM_BUILD_ROOT%{_iconsdir}



Rpm normally finds application requirements and includes them in the packaged application. For LSB, we need to specify these manually as rpm does not do it for us. We'll specifically require LSB3.0, although it's possible to allow lesser or multiple versions.

+# (sb) automatic requires doesn't pick the ld-lsb dynamic loader requirement
+%ifarch %ix86
+Requires:      lsb-core-ia32 = 3.0 lsb-graphics-ia32 = 3.0

This change in the %setup section is just because we've renamed the package to xpaint-lsb:

-%setup -q 
+%setup -q -n %rname-%version 

To build the application, we need to make a change in Local.config so the /opt/xpaint directory is used asthe target directory. We also want to use lsbcc instead of gcc.

+sed -i "s|SHAREDIR = /usr/share/xpaint|SHAREDIR = %{tdir}/share|" Local.config

For the %install stanza we again use lsbcc and modify the destination paths to /opt/xpaint.

-make \
+make CC=lsbcc \
-       BINDIR=%{_prefix}/X11R6/bin \
-       MANDIR=%{_prefix}/X11R6/man/man1 install
+       BINDIR=%{tdir}/bin \
+       LIBDIR=%{tdir}/lib \
+       SHAREDIR=%{tdir}/share \
+       MANDIR=%{tdir}/man/man1 \
+       CONFDIR=%{_sysconfdir}%{tdir}/X11 \
+       install

Normally we use the %doc macro to install documents, this doesn't seem to work for an LSB application, so we manually install the docs in %install:

+# (sb) can't use %doc macro in an LSB package
+install -d $RPM_BUILD_ROOT%{tdir}%{_datadir}/doc/%{rname}-%{version}
+install [[ChangeLog]] README README.PNG TODO Doc/* $RPM_BUILD_ROOT%{tdir}%{_datadir

Finally the %files section reflects the changes in locations we've made, basically moving everything from /usr to /opt/xpaint:

-%doc [[ChangeLog]] README README.PNG TODO Doc
-%dir %{_datadir}/xpaint
-%dir %{<i>datadir}/xpaint/c</i>scripts
-%dir %{<i>datadir}/xpaint/c</i>scripts/3d_curves
-%dir %{<i>datadir}/xpaint/c</i>scripts/3d_surfaces
-%dir %{<i>datadir}/xpaint/c</i>scripts/filters
-%dir %{<i>datadir}/xpaint/c</i>scripts/images
-%dir %{<i>datadir}/xpaint/c</i>scripts/layers
-%dir %{<i>datadir}/xpaint/c</i>scripts/procedures
-%dir %{_datadir}/xpaint/help
-%dir %{_datadir}/xpaint/messages
-%dir %{_datadir}/xpaint/include
-%config(noreplace) %{_sysconfdir}/X11/app-defaults/XPaint*
+%dir %{tdir}/share
+%dir %{tdir}/share/c_scripts
+%dir %{tdir}/share/c_scripts/3d_curves
+%dir %{tdir}/share/c_scripts/3d_surfaces
+%dir %{tdir}/share/c_scripts/filters
+%dir %{tdir}/share/c_scripts/images
+%dir %{tdir}/share/c_scripts/layers
+%dir %{tdir}/share/c_scripts/procedures
+%dir %{tdir}/share/help
+%dir %{tdir}/share/messages
+%dir %{tdir}/share/include
+%dir %{_sysconfdir}%{tdir}
+%config(noreplace) %{_sysconfdir}%{tdir}/X11/app-defaults/XPaint*

Building our application

The specification for ia32 requires that the package must specify an architecture of i486. Normally on Mandriva Linux our packages are .i586.rpm. We can specify the architecture when we build:

[stew@presario30 SPECS]$ rpm -bb --target i486-linux xpaint-lsb.spec

Checking our application

We can check our xpaint binary using the lsbappchk program. Since xpaint is a graphical based application, we'll need to tell lsbappchk to consider the LSB_Graphics module or it will complain about requirements outside of LSB_Core.

[root@presaro30 /]# /opt/lsb/bin/lsbappchk -M LSB_Graphics /opt/xpaint/bin/xpaint 
also checking symbols in module LSB_Graphics
/opt/lsb/bin/lsbappchk for LSB Specification 3.0.0 
Checking binary /opt/xpaint/bin/xpaint
Section Not recognized by name. Checking as type SHT_PROGBITS
Section .got.plt: Not recognized by name. Checking as type SHT_PROGBITS

Tjreport is used to summarize the output from the LSB testing tools. A copy is provided in the "lsb" package:

[root@presario30 ~]# tjreport journal.appchk.xpaint 

Test was run: 20050622 10:01:24 
Total Tests Passed: 2068
Total Tests Failed (including waived): 0
Total Tests Failed (excluding waived): 0

Checking our package

We can test our package with lsbpkgchk. We use the "-L xpaint" to simulate that we're using a registered LANANA name. Otherwise pkgchk will complain about usage of /opt/xpaint and /etc/opt/expaint as not conforming to FHS.

[stew@presario30 i486]$ /opt/lsb/bin/lsbpkgchk -L xpaint xpaint-lsb-2.7.7-1mdk.i486.rpm

At the time of this writing, lsbpkgchk sends a lot of error output to stdout. For now we'll ignore this and just look at the journal:

[stew@presario30 i486]$ tjreport journal.pkgchk.xpaint-lsb-2.7.7-1mdk.i486.rpm 

Test was run: 20050622 18:09:15 
Total Tests Passed: 88
Total Tests Failed (including waived): 0
Total Tests Failed (excluding waived): 0


That's about it. We could have chosen to bundle the libraries that LSB doesn't define in our application and place them under /opt/xpaint/lib. A larger application might be a bit more complicated getting it configured to compile and run correctly out of /opt. As LSB grows, more interfaces will be defined and included.

Personal tools