Sample2 is another example of simple makefile but this time there is more than one single target. It does not take into consideration inc_a.h module because it is not described in the dependency list of app target. Now you see why mkfile.w is considered a bad or incomplete makefile.
mkfile.w: An incomplete or bad written makefile (.app.c and inc_a.h: a simple C application.
Source code contains a directory called sample1. If any dependency has a changed timestamp since the last build make command will execute the rule associated with the target. The makefile is read by make command which determines target files to be built by comparing the dates and times (timestamp) of source files in Dependency List. Also, a space at end of the rule line may cause make issues an error message. Rules are the necessary commands to create the target file by using Dependency List.Īs you see in figure 1 each command in the Rules part must be on lines that start with a TAB character. target depends upon a set of source files or even others targets described in Dependency List. A target most of time is a file to be created/updated. For instance, if your makefile is called run.mk then to execute make command type:Ī make file consists of a set of targets, dependencies and rules. The makefile often resides in the same directory as other source files and it can have any name you want. Make requires a makefile that tells it how your application should be built. It will be described later in this article. target is a tag (or name defined) present in makefile. The main point is makefile structure and how it works. In this article an explanation of all those options are not in the scope. You can type make -help to see all options make command supports. 4.4 Testing sample4 - mkfile3 and mkfile4.Suffix Rules: Simplifying Makefiles Syntax Phony Targets Macros and Special Characters Move make_samples.zip to directory created.Create a directory in your home directory.So, for a better understanding of this article:
You should download the samples file and unzip it with the unzip command or any other preferred tool. The most important files in the samples are the makefiles not the C source code.
There is a zip file with many samples in a directory structure.
This article is not a full tutorial, it focuses on C applications and how to use the make command and makefile to build them. The make command is used not only to help a developer compile applications, it can be used whenever you want to produce output files from several input files. The tool I'm talking about is the make command. However, when a project gets too complex with many source files it becomes necessary to have a tool that allows the developer to manage the project. Developers can recompile them easily by calling the compiler directly, passing source files as arguments. Small C/C++ applications with a couple of modules are easy to manage. Download samples in ZIP format - 9.45 KB.