Installing software from sources
Understand a little more ./configure and make
In this section we will see a little more about how the installation process works, in the previous section we saw the big line without looking under the lid of the process, although this is not essential it is still interesting especially for a administrator of understand the whole process. Of course, the higher your programming skills, the more you will be able to understand the process mainly the part of the configure, because the compilation remains the instruction conversion in a C, C ++, fortran, … language in a binary language, we will thus find the files include as well as the linkage with the libraries .so / .dll (under windows).
./Configure
The first step during the compilation is the configure as mentioned this script performs the validation of the libraries, during the configuration of htop we found that it had raised the problem the configure script is a simple shell, but very bulky:
configure file | |
1 2 3 4 5 | admuser@srv01:~/htop-1.0.2$ file configure configure: POSIX shell script, ASCII text executable admuser@srv01:~/htop-1.0.2$ wc -l configure 14966 configure |
with 14966 lines we will not read the whole file but take some section, if you are curious you find by reading the email that the script is complex, the person who provides htop did NOT write the whole file , the latter is generated using the tools: autoconf, automake
There are tons of documentation and howtos. Google for something like “autoconf automake howto”. The good documentation is in the official manual pages: |
A good starting point is the help: D, always a source of information, the configuration script consists of two parts, a generic section that is equivalent for several applications and the specific section that allows to activate features:
help configure [common section] | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | admuser@srv01:~/htop-1.0.2$ ./configure --help 'configure' configures htop 1.0.2 to adapt to many kinds of systems. Usage: ./configure [OPTION]... [VAR=VALUE]... To assign environment variables (e.g., CC, CFLAGS...), specify them as VAR=VALUE. See below for descriptions of some of the useful variables. Defaults for the options are specified in brackets. Configuration: -h, --help display this help and exit --help=short display options specific to this package --help=recursive display the short help of all the included packages -V, --version display version information and exit -q, --quiet, --silent do not print 'checking...' messages --cache-file=FILE cache test results in FILE [disabled] -C, --config-cache alias for '--cache-file=config.cache' -n, --no-create do not create output files --srcdir=DIR find the sources in DIR [configure dir or '..'] Installation directories: --prefix=PREFIX install architecture-independent files in PREFIX [/usr/local] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [PREFIX] By default, 'make install' will install all the files in '/usr/local/bin', '/usr/local/lib' etc. You can specify an installation prefix other than '/usr/local' using '--prefix', for instance '--prefix=$HOME'. For better control, use the options below. Fine tuning of the installation directories: --bindir=DIR user executables [EPREFIX/bin] --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] --datadir=DIR read-only architecture-independent data [DATAROOTDIR] --infodir=DIR info documentation [DATAROOTDIR/info] --localedir=DIR locale-dependent data [DATAROOTDIR/locale] --mandir=DIR man documentation [DATAROOTDIR/man] --docdir=DIR documentation root [DATAROOTDIR/doc/htop] --htmldir=DIR html documentation [DOCDIR] --dvidir=DIR dvi documentation [DOCDIR] --pdfdir=DIR pdf documentation [DOCDIR] --psdir=DIR ps documentation [DOCDIR] Program names: --program-prefix=PREFIX prepend PREFIX to installed program names --program-suffix=SUFFIX append SUFFIX to installed program names --program-transform-name=PROGRAM run sed PROGRAM on installed program names System types: --build=BUILD configure for building on BUILD [guessed] --host=HOST cross-compile to build programs to run on HOST [BUILD] --target=TARGET configure for building compilers for TARGET [HOST] |
help configure [specific section] | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | Optional Features: --disable-option-checking ignore unrecognized --enable/--with options --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] --disable-dependency-tracking speeds up one-time build --enable-dependency-tracking do not reject slow dependency extractors --enable-shared[=PKGS] build shared libraries [default=no] --enable-static[=PKGS] build static libraries [default=yes] --enable-fast-install[=PKGS] optimize for fast installation [default=yes] --disable-libtool-lock avoid locking (might break parallel builds) --enable-openvz enable OpenVZ support --enable-cgroup enable cgroups support --enable-vserver enable VServer support --enable-ancient-vserver enable ancient VServer support (implies --enable-vserver) --enable-taskstats enable per-task IO Stats (taskstats kernel sup required) --enable-unicode enable Unicode support --enable-native-affinity enable native sched_setaffinity and sched_getaffinity for affinity support, disables hwloc --enable-hwloc enable hwloc support for CPU affinity Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-pic try to use only PIC/non-PIC objects [default=use both] --with-gnu-ld assume the C compiler uses GNU ld [default=no] --with-proc=DIR Location of a Linux-compatible proc filesystem (default=/proc). |
Let’s analyze some general options:
--prefix=PREFIX install architecture-independent files in PREFIX [/usr/local]
This allows to define the place where will be installed the software prefix .. This defines the variable prefix which will be used to define the places where will be copy the binary, the man pages, etc.
default: / usr / local /
–bindir=DIR user executables [EPREFIX/bin]
This defined variable where the binary will be installed at the end we find the value EPREFIX defined by “–prefix” so here by default we will have the binaries in / usr / local / bin
precisely if we look at our previous installation of htop, because we have not changed the prefixbinary htop
1 2
admuser@srv01:~/htop-1.0.2$ which htop /usr/local/bin/htop
–sbindir, –mandir, -sysconfdir, … As you can see the position of the files is very configuration, in practice personally the only variable that I change is –prefix
Let’s analyze some specific options:
–enable-openvz –enable-cgroup –enable-vserver –enable-ancient-vserver –enable-vserver –enable-taskstats –enable-unicode –enable-native-affinity –enable-hwloc : we see system functionality that will be enabled during compilation, by default all options are active. That’s why at the first compilation we got the following message:
unicode compilation error
1 2 3 4
checking for strdup... yes checking whether gcc -std=c99 option works... yes checking for refresh in -lncursesw... no configure: error: You may want to use --disable-unicode or install libncursesw.
–disable-FEATURE in line 3 indicates that one of the functionalities can be deactivated by explicitly defining –disable-unicode for example, this equals –enable-unicode = no. Of course to understand the features especially at the beginning must googled! There is unfortunately no secret.
Here is another example configuration for another application screen we find that the options are not equivalent:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | admuser@srv01:~/screen-4.2.1$ ./configure --help [ ... ] Optional Features: --disable-option-checking ignore unrecognized --enable/--with options --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] --disable-socket-dir disable system wide socket-dir and use ~/.screen instead --enable-pam enable PAM support --enable-use-locale use localized month/day names --enable-telnet enable builtin telnet --enable-colors256 enable support for 256 colors --enable-rxvt_osc enable support for rxvt OSC codes Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-socket-dir=path where to put the per-user sockets --with-pty-mode=mode default mode for ptys --with-pty-group=group default group for ptys --with-sys-screenrc=path to the global screenrc file [ ... ] |
make and the Makefile
make is a software that automatically builds files, often executable, or libraries from basic elements such as source code. It uses files called makefile that specify how to build the target files. Unlike a simple shell script, make executes the commands only if they are needed. The goal is to arrive at a result (compiled or installed software, created documentation, etc.) without necessarily redoing all the steps. make is especially used on UNIX platforms.
Operation
It is mainly used to facilitate the compilation and the editing of links since in this process the final result depends on previous operations.
To do this, make uses a configuration file called makefile, which is often called Makefile. The latter describes targets (which are often files, but not always), what other targets they depend on, and what actions (commands) to achieve.
In order to rebuild a user-specified target, make will look for the targets needed to rebuild that target, and this recursively. (In doing so, it actually creates a topological sort of the dependency relationship on the targets.) Some variants of make provide the ability to run tasks in parallel, if possible.
The dependency rules can be explicit (file names given explicitly) or implicit (via file patterns, for example file.o depends on file.c, if it exists, via a recompilation).
make can be called with a list of target files by the following command line:
make CIBLE [CIBLE ...]
If no argument is passed, make will build the first specified target in the makefile. Traditionally, this target is called all.
The modification date of the target file allows make to determine if it is up to date. So the target is not rebuilt.
make looks in the current directory for the makefile to use. For example, the GNU make looks in the order, a GNUmakefile, makefile, Makefile, and then executes the specified (or default) targets for that file only.
The language used in the makefile is declarative programming. Unlike imperative programming, this means that the order in which the instructions must be executed does not matter.
The rules
A makefile consists of rules. The simplest form of rule is:
example make file | |
1 2 3 4 5 6 7 | cible [cible ...]: [composant ...] [tabulation] commande 1 . . . [tabulation] commande n |
The target is most often a file to build, but it can also define an action (erase, compile …). The components are prerequisites needed to perform the action defined by the rule. In other words, the components are the targets of other rules that must be realized before you can achieve this rule. The rule defines an action by a series of commands. These commands define how to use the components to produce the target. Each command must be preceded by a tab character.
Commands are executed by a separate shell or by a command line interpreter.
Here is an example of makefile:
MAkefile example | |
1 2 3 4 5 6 7 8 9 | all: cible1 cible2 echo ''all : ok'' cible1: echo ''cible1 : ok'' cible2: echo ''cible2 : ok'' |
When this makefile is executed through the make all command or the make command, the ‘all’ rule is executed. It requires the realization of the ‘target1’ and ‘target2’ components that are associated with the ‘target1’ and ‘target2’ rules. These rules will therefore be executed automatically before the ‘all’ rule. On the other hand, the make target1 command will only execute the ‘target1’ rule.
In order to resolve the order in which the rules must be executed, make uses a topological sort.
Note that a rule does not necessarily contain an order.
Components are not always targets to other rules, they can also be files needed to build the target file:
output make file | |
1 2 3 | sortie.txt: fichier1.txt fichier2.txt cat fichier1.txt fichier2.txt > sortie.txt |
The sample rule above builds the output.txt file using the files file1.txt and file2.txt. By executing the makefile, make checks if the output.txt file exists and if it does not exist, it will build it using the command defined in the rule.
Command lines can have one or more of the following three prefixes:
A minus sign (-), specifying that errors should be ignored;
An at sign (@), specifying that the command should not be displayed in the standard output before being executed;
A plus sign (+), the command is executed even if make is called in a “do not execute” mode.