https://www.sharetechnote.com/html/C_makefile.html
makefile
As you know, in order to execute the program written in C, we need to do compilation and link to convert the c source code to an executable binary file. This compilation and link process would not be a big issue if you are handling a small number of c files and h files, but the process would go more and more complicated as the number of those files increases and you need to use more complicated compilation / link options. Repeating those compilation and link process over and over can be an annoying process. makefile is a kind of batch file (similar to shell program) that execute the predefined compilation/link procedure.
如果你曾经尝试过使用任何大规模的程序(比如那些你可以从互联网或github上获取的开源程序),你就会发现大多数程序的源代码都附带有自己的makefile,并且理解这些makefiles的内容并不是一件容易的事情。
本说明旨在帮助你理解那些程序提供的makefile的内容,并帮助你为你自己的程序创建makefiles。
无makefile编译
最简单的makefile
带有宏的最简单makefile
特殊符号
#include "hello.h"
int main(void)
{
print_hello();
return 1;
}
#include <stdio.h>
void print_hello(void)
{
printf("Hello World \n");
}
# gcc hello.c -o hello.o