helloworld作为起点: 直接贴执行的源代码与增加 makefile $(warning string)调试信息后的效果:
三个源文件:
1: print.h
#include <stdio.h>
void printhello();
2:print.c
#include "print.h"
void printhello()
{
printf("hello world!\n");
}
3:main.c
#include "print.h"
int main(int argc, char *argv[])
{
printhello();
return 0;
}
Makefile :(添加了$(warning string)的调试信息 :https://www.cnblogs.com/AP0904225/p/5936465.html)
makefile:
$(warning "some text1....")helloworld:main.o print.o
$(warning "some text2....")gcc -o helloworld main.o print.o
$(warning "some text3....")main.o:main.c print.h
$(warning "some text4....")gcc -c main.c
$(warning "some text5....")print.o:print.c print.h
$(warning "some text6....")gcc -c print.c
$(warning "some text7....")clean:
$(warning "some text8....")rm helloworld main.o print.o
查看makefile 及 对应执行的行号:
# cat makefile -n
1 $(warning "some text1....")helloworld:main.o print.o
2 $(warning "some text2....")gcc -o helloworld main.o print.o
3
4 $(warning "some text3....")main.o:main.c print.h
5 $(warning "some text4....")gcc -c main.c
6
7 $(warning "some text5....")print.o:print.c print.h
8 $(warning "some text6....")gcc -c print.c
9
10 $(warning "some text7....")clean:
11 $(warning "some text8....")rm helloworld main.o print.o
增加$(warning string)调试信息后,makefile执行后的效果:
makefile:1: "some text1...."
makefile:4: "some text3...."
makefile:7: "some text5...."
makefile:10: "some text7...."
makefile:5: "some text4...."
gcc -c main.c
makefile:8: "some text6...."
gcc -c print.c
makefile:2: "some text2...."
gcc -o helloworld main.o print.o