Linux-Mandrake:
User Guide and
Reference Manual

MandrakeSoft

 
 
January 2000
http://www.linux-mandrake.com


Next : Command Line Utilities
Previous : Compiling and installing new kernels
Up

(Back to the table of contents)

Chapter 1 : Building and installing free software


I am often asked how to install free software from sources. Compiling software by oneself is really easy because most of the steps to follow are the same whatever the software to install is.

The aim of this document is to guide the beginner step by step, by trying to avoid the pitfall of incantatory, and by explaining to him the meaning of each move. Yet, I assume that the reader has a minimal knowledge of Unix (ls or mkdir for instance).

This guide is only a guide, not a reference manual. That is why several links are given at the end so as to answer the remaining questions. This guide can probably be improved, so I will thanksfully receive remarks or corrections on its contents.

Introduction

What makes the difference between free software and proprietary software is the access to the sources of the software[23]. That means that free software is distributed as archives of source files. It may disconcert beginners, because users of free software must compile sources by themselves before they can use the software.

Nowadays, there are compiled versions of most of the existing free software. The user in a hurry just has to install binaries. Yet, some free software are not distributed under this form, or the earlier versions are not yet distributed under binary form. Furthermore, if you use an exotic operating system or an exotic architecture, a lot of software will not be compiled for you. More, compiling software by oneself allows to keep only the interesting options or to extend the functionalities of the software by adding extensions in order to obtain a software that fits exactly one's needs.

Requirements

To build a free software, you need:

Compiling a free software does not generally present a lot of problems, but if you are not used to it, the smallest snag can throw you into a difficult position. The aim of this document is precisely to show you how to escape from such a situation.

Compilation

Principle

In order to translate a source code into a binary file, a compilation must be done (usually from C or C++ sources, which are the most widespread languages among the (Unix) free software community). Some free software is written in languages which do not require compilation (for instance Perl or the shell, but they still require to be configured.

C compilation is logically done by a C compiler that is usually GCC, the free compiler written by the GNU project (at URL http://www.gnu.org/). Compiling a whole software package is a complex task, which goes through the successive compilation of different source files (it is easier for the programmer to put the different parts of his work in separate files, for various reasons). In order to make it easier, these repetitive operations are made by a utility named make.

The four steps of compilation

To understand how compilation works (and so, to be able to solve possible problems), one has to know its four steps. Its object is to little by little convert a text written in a language that is comprehensible by a trained human being (i.e. C language), towards a language that is comprehensible by a machine (or a very trained human being and even so, in few cases). GCC executes four programs one after the other, each of which takes on one step:

Structure of a distribution

A correctly structured free software distribution always has the same organization:

Decompression

tar.gz archive

The standard[24] of compression under Unix systems is the gzip format, developed by the GNU project, and considered as one of the best general compressing tools.

gzip is often associated with a utility named tar. tar is a survivor of antediluvian times, when computerists stored their data on tapes. Nowadays, floppy disks and CDROM have replaced tapes, but tar is still being used to create archives. All the files in a directory can be appended in a single file for instance. This file can then be easily compressed with gzip.

This is the reason why much free software is available as tar archives, compressed with gzip. So, their extensions are .tar.gz (or also .tgz to shorten).

The use of GNU Tar

To decompress this archive, gzip and then tar can be used. But the GNU version of tar (gtar) allows to use gzip "on-the-fly", and to uncompress an archive file without hardly noticing it (and without the need for the extra disk space).

The use of tar is incantatory:

tar <file options> <.tar.gz file> [<files>]

The <files> option is not compulsory. If it is omitted, processing will be made on the whole archive. This argument does not need to be specified to extract the contents of a .tar.gz archive.

For instance:

$ tar xvfz guile-1.3.tar.gz
-rw-r--r-- 442/1002      10555 1998-10-20 07:31 guile-1.3/Makefile.in
-rw-rw-rw- 442/1002       6668 1998-10-20 06:59 guile-1.3/README
-rw-rw-rw- 442/1002       2283 1998-02-01 22:05 guile-1.3/AUTHORS
-rw-rw-rw- 442/1002      17989 1997-05-27 00:36 guile-1.3/COPYING
-rw-rw-rw- 442/1002      28545 1998-10-20 07:05 guile-1.3/ChangeLog
-rw-rw-rw- 442/1002       9364 1997-10-25 08:34 guile-1.3/INSTALL
-rw-rw-rw- 442/1002       1223 1998-10-20 06:34 guile-1.3/Makefile.am
-rw-rw-rw- 442/1002      98432 1998-10-20 07:30 guile-1.3/NEWS
-rw-rw-rw- 442/1002       1388 1998-10-20 06:19 guile-1.3/THANKS
-rw-rw-rw- 442/1002       1151 1998-08-16 21:45 guile-1.3/TODO
...

Among the options of tar:

bzip2

A compression format named bzip2 tends to replace gzip. bzip2 produces shortest archives than gzip does, but is not yet a standard. Since little ago, .tar.bz2 extensions can be found.

bzip2 is used like gzip by means of the tar command. The only thing to do is to replace the letter z by the letter y. For instance:

$ tar xvfy foo.tar.bz2

Some distributions use or used to use the option I instead:

$ tar xvfI foo.tar.bz2

Another way (which seems to be more portable, but is longer to type!):

$ tar --use-compress-program=bzip2 -xvf foo.tar.bz2

bzip2 must be installed and included in your 'PATH' environment variable before you run tar.

Just do it!

The easiest way

Now that you are ready to uncompress the archive, do not forget to do it as administrator (root). You will need to do things that a single user is not allowed to do, and even if you can perform some of them as a regular user, it is simpler to just be root the whole time.

The first step is to be in the /usr/local/src directory, and to copy the archive there. Thanks to it, you will always be able to find the archive if you lose the installed software. If you do not have a lot of space on your disk, save the archive on a floppy disk after having installed the software. You can also delete it but be sure that you can find it on the Web whenever you need it.

Normally, decompressing a tar archive should create a new directory (you can check that beforehand thanks to the t option). Go then in that directory, you are now ready to proceed further.

The safest way

Unix systems (of which GNU/Linux et FreeBSD are examples) are secured systems. That means that normal users cannot either make operations that may endanger the system (format a disk, for instance) or alter other users' files. In practice and in particular, it immunizes the system against viruses.

On the other hand, root can do everything, even running a malicious program. To dispose of the source code is a guarantee of security faced to viruses, but you can be paranoiac[25].

The idea is to create a user dedicated to administration (free or admin for example) by using the adduser command. This user must be allowed to write in the following directories: /usr/local/src, /usr/local/bin and /usr/local/lib, as well as all the sub-tree of /usr/man (he also may need to be able to copy files elsewhere). I recommend to you to make this user owner of the necessary directories, or to create a group for him and to make the directories writable for the group.

Once these precautions are taken, you can follow the instructions in the section 84.0.

Configuration

A purely technical interest of the fact you dispose of the sources is the porting of the software. A free software developed for a Unix system can be used on all of the existing Unix systems (whether they are free or proprietary), with however some changes. That requires to configure the software just before compiling it.

Several configuration systems exist, you have to use the one the author of the software wants (sometimes, several are needed). Usually, you can:

Autoconf

Principle

Autoconf is used to correctly configure a software. It creates the files required by the compilation (for instance, Makefile for instance), and sometimes changes directly the sources (for instance by using a config.h.in file).

The principle of Autoconf is simple:

Example

An example of the use of Autoconf:

$ ./configure
loading cache ./config.cache
checking for gcc... gcc
checking whether the C compiler (gcc  ) works... yes
checking whether the C compiler (gcc  ) is a cross-compiler... no
checking whether we are using GNU C... yes
checking whether gcc accepts -g... yes
checking for main in -lX11... yes
checking for main in -lXpm... yes
checking for main in -lguile... yes
checking for main in -lm... yes
checking for main in -lncurses... yes
checking how to run the C preprocessor... gcc -E
checking for X... libraries /usr/X11R6/lib, headers /usr/X11R6/include
checking for ANSI C header files... yes
checking for unistd.h... yes
checking for working const... yes
updating cache ./config.cache
creating ./config.status
creating lib/Makefile
creating src/Makefile
creating Makefile

To have a better control of what configure generates, some options may be added by the way of the command line or environment variables. Example:

$ ./configure --with-gcc --prefix=/opt/GNU

or (with Bash):

$ export CC=`which gcc`
$ export CFLAGS=-O2
$ ./configure --with-gcc

or:

$ CC=gcc CFLAGS=-O2 ./configure

What if... it does not work?

Typically, it is an error of type configure: error: Cannot find library guile (most of the errors of the configure script).

That means that the configure script was not able to find a library (the guile library in the example). The principle is that the configure script compiles a short test program, which uses this library. If it does not succeed in compiling this program, it will not be able to compile the software. Then an error occurs.

If you do not understand the error message stored in the config.log file, do not hesitate to ask for help from the free software community (see section 231.0).

Furthermore, check whether configure answers by 100% of No or whether it answers No while you are sure that a library exists. For instance, it would be very strange that there is no curses library on your system). In that case, the 'LD_LIBRARY_PATH' variable is probably wrong!

Imake

Imake allows to configure a free software by creating a Makefile file from simple rules. These rules determine which files need to be compiled to build the binary file, and Imake generates the corresponding Makefile. These rules are specified in a file named Imakefile.

What makes the interest of Imake is that it uses information site-dependent (architecture-dependent). It is quite handy for applications using X Window System. But Imake is used for many other applications.

The easiest use of Imake is to go into the main directory of the decompressed archive, and then to run the xmkmf script, which calls the imake program:

$ xmkmf -a
imake -DUseInstalled -I/usr/X11R6/lib/X11/config
make Makefiles

If the site is not correctly installed, recompile and install X11R6!

Various shell scripts

Read the INSTALL or README files for more information. Usually, you have to run a file of type install.sh or configure.sh. Then, either the installation script is non-interactive (and determines itself what it needs) or it asks you information on your system (paths, for instance).

If you do not manage to determine the file you have to run, you can type ./ (under Bash), and than press twice the TAB key (tabulation key). Bash automatically (in its default configuration) completes by a possible executable file from the directory (therefore, a possible configuration script). If several files may be executed, it gives you a list. You just have to choose the right file.

A particular case is the installation of Perl modules (but not only). The installation of such modules is made by the execution of a configuration script, which is written in Perl. The command to execute is usually:

$ perl Makefile.PL

Alternatives

Some free software distributions are badly organized, especially during the first stages of development (but the user is warned!). They sometimes require to change "by hand" some configuration files. Usually, these files are a Makefile file (see section 147.0) and a config.h file (this name is only conventional).

I advise against these manipulations except for users who know what they are doing. This requires a real knowledge and some motivation to succeed. But practice makes perfect.

Compilation

Now that the software is correctly configured, it only remains to be compiled. This stage is usually easy, and does not set serious problems.

make

The favorite tool of the free software community to compile sources is make. It has two interests:

Actions that must be executed to obtain a compiled version of the sources are stored in a file often named Makefile or GNUMakefile. Actually, when make is called, it reads this file -- if it exists -- in the current directory. If not, the file may be specified by using the option -f with make.

Rules

make operates in accordance with a system of dependencies. So compiling a binary file ("target") requires to go through several stages ("dependencies"). For instance, to create the (imaginary) glloq binary file, the main.o and init.o object files (intermediate files of the compilation) must be compiled and then linked. These object files are also targets, whose dependencies are the source files.

This text is only a minimal introduction to survive in the merciless world of make. If you want to learn more, I advise you to go to website of APRIL (http://www.april.org/groupes/doc/), where you can find more detailed documentation about make. For an exhaustive documentation, refer to Managing Projects with Make, 2nd edition, O'Reilly, by Andrew Oram and Steve Talbott.

Go, go, go!

Usually, the use of make follows several conventions. For instance:

The first stage is to compile the program, and therefore to type (imaginary example):

$ make
gcc -c glloq.c -o glloq.o
gcc -c init.c -o init.o
gcc -c main.c -o main.o
gcc -lgtk -lgdk -lglib -lXext -lX11 -lm glloq.o init.o main.o -o glloq

Excellent, the binary file is correctly compiled. We are ready to go to the next stage, which is the installation of the files of the distribution (binary files, data files, etc). See section 210.0.

Explanations

If you are curious enough to look in the Makefile file, you will find known commands (rm, mv, cp, etc), but also strange strings, looking like '$(CFLAGS)'.

They are variables, that means strings that are usually set at the beginning of the Makefile file, and then replaced by the value they are associated with. It is quite useful when you want to use the same compilation options several times in a row.

For instance, to print the string "foo" on the screen using make all:

TEST = foo
all:
        echo $(TEST)

Most of the time, the following variables are set:

What if... it does not work?

Do not panic, it can happen to anyone. Among the most common causes:

Installation

With make

Now that all is compiled, you have to copy the built files to an appropriate place (usually in one of the sub-directories of /usr/local).

make can usually perform this task. A special target is the target install. So, using make install allows to install the required files.

Usually, the procedure is described in the INSTALL or README file. But sometimes, the developer has forgotten to provide one. In that case, you must install everything by yourself.

Copy then:

Here you are finished! Congratulations! You now are ready to compile the whole of your operating system.

Problems

If you just have installed a free software, GNU tar for instance, and if, when you execute it, another software is started or it does not work like it did when you tested it directly from the src directory, it is a 'PATH' problem, which finds the programs in a directory before the one where you have installed the new software. Check by executing type -a <program>.

The solution is to put the installation directory higher in the 'PATH' and/or to delete/rename the files that are executed whereas they were not asked to, and/or rename your new programs (into gtar in this example) so that there is no more confusion.

You can also make an alias if the shell allows it (for instance, say that tar means /usr/local/bin/gtar).

Support

Documentation

Several documentation sources:

Technical support

If you have bought an "official" Linux-Mandrake distribution , you can ask the technical support for information on your system. I think that the technical support has other things to do than help all the users to install additional software, but some of them offer a 'x' days-installation help. Perhaps they can spend some time on compilation problems?

You can also rely on help from the free software community:

How to find free software

To find free software, a lot of links may help you:

Acknowledgements

Copyright

Copyright (c) 1999 Benjamin Drieu, association APRIL (which website is http://www.april.org/).

This document is free documentation; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This work is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See the GNU General Public License for more details.

You will find the GNU General Public License at address http://www.gnu.org/copyleft/gpl.html; you can also get a copy of it by writing to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.


Next : Command Line Utilities
Previous : Compiling and installing new kernels
Up

Copyright © 2000 MandrakeSoft