Makefile: what is it, and what is its purpose?

I'm wanting to stop using IDE, and a friend advised me to use a Makefile for my programs, so:

  • What is Makefile?
  • What is its purpose?
Author: Maniero, 2016-09-21

1 answers

Normally associated with a utility called Make, or possibly some variation of it. It is just a configuration file that instructs what Make should do.

Make is used to automate the process of building applications by calling the compiler, linkeditor, running tests, and even doing deploy, among other possible operations. Originally it was created for C, but can be used with any type of application, although it is common for each language to have its own utility to manage this.

The file is a map of the project / solution indicating all files that are involved and how they should be compiled. Each can have a specific way of being treated. It can contain where the parts of the project are and their dependencies which Make will manage.

It is common to have some conditional operations depending on the result of previous operations. For example a build only it will occur if the source file has been modified. Either the linker be called If every build works, or call another utility if the tests fail.

Is practically a system of script with more specific purpose.

To achieve this goal there is a set of rules called directives.

Example taken from Wikipedia :

edit : main.o kbd.o command.o display.o 
    cc -o edit main.o kbd.o command.o display.o
     
main.o : main.c defs.h
    cc -c main.c
kbd.o : kbd.c defs.h command.h
    cc -c kbd.c
command.o : command.c defs.h command.h
    cc -c command.c
display.o : display.c defs.h
    cc -c display.c

clean :
     rm edit main.o kbd.o command.o display.o

I put on GitHub for future reference.

 8
Author: Maniero, 2020-11-09 18:17:56