LPI Linux Certification/Make & Install Programs From Source
Candidates should be able to build and install an executable program from source. This objective includes being able to unpack a file of sources. Candidates should be able to make simple customizations to the Makefile, for example changing paths or adding extra include directories, either in the raw Makefile or using the configure tools.
- Key knowledge area(s):
- Unpack a file of sources using typical compression utilities.
- Make simple customizations to Makefile such as changing paths or adding extra include directories.
- Apply parameters to a configure script.
- Know where sources are stored by default.
- Compile a RPM or DPKG software package using sources.
- The following is a partial list of the used files, terms and utilities:
- RPM and DPKG commands
An archive is a collection of related files stored in one file. The command that allows you to store files and subtree directories in one file is tar.
tar function & options files
Common functions: -c: Create a new tar file. -t: Tell the contents of a tar file. -x: Extract the contents of a tar file.
Common options: -f file: Specify the name of the tar file.
tar cvf mybackup.tar ~ tar cvf usr.tar /usr tar tvf mybackup.tar tar xvf mybackup.tar
It is good practice to use the .tar extension for all files archived with tar.
Compression saves space for storage and file transfer. There are multiple utilities to do compression:
- compress, uncompress # Old Unix compression algorithm
- gzip, gunzip # Most common use
- bzip2, bunzip2 # Best compression algorithm
Once an archive has been created , it can be compressed. Examples:
$ ls -l backup.tar -rw-r--r-- 1 rarrigon users 22773760 nov 10 11:07 backup.tar
$ gzip -v backup.tar backup.tar: 53.8% -- replaced with backup.tar.gz
$ ls -l backup.tar.gz -rw-r--r-- 1 rarrigon users 10507393 nov 10 11:07 backup.tar.gz
gunzip backup.tar.gz $ bzip2 -v backup.tar backup.tar: 2.260:1, 3.540 bits/byte, 55.75% saved, 22773760 in, 10077846 out.
Files archiving and compression
When archiving files and subdirectories it is possible to package and compress them in one command. Examples:
tar cvzf backup.tgz ~ # Backup of home with gzip tar cvjf backup.tbz ~ # Backup of home with bzip2 tar xvzf backup.tgz # Extract and gunzip backup.tgz tar xvjf backup.tbz # Extract and bunzip2 backup.tbz
By default tar uses a relative path but with the -P option it is possible to save files with an absolute path. Files in this mode will always be extracted at the same location.
For compressing and archiving in one line
$ tar cvf - . | gzip > target.tar.gz
For unzipping a compressed archive:
$ gunzip -c file_name.tar.gz |tar xvf -
GNU tool chain
Under Linux all the sources can be built with the standard GNU tool chain. make Utility to maintain group of programs. Use the rules defined in Makefile.
- gcc ANSI C Compiler
- g++ C++ Compiler
Many compressed or archived packages once installed will have information files (README, INSTALL) that should explain how it should be built and installed. The files Makefile.in and configure.in are the basic files that will be used to generate a final Makefile. The configured file in general scans the system and will build a final Makefile.
- Do an archive of the /bin and the /sbin directories. With which compression utilities do you get the smallest file size? Use -v to get in percentage the size file reduction.
- Install the file /usr/src/packages/SOURCES/grub-09.tar.bz2 in /tmp and by reading INSTALL and README build the sources.
- Find the way to uncompress a .deb an a .rpm archive, what is in ?
- In on command line, compress a new file and uncompress this new file somewhere else.