While some H/FOSS software is available as binary (executable) packages, much of it is available only in source code form, and requires that you build it yourself before you can run it. Even when binary packages are available, if you are going to contribute to the project by modifying, extending or patch the code, you'll need to get the source code and be able to build the executables yourself.
The tutorial below will introduce you to the two most common build tools used H/FOSS projects, configure
and make
. It will also walk you through the use of these tools in a small HelloWorld project. In this activity you will install a full-scale FOSS project that uses configure
and make
. This will obviously require that you use configure
and make
, but will also require you to, as is quite typical, find and install some additional dependencies and deal with imperfect installation instructions.
Prerequisites
Before starting work through the tutorial below. The Hello World example will introduce you to the use of the unix autotools and the configure
and make
tools:
Assignment
Your task is to download, configure, build and install Freeciv - "a Free and Open Source empire-building strategy game inspired by the history of human civilization." You should do this in Ubuntu within VirtualBox. Ideally, begin from the last snapshot you created during the Software Installation Activity.
The following broad steps will help to guide you through the process. However, at each step you may need to consult the project installation directions, install unmet dependencies, debug errors and Google to find additional information.
Download / Unpack
Rather than installing the latest version of Freeciv, we will be installing an older version. By installing an older version we'll know where the complications arise and can ensure that the process clearly illustrates the configure/make process. You should feel free to have a go at installing the newest version later if you are interested.
freeciv-2.1.9.tar.bz2
file in the Files
area of the freeciv SourceForge site. This was available as of this writing (Sept 2016).
freeciv-2.1.9.tar.bz2
file from your Downloads directory to your Documents directory. Despite the convenience, it is generally poor form to use files or do work in the Downloads
directory.
freeciv-2.1.9.tar.bz2
file to get the freeciv-2.1.9
source directory.
tar
bz2
are compressed archive files. You'll need to decompress the bz2 file to get the freeciv-2.1.9.tar
file.
tar
are tape archives. This is a bunch of files and directories packed into a single uncompressed file. You'll need to extract the tape archive to get the freciv-2.1.9
directory that contains the source code.
README and INSTALL
Most H/FOSS project will include README
and INSTALL
files in their source directory. These files contain information about the product and how to build/install it. The important information necessary to build Freciv is contained the INSTALL
file.
gedit
) or display (more
) the INSTALL
file.
Configure
You learned a lot about configure scripts in the assigned tutorial. They are used by many H/FOSS projects to detect machine particulars and to create the makefiles that are used to control the compilation of the source code into the executable(s).
freeciv-2.1.9
directory and notice that it contains the configure.ac
and Makefile.am
files that get converted in to the configure
script and the Makefile.in
file by the autotools (autoconf
and automake
) that you learned about.
configure
script and the Makefile.in
file. This is because autotools were run by the developers and the results were packaged in the tar file you downloaded - how convenient! If they were not, the autotools could be used to generate them from the configure.ac
and Makefile.am
files. In fact, the developers provide a shell script (autogen.sh
) that does exactly that.
configure
script as described in section "2b. Generating the Makefile for release versions" of the INSTALL
document.
configure
script terminates with an error:
configure: error: no acceptable C compiler found in $PATH
configure
script terminates with an error:
configure: error: Could not find zlib library.
apt-get
, so search around until you find something that uses apt-get
.
-dev
appended. The basic package should already be installed, so you'll just need to install the -dev
package.
configure
script again.
configure
script terminates with an error:
configure: error: could not guess which client to compile
INSTALL
we may have caught it before now. But, truth be told, the more common approach is to just plow ahead and address issues as they arise, as we've been doing.
configure
script to find the source of the problem.
configure
script again.
freeciv-2.1.9
directory now contains a Makefile
.
Make
Once the project is configured and the Makefile
s have been generated the executable programs must still be built. The make
command uses the information from the Makefile
s to compile the source code into the executable programs.
INSTALL
document.
make[1]: Leaving directory '/home/comp491/Documents/freeciv-2.1.9'
Makefile:517: recipe for target 'all' failed
make: *** [all] Error 2
make
command you'll find that the source of the problem is an undefined reference to a symbol in the GLIC library that was discovered during while linking the compiled files:
/usr/bin/ld: civclient.o: undefined reference to symbol 'pow@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
...
configure
with some additional flags.
make
again.
freeciv-2.1.9
directory and confirm that two new executable files (civ
and ser
) have been created.
Install
It is possible to run the newly created executable programs directly from the freeciv-2.1.9
directory. However, those files are only available to your user. There are typically many users on a unix based system (e.g. consider the lab machines). To make the executables available to all users they must be placed into a publicly accessible location. On unix systems, this typically means copying them into the /usr/bin
or /usr/local/bin
directories. Most Makefile
s contain instructions for installing the program in an appropriate publicly accessible location.
INSTALL
document.
make install
terminates with an error
make install
command to determine the problem.
make install
command correctly.
/usr/local/bin
. Notice that the install process changed the names of the executables (civclient
and civserver
).
Run
When executable programs are installed in a publicly accessible location they are easy for everyone to run from the command line. When the location of the executable is also in the user's PATH
environment variable, they simply type the name of the executable on the command line. The shell searches the directories in the PATH
for the program and runs it if it is found.
/usr/local/bin
directory is in your PATH
environment variable.
env
command will list all of your environment variables.
grep ^PATH
will show just your PATH
variable.
civclient
)
Clean
You may have noticed earlier that the second time you ran make it went much faster than the first. This is because many of the files had already been compiled, had not changed, and were not affected by the new configuration. Sometimes however, you will want to rebuild the entire project from a fresh state. Most Makefile
s contain instructions for removing all of the files created by the build process.
make
again. Notice that it goes very quickly because there are no files that need to be compiled.
client
and common
and server
directories. You will see lots of .o
files. These are the .c
files compiled into object code, which are then linked together into the full executable.
make clean
client
and common
and server
directories. Notice that the .o
files are now all gone. Running make
again would require that they all be compiled again, resulting the much longer process we experienced earlier.
Acknowledgements: This assignment builds from and adapts ideas and content from the following activities created by others: