makefile每日练习 (一)

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

 


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值