-
Most software follows a 3-step process to build from source: ./configure && Make && install.
-
The configures script checks dependencies, while Make generates a feasible file; Autoconf/carake helps automation.
-
Installation is usually optional and mainly a convenience, so that you can carry out assignments that are copied to a Padmap.
Installing from the source may seem a bit intimidating than the use of your package manager. But three simple assignments help ensure that the process is still smooth.
What is building the source?
Programs that you perform on your computer are interpreted or compiled. The first are text files with the code that another program – an interpreter – will read and implement when you perform them. The latter are independent binary files that contain machine code and are carried out immediately.
Compiled executable files are very common, especially for larger programs. When you build from the source, use a compiler – such as GCC – to generate an enforceable file from the source code of the application, which can be distributed over many individual files.
Because building the source can be a complex and long -term process, it is usually automated through another program, usually made. You can write Makefiles to determine how a project builds its final enforceable program.
Makefiles themselves become large and log in more complicated projects. This applies in particular to portable apps that must work in different architectures and environments. To meet these situations, many projects generate their makefiles automatically using a tool called AutoConF/car cake.
The 3-step Build process: configure, create, install
The result of all this is a common pattern that uses a lot of software to build from the source:
./configure && make && make install
Many popular programs use this pattern – or a variant – including Apache, which explains the process in the installation file:
A fragment from the Apache installation file with transparent steps, including ./configure, making and installing.
Node.JS is another example of software that uses this pattern. The Building.md file contains relevant instructions:
A fragment from the file node.js building.md that explains it ./configure, make, make -install process.
Each project uses its own approach to build its source, even if it is a simple variation of the three -step pattern. An important distinction is how you perform the assignment chain. Performing the logical and operator (&&) ensures that the chain stops if one of the parts fails:
./configure && make && make install
As an alternative you can perform each assignment separately, but still use only one rule, with semicolons:
./configure; make; make install
As a result, each part is carried out, even if earlier steps have failed. Your choice will not always make a lot of practical difference, and you can also perform them as three separate assignments:
./configure
make
make install
You may not want to fully install the software and prefer to perform directly from its own folder. This is perfect ok to do; you just have to Create Installation command.
Some repos contain a configurescript, others (such as GREP) expect to perform another script that generates this configure file. If you are looking for the easiest option, always consult the installation or build or readme file and follow the recommendation of the project.
How ./configure kicks things
Configuring the Shell script is usually the starting point of the construction process. It draws up the rest of the process for your specific environment.
The script checks for different dependencies that the project requires. It ensures that all required elements are present and correct, with the right versions. Run ./configure And you must end with a file with the name Makefile used in the next phase.
The configurescript itself is very configurable, via order control options. Run ./configure -Help For a detailed description of them.
Both configure and make generate a lot of exports. If you just want to perform these assignments and ignore what they do behind the scenes, you can –Calm Option to suppress most output.
If there is no configurescript, a project can offer a way to generate one. For example, the HTOP repository contains an autogenous.sh script. Performing this will generate a configurescript:
Export of the autogenous.sh script that is executed in the HTOP repository source code, which shows that it generates a configurescript.
Very simple projects, and that are not written in the C -language, can completely miss a configurescript. In this case, the three -step process is a two -step: just executed MAK & S make Install.
The configurescript often determines what happens later during the installation. In particular, the option -prefix is common. This defines the main folder under which the software is installed. By default this /USR /local, but you can offer an alternative if you want to organize your files differently.
Make does most of the work
After Configure has generated a Makefile, you can start the actual process of building the software. The Make program reads in a Makefile and checks a series of rules to decide what to build.
Makefiles written by hand are usually easy to read as soon as you are familiar with their syntax. In the simplest case, a Makefile describes how one file of the other can be generated when the last parent is. This Makefile describes, for example, the construction process of a very simple program:
program: program.c
gcc -o program program.c
Here the executable file program depends on the source file program.c. When it is performed, it checks the file against the dependencies. If nothing has changed since the last build – IE program is newer than program.c – will simply leave, safely in the assumption that nothing should be done. However, if Program.c has been changed, it is performed GCC and the program is compiled.
There is much more to make than this simplest case, and generated makefiles are usually much more complex. This generated Makefile for the HTOP program is, for example, 2,440 lines long:
An excerpt from the automatically generated Makefile for the HTOP project.
But you don’t have to worry about this. Unless you hack the source code – or which you write – you can be executed without really worrying about what is happening under the hood.
The step step can take a long time to be executed, especially for complex software involving different components. Be patient and don’t worry if it failure. The cause will usually be a missing dependence, and one of the benefits of Make is that it will resume the construction process without losing the work already done.
Implemented with make -installation
A typical build generates a compiled feasible file, either in the root of the project or often in a sub -directory called Bin. This is usually a self -standing program that you can perform via the entire path:
Running Make In the CLI directory creates a BIN sub -directory with the final enforceable file.
This is great to test or work on your own software, but you ultimately want to install it at a more convenient location.
Most makefiles have an installation goal that will check when you perform make make make. This often uses the order to install individual files and to set appropriate permissions and property.
The installation location depends on how you have driven configure. Remember that the standard location for executable files/USR/Local/Bin, for which you may not have permission to write. If your user cannot write to the installation location, you must install SUDO and specify the root password to continue.
Whatever the installation location is, it must be on your path, so that you can perform the program by typing the name on the assignment rule, instead of the entire path.