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

Asked

Viewed 2,572 times

9

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

  • What is a Makefile?
  • What is your purpose?

1 answer

8


Usually associated with a utility called Make, or eventually some variation of it. It is just a configuration file that instructs what the Make must do.

The Make is used to automate the process of building applications by calling the compiler, linkeditor, running tests, and even doing the deploy, among other possible operations. Originally it was created for C, but can be used with any type of application, yet it is common for every 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 should be compiled. Each can have a specific way of being treated. It can contain where the parts of the project and its dependencies are Make will make the management.

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

It is practically a system of script for 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

I put in the Github for future reference.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.