22.1 C

Linux make command

Popular Posts

For the Unix or similar operating systems make is an program to build and maintain collections of programs (and different kinds of files) using the source code.

This page describes make, the GNU/ Linux version of make..


The function for this make program is to identify whether the pieces of a program require to be reconfigured or compiling and to issue the necessary commands to rebuild the program. This document describes how to use the GNU make implementation make made by Richard Stallman and Roland McGrath, and is currently maintained by Paul Smith. A majority of the examples below are C programming as they are the generally used, but you can make use of make with any language that’s compiler is run using the shell command. Actually, make is not restricted to programming. It can be used to describe any task in which certain files need to be automatically updated from other files as soon as the other ones modify.

In order to prepare for using to make the program, you need to create an file known as”the makefile which outlines the relationships between the files within your program and also the commands to update each file. In a software program, usually the executable file is upgraded via objects files that are then created by combining the source files.

If a makefile that is suitable exists every time you modify the source files, you can use the following command is a simple one to use:

can be used to complete all required recompilations. Make is sufficient for all recompilations. program can be used to perform all necessary recompilations. program makes use of the makefile database and the times of last modification of the files to determine what files have to be changed. For each file it issue the commands stored by the data base.

make executes commands within the makefile to modify one or more target names in which the name is usually a name of a program. If the -f parameter isn’t in use, make will search to the Makefiles, GNUmakefile makefile, and Makefile in the order listed above.

Normally , you should label your makefile createfile and makefile. (The official name that is recommended should be Makefile due to its prominent placement in the middle of the directory listing, and right next to other important files like the README.) The first name we have checked, GNUmakefile, is not recommended for all createfiles. It is recommended to choose this name if have a makefile particular to GNU make which cannot be recognized in other editions that use create. If your makefile has an underscore (” “) and the normal input is read.

create updates targets if it relies on files that have been altered since the last time the target was changed or if the target does not exist.

The Typical Use

make is used to construct executable programs and libraries by utilizing the source code. In general, make is useful for any process which involves the execution of arbitrary commands to convert the source file into the desired outcome. For instance, make could be used to identify any changes that has been made to an image (the the source) and the actions to transform may include converting the file to a specific format, then copy the results into an software for managing content and then to send an email to a group of users to whom executed the above steps.

make is invoked using an array of target names of files to build using commands-line argument:

Without argument, make builds the first target in its makefile. It is usually a target that is named by its entirety.

create decides whether a file must be rebuilt by the comparison of the file’s modifications times. This resolves the issue of making sure that files are created which are already updated, however, it does not work when a file changes however its modification time remains within the last. The changes could result from the restoration of old versions of the origin file or even when it is a networking filesytem is the source for files, and its clock or timezone are not aligned with the system running the the make. The user should deal with the situation by requiring an entire build. In contrast, if the time for modification of a source file is not in the near future, it could cause unnecessary rebuilding.


make searches the directory to locate the makefile that you want to run. GNU make searches for files to find the name of a file from GNUmakefilemakefile followed by Makefile which then runs the specific target(s) from the file.

Makefile is a language that’s similar to imperative programming. makefile language is similar to declarative programming where the necessary conditions for achieving the end result are specified, but the order in which actions have to be performed is not critical. This could be confusing for those who are who are used to imperative programming which clearly outlines how the desired outcome will be achieved.

One issue with build automation is the customisation of an automated build process for specific operating system. For example an compiler for one platform may not be able to accept the same features as the one on another. This can be a problem that is not dealt with using make by itself. This issue is usually handled by creating distinct instructions for building specific to the platform which can be handled using create. The most common tools used to accomplish this include autoconf and the cmake.


A makefile is basically a set comprised of the rules. Each rule starts with a dependency statement that specifies a target. It is and is followed by an apostrophe (” :“) and, if desired, an enumeration of the components (files and other objects) upon which the target relies. It is organized to ensure it is clear that the goal (left right hand side of the colon) is dependent on the component (right right hand side of the colon). It is typical to use components as prerequisites of the goal.

Here, is the tab Character . The rule usually has only one unique target instead of multiple targets.

For instance the C .o object file is created by .c files, therefore .c files come first (i.e. the specific object file targets depend on the C Source file, as do header files). Since create itself doesn’t understand the distinction between various types of files, it could lead to human error. A misplaced or unintentionally added dependency may not immediately obvious , and could cause subtle glitches within the software that is generated. Makefiles can be written that produce these dependencies by calling third-party software, and some makefile generators like one called the GNU automake toolchain, are able to perform this task automatically.

Following each dependency line, there are a set of command line could follow, which outline the method of transforming parts (usually sources files) into the desired output (usually”output”) “output”). If any component has been modified, the command line are executed.

In the case of GNU make the initial command could be in the same line as the prerequisites and followed by semicolons

Every command line has to begin with a tab character in order to be acknowledged as an actual command. Tab is an example of a space character, however the space character doesn’t have the same meaning. This is a problem, as there might be no visible distinction between a tab and the space characters. This particular aspect of the syntax used in makefiles is frequently the subject of criticismand it is crucial to be aware of.

But, GNU make (since version 3.82) permits the user to select one symbol (one characters) as the prefix of the recipe by using the .RECIPEPREFIX special variable such as:

Each command is executed in an individual shell or command-line interpreter. Since operating systems have different interpreters for command lines, this could result in makefiles that are not portable. For example, GNU make is by default executing commands using the /bin/sh shell that is the shell used by Unix commands such as Cp are usually used.

A rule might not have commands defined. The dependency line could be composed of only components that are referring to specific targets, such as:

The rules’ command lines are typically arranged in a way that they produce the intended result. For instance, If ” file.html” is more recent, it is changed to text. The makefile’s content:

The above rule will be activated when you making changes to ” file.txt“.

Following the procedure, make would typically follow this rule to change”file.txt” target ” file.txt” destination if ” file.html” was newer:

Command lines may have any of the prefixes below:

  • A hyper-minus ( ) to indicate that mistakes are not taken into consideration
  • an at symbol ( @) an at sign (@) to indicate that the command will not be written to the standard output prior to when the command is executed.
  • With a plus symbol ( +) indicates that the command is executed regardless of whether the command is executed in the “do not perform” mode

The ability to ignore errors and silence any echo output is also achieved using the goals ” .IGNORE” and ” .SILENT” and “.SILENT.


A makefile may contain definitions for macros. Macros are typically described as variables when they contain simple definitions of strings, such as ” CC=clang” that would indicate that clang is used to be an example of a C compiler. Macros that are included in makefiles could be modified in commands that are passed through make. make utility. variable for environment can also be used as macros.

Macros permit users to specify the program that is invoked and other specific behavior that they want to implement in the process of building. As an example, as demonstrated it is possible to specify the “CC” macro ” CC” is commonly used in makefiles towards the place of the C compiler.

Suffix Rules

Suffix rules include “targets” with names of their form .FROM.TO and are utilized to initiate actions that are based on the extension of a file. In the commands of the suffix-related rules POSIX stipulates that internal macro ” $<” refers to the initial necessary condition as well as ” [email protected[email protected]” is the intended target. In this instance that transforms an HTML file to text using you will notice that the redirection token ” >” is part of the command line ” $<” is a macro that refers directly to the HTML file:

Other Elements

  • One-line comments start by using the hash sign (” #“).
  • Certain directives in makefiles may contain other makefiles.
  • Line continuation is identified by the”backslash” (” \“) character at the end of the line, like:

Exit Status

GNU makes exits with the status:

  • 0. when all makefiles have been successfully parsed, and no targets that were constructed failedto build;
  • 1 If you used the “-q=” flag was set as well make determines that the target must be rebuilt as well as
  • 2 If any errors were found.


Makefiles are usually used to compile the code ( *.c*.cc*.C, etc. ) however, they are also employed to give commands for automating everyday tasks.

Here’s three possible ways to execute make in conjunction with a particular makefile. It is the create commands are first listed followed by the makefile

If you are you are given in distmake will create a release archive using the directory currently in use.

Following, we will provide an extremely basic makefile that , by the default (the ” all” rule which is the first rule listed) compiles a source code known as ” helloworld.c” by using its C compiler. It additionally provides an ” clean” goal to delete the generated files in case the user wishes to begin from scratch. There are two macros: “[email protected]”[email protected] [email protected] and $ are two macros inside the system (also called automatic variables) which refer to the name of the target and the implicit source and implicit source, respectively. In the case below, $^ is expanded to include an encapsulated space separated list of the necessary elements.

A lot of systems have already-defined create regulations and macros that define common tasks, such as compilation based on suffixes of files. This lets users skip the actual (often non-portable) instructions to create the desired destination from source(s). On such systems, the makefile above could be altered as follows:

By using this makefile, the issue it is the case that ” helloworld.o” relies from ” helloworld.c” is now handled through the make. In this example, it doesn’t matter however the true significance of suffix rules becomes apparent when the amount of source files included in an application starts to increase. You only need to create a rule for linking and declare the object files as required. makes will decide implicitly how to create all object files and search for any changes to of the sources.

Simple suffix rules work provided that the source files don’t depend on one another or on other files, such as header files. Another option to simplify the process of building is to utilize pattern matching rules which can be used with the compiler-assisted generation of dependency.

The next scenario requires the GCC compiler. It’s a general makefile that compiles every C files within a folder to the object files, and then connects them to the executable. Before compilation is completed the dependencies are collected in a format that is compatible with makefiles to an unnoticed file called ” .depend” which is later added in the makefile.

Previous articleStart
Next articleCheck box
- Advertisement -spot_img

More articles


Please enter your comment!
Please enter your name here

- Advertisement -spot_img

Recent Posts