24-feb-11-compiling-presentation

= 24-Feb-2011 LUG Presentation - Compiling in GNU Linux =

Slide-1 : Applications

 * Typically packaged by developers in compliable source code in a ‘tarball’ (.tar.gz compressed format)
 * Developers often will use/call the source code of another application/library, where the source code of that application/library needs to be present for the compilation to succeed
 * Packagers for the various Linux distributions typically take the source code/tarball, compile and package it for their specific Linux distribution.
 * Red-Hat/Fedora/openSUSE = .rpm
 * Debian based = .deb

Slide-2 : Basic Compilation in Linux
INSERT IMAGE HERE

Notes:


 * “make” handles that under the rules specified in one or more Makefile. These rules are quite generic and may include other steps other than compiling and linking, like for instance create the package (.rpm or .deb).
 * In Debian, the “rules” file is a Makefile, just a different name.

Slide 3 : Basic Compliation in Linux
Building from a tarball tar –zxvf somefile.tar.gz
 * Obtain the tarball (tar.gz) from the developers web site, or for example from source.forge
 * Copy the tarball (tar.gz) file into a local user directory, say /home/username/tars
 * Untar the file
 * Read the “readme.txt” and “install.txt” (very important)
 * Figure out what libraries are needed, and install those libraries. If looking for "libapplication" then you may install "application-devel" package.  Often NOT that simple. :(

Notes:
 * It’s not simple as the application may have been developed over a single version of more libraries. Because the libraries evolve like the application does, a newer version may or may not be compatible with the past version.
 * Usually, a major version change means no backward-compatibility guaranteed (see python). Other minor version changes should keep the combatibility.
 * And we are not talking of applications compiled with a library version and installed somewhere where a different version of that library is installed. This is what does application deployment interesting ...

Slide 4 : Basic Compliation in Linux (continued ... )
./configure   # checks to see if have all needed libraries/apps # notorious for not being complete # prepares files (Makefile) for the next step make          # does the compiling and linking. # Where failures typically will occur su            # root permissions possibly needed from here on  make install   # puts compiled binary into the various sub-directories # such as in the /usr/local/bin subdirectory make clean    # cleans up temporary files created by                 # the compiling and linking process make uninstall # uninstalls IF run from the original make directory

There there is no database tracking of an application installed by using this method (as opposed to via .deb or .rpm)

Notes:  /usr/local/bin here is the “prefix”. This is usually changed at ./configure step using the –prefix="/my/own/path" argument, for instance ./configure –prefix=/my/own/path.

Slide 5 : Basic Compliation in Linux (Checkinstall)
CHECKINSTALL

./configure make su   checkinstall    # if it fails then try make install   # puts compiled binary into the directory – ‘cross the Rubicon’ at this point checkinstall   # run 2nd time only if 1st attempt failed and ‘make install’ worked # then install the .deb or .rpm created in /usr/src/packages/… which allows database tracking/removal
 * Properly packaging one’s own .deb or .rpm is difficult and requires advanced knowledge.
 * But installing from a tarball means the .deb/.rpm database does not track the application.
 * Checkinstall builds a poor quality .deb or .rpm that can be used on one’s own PC (but best NOT passed to others)
 * Reference checkinstall webpage

Slide 6 : Basic Compliation in Linux (Rebuilding an RPM (page-1))
Rebuilding an rpm (page-1)


 * This is specific to Linux rpm based distributions (debian based have their own method)
 * Can rebuild an rpm from an rpm’s .src file, where that includes inside the tarball, and a specification file that assists in making the compilation often easier (easier than just using a tarball).
 * Would use, for example, if you want an rpm for openSUSE-11.4, but you can only find one for openSUSE-11.2. Then assuming NO relevant changes between openSUSE version, you can use this method

Slide 7 : Basic Compliation in Linux (Rebuilding an RPM (page-2))
Rebuilding an rpm (page-2) rpmbuild -–rebuild application-1.x.y.src.rpm rpmbuild -–rebuild application-1.x.y.src.rpm rpm –uvh application-1.x.y-1.rpm
 * Download (for example) application-1.x.y.src.rpm
 * As regular user type:
 * That will likely fail, telling you what libraries & other applications you need first. Install those. Then again try:
 * If it succeeds, it will place the new application-1.x.y-1.rpm in the location /usr/src/packages/rpms ….
 * Install the new rpm with root permissions
 * If it does not succeed, keep solving problems / dependency issues and try again. Based on the spec file the rpm should advise what needs to be installed to solve a dependency issue

Slide 8 : Basic Compliation in Linux (About RPMs (page-3))
 About rpm (page-3)


 * EUMETSAT/MED uses RPMs to install software on EPS
 * Complex rules are usually developed by CSM
 * The .spec files are developed and versioned like source files
 * The target OS is AIX

Slide 9 : Basic Compliation in Linux (GNU/Debian distributions (slide-1))
About deb
 * Used by GNU/Debian based distributions
 * Packaging related files usually under “debian” directory from a tarball source
 * “debian/rules” is the executable Makefile that drives the build (compiling + linking)
 * Defined by Debian Policy Manual

Slide 10 : Basic Compliation in Linux (GNU/Debian distributions (slide-2))
About deb (and apt)
 * APT keeps deb packages updated against network or local repositories (sources)
 * Install: apt-get install application
 * This will download and install missing deb packages needed for the application to run
 * Source: apt-get source application
 * Will download and put in local dir the application source plus Debian auxiliary files
 * apt-get build-deb application
 * Download+install required build libraries

Notes:
 * A "source" can be also a filesystem including DVDs
 * "build libraries" here means usually the "-dev" named packages. These are object (machine code) and include files (source) needed to compile and link an application against that library.

Slide 11 : Basic Compliation in Linux (GNU/Debian distributions (slide-3))
About deb (and apt)
 * Build: debuild application
 * Install: debi package

Slide 12 : Basic Compliation in Linux (Alien appliction)
Alien alien [--to-deb] [--to-rpm] [--to-tgz] [--to-slp] [options] file [...] alien --to-rpm application-1.x.y-1.deb
 * Converting an rpm from one distribution package to another : http://kitenet.net/~joey/code/alien/
 * Perl script: converts between rpm, dpkg, slp, and tgz file formats
 * Useful if another distribution (of similar kernel build with similar libraries/graphics) has an application packaged that is not packaged for your favourite distribution.
 * Syntax:
 * Man page: http://linux.die.net/man/1/alien
 * Example rpm use to convert .deb to .rpm:
 * Not nominally recommended to do this (ie only as a very last resort)