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

7

I want to stop using IDE, and a friend advised me to use a Makefile for my programs, then:

  • What is Makefile?
  • What is your purpose?
asked by anonymous 21.09.2016 / 18:12

1 answer

6

Usually 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, linker , running tests, and even doing deploy , among other operations possible. Originally it was created for C, but it can be used with any type of application, although it is common for each language to have its own utility to manage it.

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

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

It's practically a script system with a 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
    
21.09.2016 / 18:23