Building from Source

So far in this book, the applications have all been installed from precompiled binary Red Hat Packet Manager (RPM) packages. You ve seen how quick and easy it is to install, modify, and uninstall programs from precompiled binaries. However, many applications are also available as (uncompiled) source code, typically in a compressed archive of some sort (for example, .tar.gz or .tar.bz2 ).

Many applications are made available in both formats (RPM and uncompiled source), and if you want to install such an application, you have a choice about which format to use ”building applications via source code or installing prebuilt binary RPM packages. In this situation, it s not clear which method is preferable; it comes down to personal preference. The following table summarizes the levels of difficulty and control involved.


Binary RPM

Source Code

Ease of installation


Low to high; dependent on environment

Ease of un-installation


Low to high

Control of build process and installation


Medium to high

The RPM keeps track of dependencies, giving you the ability to upgrade or uninstall a package quite easily. While an RPM package tends to install the files contained in the package in disparate locations throughout the system, it is possible to use the --prefix and --relocate options to force RPM to install the files in specific directories. But, if you want even more control over the installation process, you should build the application from source code.

Of course, there are also many applications for which there is no RPM package ”only the uncompiled source code is made available. If you want to install an application of this type, you have no choice but to produce the application yourself, by building and compiling the source code on your system.

In the next section, we ll download, build, and install version 2.0.17 of the gFTP application, an FTP client application with a graphic user interface, from its source code. Fedora Core comes prebuilt with version 2.0.17 of the gFTP application, so you don t have to worry about upgrading the application. However, by learning how to build the application from its source code now, you can update to the latest version when it becomes available.

Installing Development Tools and Libraries

Before starting to build your first application from source code, you need to install the appropriate development tools and code libraries. First, you need to have certain development tools installed, including make and gcc for initiating the build process and to compile the C source code, respectively. Second, you need to install the X Window system and GNOME software development libraries. The gFTP application uses these libraries to create a rich GNOME-compliant user interface. We ll use the RPM applet to install these required packages.

Try It Out Installing the Development Tools

  1. Launch the RPM applet (either from the Main Menu>System Settings>Add/Remove Applications menu, or by executing the system-config-packages application from the command line).

  2. As you peruse the list of package categories, you will see the Development package category toward the end. Click Development Tools, which bundles the make and gcc packages, as well as the X Software Development and GNOME Software Development package groups, and press the Update button (see Figure 11-3).

    The installation process takes some time, but once it s finished, you can start your application-building process.

    click to expand
    Figure 11-3

Building the Application

As you will soon see, the entire process of building and installing the gFTP application is limited to three simple steps. You can apply these same techniques when building other applications from source code, as well.

Try It Out Compiling the gFTP Application

  1. Determine the root source directory where you will be building any and all applications. A good directory to choose is /usr/local/src because it is separate from the standard operating system installation directories. Remember, you need to be logged on as the root user to have the necessary privileges to create and modify files in this directory.

  2. Once you have decided on the root source directory, you should create a subdirectory where you will unpack the source code for the application. Some source code packages when unpacked create a directory to hold all of their files, while others just dump the files into the current directory. Take this step to ensure that you do not end up with source code files cluttered all over the /usr/local/src root directory:

       # mkdir /usr/local/src/gftp   
  3. Obtain the source code for gFTP from the following URL: .

    Notice that the source code is distributed as a compressed tar archive. You can download it using a Web browser, or by using the wget program, like so:

       # cd /usr/local/src/gftp     # wget   --02:13:47--               => 'gftp-2.0.17.tar.gz'    Resolving    Connecting to[]:80... connected.    HTTP request sent, awaiting response... 200 OK    Length: 1,931,750 [application/x-gzip]        100%[====================================>] 1,931,750 356.05K/s ETA 00:00        02:13:53 (339.65 KB/s) - 'gftp-2.0.17.tar.gz' saved [1931750/1931750] 
  4. Uncompress and untar the archive:

       # tar -zkxvf gftp-2.0.17.tar.gz   gftp-2.0.17/    gftp-2.0.17/po/    gftp-2.0.17/po/zh_CN.po    gftp-2.0.17/po/Makevars    ...    gftp-2.0.17/README.html    gftp-2.0.17/INSTALL    gftp-2.0.17/ABOUT-NLS    gftp-2.0.17/ChangeLog    gftp-2.0.17/COPYING    gftp-2.0.17/ChangeLog-old 

    The -k switch forces tar to keep any existing files; it will not overwrite existing files with files from the archive. This is for your own safety and ensures that you will not lose any important files in case you are exposed to a rogue package that was designed to destroy existing files.

  5. We now have a directory called gftp-2.0.17 , which contains all of the source code for the gFTP application. Let s get into that directory and run the configure program, which configures the source code for building on your system.

       # cd gftp-2.0.17     # ./configure --prefix=/usr/local   creating cache ./config.cache    checking for non-GNU ld... /usr/bin/ld    checking if the linker (/usr/bin/ld) is GNU ld... yes    checking for a BSD compatible install... /usr/bin/install -c    checking whether build environment is sane... yes    checking whether make sets ${MAKE}... yes    checking for working aclocal-1.4... found    checking for working autoconf... found    checking for working automake-1.4... found    checking for working autoheader... found    checking for working makeinfo... found    checking host system type... i686-pc-linux-gnu    checking for gcc... gcc    ...    creating config.h    creating po/POTFILES    creating po/Makefile 

    As you can see, the configure command does a lot of work, trying to determine what type of system you have and what tools are available. We have asked the configure application to use the /usr/local prefix when it is time to install the application. In other words, all of the files that we need to install will be installed in various subdirectories under /usr/local . This allows you to control where you store all of your custom-built application s data and files.

  6. Now, you are ready to compile. Simply invoke the make command:

       # make   make  all-recursive    make[1]: Entering directory '/usr/local/src/gftp/gftp-2.0.17'    Making all in intl    make[2]: Entering directory '/usr/local/src/gftp/gftp-2.0.17/intl'    make[2]: Nothing to be done for 'all'.    make[2]: Leaving directory '/usr/local/src/gftp/gftp-2.0.17/intl'    Making all in docs    make[2]: Entering directory '/usr/local/src/gftp/gftp-2.0.17/docs'    Making all in sample.gftp    make[3]: Entering directory              '/usr/local/src/gftp/gftp-2.0.17/docs/sample.gftp'    make[3]: Nothing to be done for 'all'.    make[3]: Leaving directory '/usr/local/src/gftp/gftp-2.0.17/docs/sample.gftp'    make[3]: Entering directory '/usr/local/src/gftp/gftp-2.0.17/docs'    make[3]: Nothing to be done for 'all-am'.    make[3]: Leaving directory '/usr/local/src/gftp/gftp-2.0.17/docs'    make[2]: Leaving directory '/usr/local/src/gftp/gftp-2.0.17/docs'    Making all in lib    make[2]: Entering directory '/usr/local/src/gftp/gftp-2.0.17/lib'    gcc -DHAVE_CONFIG_H -I. -I. -I.. -I/usr/include/glib-2.0         -I/usr/lib/glib-2.0/include   -D_REENTRANT -I../intl         -DSHARE_DIR=\"/usr/local/share/gftp\"         -DLOCALE_DIR=\"/usr/local/share/locale\"            -g -O2 -c bookmark.c    ...    make[2]: Leaving directory '/usr/local/src/gftp/gftp-2.0.17'    make[1]: Leaving directory '/usr/local/src/gftp/gftp-2.0.17' 

    The make command follows the instructions specified in Makefile (which was customized to the system by the configure program) to build the application. In this case, there are only a small number of C source files that need to be compiled. So after a few minutes, make finishes and we have our application.

  7. Install the compiled application into /usr/local :

       # make install   Making install in intl    make[1]: Entering directory '/usr/local/src/gftp/gftp-2.0.17/intl'    if { test "gftp" = "gettext-runtime"  test "gftp" = "gettext-tools"; } \       && test 'no' = yes; then \      /bin/sh .././mkinstalldirs /usr/local/lib /usr/local/include; \      /usr/bin/install -c -m 644 libintl.h /usr/local/include/libintl.h; \      @LIBTOOL@ --mode=install \        /usr/bin/install -c -m 644 libintl.a /usr/local/lib/libintl.a; \      if test "@RELOCATABLE@" = yes; then \        dependencies='sed -n -e 's,^dependency_libs=\(.*\),,p'           < /usr/local/lib/  sed -e "s,^',," -e "s,'$,,"'; \        if test -n "ependencies"; then \          rm -f /usr/local/lib/; \        fi; \      fi; \    else \      : ; \    fi    ...    make[2]: Leaving directory '/usr/local/src/gftp/gftp-2.0.17'    make[1]: Leaving directory '/usr/local/src/gftp/gftp-2.0.17' 
  8. Let s check to see that the new version of the gFTP application has been built and installed properly. Because you asked the make program to install the application and its related files in /usr/local , you will find the gFTP binary executable in /usr/local/bin . You can execute the application with the “version switch to verify that it is indeed version 2.0.17, like so:

       $ /usr/local/bin/gftp --version   gFTP 2.0.17 

    The existing version continues to exist on your system in its original location, /usr/bin , which you can see for yourself:

       $ /usr/bin/gftp -version   gFTP 2.0.17 

It is up to you to decide whether you want to keep both versions around. Typically, when you install a new version of a software application, you should keep the older version around until you have had the chance to test the new version for some period of time. That way, you can always revert back to the original version if the newer version of the application is problematic .


Before you build any application from its source code, you should spend some time reading through the README and INSTALL files, as well as looking at some of the source code. That way, you can get a better handle on the application s features and limitations.

You have compiled and built your first application straight from source code; the process was quite straightforward for this application, although it will vary somewhat from application to application:

   # ./configure --prefix=/some/dir     # make     # make install   

By building applications in this manner, you have more control over the entire process and can decide how to modify or optimize the code and select where and how to install its components . For the most part, the building process is not difficult. Sometimes, however, you may run into difficulties getting the code to compile. It is beyond the scope of this book to discuss these various situations, so please refer to Professional Linux Programming , by Neil Matthew and Richard Stones, for more details.

Beginning Fedora 2
Beginning Fedora 2
ISBN: 0764569961
EAN: 2147483647
Year: 2006
Pages: 170 © 2008-2017.
If you may any questions please contact us: