A makefile is a file that contains instructions used by a compiler to build a program from source code. These instructions typically define the resources that the program depends on in order to function properly, as well as any additional directives as defined by the developer. In the following simple example, the program executable myprog depends on two object files, mymain.o and myfunc.o: myprog:
mymain.o myfunc.o gcc -o myprog mymain.o myfunc.o mymain.o: mymain.c gcc -c mymain.c myfunc.o: myfunc.c gcc -c myfunc.c
On the second line, gcc compiles the objects necessary for the program to run. On the remaining lines, each object is associated with a C source code file, then compiled using that source file. Using this approach, if you make changes to a single C source file (e.g., mymain.c), the make command will be able to efficiently rebuild the program based on the directives in the makefile.