Compiling and Developing Software


The packages found in the Ubuntu repositories do not include all open source software (far from it!). The main and restricted repositories only include software explicitly supported by Ubuntu and its managing company, Canonical. The universe and multiverse repositories only include Ubuntu packages that are (or were) supported by someone in the community. There are hundreds of thousands of open source projects that are not in these repositories, and many only require you to download the source and compile them.

There are many reasons why you might want to download source code. Some of the common reasons include:

  • Cutting edge-Software found in the Ubuntu repositories may be outdated. If you want the most recent version, you will probably need to visit the project's home page and download source code.

  • Tweaking-If you don't like how some piece of software functions, you can download the source code and change it.

  • Fixing-Some packages do not work. This may be due to broken dependencies or out- dated software components. In any case, you can retrieve the code, patch it as necessary, and install it on your system. You are not limited to precompiled software.

  • Educating-If you want to understand how something works, you can download the source and look at the code. Code from open source projects can be used as excellent examples and templates.

  • Extending-Many projects are extensible. By downloading the source code, you can see how to interface new software into a project.

  • Leveraging-Why reinvent the wheel? If some source code does a function that you need, you can download the code and adapt it to your needs. Be sure to pay attention to the original author's licensing requirements; some source code cannot be freely used without restrictions.

  • Sharing-Every package in the universe and multiverse repositories was compiled and tested by someone. Perhaps you would like to add your favorite projects so the community can benefit?

  • Uniqueness-Many open source projects not found in the Ubuntu repositories provide very unique and useful functions. If you cannot download the functionality in binary form, then you will need to acquire the source.

Regardless of the reason, you will need some way to retrieve the source code and compile it. Some open source code is built for specific platforms and operating systems. For example, the mail reader elm and the graphic program xv were both designed for very old versions of Linux and have not been maintained. Downloading the source to these projects is not enough. You will likely need to edit the files before you can build these executables. To compile any incompatible projects, you may need a full development environment.

Installing Package Source Code

Many packages are available as pre-compiled executables and as source code. If you plan to install any source code then you'll need to install the dpkg-dev package. This brings in one required executable: /usr/bin/dpkg-source. This is used to unpack source code packages.

Many packages include developer installs. For example, the linux-kernel-devel package places source code on the system for people doing kernel development. Most major subsystems, including audio, USB, and X-Windows, provide developer packages.

Note 

Some packages do not actually install code. For example, linux-kernel-devel is a package that is only used to install some specific dependencies. The code actually comes from its dependencies.

The other way to retrieve source code from the Ubuntu repositories is to actually download the source, and not an installation package. Source code is downloaded using apt-get source package_name. Every package in the main and universe repositories should include source code, but source code may be missing from the restricted and multiverse repositories.

Note 

Not every package includes source code. Although source code is expected for packages in the main and universe repositories, it may not exist for software found in the restricted and multi- verse repositories.

The installation of binary files requires you to run apt-get as root. This is because files are placed in privileged directories and the catalog of installed packages must be updated. In contrast, source files are deposited in the current directory, so root permission is not required. This also means that there is no automatic removal. For example, to download the source code to gcalctool and unpack it, use:

 mkdir src cd src apt-get source gcalctool 

If you also want to automatically compile it, add the –compile flag to the apt-get line.

 apt-get --compile source gcalctool 
Warning 

While apt-get install downloads dependencies, the apt-get source command does not. You may be required to download and install different developer packages and additional source code. Do not expect automatic compilation to work perfectly every time.

If you are done with the source code, you can remove it without using apt-get.

 rm -rf gcalctool* 

Programming with C

Most open source projects are written in C, C++, Java, Perl, Python, or Shell Script. Perl, Python, and Bash (for Shell Scripts) are installed by default. Although basic C and C++ compilers are installed, these are not the full development environments. You should consider installing full environments.

There are many components to the full C and C++ environment. The key ones to install are:

  • The Gnu C Compiler (gcc) and Gnu C++ (g++). These packages also install the manuals and documentation in case you need to look up any standard library calls.

     sudo apt-get install gcc g++ sudo apt-get install gcc-doc manpages-dev 
  • The make command is commonly used for building executables. Other build-environment tools include autoconf, automake, and libtool.

     sudo apt-get install make autoconf automake libtool 
  • If the code uses any complicated state machines or lexical analyzers, then you will probably need flex and bison.

     sudo apt-get install flex bison bison-doc 
  • The zlib library is very common. Most tools that perform compression use it. Some well-known examples include gzip, bz2, and unzip, but other tools like JPEG rendering systems and MP3 players also use zlib.

     sudo apt-get install zlib1g zlib1g-dev 
  • Most graphic systems use the X11 graphic library. You will probably need the development environment since it provides the application programming interface (API) to X- Windows.

     sudo apt-get install xlibs-dev 
  • If you plan to do any hard-core development, you might want an integrated development environment (IDE). Under Ubuntu, you have a couple of options.

    • Anjuta is a fully functional IDE with a graphical interface. To install it, use sudo apt-get install anjuta.

    • Eclipse is a very popular IDE for Java, but it does have an extension for C programming. Use sudo apt-get install eclipse-cdt to install the C Developer Tool.

Note 

Anjuta is designed for C and C++ software development. In contrast, Eclipse is an extension of a Java IDE. As a result, Eclipse requires include a lot of additional packages that Anjuta does not need. The list of requirements for Eclipse includes Ant (a Java build system that is comparable to make), Java (the full environment), and even the Mozilla web browser (Uh, I don't know why, but it is a prerequisite).

Enabling Java

Java is a programming language that is used by some developers as an alternative to C and C++. Its strength is in portability: a program created in Java does not need to be recompiled on every platform. Because of its portability, some web sites use Java instead of static HTML or dynamic HTML with JavaScript.

Note 

Despite the naming similarity, Java and JavaScript are very different languages. The JavaScript name was more of a marketing blitz than a functional expression. At the time the language was created, Java was popular and scripts implied simple. Unfortunately, many non-programmers still think that JavaScript uses Java.

In previous versions of Ubuntu, there were many options for installing Java, and all required multiple steps. The problem was the licensing: Sun Microsystems used a restrictive license that was not appropriate for the restrictive or multiverse repositories. When Ubuntu Dapper was released, Sun changed the licensing, allowing the package to be placed in the multiverse repository. To install Java:

  1. Enable the multiverse repository by editing /etc/apt/source.list and removing the commented line for the multiverse repository.

     deb http://us.archive.ubuntu.com/ubuntu/ dapper-backports main \ restricted universe multiverse 

  2. Install the Java Runtime Environment (JRE).

     sudo apt-get install sun-java5-jre 
  3. If you would like to use Java with the Mozilla Firefox web browser, you will need to install the Java plugin and configure it as the default JRE.

     sudo apt-get install sun-java5-plugin sudo update-alternatives --config java 
  4. For build environments, Ant is the tool of choice (few Java environments use make).

     sudo apt-get install ant ant-doc 
  5. If you need a full IDE for Java, consider using Eclipse.

     sudo apt-get install eclipse 

The Sun Java 5.0 runtime environment requires you to agree to the Sun licensing. In some environments, this may not be desirable. In addition, this version of Java is not available for all platforms. For example, as of August 2006, sun-java5-jre did not install on the PowerPC because the sun-java5-bin package was unavailable. Fortunately, there are some alternatives to Sun's Java implementation.

  • The free-java-sdk package provides an open source Java development and runtime environment.

     sudo apt-get install free-java-sdk 
  • The GNU compiler for Java is an alternate open source Java implementation. A basic GCJ compiler is installed by the default, but you may want to install the entire JRE and the web browser plug-in.

     sudo apt-get install gcj gij sudo apt-get install gcjwebplugin 



Hacking Ubuntu
Hacking Ubuntu: Serious Hacks Mods and Customizations (ExtremeTech)
ISBN: 047010872X
EAN: 2147483647
Year: 2004
Pages: 124
Authors: Neal Krawetz

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net