OnWorks Linux and Windows Online WorkStations

Menu
Logo

Free Hosting Online for WorkStations

< Previous | Contents | Next >

Obtaining The Source Code

For our compiling exercise, we are going to compile a program from the GNU Project called diction. This is a handy little program that checks text files for writing quality and style. As programs go, it is fairly small and easy to build.

Following convention, we’re first going to create a directory for our source code named

src and then download the source code into it using ftp:



image

[me@linuxbox ~]$ mkdir src [me@linuxbox ~]$ cd src [me@linuxbox src]$ ftp ftp.gnu.org Connected to ftp.gnu.org.

220 GNU FTP server ready.

Name (ftp.gnu.org:me): anonymous

230 Login successful. Remote system type is UNIX.

Using binary mode to transfer files. ftp> cd gnu/diction

250 Directory successfully changed. ftp> ls

200 PORT command successful. Consider using PASV.

150 Here comes the directory listing.


-rw-r--r--

1

1003

65534

68940

Aug

28

1998

diction-0.7.tar.gz

-rw-r--r--

1

1003

65534

90957

Mar

04

2002

diction-1.02.tar.gz

-rw-r--r--

1

1003

65534

141062

Sep

17

2007

diction-1.11.tar.gz

226 Directory send OK.

ftp> get diction-1.11.tar.gz

local: diction-1.11.tar.gz remote: diction-1.11.tar.gz

200 PORT command successful. Consider using PASV.

150 Opening BINARY mode data connection for diction-1.11.tar.gz (141062 bytes).

226 File send OK.

141062 bytes received in 0.16 secs (847.4 kB/s) ftp> bye

221 Goodbye. [me@linuxbox src]$ ls diction-1.11.tar.gz



image

Note: Since we are the “maintainer” of this source code while we compile it, we will keep it in ~/src. Source code installed by your distribution will be installed in /usr/src, while source code we maintain that's intended for use by multiple users is usually installed in /usr/local/src.


image

As we can see, source code is usually supplied in the form of a compressed tar file. Sometimes called a tarball, this file contains the source tree, or hierarchy of directories and files that comprise the source code. After arriving at the ftp site, we examine the list of tar files available and select the newest version for download. Using the get com- mand within ftp, we copy the file from the ftp server to the local machine.

Once the tar file is downloaded, it must be unpacked. This is done with the tar program:


[me@linuxbox src]$ tar xzf diction-1.11.tar.gz

[me@linuxbox src]$ tar xzf diction-1.11.tar.gz


[me@linuxbox src]$ ls

diction-1.11 diction-1.11.tar.gz

[me@linuxbox src]$ ls

diction-1.11 diction-1.11.tar.gz


image

Tip: The diction program, like all GNU Project software, follows certain stan- dards for source code packaging. Most other source code available in the Linux ecosystem also follows this standard. One element of the standard is that when the source code tar file is unpacked, a directory will be created which contains the source tree, and that this directory will be named project-x.xx, thus containing both the project’s name and its version number. This scheme allows easy installation of multiple versions of the same program. However, it is often a good idea to examine the layout of the tree before unpacking it. Some projects will not create the direc- tory, but instead will deliver the files directly into the current directory. This will make a mess in your otherwise well-organized src directory. To avoid this, use the following command to examine the contents of the tar file:


tar tzvf tarfile | head


image


Top OS Cloud Computing at OnWorks: