Makefile include
tree
liyongjun@Box:~/project/c/app$ ls
main.c Makefile Makefile.inc
main.c
#include <stdio.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
int i = 0;
while(1)
{
printf("hello world %d\n", i++);
fflush(stdout);
sleep(1);
}
return 0;
}
Makefile.inc
all:
gcc main.c -o main
clean:
rm main
Makefile
include Makefile.inc
执行
liyongjun@Box:~/project/c/app$ make
gcc main.c -o main
liyongjun@Box:~/project/c/app$ ./main
hello world 0
hello world 1
hello world 2
^C
liyongjun@Box:~/project/c/app$ make clean
rm main
liyongjun@Box:~/project/c/app$
Makefile 的 include 可以简单地理解为就地展开。虽然实际情况会比这复杂。