Porting to the LSB
Porting to the LSB is similar to porting from one OS to another. It does have some more benefits which make it better. If the hardware (ie x86 or PPC for instance) is the same there would be no need to recompile and link as the binaries will run. This is the goal of the LSB. Then why have to port? Would it be good to only have one source base from which the application can be built for several different target OS's? It certainly would. It would make maintaining code easier. So what things need to be considered when trying to achieve this goal?
Here are things to keep in mind when porting not only to the LSB but porting in general.
-
Consider endianess ( big versus little) This is typically at the architecture level
-
Consider 32 bit versus 64 bit. Do not use anything that relies on one or the other.
-
Avoid hard coded addresses
-
Use sizeof when getting sizes of objects. This is especially true when going from 32 bit to 64 bit
-
Do not assume that char is signed or unsigned
-
Do not assume that float are the same size as double
-
Be very careful when using #ifdef
-
Always create function prototypes and have the compiler check for strict use by using the -Wstrict-prototyes option in compiling.
-
Use POSIX interfaces and data types
-
Use only standard function that are in the C and C++ libraries.
-
Avoid extensions to libraries or libraries that are distribution specific
-
Use the LSB tools found in the LSB SDK for building applications
-
Follow the FHS for file system hierarchy
The above list is by no means the only things to be aware of but it is a start based on the author's and other's experiences from porting applications. When in doubt look to the LSB Specification. When looking at the eventual outcome of the port consider the LSB and the FHS specifications. The LSB specification specifies how to write programs and the functions that are available. The FHS specifies a standard file hierarchy standard which all certified distributions use. The purpose of this file standard is to protect the distribution from applications and the applications from the distribution. It guarantees integrity and structure such that some areas can be set to read-only and further protected and secure. Following these two guidelines ensures that the applications are binary compatible and will run on any certified distribution.
This is not a complete guide to porting but a starting point to get hints and tips of what to look for and at when porting. The resources below go into more specific detail about porting from one distribution to another. There is an example of a port of a sample application in a tutorial. This gives a better feel for things to do.
Resources:
-
LSB Specification http://www.linux-foundation.org/en/Specifications
-
Migrating RedHat applications to SuSE – Technical Overview
http://www.novell.com/coolsolutions/feature/11223.html -
A tutorial about creating LSB compliant applications (somewhat dated but approach is still valid)
http://www.ibm.com/developerworks/linux/library/l-lsb.html


