Home Previous Up Next3.5. Installing software packages from source code.
About
Contents
Projects
Thwab
Articles
Downloads
عربي

3.5. Installing software packages from source code.

Main feature of Free Software is the availability of source codes, we will learn how convert them to executable files and install them so that you could run them just by typing their names. We will discuss how to get them using CVS and how to apply modifications called patches.

Section quote:

  • "Talk is cheap. Show me the code."
        -- Linus Torvalds

Section contents:

3.5.1. Before you start.

Souce code files we are going to "talk" about are not .src.rpm packages but source archives like source tarballs (compressed TAR files) that ends with .tar.gz (or equivalentely .tgz) or TAR files commpressed with bzip2 having .tar.bz2 suffix. Put source archive in your home, then uncompress from your favorite GUI file manager (eg. "right click -> extract") or with command line tools:

bash$ tar -xvzf filename.tar.gz
if 'bzip2' is used to compress it (a 'tar.bz2' file) then replace 'z' with 'j' in other words the command becomes:
bash$ tar -xvjf filename.tar.bz2
usually a folder will be created, enter it (with 'cd' or using GUI) you could see files like INSTALL or README, you should read those files before you do any thing, open them with your favorite text editor or pager, you could type from command line: less INSTALL to browse the file in 'less' pager (in this case press 'q' to quit), the over all session could look like this
bash$ tar -xvzf filename.tar.gz
bash$ cd filename
bash$ ls
INSTALL	blah.c	foobar.c	make	configure
bash$ less INSTALL

 Warning

Installing software from source code may confuse your package manager, specially about dependency, to take over this problem you could use your distribution specific source code packages which could be compiled into a binary package then installed usually, those source packages like '.src.rpm' files in RPM distributions (eg. Red Hat) or in Debian the compination of '.orig.tar.gz' , '.diff.gz' and '.dsc' files. Another solution is to change installation prefix from '/' to '/usr/local'.

3.5.2. Compiling.

Steps after extracting files differ from package to another, but usually we have things in common, inside the extracted folder type:

bash$ ./configure
bash$ make
bash$ su
password:
bash# make install
bash# exit
bash$ 
the first './configure' command runs 'configure' script from the the current directory './', this script try to do platform specific configurations, if it fails do not continue until you solve it, usually the reason of failur could be a missing developing package, a package it's name ends with '-devel' (or '-dev' in Debian) just install it using your distibution package manager, for example if you are about to compile a package and './configure' complains about missing files related to 'GTK2' then you have install 'gtk2-devel' (of course this is just part of the package name), let's assume that this fixs it, now 'configure' works, we continue to the next line, we run the 'make' tool on the resulting 'Makefile' generated from the prevois line, then become 'root' with 'su' and call the same 'make' but to install the resulted files by moving them to a suitable place, you could pass some settings to 'configure', for example to set the prefix of installing directory use something like "./configure --prefix='/usr/X11R6'", other options could be for optimizing or debuging.

If 'make' had failed or interrupted and you want to retry make sure you have a clean start, just run 'make clean' (or in some cases 'make mrproper') before you rerun 'make'. If this source package contain programs other than the main program on which it depends, type 'make dep' before 'make', if this source package provide many programs and you don't want to wait to compile them all, just type 'make' followed by target name of the program you want to make. If every thing is done you could remove intermediate files issue 'make clean'.

You could override default options in the 'Makefile', for example you could set the C compiler by specifing CC variable or pass options to it, an unusual use for it could be "make CC='gcc -s'" which strip debuging information (to have smaller files), another unusual use (yet useful) to enable optimization with something like this:
make CC='gcc -s -O2 -fexpensive-optimizations -fomit-frame-pointer -mpentium' here we specify 2nd level of optimization with '-O2' (you could ask for deeper optimization but more than two are not reliable) other types of optimization could be used besides those used in the exmaple like '-f optimize-register-move','-f regmove' or '-f rerun-loop-opt', you could specify options that makes float point calculations faster (but less accurate and harder for debuging) with '-f fast-math', you could specify the target architecture and CPU with '-march=TARGET' and '-mcpu=TARGET', Mr. Isam Byasidi told me that it's better to pass compiler arguments through 'XXCFLAGS' variable. If you want to install it in a place differs from the default you could use something like "make PREFIX='/usr/X11R6' install" instead of 'make install', this will case the program to be installed in '/usr/local' (this trick could be used to have both 'wine' and the CVS version of 'winex' installed, by have each in different tree)

3.5.3. Patching.

Some source packges need a few changes to compile or to provide new features, instead of downloading a large grand new file having many common things with what you had downloaded before, developers saves the differences with 'diff' tool in a file called patch, you could download this small file and generate the new files by applying it, the patche could be applied with 'patch -Np1 -i /path/to/file.patch' or 'patch -b -p0 < /path/to/file.patch' according it was generaated, this should be done before './configure', this an exmaple: once less-378 have a problem calculating the length of line having Arabic letters, Arabeyes.org has a patch to fix this problem, after you download the original file 'less-378.tar.gz' and the patch file 'less_composing.patch.tgz' save them at your home:

bash$ tar -xvzf less-378.tar.gz
bash$ cd less-378
bash$ tar -xvzf ../less_composing.patch.tgz
bash$ patch -b -p0 < less_composing.patch
bash$ ./configure
bash$ su
bash# make && make install

3.5.4. Getting source code through CVS.

Concurrent Versions System (CVS) is heavely used by the community of GNU/Linux, as you know free software is developed not by a few developers but thousands of them spread all over the world, they never met in a physical environment, they meet in the cyber space (as media call it), CVS tools help the project administrator to manage each small change by different developers, different versions and take over conflicts of overwriting each others files, very fast in a small size.

CVS could be used to take a snapshot of the source package, which mean to download the most recent fresh version as it gets written, to use CVS you should first declare CVSROOT environment variable like this:
'export CVSROOT=":USER:PASSWORD@HOST/PROJ/DIR"' where 'USER' and 'PASSWORD' are you account information as supplyed by the project manager (a anonymous or guest account could be found) 'HOST' is the address or the name of the CVS server, the rest is the project name and directory, now we could start using it, first login to the server with 'cvs login' to downlod the project type 'cvs checkout PROJ' this will create a new directory (use 'cd' to enter it) containing the source files (with an extra CVS directory, you could delete it if you are not planing to takepart in developing it) you could compile it usually. The following example demonstrate how CVS could be used to get and compile glchess

bash$ export CVS_RSH='ssh'
bash$ export CVSROOT=\
":pserver:anonymous@cvs.glchess.sourceforge.net:/cvsroot/glchess"
bash$ cvs login
bash$ cvs -z3 checkout glchess
bash$ cd glchess
bash$ ./configure
bash$ make
bash$ su
bash# make install
the environment variable 'CVS_RSH' is used to have secure connection to Sourceforge.net, the '-z3' options used to set compression level to 3.

You could get involved in developing it using CVS, after you get an account, download snapshot, and edit any file then send it back using 'cvs commit' option '-m' used to describe your modification and '-kb' option is used with binary files, for example:

bash$ cvs commit -m "More Comments Added to file1.c" file1.c

ToC
Copyrights & Copylefts
What is Linux?
How to install Linux?
Halloween Documents

ArabEyes
Wikipedia
OpenSource
GNU
FSF's FSD
OSI's OSD
Linux.org
Linux.com
LinuxToday
SlashDot
FreshMeat
LWN.net

About Islam
What is Islam ?
We love Jesus; honored and not crucified.
Do you love Jesus or Paul ?
Who is Muhammad [PBUH] ?
Articles
Your scanner works on Linux
Linux cleaning Windows Viruses
Report
Unwanted Advertisements
Bugs and misspellings
Dead links:

 

Best viewed with free web browsers

You may get more high quality software from here for free
proud to be 100% Microsoft FREE GNU FDL


Generously Hosted by www.JadMadi.net

Previous Up 3.5. Installing software packages from source code. Next
Copyright © 2007, Muayyad Saleh AlSadi